eslint-plugin-inclusive-language
Advanced tools
Comparing version 1.1.0 to 1.2.0
@@ -8,2 +8,7 @@ # Changelog | ||
## [1.2.0](https://github.com/muenzpraeger/eslint-plugin-inclusive-language/compare/1.1.0...1.2.0) - 2020-07-03 | ||
- Allow partial matches of allowed terms [saramarcondes](https://github.com/saramarcondes) [`PR 8`](https://github.com/muenzpraeger/eslint-plugin-inclusive-language/pull/8) | ||
- Allow inline configuration of rules [muenzpraeger](https://github.com/muenzpraeger) [`PR 9`](https://github.com/muenzpraeger/eslint-plugin-inclusive-language/pull/9) | ||
## [1.1.0](https://github.com/muenzpraeger/eslint-plugin-inclusive-language/compare/1.0.0...1.1.0) - 2020-07-02 | ||
@@ -10,0 +15,0 @@ |
@@ -5,2 +5,6 @@ 'use strict'; | ||
const path = require('path'); | ||
const { | ||
getCustomRuleConfig, | ||
mergeRuleConfigs | ||
} = require('../utils/custom-rule-config'); | ||
@@ -19,8 +23,23 @@ const DEFAULT_MESSAGE = | ||
function customRuleConfig(filePath) { | ||
const customPath = path.resolve(process.cwd(), filePath); | ||
if (fs.existsSync(customPath)) { | ||
return JSON.parse(fs.readFileSync(customPath), 'utf8'); | ||
} | ||
return; | ||
/** | ||
* Remove allowed terms from the list of words, checking | ||
* for partial or complete matches based on each allowed | ||
* term's configuration. | ||
* | ||
* @param {string[]} words The list of words to filter | ||
* @returns {string[]} The list of words excluding any allowed terms | ||
*/ | ||
function excludeAllowedTerms(words) { | ||
return words.filter((word) => { | ||
const isAllowedTerm = ruleConfig.allowedTerms.find( | ||
({ term, allowPartialMatches }) => { | ||
if (!allowPartialMatches) { | ||
return word.toLowerCase() === term; | ||
} | ||
return word.toLowerCase().includes(term); | ||
} | ||
); | ||
return !isAllowedTerm; | ||
}); | ||
} | ||
@@ -34,9 +53,7 @@ | ||
// match whole words and partial words, at the end and beginning of sentences | ||
regex = new RegExp(`\\S*${wordDeclaration.word}\\S*`, 'ig'); | ||
regex = new RegExp(`[\\w-_]*${wordDeclaration.word}[\\w-_]*`, 'ig'); | ||
const matches = value.match(regex); | ||
if (matches) { | ||
return matches.filter( | ||
(word) => !ruleConfig.allowedTerms.includes(word.toLowerCase()) | ||
).length; | ||
return excludeAllowedTerms(matches).length; | ||
} | ||
@@ -93,14 +110,8 @@ return null; | ||
create: function (context) { | ||
if (context.options && context.options.length > 0) { | ||
const customConfig = customRuleConfig(context.options[0]); | ||
if (customConfig !== undefined) { | ||
ruleConfig = { | ||
words: [...ruleConfig.words, ...(customConfig.words || [])], | ||
allowedTerms: [ | ||
...ruleConfig.allowedTerms, | ||
...(customConfig.allowedTerms || []) | ||
] | ||
}; | ||
} | ||
const customConfig = getCustomRuleConfig(context); | ||
if (customConfig) { | ||
ruleConfig = mergeRuleConfigs(ruleConfig, customConfig); | ||
} | ||
return { | ||
@@ -107,0 +118,0 @@ Literal(node) { |
{ | ||
"name": "eslint-plugin-inclusive-language", | ||
"version": "1.1.0", | ||
"version": "1.2.0", | ||
"description": "An ESLint plugin to raise awareness for using inclusive language not only in your codebase, but in life.", | ||
@@ -5,0 +5,0 @@ "main": "lib/index.js", |
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
16031
8
228
3