From 3484a231402a0b8e6d94ee023d93795f20be58f5 Mon Sep 17 00:00:00 2001 From: Rich Trott Date: Mon, 26 Apr 2021 06:51:56 -0700 Subject: [PATCH] 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: https://github.com/nodejs/node/pull/38413 Reviewed-By: Colin Ihrig Reviewed-By: Antoine du Hamel Reviewed-By: James M Snell --- .../test-eslint-non-ascii-character.js | 26 +++++++++++++++++++ tools/eslint-rules/non-ascii-character.js | 10 ------- 2 files changed, 26 insertions(+), 10 deletions(-) create mode 100644 test/parallel/test-eslint-non-ascii-character.js diff --git a/test/parallel/test-eslint-non-ascii-character.js b/test/parallel/test-eslint-non-ascii-character.js new file mode 100644 index 00000000000000..0b4a09f813431b --- /dev/null +++ b/test/parallel/test-eslint-non-ascii-character.js @@ -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." }], + }, + ] +}); diff --git a/tools/eslint-rules/non-ascii-character.js b/tools/eslint-rules/non-ascii-character.js index 6588125d33d201..f9ee24273fdcb6 100644 --- a/tools/eslint-rules/non-ascii-character.js +++ b/tools/eslint-rules/non-ascii-character.js @@ -46,12 +46,6 @@ module.exports = (context) => { node, message, loc: sourceCode.getLocFromIndex(offendingCharacterPosition), - fix: (fixer) => { - return fixer.replaceText( - node, - suggestion ? `${suggestion}` : '' - ); - } }); }; @@ -59,7 +53,3 @@ module.exports = (context) => { Program: (node) => reportIfError(node, context.getSourceCode()) }; }; - -module.exports.meta = { - fixable: 'code' -};