Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Check spelling in UPPER_CASE_SEPARATED_BY_UNDERSCORE #17

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@
"type": "git",
"url": "https://github.com/aotaduy/eslint-plugin-spellcheck.git"
},
"scripts": {
"test": "mocha"
},
"author": "Andres Otaduy",
"license": "MIT",
"bugs": {
Expand Down
4 changes: 3 additions & 1 deletion rules/spell-checker.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,9 @@ module.exports = function(context) {

function checkSpelling(aNode, value, spellingType) {
if(!hasToSkip(value)) {
var nodeWords = value.replace(/[^a-zA-Z ]/g, ' ').replace(/([A-Z])/g, ' $1').toLowerCase().split(' ');
var nodeWords = value
.replace(/\b([A-Z][A-Z0-9_]*)\b/g, function(s) { return s.toLowerCase().split('_'); })
.replace(/[^a-zA-Z ]/g, ' ').replace(/([A-Z])/g, ' $1').toLowerCase().split(' ');
nodeWords
.filter(function(aWord) {
return !lodash.includes(options.skipWords, aWord) && !spell.check(aWord);
Expand Down
20 changes: 20 additions & 0 deletions test/spell-checker.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ eslintTester.addRuleTest('rules/spell-checker', {
code: 'var url = "http://examplus.com"',
args:[2, {skipWords: ['url'], skipIfMatch:['http://[^\s]*']}]
},
'var MY_ACTION = "MY_ACTION"',
'var MY_ACTION2 = "MY_ACTION2"',
'var a = 1 // This is MY_ACTION',

],
invalid: [
Expand Down Expand Up @@ -91,6 +94,23 @@ eslintTester.addRuleTest('rules/spell-checker', {
errors: [
{ message: 'You have a misspelled word: color on Comment'},
{ message: 'You have a misspelled word: behavior on Comment'}]
},
{
code: 'var MY_ACTOIN = "MY_ATCION"',
errors: [
{ message: 'You have a misspelled word: actoin on Identifier'},
{ message: 'You have a misspelled word: atcion on String'}]
},
{
code: 'var MY_ACTOIN2 = "MY_ATCION2"',
errors: [
{ message: 'You have a misspelled word: actoin on Identifier'},
{ message: 'You have a misspelled word: atcion on String'}]
},
{
code: 'var a = 1 // This is MY_ACTOIN',
errors: [
{ message: 'You have a misspelled word: actoin on Comment'}]
}

]
Expand Down