File size: 6,397 Bytes
1e92f2d | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 | /**
* @type {import('eslint').Linter.Config}
*/
const config = {
extends: [
'algolia',
'algolia/jest',
'algolia/react',
'algolia/typescript',
'plugin:react-hooks/recommended',
],
globals: {
__DEV__: false,
},
settings: {
react: {
version: 'detect',
},
'import/resolver': {
node: {
// The migration is an incremental process so we import TypeScript modules
// from JavaScript files.
// By default, `import/resolver` only supports JavaScript modules.
extensions: ['.js', '.ts', '.tsx'],
},
},
},
rules: {
'no-param-reassign': 'off',
// We rely on `@typescript-eslint/no-use-before-define`
'no-use-before-define': 'off',
// @TODO: remove once this is in `eslint-config-algolia`
'valid-jsdoc': 'off',
// @TODO: remove once this is in `eslint-config-algolia`
'@typescript-eslint/explicit-member-accessibility': 'off',
// @TODO: re-enable this once the code base is made for it
'@typescript-eslint/consistent-type-assertions': 'off',
'@typescript-eslint/consistent-type-imports': 'error',
// @TODO: re-enable once the rule is properly setup for monorepos
// https://github.com/benmosher/eslint-plugin-import/issues/1103
// https://github.com/benmosher/eslint-plugin-import/issues/1174
'import/no-extraneous-dependencies': 'off',
'@typescript-eslint/explicit-member-accessibility': ['off'],
'@typescript-eslint/naming-convention': [
'error',
{
selector: 'variable',
modifiers: ['destructured'],
format: null,
},
{
selector: 'variable',
format: ['camelCase', 'PascalCase', 'UPPER_CASE'],
leadingUnderscore: 'allow',
filter: {
regex:
'^EXPERIMENTAL_|__DEV__|__APP_INITIAL_STATE__|__SERVER_STATE__|free_shipping',
match: false,
},
},
{
selector: 'typeParameter',
format: ['PascalCase'],
prefix: ['T', 'K'],
},
{
selector: 'interface',
format: ['PascalCase'],
custom: {
regex: '^I[A-Z]',
match: false,
},
},
],
'import/extensions': 'off',
'eslint-comments/disable-enable-pair': 'off',
'react/jsx-no-bind': 'off',
// We can't display an error message with the ESLint version we're using
// See https://github.com/eslint/eslint/pull/14580
'no-restricted-imports': [
'error',
{
// We disallow InstantSearch.js CJS imports to only use ESM and not
// end up having duplicated source code in our bundle.
patterns: ['instantsearch.js/cjs/*'],
// We disallow importing the root ES import because the transformed CJS
// build then includes everything (widgets, components, etc.) and these
// aren't required or useful.
paths: ['instantsearch.js/es'],
},
],
'react-hooks/exhaustive-deps': [
'warn',
{
additionalHooks: '(useIsomorphicLayoutEffect)',
},
],
},
overrides: [
{
files: ['*.ts', '*.tsx'],
rules: {
// This rule has issues with the TypeScript parser, but tsc catches
// these sorts of errors anyway.
// See: https://github.com/typescript-eslint/typescript-eslint/issues/342
'no-undef': 'off',
},
},
{
files: ['stories/**/*'],
rules: {
'react/prop-types': 'off',
'@typescript-eslint/no-use-before-define': ['off'],
},
},
{
files: ['scripts/**/*', '*.config.js', '*.conf.js'],
rules: {
'import/no-commonjs': 'off',
},
},
{
files: [
'packages/react-instantsearch-hooks/**/*',
'packages/react-instantsearch-hooks-*/**/*',
],
rules: {
// We don't ship PropTypes in the next version of the library.
'react/prop-types': 'off',
'import/order': [
'error',
{
alphabetize: {
order: 'asc',
caseInsensitive: true,
},
'newlines-between': 'always',
groups: [
'builtin',
'external',
'parent',
'sibling',
'index',
'type',
],
pathGroups: [
{
pattern: '@/**/*',
group: 'parent',
position: 'before',
},
],
pathGroupsExcludedImportTypes: ['builtin'],
},
],
'import/extensions': ['error', 'never'],
},
settings: {
'import/parsers': {
'@typescript-eslint/parser': ['.ts', '.tsx'],
},
},
},
{
files: 'packages/**/*',
excludedFiles: ['*.test.*', '**/__tests__/**'],
rules: {
'no-restricted-syntax': [
'error',
{
selector: '[async=true]',
message:
'The polyfill for async/await is very large, which is why we use promise chains',
},
{
selector: 'ForInStatement',
message:
'for..in loops iterate over the entire prototype chain, which is virtually never what you want. Use Object.{keys,values,entries}, and iterate over the resulting array.',
},
{
selector: 'ForOfStatement',
message:
'iterators/generators require regenerator-runtime, which is too heavyweight for this guide to allow them. Separately, loops should be avoided in favor of array iterations.',
},
{
selector: 'LabeledStatement',
message:
'Labels are a form of GOTO; using them makes code confusing and hard to maintain and understand.',
},
{
selector: 'WithStatement',
message:
'`with` is disallowed in strict mode because it makes code impossible to predict and optimize.',
},
],
},
},
// Disable stricter rules introduced for the next versions of the libraries.
{
files: [
'packages/react-instantsearch-core/**/*',
'packages/react-instantsearch-dom/**/*',
],
rules: {
'@typescript-eslint/ban-types': 'off',
},
},
],
};
module.exports = config;
|