Skip to content

Commit f90d27d

Browse files
Merge pull request #2905 from aklkv/fix/flat-gts-ts-recommended
Apply typescript-eslint's eslint-recommended overrides in the flat gts config
2 parents 19ec9b8 + d365705 commit f90d27d

4 files changed

Lines changed: 54 additions & 25 deletions

File tree

‎lib/config/recommended-gts.js‎

Lines changed: 1 addition & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,5 @@
11
const base = require('./base');
22
const gtsRules = require('../recommended-rules-gts');
3-
4-
// see https://github.com/typescript-eslint/typescript-eslint/issues/8607
5-
// https://github.com/typescript-eslint/typescript-eslint/blob/v7.4.0/packages/eslint-plugin/src/configs/eslint-recommended-raw.ts
6-
const tsRecommended = {
7-
'constructor-super': 'off', // ts(2335) & ts(2377)
8-
'getter-return': 'off', // ts(2378)
9-
'no-const-assign': 'off', // ts(2588)
10-
'no-dupe-args': 'off', // ts(2300)
11-
'no-dupe-class-members': 'off', // ts(2393) & ts(2300)
12-
'no-dupe-keys': 'off', // ts(1117)
13-
'no-func-assign': 'off', // ts(2630)
14-
'no-import-assign': 'off', // ts(2632) & ts(2540)
15-
'no-new-symbol': 'off', // ts(7009)
16-
'no-obj-calls': 'off', // ts(2349)
17-
'no-redeclare': 'off', // ts(2451)
18-
'no-setter-return': 'off', // ts(2408)
19-
'no-this-before-super': 'off', // ts(2376) & ts(17009)
20-
'no-undef': 'off', // ts(2304) & ts(2552)
21-
'no-unreachable': 'off', // ts(7027)
22-
'no-unsafe-negation': 'off', // ts(2365) & ts(2322) & ts(2358)
23-
'no-var': 'error', // ts transpiles let/const to var, so no need for vars any more
24-
'prefer-const': 'error', // ts provides better types with const
25-
'prefer-rest-params': 'error', // ts provides better types with rest args over arguments
26-
'prefer-spread': 'error', // ts transpiles spread to apply, so no need for manual apply
27-
};
3+
const tsRecommended = require('../ts-recommended-rules');
284

295
module.exports = [...base, { rules: { ...gtsRules, ...tsRecommended } }];

‎lib/recommended.mjs‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import emberPlugin from './index.js';
22
import baseRules from './recommended-rules.js';
33
import gjsRules from './recommended-rules-gjs.js';
44
import gtsRules from './recommended-rules-gts.js';
5+
import tsRecommendedRules from './ts-recommended-rules.js';
56
import emberParser from 'ember-eslint-parser';
67
import emberHbsParser from 'ember-eslint-parser/hbs';
78

@@ -52,6 +53,7 @@ export const gts = {
5253
rules: {
5354
...base.rules,
5455
...gtsRules,
56+
...tsRecommendedRules,
5557
},
5658
};
5759

‎lib/ts-recommended-rules.js‎

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
'use strict';
2+
3+
// typescript-eslint's `eslintRecommended` turns off the core rules TypeScript
4+
// already checks, but only for .ts, .tsx, .mts and .cts files, so .gts files
5+
// need the same overrides from us.
6+
// https://github.com/typescript-eslint/typescript-eslint/issues/8607
7+
module.exports = {
8+
'constructor-super': 'off', // ts(2335) & ts(2377)
9+
'getter-return': 'off', // ts(2378)
10+
'no-class-assign': 'off', // ts(2629)
11+
'no-const-assign': 'off', // ts(2588)
12+
'no-dupe-args': 'off', // ts(2300)
13+
'no-dupe-class-members': 'off', // ts(2393) & ts(2300)
14+
'no-dupe-keys': 'off', // ts(1117)
15+
'no-func-assign': 'off', // ts(2630)
16+
'no-import-assign': 'off', // ts(2632) & ts(2540)
17+
'no-new-native-nonconstructor': 'off', // ts(7009)
18+
'no-new-symbol': 'off', // ts(7009)
19+
'no-obj-calls': 'off', // ts(2349)
20+
'no-redeclare': 'off', // ts(2451)
21+
'no-setter-return': 'off', // ts(2408)
22+
'no-this-before-super': 'off', // ts(2376) & ts(17009)
23+
'no-undef': 'off', // ts(2304) & ts(2552)
24+
'no-unreachable': 'off', // ts(7027)
25+
'no-unsafe-negation': 'off', // ts(2365) & ts(2322) & ts(2358)
26+
'no-var': 'error', // ts transpiles let/const to var, so no need for vars any more
27+
'no-with': 'off', // ts(1101) & ts(2410)
28+
'prefer-const': 'error', // ts provides better types with const
29+
'prefer-rest-params': 'error', // ts provides better types with rest args over arguments
30+
'prefer-spread': 'error', // ts transpiles spread to apply, so no need for manual apply
31+
};

‎tests/ts-recommended-rules.js‎

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
'use strict';
2+
3+
const tseslint = require('typescript-eslint');
4+
const tsRecommendedRules = require('../lib/ts-recommended-rules');
5+
const recommendedGts = require('../lib/config/recommended-gts');
6+
7+
describe('typescript-eslint overrides for .gts', () => {
8+
it('match the rules typescript-eslint turns off for .ts files', () => {
9+
expect(tsRecommendedRules).toStrictEqual(tseslint.configs.eslintRecommended.rules);
10+
});
11+
12+
it('apply in the gts config from eslint-plugin-ember/recommended', async () => {
13+
const { gts } = await import('../lib/recommended');
14+
expect(gts.rules).toMatchObject(tsRecommendedRules);
15+
});
16+
17+
it('apply in eslint-plugin-ember/configs/recommended-gts', () => {
18+
expect(recommendedGts.at(-1).rules).toMatchObject(tsRecommendedRules);
19+
});
20+
});

0 commit comments

Comments
 (0)