From d1d3c5a8831033e0b123188ba16dbc52f6a430c9 Mon Sep 17 00:00:00 2001 From: headlessNode Date: Thu, 5 Dec 2024 20:04:38 +0500 Subject: [PATCH 1/3] feat: add fixer function --- .../rules/no-empty-comments/lib/main.js | 21 ++++++-- .../test/fixtures/invalid.js | 49 +++++++++++++++++-- 2 files changed, 63 insertions(+), 7 deletions(-) diff --git a/lib/node_modules/@stdlib/_tools/eslint/rules/no-empty-comments/lib/main.js b/lib/node_modules/@stdlib/_tools/eslint/rules/no-empty-comments/lib/main.js index 31247ef0ee9c..d6d6b84d8d74 100644 --- a/lib/node_modules/@stdlib/_tools/eslint/rules/no-empty-comments/lib/main.js +++ b/lib/node_modules/@stdlib/_tools/eslint/rules/no-empty-comments/lib/main.js @@ -49,8 +49,22 @@ function main(context) { context.report({ 'node': null, 'message': 'Empty comments are not allowed', - 'loc': comment.loc + 'loc': comment.loc, + 'fix': fix }); + + /** + * Fixes the lint error by removing empty comments. + * @private + * @param {Function} fixer - ESLint fixer + * @returns {(Object|null)} fix or null + */ + function fix( fixer ) { + if ( comment.type === 'Block' || comment.type === 'Line' ) { + return fixer.removeRange( comment.range ); + } + return null; + } } /** @@ -98,11 +112,12 @@ function main(context) { rule = { 'meta': { + 'type': 'layout', 'docs': { 'description': 'enforce that comments are not empty' }, - 'schema': [], - 'fixable': null + 'fixable': 'code', + 'schema': [] }, 'create': main }; diff --git a/lib/node_modules/@stdlib/_tools/eslint/rules/no-empty-comments/test/fixtures/invalid.js b/lib/node_modules/@stdlib/_tools/eslint/rules/no-empty-comments/test/fixtures/invalid.js index 6598a329ac6e..b3f04f444444 100644 --- a/lib/node_modules/@stdlib/_tools/eslint/rules/no-empty-comments/test/fixtures/invalid.js +++ b/lib/node_modules/@stdlib/_tools/eslint/rules/no-empty-comments/test/fixtures/invalid.js @@ -33,7 +33,13 @@ test = { 'message': 'Empty comments are not allowed', 'type': null } - ] + ], + 'output': [ + 'function pow2( x ) {', + ' ', + ' return x*x;', + '}' + ].join( '\n' ) }; invalid.push( test ); @@ -55,7 +61,19 @@ test = { 'message': 'Empty comments are not allowed', 'type': null } - ] + ], + 'output': [ + 'function fizzBuzz() {', + ' var out;', + ' var i;', + '', + ' for ( i = 1; i <= 100; i++ ) {', + ' out = ( i % 5 === 0 ) ? "Buzz" : ( i % 3 === 0 ) ? "Fizz" : i;', + ' ', + ' console.log( out );', + ' }', + '}' + ].join( '\n' ) }; invalid.push( test ); @@ -81,7 +99,19 @@ test = { 'message': 'Empty comments are not allowed', 'type': null } - ] + ], + 'output': [ + 'function makePerson() {', + ' var person = {', + ' ', + ' \'title\': \'engineer\',', + '', + ' ', + ' \'name\': \'Susan\'', + ' };', + ' return person;', + '}' + ].join( '\n' ) }; invalid.push( test ); @@ -102,7 +132,18 @@ test = { 'message': 'Empty comments are not allowed', 'type': null } - ] + ], + 'output': [ + 'function square( x ) {', + ' var out;', + ' var x;', + '', + ' out = x*x;', + ' ', + '', + ' return out;', + '}' + ].join( '\n' ) }; invalid.push( test ); From f7e2a1df5c3d6adf4788bada7d30a76c85ad011c Mon Sep 17 00:00:00 2001 From: headlessNode Date: Thu, 5 Dec 2024 20:57:44 +0500 Subject: [PATCH 2/3] docs: apply review suggestion --- .../_tools/eslint/rules/no-empty-comments/lib/main.js | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/lib/node_modules/@stdlib/_tools/eslint/rules/no-empty-comments/lib/main.js b/lib/node_modules/@stdlib/_tools/eslint/rules/no-empty-comments/lib/main.js index d6d6b84d8d74..fffedcf9f24f 100644 --- a/lib/node_modules/@stdlib/_tools/eslint/rules/no-empty-comments/lib/main.js +++ b/lib/node_modules/@stdlib/_tools/eslint/rules/no-empty-comments/lib/main.js @@ -54,11 +54,11 @@ function main(context) { }); /** - * Fixes the lint error by removing empty comments. - * @private - * @param {Function} fixer - ESLint fixer - * @returns {(Object|null)} fix or null - */ + * Fixes the lint error by removing empty comments. + * @private + * @param {Function} fixer - ESLint fixer + * @returns {(Object|null)} fix or null + */ function fix( fixer ) { if ( comment.type === 'Block' || comment.type === 'Line' ) { return fixer.removeRange( comment.range ); From abd4daba5b4383af74d58ea954353cb0194dab24 Mon Sep 17 00:00:00 2001 From: Philipp Burckhardt Date: Sat, 7 Dec 2024 16:56:06 -0500 Subject: [PATCH 3/3] docs: add empty line and update description Signed-off-by: Philipp Burckhardt --- .../@stdlib/_tools/eslint/rules/no-empty-comments/lib/main.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/node_modules/@stdlib/_tools/eslint/rules/no-empty-comments/lib/main.js b/lib/node_modules/@stdlib/_tools/eslint/rules/no-empty-comments/lib/main.js index fffedcf9f24f..9d2c96648f1b 100644 --- a/lib/node_modules/@stdlib/_tools/eslint/rules/no-empty-comments/lib/main.js +++ b/lib/node_modules/@stdlib/_tools/eslint/rules/no-empty-comments/lib/main.js @@ -54,7 +54,8 @@ function main(context) { }); /** - * Fixes the lint error by removing empty comments. + * Fixes the lint error. + * * @private * @param {Function} fixer - ESLint fixer * @returns {(Object|null)} fix or null