UNPKG

@wise/eslint-config

Version:
207 lines (206 loc) 7 kB
import path from 'node:path'; import { fileURLToPath } from 'node:url'; import { fixupConfigRules } from '@eslint/compat'; import { FlatCompat } from '@eslint/eslintrc'; import js from '@eslint/js'; import transferwise from '@transferwise/eslint-plugin'; import jsxA11y from 'eslint-plugin-jsx-a11y'; import react from 'eslint-plugin-react'; import { defineConfig } from './_defineConfig.js'; const __filename = fileURLToPath(import.meta.url); const __dirname = path.dirname(__filename); const compat = new FlatCompat({ baseDirectory: __dirname, recommendedConfig: js.configs.recommended, allConfig: js.configs.all, }); export default defineConfig([ react.configs.flat.recommended, react.configs.flat['jsx-runtime'], jsxA11y.flatConfigs.recommended, // TODO: Still doesn't support flat config ...fixupConfigRules(...compat.extends('plugin:react-hooks/recommended')), { plugins: { '@transferwise': transferwise, }, settings: { react: { version: 'detect', }, linkComponents: [ { name: 'Link', linkAttribute: ['href', 'to'], }, ], 'jsx-a11y': { components: { ActionButton: 'button', Button: 'button', Checkbox: 'input', CircularButton: 'button', DateInput: 'input', DateLookup: 'input', InputWithDisplayFormat: 'input', Link: 'a', MoneyInput: 'input', PhoneNumberInput: 'input', Radio: 'input', SearchInput: 'input', SelectInput: 'input', Typeahead: 'input', UploadInput: 'input', }, }, }, rules: { '@transferwise/form-has-method-attribute': 'error', 'react/button-has-type': 'error', 'react/checked-requires-onchange-or-readonly': 'warn', 'react/default-props-match-prop-types': 'error', 'react/destructuring-assignment': 'warn', 'react/display-name': ['warn'], 'react/forbid-foreign-prop-types': [ 'warn', { allowInPropTypes: true, }, ], 'react/forbid-prop-types': [ 'warn', { checkContextTypes: true, checkChildContextTypes: true, }, ], 'react/function-component-definition': [ 'off', { namedComponents: ['function-declaration', 'function-expression'], unnamedComponents: 'function-expression', }, ], 'react/hook-use-state': 'off', 'react/iframe-missing-sandbox': 'error', 'react/jsx-boolean-value': 'warn', 'react/jsx-curly-brace-presence': [ 'warn', { propElementValues: 'always', }, ], 'react/jsx-filename-extension': [ 'off', { extensions: ['.jsx', '.tsx'], ignoreFilesWithoutCode: true, }, ], 'react/jsx-fragments': 'warn', 'react/jsx-handler-names': 'off', 'react/jsx-key': [ 'error', { checkFragmentShorthand: true, checkKeyMustBeforeSpread: true, warnOnDuplicates: true, }, ], 'react/jsx-no-bind': [ 'warn', { ignoreRefs: true, allowArrowFunctions: true, }, ], 'react/jsx-no-constructed-context-values': 'error', 'react/jsx-no-duplicate-props': [ 'error', { ignoreCase: true, }, ], 'react/jsx-no-leaked-render': [ 'off', { validStrategies: ['ternary'], }, ], 'react/jsx-no-script-url': [ 'error', { includeFromSettings: true, }, ], 'react/jsx-no-target-blank': [ 'error', { warnOnSpreadAttributes: true, }, ], 'react/jsx-no-useless-fragment': [ 'warn', { allowExpressions: true, }, ], 'react/jsx-pascal-case': [ 'error', { allowAllCaps: true, }, ], 'react/jsx-sort-props': [ 'warn', { callbacksLast: true, noSortAlphabetically: true, reservedFirst: true, }, ], 'react/no-access-state-in-setstate': 'error', 'react/no-array-index-key': 'warn', 'react/no-arrow-function-lifecycle': 'warn', 'react/no-danger': 'warn', 'react/no-did-update-set-state': 'error', 'react/no-invalid-html-attribute': 'error', 'react/no-namespace': 'error', 'react/no-object-type-as-default-prop': 'error', 'react/no-redundant-should-component-update': 'warn', 'react/no-string-refs': [ 'error', { noTemplateLiterals: true, }, ], 'react/no-this-in-sfc': 'error', 'react/no-typos': 'error', 'react/no-unstable-nested-components': 'error', 'react/no-unused-class-component-methods': 'warn', 'react/no-unused-prop-types': 'off', 'react/no-unused-state': 'warn', 'react/no-will-update-set-state': 'error', 'react/prefer-es6-class': 'warn', 'react/prefer-stateless-function': 'warn', 'react/self-closing-comp': 'warn', 'react/sort-comp': 'off', 'react/sort-prop-types': [ 'warn', { callbacksLast: true, noSortAlphabetically: true, }, ], 'react/style-prop-object': 'error', 'react/void-dom-elements-no-children': 'error', curly: 'warn', }, }, { files: ['**/*.tsx'], rules: { 'react/prop-types': 'off', }, }, ]);