Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Forbid non-ASCII characters in JS files (#3053)
- Loading branch information
1 parent
676c775
commit 777c7e9
Showing
6 changed files
with
51 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,11 @@ | ||
'use strict'; | ||
|
||
const onlyASCII = require('./only-ascii'); | ||
const noDirImport = require('./no-dir-import'); | ||
|
||
module.exports = { | ||
rules: { | ||
'only-ascii': onlyASCII, | ||
'no-dir-import': noDirImport, | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
'use strict'; | ||
|
||
module.exports = { | ||
meta: { | ||
schema: [ | ||
{ | ||
type: 'object', | ||
properties: { | ||
allowEmoji: { | ||
type: 'boolean', | ||
}, | ||
}, | ||
additionalProperties: false, | ||
}, | ||
], | ||
}, | ||
create: onlyASCII, | ||
}; | ||
|
||
function onlyASCII(context) { | ||
const regExp = | ||
context.options[0]?.allowEmoji === true | ||
? /[^\p{ASCII}\p{Emoji}]+/gu | ||
: /\P{ASCII}+/gu; | ||
|
||
return { | ||
Program() { | ||
const sourceCode = context.getSourceCode(); | ||
const text = sourceCode.getText(); | ||
|
||
for (const match of text.matchAll(regExp)) { | ||
context.report({ | ||
loc: sourceCode.getLocFromIndex(match.index), | ||
message: `Non-ASCII character "${match[0]}" found.`, | ||
}); | ||
} | ||
}, | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,8 @@ | ||
{ | ||
"name": "eslint-plugin-graphql-internal", | ||
"version": "0.0.0" | ||
"version": "0.0.0", | ||
"private": true, | ||
"engines": { | ||
"node": ">= 14.0.0" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters