Skip to content

Commit 0be7638

Browse files
committed
feat: add eslint/rules/eol-open-bracket-spacing
--- type: pre_commit_static_analysis_report description: Results of running static analysis checks when committing changes. report: - task: lint_filenames status: passed - task: lint_editorconfig status: passed - task: lint_markdown status: passed - task: lint_package_json status: passed - task: lint_repl_help status: na - task: lint_javascript_src status: passed - task: lint_javascript_cli status: na - task: lint_javascript_examples status: passed - task: lint_javascript_tests status: passed - task: lint_javascript_benchmarks status: na - task: lint_python status: na - task: lint_r status: na - task: lint_c_src status: na - task: lint_c_examples status: na - task: lint_c_benchmarks status: na - task: lint_c_tests_fixtures status: na - task: lint_shell status: na - task: lint_typescript_declarations status: na - task: lint_typescript_tests status: na - task: lint_license_headers status: passed --- --- type: pre_push_report description: Results of running various checks prior to pushing changes. report: - task: run_javascript_examples status: passed - task: run_c_examples status: na - task: run_cpp_examples status: na - task: run_javascript_readme_examples status: passed - task: run_c_benchmarks status: na - task: run_cpp_benchmarks status: na - task: run_fortran_benchmarks status: na - task: run_javascript_benchmarks status: na - task: run_julia_benchmarks status: na - task: run_python_benchmarks status: na - task: run_r_benchmarks status: na - task: run_javascript_tests status: na ---
1 parent 584df38 commit 0be7638

File tree

11 files changed

+1002
-0
lines changed

11 files changed

+1002
-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+
* No spaces allowed between an opening parenthesis or bracket and a nested object or array expression.
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: 165 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,165 @@
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.
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.
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+
var result;
101+
var code;
102+
103+
code = [
104+
'function test() {',
105+
' var log = require( \'@stdlib/console/log\' );',
106+
' log( {',
107+
' "key": "value"',
108+
' });',
109+
' var arr = [ {',
110+
' "nested": true',
111+
' }];',
112+
' log( arr );',
113+
'}'
114+
].join( '\n' );
115+
116+
linter.defineRule( 'eol-open-bracket-spacing', rule );
117+
118+
result = linter.verify( code, {
119+
'rules': {
120+
'eol-open-bracket-spacing': 'error'
121+
}
122+
});
123+
/* returns
124+
[
125+
{
126+
'ruleId': 'eol-open-bracket-spacing',
127+
'severity': 2,
128+
'message': 'No spaces allowed between an opening parenthesis or bracket and a nested object or array expression',
129+
'line': 3,
130+
'column': 3,
131+
'nodeType': 'CallExpression'
132+
},
133+
{
134+
'ruleId': 'eol-open-bracket-spacing',
135+
'severity': 2,
136+
'message': 'No spaces allowed between an opening parenthesis or bracket and a nested object or array expression',
137+
'line': 6,
138+
'column': 13,
139+
'nodeType': 'ArrayExpression'
140+
}
141+
]
142+
*/
143+
```
144+
145+
</section>
146+
147+
<!-- /.examples -->
148+
149+
<!-- Section for related `stdlib` packages. Do not manually edit this section, as it is automatically populated. -->
150+
151+
<section class="related">
152+
153+
</section>
154+
155+
<!-- /.related -->
156+
157+
<!-- Section for all links. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
158+
159+
<section class="links">
160+
161+
[eslint-rules]: https://eslint.org/docs/developer-guide/working-with-rules
162+
163+
</section>
164+
165+
<!-- /.links -->
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
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+
var result;
26+
var code;
27+
28+
code = [
29+
'function test() {',
30+
' var log = require( \'@stdlib/console/log\' );',
31+
' log( {',
32+
' "key": "value"',
33+
' });',
34+
' var arr = [ {',
35+
' "nested": true',
36+
' }];',
37+
' log( arr );',
38+
'}'
39+
].join( '\n' );
40+
41+
linter.defineRule( 'eol-open-bracket-spacing', rule );
42+
43+
result = linter.verify( code, {
44+
'rules': {
45+
'eol-open-bracket-spacing': 'error'
46+
}
47+
});
48+
console.log( result );
49+
/* =>
50+
[
51+
{
52+
'ruleId': 'eol-open-bracket-spacing',
53+
'severity': 2,
54+
'message': 'No spaces allowed between an opening parenthesis or bracket and a nested object or array expression',
55+
'line': 3,
56+
'column': 3,
57+
'nodeType': 'CallExpression'
58+
},
59+
{
60+
'ruleId': 'eol-open-bracket-spacing',
61+
'severity': 2,
62+
'message': 'No spaces allowed between an opening parenthesis or bracket and a nested object or array expression',
63+
'line': 6,
64+
'column': 13,
65+
'nodeType': 'ArrayExpression'
66+
}
67+
]
68+
*/
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.
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)