|
| 1 | +import babelParser from '@babel/eslint-parser'; |
| 2 | +import { FlatCompat } from '@eslint/eslintrc'; |
| 3 | +import js from '@eslint/js'; |
| 4 | +import ember from 'eslint-plugin-ember'; |
| 5 | +import emberConcurrency from 'eslint-plugin-ember-concurrency'; |
| 6 | +import importHelpers from 'eslint-plugin-import-helpers'; |
| 7 | +import prettier from 'eslint-plugin-prettier'; |
| 8 | +import globals from 'globals'; |
| 9 | +import path from 'node:path'; |
| 10 | +import { fileURLToPath } from 'node:url'; |
| 11 | + |
| 12 | +const __filename = fileURLToPath(import.meta.url); |
| 13 | +const __dirname = path.dirname(__filename); |
| 14 | +const compat = new FlatCompat({ |
| 15 | + baseDirectory: __dirname, |
| 16 | + recommendedConfig: js.configs.recommended, |
| 17 | + allConfig: js.configs.all, |
| 18 | +}); |
| 19 | + |
| 20 | +export default [ |
| 21 | + { |
| 22 | + ignores: [ |
| 23 | + '.git/**/*', |
| 24 | + 'crates/', |
| 25 | + 'playwright-report/', |
| 26 | + 'target/', |
| 27 | + 'test-results/', |
| 28 | + 'tmp/', |
| 29 | + // unconventional js |
| 30 | + 'blueprints/*/files/', |
| 31 | + 'vendor/', |
| 32 | + // compiled output |
| 33 | + 'dist/', |
| 34 | + 'tmp/', |
| 35 | + // dependencies |
| 36 | + 'bower_components/', |
| 37 | + 'node_modules/', |
| 38 | + // misc |
| 39 | + 'coverage/', |
| 40 | + '!**/.*', |
| 41 | + // ember-try |
| 42 | + '.node_modules.ember-try/', |
| 43 | + 'bower.json.ember-try', |
| 44 | + 'package.json.ember-try', |
| 45 | + ], |
| 46 | + }, |
| 47 | + ...compat.extends( |
| 48 | + 'eslint:recommended', |
| 49 | + 'plugin:ember/recommended', |
| 50 | + 'plugin:qunit/recommended', |
| 51 | + 'plugin:qunit-dom/recommended', |
| 52 | + 'plugin:unicorn/recommended', |
| 53 | + 'plugin:prettier/recommended', |
| 54 | + ), |
| 55 | + { |
| 56 | + plugins: { |
| 57 | + ember, |
| 58 | + 'ember-concurrency': emberConcurrency, |
| 59 | + prettier, |
| 60 | + 'import-helpers': importHelpers, |
| 61 | + }, |
| 62 | + |
| 63 | + languageOptions: { |
| 64 | + globals: { |
| 65 | + ...globals.browser, |
| 66 | + }, |
| 67 | + |
| 68 | + parser: babelParser, |
| 69 | + ecmaVersion: 2018, |
| 70 | + sourceType: 'module', |
| 71 | + |
| 72 | + parserOptions: { |
| 73 | + requireConfigFile: false, |
| 74 | + |
| 75 | + babelOptions: { |
| 76 | + plugins: [ |
| 77 | + [ |
| 78 | + '@babel/plugin-proposal-decorators', |
| 79 | + { |
| 80 | + decoratorsBeforeExport: true, |
| 81 | + }, |
| 82 | + ], |
| 83 | + ], |
| 84 | + }, |
| 85 | + }, |
| 86 | + }, |
| 87 | + |
| 88 | + rules: { |
| 89 | + // it's fine to use `return` without a value and rely on the implicit `undefined` return value |
| 90 | + 'getter-return': 'off', |
| 91 | + |
| 92 | + // declaration sort is taken care of by `import-helpers/order-imports` |
| 93 | + 'sort-imports': ['error', { ignoreDeclarationSort: true, ignoreCase: true }], |
| 94 | + |
| 95 | + 'prettier/prettier': 'error', |
| 96 | + |
| 97 | + // disabled because we still use `this.set()` in a few places and it works just fine |
| 98 | + 'ember/classic-decorator-no-classic-methods': 'off', |
| 99 | + // disabled because the alternatives are currently not worth the additional complexity |
| 100 | + 'ember/no-array-prototype-extensions': 'off', |
| 101 | + |
| 102 | + 'ember-concurrency/no-perform-without-catch': 'warn', |
| 103 | + 'ember-concurrency/require-task-name-suffix': 'error', |
| 104 | + |
| 105 | + // disabled because of false positives in `assert.rejects()` calls |
| 106 | + 'qunit/require-expect': 'off', |
| 107 | + |
| 108 | + // disabled because of false positives related to ember-concurrency usage |
| 109 | + 'unicorn/consistent-function-scoping': 'off', |
| 110 | + 'unicorn/explicit-length-check': ['error', { 'non-zero': 'not-equal' }], |
| 111 | + // disabled because it conflicts with Ember.js conventions |
| 112 | + 'unicorn/no-anonymous-default-export': 'off', |
| 113 | + // disabled because of false positives related to `EmberArray` |
| 114 | + 'unicorn/no-array-for-each': 'off', |
| 115 | + // disabled because it is annoying in some cases... |
| 116 | + 'unicorn/no-await-expression-member': 'off', |
| 117 | + // disabled because we need `null` since JSON has no `undefined` |
| 118 | + 'unicorn/no-null': 'off', |
| 119 | + // disabled because this rule conflicts with prettier |
| 120 | + 'unicorn/no-nested-ternary': 'off', |
| 121 | + // disabled because of unfixable false positives |
| 122 | + 'unicorn/prevent-abbreviations': 'off', |
| 123 | + // disabled because we are targeting only browsers at the moment |
| 124 | + 'unicorn/prefer-global-this': 'off', |
| 125 | + // disabled because we don't want to go all-in on ES6 modules for Node.js code yet |
| 126 | + 'unicorn/prefer-module': 'off', |
| 127 | + // disabled because it seems unnecessary |
| 128 | + 'unicorn/prefer-number-properties': 'off', |
| 129 | + // disabled because it seems unnecessary |
| 130 | + 'unicorn/prefer-reflect-apply': 'off', |
| 131 | + // disabled because of false positives related to `EmberArray` |
| 132 | + 'unicorn/prefer-spread': 'off', |
| 133 | + // disabled because it seems unnecessary |
| 134 | + 'unicorn/prefer-string-raw': 'off', |
| 135 | + // disabled because of Sentry issues |
| 136 | + 'unicorn/prefer-string-replace-all': 'off', |
| 137 | + // disabled because switch statements in JS are quite error-prone |
| 138 | + 'unicorn/prefer-switch': 'off', |
| 139 | + // disabled because of false positives |
| 140 | + 'unicorn/consistent-destructuring': 'off', |
| 141 | + 'unicorn/filename-case': ['error', { case: 'kebabCase', ignore: ['^-'] }], |
| 142 | + |
| 143 | + 'import-helpers/order-imports': [ |
| 144 | + 'error', |
| 145 | + { |
| 146 | + newlinesBetween: 'always', |
| 147 | + groups: [ |
| 148 | + // Node.js built-in modules |
| 149 | + '/^(assert|async_hooks|buffer|child_process|cluster|console|constants|crypto|dgram|dns|domain|events|fs|http|http2|https|inspector|module|net|os|path|perf_hooks|process|punycode|querystring|readline|repl|stream|string_decoder|timers|tls|trace_events|tty|url|util|v8|vm|zli)/', |
| 150 | + // Testing modules |
| 151 | + ['/^(qunit|ember-qunit|@ember/test-helpers|ember-exam|htmlbars-inline-precompile)$/', '/^ember-exam\\//'], |
| 152 | + // Ember.js modules |
| 153 | + ['/^@(ember|ember-data|glimmer)\\//', '/^(ember|ember-data|rsvp)$/', '/^ember-data\\//'], |
| 154 | + ['module'], |
| 155 | + ['/^crates-io\\//'], |
| 156 | + ['parent', 'sibling', 'index'], |
| 157 | + ], |
| 158 | + alphabetize: { order: 'asc', ignoreCase: true }, |
| 159 | + }, |
| 160 | + ], |
| 161 | + }, |
| 162 | + }, |
| 163 | + |
| 164 | + // test files |
| 165 | + { |
| 166 | + files: ['tests/**/*.js'], |
| 167 | + |
| 168 | + rules: { |
| 169 | + 'unicorn/consistent-function-scoping': 'off', |
| 170 | + 'unicorn/prefer-dom-node-dataset': 'off', |
| 171 | + }, |
| 172 | + }, |
| 173 | + |
| 174 | + // node files |
| 175 | + { |
| 176 | + files: [ |
| 177 | + 'eslint.config.mjs', |
| 178 | + '**/.template-lintrc.js', |
| 179 | + '**/ember-cli-build.js', |
| 180 | + '**/testem.js', |
| 181 | + 'blueprints/*/index.js', |
| 182 | + 'config/**/*.js', |
| 183 | + 'lib/*/index.js', |
| 184 | + 'server/**/*.js', |
| 185 | + ], |
| 186 | + |
| 187 | + languageOptions: { |
| 188 | + globals: { |
| 189 | + ...Object.fromEntries(Object.entries(globals.browser).map(([key]) => [key, 'off'])), |
| 190 | + ...globals.node, |
| 191 | + }, |
| 192 | + |
| 193 | + ecmaVersion: 2018, |
| 194 | + sourceType: 'script', |
| 195 | + }, |
| 196 | + }, |
| 197 | +]; |
0 commit comments