Skip to content

Commit 1e0ab23

Browse files
committed
Adding loc to report
1 parent bd452d5 commit 1e0ab23

File tree

3 files changed

+10
-6
lines changed

3 files changed

+10
-6
lines changed

lib/internal/test/unicode.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,6 @@
33
// This module exists entirely for regression testing purposes.
44
// See `test/parallel/test-internal-unicode.js`.
55

6-
module.exports = '✓'; // eslint-disable-line
6+
/* eslint-disable non-ascii-character */
7+
module.exports = '✓';
8+
/* eslint-enable non-ascii-character */

lib/timers.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ const Timeout = timerInternals.Timeout;
9797
// TimerWrap C++ handle, which makes the call after the duration to process the
9898
// list it is attached to.
9999
//
100-
// eslint-disable non-ascii-character
100+
/* eslint-disable non-ascii-character */
101101
//
102102
// ╔════ > Object Map
103103
// ║
@@ -119,7 +119,7 @@ const Timeout = timerInternals.Timeout;
119119
// ║
120120
// ╚════ > Linked List
121121
//
122-
// eslint-enable non-ascii-character
122+
/* eslint-enable non-ascii-character */
123123
//
124124
// With this, virtually constant-time insertion (append), removal, and timeout
125125
// is possible in the JavaScript layer. Any one list of timers is able to be

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

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,14 @@ const suggestions = {
2626

2727
module.exports = (context) => {
2828

29-
const reportIfError = (node, text) => {
29+
const reportIfError = (node, sourceCode) => {
3030

31-
const matches = text.match(nonAsciiRegexPattern);
31+
const matches = sourceCode.text.match(nonAsciiRegexPattern);
3232

3333
if (!matches) return;
3434

3535
const offendingCharacter = matches[0];
36+
const offendingCharacterPosition = matches.index;
3637
const suggestion = suggestions[offendingCharacter];
3738

3839
let message = `Non-ASCII character '${offendingCharacter}' detected.`;
@@ -44,6 +45,7 @@ module.exports = (context) => {
4445
context.report({
4546
node,
4647
message,
48+
loc: sourceCode.getLocFromIndex(offendingCharacterPosition),
4749
fix: (fixer) => {
4850
return fixer.replaceText(
4951
node,
@@ -54,6 +56,6 @@ module.exports = (context) => {
5456
};
5557

5658
return {
57-
Program: (node) => reportIfError(node, context.getSourceCode().text)
59+
Program: (node) => reportIfError(node, context.getSourceCode())
5860
};
5961
};

0 commit comments

Comments
 (0)