Skip to content

Commit 2ebcd7b

Browse files
committed
refactor: 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 febeefb commit 2ebcd7b

File tree

2 files changed

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

2 files changed

+27
-3
lines changed

lib/node_modules/@stdlib/_tools/eslint/rules/line-closing-bracket-spacing/lib/main.js

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -87,15 +87,21 @@ function main( context ) {
8787
) {
8888
args = node.arguments;
8989
lastElem = args[ args.length - 1 ];
90-
if ( lastElem.type === 'ObjectExpression' ) {
90+
if (
91+
lastElem.type === 'ObjectExpression' &&
92+
lastElem.properties.length > 0
93+
) {
9194
prevToken = source.getLastToken( lastElem );
9295
tokenAfter = source.getTokenAfter( prevToken );
9396
if ( source.isSpaceBetween( prevToken, tokenAfter ) ) {
9497
report( node, prevToken, tokenAfter );
9598
}
9699
} else if ( lastElem.type === 'ArrayExpression' ) {
97100
elem = lastElem.elements[ lastElem.elements.length - 1 ];
98-
if ( elem.type === 'ObjectExpression' ) {
101+
if (
102+
elem.type === 'ObjectExpression' &&
103+
elem.properties.length > 0
104+
) {
99105
prevToken = source.getLastToken( lastElem );
100106
tokenAfter = source.getTokenAfter( prevToken );
101107
if ( source.isSpaceBetween( prevToken, tokenAfter ) ) {
@@ -120,7 +126,10 @@ function main( context ) {
120126
node.elements.length > 0
121127
) {
122128
elem = node.elements[ node.elements.length - 1 ];
123-
if ( elem.type === 'ObjectExpression' ) {
129+
if (
130+
elem.type === 'ObjectExpression' &&
131+
elem.properties.length > 0
132+
) {
124133
prevToken = source.getLastToken( elem );
125134
tokenAfter = source.getTokenAfter( prevToken );
126135
if ( source.isSpaceBetween( prevToken, tokenAfter ) ) {

lib/node_modules/@stdlib/_tools/eslint/rules/line-closing-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)