Skip to content

Commit

Permalink
refactor: rename ignoreUpperCaseUnderscore to enableUpperCaseUndersco…
Browse files Browse the repository at this point in the history
…reCheck
  • Loading branch information
stu01509 committed Nov 18, 2022
1 parent 29b6825 commit 3ee411e
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 16 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ Check Spelling inside identifiers
"ignoreRequire": <<Boolean>>, default: false
Exclude `require()` imports from spell-checking. Useful for excluding NPM package name false-positives.
"ignoreUpperCaseUnderscore": <<Boolean>>, default: false
"enableUpperCaseUnderscoreCheck": <<Boolean>>, default: false
Exclude checking uppercase words separated by an underscore. e.g., `SEARCH_CONDITIONS_LIMIT`
"templates": <<Boolean>>, default: true
Expand Down
7 changes: 3 additions & 4 deletions rules/spell-checker.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ module.exports = {
type: 'boolean',
default: false
},
ignoreUpperCaseUnderscore: {
enableUpperCaseUnderscoreCheck: {
type: 'boolean',
default: false
},
Expand Down Expand Up @@ -202,13 +202,12 @@ module.exports = {
}

function underscoreParser(aNode, value, spellingType) {
if (options.ignoreUpperCaseUnderscore) {
if (!options.enableUpperCaseUnderscoreCheck) {
checkSpelling(aNode, value, spellingType);
} else {
const hasUnderscore = value.split('_').length > 1;
const splitValues = value.split('_');
splitValues.forEach((word) => {
checkSpelling(aNode, hasUnderscore ? word.toLowerCase() : word, spellingType);
checkSpelling(aNode, word.toLowerCase(), spellingType);
})
}
}
Expand Down
34 changes: 23 additions & 11 deletions test/spell-checker.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ var ruleTester = new RuleTester({
},

parserOptions: {
"ecmaVersion": 2018,
"sourceType": "module",
'ecmaVersion': 2018,
'sourceType': 'module',
ecmaFeatures: {
"modules": true
'modules': true
}
}
});
Expand All @@ -45,15 +45,13 @@ ruleTester.run('spellcheck/spell-checker', rule, {
'var a = Math.trunc(-0.1)',
'var a = "test", test = `${a}`;',
'var a = "ADD_SUM";',
'var a = "ADD_SMU";',
'const SEARCH_CONDITIONS_LIMIT = 9;',
{
code: 'var a = "ADD_SMU"',
options:[{ ignoreUpperCaseUnderscore: true }]
},
{
code: 'const SEACH_CONDITIONS_LIMIT = 9;',
options:[{ ignoreUpperCaseUnderscore: true }]
},
'const SEACH_CONDITIONS_LIMIT = 9;',
'const KEY = "HELLO_WORLD";',
'const KEY = "HELLO_WORDL";',
'const PASSWORD = "123456";',
'const PASSWROD = "123456";',
{
code: 'var a = 1 // This is a comment',
options: [{lang: 'sym', langDir: __dirname}]
Expand Down Expand Up @@ -195,13 +193,27 @@ ruleTester.run('spellcheck/spell-checker', rule, {
},
{
code: 'var a = "ADD_SMU"',
options:[{ enableUpperCaseUnderscoreCheck: true }],
errors: [
{ message: 'You have a misspelled word: smu on String'}]
},
{
code: 'const SEACH_CONDITIONS_LIMIT = 9;',
options:[{ enableUpperCaseUnderscoreCheck: true }],
errors: [
{ message: 'You have a misspelled word: seach on Identifier'}]
},
{
code: 'const KEY = "HELLO_WORDL";',
options:[{ enableUpperCaseUnderscoreCheck: true }],
errors: [
{ message: 'You have a misspelled word: wordl on String'}]
},
{
code: 'const PASSWROD = "123456";',
options:[{ enableUpperCaseUnderscoreCheck: true }],
errors: [
{ message: 'You have a misspelled word: passwrod on Identifier'}]
},
]
});

0 comments on commit 3ee411e

Please sign in to comment.