|
| 1 | +/** |
| 2 | + * @type {ESLint.ConfigData} |
| 3 | + */ |
| 4 | +module.exports = { |
| 5 | + extends: ['prettier'], |
| 6 | + ignorePatterns: [ |
| 7 | + '**/app/**', |
| 8 | + '**/public/**', |
| 9 | + |
| 10 | + // Enable dotfile linting |
| 11 | + '!.*', |
| 12 | + 'node_modules', |
| 13 | + 'node_modules/.*', |
| 14 | + |
| 15 | + // Prevent CHANGELOG history changes |
| 16 | + 'CHANGELOG.md' |
| 17 | + ], |
| 18 | + overrides: [ |
| 19 | + { |
| 20 | + files: ['**/*.{cjs,js,mjs}'], |
| 21 | + extends: [ |
| 22 | + 'eslint:recommended', |
| 23 | + 'plugin:import/recommended', |
| 24 | + 'plugin:jest/style', |
| 25 | + 'plugin:jest-dom/recommended', |
| 26 | + 'plugin:jsdoc/recommended-typescript-flavor', |
| 27 | + 'plugin:n/recommended', |
| 28 | + 'plugin:promise/recommended', |
| 29 | + 'plugin:@typescript-eslint/strict', |
| 30 | + 'plugin:@typescript-eslint/stylistic', |
| 31 | + 'prettier' |
| 32 | + ], |
| 33 | + parser: '@typescript-eslint/parser', |
| 34 | + parserOptions: { |
| 35 | + ecmaVersion: 'latest' |
| 36 | + }, |
| 37 | + plugins: [ |
| 38 | + '@typescript-eslint', |
| 39 | + 'import', |
| 40 | + 'jsdoc', |
| 41 | + 'n', |
| 42 | + 'promise', |
| 43 | + 'jest', |
| 44 | + 'jest-dom' |
| 45 | + ], |
| 46 | + rules: { |
| 47 | + // Always import Node.js packages from `node:*` |
| 48 | + 'import/enforce-node-protocol-usage': ['error', 'always'], |
| 49 | + |
| 50 | + // Check import or require statements are A-Z ordered |
| 51 | + 'import/order': [ |
| 52 | + 'error', |
| 53 | + { |
| 54 | + 'alphabetize': { order: 'asc' }, |
| 55 | + 'newlines-between': 'always' |
| 56 | + } |
| 57 | + ], |
| 58 | + |
| 59 | + // Check for valid formatting |
| 60 | + 'jsdoc/check-line-alignment': [ |
| 61 | + 'warn', |
| 62 | + 'never', |
| 63 | + { |
| 64 | + wrapIndent: ' ' |
| 65 | + } |
| 66 | + ], |
| 67 | + |
| 68 | + // JSDoc blocks are optional by default |
| 69 | + 'jsdoc/require-jsdoc': 'off', |
| 70 | + |
| 71 | + // Require hyphens before param description |
| 72 | + // Aligns with TSDoc style: https://tsdoc.org/pages/tags/param/ |
| 73 | + 'jsdoc/require-hyphen-before-param-description': 'warn', |
| 74 | + |
| 75 | + // JSDoc @param required in (optional) blocks but |
| 76 | + // @param description is not necessary by default |
| 77 | + 'jsdoc/require-param-description': 'off', |
| 78 | + 'jsdoc/require-param-type': 'error', |
| 79 | + 'jsdoc/require-param': 'off', |
| 80 | + |
| 81 | + // JSDoc @returns is optional |
| 82 | + 'jsdoc/require-returns-description': 'off', |
| 83 | + 'jsdoc/require-returns-type': 'off', |
| 84 | + 'jsdoc/require-returns': 'off', |
| 85 | + |
| 86 | + // Maintain new line after description |
| 87 | + 'jsdoc/tag-lines': [ |
| 88 | + 'warn', |
| 89 | + 'never', |
| 90 | + { |
| 91 | + startLines: 1 |
| 92 | + } |
| 93 | + ] |
| 94 | + }, |
| 95 | + settings: { |
| 96 | + jsdoc: { |
| 97 | + // Allows us to use type declarations that exist in our dependencies |
| 98 | + mode: 'typescript' |
| 99 | + } |
| 100 | + } |
| 101 | + }, |
| 102 | + { |
| 103 | + // CommonJS modules allow require statements |
| 104 | + files: ['**/*.{cjs,js}'], |
| 105 | + rules: { |
| 106 | + '@typescript-eslint/no-require-imports': 'off', |
| 107 | + '@typescript-eslint/no-var-requires': 'off' |
| 108 | + } |
| 109 | + }, |
| 110 | + { |
| 111 | + // ES modules mandatory file extensions |
| 112 | + files: ['**/*.mjs'], |
| 113 | + rules: { |
| 114 | + 'import/extensions': [ |
| 115 | + 'error', |
| 116 | + 'always', |
| 117 | + { |
| 118 | + ignorePackages: true, |
| 119 | + pattern: { |
| 120 | + cjs: 'always', |
| 121 | + js: 'always', |
| 122 | + mjs: 'always' |
| 123 | + } |
| 124 | + } |
| 125 | + ] |
| 126 | + } |
| 127 | + }, |
| 128 | + { |
| 129 | + // Configure ESLint in test files |
| 130 | + files: ['**/*.test.{cjs,js,mjs}'], |
| 131 | + extends: ['plugin:jest/recommended', 'plugin:jest/style'], |
| 132 | + env: { |
| 133 | + 'jest/globals': true |
| 134 | + }, |
| 135 | + plugins: ['jest'] |
| 136 | + }, |
| 137 | + { |
| 138 | + // Configure ESLint in browser JavaScript |
| 139 | + files: ['app/assets/**/*.{cjs,js,mjs}'], |
| 140 | + excludedFiles: ['app/assets/**/*.test.{cjs,js,mjs}'], |
| 141 | + env: { |
| 142 | + browser: true |
| 143 | + }, |
| 144 | + parserOptions: { |
| 145 | + // Note: Allow ES2015 for import/export syntax |
| 146 | + ecmaVersion: '2015' |
| 147 | + } |
| 148 | + } |
| 149 | + ], |
| 150 | + root: true |
| 151 | +} |
| 152 | + |
| 153 | +/** |
| 154 | + * @import { ESLint } from 'eslint' |
| 155 | + */ |
0 commit comments