Skip to content

Commit

Permalink
feat: add eslint/rules/eol-open-bracket-spacing
Browse files Browse the repository at this point in the history
PR-URL: stdlib-js#4061
Private-ref: https://github.com/stdlib-js/todo/issues/2324
Reviewed-by: Athan Reines <kgryte@gmail.com>

---
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: passed
  - task: run_cpp_examples
    status: na
  - task: run_javascript_readme_examples
    status: failed
---
  • Loading branch information
headlessNode authored and Vinit-Pandit committed Dec 23, 2024
1 parent acb12c7 commit a766b97
Show file tree
Hide file tree
Showing 11 changed files with 996 additions and 0 deletions.
46 changes: 46 additions & 0 deletions etc/eslint/rules/stdlib.js
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,52 @@ rules[ 'stdlib/doctest-quote-props' ] = 'error';
*/
rules[ 'stdlib/empty-line-before-comment' ] = 'error';

/**
* Disallow spaces between an opening parenthesis or bracket and a nested object or array expression at the end of a line.
*
* @name eol-open-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/eol-open-bracket-spacing' ] = 'error';

/**
* Require blockquotes to have `2` character indentation.
*
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.
-->

# eol-open-bracket-spacing

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

</section>

<!-- /.intro -->

<section class="usage">

## Usage

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

#### rule

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

**Bad**:

<!-- eslint-disable stdlib/eol-open-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/eol-open-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( 'eol-open-bracket-spacing', rule );

var result = linter.verify( code, {
'rules': {
'eol-open-bracket-spacing': 'error'
}
});
/* returns
[
{
'ruleId': 'eol-open-bracket-spacing',
'severity': 2,
'message': 'No spaces allowed between an opening parenthesis or bracket and a nested object or array expression at the end of a line',
'line': 3,
'column': 3,
'nodeType': 'CallExpression'
},
{
'ruleId': 'eol-open-bracket-spacing',
'severity': 2,
'message': 'No spaces allowed between an opening parenthesis or bracket and a nested object or array expression at the end 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 -->
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
/**
* @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.
*/

'use strict';

var Linter = require( 'eslint' ).Linter;
var rule = require( './../lib' );

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( 'eol-open-bracket-spacing', rule );

var result = linter.verify( code, {
'rules': {
'eol-open-bracket-spacing': 'error'
}
});
console.log( result );
/* =>
[
{
'ruleId': 'eol-open-bracket-spacing',
'severity': 2,
'message': 'No spaces allowed between an opening parenthesis or bracket and a nested object or array expression at the end of a line',
'line': 3,
'column': 3,
'nodeType': 'CallExpression'
},
{
'ruleId': 'eol-open-bracket-spacing',
'severity': 2,
'message': 'No spaces allowed between an opening parenthesis or bracket and a nested object or array expression at the end of a line',
'line': 6,
'column': 13,
'nodeType': 'ArrayExpression'
}
]
*/
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/**
* @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.
*/

'use strict';

/**
* 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.
*
* @module @stdlib/_tools/eslint/rules/eol-open-bracket-spacing
*
* @example
* var rule = require( '@stdlib/_tools/eslint/rules/eol-open-bracket-spacing' );
*
* console.log( rule );
*/

// MODULES //

var main = require( './main.js' );


// EXPORTS //

module.exports = main;
Loading

0 comments on commit a766b97

Please sign in to comment.