Skip to content

Commit aaf7299

Browse files
authored
feat: add eslint/rules/eol-open-bracket-spacing
PR-URL: #4061 Private-ref: stdlib-js/todo#2324 Reviewed-by: Athan Reines <kgryte@gmail.com>
1 parent acb12c7 commit aaf7299

File tree

11 files changed

+996
-0
lines changed

11 files changed

+996
-0
lines changed

etc/eslint/rules/stdlib.js

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,52 @@ rules[ 'stdlib/doctest-quote-props' ] = 'error';
200200
*/
201201
rules[ 'stdlib/empty-line-before-comment' ] = 'error';
202202

203+
/**
204+
* Disallow spaces between an opening parenthesis or bracket and a nested object or array expression at the end of a line.
205+
*
206+
* @name eol-open-bracket-spacing
207+
* @memberof rules
208+
* @type {string}
209+
* @default 'error'
210+
*
211+
* @example
212+
* // Bad...
213+
* var log = require( '@stdlib/console/log' );
214+
*
215+
* log( {
216+
* 'foo': true
217+
* });
218+
*
219+
* log( [
220+
* 1,
221+
* 2,
222+
* 3
223+
* ]);
224+
*
225+
* log( [ {
226+
* 'bar': true
227+
* }]);
228+
*
229+
* @example
230+
* // Good...
231+
* var log = require( '@stdlib/console/log' );
232+
*
233+
* log({
234+
* 'foo': true
235+
* });
236+
*
237+
* log([
238+
* 1,
239+
* 2,
240+
* 3
241+
* ]);
242+
*
243+
* log([{
244+
* 'bar': true
245+
* }]);
246+
*/
247+
rules[ 'stdlib/eol-open-bracket-spacing' ] = 'error';
248+
203249
/**
204250
* Require blockquotes to have `2` character indentation.
205251
*
Lines changed: 163 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,163 @@
1+
<!--
2+
3+
@license Apache-2.0
4+
5+
Copyright (c) 2024 The Stdlib Authors.
6+
7+
Licensed under the Apache License, Version 2.0 (the "License");
8+
you may not use this file except in compliance with the License.
9+
You may obtain a copy of the License at
10+
11+
http://www.apache.org/licenses/LICENSE-2.0
12+
13+
Unless required by applicable law or agreed to in writing, software
14+
distributed under the License is distributed on an "AS IS" BASIS,
15+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16+
See the License for the specific language governing permissions and
17+
limitations under the License.
18+
19+
-->
20+
21+
# eol-open-bracket-spacing
22+
23+
> [ESLint rule][eslint-rules] to enforce that no spaces are present between an opening parenthesis or bracket and a nested object or array expression at the end of a line.
24+
25+
<section class="intro">
26+
27+
</section>
28+
29+
<!-- /.intro -->
30+
31+
<section class="usage">
32+
33+
## Usage
34+
35+
```javascript
36+
var rule = require( '@stdlib/_tools/eslint/rules/eol-open-bracket-spacing' );
37+
```
38+
39+
#### rule
40+
41+
[ESLint rule][eslint-rules] to enforce that no spaces are present between an opening parenthesis or bracket and a nested object or array expression at the end of a line.
42+
43+
**Bad**:
44+
45+
<!-- eslint-disable stdlib/eol-open-bracket-spacing -->
46+
47+
```javascript
48+
var log = require( '@stdlib/console/log' );
49+
50+
log( {
51+
'foo': true
52+
});
53+
54+
log( [
55+
1,
56+
2,
57+
3
58+
]);
59+
60+
log( [ {
61+
'bar': true
62+
}]);
63+
```
64+
65+
**Good**:
66+
67+
```javascript
68+
var log = require( '@stdlib/console/log' );
69+
70+
log({
71+
'foo': true
72+
});
73+
74+
log([
75+
1,
76+
2,
77+
3
78+
]);
79+
80+
log([{
81+
'bar': true
82+
}]);
83+
```
84+
85+
</section>
86+
87+
<!-- /.usage -->
88+
89+
<section class="examples">
90+
91+
## Examples
92+
93+
<!-- eslint no-undef: "error" -->
94+
95+
```javascript
96+
var Linter = require( 'eslint' ).Linter;
97+
var rule = require( '@stdlib/_tools/eslint/rules/eol-open-bracket-spacing' );
98+
99+
var linter = new Linter();
100+
101+
var code = [
102+
'function test() {',
103+
' var log = require( \'@stdlib/console/log\' );',
104+
' log( {',
105+
' "key": "value"',
106+
' });',
107+
' var arr = [ {',
108+
' "nested": true',
109+
' }];',
110+
' log( arr );',
111+
'}'
112+
].join( '\n' );
113+
114+
linter.defineRule( 'eol-open-bracket-spacing', rule );
115+
116+
var result = linter.verify( code, {
117+
'rules': {
118+
'eol-open-bracket-spacing': 'error'
119+
}
120+
});
121+
/* returns
122+
[
123+
{
124+
'ruleId': 'eol-open-bracket-spacing',
125+
'severity': 2,
126+
'message': 'No spaces allowed between an opening parenthesis or bracket and a nested object or array expression at the end of a line',
127+
'line': 3,
128+
'column': 3,
129+
'nodeType': 'CallExpression'
130+
},
131+
{
132+
'ruleId': 'eol-open-bracket-spacing',
133+
'severity': 2,
134+
'message': 'No spaces allowed between an opening parenthesis or bracket and a nested object or array expression at the end of a line',
135+
'line': 6,
136+
'column': 13,
137+
'nodeType': 'ArrayExpression'
138+
}
139+
]
140+
*/
141+
```
142+
143+
</section>
144+
145+
<!-- /.examples -->
146+
147+
<!-- Section for related `stdlib` packages. Do not manually edit this section, as it is automatically populated. -->
148+
149+
<section class="related">
150+
151+
</section>
152+
153+
<!-- /.related -->
154+
155+
<!-- Section for all links. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
156+
157+
<section class="links">
158+
159+
[eslint-rules]: https://eslint.org/docs/developer-guide/working-with-rules
160+
161+
</section>
162+
163+
<!-- /.links -->
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
/**
2+
* @license Apache-2.0
3+
*
4+
* Copyright (c) 2024 The Stdlib Authors.
5+
*
6+
* Licensed under the Apache License, Version 2.0 (the "License");
7+
* you may not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
18+
19+
'use strict';
20+
21+
var Linter = require( 'eslint' ).Linter;
22+
var rule = require( './../lib' );
23+
24+
var linter = new Linter();
25+
26+
var code = [
27+
'function test() {',
28+
' var log = require( \'@stdlib/console/log\' );',
29+
' log( {',
30+
' "key": "value"',
31+
' });',
32+
' var arr = [ {',
33+
' "nested": true',
34+
' }];',
35+
' log( arr );',
36+
'}'
37+
].join( '\n' );
38+
39+
linter.defineRule( 'eol-open-bracket-spacing', rule );
40+
41+
var result = linter.verify( code, {
42+
'rules': {
43+
'eol-open-bracket-spacing': 'error'
44+
}
45+
});
46+
console.log( result );
47+
/* =>
48+
[
49+
{
50+
'ruleId': 'eol-open-bracket-spacing',
51+
'severity': 2,
52+
'message': 'No spaces allowed between an opening parenthesis or bracket and a nested object or array expression at the end of a line',
53+
'line': 3,
54+
'column': 3,
55+
'nodeType': 'CallExpression'
56+
},
57+
{
58+
'ruleId': 'eol-open-bracket-spacing',
59+
'severity': 2,
60+
'message': 'No spaces allowed between an opening parenthesis or bracket and a nested object or array expression at the end of a line',
61+
'line': 6,
62+
'column': 13,
63+
'nodeType': 'ArrayExpression'
64+
}
65+
]
66+
*/
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
/**
2+
* @license Apache-2.0
3+
*
4+
* Copyright (c) 2024 The Stdlib Authors.
5+
*
6+
* Licensed under the Apache License, Version 2.0 (the "License");
7+
* you may not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
18+
19+
'use strict';
20+
21+
/**
22+
* ESLint rule to enforce that no spaces are present between an opening parenthesis or bracket and a nested object or array expression at the end of a line.
23+
*
24+
* @module @stdlib/_tools/eslint/rules/eol-open-bracket-spacing
25+
*
26+
* @example
27+
* var rule = require( '@stdlib/_tools/eslint/rules/eol-open-bracket-spacing' );
28+
*
29+
* console.log( rule );
30+
*/
31+
32+
// MODULES //
33+
34+
var main = require( './main.js' );
35+
36+
37+
// EXPORTS //
38+
39+
module.exports = main;

0 commit comments

Comments
 (0)