diff --git a/README.md b/README.md index 7f7f726..4904119 100644 --- a/README.md +++ b/README.md @@ -77,7 +77,7 @@ Check Spelling inside identifiers "ignoreRequire": <>, default: false Exclude `require()` imports from spell-checking. Useful for excluding NPM package name false-positives. -"ignoreUpperCaseUnderscore": <>, default: false +"enableUpperCaseUnderscoreCheck": <>, default: false Exclude checking uppercase words separated by an underscore. e.g., `SEARCH_CONDITIONS_LIMIT` "templates": <>, default: true diff --git a/rules/spell-checker.js b/rules/spell-checker.js index c2f44c3..8b16e5f 100644 --- a/rules/spell-checker.js +++ b/rules/spell-checker.js @@ -73,7 +73,7 @@ module.exports = { type: 'boolean', default: false }, - ignoreUpperCaseUnderscore: { + enableUpperCaseUnderscoreCheck: { type: 'boolean', default: false }, @@ -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); }) } } diff --git a/test/spell-checker.js b/test/spell-checker.js index c539f7b..7b9f58d 100644 --- a/test/spell-checker.js +++ b/test/spell-checker.js @@ -15,10 +15,10 @@ var ruleTester = new RuleTester({ }, parserOptions: { - "ecmaVersion": 2018, - "sourceType": "module", + 'ecmaVersion': 2018, + 'sourceType': 'module', ecmaFeatures: { - "modules": true + 'modules': true } } }); @@ -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}] @@ -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'}] + }, ] });