Skip to content

Commit e9f48a5

Browse files
Merge branch 'stdlib-js:develop' into develop
2 parents cc882e9 + 0734a5f commit e9f48a5

File tree

17 files changed

+1213
-5
lines changed

17 files changed

+1213
-5
lines changed

.github/labeler.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,3 +35,7 @@ REPL:
3535
Statistics:
3636
- changed-files:
3737
- any-glob-to-all-files: '**/stats/**/*'
38+
39+
Tools:
40+
- changed-files:
41+
- any-glob-to-all-files: '**/_tools/**/*'

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/eol-open-bracket-spacing/lib/main.js

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,10 @@ function main( context ) {
9191
) {
9292
prevToken = source.getTokenBefore( args[ 0 ] );
9393
tokenAfter = source.getFirstToken( args[ 0 ] );
94-
if ( source.isSpaceBetween( prevToken, tokenAfter ) ) {
94+
if (
95+
prevToken.loc.end.line === tokenAfter.loc.end.line &&
96+
source.isSpaceBetween( prevToken, tokenAfter )
97+
) {
9598
report( node, prevToken, tokenAfter );
9699
}
97100
} else if ( args[ 0 ].type === 'ArrayExpression' ) {
@@ -102,7 +105,10 @@ function main( context ) {
102105
) {
103106
prevToken = source.getTokenBefore( args[ 0 ] );
104107
tokenAfter = source.getFirstToken( args[ 0 ] );
105-
if ( source.isSpaceBetween( prevToken, tokenAfter ) ) {
108+
if (
109+
prevToken.loc.end.line === tokenAfter.loc.end.line &&
110+
source.isSpaceBetween( prevToken, tokenAfter )
111+
) {
106112
report( node, prevToken, tokenAfter );
107113
}
108114
} else {
@@ -111,6 +117,7 @@ function main( context ) {
111117
nextToken = source.getTokenAfter( tokenAfter );
112118
if (
113119
tokenAfter.loc.end.line !== nextToken.loc.end.line &&
120+
prevToken.loc.end.line === tokenAfter.loc.end.line &&
114121
source.isSpaceBetween( prevToken, tokenAfter )
115122
) {
116123
report( node, prevToken, tokenAfter );
@@ -131,7 +138,10 @@ function main( context ) {
131138
prevToken = source.getFirstToken( node );
132139
tokenAfter = source.getFirstToken( elem );
133140

134-
if ( source.isSpaceBetween( prevToken, tokenAfter ) ) {
141+
if (
142+
prevToken.loc.end.line === tokenAfter.loc.end.line &&
143+
source.isSpaceBetween( prevToken, tokenAfter )
144+
) {
135145
report( node, prevToken, tokenAfter );
136146
}
137147
}

lib/node_modules/@stdlib/_tools/eslint/rules/eol-open-bracket-spacing/test/fixtures/unvalidated.js

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,56 @@ test = {
5050
};
5151
valid.push( test);
5252

53+
test = {
54+
'code': [
55+
' var log = require( \'@stdlib/console/log\' );',
56+
' log(',
57+
' {',
58+
' \'a\': 1',
59+
' }',
60+
' );'
61+
].join( '\n' )
62+
};
63+
valid.push( test);
64+
65+
test = {
66+
'code': [
67+
' var log = require( \'@stdlib/console/log\' );',
68+
' log(',
69+
' [',
70+
' 1,',
71+
' 2',
72+
' ]',
73+
' );'
74+
].join( '\n' )
75+
};
76+
valid.push( test);
77+
78+
test = {
79+
'code': [
80+
' var log = require( \'@stdlib/console/log\' );',
81+
' log(',
82+
' [',
83+
' {',
84+
' \'a\': 1',
85+
' }',
86+
' ]',
87+
' );'
88+
].join( '\n' )
89+
};
90+
valid.push( test);
91+
92+
test = {
93+
'code': [
94+
' var arr = [',
95+
' {',
96+
' \'a\': 1',
97+
' }',
98+
'];'
99+
].join( '\n' )
100+
};
101+
valid.push( test);
102+
53103

54104
// EXPORTS //
55105

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 -->

0 commit comments

Comments
 (0)