Skip to content

Commit

Permalink
Adding loc to report
Browse files Browse the repository at this point in the history
  • Loading branch information
SirR4T committed Jan 19, 2018
1 parent bd452d5 commit 1e0ab23
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 6 deletions.
4 changes: 3 additions & 1 deletion lib/internal/test/unicode.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
4 changes: 2 additions & 2 deletions lib/timers.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
// β•‘
Expand All @@ -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
Expand Down
8 changes: 5 additions & 3 deletions tools/eslint-rules/non-ascii-character.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.`;
Expand All @@ -44,6 +45,7 @@ module.exports = (context) => {
context.report({
node,
message,
loc: sourceCode.getLocFromIndex(offendingCharacterPosition),
fix: (fixer) => {
return fixer.replaceText(
node,
Expand All @@ -54,6 +56,6 @@ module.exports = (context) => {
};

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

0 comments on commit 1e0ab23

Please sign in to comment.