diff --git a/etc/eslint/rules/stdlib.js b/etc/eslint/rules/stdlib.js index 5304d3895a5c..0de07ac30f90 100644 --- a/etc/eslint/rules/stdlib.js +++ b/etc/eslint/rules/stdlib.js @@ -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. * diff --git a/lib/node_modules/@stdlib/_tools/eslint/rules/eol-open-bracket-spacing/README.md b/lib/node_modules/@stdlib/_tools/eslint/rules/eol-open-bracket-spacing/README.md new file mode 100644 index 000000000000..721f820dae72 --- /dev/null +++ b/lib/node_modules/@stdlib/_tools/eslint/rules/eol-open-bracket-spacing/README.md @@ -0,0 +1,163 @@ + + +# 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. + +
+ +
+ + + +
+ +## 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**: + + + +```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 +}]); +``` + +
+ + + +
+ +## Examples + + + +```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' + } + ] +*/ +``` + +
+ + + + + + + + + + + + + + diff --git a/lib/node_modules/@stdlib/_tools/eslint/rules/eol-open-bracket-spacing/examples/index.js b/lib/node_modules/@stdlib/_tools/eslint/rules/eol-open-bracket-spacing/examples/index.js new file mode 100644 index 000000000000..9645f73f936d --- /dev/null +++ b/lib/node_modules/@stdlib/_tools/eslint/rules/eol-open-bracket-spacing/examples/index.js @@ -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' + } + ] +*/ diff --git a/lib/node_modules/@stdlib/_tools/eslint/rules/eol-open-bracket-spacing/lib/index.js b/lib/node_modules/@stdlib/_tools/eslint/rules/eol-open-bracket-spacing/lib/index.js new file mode 100644 index 000000000000..2353d04e43c6 --- /dev/null +++ b/lib/node_modules/@stdlib/_tools/eslint/rules/eol-open-bracket-spacing/lib/index.js @@ -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; diff --git a/lib/node_modules/@stdlib/_tools/eslint/rules/eol-open-bracket-spacing/lib/main.js b/lib/node_modules/@stdlib/_tools/eslint/rules/eol-open-bracket-spacing/lib/main.js new file mode 100644 index 000000000000..59474cccfef8 --- /dev/null +++ b/lib/node_modules/@stdlib/_tools/eslint/rules/eol-open-bracket-spacing/lib/main.js @@ -0,0 +1,156 @@ +/** +* @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'; + +// VARIABLES // + +var rule; + + +// FUNCTIONS // + +/** +* Rule for validating that no spaces are present between an opening parenthesis or bracket and a nested object or array expression at the end of a line. +* +* @private +* @param {Object} context - ESLint context +* @returns {Object} validators +*/ +function main( context ) { + var source = context.getSourceCode(); + + /** + * Reports the error message. + * + * @private + * @param {ASTNode} node - node to report + * @param {Object} prevToken - token before the space + * @param {Object} tokenAfter - token after the space + */ + function report( node, prevToken, tokenAfter ) { + context.report({ + 'node': node, + 'message': 'No spaces allowed between an opening parenthesis or bracket and a nested object or array expression at the end of a line', + 'fix': fix + }); + + /** + * Fixes lint the error by removing the space before the object or array expression. + * + * @private + * @param {Object} fixer - ESLint fixer + * @returns {Object} fix + */ + function fix( fixer ) { + var afterIdx; + var prevIdx; + + prevIdx = source.getIndexFromLoc( prevToken.loc.end ); + afterIdx = source.getIndexFromLoc( tokenAfter.loc.start ); + return fixer.replaceTextRange( [ prevIdx, afterIdx ], '' ); + } + } + + /** + * Checks whether there are spaces present between an opening parenthesis or bracket and a nested object or array expression at the end of a line. + * + * @private + * @param {ASTNode} node - node to examine + */ + function validate( node ) { + var tokenAfter; + var nextToken; + var prevToken; + var elem; + var args; + + if ( + node.type === 'CallExpression' && + node.arguments.length > 0 + ) { + args = node.arguments; + if ( args[ 0 ].type === 'ObjectExpression' ) { + prevToken = source.getTokenBefore( args[ 0 ] ); + tokenAfter = source.getFirstToken( args[ 0 ] ); + if ( source.isSpaceBetween( prevToken, tokenAfter ) ) { + report( node, prevToken, tokenAfter ); + } + } else if ( args[ 0 ].type === 'ArrayExpression' ) { + elem = args[ 0 ].elements[ 0 ]; + if ( elem.type === 'ObjectExpression' ) { + prevToken = source.getTokenBefore( args[ 0 ] ); + tokenAfter = source.getFirstToken( args[ 0 ] ); + if ( source.isSpaceBetween( prevToken, tokenAfter ) ) { + report( node, prevToken, tokenAfter ); + } + } else { + prevToken = source.getTokenBefore( args[ 0 ] ); + tokenAfter = source.getFirstToken( args[ 0 ] ); + nextToken = source.getTokenAfter( tokenAfter ); + if ( + tokenAfter.loc.end.line !== nextToken.loc.end.line && + source.isSpaceBetween( prevToken, tokenAfter ) + ) { + report( node, prevToken, tokenAfter ); + } + } + } + } + + if ( + node.type === 'ArrayExpression' && + node.elements.length > 0 + ) { + elem = node.elements[ 0 ]; + if ( elem.type === 'ObjectExpression' ) { + prevToken = source.getFirstToken( node ); + tokenAfter = source.getFirstToken( elem ); + + if ( source.isSpaceBetween( prevToken, tokenAfter ) ) { + report( node, prevToken, tokenAfter ); + } + } + } + } + + return { + 'CallExpression': validate, + 'ArrayExpression': validate + }; +} + + +// MAIN // + +rule = { + 'meta': { + 'type': 'layout', + 'docs': { + 'description': 'disallow spaces between an opening parenthesis or bracket and a nested object or array expression at the end of a line' + }, + 'schema': [], + 'fixable': 'whitespace' + }, + 'create': main +}; + + +// EXPORTS // + +module.exports = rule; diff --git a/lib/node_modules/@stdlib/_tools/eslint/rules/eol-open-bracket-spacing/package.json b/lib/node_modules/@stdlib/_tools/eslint/rules/eol-open-bracket-spacing/package.json new file mode 100644 index 000000000000..4773e06bbbbd --- /dev/null +++ b/lib/node_modules/@stdlib/_tools/eslint/rules/eol-open-bracket-spacing/package.json @@ -0,0 +1,63 @@ +{ + "name": "@stdlib/_tools/eslint/rules/eol-open-bracket-spacing", + "version": "0.0.0", + "description": "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.", + "license": "Apache-2.0", + "author": { + "name": "The Stdlib Authors", + "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" + }, + "contributors": [ + { + "name": "The Stdlib Authors", + "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" + } + ], + "bin": {}, + "main": "./lib", + "directories": { + "example": "./examples", + "lib": "./lib", + "test": "./test" + }, + "scripts": {}, + "homepage": "https://github.com/stdlib-js/stdlib", + "repository": { + "type": "git", + "url": "git://github.com/stdlib-js/stdlib.git" + }, + "bugs": { + "url": "https://github.com/stdlib-js/stdlib/issues" + }, + "dependencies": {}, + "devDependencies": {}, + "engines": { + "node": ">=0.10.0", + "npm": ">2.7.0" + }, + "os": [ + "aix", + "darwin", + "freebsd", + "linux", + "macos", + "openbsd", + "sunos", + "win32", + "windows" + ], + "keywords": [ + "stdlib", + "tools", + "tool", + "eslint", + "lint", + "custom", + "rules", + "rule", + "array", + "object", + "plugin", + "whitespace" + ] +} diff --git a/lib/node_modules/@stdlib/_tools/eslint/rules/eol-open-bracket-spacing/test/fixtures/invalid.js b/lib/node_modules/@stdlib/_tools/eslint/rules/eol-open-bracket-spacing/test/fixtures/invalid.js new file mode 100644 index 000000000000..30fe652a99aa --- /dev/null +++ b/lib/node_modules/@stdlib/_tools/eslint/rules/eol-open-bracket-spacing/test/fixtures/invalid.js @@ -0,0 +1,230 @@ +/** +* @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 valid = []; +var test; + +test = { + 'code': [ + 'var arr = [ {', + ' key1: "value1",', + ' key2: "value2"', + '}];' + ].join( '\n' ), + 'errors': [{ + 'message': 'No spaces allowed between an opening parenthesis or bracket and a nested object or array expression at the end of a line', + 'type': null + }], + 'output': [ + 'var arr = [{', + ' key1: "value1",', + ' key2: "value2"', + '}];' + ].join( '\n' ) +}; +valid.push( test ); + +test = { + 'code': [ + 'function sum( x ) {', + ' var sum = 0;', + ' for ( var i = 0; i < x.length; i++ ) {', + ' sum += x[ i ];', + ' }', + ' return sum;', + '}', + 'var arrSum = sum( [', + ' 1,', + ' 2,', + ' 3,', + ' 4', + ']);' + ].join( '\n' ), + 'errors': [{ + 'message': 'No spaces allowed between an opening parenthesis or bracket and a nested object or array expression at the end of a line', + 'type': null + }], + 'output': [ + 'function sum( x ) {', + ' var sum = 0;', + ' for ( var i = 0; i < x.length; i++ ) {', + ' sum += x[ i ];', + ' }', + ' return sum;', + '}', + 'var arrSum = sum([', + ' 1,', + ' 2,', + ' 3,', + ' 4', + ']);' + ].join( '\n' ) +}; +valid.push( test ); + +test = { + 'code': [ + 'function log( x ) {', + ' for ( var i = 0; i < x.length; i++ ) {', + ' console.log( x[ i ] );', + ' }', + '}', + 'log( [{', + ' a: 1,', + ' b: 2', + '}]);' + ].join( '\n' ), + 'errors': [{ + 'message': 'No spaces allowed between an opening parenthesis or bracket and a nested object or array expression at the end of a line', + 'type': null + }], + 'output': [ + 'function log( x ) {', + ' for ( var i = 0; i < x.length; i++ ) {', + ' console.log( x[ i ] );', + ' }', + '}', + 'log([{', + ' a: 1,', + ' b: 2', + '}]);' + ].join( '\n' ) +}; +valid.push( test); + +test = { + 'code': [ + 'function log( x ) {', + ' for ( var i = 0; i < x.length; i++ ) {', + ' console.log( x[ i ] );', + ' }', + '}', + 'log([ {', + ' a: 1,', + ' b: 2', + '}]);' + ].join( '\n' ), + 'errors': [{ + 'message': 'No spaces allowed between an opening parenthesis or bracket and a nested object or array expression at the end of a line', + 'type': null + }], + 'output': [ + 'function log( x ) {', + ' for ( var i = 0; i < x.length; i++ ) {', + ' console.log( x[ i ] );', + ' }', + '}', + 'log([{', + ' a: 1,', + ' b: 2', + '}]);' + ].join( '\n' ) +}; +valid.push( test); + +test = { + 'code': [ + 'function log( x ) {', + ' for ( var i = 0; i < x.length; i++ ) {', + ' console.log( x[ i ] );', + ' }', + '}', + 'log( [ {', + ' a: 1,', + ' b: 2', + '}]);' + ].join( '\n' ), + 'errors': [{ + 'message': 'No spaces allowed between an opening parenthesis or bracket and a nested object or array expression at the end of a line', + 'type': null + }, { + 'message': 'No spaces allowed between an opening parenthesis or bracket and a nested object or array expression at the end of a line', + 'type': null + }], + 'output': [ + 'function log( x ) {', + ' for ( var i = 0; i < x.length; i++ ) {', + ' console.log( x[ i ] );', + ' }', + '}', + 'log([{', + ' a: 1,', + ' b: 2', + '}]);' + ].join( '\n' ) +}; +valid.push( test); + +test = { + 'code': [ + 'console.log( [', + ' Math.random(),', + ' Math.random()', + ']);', + '/* e.g., =>', + ' [', + ' 0.2580887012988746,', + ' 0.128454513229588', + ' ]', + '*/' + ].join( '\n' ), + 'errors': [{ + 'message': 'No spaces allowed between an opening parenthesis or bracket and a nested object or array expression at the end of a line', + 'type': null + }], + 'output': [ + 'console.log([', + ' Math.random(),', + ' Math.random()', + ']);', + '/* e.g., =>', + ' [', + ' 0.2580887012988746,', + ' 0.128454513229588', + ' ]', + '*/' + ].join( '\n' ) +}; +valid.push( test ); + +test = { + 'code': [ + 'console.log( {', + ' a: Math.random(),', + ' b: Math.random()', + '});' + ].join( '\n' ), + 'errors': [{ + 'message': 'No spaces allowed between an opening parenthesis or bracket and a nested object or array expression at the end of a line', + 'type': null + }], + 'output': [ + 'console.log({', + ' a: Math.random(),', + ' b: Math.random()', + '});' + ].join( '\n' ) +}; +valid.push( test ); + + +// EXPORTS // + +module.exports = valid; diff --git a/lib/node_modules/@stdlib/_tools/eslint/rules/eol-open-bracket-spacing/test/fixtures/unvalidated.js b/lib/node_modules/@stdlib/_tools/eslint/rules/eol-open-bracket-spacing/test/fixtures/unvalidated.js new file mode 100644 index 000000000000..c6c33b1faa84 --- /dev/null +++ b/lib/node_modules/@stdlib/_tools/eslint/rules/eol-open-bracket-spacing/test/fixtures/unvalidated.js @@ -0,0 +1,41 @@ +/** +* @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 valid = []; +var test; + +test = { + 'code': [ + 'function sum( x ) {', + ' var sum = 0;', + ' for ( var i = 0; i < x.length; i++ ) {', + ' sum += x[ i ];', + ' }', + ' return sum;', + '}', + 'var arrSum = sum( [ 1, 2, 3, 4 ] );' + ].join( '\n' ) +}; +valid.push( test); + + +// EXPORTS // + +module.exports = valid; diff --git a/lib/node_modules/@stdlib/_tools/eslint/rules/eol-open-bracket-spacing/test/fixtures/valid.js b/lib/node_modules/@stdlib/_tools/eslint/rules/eol-open-bracket-spacing/test/fixtures/valid.js new file mode 100644 index 000000000000..761141fd2b28 --- /dev/null +++ b/lib/node_modules/@stdlib/_tools/eslint/rules/eol-open-bracket-spacing/test/fixtures/valid.js @@ -0,0 +1,97 @@ +/** +* @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 valid = []; +var test; + +test = { + 'code': [ + 'var arr = [{', + ' key1: "value1",', + ' key2: "value2"', + '}];' + ].join( '\n' ) +}; +valid.push( test ); + +test = { + 'code': [ + 'function sum( x ) {', + ' var sum = 0;', + ' for ( var i = 0; i < x.length; i++ ) {', + ' sum += x[ i ];', + ' }', + ' return sum;', + '}', + 'var arrSum = sum([', + ' 1,', + ' 2,', + ' 3,', + ' 4', + ']);' + ].join( '\n' ) +}; +valid.push( test); + +test = { + 'code': [ + 'function log( x ) {', + ' for ( var i = 0; i < x.length; i++ ) {', + ' console.log( x[ i ] );', + ' }', + '}', + 'log([{', + ' a: 1,', + ' b: 2', + '}]);' + ].join( '\n' ) +}; +valid.push( test); + +test = { + 'code': [ + 'console.log([', + ' Math.random(),', + ' Math.random()', + ']);', + '/* e.g., =>', + ' [', + ' 0.2580887012988746,', + ' 0.128454513229588', + ' ]', + '*/' + ].join( '\n' ) +}; +valid.push( test ); + +test = { + 'code': [ + 'console.log({', + ' a: Math.random(),', + ' b: Math.random()', + '});' + ].join( '\n' ) +}; +valid.push( test ); + + +// EXPORTS // + +module.exports = valid; diff --git a/lib/node_modules/@stdlib/_tools/eslint/rules/eol-open-bracket-spacing/test/test.js b/lib/node_modules/@stdlib/_tools/eslint/rules/eol-open-bracket-spacing/test/test.js new file mode 100644 index 000000000000..43153651efa8 --- /dev/null +++ b/lib/node_modules/@stdlib/_tools/eslint/rules/eol-open-bracket-spacing/test/test.js @@ -0,0 +1,86 @@ +/** +* @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'; + +// MODULES // + +var tape = require( 'tape' ); +var RuleTester = require( 'eslint' ).RuleTester; +var rule = require( './../lib' ); + + +// FIXTURES // + +var valid = require( './fixtures/valid.js' ); +var invalid = require( './fixtures/invalid.js' ); +var unvalidated = require( './fixtures/unvalidated.js' ); + + +// TESTS // + +tape( 'main export is an object', function test( t ) { + t.ok( true, __filename ); + t.equal( typeof rule, 'object', 'main export is an object' ); + t.end(); +}); + +tape( 'the function positively validates code where no spaces are present between an opening parenthesis or bracket and a nested object or array expression at the end of a line', function test( t ) { + var tester = new RuleTester(); + + try { + tester.run( 'eol-open-bracket-spacing', rule, { + 'valid': valid, + 'invalid': [] + }); + t.pass( 'passed without errors' ); + } catch ( err ) { + t.fail( 'encountered an error: ' + err.message ); + } + t.end(); +}); + +tape( 'the function negatively validates code where spaces are present between an opening parenthesis or bracket and a nested object or array expression at the end of a line', function test( t ) { + var tester = new RuleTester(); + + try { + tester.run( 'eol-open-bracket-spacing', rule, { + 'valid': [], + 'invalid': invalid + }); + t.pass( 'passed without errors' ); + } catch ( err ) { + t.fail( 'encountered an error: ' + err.message ); + } + t.end(); +}); + +tape( 'the function does not validate non-object or non-array or inline array expressions', function test( t ) { + var tester = new RuleTester(); + + try { + tester.run( 'eol-open-bracket-spacing', rule, { + 'valid': unvalidated, + 'invalid': [] + }); + t.pass( 'passed without errors' ); + } catch ( err ) { + t.fail( 'encountered an error: ' + err.message ); + } + t.end(); +}); diff --git a/lib/node_modules/@stdlib/_tools/eslint/rules/lib/index.js b/lib/node_modules/@stdlib/_tools/eslint/rules/lib/index.js index 3a8df9a27024..221f82484546 100644 --- a/lib/node_modules/@stdlib/_tools/eslint/rules/lib/index.js +++ b/lib/node_modules/@stdlib/_tools/eslint/rules/lib/index.js @@ -81,6 +81,15 @@ setReadOnly( rules, 'doctest-quote-props', require( '@stdlib/_tools/eslint/rules */ setReadOnly( rules, 'empty-line-before-comment', require( '@stdlib/_tools/eslint/rules/empty-line-before-comment' ) ); +/** +* @name eol-open-bracket-spacing +* @memberof rules +* @readonly +* @type {Function} +* @see {@link module:@stdlib/_tools/eslint/rules/eol-open-bracket-spacing} +*/ +setReadOnly( rules, 'eol-open-bracket-spacing', require( '@stdlib/_tools/eslint/rules/eol-open-bracket-spacing' ) ); + /** * @name first-unit-test * @memberof rules