diff --git a/lib/internal/test/unicode.js b/lib/internal/test/unicode.js index 6432eb9d9decdf..7172a43ec20a8a 100644 --- a/lib/internal/test/unicode.js +++ b/lib/internal/test/unicode.js @@ -3,4 +3,6 @@ // This module exists entirely for regression testing purposes. // See `test/parallel/test-internal-unicode.js`. -module.exports = '✓'; // eslint-disable-line +/* eslint-disable non-ascii-character */ +module.exports = '✓'; +/* eslint-enable non-ascii-character */ diff --git a/lib/timers.js b/lib/timers.js index 548ac2450c782a..59a5d5272c38fc 100644 --- a/lib/timers.js +++ b/lib/timers.js @@ -97,7 +97,7 @@ const Timeout = timerInternals.Timeout; // TimerWrap C++ handle, which makes the call after the duration to process the // list it is attached to. // -// eslint-disable non-ascii-character +/* eslint-disable non-ascii-character */ // // ╔════ > Object Map // ║ @@ -119,7 +119,7 @@ const Timeout = timerInternals.Timeout; // ║ // ╚════ > Linked List // -// eslint-enable non-ascii-character +/* eslint-enable non-ascii-character */ // // With this, virtually constant-time insertion (append), removal, and timeout // is possible in the JavaScript layer. Any one list of timers is able to be diff --git a/tools/eslint-rules/non-ascii-character.js b/tools/eslint-rules/non-ascii-character.js index b0f050a1397619..e67aac7cd91e82 100644 --- a/tools/eslint-rules/non-ascii-character.js +++ b/tools/eslint-rules/non-ascii-character.js @@ -26,13 +26,14 @@ const suggestions = { module.exports = (context) => { - const reportIfError = (node, text) => { + const reportIfError = (node, sourceCode) => { - const matches = text.match(nonAsciiRegexPattern); + const matches = sourceCode.text.match(nonAsciiRegexPattern); if (!matches) return; const offendingCharacter = matches[0]; + const offendingCharacterPosition = matches.index; const suggestion = suggestions[offendingCharacter]; let message = `Non-ASCII character '${offendingCharacter}' detected.`; @@ -44,6 +45,7 @@ module.exports = (context) => { context.report({ node, message, + loc: sourceCode.getLocFromIndex(offendingCharacterPosition), fix: (fixer) => { return fixer.replaceText( node, @@ -54,6 +56,6 @@ module.exports = (context) => { }; return { - Program: (node) => reportIfError(node, context.getSourceCode().text) + Program: (node) => reportIfError(node, context.getSourceCode()) }; };