2023-04-28 10:29:45 +00:00
|
|
|
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.',
|
|
|
|
},
|
|
|
|
];
|
|
|
|
|
2018-11-13 19:21:04 +00:00
|
|
|
module.exports = {
|
2023-08-30 06:56:28 +00:00
|
|
|
env: {
|
|
|
|
browser: true,
|
2023-12-12 23:05:20 +00:00
|
|
|
jest: true,
|
2023-08-30 06:56:28 +00:00
|
|
|
},
|
2022-09-14 22:00:20 +00:00
|
|
|
root: true,
|
2021-01-05 13:58:18 +00:00
|
|
|
extends: [
|
|
|
|
'plugin:@woocommerce/eslint-plugin/recommended',
|
|
|
|
'plugin:you-dont-need-lodash-underscore/compatible',
|
2023-11-02 13:01:42 +00:00
|
|
|
'plugin:storybook/recommended',
|
2021-01-05 13:58:18 +00:00
|
|
|
],
|
2018-11-13 19:21:04 +00:00
|
|
|
globals: {
|
2021-04-22 11:37:27 +00:00
|
|
|
wcBlocksMiddlewareConfig: 'readonly',
|
2020-06-10 18:21:34 +00:00
|
|
|
fetchMock: true,
|
2020-07-14 19:46:44 +00:00
|
|
|
jQuery: 'readonly',
|
2020-08-20 14:14:12 +00:00
|
|
|
IntersectionObserver: 'readonly',
|
2020-09-07 17:31:10 +00:00
|
|
|
// @todo Move E2E related ESLint configuration into custom config.
|
|
|
|
//
|
|
|
|
// We should have linting properties only included for files that they
|
|
|
|
// are specific to as opposed to globally.
|
|
|
|
page: 'readonly',
|
|
|
|
browser: 'readonly',
|
|
|
|
context: 'readonly',
|
|
|
|
jestPuppeteer: 'readonly',
|
2018-11-13 19:21:04 +00:00
|
|
|
},
|
2020-09-20 23:54:08 +00:00
|
|
|
settings: {
|
|
|
|
jsdoc: { mode: 'typescript' },
|
2021-01-28 13:53:09 +00:00
|
|
|
// List of modules that are externals in our webpack config.
|
|
|
|
// This helps the `import/no-extraneous-dependencies` and
|
|
|
|
//`import/no-unresolved` rules account for them.
|
|
|
|
'import/core-modules': [
|
|
|
|
'@woocommerce/block-data',
|
|
|
|
'@woocommerce/blocks-checkout',
|
2023-10-17 09:47:34 +00:00
|
|
|
'@woocommerce/blocks-components',
|
2021-02-04 15:30:28 +00:00
|
|
|
'@woocommerce/price-format',
|
2021-01-28 13:53:09 +00:00
|
|
|
'@woocommerce/settings',
|
|
|
|
'@woocommerce/shared-context',
|
|
|
|
'@woocommerce/shared-hocs',
|
2022-08-12 14:23:08 +00:00
|
|
|
'@woocommerce/data',
|
2021-01-28 13:53:09 +00:00
|
|
|
'@wordpress/a11y',
|
|
|
|
'@wordpress/api-fetch',
|
|
|
|
'@wordpress/block-editor',
|
|
|
|
'@wordpress/compose',
|
|
|
|
'@wordpress/data',
|
2022-08-12 14:23:08 +00:00
|
|
|
'@wordpress/core-data',
|
|
|
|
'@wordpress/editor',
|
2021-01-28 13:53:09 +00:00
|
|
|
'@wordpress/escape-html',
|
|
|
|
'@wordpress/hooks',
|
|
|
|
'@wordpress/keycodes',
|
|
|
|
'@wordpress/url',
|
2022-05-23 12:05:30 +00:00
|
|
|
'@woocommerce/blocks-test-utils',
|
|
|
|
'@woocommerce/e2e-utils',
|
2023-08-10 14:02:33 +00:00
|
|
|
'@woocommerce/e2e-mocks',
|
2021-01-28 13:53:09 +00:00
|
|
|
'babel-jest',
|
|
|
|
'dotenv',
|
|
|
|
'jest-environment-puppeteer',
|
|
|
|
'lodash/kebabCase',
|
|
|
|
'lodash',
|
|
|
|
'prop-types',
|
|
|
|
'react',
|
|
|
|
'requireindex',
|
2023-04-05 12:43:03 +00:00
|
|
|
'react-transition-group',
|
2021-01-28 13:53:09 +00:00
|
|
|
],
|
|
|
|
'import/resolver': {
|
|
|
|
node: {},
|
|
|
|
webpack: {},
|
2021-02-24 01:36:24 +00:00
|
|
|
typescript: {},
|
2021-01-28 13:53:09 +00:00
|
|
|
},
|
2020-09-20 23:54:08 +00:00
|
|
|
},
|
2018-11-13 19:21:04 +00:00
|
|
|
rules: {
|
2020-06-05 19:13:51 +00:00
|
|
|
'woocommerce/feature-flag': 'off',
|
2020-10-28 09:14:46 +00:00
|
|
|
'react-hooks/exhaustive-deps': 'error',
|
2020-12-14 11:54:34 +00:00
|
|
|
'react/jsx-fragments': [ 'error', 'syntax' ],
|
2021-01-11 12:12:26 +00:00
|
|
|
'@wordpress/no-global-active-element': 'warn',
|
2021-11-08 09:06:29 +00:00
|
|
|
'@wordpress/i18n-text-domain': [
|
|
|
|
'error',
|
|
|
|
{
|
2023-12-12 23:05:20 +00:00
|
|
|
allowedTextDomain: [ 'woocommerce' ],
|
2021-11-08 09:06:29 +00:00
|
|
|
},
|
|
|
|
],
|
2023-04-28 10:29:45 +00:00
|
|
|
'no-restricted-imports': [
|
|
|
|
'error',
|
|
|
|
{
|
|
|
|
paths: restrictedImports,
|
|
|
|
},
|
|
|
|
],
|
2023-03-02 14:26:00 +00:00
|
|
|
'@typescript-eslint/no-restricted-imports': [
|
|
|
|
'error',
|
|
|
|
{
|
|
|
|
paths: [
|
|
|
|
{
|
|
|
|
name: 'react',
|
|
|
|
message:
|
|
|
|
'Please use React API through `@wordpress/element` instead.',
|
|
|
|
allowTypeImports: true,
|
|
|
|
},
|
|
|
|
],
|
|
|
|
},
|
|
|
|
],
|
2021-07-09 16:53:45 +00:00
|
|
|
camelcase: [
|
|
|
|
'error',
|
|
|
|
{
|
|
|
|
properties: 'never',
|
|
|
|
ignoreGlobals: true,
|
|
|
|
},
|
|
|
|
],
|
2022-11-11 19:14:18 +00:00
|
|
|
'react/react-in-jsx-scope': 'off',
|
2019-09-05 15:09:31 +00:00
|
|
|
},
|
2021-01-05 13:58:18 +00:00
|
|
|
overrides: [
|
2023-11-20 12:06:12 +00:00
|
|
|
{
|
|
|
|
files: [ '**/tests/e2e-jest/**' ],
|
|
|
|
rules: {
|
|
|
|
'jest/no-disabled-tests': 'off',
|
|
|
|
},
|
|
|
|
},
|
2021-01-05 13:58:18 +00:00
|
|
|
{
|
|
|
|
files: [ '**/bin/**.js', '**/storybook/**.js', '**/stories/**.js' ],
|
|
|
|
rules: {
|
|
|
|
'you-dont-need-lodash-underscore/omit': 'off',
|
|
|
|
},
|
|
|
|
},
|
2021-02-24 01:36:24 +00:00
|
|
|
{
|
|
|
|
files: [ '*.ts', '*.tsx' ],
|
|
|
|
parser: '@typescript-eslint/parser',
|
|
|
|
extends: [
|
|
|
|
'plugin:@woocommerce/eslint-plugin/recommended',
|
|
|
|
'plugin:you-dont-need-lodash-underscore/compatible',
|
|
|
|
'plugin:@typescript-eslint/recommended',
|
|
|
|
],
|
|
|
|
rules: {
|
|
|
|
'@typescript-eslint/no-explicit-any': 'error',
|
|
|
|
'no-use-before-define': 'off',
|
|
|
|
'@typescript-eslint/no-use-before-define': [ 'error' ],
|
|
|
|
'jsdoc/require-param': 'off',
|
2021-03-09 10:50:51 +00:00
|
|
|
'no-shadow': 'off',
|
|
|
|
'@typescript-eslint/no-shadow': [ 'error' ],
|
2021-05-16 17:59:32 +00:00
|
|
|
'@typescript-eslint/no-unused-vars': [
|
|
|
|
'error',
|
|
|
|
{ ignoreRestSiblings: true },
|
|
|
|
],
|
2021-07-09 16:53:45 +00:00
|
|
|
camelcase: 'off',
|
|
|
|
'@typescript-eslint/naming-convention': [
|
|
|
|
'error',
|
|
|
|
{
|
|
|
|
selector: [ 'method', 'variableLike' ],
|
|
|
|
format: [ 'camelCase', 'PascalCase', 'UPPER_CASE' ],
|
|
|
|
leadingUnderscore: 'allowSingleOrDouble',
|
|
|
|
filter: {
|
|
|
|
regex: 'webpack_public_path__',
|
|
|
|
match: false,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
selector: 'typeProperty',
|
|
|
|
format: [ 'camelCase', 'snake_case' ],
|
|
|
|
filter: {
|
|
|
|
regex: 'API_FETCH_WITH_HEADERS|Block',
|
|
|
|
match: false,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
],
|
2022-11-11 19:14:18 +00:00
|
|
|
'react/react-in-jsx-scope': 'off',
|
2021-02-24 01:36:24 +00:00
|
|
|
},
|
|
|
|
},
|
2021-03-10 15:03:26 +00:00
|
|
|
{
|
|
|
|
files: [ './assets/js/mapped-types.ts' ],
|
|
|
|
rules: {
|
|
|
|
'@typescript-eslint/no-explicit-any': 'off',
|
|
|
|
'@typescript-eslint/no-shadow': 'off',
|
|
|
|
'no-shadow': 'off',
|
|
|
|
},
|
|
|
|
},
|
2021-01-05 13:58:18 +00:00
|
|
|
],
|
2018-11-13 19:21:04 +00:00
|
|
|
};
|