Skip to content

Commit 9d632d5

Browse files
authored
feat: add _tools/eslint/rules/line-closing-bracket-spacing
PR-URL: #4211 Private-ref: stdlib-js/todo#2325 Reviewed-by: Athan Reines <[email protected]>
1 parent a3766c6 commit 9d632d5

File tree

11 files changed

+1081
-1
lines changed

11 files changed

+1081
-1
lines changed

etc/eslint/rules/stdlib.js

Lines changed: 47 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ rules[ 'stdlib/capitalized-comments' ] = [ 'warn', {
6969
'stdlib',
7070
'throws'
7171
]
72-
} ];
72+
}];
7373

7474
/**
7575
* Enforce that return annotation values match actual output.
@@ -3861,6 +3861,52 @@ rules[ 'stdlib/jsdoc-unordered-list-marker-style' ] = [ 'error', '-' ];
38613861
*/
38623862
rules[ 'stdlib/jsdoc-main-export' ] = 'error';
38633863

3864+
/**
3865+
* Disallow spaces between a closing parenthesis or bracket and a nested object or array expression at the beginning of a line.
3866+
*
3867+
* @name line-closing-bracket-spacing
3868+
* @memberof rules
3869+
* @type {string}
3870+
* @default 'error'
3871+
*
3872+
* @example
3873+
* // Bad...
3874+
* var log = require( '@stdlib/console/log' );
3875+
*
3876+
* log({
3877+
* 'foo': true
3878+
* } );
3879+
*
3880+
* log([
3881+
* 1,
3882+
* 2,
3883+
* 3
3884+
* ] );
3885+
*
3886+
* log([{
3887+
* 'bar': true
3888+
* } ] );
3889+
*
3890+
* @example
3891+
* // Good...
3892+
* var log = require( '@stdlib/console/log' );
3893+
*
3894+
* log({
3895+
* 'foo': true
3896+
* });
3897+
*
3898+
* log([
3899+
* 1,
3900+
* 2,
3901+
* 3
3902+
* ]);
3903+
*
3904+
* log([{
3905+
* 'bar': true
3906+
* }]);
3907+
*/
3908+
rules[ 'stdlib/line-closing-bracket-spacing' ] = 'error';
3909+
38643910
/**
38653911
* Enforce that export statements are placed at the end of a file.
38663912
*

lib/node_modules/@stdlib/_tools/eslint/rules/lib/index.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -765,6 +765,15 @@ setReadOnly( rules, 'jsdoc-typedef-typos', require( '@stdlib/_tools/eslint/rules
765765
*/
766766
setReadOnly( rules, 'jsdoc-unordered-list-marker-style', require( '@stdlib/_tools/eslint/rules/jsdoc-unordered-list-marker-style' ) );
767767

768+
/**
769+
* @name line-closing-bracket-spacing
770+
* @memberof rules
771+
* @readonly
772+
* @type {Function}
773+
* @see {@link module:@stdlib/_tools/eslint/rules/line-closing-bracket-spacing}
774+
*/
775+
setReadOnly( rules, 'line-closing-bracket-spacing', require( '@stdlib/_tools/eslint/rules/line-closing-bracket-spacing' ) );
776+
768777
/**
769778
* @name module-exports-last
770779
* @memberof rules
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+
# line-closing-bracket-spacing
22+
23+
> [ESLint rule][eslint-rules] to enforce that no spaces are present between a closing parenthesis or bracket and a nested object or array expression at the beginning 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/line-closing-bracket-spacing' );
37+
```
38+
39+
#### rule
40+
41+
[ESLint rule][eslint-rules] to enforce that no spaces are present between a closing parenthesis or bracket and a nested object or array expression at the beginning of a line.
42+
43+
**Bad**:
44+
45+
<!-- eslint-disable stdlib/line-closing-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/line-closing-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( 'line-closing-bracket-spacing', rule );
115+
116+
var result = linter.verify( code, {
117+
'rules': {
118+
'line-closing-bracket-spacing': 'error'
119+
}
120+
});
121+
/* returns
122+
[
123+
{
124+
'ruleId': 'line-closing-bracket-spacing',
125+
'severity': 2,
126+
'message': 'No spaces allowed between a closing parenthesis or bracket and a nested object or array expression at the beginning of a line',
127+
'line': 3,
128+
'column': 3,
129+
'nodeType': 'CallExpression'
130+
},
131+
{
132+
'ruleId': 'line-closing-bracket-spacing',
133+
'severity': 2,
134+
'message': 'No spaces allowed between a closing parenthesis or bracket and a nested object or array expression at the beginning 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( 'line-closing-bracket-spacing', rule );
40+
41+
var result = linter.verify( code, {
42+
'rules': {
43+
'line-closing-bracket-spacing': 'error'
44+
}
45+
});
46+
console.log( result );
47+
/* =>
48+
[
49+
{
50+
'ruleId': 'line-closing-bracket-spacing',
51+
'severity': 2,
52+
'message': 'No spaces allowed between a closing parenthesis or bracket and a nested object or array expression at the beginning of a line',
53+
'line': 3,
54+
'column': 3,
55+
'nodeType': 'CallExpression'
56+
},
57+
{
58+
'ruleId': 'line-closing-bracket-spacing',
59+
'severity': 2,
60+
'message': 'No spaces allowed between a closing parenthesis or bracket and a nested object or array expression at the beginning 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 a closing parenthesis or bracket and a nested object or array expression at the beginning of a line.
23+
*
24+
* @module @stdlib/_tools/eslint/rules/line-closing-bracket-spacing
25+
*
26+
* @example
27+
* var rule = require( '@stdlib/_tools/eslint/rules/line-closing-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)