|
| 1 | +'use strict'; |
| 2 | + |
| 3 | +const restrictedGlobals = require('confusing-browser-globals'); |
| 4 | + |
| 5 | +const OFF = 'off'; |
| 6 | +const ERROR = 'error'; |
| 7 | + |
| 8 | +// Files that are transformed and can use ES6/JSX. |
| 9 | +const esNextPaths = [ |
| 10 | + // Internal forwarding modules |
| 11 | + './index.js', |
| 12 | + // Source files |
| 13 | + 'src/**/*.js', |
| 14 | + // Jest |
| 15 | + 'scripts/jest/setupTests.js', |
| 16 | +]; |
| 17 | + |
| 18 | +// Files that we distribute on npm that should be ES5-only. |
| 19 | +const es5Paths = ['npm/**/*.js']; |
| 20 | + |
| 21 | +module.exports = { |
| 22 | + env: { |
| 23 | + browser: true, |
| 24 | + es6: true, |
| 25 | + node: true, |
| 26 | + }, |
| 27 | + extends: [ |
| 28 | + 'eslint:recommended', |
| 29 | + 'plugin:react/recommended', |
| 30 | + 'plugin:prettier/recommended', |
| 31 | + 'prettier/react', |
| 32 | + ], |
| 33 | + globals: { |
| 34 | + Atomics: 'readonly', |
| 35 | + SharedArrayBuffer: 'readonly', |
| 36 | + }, |
| 37 | + parser: 'babel-eslint', |
| 38 | + parserOptions: { |
| 39 | + ecmaVersion: 2018, |
| 40 | + sourceType: 'script', |
| 41 | + }, |
| 42 | + plugins: ['react'], |
| 43 | + settings: { |
| 44 | + react: { |
| 45 | + version: 'detect', |
| 46 | + }, |
| 47 | + }, |
| 48 | + rules: { |
| 49 | + 'no-console': ERROR, |
| 50 | + 'no-empty': OFF, |
| 51 | + 'no-restricted-globals': [ERROR, ...restrictedGlobals], |
| 52 | + 'no-unsafe-finally': OFF, |
| 53 | + 'no-unused-vars': [ERROR, {args: 'none'}], |
| 54 | + 'no-useless-escape': OFF, |
| 55 | + |
| 56 | + // We apply these settings to files that should run on Node. |
| 57 | + // They can't use JSX or ES6 modules, and must be in strict mode. |
| 58 | + // They can, however, use other ES6 features. |
| 59 | + // (Note these rules are overridden later for source files.) |
| 60 | + 'no-var': ERROR, |
| 61 | + strict: ERROR, |
| 62 | + }, |
| 63 | + overrides: [ |
| 64 | + { |
| 65 | + // We apply these settings to files that we ship through npm. |
| 66 | + // They must be ES5. |
| 67 | + files: es5Paths, |
| 68 | + parser: 'espree', |
| 69 | + parserOptions: { |
| 70 | + ecmaVersion: 5, |
| 71 | + sourceType: 'script', |
| 72 | + }, |
| 73 | + rules: { |
| 74 | + 'no-var': OFF, |
| 75 | + strict: ERROR, |
| 76 | + }, |
| 77 | + overrides: [ |
| 78 | + { |
| 79 | + // These files are ES5 but with ESM support. |
| 80 | + files: ['npm/esm/**/*.js'], |
| 81 | + parserOptions: { |
| 82 | + // Although this is supposed to be 5, ESLint doesn't allow sourceType 'module' when ecmaVersion < 2015. |
| 83 | + // See https://github.com/eslint/eslint/issues/9687#issuecomment-508448526 |
| 84 | + ecmaVersion: 2015, |
| 85 | + sourceType: 'module', |
| 86 | + }, |
| 87 | + }, |
| 88 | + ], |
| 89 | + }, |
| 90 | + { |
| 91 | + // We apply these settings to the source files that get compiled. |
| 92 | + // They can use all features including JSX (but shouldn't use `var`). |
| 93 | + files: esNextPaths, |
| 94 | + parserOptions: { |
| 95 | + ecmaVersion: 2018, |
| 96 | + sourceType: 'module', |
| 97 | + }, |
| 98 | + rules: { |
| 99 | + 'no-var': ERROR, |
| 100 | + strict: OFF, |
| 101 | + }, |
| 102 | + }, |
| 103 | + { |
| 104 | + // Rollup understands ESM |
| 105 | + files: ['rollup.config.js'], |
| 106 | + parserOptions: { |
| 107 | + ecmaVersion: 2018, |
| 108 | + sourceType: 'module', |
| 109 | + }, |
| 110 | + }, |
| 111 | + { |
| 112 | + files: ['**/__tests__/**/*.js', 'scripts/jest/setupTests.js'], |
| 113 | + env: { |
| 114 | + 'jest/globals': true, |
| 115 | + }, |
| 116 | + plugins: ['jest'], |
| 117 | + rules: { |
| 118 | + // https://github.com/jest-community/eslint-plugin-jest |
| 119 | + 'jest/no-focused-tests': ERROR, |
| 120 | + 'jest/valid-expect': ERROR, |
| 121 | + 'jest/valid-expect-in-promise': ERROR, |
| 122 | + |
| 123 | + // React & JSX |
| 124 | + // This isn't useful in our test code |
| 125 | + 'react/display-name': OFF, |
| 126 | + 'react/jsx-key': OFF, |
| 127 | + 'react/no-deprecated': OFF, |
| 128 | + 'react/no-string-refs': OFF, |
| 129 | + 'react/prop-types': OFF, |
| 130 | + }, |
| 131 | + }, |
| 132 | + { |
| 133 | + files: ['scripts/**/*.js', 'npm/**/*.js'], |
| 134 | + rules: { |
| 135 | + 'no-console': OFF, |
| 136 | + }, |
| 137 | + }, |
| 138 | + ], |
| 139 | +}; |
0 commit comments