Skip to content

Commit

Permalink
fix: handle edge cases in `_tools/eslint/rules/eol-open-bracket-spaci…
Browse files Browse the repository at this point in the history
…ng` (stdlib-js#4310)

PR-URL: stdlib-js#4310
Reviewed-by: Athan Reines <[email protected]>
  • Loading branch information
headlessNode authored Dec 28, 2024
1 parent 9d632d5 commit 5b30771
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 3 deletions.
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

0 comments on commit 5b30771

Please sign in to comment.