Skip to content

Commit

Permalink
Merge branch 'stdlib-js:develop' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
0PrashantYadav0 authored Dec 28, 2024
2 parents cc882e9 + 0734a5f commit e9f48a5
Show file tree
Hide file tree
Showing 17 changed files with 1,213 additions and 5 deletions.
4 changes: 4 additions & 0 deletions .github/labeler.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,7 @@ REPL:
Statistics:
- changed-files:
- any-glob-to-all-files: '**/stats/**/*'

Tools:
- changed-files:
- any-glob-to-all-files: '**/_tools/**/*'
48 changes: 47 additions & 1 deletion etc/eslint/rules/stdlib.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ rules[ 'stdlib/capitalized-comments' ] = [ 'warn', {
'stdlib',
'throws'
]
} ];
}];

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

/**
* Disallow spaces between a closing parenthesis or bracket and a nested object or array expression at the beginning of a line.
*
* @name line-closing-bracket-spacing
* @memberof rules
* @type {string}
* @default 'error'
*
* @example
* // Bad...
* var log = require( '@stdlib/console/log' );
*
* log({
* 'foo': true
* } );
*
* log([
* 1,
* 2,
* 3
* ] );
*
* log([{
* 'bar': true
* } ] );
*
* @example
* // Good...
* var log = require( '@stdlib/console/log' );
*
* log({
* 'foo': true
* });
*
* log([
* 1,
* 2,
* 3
* ]);
*
* log([{
* 'bar': true
* }]);
*/
rules[ 'stdlib/line-closing-bracket-spacing' ] = 'error';

/**
* Enforce that export statements are placed at the end of a file.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,10 @@ function main( context ) {
) {
prevToken = source.getTokenBefore( args[ 0 ] );
tokenAfter = source.getFirstToken( args[ 0 ] );
if ( source.isSpaceBetween( prevToken, tokenAfter ) ) {
if (
prevToken.loc.end.line === tokenAfter.loc.end.line &&
source.isSpaceBetween( prevToken, tokenAfter )
) {
report( node, prevToken, tokenAfter );
}
} else if ( args[ 0 ].type === 'ArrayExpression' ) {
Expand All @@ -102,7 +105,10 @@ function main( context ) {
) {
prevToken = source.getTokenBefore( args[ 0 ] );
tokenAfter = source.getFirstToken( args[ 0 ] );
if ( source.isSpaceBetween( prevToken, tokenAfter ) ) {
if (
prevToken.loc.end.line === tokenAfter.loc.end.line &&
source.isSpaceBetween( prevToken, tokenAfter )
) {
report( node, prevToken, tokenAfter );
}
} else {
Expand All @@ -111,6 +117,7 @@ function main( context ) {
nextToken = source.getTokenAfter( tokenAfter );
if (
tokenAfter.loc.end.line !== nextToken.loc.end.line &&
prevToken.loc.end.line === tokenAfter.loc.end.line &&
source.isSpaceBetween( prevToken, tokenAfter )
) {
report( node, prevToken, tokenAfter );
Expand All @@ -131,7 +138,10 @@ function main( context ) {
prevToken = source.getFirstToken( node );
tokenAfter = source.getFirstToken( elem );

if ( source.isSpaceBetween( prevToken, tokenAfter ) ) {
if (
prevToken.loc.end.line === tokenAfter.loc.end.line &&
source.isSpaceBetween( prevToken, tokenAfter )
) {
report( node, prevToken, tokenAfter );
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,56 @@ test = {
};
valid.push( test);

test = {
'code': [
' var log = require( \'@stdlib/console/log\' );',
' log(',
' {',
' \'a\': 1',
' }',
' );'
].join( '\n' )
};
valid.push( test);

test = {
'code': [
' var log = require( \'@stdlib/console/log\' );',
' log(',
' [',
' 1,',
' 2',
' ]',
' );'
].join( '\n' )
};
valid.push( test);

test = {
'code': [
' var log = require( \'@stdlib/console/log\' );',
' log(',
' [',
' {',
' \'a\': 1',
' }',
' ]',
' );'
].join( '\n' )
};
valid.push( test);

test = {
'code': [
' var arr = [',
' {',
' \'a\': 1',
' }',
'];'
].join( '\n' )
};
valid.push( test);


// EXPORTS //

Expand Down
9 changes: 9 additions & 0 deletions lib/node_modules/@stdlib/_tools/eslint/rules/lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -765,6 +765,15 @@ setReadOnly( rules, 'jsdoc-typedef-typos', require( '@stdlib/_tools/eslint/rules
*/
setReadOnly( rules, 'jsdoc-unordered-list-marker-style', require( '@stdlib/_tools/eslint/rules/jsdoc-unordered-list-marker-style' ) );

/**
* @name line-closing-bracket-spacing
* @memberof rules
* @readonly
* @type {Function}
* @see {@link module:@stdlib/_tools/eslint/rules/line-closing-bracket-spacing}
*/
setReadOnly( rules, 'line-closing-bracket-spacing', require( '@stdlib/_tools/eslint/rules/line-closing-bracket-spacing' ) );

/**
* @name module-exports-last
* @memberof rules
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,163 @@
<!--
@license Apache-2.0
Copyright (c) 2024 The Stdlib Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->

# line-closing-bracket-spacing

> [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.
<section class="intro">

</section>

<!-- /.intro -->

<section class="usage">

## Usage

```javascript
var rule = require( '@stdlib/_tools/eslint/rules/line-closing-bracket-spacing' );
```

#### rule

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

**Bad**:

<!-- eslint-disable stdlib/line-closing-bracket-spacing -->

```javascript
var log = require( '@stdlib/console/log' );

log({
'foo': true
} );

log([
1,
2,
3
] );

log([{
'bar': true
} ] );
```

**Good**:

```javascript
var log = require( '@stdlib/console/log' );

log({
'foo': true
});

log([
1,
2,
3
]);

log([{
'bar': true
}]);
```

</section>

<!-- /.usage -->

<section class="examples">

## Examples

<!-- eslint no-undef: "error" -->

```javascript
var Linter = require( 'eslint' ).Linter;
var rule = require( '@stdlib/_tools/eslint/rules/line-closing-bracket-spacing' );

var linter = new Linter();

var code = [
'function test() {',
' var log = require( \'@stdlib/console/log\' );',
' log({',
' "key": "value"',
' } );',
' var arr = [{',
' "nested": true',
' } ];',
' log( arr );',
'}'
].join( '\n' );

linter.defineRule( 'line-closing-bracket-spacing', rule );

var result = linter.verify( code, {
'rules': {
'line-closing-bracket-spacing': 'error'
}
});
/* returns
[
{
'ruleId': 'line-closing-bracket-spacing',
'severity': 2,
'message': 'No spaces allowed between a closing parenthesis or bracket and a nested object or array expression at the beginning of a line',
'line': 3,
'column': 3,
'nodeType': 'CallExpression'
},
{
'ruleId': 'line-closing-bracket-spacing',
'severity': 2,
'message': 'No spaces allowed between a closing parenthesis or bracket and a nested object or array expression at the beginning of a line',
'line': 6,
'column': 13,
'nodeType': 'ArrayExpression'
}
]
*/
```

</section>

<!-- /.examples -->

<!-- Section for related `stdlib` packages. Do not manually edit this section, as it is automatically populated. -->

<section class="related">

</section>

<!-- /.related -->

<!-- Section for all links. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->

<section class="links">

[eslint-rules]: https://eslint.org/docs/developer-guide/working-with-rules

</section>

<!-- /.links -->
Loading

0 comments on commit e9f48a5

Please sign in to comment.