Skip to content

Commit d4efbed

Browse files
authored
v2.0.0 - Better TypeScript support (#79)
* Bump version * Bump deps * Remove dep * Settings updates for file parsing and extension resolution * Add array-type rule Closes #2 * Add consistent-type-definitions Closes #3 * Add explicit-function-return-type Closes #4 * Add method-signature-style Closes #5 * Add no-dynamic-delete Closes #6 * Add prefer-enum-initializers Closes #9 * Add prefer-optional-chain Closes #11 * Add dot-notation Closes #13 * Update index.js * Add no-array-constructor Closes #15 * Add no-dupe-class-members Closes #16 * Add no-redeclare Closes #18 * Add no-shadow Closes #19 * Add no-unused-expressions Closes #20 * Update index.js * Group ESLint overrides * Add @typescript-eslint rules * Add eslint overrides * Add naming-convention * Update tests to use fixtures * Update index.js * Update index.js * Update index.js * Update index.js * Update index.js * Override import/extensions and import/no-extraneous-dependencies * Ignore fixtures * Update eslint-config-tc * Remove type based rules for now * Update index.js
1 parent fcc7f23 commit d4efbed

7 files changed

+1102
-73
lines changed

index.js

Lines changed: 193 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,197 @@
11
module.exports = {
2-
extends: ['plugin:@typescript-eslint/recommended', 'prettier/@typescript-eslint'],
2+
extends: ['plugin:@typescript-eslint/recommended', 'eslint-config-prettier'],
33
parser: '@typescript-eslint/parser',
44
plugins: ['@typescript-eslint', 'prettier'],
5+
settings: {
6+
'import/parsers': {
7+
'@typescript-eslint/parser': ['.ts', '.tsx', '.d.ts'],
8+
},
9+
'import/resolver': {
10+
node: {
11+
extensions: ['.mjs', '.js', '.json', '.ts', '.d.ts'],
12+
},
13+
},
14+
'import/extensions': ['.js', '.mjs', '.jsx', '.ts', '.tsx', '.d.ts'],
15+
'import/external-module-folders': ['node_modules', 'node_modules/@types'],
16+
},
17+
rules: {
18+
// @typescript-eslint rules
19+
// -----------------------------
20+
21+
// https://github.com/typescript-eslint/typescript-eslint/blob/master/packages/eslint-plugin/docs/rules/array-type.md
22+
'@typescript-eslint/array-type': ['error', {default: 'array'}],
23+
24+
// https://github.com/typescript-eslint/typescript-eslint/blob/master/packages/eslint-plugin/docs/rules/consistent-type-definitions.md
25+
'@typescript-eslint/consistent-type-definitions': ['error', 'interface'],
26+
27+
// https://github.com/typescript-eslint/typescript-eslint/blob/master/packages/eslint-plugin/docs/rules/explicit-function-return-type.md
28+
// disable the rule for all files, see overrides below.
29+
'@typescript-eslint/explicit-function-return-type': 'off',
30+
31+
// https://github.com/typescript-eslint/typescript-eslint/blob/master/packages/eslint-plugin/docs/rules/method-signature-style.md
32+
'@typescript-eslint/method-signature-style': 'error',
33+
34+
// https://github.com/typescript-eslint/typescript-eslint/blob/master/packages/eslint-plugin/docs/rules/naming-convention.md
35+
camelcase: 'off',
36+
'@typescript-eslint/naming-convention': [
37+
'error',
38+
{
39+
selector: 'default',
40+
format: ['camelCase'],
41+
},
42+
{
43+
selector: 'variable',
44+
format: ['camelCase', 'UPPER_CASE'],
45+
},
46+
{
47+
selector: 'parameter',
48+
format: ['camelCase'],
49+
leadingUnderscore: 'allow',
50+
},
51+
{
52+
// Matches: class, interface, typeAlias, enum, typeParameter
53+
selector: 'typeLike',
54+
format: ['PascalCase'],
55+
},
56+
{
57+
selector: 'enumMember',
58+
format: ['PascalCase'],
59+
},
60+
],
61+
62+
// https://github.com/typescript-eslint/typescript-eslint/blob/master/packages/eslint-plugin/docs/rules/no-dynamic-delete.md
63+
'@typescript-eslint/no-dynamic-delete': 'error',
64+
65+
// https://github.com/typescript-eslint/typescript-eslint/blob/master/packages/eslint-plugin/docs/rules/prefer-enum-initializers.md
66+
'@typescript-eslint/prefer-enum-initializers': 'error',
67+
68+
// https://github.com/typescript-eslint/typescript-eslint/blob/master/packages/eslint-plugin/docs/rules/prefer-optional-chain.md
69+
'@typescript-eslint/prefer-optional-chain': 'error',
70+
71+
// https://github.com/typescript-eslint/typescript-eslint/blob/master/packages/eslint-plugin/docs/rules/prefer-ts-expect-error.md
72+
'@typescript-eslint/prefer-ts-expect-error': 'error',
73+
74+
// @typescript-eslint overrides
75+
// that work better than ESLint
76+
// The base rule needs to be disabled to prevent false positives.
77+
// -----------------------------
78+
79+
// https://github.com/typescript-eslint/typescript-eslint/blob/master/packages/eslint-plugin/docs/rules/lines-between-class-members.md
80+
'lines-between-class-members': 'off',
81+
'@typescript-eslint/lines-between-class-members': ['error'],
82+
83+
// https://github.com/typescript-eslint/typescript-eslint/blob/master/packages/eslint-plugin/docs/rules/no-dupe-class-members.md
84+
'no-dupe-class-members': 'off',
85+
'@typescript-eslint/no-dupe-class-members': ['error'],
86+
87+
// https://github.com/typescript-eslint/typescript-eslint/blob/master/packages/eslint-plugin/docs/rules/no-empty-function.md
88+
'no-empty-function': 'off',
89+
'@typescript-eslint/no-empty-function': ['error'],
90+
91+
// https://github.com/typescript-eslint/typescript-eslint/blob/master/packages/eslint-plugin/docs/rules/no-loop-func.md
92+
'no-loop-func': 'off',
93+
'@typescript-eslint/no-loop-func': 'error',
94+
95+
// https://github.com/typescript-eslint/typescript-eslint/blob/master/packages/eslint-plugin/docs/rules/no-redeclare.md
96+
'no-redeclare': 'off',
97+
'@typescript-eslint/no-redeclare': ['error'],
98+
99+
// https://github.com/typescript-eslint/typescript-eslint/blob/master/packages/eslint-plugin/docs/rules/no-shadow.md
100+
'no-shadow': 'off',
101+
'@typescript-eslint/no-shadow': ['error'],
102+
103+
// https://github.com/typescript-eslint/typescript-eslint/blob/master/packages/eslint-plugin/docs/rules/no-unused-expressions.md
104+
'no-array-constructor': 'off',
105+
'@typescript-eslint/no-array-constructor': ['error'],
106+
107+
// https://github.com/typescript-eslint/typescript-eslint/blob/master/packages/eslint-plugin/docs/rules/no-unused-expressions.md
108+
'no-unused-expressions': 'off',
109+
'@typescript-eslint/no-unused-expressions': ['error'],
110+
111+
// https://github.com/typescript-eslint/typescript-eslint/blob/master/packages/eslint-plugin/docs/rules/no-use-before-define.md
112+
'no-use-before-define': 'off',
113+
'@typescript-eslint/no-use-before-define': ['error'],
114+
115+
// https://github.com/typescript-eslint/typescript-eslint/blob/master/packages/eslint-plugin/docs/rules/no-useless-constructor.md
116+
'no-useless-constructor': 'off',
117+
'@typescript-eslint/no-useless-constructor': ['error'],
118+
119+
// https://github.com/typescript-eslint/typescript-eslint/blob/master/packages/eslint-plugin/docs/rules/no-unused-vars.md
120+
'no-unused-vars': 'off',
121+
'@typescript-eslint/no-unused-vars': 'error',
122+
123+
// Override Airbnb 'import/extensions' rule. Add 'ts' and 'tsx'.
124+
// https://github.com/benmosher/eslint-plugin-import/blob/master/docs/rules/extensions.md
125+
'import/extensions': [
126+
'error',
127+
'ignorePackages',
128+
{
129+
js: 'never',
130+
mjs: 'never',
131+
jsx: 'never',
132+
ts: 'never',
133+
tsx: 'never',
134+
},
135+
],
136+
137+
// Override Airbnb 'import/no-extraneous-dependencies' rule. Add 'ts' and 'tsx'.
138+
// https://github.com/benmosher/eslint-plugin-import/blob/master/docs/rules/no-extraneous-dependencies.md
139+
'import/no-extraneous-dependencies': [
140+
'error',
141+
{
142+
devDependencies: [
143+
'test/**',
144+
'tests/**',
145+
'spec/**',
146+
'**/__tests__/**',
147+
'**/__mocks__/**',
148+
'test.{js,jsx,ts,tsx}',
149+
'test-*.{js,jsx,ts,tsx}',
150+
'**/*{.,_}{test,spec}.{js,jsx,ts,tsx}',
151+
'**/jest.config.js',
152+
'**/jest.setup.js',
153+
'**/vue.config.js',
154+
'**/webpack.config.js',
155+
'**/webpack.config.*.js',
156+
'**/rollup.config.js',
157+
'**/rollup.config.*.js',
158+
'**/gulpfile.js',
159+
'**/gulpfile.*.js',
160+
'**/Gruntfile{,.js}',
161+
'**/protractor.conf.js',
162+
'**/protractor.conf.*.js',
163+
'**/karma.conf.js',
164+
],
165+
optionalDependencies: false,
166+
},
167+
],
168+
},
169+
overrides: [
170+
{
171+
// Enable the rule specifically for TypeScript files
172+
files: ['*.ts', '*.tsx'],
173+
rules: {
174+
// Required for mixed JS/TS code bases - https://github.com/typescript-eslint/typescript-eslint/blob/master/packages/eslint-plugin/docs/rules/explicit-function-return-type.md
175+
'@typescript-eslint/explicit-function-return-type': ['error'],
176+
177+
// Disable the following rules since the TypeScript
178+
// compiler does it.
179+
'constructor-super': 'off',
180+
'getter-return': 'off',
181+
'no-const-assign': 'off',
182+
'no-dupe-args': 'off',
183+
'no-dupe-keys': 'off',
184+
'no-func-assign': 'off',
185+
'no-new-symbol': 'off',
186+
'no-obj-calls': 'off',
187+
'no-this-before-super': 'off',
188+
'no-undef': 'off',
189+
'no-unreachable': 'off',
190+
'no-unsafe-negation': 'off',
191+
'valid-typeof': 'off',
192+
'import/named': 'off',
193+
'import/no-unresolved': 'off',
194+
},
195+
},
196+
],
5197
};

0 commit comments

Comments
 (0)