eslint-plugin-spellcheck
Advanced tools
Comparing version 0.0.19 to 0.0.20
{ | ||
"name": "eslint-plugin-spellcheck", | ||
"version": "0.0.19", | ||
"version": "0.0.20", | ||
"description": "ESLint rules to spell check js files", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
# eslint-plugin-spellcheck | ||
[eslint](http://eslint.org) plugin to spell check words on identifiers, Strings and comments of javascript files. | ||
[![dependencies Status](https://david-dm.org/aotaduy/eslint-plugin-spellcheck/status.svg)](https://david-dm.org/aotaduy/eslint-plugin-spellcheck) | ||
[![Build Status](https://travis-ci.org/aotaduy/eslint-plugin-spellcheck.svg?branch=master)](https://travis-ci.org/aotaduy/eslint-plugin-spellcheck) | ||
[![Build CI](https://github.com/aotaduy/eslint-plugin-spellcheck/actions/workflows/node.js.yml/badge.svg)](https://github.com/aotaduy/eslint-plugin-spellcheck/actions/workflows/node.js.yml) | ||
## Usage in a project | ||
@@ -81,2 +80,5 @@ | ||
"enableUpperCaseUnderscoreCheck": <<Boolean>>, default: false | ||
Exclude checking uppercase words separated by an underscore. e.g., `SEARCH_CONDITIONS_LIMIT` | ||
"templates": <<Boolean>>, default: true | ||
@@ -83,0 +85,0 @@ Check Spelling inside ES6 templates you should enable parser options for ES6 features for this to work |
@@ -76,2 +76,6 @@ // Native modules | ||
}, | ||
enableUpperCaseUnderscoreCheck: { | ||
type: 'boolean', | ||
default: false | ||
}, | ||
templates: { | ||
@@ -115,3 +119,2 @@ type: 'boolean', | ||
] | ||
}, | ||
@@ -169,7 +172,7 @@ | ||
function checkSpelling(aNode, value, spellingType) { | ||
if(!hasToSkip(value)) { | ||
if (!hasToSkip(value)) { | ||
// Regular expression matches regexp metacharacters, and any special char | ||
var regexp = /(\\[sSwdDB0nfrtv])|\\[0-7][0-7][0-7]|\\x[0-9A-F][0-9A-F]|\\u[0-9A-F][0-9A-F][0-9A-F][0-9A-F]|[^0-9a-zA-Z '’]/g, | ||
nodeWords = value.replace(regexp, ' ') | ||
.replace(/([A-Z])/g, ' $1').split(' '), | ||
.replace(/([A-Z])/g, ' $1').split(' '), | ||
errors; | ||
@@ -179,18 +182,18 @@ errors = nodeWords | ||
.filter(isSpellingError) | ||
.filter(function(aWord) { | ||
// Split words by numbers for special cases such as test12anything78variable and to include 2nd and 3rd ordinals | ||
// also for Proper names we convert to lower case in second pass. | ||
.filter(function (aWord) { | ||
// Split words by numbers for special cases such as test12anything78variable and to include 2nd and 3rd ordinals | ||
// also for Proper names we convert to lower case in second pass. | ||
var splitByNumberWords = aWord.replace(/[0-9']/g, ' ').replace(/([A-Z])/g, ' $1').toLowerCase().split(' '); | ||
return splitByNumberWords.some(isSpellingError); | ||
}) | ||
.forEach(function(aWord) { | ||
.forEach(function (aWord) { | ||
context.report( | ||
aNode, | ||
'You have a misspelled word: {{word}} on {{spellingType}}', { | ||
word: aWord, | ||
spellingType: spellingType | ||
}); | ||
word: aWord, | ||
spellingType: spellingType | ||
}); | ||
}); | ||
} | ||
} | ||
} | ||
@@ -205,16 +208,28 @@ function isInImportDeclaration(aNode) { | ||
function underscoreParser(aNode, value, spellingType) { | ||
if (!options.enableUpperCaseUnderscoreCheck) { | ||
checkSpelling(aNode, value, spellingType); | ||
} else { | ||
const splitValues = value.split('_'); | ||
splitValues.forEach((word) => { | ||
checkSpelling(aNode, word.toLowerCase(), spellingType); | ||
}) | ||
} | ||
} | ||
function checkComment(aNode) { | ||
if(options.comments) { | ||
checkSpelling(aNode, aNode.value, 'Comment'); | ||
if (options.comments) { | ||
underscoreParser(aNode, aNode.value, 'Comment'); | ||
} | ||
} | ||
function checkLiteral(aNode){ | ||
if(options.strings && typeof aNode.value === 'string' && !isInImportDeclaration(aNode)) { | ||
checkSpelling(aNode, aNode.value, 'String'); | ||
function checkLiteral(aNode) { | ||
if (options.strings && typeof aNode.value === 'string' && !isInImportDeclaration(aNode)) { | ||
underscoreParser(aNode, aNode.value, 'String'); | ||
} | ||
} | ||
function checkTemplateElement(aNode){ | ||
if(options.templates && typeof aNode.value.raw === 'string' && !isInImportDeclaration(aNode)) { | ||
checkSpelling(aNode, aNode.value.raw, 'Template'); | ||
function checkTemplateElement(aNode) { | ||
if (options.templates && typeof aNode.value.raw === 'string' && !isInImportDeclaration(aNode)) { | ||
underscoreParser(aNode, aNode.value.raw, 'Template'); | ||
} | ||
@@ -224,4 +239,4 @@ } | ||
function checkIdentifier(aNode) { | ||
if(options.identifiers) { | ||
checkSpelling(aNode, aNode.name, 'Identifier'); | ||
if (options.identifiers) { | ||
underscoreParser(aNode, aNode.name, 'Identifier'); | ||
} | ||
@@ -228,0 +243,0 @@ } |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
2421467
570
168