Skip to content

Commit 6350d35

Browse files
Trotttargos
authored andcommitted
tools: remove fixer for non-ascii-character ESLint custom rule
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]>
1 parent 620ee42 commit 6350d35

File tree

2 files changed

+26
-10
lines changed

2 files changed

+26
-10
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
'use strict';
2+
3+
const common = require('../common');
4+
if (!common.hasCrypto)
5+
common.skip('missing crypto');
6+
7+
common.skipIfEslintMissing();
8+
9+
const RuleTester = require('../../tools/node_modules/eslint').RuleTester;
10+
const rule = require('../../tools/eslint-rules/non-ascii-character');
11+
12+
new RuleTester().run('non-ascii-characters', rule, {
13+
valid: [
14+
{
15+
code: 'console.log("fhqwhgads")',
16+
options: []
17+
},
18+
],
19+
invalid: [
20+
{
21+
code: 'console.log("μ")',
22+
options: [],
23+
errors: [{ message: "Non-ASCII character 'μ' detected." }],
24+
},
25+
]
26+
});

tools/eslint-rules/non-ascii-character.js

-10
Original file line numberDiff line numberDiff line change
@@ -46,20 +46,10 @@ module.exports = (context) => {
4646
node,
4747
message,
4848
loc: sourceCode.getLocFromIndex(offendingCharacterPosition),
49-
fix: (fixer) => {
50-
return fixer.replaceText(
51-
node,
52-
suggestion ? `${suggestion}` : ''
53-
);
54-
}
5549
});
5650
};
5751

5852
return {
5953
Program: (node) => reportIfError(node, context.getSourceCode())
6054
};
6155
};
62-
63-
module.exports.meta = {
64-
fixable: 'code'
65-
};

0 commit comments

Comments
 (0)