Skip to content

Commit 5b30771

Browse files
authored
fix: handle edge cases in _tools/eslint/rules/eol-open-bracket-spacing (#4310)
PR-URL: #4310 Reviewed-by: Athan Reines <kgryte@gmail.com>
1 parent 9d632d5 commit 5b30771

File tree

2 files changed

+63
-3
lines changed
  • lib/node_modules/@stdlib/_tools/eslint/rules/eol-open-bracket-spacing

2 files changed

+63
-3
lines changed

lib/node_modules/@stdlib/_tools/eslint/rules/eol-open-bracket-spacing/lib/main.js

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,10 @@ function main( context ) {
9191
) {
9292
prevToken = source.getTokenBefore( args[ 0 ] );
9393
tokenAfter = source.getFirstToken( args[ 0 ] );
94-
if ( source.isSpaceBetween( prevToken, tokenAfter ) ) {
94+
if (
95+
prevToken.loc.end.line === tokenAfter.loc.end.line &&
96+
source.isSpaceBetween( prevToken, tokenAfter )
97+
) {
9598
report( node, prevToken, tokenAfter );
9699
}
97100
} else if ( args[ 0 ].type === 'ArrayExpression' ) {
@@ -102,7 +105,10 @@ function main( context ) {
102105
) {
103106
prevToken = source.getTokenBefore( args[ 0 ] );
104107
tokenAfter = source.getFirstToken( args[ 0 ] );
105-
if ( source.isSpaceBetween( prevToken, tokenAfter ) ) {
108+
if (
109+
prevToken.loc.end.line === tokenAfter.loc.end.line &&
110+
source.isSpaceBetween( prevToken, tokenAfter )
111+
) {
106112
report( node, prevToken, tokenAfter );
107113
}
108114
} else {
@@ -111,6 +117,7 @@ function main( context ) {
111117
nextToken = source.getTokenAfter( tokenAfter );
112118
if (
113119
tokenAfter.loc.end.line !== nextToken.loc.end.line &&
120+
prevToken.loc.end.line === tokenAfter.loc.end.line &&
114121
source.isSpaceBetween( prevToken, tokenAfter )
115122
) {
116123
report( node, prevToken, tokenAfter );
@@ -131,7 +138,10 @@ function main( context ) {
131138
prevToken = source.getFirstToken( node );
132139
tokenAfter = source.getFirstToken( elem );
133140

134-
if ( source.isSpaceBetween( prevToken, tokenAfter ) ) {
141+
if (
142+
prevToken.loc.end.line === tokenAfter.loc.end.line &&
143+
source.isSpaceBetween( prevToken, tokenAfter )
144+
) {
135145
report( node, prevToken, tokenAfter );
136146
}
137147
}

lib/node_modules/@stdlib/_tools/eslint/rules/eol-open-bracket-spacing/test/fixtures/unvalidated.js

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,56 @@ test = {
5050
};
5151
valid.push( test);
5252

53+
test = {
54+
'code': [
55+
' var log = require( \'@stdlib/console/log\' );',
56+
' log(',
57+
' {',
58+
' \'a\': 1',
59+
' }',
60+
' );'
61+
].join( '\n' )
62+
};
63+
valid.push( test);
64+
65+
test = {
66+
'code': [
67+
' var log = require( \'@stdlib/console/log\' );',
68+
' log(',
69+
' [',
70+
' 1,',
71+
' 2',
72+
' ]',
73+
' );'
74+
].join( '\n' )
75+
};
76+
valid.push( test);
77+
78+
test = {
79+
'code': [
80+
' var log = require( \'@stdlib/console/log\' );',
81+
' log(',
82+
' [',
83+
' {',
84+
' \'a\': 1',
85+
' }',
86+
' ]',
87+
' );'
88+
].join( '\n' )
89+
};
90+
valid.push( test);
91+
92+
test = {
93+
'code': [
94+
' var arr = [',
95+
' {',
96+
' \'a\': 1',
97+
' }',
98+
'];'
99+
].join( '\n' )
100+
};
101+
valid.push( test);
102+
53103

54104
// EXPORTS //
55105

0 commit comments

Comments
 (0)