|
| 1 | +import antfu from '@antfu/eslint-config'; |
| 2 | + |
| 3 | +export default antfu( |
| 4 | + { |
| 5 | + react: true, |
| 6 | + stylistic: { |
| 7 | + indent: 'tab', |
| 8 | + }, |
| 9 | + unicorn: { |
| 10 | + allRecommended: true, |
| 11 | + }, |
| 12 | + globals: [ |
| 13 | + 'browser', |
| 14 | + ], |
| 15 | + typescript: { |
| 16 | + overrides: { |
| 17 | + 'ts/method-signature-style': 'off', // Disagree and it breaks types https://github.com/typescript-eslint/typescript-eslint/issues/1991 |
| 18 | + 'ts/consistent-type-definitions': 'off', // Review later |
| 19 | + 'ts/explicit-function-return-type': [ |
| 20 | + 'error', |
| 21 | + { |
| 22 | + allowExpressions: true, |
| 23 | + }, |
| 24 | + ], |
| 25 | + }, |
| 26 | + }, |
| 27 | + rules: { |
| 28 | + 'react-refresh/only-export-components': 'off', // N/A |
| 29 | + 'react/no-missing-key': 'off', // N/A |
| 30 | + |
| 31 | + 'no-irregular-whitespace': 'off', // We do want to use non-breaking spaces |
| 32 | + 'jsdoc/check-alignment': 'off', // Can't autofix, tedious manual fix |
| 33 | + 'style/jsx-tag-spacing': 'off', // TODO: Later, together with JSX single quotes |
| 34 | + |
| 35 | + // Antfu style disagreements |
| 36 | + 'regexp/no-useless-character-class': 'off', // [/] is more readable than \/ |
| 37 | + 'style/object-curly-spacing': ['error', 'never'], // Unnecessary change for now |
| 38 | + 'style/block-spacing': ['error', 'never'], // Same |
| 39 | + 'jsonc/array-bracket-spacing': 'off', // Same |
| 40 | + 'style/brace-style': ['error', '1tbs'], // Naw, man |
| 41 | + 'style/semi': ['error', 'always'], |
| 42 | + 'style/member-delimiter-style': ['error', { |
| 43 | + multiline: { |
| 44 | + delimiter: 'semi', |
| 45 | + }, |
| 46 | + }], |
| 47 | + 'style/arrow-parens': ['error', 'as-needed'], |
| 48 | + 'prefer-template': 'off', // When there's a single `+` templates are less readable |
| 49 | + 'style/jsx-one-expression-per-line': 'off', // Terrible for inline elements, e.g. text |
| 50 | + |
| 51 | + // Disable some unicorn rules |
| 52 | + 'unicorn/expiring-todo-comments': 'off', // We just got too many, too much noise |
| 53 | + 'unicorn/no-nested-ternary': 'off', |
| 54 | + 'unicorn/better-regex': 'off', |
| 55 | + 'unicorn/prefer-top-level-await': 'off', |
| 56 | + 'unicorn/prefer-dom-node-dataset': 'off', |
| 57 | + 'unicorn/prefer-ternary': 'off', // Unreadable https://github.com/sindresorhus/eslint-plugin-unicorn/issues/1633 |
| 58 | + 'unicorn/no-null': 'off', // TODO: Later |
| 59 | + 'unicorn/prevent-abbreviations': [ |
| 60 | + 'error', |
| 61 | + { |
| 62 | + replacements: { |
| 63 | + props: false, |
| 64 | + ref: false, |
| 65 | + nav: false, |
| 66 | + }, |
| 67 | + }, |
| 68 | + ], |
| 69 | + |
| 70 | + // Restore errors |
| 71 | + 'no-await-in-loop': 'error', |
| 72 | + 'new-cap': [ |
| 73 | + 'error', |
| 74 | + { |
| 75 | + newIsCap: true, |
| 76 | + capIsNew: true, |
| 77 | + }, |
| 78 | + ], |
| 79 | + |
| 80 | + 'test/consistent-test-it': 'off', |
| 81 | + 'sort-imports': 'off', |
| 82 | + 'antfu/top-level-function': 'off', // Maybe later |
| 83 | + 'unused-imports/no-unused-vars': 'off', // Buggy |
| 84 | + 'no-console': 'off', |
| 85 | + 'jsonc/sort-keys': 'off', |
| 86 | + |
| 87 | + 'ts/no-restricted-types': [ |
| 88 | + 'error', |
| 89 | + { |
| 90 | + types: { |
| 91 | + 'object': { |
| 92 | + message: 'The `object` type is hard to use. Use `Record<string, unknown>` instead. See: https://github.com/typescript-eslint/typescript-eslint/pull/848', |
| 93 | + fixWith: 'Record<string, unknown>', |
| 94 | + }, |
| 95 | + 'null': { |
| 96 | + message: 'Use `undefined` instead. See: https://github.com/sindresorhus/meta/issues/7', |
| 97 | + fixWith: 'undefined', |
| 98 | + }, |
| 99 | + 'Buffer': { |
| 100 | + message: 'Use Uint8Array instead. See: https://sindresorhus.com/blog/goodbye-nodejs-buffer', |
| 101 | + suggest: [ |
| 102 | + 'Uint8Array', |
| 103 | + ], |
| 104 | + }, |
| 105 | + '[]': 'Don\'t use the empty array type `[]`. It only allows empty arrays. Use `SomeType[]` instead.', |
| 106 | + '[[]]': 'Don\'t use `[[]]`. It only allows an array with a single element which is an empty array. Use `SomeType[][]` instead.', |
| 107 | + '[[[]]]': 'Don\'t use `[[[]]]`. Use `SomeType[][][]` instead.', |
| 108 | + '[[[[]]]]': 'ur drunk 🤡', |
| 109 | + '[[[[[]]]]]': '🦄💥', |
| 110 | + }, |
| 111 | + }, |
| 112 | + ], |
| 113 | + 'no-restricted-syntax': [ |
| 114 | + 'error', |
| 115 | + { |
| 116 | + selector: |
| 117 | + ':matches([callee.name=delegate], [callee.name=$], [callee.name=$$], [callee.name=observe], [callee.property.name=querySelector], [callee.property.name=querySelectorAll], [callee.property.name=closest])[arguments.0.value=/,/][arguments.0.value.length>=20]:not([arguments.0.value=/:has|:is/])', |
| 118 | + message: 'Instead of a single string, pass an array of selectors and add comments to each selector', |
| 119 | + }, |
| 120 | + { |
| 121 | + selector: |
| 122 | + ':matches([callee.name=delegate], [callee.name=$], [callee.name=$$], [callee.name=observe], [callee.property.name=querySelector], [callee.property.name=querySelectorAll], [callee.property.name=closest])[arguments.0.type=ArrayExpression][arguments.0.elements.length=1]:not([arguments.0.value=/:has|:is/])', |
| 123 | + message: 'Instead of a single string, pass an array of selectors and add comments to each selector', |
| 124 | + }, |
| 125 | + ], |
| 126 | + 'jsx-quotes': [ |
| 127 | + 'error', |
| 128 | + 'prefer-double', |
| 129 | + ], |
| 130 | + 'no-alert': 'off', |
| 131 | + 'ts/no-unsafe-assignment': 'off', |
| 132 | + 'ts/no-unsafe-argument': 'off', |
| 133 | + 'ts/no-unsafe-member-access': 'off', |
| 134 | + 'ts/no-unsafe-return': 'off', |
| 135 | + 'ts/no-unsafe-call': 'off', |
| 136 | + 'ts/consistent-type-imports': 'off', |
| 137 | + 'n/prefer-global/process': 'off', |
| 138 | + 'import/no-cycle': 'off', // Slow, Rollup handles this |
| 139 | + 'import/no-unassigned-import': 'off', |
| 140 | + 'import/prefer-default-export': 'error', |
| 141 | + 'import/order': [ |
| 142 | + 'error', |
| 143 | + { |
| 144 | + 'groups': [ |
| 145 | + [ |
| 146 | + 'builtin', |
| 147 | + 'external', |
| 148 | + ], |
| 149 | + ], |
| 150 | + 'newlines-between': 'always-and-inside-groups', |
| 151 | + }, |
| 152 | + ], |
| 153 | + // TODO: Enable after https://github.com/Rel1cx/eslint-react/issues/739 |
| 154 | + // "react/function-component-definition": [ |
| 155 | + // "error", |
| 156 | + // { |
| 157 | + // "namedComponents": "function-declaration" |
| 158 | + // } |
| 159 | + // ] |
| 160 | + }, |
| 161 | + }, |
| 162 | + { |
| 163 | + files: [ |
| 164 | + 'build/*', |
| 165 | + ], |
| 166 | + rules: { |
| 167 | + 'ts/triple-slash-reference': 'off', |
| 168 | + 'unicorn/prefer-module': 'off', |
| 169 | + }, |
| 170 | + }, |
| 171 | + { |
| 172 | + files: [ |
| 173 | + 'source/features/*', |
| 174 | + ], |
| 175 | + rules: { |
| 176 | + 'import/prefer-default-export': 'off', |
| 177 | + }, |
| 178 | + }, |
| 179 | + { |
| 180 | + files: [ |
| 181 | + '**/*.md', |
| 182 | + ], |
| 183 | + rules: { |
| 184 | + 'style/no-multiple-empty-lines': 'off', |
| 185 | + }, |
| 186 | + }, |
| 187 | + { |
| 188 | + files: [ |
| 189 | + '.github/**', |
| 190 | + ], |
| 191 | + rules: { |
| 192 | + 'unicorn/filename-case': 'off', |
| 193 | + }, |
| 194 | + }, |
| 195 | + // https://eslint.org/docs/latest/use/configure/ignore#ignoring-files |
| 196 | + { |
| 197 | + ignores: ['safari'], |
| 198 | + }, |
| 199 | +); |
0 commit comments