From 6b7867c0a321c776106230b56bddc2f1e213cd1a Mon Sep 17 00:00:00 2001 From: Athan Reines Date: Thu, 26 Dec 2024 14:27:44 -0800 Subject: [PATCH 1/4] chore: auto-label changes to internal project tools --- 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: na - task: lint_package_json status: na - task: lint_repl_help status: na - task: lint_javascript_src status: na - task: lint_javascript_cli status: na - task: lint_javascript_examples status: na - task: lint_javascript_tests status: na - 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 --- --- .github/labeler.yml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.github/labeler.yml b/.github/labeler.yml index 01711a0fb732..2994baf6234e 100644 --- a/.github/labeler.yml +++ b/.github/labeler.yml @@ -35,3 +35,7 @@ REPL: Statistics: - changed-files: - any-glob-to-all-files: '**/stats/**/*' + +Tools: +- changed-files: + - any-glob-to-all-files: '**/_tools/**/*' From 9d632d504e6c75c4955710c05ce1a7cad722c3dc Mon Sep 17 00:00:00 2001 From: Muhammad Haris <101793258+headlessNode@users.noreply.github.com> Date: Sat, 28 Dec 2024 13:49:35 +0500 Subject: [PATCH 2/4] feat: add `_tools/eslint/rules/line-closing-bracket-spacing` PR-URL: https://github.com/stdlib-js/stdlib/pull/4211 Private-ref: https://github.com/stdlib-js/todo/issues/2325 Reviewed-by: Athan Reines --- etc/eslint/rules/stdlib.js | 48 +++- .../@stdlib/_tools/eslint/rules/lib/index.js | 9 + .../line-closing-bracket-spacing/README.md | 163 +++++++++++++ .../examples/index.js | 66 +++++ .../line-closing-bracket-spacing/lib/index.js | 39 +++ .../line-closing-bracket-spacing/lib/main.js | 175 +++++++++++++ .../line-closing-bracket-spacing/package.json | 63 +++++ .../test/fixtures/invalid.js | 230 ++++++++++++++++++ .../test/fixtures/unvalidated.js | 106 ++++++++ .../test/fixtures/valid.js | 97 ++++++++ .../line-closing-bracket-spacing/test/test.js | 86 +++++++ 11 files changed, 1081 insertions(+), 1 deletion(-) create mode 100644 lib/node_modules/@stdlib/_tools/eslint/rules/line-closing-bracket-spacing/README.md create mode 100644 lib/node_modules/@stdlib/_tools/eslint/rules/line-closing-bracket-spacing/examples/index.js create mode 100644 lib/node_modules/@stdlib/_tools/eslint/rules/line-closing-bracket-spacing/lib/index.js create mode 100644 lib/node_modules/@stdlib/_tools/eslint/rules/line-closing-bracket-spacing/lib/main.js create mode 100644 lib/node_modules/@stdlib/_tools/eslint/rules/line-closing-bracket-spacing/package.json create mode 100644 lib/node_modules/@stdlib/_tools/eslint/rules/line-closing-bracket-spacing/test/fixtures/invalid.js create mode 100644 lib/node_modules/@stdlib/_tools/eslint/rules/line-closing-bracket-spacing/test/fixtures/unvalidated.js create mode 100644 lib/node_modules/@stdlib/_tools/eslint/rules/line-closing-bracket-spacing/test/fixtures/valid.js create mode 100644 lib/node_modules/@stdlib/_tools/eslint/rules/line-closing-bracket-spacing/test/test.js diff --git a/etc/eslint/rules/stdlib.js b/etc/eslint/rules/stdlib.js index 0de07ac30f90..09d3f9d7e717 100644 --- a/etc/eslint/rules/stdlib.js +++ b/etc/eslint/rules/stdlib.js @@ -69,7 +69,7 @@ rules[ 'stdlib/capitalized-comments' ] = [ 'warn', { 'stdlib', 'throws' ] -} ]; +}]; /** * Enforce that return annotation values match actual output. @@ -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. * 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 221f82484546..8b029f004377 100644 --- a/lib/node_modules/@stdlib/_tools/eslint/rules/lib/index.js +++ b/lib/node_modules/@stdlib/_tools/eslint/rules/lib/index.js @@ -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 diff --git a/lib/node_modules/@stdlib/_tools/eslint/rules/line-closing-bracket-spacing/README.md b/lib/node_modules/@stdlib/_tools/eslint/rules/line-closing-bracket-spacing/README.md new file mode 100644 index 000000000000..3eb00ea1186f --- /dev/null +++ b/lib/node_modules/@stdlib/_tools/eslint/rules/line-closing-bracket-spacing/README.md @@ -0,0 +1,163 @@ + + +# 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. + +
+ +
+ + + +
+ +## 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**: + + + +```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/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' + } + ] +*/ +``` + +
+ + + + + + + + + + + + + + diff --git a/lib/node_modules/@stdlib/_tools/eslint/rules/line-closing-bracket-spacing/examples/index.js b/lib/node_modules/@stdlib/_tools/eslint/rules/line-closing-bracket-spacing/examples/index.js new file mode 100644 index 000000000000..bcf3c22419df --- /dev/null +++ b/lib/node_modules/@stdlib/_tools/eslint/rules/line-closing-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( 'line-closing-bracket-spacing', rule ); + +var result = linter.verify( code, { + 'rules': { + 'line-closing-bracket-spacing': 'error' + } +}); +console.log( result ); +/* => + [ + { + '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' + } + ] +*/ diff --git a/lib/node_modules/@stdlib/_tools/eslint/rules/line-closing-bracket-spacing/lib/index.js b/lib/node_modules/@stdlib/_tools/eslint/rules/line-closing-bracket-spacing/lib/index.js new file mode 100644 index 000000000000..73a632bf9f55 --- /dev/null +++ b/lib/node_modules/@stdlib/_tools/eslint/rules/line-closing-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 a closing parenthesis or bracket and a nested object or array expression at the beginning of a line. +* +* @module @stdlib/_tools/eslint/rules/line-closing-bracket-spacing +* +* @example +* var rule = require( '@stdlib/_tools/eslint/rules/line-closing-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/line-closing-bracket-spacing/lib/main.js b/lib/node_modules/@stdlib/_tools/eslint/rules/line-closing-bracket-spacing/lib/main.js new file mode 100644 index 000000000000..e5124581c845 --- /dev/null +++ b/lib/node_modules/@stdlib/_tools/eslint/rules/line-closing-bracket-spacing/lib/main.js @@ -0,0 +1,175 @@ +/** +* @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 a closing parenthesis or bracket and a nested object or array expression at the beginning 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} tokenBefore - token before the space + * @param {Object} lastToken - token after the space + */ + function report( node, tokenBefore, lastToken ) { + context.report({ + 'node': node, + 'message': 'No spaces allowed between a closing parenthesis or bracket and a nested object or array expression at the beginning of a line', + 'fix': fix + }); + + /** + * Fixes lint the error by removing the space after the object or array expression. + * + * @private + * @param {Object} fixer - ESLint fixer + * @returns {Object} fix + */ + function fix( fixer ) { + var afterIdx; + var prevIdx; + + prevIdx = source.getIndexFromLoc( tokenBefore.loc.end ); + afterIdx = source.getIndexFromLoc( lastToken.loc.start ); + return fixer.replaceTextRange( [ prevIdx, afterIdx ], '' ); + } + } + + /** + * Checks whether there are spaces present between a closing parenthesis or bracket and a nested object or array expression at the beginning of a line. + * + * @private + * @param {ASTNode} node - node to examine + */ + function validate( node ) { + var tokenBefore; + var tokenAfter; + var prevToken; + var lastElem; + var elem; + var args; + + if ( + node.type === 'CallExpression' && + node.arguments.length > 0 + ) { + args = node.arguments; + lastElem = args[ args.length - 1 ]; + if ( + lastElem.type === 'ObjectExpression' && + lastElem.properties.length > 0 + ) { + prevToken = source.getLastToken( lastElem ); + tokenAfter = source.getTokenAfter( prevToken ); + if ( + prevToken.loc.end.line === tokenAfter.loc.end.line && + source.isSpaceBetween( prevToken, tokenAfter ) + ) { + report( node, prevToken, tokenAfter ); + } + } else if ( lastElem.type === 'ArrayExpression' ) { + elem = lastElem.elements[ lastElem.elements.length - 1 ]; + if ( + elem.type === 'ObjectExpression' && + elem.properties.length > 0 + ) { + prevToken = source.getLastToken( lastElem ); + tokenAfter = source.getTokenAfter( prevToken ); + if ( + prevToken.loc.end.line === tokenAfter.loc.end.line && + source.isSpaceBetween( prevToken, tokenAfter ) + ) { + report( node, prevToken, tokenAfter ); + } + } else { + prevToken = source.getLastToken( lastElem ); + tokenBefore = source.getTokenBefore( prevToken ); + tokenAfter = source.getTokenAfter( prevToken ); + if ( + tokenBefore.loc.end.line !== prevToken.loc.end.line && + prevToken.loc.end.line === tokenAfter.loc.end.line && + source.isSpaceBetween( prevToken, tokenAfter ) + ) { + report( node, prevToken, tokenAfter ); + } + } + } + } + + if ( + node.type === 'ArrayExpression' && + node.elements.length > 0 + ) { + elem = node.elements[ node.elements.length - 1 ]; + if ( + elem.type === 'ObjectExpression' && + elem.properties.length > 0 + ) { + prevToken = source.getLastToken( elem ); + tokenAfter = source.getTokenAfter( prevToken ); + if ( + prevToken.loc.end.line === tokenAfter.loc.end.line && + source.isSpaceBetween( prevToken, tokenAfter ) + ) { + report( node, prevToken, tokenAfter ); + } + } + } + } + return { + 'CallExpression': validate, + 'ArrayExpression': validate + }; +} + + +// MAIN // + +rule = { + 'meta': { + 'type': 'layout', + 'docs': { + 'description': 'disallow spaces between a closing parenthesis or bracket and a nested object or array expression at the beginning of a line' + }, + 'schema': [], + 'fixable': 'whitespace' + }, + 'create': main +}; + + +// EXPORTS // + +module.exports = rule; diff --git a/lib/node_modules/@stdlib/_tools/eslint/rules/line-closing-bracket-spacing/package.json b/lib/node_modules/@stdlib/_tools/eslint/rules/line-closing-bracket-spacing/package.json new file mode 100644 index 000000000000..95deaaa40c21 --- /dev/null +++ b/lib/node_modules/@stdlib/_tools/eslint/rules/line-closing-bracket-spacing/package.json @@ -0,0 +1,63 @@ +{ + "name": "@stdlib/_tools/eslint/rules/line-closing-bracket-spacing", + "version": "0.0.0", + "description": "ESLint rule 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.", + "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/line-closing-bracket-spacing/test/fixtures/invalid.js b/lib/node_modules/@stdlib/_tools/eslint/rules/line-closing-bracket-spacing/test/fixtures/invalid.js new file mode 100644 index 000000000000..2675a13bd9a1 --- /dev/null +++ b/lib/node_modules/@stdlib/_tools/eslint/rules/line-closing-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 a closing parenthesis or bracket and a nested object or array expression at the beginning 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 a closing parenthesis or bracket and a nested object or array expression at the beginning 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 a closing parenthesis or bracket and a nested object or array expression at the beginning 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 a closing parenthesis or bracket and a nested object or array expression at the beginning 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 a closing parenthesis or bracket and a nested object or array expression at the beginning of a line', + 'type': null + }, { + 'message': 'No spaces allowed between a closing parenthesis or bracket and a nested object or array expression at the beginning 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 a closing parenthesis or bracket and a nested object or array expression at the beginning 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 a closing parenthesis or bracket and a nested object or array expression at the beginning 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/line-closing-bracket-spacing/test/fixtures/unvalidated.js b/lib/node_modules/@stdlib/_tools/eslint/rules/line-closing-bracket-spacing/test/fixtures/unvalidated.js new file mode 100644 index 000000000000..1661199904a5 --- /dev/null +++ b/lib/node_modules/@stdlib/_tools/eslint/rules/line-closing-bracket-spacing/test/fixtures/unvalidated.js @@ -0,0 +1,106 @@ +/** +* @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); + +test = { + 'code': [ + ' var log = require( \'@stdlib/console/log\' );', + ' log( {} );' + ].join( '\n' ) +}; +valid.push( test); + +test = { + 'code': [ + 'var arr = [ 1, 2, 3, 4, {} ];' + ].join( '\n' ) +}; +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 // + +module.exports = valid; diff --git a/lib/node_modules/@stdlib/_tools/eslint/rules/line-closing-bracket-spacing/test/fixtures/valid.js b/lib/node_modules/@stdlib/_tools/eslint/rules/line-closing-bracket-spacing/test/fixtures/valid.js new file mode 100644 index 000000000000..761141fd2b28 --- /dev/null +++ b/lib/node_modules/@stdlib/_tools/eslint/rules/line-closing-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/line-closing-bracket-spacing/test/test.js b/lib/node_modules/@stdlib/_tools/eslint/rules/line-closing-bracket-spacing/test/test.js new file mode 100644 index 000000000000..8211342fc34f --- /dev/null +++ b/lib/node_modules/@stdlib/_tools/eslint/rules/line-closing-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 a closing parenthesis or bracket and a nested object or array expression at the beginning of a line', function test( t ) { + var tester = new RuleTester(); + + try { + tester.run( 'line-closing-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 a closing parenthesis or bracket and a nested object or array expression at the beginning of a line', function test( t ) { + var tester = new RuleTester(); + + try { + tester.run( 'line-closing-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( 'line-closing-bracket-spacing', rule, { + 'valid': unvalidated, + 'invalid': [] + }); + t.pass( 'passed without errors' ); + } catch ( err ) { + t.fail( 'encountered an error: ' + err.message ); + } + t.end(); +}); From 5b3077158633c10b757ffc27c7f5de092b6b426f Mon Sep 17 00:00:00 2001 From: Muhammad Haris <101793258+headlessNode@users.noreply.github.com> Date: Sat, 28 Dec 2024 13:52:43 +0500 Subject: [PATCH 3/4] fix: handle edge cases in `_tools/eslint/rules/eol-open-bracket-spacing` (#4310) PR-URL: https://github.com/stdlib-js/stdlib/pull/4310 Reviewed-by: Athan Reines --- .../eol-open-bracket-spacing/lib/main.js | 16 ++++-- .../test/fixtures/unvalidated.js | 50 +++++++++++++++++++ 2 files changed, 63 insertions(+), 3 deletions(-) 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 index 8cd70482498e..0655164d9324 100644 --- 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 @@ -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' ) { @@ -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 { @@ -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 ); @@ -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 ); } } 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 index e99ae557b430..d6b9c4fa4ac8 100644 --- 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 @@ -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 // From 0734a5f0e09c2619f4bd38e299e16970fa88f0c3 Mon Sep 17 00:00:00 2001 From: Athan Reines Date: Sat, 28 Dec 2024 01:15:13 -0800 Subject: [PATCH 4/4] fix: address off-by-one index bug --- 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: na - task: lint_package_json status: na - 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: na - 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: na - 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 --- --- .../examples/fixtures/math_markup.txt | 22 ++++++++++ .../examples/math_markup.js | 42 +++++++++++++++++++ .../remark-svg-equations/lib/transformer.js | 2 +- 3 files changed, 65 insertions(+), 1 deletion(-) create mode 100644 lib/node_modules/@stdlib/_tools/remark/plugins/remark-svg-equations/examples/fixtures/math_markup.txt create mode 100644 lib/node_modules/@stdlib/_tools/remark/plugins/remark-svg-equations/examples/math_markup.js diff --git a/lib/node_modules/@stdlib/_tools/remark/plugins/remark-svg-equations/examples/fixtures/math_markup.txt b/lib/node_modules/@stdlib/_tools/remark/plugins/remark-svg-equations/examples/fixtures/math_markup.txt new file mode 100644 index 000000000000..e635e534455b --- /dev/null +++ b/lib/node_modules/@stdlib/_tools/remark/plugins/remark-svg-equations/examples/fixtures/math_markup.txt @@ -0,0 +1,22 @@ +# Absolute Value + +
+ +The absolute value is defined as + + + +```math +|x| = \begin{cases} x & \textrm{if}\ x \geq 0 \\ -x & \textrm{if}\ x < 0\end{cases} +``` + + + + + +
+ + diff --git a/lib/node_modules/@stdlib/_tools/remark/plugins/remark-svg-equations/examples/math_markup.js b/lib/node_modules/@stdlib/_tools/remark/plugins/remark-svg-equations/examples/math_markup.js new file mode 100644 index 000000000000..137d2aeda7bc --- /dev/null +++ b/lib/node_modules/@stdlib/_tools/remark/plugins/remark-svg-equations/examples/math_markup.js @@ -0,0 +1,42 @@ +/** +* @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 readFileSync = require( 'fs' ).readFileSync; +var join = require( 'path' ).join; +var remark = require( 'remark' ); +var insertEquations = require( './../lib' ); + +// Load a Markdown file... +var fpath = join( __dirname, 'fixtures/math_markup.txt' ); +var opts = { + 'encoding': 'utf8' +}; +var file = readFileSync( fpath, opts ); + +// Insert equations: +remark().use( insertEquations ).process( file, done ); + +function done( error, out ) { + if ( error ) { + throw error; + } + // Output the processed Markdown file: + console.log( out.contents ); +} diff --git a/lib/node_modules/@stdlib/_tools/remark/plugins/remark-svg-equations/lib/transformer.js b/lib/node_modules/@stdlib/_tools/remark/plugins/remark-svg-equations/lib/transformer.js index a6c369363f04..a59854994fef 100644 --- a/lib/node_modules/@stdlib/_tools/remark/plugins/remark-svg-equations/lib/transformer.js +++ b/lib/node_modules/@stdlib/_tools/remark/plugins/remark-svg-equations/lib/transformer.js @@ -203,7 +203,7 @@ function transformer( tree, file, clbk ) { // Note: we don't splice--we simply replace--in order to avoid invalidating the indices of the equation elements in the AST. If we were to remove children, a subsequent resolved equation index would no longer be accurate... parent.children[ i+1 ] = newNode; - parent.children[ i+1 ] = { + parent.children[ i+2 ] = { 'type': 'html', 'value': '' };