|
| 1 | +import base, { createConfig } from '@metamask/eslint-config'; |
| 2 | +import jest from '@metamask/eslint-config-jest'; |
| 3 | +import nodejs from '@metamask/eslint-config-nodejs'; |
| 4 | +import typescript from '@metamask/eslint-config-typescript'; |
| 5 | + |
| 6 | +const config = createConfig([ |
| 7 | + { |
| 8 | + ignores: ['dist/', 'docs/', '.yarn/'], |
| 9 | + }, |
| 10 | + |
| 11 | + { |
| 12 | + extends: base, |
| 13 | + |
| 14 | + languageOptions: { |
| 15 | + sourceType: 'module', |
| 16 | + parserOptions: { |
| 17 | + tsconfigRootDir: import.meta.dirname, |
| 18 | + }, |
| 19 | + }, |
| 20 | + |
| 21 | + rules: { |
| 22 | + // Consider copying this to @metamask/eslint-config |
| 23 | + 'jsdoc/require-jsdoc': [ |
| 24 | + 'error', |
| 25 | + { |
| 26 | + require: { |
| 27 | + // Classes |
| 28 | + ClassDeclaration: true, |
| 29 | + // Function declarations |
| 30 | + FunctionDeclaration: true, |
| 31 | + // Methods |
| 32 | + MethodDefinition: true, |
| 33 | + }, |
| 34 | + contexts: [ |
| 35 | + // Type interfaces that are not defined within `declare` blocks |
| 36 | + ':not(TSModuleBlock) > TSInterfaceDeclaration', |
| 37 | + // Type aliases |
| 38 | + 'TSTypeAliasDeclaration', |
| 39 | + // Enums |
| 40 | + 'TSEnumDeclaration', |
| 41 | + // Arrow functions that are not contained within plain objects or |
| 42 | + // are not arguments to functions or methods |
| 43 | + ':not(Property, NewExpression, CallExpression) > ArrowFunctionExpression', |
| 44 | + // Function expressions that are not contained within plain objects |
| 45 | + // or are not arguments to functions or methods |
| 46 | + ':not(Property, NewExpression, CallExpression) > FunctionExpression', |
| 47 | + // Exported variables at the root |
| 48 | + 'ExportNamedDeclaration:has(> VariableDeclaration)', |
| 49 | + ], |
| 50 | + }, |
| 51 | + ], |
| 52 | + // Consider copying this to @metamask/eslint-config |
| 53 | + 'jsdoc/no-blank-blocks': 'error', |
| 54 | + }, |
| 55 | + |
| 56 | + settings: { |
| 57 | + 'import-x/extensions': ['.js', '.mjs'], |
| 58 | + }, |
| 59 | + }, |
| 60 | + |
| 61 | + { |
| 62 | + files: ['**/*.ts'], |
| 63 | + extends: typescript, |
| 64 | + rules: { |
| 65 | + // Consider copying this to @metamask/eslint-config |
| 66 | + '@typescript-eslint/explicit-function-return-type': [ |
| 67 | + 'error', |
| 68 | + { |
| 69 | + allowExpressions: true, |
| 70 | + }, |
| 71 | + ], |
| 72 | + // Consider copying this to @metamask/eslint-config |
| 73 | + 'jsdoc/require-jsdoc': [ |
| 74 | + 'error', |
| 75 | + { |
| 76 | + require: { |
| 77 | + // Classes |
| 78 | + ClassDeclaration: true, |
| 79 | + // Function declarations |
| 80 | + FunctionDeclaration: true, |
| 81 | + // Methods |
| 82 | + MethodDefinition: true, |
| 83 | + }, |
| 84 | + contexts: [ |
| 85 | + // Type interfaces that are not defined within `declare` blocks |
| 86 | + ':not(TSModuleBlock) > TSInterfaceDeclaration', |
| 87 | + // Type aliases |
| 88 | + 'TSTypeAliasDeclaration', |
| 89 | + // Enums |
| 90 | + 'TSEnumDeclaration', |
| 91 | + // Arrow functions that are not contained within plain objects or |
| 92 | + // are not arguments to functions or methods |
| 93 | + ':not(Property, NewExpression, CallExpression) > ArrowFunctionExpression', |
| 94 | + // Function expressions that are not contained within plain objects |
| 95 | + // or are not arguments to functions or methods |
| 96 | + ':not(Property, NewExpression, CallExpression) > FunctionExpression', |
| 97 | + // Exported variables at the root |
| 98 | + 'ExportNamedDeclaration:has(> VariableDeclaration)', |
| 99 | + ], |
| 100 | + }, |
| 101 | + ], |
| 102 | + // Consider copying this to @metamask/eslint-config |
| 103 | + 'jsdoc/no-blank-blocks': 'error', |
| 104 | + }, |
| 105 | + }, |
| 106 | + |
| 107 | + { |
| 108 | + files: ['**/*.js', '**/*.cjs', '**/*.ts', '**/*.test.ts', '**/*.test.js'], |
| 109 | + ignores: ['src/ui/**'], |
| 110 | + extends: nodejs, |
| 111 | + }, |
| 112 | + |
| 113 | + { |
| 114 | + files: ['**/*.test.ts'], |
| 115 | + extends: jest, |
| 116 | + }, |
| 117 | + |
| 118 | + // List this last to override any settings inherited from plugins, |
| 119 | + // especially `eslint-config-n`, which mistakenly assumes that all `.cjs` |
| 120 | + // files are modules (since we specified `type: module` in `package.json`) |
| 121 | + { |
| 122 | + files: ['**/*.js', '**/*.cjs'], |
| 123 | + // This *is* a script, but is written using ESM. |
| 124 | + ignores: ['bin/create-release-branch.js'], |
| 125 | + languageOptions: { |
| 126 | + sourceType: 'script', |
| 127 | + }, |
| 128 | + }, |
| 129 | +]); |
| 130 | + |
| 131 | +export default config; |
0 commit comments