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