Skip to content

Commit

Permalink
tools: remove fixer for non-ascii-character ESLint custom rule
Browse files Browse the repository at this point in the history
The fixer for non-ascii-character does not typidally do the right thing.
It removes the entire node, not the offending character. I discovered
this when it removed the entire contents of a file and I wasn't sure
which auto-fix rule was doing it.

This commit adds a minimal test for the rule. The tests require that
auto-fix results be supplied, so if someone wants to re-add auto-fixing
to the rule, we'll have tests that it does the right thing.

PR-URL: #38413
Reviewed-By: Colin Ihrig <[email protected]>
Reviewed-By: Antoine du Hamel <[email protected]>
Reviewed-By: James M Snell <[email protected]>
  • Loading branch information
Trott committed Apr 28, 2021
1 parent 346f0e9 commit 896e5af
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 10 deletions.
26 changes: 26 additions & 0 deletions test/parallel/test-eslint-non-ascii-character.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
'use strict';

const common = require('../common');
if (!common.hasCrypto)
common.skip('missing crypto');

common.skipIfEslintMissing();

const RuleTester = require('../../tools/node_modules/eslint').RuleTester;
const rule = require('../../tools/eslint-rules/non-ascii-character');

new RuleTester().run('non-ascii-characters', rule, {
valid: [
{
code: 'console.log("fhqwhgads")',
options: []
},
],
invalid: [
{
code: 'console.log("μ")',
options: [],
errors: [{ message: "Non-ASCII character 'μ' detected." }],
},
]
});
10 changes: 0 additions & 10 deletions tools/eslint-rules/non-ascii-character.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,20 +46,10 @@ module.exports = (context) => {
node,
message,
loc: sourceCode.getLocFromIndex(offendingCharacterPosition),
fix: (fixer) => {
return fixer.replaceText(
node,
suggestion ? `${suggestion}` : ''
);
}
});
};

return {
Program: (node) => reportIfError(node, context.getSourceCode())
};
};

module.exports.meta = {
fixable: 'code'
};

0 comments on commit 896e5af

Please sign in to comment.