From bb44b4428784ef4766ed5896d570f7d7d14ca14c Mon Sep 17 00:00:00 2001 From: Mike Jolley Date: Thu, 20 Apr 2023 13:53:25 +0100 Subject: [PATCH] Add eslint rule to restrict lodash import --- .eslintrc.js | 124 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 124 insertions(+) diff --git a/.eslintrc.js b/.eslintrc.js index 8121a04e34b..dc20ccdcdf7 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -1,3 +1,121 @@ +const restrictedImports = [ + { + name: 'lodash', + importNames: [ + 'camelCase', + 'capitalize', + 'castArray', + 'chunk', + 'clamp', + 'clone', + 'cloneDeep', + 'compact', + 'concat', + 'countBy', + 'debounce', + 'deburr', + 'defaults', + 'defaultTo', + 'delay', + 'difference', + 'differenceWith', + 'dropRight', + 'each', + 'escape', + 'escapeRegExp', + 'every', + 'extend', + 'filter', + 'find', + 'findIndex', + 'findKey', + 'findLast', + 'first', + 'flatMap', + 'flatten', + 'flattenDeep', + 'flow', + 'flowRight', + 'forEach', + 'fromPairs', + 'has', + 'identity', + 'includes', + 'invoke', + 'isArray', + 'isBoolean', + 'isEqual', + 'isFinite', + 'isFunction', + 'isMatch', + 'isNil', + 'isNumber', + 'isObject', + 'isObjectLike', + 'isPlainObject', + 'isString', + 'isUndefined', + 'keyBy', + 'keys', + 'last', + 'lowerCase', + 'map', + 'mapKeys', + 'maxBy', + 'memoize', + 'merge', + 'negate', + 'noop', + 'nth', + 'omit', + 'omitBy', + 'once', + 'orderby', + 'overEvery', + 'partial', + 'partialRight', + 'pick', + 'pickBy', + 'random', + 'reduce', + 'reject', + 'repeat', + 'reverse', + 'setWith', + 'size', + 'snakeCase', + 'some', + 'sortBy', + 'startCase', + 'startsWith', + 'stubFalse', + 'stubTrue', + 'sum', + 'sumBy', + 'take', + 'throttle', + 'times', + 'toString', + 'trim', + 'truncate', + 'unescape', + 'unionBy', + 'uniq', + 'uniqBy', + 'uniqueId', + 'uniqWith', + 'upperFirst', + 'values', + 'without', + 'words', + 'xor', + 'zip', + ], + message: + 'This Lodash method is not recommended. Please use native functionality instead. If using `memoize`, please use `memize` instead.', + }, +]; + module.exports = { root: true, extends: [ @@ -71,6 +189,12 @@ module.exports = { allowedTextDomain: [ 'woo-gutenberg-products-block' ], }, ], + 'no-restricted-imports': [ + 'error', + { + paths: restrictedImports, + }, + ], '@typescript-eslint/no-restricted-imports': [ 'error', {