Socket
Socket
Sign inDemoInstall

eslint-plugin-spellcheck

Package Overview
Dependencies
Maintainers
1
Versions
17
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

eslint-plugin-spellcheck - npm Package Compare versions

Comparing version 0.0.8 to 0.0.9

coverage/coverage-final.json

5

package.json
{
"name": "eslint-plugin-spellcheck",
"version": "0.0.8",
"version": "0.0.9",
"description": "ESLint rules to spell check js files",

@@ -18,2 +18,3 @@ "main": "index.js",

"test": "gulp",
"performance": "gulp performance",
"lint": "eslint -c .eslintrc.json rules/*.js"

@@ -29,3 +30,3 @@ },

"coveralls": "^2.11.12",
"eslint": "^3.2.2",
"eslint": "^3.2.2 || ^4.0.0",
"gulp": "^3.9.1",

@@ -32,0 +33,0 @@ "gulp-istanbul": "1.0.0",

28

README.md
# 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)
## Configuration
This ESLint plugin, like others, can be reconfigured to produce errors (2), warnings (1), or disabled (0) with the first numeric argument. For more information on ESLint configuration, see: http://eslint.org/docs/user-guide/configuring
````

@@ -27,4 +30,11 @@ "comments": <<Boolean>> default: true

"skipIfMatch": <<Array Of Strings>> default: []
Array of Regular Expressions that if matched will not be checked.
Array of Regular Expressions the plugin will try to match the js node element value (identifier, comment, string, string template, etc) and will not check the entire node content if matched, be careful in comments because if a part of the comment is matched the entire comment will not be checked, same for strings.
i.e: "^[-\\w]+\/[-\\w\\.]+$" will ignore MIME types.
"skipWordIfMatch": <<Array Of Strings>> default: []
Array of Regular Expressions the plugin will try to match every single word that is found in the nodes (identifier, comment, string, string template, etc) and will not check the single word if matched.
i.e: "^[-\\w]+\/[-\\w\\.]+$" will ignore MIME types.
"minLength": <<Number>> default: 1
Words with a character-amount of less than the minLength will not be spell-checked.
````

@@ -70,4 +80,8 @@

"http://[^s]*",
"^[-\\w]+\/[-\\w\\.]+$" //For MIME Types
]
"^[-\\w]+\/[-\\w\\.]+$" //For MIME Types
],
"skipWordIfMatch": [
"^foobar.*$" // words that begin with foobar will not be checked
],
"minLength": 3
}

@@ -108,3 +122,7 @@ ]

"http://[^s]*"
]
],
"skipWordIfMatch": [
"^foobar.*$"
],
"minLength": 3
}

@@ -111,0 +129,0 @@ ]

@@ -18,5 +18,13 @@ // Native modules

lodash.keys(globals.jquery),
lodash.keys(globals.shelljs)
lodash.keys(globals.shelljs),
Object.getOwnPropertyNames(String.prototype),
Object.getOwnPropertyNames(JSON),
Object.getOwnPropertyNames(Math)
);
// ESLint 3 had "eslint.version" in context. ESLint 4 does not have one.
function isEslint4OrAbove(context) {
return !('eslint' in context);
}
module.exports = {

@@ -81,2 +89,10 @@ // meta (object) contains metadata for the rule:

default: []
},
skipWordIfMatch: {
type: 'array',
default: []
},
minLength: {
type: 'number',
default: 1
}

@@ -105,7 +121,8 @@ },

skipWords: [],
skipIfMatch: []
skipIfMatch: [],
skipWordIfMatch: [],
minLength: 1
},
options = lodash.assign(defaultOptions, context.options[0]),
lang = options.lang || 'en_US';
dictionary = spell.parse({

@@ -117,8 +134,11 @@ aff: fs.readFileSync(__dirname + '/utils/dicts/' + lang + '.aff'),

spell.use(dictionary);
options.skipWords = lodash.union(options.skipWords, skipWords)
options.skipWords = new Set(lodash.union(options.skipWords, skipWords)
.map(function (string) {
return string.toLowerCase();
});
}));
function isSpellingError(aWord) {
return !options.skipWords.has(aWord) && !spell.check(aWord);
}
function checkSpelling(aNode, value, spellingType) {

@@ -129,16 +149,15 @@ if(!hasToSkip(value)) {

nodeWords = value.replace(regexp, ' ')
.replace(/([A-Z])/g, ' $1').split(' ');
nodeWords
.replace(/([A-Z])/g, ' $1').split(' '),
errors;
errors = nodeWords
.filter(hasToSkipWord)
.filter(isSpellingError)
.filter(function(aWord) {
return !lodash.includes(options.skipWords, aWord) && !spell.check(aWord);
})
.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(function (aWord) {
return !lodash.includes(options.skipWords, aWord) && !spell.check(aWord);
});
return splitByNumberWords.some(isSpellingError);
})
.forEach(function(aWord) {
console.log(aWord);
context.report(

@@ -178,3 +197,3 @@ aNode,

function hasToSkip(value) {
return lodash.includes(options.skipWords, value) ||
return options.skipWords.has(value) ||
lodash.find(options.skipIfMatch, function (aPattern) {

@@ -185,4 +204,33 @@ return value.match(aPattern);

/**
* returns false if the word has to be skipped
* @param {string} word
* @return {Boolean} false if skip; true if not
*/
function hasToSkipWord(word) {
if(word.length < options.minLength) return false;
if(lodash.find(options.skipWordIfMatch, function (aPattern) {
return word.match(aPattern);
})){
return false;
}
return true;
}
// Coverage exclusion only needed for ESLint<4
/* istanbul ignore next */
if (isEslint4OrAbove(context)) {
context
.getSourceCode()
.getAllComments()
.forEach(function (commentNode) {
checkComment(commentNode);
});
}
return {
// Noop in ESLint 4+
'BlockComment': checkComment,
// Noop in ESLint 4+
'LineComment': checkComment,

@@ -189,0 +237,0 @@ 'Literal': checkLiteral,

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc