|
1 | 1 | 'use strict';
|
2 | 2 |
|
| 3 | +const nodeFiles = [ |
| 4 | + '.eslintrc.js', |
| 5 | + '.lintstagedrc.js', |
| 6 | + '.prettierrc.js', |
| 7 | + '.template-lintrc.{js,ts}', |
| 8 | + 'ember-cli-build.{js,ts}', |
| 9 | + 'testem.{js,ts}', |
| 10 | + 'blueprints/*/index.{js,ts}', |
| 11 | + 'config/**/*.{js,ts}', |
| 12 | + 'lib/*/index.{js,ts}', |
| 13 | + 'server/**/*.{js,ts}', |
| 14 | +]; |
| 15 | + |
| 16 | +const browserFiles = [ |
| 17 | + 'addon/**/*.{js,ts}', |
| 18 | + 'addon-test-support/**/*.{js,ts}', |
| 19 | + 'app/**/*.{js,ts}', |
| 20 | + 'test-support/**/*.{js,ts}', |
| 21 | + 'types/**/*.{js,ts}', |
| 22 | +]; |
| 23 | + |
| 24 | +const browserTestFiles = ['tests/**/*.{js,ts}']; |
| 25 | + |
3 | 26 | module.exports = {
|
4 | 27 | root: true,
|
5 |
| - parser: 'babel-eslint', |
| 28 | + parser: '@typescript-eslint/parser', |
6 | 29 | parserOptions: {
|
7 | 30 | ecmaVersion: 2018,
|
8 | 31 | sourceType: 'module',
|
9 |
| - ecmaFeatures: { |
10 |
| - legacyDecorators: true |
11 |
| - } |
| 32 | + project: ['./tsconfig.json', './tsconfig-node.json'], |
12 | 33 | },
|
13 |
| - plugins: [ |
14 |
| - 'ember' |
15 |
| - ], |
| 34 | + plugins: ['@typescript-eslint', 'ember', 'prettier'], |
16 | 35 | extends: [
|
17 | 36 | 'eslint:recommended',
|
18 |
| - 'plugin:ember/recommended' |
| 37 | + 'plugin:@typescript-eslint/eslint-recommended', |
| 38 | + 'plugin:@typescript-eslint/recommended', |
| 39 | + 'plugin:@typescript-eslint/recommended-requiring-type-checking', |
| 40 | + 'plugin:ember/recommended', |
| 41 | + 'standard', |
| 42 | + |
| 43 | + 'prettier/@typescript-eslint', |
| 44 | + 'prettier/standard', |
| 45 | + |
| 46 | + // This one should come last |
| 47 | + 'plugin:prettier/recommended', |
19 | 48 | ],
|
20 | 49 | env: {
|
21 |
| - browser: true |
| 50 | + browser: true, |
22 | 51 | },
|
23 | 52 | rules: {
|
24 |
| - 'ember/no-jquery': 'error' |
| 53 | + '@typescript-eslint/ban-ts-ignore': 'off', // Can't fully get rid of it due to TS quirks and issues with third-party depenecies |
| 54 | + '@typescript-eslint/camelcase': 'off', // Allow two levels of separation, e. g. ProductWizard_SidebarConfig_ListWithHeader_Component_Args |
| 55 | + '@typescript-eslint/class-name-casing': 'off', // Allow two levels of separation, e. g. ProductWizard_SidebarConfig_ListWithHeader_Component_Args |
| 56 | + '@typescript-eslint/no-empty-function': 'off', // Noop is a valid technique. |
| 57 | + '@typescript-eslint/no-empty-interface': 'off', // Required for simplified typing of Mirage and Ember Data |
| 58 | + '@typescript-eslint/no-non-null-assertion': 'off', // When I do it, I mean it. |
| 59 | + '@typescript-eslint/no-unsafe-assignment': 'off', // Reenabled for TS files only |
| 60 | + '@typescript-eslint/no-unsafe-call': 'off', // Reenabled for TS files only |
| 61 | + '@typescript-eslint/no-unsafe-member-access': 'off', // Reenabled for TS files only |
| 62 | + '@typescript-eslint/no-unsafe-return': 'off', // Reenabled for TS files only |
| 63 | + '@typescript-eslint/no-unused-expressions': 'off', // Reenabled for non-tests only (Chai needs this disabled) |
| 64 | + '@typescript-eslint/no-unused-vars': ['error', { argsIgnorePattern: '^_' }], |
| 65 | + '@typescript-eslint/no-var-requires': 'off', // Reenabled for non-Node files only |
| 66 | + |
| 67 | + // As this rule would freak out on JS files (by design!), |
| 68 | + // it has to be enabled only for .ts in the overrides section, |
| 69 | + // See https://github.com/typescript-eslint/typescript-eslint/blob/master/packages/eslint-plugin/docs/rules/explicit-function-return-type.md#configuring-in-a-mixed-jsts-codebase |
| 70 | + '@typescript-eslint/explicit-function-return-type': 'off', |
| 71 | + |
| 72 | + camelcase: 'off', // Have to keep this off for the TS equivalent to take precedence |
| 73 | + 'no-console': ['error', { allow: ['debug', 'error', 'info', 'warn'] }], |
| 74 | + 'no-unused-expressions': 'off', |
| 75 | + 'no-useless-constructor': 'off', // This rule crashes ESLint unless disabled |
| 76 | + |
| 77 | + 'node/no-unpublished-require': 'off', // Reenabled for non-Node files only |
| 78 | + |
| 79 | + 'prefer-const': 'error', // Only use `let` when you are actually mutating the variable |
| 80 | + 'prettier/prettier': 'error', |
25 | 81 | },
|
26 | 82 | overrides: [
|
27 | 83 | // node files
|
28 | 84 | {
|
29 |
| - files: [ |
30 |
| - '.eslintrc.js', |
31 |
| - '.template-lintrc.js', |
32 |
| - 'ember-cli-build.js', |
33 |
| - 'index.js', |
34 |
| - 'testem.js', |
35 |
| - 'blueprints/*/index.js', |
36 |
| - 'config/**/*.js', |
37 |
| - 'tests/dummy/config/**/*.js' |
38 |
| - ], |
39 |
| - excludedFiles: [ |
40 |
| - 'addon/**', |
41 |
| - 'addon-test-support/**', |
42 |
| - 'app/**', |
43 |
| - 'tests/dummy/app/**' |
44 |
| - ], |
| 85 | + files: nodeFiles, |
45 | 86 | parserOptions: {
|
46 |
| - sourceType: 'script' |
| 87 | + sourceType: 'script', |
47 | 88 | },
|
48 | 89 | env: {
|
49 | 90 | browser: false,
|
50 |
| - node: true |
| 91 | + node: true, |
51 | 92 | },
|
52 | 93 | plugins: ['node'],
|
53 |
| - rules: Object.assign({}, require('eslint-plugin-node').configs.recommended.rules, { |
| 94 | + rules: { |
| 95 | + ...require('eslint-plugin-node').configs.recommended.rules, // eslint-disable-line node/no-unpublished-require |
54 | 96 | // add your custom rules and overrides for node files here
|
55 |
| - }) |
56 |
| - } |
57 |
| - ] |
| 97 | + 'node/no-unsupported-features/es-syntax': ['error', { version: '>=12.0.0' }], |
| 98 | + }, |
| 99 | + }, |
| 100 | + { |
| 101 | + // browser files, including tests |
| 102 | + files: [...browserFiles, ...browserTestFiles], |
| 103 | + rules: { |
| 104 | + '@typescript-eslint/no-var-requires': 'error', // Reenabled for non-Node files only |
| 105 | + 'node/no-unpublished-require': 'error', // Reenabled for non-Node files only |
| 106 | + }, |
| 107 | + }, |
| 108 | + { |
| 109 | + /// non-tests |
| 110 | + files: [...nodeFiles, ...browserFiles], |
| 111 | + rules: { |
| 112 | + '@typescript-eslint/no-unused-expressions': 'error', // Reenabled for non-tests only (Chai needs this disabled) |
| 113 | + }, |
| 114 | + }, |
| 115 | + { |
| 116 | + // TS files |
| 117 | + files: ['*.ts'], |
| 118 | + rules: { |
| 119 | + '@typescript-eslint/explicit-function-return-type': 'error', // We want to be strict with types |
| 120 | + '@typescript-eslint/no-unsafe-assignment': 'error', // Reenabled for TS files only |
| 121 | + '@typescript-eslint/no-unsafe-call': 'error', // Reenabled for TS files only |
| 122 | + '@typescript-eslint/no-unsafe-member-access': 'error', // Reenabled for TS files only |
| 123 | + '@typescript-eslint/no-unsafe-return': 'error', // Reenabled for TS files only |
| 124 | + }, |
| 125 | + }, |
| 126 | + ], |
58 | 127 | };
|
0 commit comments