|
| 1 | +/* Copyright 2020-2021 VMware, Inc. |
| 2 | + * SPDX-License-Identifier: MIT */ |
| 3 | + |
| 4 | +/** This file is from eslint-config-react-app but we removed flowtype. */ |
| 5 | + |
| 6 | +'use strict'; |
| 7 | + |
| 8 | +// Inspired by https://github.com/airbnb/javascript but less opinionated. |
| 9 | + |
| 10 | +// We use eslint-loader so even warnings are very visible. |
| 11 | +// This is why we prefer to use "WARNING" level for potential errors, |
| 12 | +// and we try not to use "ERROR" level at all. |
| 13 | + |
| 14 | +// In the future, we might create a separate list of rules for production. |
| 15 | +// It would probably be more strict. |
| 16 | + |
| 17 | +// The ESLint browser environment defines all browser globals as valid, |
| 18 | +// even though most people don't know some of them exist (e.g. `name` or `status`). |
| 19 | +// This is dangerous as it hides accidentally undefined variables. |
| 20 | +// We blacklist the globals that we deem potentially confusing. |
| 21 | +// To use them, explicitly reference them, e.g. `window.name` or `window.status`. |
| 22 | +const restrictedGlobals = require('confusing-browser-globals'); |
| 23 | + |
| 24 | +module.exports = { |
| 25 | + extends: [require.resolve('./base')], |
| 26 | + |
| 27 | + plugins: ['import', 'jsx-a11y', 'react-hooks'], |
| 28 | + |
| 29 | + overrides: [ |
| 30 | + { |
| 31 | + files: ['**/*.ts?(x)'], |
| 32 | + parser: '@typescript-eslint/parser', |
| 33 | + parserOptions: { |
| 34 | + ecmaVersion: 2018, |
| 35 | + sourceType: 'module', |
| 36 | + ecmaFeatures: { |
| 37 | + jsx: true, |
| 38 | + }, |
| 39 | + |
| 40 | + // typescript-eslint specific options |
| 41 | + warnOnUnsupportedTypeScriptVersion: true, |
| 42 | + }, |
| 43 | + plugins: ['@typescript-eslint'], |
| 44 | + // If adding a typescript-eslint version of an existing ESLint rule, |
| 45 | + // make sure to disable the ESLint rule here. |
| 46 | + rules: { |
| 47 | + // TypeScript's `noFallthroughCasesInSwitch` option is more robust (#6906) |
| 48 | + 'default-case': 'off', |
| 49 | + // 'tsc' already handles this (https://github.com/typescript-eslint/typescript-eslint/issues/291) |
| 50 | + 'no-dupe-class-members': 'off', |
| 51 | + // 'tsc' already handles this (https://github.com/typescript-eslint/typescript-eslint/issues/477) |
| 52 | + 'no-undef': 'off', |
| 53 | + |
| 54 | + // Add TypeScript specific rules (and turn off ESLint equivalents) |
| 55 | + '@typescript-eslint/consistent-type-assertions': 'warn', |
| 56 | + 'no-array-constructor': 'off', |
| 57 | + '@typescript-eslint/no-array-constructor': 'warn', |
| 58 | + 'no-redeclare': 'off', |
| 59 | + '@typescript-eslint/no-redeclare': 'warn', |
| 60 | + 'no-use-before-define': 'off', |
| 61 | + '@typescript-eslint/no-use-before-define': [ |
| 62 | + 'warn', |
| 63 | + { |
| 64 | + functions: false, |
| 65 | + classes: false, |
| 66 | + variables: false, |
| 67 | + typedefs: false, |
| 68 | + }, |
| 69 | + ], |
| 70 | + 'no-unused-expressions': 'off', |
| 71 | + '@typescript-eslint/no-unused-expressions': [ |
| 72 | + 'error', |
| 73 | + { |
| 74 | + allowShortCircuit: true, |
| 75 | + allowTernary: true, |
| 76 | + allowTaggedTemplates: true, |
| 77 | + }, |
| 78 | + ], |
| 79 | + 'no-unused-vars': 'off', |
| 80 | + '@typescript-eslint/no-unused-vars': [ |
| 81 | + 'warn', |
| 82 | + { |
| 83 | + args: 'none', |
| 84 | + ignoreRestSiblings: true, |
| 85 | + }, |
| 86 | + ], |
| 87 | + 'no-useless-constructor': 'off', |
| 88 | + '@typescript-eslint/no-useless-constructor': 'warn', |
| 89 | + }, |
| 90 | + }, |
| 91 | + ], |
| 92 | + |
| 93 | + // NOTE: When adding rules here, you need to make sure they are compatible with |
| 94 | + // `typescript-eslint`, as some rules such as `no-array-constructor` aren't compatible. |
| 95 | + rules: { |
| 96 | + // http://eslint.org/docs/rules/ |
| 97 | + 'array-callback-return': 'warn', |
| 98 | + 'default-case': ['warn', { commentPattern: '^no default$' }], |
| 99 | + 'dot-location': ['warn', 'property'], |
| 100 | + eqeqeq: ['warn', 'smart'], |
| 101 | + 'new-parens': 'warn', |
| 102 | + 'no-array-constructor': 'warn', |
| 103 | + 'no-caller': 'warn', |
| 104 | + 'no-cond-assign': ['warn', 'except-parens'], |
| 105 | + 'no-const-assign': 'warn', |
| 106 | + 'no-control-regex': 'warn', |
| 107 | + 'no-delete-var': 'warn', |
| 108 | + 'no-dupe-args': 'warn', |
| 109 | + 'no-dupe-class-members': 'warn', |
| 110 | + 'no-dupe-keys': 'warn', |
| 111 | + 'no-duplicate-case': 'warn', |
| 112 | + 'no-empty-character-class': 'warn', |
| 113 | + 'no-empty-pattern': 'warn', |
| 114 | + 'no-eval': 'warn', |
| 115 | + 'no-ex-assign': 'warn', |
| 116 | + 'no-extend-native': 'warn', |
| 117 | + 'no-extra-bind': 'warn', |
| 118 | + 'no-extra-label': 'warn', |
| 119 | + 'no-fallthrough': 'warn', |
| 120 | + 'no-func-assign': 'warn', |
| 121 | + 'no-implied-eval': 'warn', |
| 122 | + 'no-invalid-regexp': 'warn', |
| 123 | + 'no-iterator': 'warn', |
| 124 | + 'no-label-var': 'warn', |
| 125 | + 'no-labels': ['warn', { allowLoop: true, allowSwitch: false }], |
| 126 | + 'no-lone-blocks': 'warn', |
| 127 | + 'no-loop-func': 'warn', |
| 128 | + 'no-mixed-operators': [ |
| 129 | + 'warn', |
| 130 | + { |
| 131 | + groups: [ |
| 132 | + ['&', '|', '^', '~', '<<', '>>', '>>>'], |
| 133 | + ['==', '!=', '===', '!==', '>', '>=', '<', '<='], |
| 134 | + ['&&', '||'], |
| 135 | + ['in', 'instanceof'], |
| 136 | + ], |
| 137 | + allowSamePrecedence: false, |
| 138 | + }, |
| 139 | + ], |
| 140 | + 'no-multi-str': 'warn', |
| 141 | + 'no-native-reassign': 'warn', |
| 142 | + 'no-negated-in-lhs': 'warn', |
| 143 | + 'no-new-func': 'warn', |
| 144 | + 'no-new-object': 'warn', |
| 145 | + 'no-new-symbol': 'warn', |
| 146 | + 'no-new-wrappers': 'warn', |
| 147 | + 'no-obj-calls': 'warn', |
| 148 | + 'no-octal': 'warn', |
| 149 | + 'no-octal-escape': 'warn', |
| 150 | + 'no-redeclare': 'warn', |
| 151 | + 'no-regex-spaces': 'warn', |
| 152 | + 'no-restricted-syntax': ['warn', 'WithStatement'], |
| 153 | + 'no-script-url': 'warn', |
| 154 | + 'no-self-assign': 'warn', |
| 155 | + 'no-self-compare': 'warn', |
| 156 | + 'no-sequences': 'warn', |
| 157 | + 'no-shadow-restricted-names': 'warn', |
| 158 | + 'no-sparse-arrays': 'warn', |
| 159 | + 'no-template-curly-in-string': 'warn', |
| 160 | + 'no-this-before-super': 'warn', |
| 161 | + 'no-throw-literal': 'warn', |
| 162 | + 'no-undef': 'error', |
| 163 | + 'no-restricted-globals': ['error'].concat(restrictedGlobals), |
| 164 | + 'no-unreachable': 'warn', |
| 165 | + 'no-unused-expressions': [ |
| 166 | + 'error', |
| 167 | + { |
| 168 | + allowShortCircuit: true, |
| 169 | + allowTernary: true, |
| 170 | + allowTaggedTemplates: true, |
| 171 | + }, |
| 172 | + ], |
| 173 | + 'no-unused-labels': 'warn', |
| 174 | + 'no-unused-vars': [ |
| 175 | + 'warn', |
| 176 | + { |
| 177 | + args: 'none', |
| 178 | + ignoreRestSiblings: true, |
| 179 | + }, |
| 180 | + ], |
| 181 | + 'no-use-before-define': [ |
| 182 | + 'warn', |
| 183 | + { |
| 184 | + functions: false, |
| 185 | + classes: false, |
| 186 | + variables: false, |
| 187 | + }, |
| 188 | + ], |
| 189 | + 'no-useless-computed-key': 'warn', |
| 190 | + 'no-useless-concat': 'warn', |
| 191 | + 'no-useless-constructor': 'warn', |
| 192 | + 'no-useless-escape': 'warn', |
| 193 | + 'no-useless-rename': [ |
| 194 | + 'warn', |
| 195 | + { |
| 196 | + ignoreDestructuring: false, |
| 197 | + ignoreImport: false, |
| 198 | + ignoreExport: false, |
| 199 | + }, |
| 200 | + ], |
| 201 | + 'no-with': 'warn', |
| 202 | + 'no-whitespace-before-property': 'warn', |
| 203 | + 'react-hooks/exhaustive-deps': 'warn', |
| 204 | + 'require-yield': 'warn', |
| 205 | + 'rest-spread-spacing': ['warn', 'never'], |
| 206 | + strict: ['warn', 'never'], |
| 207 | + 'unicode-bom': ['warn', 'never'], |
| 208 | + 'use-isnan': 'warn', |
| 209 | + 'valid-typeof': 'warn', |
| 210 | + 'no-restricted-properties': [ |
| 211 | + 'error', |
| 212 | + { |
| 213 | + object: 'require', |
| 214 | + property: 'ensure', |
| 215 | + message: |
| 216 | + 'Please use import() instead. More info: https://facebook.github.io/create-react-app/docs/code-splitting', |
| 217 | + }, |
| 218 | + { |
| 219 | + object: 'System', |
| 220 | + property: 'import', |
| 221 | + message: |
| 222 | + 'Please use import() instead. More info: https://facebook.github.io/create-react-app/docs/code-splitting', |
| 223 | + }, |
| 224 | + ], |
| 225 | + 'getter-return': 'warn', |
| 226 | + |
| 227 | + // https://github.com/benmosher/eslint-plugin-import/tree/master/docs/rules |
| 228 | + 'import/first': 'error', |
| 229 | + 'import/no-amd': 'error', |
| 230 | + 'import/no-anonymous-default-export': 'warn', |
| 231 | + 'import/no-webpack-loader-syntax': 'error', |
| 232 | + |
| 233 | + // https://github.com/yannickcr/eslint-plugin-react/tree/master/docs/rules |
| 234 | + 'react/forbid-foreign-prop-types': ['warn', { allowInPropTypes: true }], |
| 235 | + 'react/jsx-no-comment-textnodes': 'warn', |
| 236 | + 'react/jsx-no-duplicate-props': 'warn', |
| 237 | + 'react/jsx-no-target-blank': 'warn', |
| 238 | + 'react/jsx-no-undef': 'error', |
| 239 | + 'react/jsx-pascal-case': [ |
| 240 | + 'warn', |
| 241 | + { |
| 242 | + allowAllCaps: true, |
| 243 | + ignore: [], |
| 244 | + }, |
| 245 | + ], |
| 246 | + 'react/no-danger-with-children': 'warn', |
| 247 | + // Disabled because of undesirable warnings |
| 248 | + // See https://github.com/facebook/create-react-app/issues/5204 for |
| 249 | + // blockers until its re-enabled |
| 250 | + 'react/no-deprecated': 'warn', |
| 251 | + 'react/no-direct-mutation-state': 'warn', |
| 252 | + 'react/no-is-mounted': 'warn', |
| 253 | + 'react/no-typos': 'error', |
| 254 | + 'react/require-render-return': 'error', |
| 255 | + 'react/style-prop-object': 'warn', |
| 256 | + |
| 257 | + // https://github.com/evcohen/eslint-plugin-jsx-a11y/tree/master/docs/rules |
| 258 | + 'jsx-a11y/alt-text': 'warn', |
| 259 | + 'jsx-a11y/anchor-has-content': 'warn', |
| 260 | + 'jsx-a11y/anchor-is-valid': [ |
| 261 | + 'warn', |
| 262 | + { |
| 263 | + aspects: ['noHref', 'invalidHref'], |
| 264 | + }, |
| 265 | + ], |
| 266 | + 'jsx-a11y/aria-activedescendant-has-tabindex': 'warn', |
| 267 | + 'jsx-a11y/aria-props': 'warn', |
| 268 | + 'jsx-a11y/aria-proptypes': 'warn', |
| 269 | + 'jsx-a11y/aria-role': ['warn', { ignoreNonDOM: true }], |
| 270 | + 'jsx-a11y/aria-unsupported-elements': 'warn', |
| 271 | + 'jsx-a11y/heading-has-content': 'warn', |
| 272 | + 'jsx-a11y/iframe-has-title': 'warn', |
| 273 | + 'jsx-a11y/img-redundant-alt': 'warn', |
| 274 | + 'jsx-a11y/no-access-key': 'warn', |
| 275 | + 'jsx-a11y/no-distracting-elements': 'warn', |
| 276 | + 'jsx-a11y/no-redundant-roles': 'warn', |
| 277 | + 'jsx-a11y/role-has-required-aria-props': 'warn', |
| 278 | + 'jsx-a11y/role-supports-aria-props': 'warn', |
| 279 | + 'jsx-a11y/scope': 'warn', |
| 280 | + |
| 281 | + // https://github.com/facebook/react/tree/master/packages/eslint-plugin-react-hooks |
| 282 | + 'react-hooks/rules-of-hooks': 'error', |
| 283 | + }, |
| 284 | +}; |
0 commit comments