Socket
Socket
Sign inDemoInstall

eslint-plugin-inclusive-language

Package Overview
Dependencies
Maintainers
1
Versions
12
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

eslint-plugin-inclusive-language - npm Package Compare versions

Comparing version 1.1.0 to 1.2.0

lib/utils/custom-rule-config.js

5

CHANGELOG.md

@@ -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 @@

53

lib/rules/use-inclusive-words.js

@@ -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",

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