|
|
const path = require( 'path' ); |
|
|
const { nodeConfig } = require( '@automattic/calypso-eslint-overrides' ); |
|
|
const { merge } = require( 'lodash' ); |
|
|
const reactVersion = require( './client/package.json' ).dependencies.react; |
|
|
|
|
|
module.exports = { |
|
|
root: true, |
|
|
parser: '@typescript-eslint/parser', |
|
|
parserOptions: { |
|
|
babelOptions: { |
|
|
configFile: path.join( __dirname, './babel.config.js' ), |
|
|
}, |
|
|
}, |
|
|
extends: [ |
|
|
'plugin:wpcalypso/react', |
|
|
'plugin:jsx-a11y/recommended', |
|
|
'plugin:jest/recommended', |
|
|
'plugin:prettier/recommended', |
|
|
'plugin:@tanstack/eslint-plugin-query/recommended', |
|
|
'plugin:md/prettier', |
|
|
'plugin:@wordpress/eslint-plugin/i18n', |
|
|
], |
|
|
overrides: [ |
|
|
{ |
|
|
|
|
|
files: [ '**/*.jsx' ], |
|
|
}, |
|
|
{ |
|
|
files: [ '*.md' ], |
|
|
parser: 'markdown-eslint-parser', |
|
|
rules: { |
|
|
'md/remark': [ |
|
|
'error', |
|
|
{ |
|
|
plugins: [ |
|
|
|
|
|
|
|
|
...require( 'eslint-plugin-md' ).configs.prettier.rules[ 'md/remark' ][ 1 ].plugins, |
|
|
|
|
|
|
|
|
[ 'lint-maximum-heading-length', false ], |
|
|
[ 'lint-no-duplicate-headings', false ], |
|
|
|
|
|
|
|
|
[ 'lint-fenced-code-flag', false ], |
|
|
|
|
|
|
|
|
[ 'message-control', { name: 'eslint', source: 'remark-lint' } ], |
|
|
], |
|
|
}, |
|
|
], |
|
|
}, |
|
|
}, |
|
|
{ |
|
|
files: [ 'packages/**/*' ], |
|
|
rules: { |
|
|
|
|
|
'no-restricted-imports': [ 'error', { patterns: [ 'calypso/*' ] } ], |
|
|
'no-restricted-modules': [ 'error', { patterns: [ 'calypso/*' ] } ], |
|
|
}, |
|
|
}, |
|
|
{ |
|
|
files: [ '**/bin/**/*', '**/test/**/*', 'webpack.config.js' ], |
|
|
...nodeConfig, |
|
|
}, |
|
|
{ |
|
|
files: [ '**/test/**/*' ], |
|
|
rules: { |
|
|
'react/display-name': 'off', |
|
|
}, |
|
|
}, |
|
|
merge( |
|
|
|
|
|
|
|
|
{}, |
|
|
|
|
|
require( '@typescript-eslint/eslint-plugin' ).configs.base, |
|
|
|
|
|
{ rules: require( '@typescript-eslint/eslint-plugin' ).configs.recommended.rules }, |
|
|
|
|
|
|
|
|
{ |
|
|
rules: require( '@typescript-eslint/eslint-plugin' ).configs[ 'eslint-recommended' ] |
|
|
.overrides[ 0 ].rules, |
|
|
}, |
|
|
|
|
|
require( 'eslint-config-prettier' ), |
|
|
|
|
|
{ |
|
|
files: [ '**/*.ts', '**/*.tsx' ], |
|
|
rules: { |
|
|
|
|
|
|
|
|
'brace-style': 'off', |
|
|
'comma-dangle': 'off', |
|
|
'comma-spacing': 'off', |
|
|
curly: 'error', |
|
|
'default-param-last': 'off', |
|
|
'dot-notation': 'off', |
|
|
'func-call-spacing': 'off', |
|
|
indent: 'off', |
|
|
'init-declarations': 'off', |
|
|
'keyword-spacing': 'off', |
|
|
'lines-between-class-members': 'off', |
|
|
'no-array-constructor': 'off', |
|
|
'no-dupe-class-members': 'off', |
|
|
'no-duplicate-imports': 'off', |
|
|
'no-empty-function': 'off', |
|
|
'no-extra-parens': 'off', |
|
|
'no-extra-semi': 'off', |
|
|
'no-invalid-this': 'off', |
|
|
'no-loop-func': 'off', |
|
|
'no-loss-of-precision': 'off', |
|
|
'no-magic-numbers': 'off', |
|
|
'no-redeclare': 'off', |
|
|
'no-shadow': 'off', |
|
|
'no-unused-expressions': 'off', |
|
|
'no-unused-vars': 'off', |
|
|
'no-use-before-define': 'off', |
|
|
'no-useless-constructor': 'off', |
|
|
quotes: [ 'error', 'single', 'avoid-escape' ], |
|
|
'require-await': 'off', |
|
|
'return-await': 'off', |
|
|
semi: 'off', |
|
|
'space-before-function-paren': 'off', |
|
|
'@typescript-eslint/ban-ts-comment': [ |
|
|
'error', |
|
|
{ |
|
|
'ts-check': 'allow-with-description', |
|
|
'ts-expect-error': 'allow-with-description', |
|
|
'ts-ignore': 'allow-with-description', |
|
|
'ts-nocheck': 'allow-with-description', |
|
|
}, |
|
|
], |
|
|
'@typescript-eslint/ban-types': [ |
|
|
'error', |
|
|
{ |
|
|
types: { |
|
|
ReactText: { |
|
|
message: |
|
|
"It's deprecated, so we don't want new uses. Inline the required type (such as string or number) instead.", |
|
|
}, |
|
|
[ 'React.ReactText' ]: { |
|
|
message: |
|
|
"It's deprecated, so we don't want new uses. Inline the required type (such as string or number) instead.", |
|
|
}, |
|
|
ReactChild: { |
|
|
message: |
|
|
"It's deprecated, so we don't want new uses. Prefer types like ReactElement, string, or number instead. If the type should be nullable, use ReactNode.", |
|
|
}, |
|
|
[ 'React.ReactChild' ]: { |
|
|
message: |
|
|
"It's deprecated, so we don't want new uses. Prefer types like ReactElement, string, or number instead. If the type should be nullable, use ReactNode.", |
|
|
}, |
|
|
}, |
|
|
extendDefaults: true, |
|
|
}, |
|
|
], |
|
|
'@typescript-eslint/no-explicit-any': 'warn', |
|
|
'@typescript-eslint/explicit-function-return-type': 'off', |
|
|
'@typescript-eslint/explicit-member-accessibility': 'off', |
|
|
'@typescript-eslint/no-unused-vars': [ 'error', { ignoreRestSiblings: true } ], |
|
|
'@typescript-eslint/no-use-before-define': [ |
|
|
'error', |
|
|
{ functions: false, typedefs: false }, |
|
|
], |
|
|
'@typescript-eslint/no-var-requires': 'off', |
|
|
|
|
|
'@typescript-eslint/camelcase': 'off', |
|
|
|
|
|
|
|
|
'import/no-extraneous-dependencies': 'off', |
|
|
'import/named': 'off', |
|
|
'import/namespace': 'off', |
|
|
'import/default': 'off', |
|
|
}, |
|
|
} |
|
|
), |
|
|
{ |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
files: [ |
|
|
'*.md.js', |
|
|
'*.md.javascript', |
|
|
'*.md.cjs', |
|
|
'*.md.ejs', |
|
|
'*.md.jsx', |
|
|
'*.md.tsx', |
|
|
'*.md.ts', |
|
|
], |
|
|
rules: { |
|
|
|
|
|
'import/no-extraneous-dependencies': 'off', |
|
|
'jest/expect-expect': 'off', |
|
|
'jest/no-focused-tests': 'off', |
|
|
'jest/no-standalone-expect': 'off', |
|
|
'jsdoc/require-param-description': 'off', |
|
|
'no-console': 'off', |
|
|
'no-redeclare': 'off', |
|
|
'no-restricted-imports': 'off', |
|
|
'no-undef': 'off', |
|
|
'no-unused-vars': 'off', |
|
|
'react/jsx-no-undef': 'off', |
|
|
'react/jsx-uses-react': 'off', |
|
|
'react/react-in-jsx-scope': 'off', |
|
|
'wpcalypso/jsx-classname-namespace': 'off', |
|
|
'@typescript-eslint/no-unused-vars': 'off', |
|
|
'jsdoc/require-param': 'off', |
|
|
'jsdoc/check-param-names': 'off', |
|
|
'@typescript-eslint/no-empty-function': 'off', |
|
|
'prettier/prettier': [ 'error', { parser: 'babel' } ], |
|
|
}, |
|
|
}, |
|
|
{ |
|
|
files: [ '*.json' ], |
|
|
extends: [ 'plugin:@automattic/json/recommended' ], |
|
|
rules: { |
|
|
|
|
|
'comma-dangle': 'off', |
|
|
'json-es/no-comments': 'error', |
|
|
}, |
|
|
overrides: [ |
|
|
{ |
|
|
|
|
|
files: [ 'package.json' ], |
|
|
rules: { |
|
|
'@automattic/json/prefer-property-order': 'off', |
|
|
'@automattic/json/require-keywords': 'off', |
|
|
'@automattic/json/require-repository-directory': 'error', |
|
|
'@automattic/json/valid-values-author': [ 'error', [ 'Automattic Inc.' ] ], |
|
|
'@automattic/json/valid-values-license': [ 'error', [ 'GPL-2.0-or-later' ] ], |
|
|
'@automattic/json/valid-values-name-scope': [ 'error', [ '@automattic' ] ], |
|
|
'@automattic/json/valid-values-publishConfig': [ 'error', [ { access: 'public' } ] ], |
|
|
}, |
|
|
}, |
|
|
{ |
|
|
files: [ './config/*.json' ], |
|
|
rules: { |
|
|
'sort-keys': 'warn', |
|
|
}, |
|
|
}, |
|
|
{ |
|
|
|
|
|
files: [ |
|
|
'./package.json', |
|
|
'./client/package.json', |
|
|
'./desktop/package.json', |
|
|
'./test/e2e/package.json', |
|
|
'./packages/wpcom-proxy-request/package.json', |
|
|
'./packages/wpcom-xhr-request/package.json', |
|
|
'./packages/wpcom.js/package.json', |
|
|
'./packages/eslint-plugin-wpcalypso/package.json', |
|
|
'./packages/i18n-calypso-cli/package.json', |
|
|
'./packages/i18n-calypso/package.json', |
|
|
'./packages/i18n-utils/package.json', |
|
|
'./packages/photon/package.json', |
|
|
], |
|
|
rules: { |
|
|
'@automattic/json/valid-values-name-scope': 'off', |
|
|
}, |
|
|
}, |
|
|
{ |
|
|
|
|
|
files: [ |
|
|
'./desktop/package.json', |
|
|
'./packages/material-design-icons/package.json', |
|
|
'./packages/wpcom-proxy-request/package.json', |
|
|
'./packages/wpcom-xhr-request/package.json', |
|
|
'./packages/wpcom.js/package.json', |
|
|
], |
|
|
rules: { |
|
|
'@automattic/json/valid-values-license': 'off', |
|
|
}, |
|
|
}, |
|
|
{ |
|
|
|
|
|
files: [ './client/**/package.json' ], |
|
|
excludedFiles: './client/package.json', |
|
|
rules: { |
|
|
'@automattic/json/require-repository-directory': 'off', |
|
|
'@automattic/json/valid-values-name-scope': 'off', |
|
|
'@automattic/json/require-author': 'off', |
|
|
'@automattic/json/require-description': 'off', |
|
|
'@automattic/json/require-license': 'off', |
|
|
'@automattic/json/require-name': 'off', |
|
|
'@automattic/json/require-version': 'off', |
|
|
}, |
|
|
}, |
|
|
{ |
|
|
|
|
|
files: [ 'tsconfig.json' ], |
|
|
rules: { |
|
|
'json-es/no-comments': 'off', |
|
|
}, |
|
|
}, |
|
|
], |
|
|
}, |
|
|
], |
|
|
env: { |
|
|
jest: true, |
|
|
node: true, |
|
|
}, |
|
|
globals: { |
|
|
|
|
|
|
|
|
|
|
|
globalThis: true, |
|
|
window: true, |
|
|
document: true, |
|
|
|
|
|
asyncRequire: true, |
|
|
|
|
|
COMMIT_SHA: true, |
|
|
|
|
|
BUILD_TIMESTAMP: true, |
|
|
}, |
|
|
plugins: [ 'import', 'you-dont-need-lodash-underscore', '@tanstack/query' ], |
|
|
settings: { |
|
|
react: { |
|
|
version: reactVersion, |
|
|
}, |
|
|
jsdoc: { |
|
|
mode: 'typescript', |
|
|
}, |
|
|
'import/internal-regex': '^calypso/', |
|
|
}, |
|
|
rules: { |
|
|
|
|
|
camelcase: 'off', |
|
|
|
|
|
|
|
|
curly: 'error', |
|
|
|
|
|
'no-constant-condition': [ 'error', { checkLoops: false } ], |
|
|
|
|
|
'no-path-concat': 'error', |
|
|
|
|
|
'one-var': [ 'error', 'never' ], |
|
|
|
|
|
|
|
|
'jest/valid-expect': 'off', |
|
|
|
|
|
'jest/expect-expect': [ |
|
|
'error', |
|
|
{ |
|
|
assertFunctionNames: [ |
|
|
|
|
|
'expect', |
|
|
], |
|
|
}, |
|
|
], |
|
|
|
|
|
|
|
|
'jsdoc/check-tag-names': [ |
|
|
'error', |
|
|
{ definedTags: [ 'jest-environment', 'jsxImportSource' ] }, |
|
|
], |
|
|
|
|
|
|
|
|
'jsdoc/require-param-description': 'off', |
|
|
'jsdoc/require-param': 'off', |
|
|
'jsdoc/require-returns-description': 'off', |
|
|
|
|
|
|
|
|
'jsx-a11y/label-has-for': 'off', |
|
|
|
|
|
|
|
|
'jsx-a11y/anchor-has-content': 'off', |
|
|
|
|
|
|
|
|
|
|
|
'jsx-a11y/no-onchange': 'off', |
|
|
|
|
|
'no-restricted-imports': [ |
|
|
2, |
|
|
{ |
|
|
paths: [ |
|
|
|
|
|
{ |
|
|
name: 'gridicons', |
|
|
message: "Please use '@automattic/components' instead.", |
|
|
}, |
|
|
|
|
|
{ |
|
|
name: 'redux', |
|
|
importNames: [ 'combineReducers' ], |
|
|
message: "`combineReducers` should be imported from 'state/utils', not 'redux'.", |
|
|
}, |
|
|
|
|
|
{ |
|
|
name: 'superagent', |
|
|
message: 'Please use native `fetch` instead.', |
|
|
}, |
|
|
|
|
|
{ |
|
|
name: '@wordpress/components', |
|
|
importNames: [ 'Dashicon', 'Icon' ], |
|
|
message: 'Please use `@wordpress/icons` instead.', |
|
|
}, |
|
|
|
|
|
{ |
|
|
name: 'url', |
|
|
message: |
|
|
"Node's `url` is deprecated. Please consider migrating to `lib/url` (see `client/lib/url/README.md`).", |
|
|
}, |
|
|
], |
|
|
}, |
|
|
], |
|
|
'no-restricted-modules': [ |
|
|
2, |
|
|
{ |
|
|
paths: [ |
|
|
|
|
|
{ |
|
|
name: 'gridicons', |
|
|
message: "Please use 'components/gridicon' instead.", |
|
|
}, |
|
|
|
|
|
{ |
|
|
name: 'superagent', |
|
|
message: 'Please use native `fetch` instead.', |
|
|
}, |
|
|
], |
|
|
}, |
|
|
], |
|
|
|
|
|
|
|
|
'no-unused-expressions': 'off', |
|
|
|
|
|
'react/forbid-foreign-prop-types': 'error', |
|
|
'react/display-name': 'error', |
|
|
'react/jsx-curly-brace-presence': [ 'error', { props: 'never', children: 'never' } ], |
|
|
'react/jsx-boolean-value': 'error', |
|
|
|
|
|
'wpcalypso/jsx-classname-namespace': 'error', |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
'import/no-nodejs-modules': [ 'error', { allow: [ 'url', 'events', 'path', 'config' ] } ], |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
'inclusive-language/use-inclusive-words': [ |
|
|
'warn', |
|
|
{ |
|
|
words: [], |
|
|
allowedTerms: [ |
|
|
|
|
|
|
|
|
{ term: 'masterbar', allowPartialMatches: true }, |
|
|
|
|
|
|
|
|
{ term: 'mastercard', allowPartialMatches: true }, |
|
|
|
|
|
|
|
|
'option_name_not_in_whitelist', |
|
|
|
|
|
|
|
|
'jetpack_protect_global_whitelist', |
|
|
|
|
|
|
|
|
|
|
|
'site_blacklisted', |
|
|
'blacklisted_domain', |
|
|
], |
|
|
}, |
|
|
], |
|
|
|
|
|
|
|
|
'import/no-extraneous-dependencies': 'error', |
|
|
'import/named': 'error', |
|
|
'import/namespace': 'error', |
|
|
'import/default': 'error', |
|
|
'import/no-duplicates': 'error', |
|
|
'import/order': [ |
|
|
'error', |
|
|
{ |
|
|
'newlines-between': 'never', |
|
|
alphabetize: { |
|
|
order: 'asc', |
|
|
}, |
|
|
groups: [ 'builtin', 'external', 'internal', 'parent', 'sibling', 'index', 'type' ], |
|
|
}, |
|
|
], |
|
|
|
|
|
'wpcalypso/no-unsafe-wp-apis': [ |
|
|
'warn', |
|
|
{ |
|
|
'@wordpress/block-editor': [ |
|
|
'__experimentalBlock', |
|
|
|
|
|
|
|
|
'__unstableInserterMenuExtension', |
|
|
'__experimentalInserterMenuExtension', |
|
|
], |
|
|
'@wordpress/compose': [ '__experimentalUseFocusOutside' ], |
|
|
'@wordpress/date': [ '__experimentalGetSettings' ], |
|
|
'@wordpress/edit-post': [ '__experimentalMainDashboardButton' ], |
|
|
'@wordpress/components': [ |
|
|
'__experimentalConfirmDialog', |
|
|
'__experimentalDivider', |
|
|
'__experimentalGrid', |
|
|
'__experimentalHStack', |
|
|
'__experimentalVStack', |
|
|
'__experimentalSpacer', |
|
|
'__experimentalText', |
|
|
'__experimentalHeading', |
|
|
'__experimentalItem', |
|
|
'__experimentalItemGroup', |
|
|
'__experimentalNavigationBackButton', |
|
|
'__experimentalNavigatorBackButton', |
|
|
'__experimentalNavigatorToParentButton', |
|
|
'__experimentalNavigatorButton', |
|
|
'__experimentalNavigatorProvider', |
|
|
'__experimentalNavigatorScreen', |
|
|
'__experimentalUseNavigator', |
|
|
'__experimentalNumberControl', |
|
|
'__unstableComposite', |
|
|
'__unstableCompositeItem', |
|
|
'__unstableUseCompositeState', |
|
|
], |
|
|
}, |
|
|
], |
|
|
|
|
|
|
|
|
'@wordpress/i18n-text-domain': 'off', |
|
|
|
|
|
|
|
|
'you-dont-need-lodash-underscore/all': 'error', |
|
|
'you-dont-need-lodash-underscore/any': 'error', |
|
|
'you-dont-need-lodash-underscore/assign': 'error', |
|
|
'you-dont-need-lodash-underscore/bind': 'error', |
|
|
'you-dont-need-lodash-underscore/cast-array': 'error', |
|
|
'you-dont-need-lodash-underscore/collect': 'error', |
|
|
'you-dont-need-lodash-underscore/contains': 'error', |
|
|
'you-dont-need-lodash-underscore/detect': 'error', |
|
|
'you-dont-need-lodash-underscore/drop': 'error', |
|
|
'you-dont-need-lodash-underscore/drop-right': 'error', |
|
|
'you-dont-need-lodash-underscore/each': 'error', |
|
|
'you-dont-need-lodash-underscore/ends-with': 'error', |
|
|
'you-dont-need-lodash-underscore/entries': 'error', |
|
|
'you-dont-need-lodash-underscore/every': 'error', |
|
|
'you-dont-need-lodash-underscore/extend-own': 'error', |
|
|
'you-dont-need-lodash-underscore/fill': 'error', |
|
|
'you-dont-need-lodash-underscore/first': 'error', |
|
|
'you-dont-need-lodash-underscore/foldl': 'error', |
|
|
'you-dont-need-lodash-underscore/foldr': 'error', |
|
|
'you-dont-need-lodash-underscore/index-of': 'error', |
|
|
'you-dont-need-lodash-underscore/inject': 'error', |
|
|
'you-dont-need-lodash-underscore/is-array': 'error', |
|
|
'you-dont-need-lodash-underscore/is-finite': 'error', |
|
|
'you-dont-need-lodash-underscore/is-function': 'error', |
|
|
'you-dont-need-lodash-underscore/is-integer': 'error', |
|
|
'you-dont-need-lodash-underscore/is-nan': 'error', |
|
|
'you-dont-need-lodash-underscore/is-nil': 'error', |
|
|
'you-dont-need-lodash-underscore/is-null': 'error', |
|
|
'you-dont-need-lodash-underscore/is-string': 'error', |
|
|
'you-dont-need-lodash-underscore/is-undefined': 'error', |
|
|
'you-dont-need-lodash-underscore/join': 'error', |
|
|
'you-dont-need-lodash-underscore/last-index-of': 'error', |
|
|
'you-dont-need-lodash-underscore/pad-end': 'error', |
|
|
'you-dont-need-lodash-underscore/pad-start': 'error', |
|
|
'you-dont-need-lodash-underscore/reduce-right': 'error', |
|
|
'you-dont-need-lodash-underscore/repeat': 'error', |
|
|
'you-dont-need-lodash-underscore/replace': 'error', |
|
|
'you-dont-need-lodash-underscore/reverse': 'error', |
|
|
'you-dont-need-lodash-underscore/select': 'error', |
|
|
'you-dont-need-lodash-underscore/slice': 'error', |
|
|
'you-dont-need-lodash-underscore/split': 'error', |
|
|
'you-dont-need-lodash-underscore/take-right': 'error', |
|
|
'you-dont-need-lodash-underscore/to-lower': 'error', |
|
|
'you-dont-need-lodash-underscore/to-pairs': 'error', |
|
|
'you-dont-need-lodash-underscore/to-upper': 'error', |
|
|
'you-dont-need-lodash-underscore/uniq': 'error', |
|
|
|
|
|
|
|
|
|
|
|
'@tanstack/query/exhaustive-deps': 'warn', |
|
|
'@wordpress/i18n-no-flanking-whitespace': 'warn', |
|
|
'@wordpress/i18n-hyphenated-range': 'warn', |
|
|
}, |
|
|
}; |
|
|
|