diff --git a/docs/rules/prevent-abbreviations.md b/docs/rules/prevent-abbreviations.md index 337606285c..0103f173b7 100644 --- a/docs/rules/prevent-abbreviations.md +++ b/docs/rules/prevent-abbreviations.md @@ -123,13 +123,13 @@ The example below disables all the default replacements and enables a custom `cm ] ``` -### whitelist +### allowList Type: `object` -You can extend the default whitelist by passing the `whitelist` option. +You can extend the default allowList by passing the `allowList` option. -Unlike the `replacements` option, `whitelist` matches full identifier names case-sensitively. +Unlike the `replacements` option, `allowList` matches full identifier names case-sensitively. For example, if you want to report `props` → `properties` (enabled by default), but allow `getInitialProps`, you could use the following configuration. @@ -137,19 +137,19 @@ For example, if you want to report `props` → `properties` (enabled by default) "unicorn/prevent-abbreviations": [ "error", { - "whitelist": { + "allowList": { "getInitialProps": true } } ] ``` -### extendDefaultWhitelist +### extendDefaultAllowList Type: `boolean`\ Default: `true` -Pass `"extendDefaultWhitelist": false` to override the default `whitelist` completely. +Pass `"extendDefaultAllowList": false` to override the default `allowList` completely. ### checkDefaultAndNamespaceImports diff --git a/package.json b/package.json index 34faba0b4a..0f09420676 100644 --- a/package.json +++ b/package.json @@ -136,7 +136,9 @@ "error", { "replacements": { - "fn": false + "ref": { + "reference": true + } } } ] diff --git a/rules/filename-case.js b/rules/filename-case.js index 6eddcb4ffc..613b602ea0 100644 --- a/rules/filename-case.js +++ b/rules/filename-case.js @@ -16,7 +16,7 @@ const PLACEHOLDER_REGEX = new RegExp(PLACEHOLDER, 'i'); const isIgnoredChar = char => !/^[a-z\d-_$]$/i.test(char); const ignoredByDefault = new Set(['index.js', 'index.mjs', 'index.cjs', 'index.ts', 'index.tsx', 'index.vue']); -function ignoreNumbers(fn) { +function ignoreNumbers(caseFunction) { return string => { const stack = []; let execResult = numberRegex.exec(string); @@ -27,7 +27,7 @@ function ignoreNumbers(fn) { execResult = numberRegex.exec(string); } - let withCase = fn(string); + let withCase = caseFunction(string); while (stack.length > 0) { withCase = withCase.replace(PLACEHOLDER_REGEX, stack.shift()); @@ -80,12 +80,12 @@ function getChosenCases(options) { function validateFilename(words, caseFunctions) { return words .filter(({ignored}) => !ignored) - .every(({word}) => caseFunctions.some(fn => fn(word) === word)); + .every(({word}) => caseFunctions.some(caseFunction => caseFunction(word) === word)); } function fixFilename(words, caseFunctions, {leading, extension}) { const replacements = words - .map(({word, ignored}) => ignored ? [word] : caseFunctions.map(fn => fn(word))); + .map(({word, ignored}) => ignored ? [word] : caseFunctions.map(caseFunction => caseFunction(word))); const { samples: combinations diff --git a/rules/prefer-keyboard-event-key.js b/rules/prefer-keyboard-event-key.js index c73a05a108..72961171b6 100644 --- a/rules/prefer-keyboard-event-key.js +++ b/rules/prefer-keyboard-event-key.js @@ -103,10 +103,10 @@ const isPropertyOf = (node, eventNode) => { // The third argument is a condition function, as one passed to `Array#filter()` // Helpful if nearest node of type also needs to have some other property -const getMatchingAncestorOfType = (node, type, fn = () => true) => { +const getMatchingAncestorOfType = (node, type, testFunction = () => true) => { let current = node; while (current) { - if (current.type === type && fn(current)) { + if (current.type === type && testFunction(current)) { return current; } diff --git a/rules/prevent-abbreviations.js b/rules/prevent-abbreviations.js index 303e760e74..b78193c45d 100644 --- a/rules/prevent-abbreviations.js +++ b/rules/prevent-abbreviations.js @@ -261,8 +261,8 @@ const prepareOptions = ({ extendDefaultReplacements = true, replacements = {}, - extendDefaultWhitelist = true, - whitelist = {}, + extendDefaultAllowList = true, + allowList = {}, ignore = [] } = {}) => { @@ -270,9 +270,9 @@ const prepareOptions = ({ defaultsDeep({}, replacements, defaultReplacements) : replacements; - const mergedWhitelist = extendDefaultWhitelist ? - defaultsDeep({}, whitelist, defaultAllowList) : - whitelist; + const mergedAllowList = extendDefaultAllowList ? + defaultsDeep({}, allowList, defaultAllowList) : + allowList; ignore = ignore.map( pattern => pattern instanceof RegExp ? pattern : new RegExp(pattern, 'u') @@ -294,15 +294,15 @@ const prepareOptions = ({ [discouragedName, new Map(Object.entries(replacements))] ) ), - whitelist: new Map(Object.entries(mergedWhitelist)), + allowList: new Map(Object.entries(mergedAllowList)), ignore }; }; -const getWordReplacements = (word, {replacements, whitelist}) => { - // Skip constants and whitelist - if (isUpperCase(word) || whitelist.get(word)) { +const getWordReplacements = (word, {replacements, allowList}) => { + // Skip constants and allowList + if (isUpperCase(word) || allowList.get(word)) { return []; } @@ -322,10 +322,10 @@ const getWordReplacements = (word, {replacements, whitelist}) => { }; const getNameReplacements = (name, options, limit = 3) => { - const {whitelist, ignore} = options; + const {allowList, ignore} = options; - // Skip constants and whitelist - if (isUpperCase(name) || whitelist.get(name) || ignore.some(regexp => regexp.test(name))) { + // Skip constants and allowList + if (isUpperCase(name) || allowList.get(name) || ignore.some(regexp => regexp.test(name))) { return {total: 0}; } @@ -818,10 +818,10 @@ const schema = [ replacements: { $ref: '#/items/0/definitions/abbreviations' }, - extendDefaultWhitelist: { + extendDefaultAllowList: { type: 'boolean' }, - whitelist: { + allowList: { $ref: '#/items/0/definitions/booleanObject' }, ignore: { diff --git a/test/prevent-abbreviations.mjs b/test/prevent-abbreviations.mjs index 8d55027fa3..417848df5d 100644 --- a/test/prevent-abbreviations.mjs +++ b/test/prevent-abbreviations.mjs @@ -107,21 +107,21 @@ const checkPropertiesOptions = [ } ]; -const extendDefaultWhitelistOptions = [ +const extendDefaultAllowListOptions = [ { - whitelist: { + allowList: { err: true }, - extendDefaultWhitelist: true + extendDefaultAllowList: true } ]; -const noExtendDefaultWhitelistOptions = [ +const noExtendDefaultAllowListOptions = [ { - whitelist: { + allowList: { err: true }, - extendDefaultWhitelist: false + extendDefaultAllowList: false } ]; @@ -275,10 +275,10 @@ ruleTester.run('prevent-abbreviations', rule, { filename: 'err/http-error.js' }, - // `extendDefaultWhitelist` option + // `extendDefaultAllowList` option { code: 'const propTypes = 2;const err = 2;', - options: extendDefaultWhitelistOptions + options: extendDefaultAllowListOptions }, // `ignore` option @@ -1311,11 +1311,11 @@ ruleTester.run('prevent-abbreviations', rule, { errors: createErrors('The filename `cb.js` should be named `circuitBreacker.js`. A more descriptive name will do too.') }, - // `extendDefaultWhitelist` option + // `extendDefaultAllowList` option { code: 'const propTypes = 2;const err = 2;', output: 'const propertyTypes = 2;const err = 2;', - options: noExtendDefaultWhitelistOptions, + options: noExtendDefaultAllowListOptions, errors: createErrors() } ]