Skip to content

Commit ee81cd1

Browse files
committed
refactor: update rule to handle edge cases
--- 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: na - task: lint_javascript_tests status: passed - 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: na - 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 ---
1 parent d16409a commit ee81cd1

File tree

2 files changed

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

2 files changed

+27
-3
lines changed

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

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -85,15 +85,21 @@ function main( context ) {
8585
node.arguments.length > 0
8686
) {
8787
args = node.arguments;
88-
if ( args[ 0 ].type === 'ObjectExpression' ) {
88+
if (
89+
args[ 0 ].type === 'ObjectExpression' &&
90+
args[ 0 ].properties.length > 0
91+
) {
8992
prevToken = source.getTokenBefore( args[ 0 ] );
9093
tokenAfter = source.getFirstToken( args[ 0 ] );
9194
if ( source.isSpaceBetween( prevToken, tokenAfter ) ) {
9295
report( node, prevToken, tokenAfter );
9396
}
9497
} else if ( args[ 0 ].type === 'ArrayExpression' ) {
9598
elem = args[ 0 ].elements[ 0 ];
96-
if ( elem.type === 'ObjectExpression' ) {
99+
if (
100+
elem.type === 'ObjectExpression' &&
101+
elem.properties.length > 0
102+
) {
97103
prevToken = source.getTokenBefore( args[ 0 ] );
98104
tokenAfter = source.getFirstToken( args[ 0 ] );
99105
if ( source.isSpaceBetween( prevToken, tokenAfter ) ) {
@@ -118,7 +124,10 @@ function main( context ) {
118124
node.elements.length > 0
119125
) {
120126
elem = node.elements[ 0 ];
121-
if ( elem.type === 'ObjectExpression' ) {
127+
if (
128+
elem.type === 'ObjectExpression' &&
129+
elem.properties.length > 0
130+
) {
122131
prevToken = source.getFirstToken( node );
123132
tokenAfter = source.getFirstToken( elem );
124133

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

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,21 @@ test = {
3535
};
3636
valid.push( test);
3737

38+
test = {
39+
'code': [
40+
' var log = require( \'@stdlib/console/log\' );',
41+
' log( {} );'
42+
].join( '\n' )
43+
};
44+
valid.push( test);
45+
46+
test = {
47+
'code': [
48+
'var arr = [ {}, 1, 2, 3, 4 ];'
49+
].join( '\n' )
50+
};
51+
valid.push( test);
52+
3853

3954
// EXPORTS //
4055

0 commit comments

Comments
 (0)