From d3f2b131ecef0e80acd87fa1fed493907a627d12 Mon Sep 17 00:00:00 2001 From: "Antonio D. Gonzalez" Date: Sat, 11 Jun 2016 18:51:57 +0200 Subject: [PATCH] Check spelling in UPPER_CASE_SEPARATED_BY_UNDERSCORE --- package.json | 3 +++ rules/spell-checker.js | 4 +++- test/spell-checker.js | 20 ++++++++++++++++++++ 3 files changed, 26 insertions(+), 1 deletion(-) diff --git a/package.json b/package.json index 2dc1116..fb0f2ac 100644 --- a/package.json +++ b/package.json @@ -7,6 +7,9 @@ "type": "git", "url": "https://github.com/aotaduy/eslint-plugin-spellcheck.git" }, + "scripts": { + "test": "mocha" + }, "author": "Andres Otaduy", "license": "MIT", "bugs": { diff --git a/rules/spell-checker.js b/rules/spell-checker.js index 272453e..7a6f515 100644 --- a/rules/spell-checker.js +++ b/rules/spell-checker.js @@ -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); diff --git a/test/spell-checker.js b/test/spell-checker.js index 4f12ad9..9fc9145 100644 --- a/test/spell-checker.js +++ b/test/spell-checker.js @@ -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: [ @@ -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'}] } ]