Skip to content

Commit e13a758

Browse files
authored
TINY-11728: Upgrade to latest typescript eslint packages (#51)
1 parent fd2f906 commit e13a758

File tree

8 files changed

+1193
-1667
lines changed

8 files changed

+1193
-1667
lines changed

.eslintrc.js

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
1+
/* eslint-env node */
12
module.exports = {
23
'extends': './dist/test/module/ESLintConfig.js',
34
"parserOptions": {
4-
"project": "tsconfig.json",
5-
"sourceType": "module"
6-
}
7-
}
5+
"projectService": true,
6+
"tsconfigRootDir": __dirname,
7+
},
8+
root: true,
9+
}

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,11 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
88
## Unreleased
99

1010
### Changed
11+
- Upgraded to `typescript` from v4 to v5
12+
- Upgraded `@typescript-eslint` packages from v5 to v8
13+
- Upgaded `eslint@^8.40.0` to `eslint@^8.57.0` to work with latest `@typescript-eslint` packages
14+
- Switched `eslint` and `@typescript-eslint` styling rules to use recommended `@stylistic` package
15+
- Enabled `no-duplicate-imports` rule in place of removed `@typescript-eslint/no-duplicate-imports` rule
1116
- Re-enabled `@typescript-eslint/no-floating-promises` rule
1217
- Disabled `@typescript-eslint/require-await`, which caused some builds to fail inconsistently and doesn't seem particularly valuable
1318

package.json

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7,24 +7,25 @@
77
"repository": "git@github.com:tinymce/eslint-plugin.git",
88
"license": "Apache-2.0",
99
"dependencies": {
10-
"@typescript-eslint/eslint-plugin": "^5.59.5",
11-
"@typescript-eslint/parser": "^5.59.5",
12-
"eslint": "^8.40.0",
10+
"@stylistic/eslint-plugin": "^2.12.1",
11+
"@typescript-eslint/eslint-plugin": "^8.19.1",
12+
"@typescript-eslint/parser": "^8.19.1",
13+
"eslint": "^8.57.0",
1314
"eslint-plugin-import": "2.26.0",
1415
"eslint-plugin-mocha": "^10.1.0",
1516
"eslint-plugin-prefer-arrow": "^1.2.3",
16-
"resolve": "^1.17.0",
17-
"typescript": "^4.9.5"
17+
"resolve": "^1.22.10",
18+
"typescript": "^5.7.2"
1819
},
1920
"devDependencies": {
2021
"@tinymce/beehive-flow": "^0.19.0",
21-
"@types/eslint": "^8.37.0",
22-
"@types/estree": "^1.0.1",
23-
"@types/node": "^20.1.3",
24-
"@types/resolve": "^1.17.1",
25-
"@typescript-eslint/typescript-estree": "^5.59.5",
26-
"jest": "^27.3.1",
27-
"ts-jest": "^27.0.7"
22+
"@types/eslint": "^8.56.0",
23+
"@types/estree": "^1.0.6",
24+
"@types/node": "^22.10.5",
25+
"@types/resolve": "^1.20.6",
26+
"@typescript-eslint/typescript-estree": "^8.19.1",
27+
"jest": "^29.7.0",
28+
"ts-jest": "^29.2.5"
2829
},
2930
"files": [
3031
"dist/main",

src/main/ts/configs/Editor.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ export const editor: Linter.Config = {
1313
'@tinymce/prefer-mcagar-tiny-dom': 'error',
1414

1515
'@typescript-eslint/explicit-module-boundary-types': [ 'error', { allowArgumentsExplicitlyTypedAsAny: true }],
16-
'@typescript-eslint/comma-dangle': [ 'error', {
16+
'@stylistic/comma-dangle': [ 'error', {
1717
arrays: 'only-multiline',
1818
objects: 'only-multiline',
1919
imports: 'never',
@@ -37,10 +37,10 @@ export const editor: Linter.Config = {
3737
}
3838
}],
3939

40-
// Disabled since we're using the typescript-eslint rule
40+
// Disabled since we're using the stylistic rule
4141
'comma-dangle': 'off',
4242
},
4343
settings: {
4444
'import/internal-regex': '^(ephox|tinymce|tiny-premium)/.*'
4545
}
46-
};
46+
};

src/main/ts/configs/Standard.ts

Lines changed: 63 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,16 @@ import { Linter } from 'eslint';
22

33
export const base: Linter.Config = {
44
extends: [
5-
'plugin:@typescript-eslint/recommended',
6-
'plugin:@typescript-eslint/recommended-requiring-type-checking'
5+
// TODO: Look at enabling recommended eslint options
6+
// 'eslint:recommended',
7+
'plugin:@typescript-eslint/recommended-type-checked',
8+
// TODO: Look at enabling recommended typescript stylistic options
9+
// 'plugin:@typescript-eslint/stylistic-type-checked',
710
],
11+
parser: '@typescript-eslint/parser',
812
plugins: [
913
'@typescript-eslint',
14+
'@stylistic',
1015
'import',
1116
'mocha',
1217
'prefer-arrow',
@@ -16,21 +21,21 @@ export const base: Linter.Config = {
1621
'@typescript-eslint/await-thenable': 'error',
1722
'@typescript-eslint/ban-ts-comment': 'error',
1823
'@typescript-eslint/ban-types': 'off',
19-
'@typescript-eslint/brace-style': 'error',
20-
'@typescript-eslint/comma-spacing': 'error',
24+
'@stylistic/brace-style': 'error',
25+
'@stylistic/comma-spacing': 'error',
2126
'@typescript-eslint/consistent-type-assertions': 'error',
2227
'@typescript-eslint/consistent-type-definitions': 'error',
2328
'@typescript-eslint/explicit-function-return-type': 'off',
2429
'@typescript-eslint/explicit-member-accessibility': [ 'error', { accessibility: 'explicit' }],
2530
'@typescript-eslint/explicit-module-boundary-types': 'off',
26-
'@typescript-eslint/func-call-spacing': 'error',
27-
'@typescript-eslint/indent': [ 'error', 2, {
31+
'@stylistic/func-call-spacing': 'error',
32+
'@stylistic/indent': [ 'error', 2, {
2833
FunctionDeclaration: { parameters: 'first' },
2934
FunctionExpression: { parameters: 'first' },
3035
SwitchCase: 1
3136
}],
32-
'@typescript-eslint/keyword-spacing': 'error',
33-
'@typescript-eslint/member-delimiter-style': [ 'error', {
37+
'@stylistic/keyword-spacing': 'error',
38+
'@stylistic/member-delimiter-style': [ 'error', {
3439
multiline: { delimiter: 'semi', requireLast: true },
3540
singleline: { delimiter: 'semi', requireLast: false }
3641
}],
@@ -42,40 +47,48 @@ export const base: Linter.Config = {
4247
format: [ 'PascalCase' ]
4348
}
4449
],
45-
'@typescript-eslint/no-duplicate-imports': 'error',
4650
'@typescript-eslint/no-empty-interface': 'off',
4751
'@typescript-eslint/no-for-in-array': 'error',
4852
'@typescript-eslint/no-implied-eval': 'error',
4953
'@typescript-eslint/no-inferrable-types': [ 'error', { ignoreParameters: true, ignoreProperties: true }],
5054
'@typescript-eslint/no-namespace': 'error',
51-
'@typescript-eslint/no-parameter-properties': 'error',
55+
'@typescript-eslint/parameter-properties': 'error',
5256
'@typescript-eslint/no-shadow': [ 'error', { hoist: 'all' }],
5357
'@typescript-eslint/no-unused-vars': [ 'warn', {
5458
vars: 'all',
5559
args: 'after-used',
60+
argsIgnorePattern: '^_',
61+
caughtErrors: 'all',
62+
caughtErrorsIgnorePattern: '^_',
63+
destructuredArrayIgnorePattern: '^_',
5664
ignoreRestSiblings: true,
57-
argsIgnorePattern: '^_'
5865
}],
59-
'@typescript-eslint/object-curly-spacing': [ 'error', 'always', { objectsInObjects: false }],
66+
'@stylistic/object-curly-spacing': [ 'error', 'always', { objectsInObjects: false }],
6067
'@typescript-eslint/prefer-for-of': 'error',
6168
'@typescript-eslint/prefer-function-type': 'error',
62-
'@typescript-eslint/quotes': [ 'error', 'single', { allowTemplateLiterals: true }],
69+
'@stylistic/quotes': [ 'error', 'single', { allowTemplateLiterals: true }],
6370
'@typescript-eslint/require-await': 'off',
6471
'@typescript-eslint/restrict-plus-operands': 'off',
6572
'@typescript-eslint/restrict-template-expressions': 'off',
66-
'@typescript-eslint/semi': [ 'error', 'always' ],
67-
'@typescript-eslint/space-before-blocks': 'error',
68-
'@typescript-eslint/space-before-function-paren': [ 'error', { anonymous: 'always', named: 'never' }],
69-
'@typescript-eslint/space-infix-ops': 'error',
70-
'@typescript-eslint/switch-exhaustiveness-check': 'error',
71-
'@typescript-eslint/type-annotation-spacing': 'error',
73+
'@stylistic/semi': [ 'error', 'always' ],
74+
'@stylistic/space-before-blocks': 'error',
75+
'@stylistic/space-before-function-paren': [ 'error', { anonymous: 'always', named: 'never' }],
76+
'@stylistic/space-infix-ops': 'error',
77+
'@stylistic/type-annotation-spacing': 'error',
7278
'@typescript-eslint/unified-signatures': 'error',
7379
'@typescript-eslint/no-floating-promises': [
7480
'error',
7581
{
7682
ignoreVoid: false
7783
}
7884
],
85+
// TODO: Look at setting all exhaustive-check options to false to be stricter
86+
'@typescript-eslint/switch-exhaustiveness-check': [
87+
'error',
88+
{
89+
considerDefaultExhaustiveForUnions: true
90+
}
91+
],
7992

8093
// TODO: Enable once we no longer support IE 11
8194
'@typescript-eslint/prefer-includes': 'off',
@@ -92,30 +105,34 @@ export const base: Linter.Config = {
92105
'@typescript-eslint/no-use-before-define': 'off',
93106
'@typescript-eslint/prefer-as-const': 'off',
94107
'@typescript-eslint/strict-boolean-expressions': 'off', // Needs StrictNullChecks
108+
'@typescript-eslint/no-empty-object-type': 'off',
109+
'@typescript-eslint/no-unsafe-function-type': 'off',
110+
'@typescript-eslint/prefer-promise-reject-errors': 'off',
111+
'@typescript-eslint/no-base-to-string': 'off',
95112

96-
'array-bracket-spacing': [ 'error', 'always', { objectsInArrays: false, arraysInArrays: false }],
113+
'@stylistic/array-bracket-spacing': [ 'error', 'always', { objectsInArrays: false, arraysInArrays: false }],
97114
'arrow-body-style': 'error',
98-
'arrow-parens': [ 'error', 'always' ],
99-
'arrow-spacing': 'error',
100-
'comma-dangle': 'off',
115+
'@stylistic/arrow-parens': [ 'error', 'always' ],
116+
'@stylistic/arrow-spacing': 'error',
117+
'@stylistic/comma-dangle': 'off',
101118
'complexity': 'off',
102-
'computed-property-spacing': 'error',
119+
'@stylistic/computed-property-spacing': 'error',
103120
'constructor-super': 'error',
104121
'curly': 'error',
105-
'dot-location': [ 'error', 'property' ],
122+
'@stylistic/dot-location': [ 'error', 'property' ],
106123
'dot-notation': 'error',
107-
'eol-last': 'off',
124+
'@stylistic/eol-last': 'off',
108125
'eqeqeq': [ 'error', 'smart' ],
109126
'guard-for-in': 'error',
110127
'id-blacklist': 'error',
111128
'id-match': 'error',
112129
'import/order': 'off',
113-
'key-spacing': [ 'error', { beforeColon: false, afterColon: true, mode: 'strict' }],
130+
'@stylistic/key-spacing': [ 'error', { beforeColon: false, afterColon: true, mode: 'strict' }],
114131
'max-classes-per-file': [ 'error', 1 ],
115132
'max-len': [ 'warn', 160 ],
116133
'mocha/no-exclusive-tests': 'error',
117134
'mocha/no-identical-title': 'error',
118-
'new-parens': 'error',
135+
'@stylistic/new-parens': 'error',
119136
'no-bitwise': 'error',
120137
'no-caller': 'error',
121138
'no-cond-assign': 'error',
@@ -125,45 +142,41 @@ export const base: Linter.Config = {
125142
'no-eval': 'error',
126143
'no-fallthrough': 'error',
127144
'no-invalid-this': 'off',
128-
'no-multi-spaces': [ 'error', { ignoreEOLComments: true }],
129-
'no-multiple-empty-lines': [ 'error', { max: 1 }],
145+
'@stylistic/no-multi-spaces': [ 'error', { ignoreEOLComments: true }],
146+
'@stylistic/no-multiple-empty-lines': [ 'error', { max: 1 }],
130147
'no-nested-ternary': 'error',
131148
'no-new-wrappers': 'error',
132149
'no-throw-literal': 'error',
133-
'no-trailing-spaces': 'error',
150+
'@stylistic/no-trailing-spaces': 'error',
134151
'no-undef-init': 'error',
135152
'no-underscore-dangle': 'error',
136153
'no-unsafe-finally': 'error',
137-
'no-unused-expressions': [ 'error', { allowTernary: true }],
154+
'@typescript-eslint/no-unused-expressions': [ 'error', { allowTernary: true }],
138155
'no-unused-labels': 'error',
139-
'no-whitespace-before-property': 'error',
156+
'@stylistic/no-whitespace-before-property': 'error',
140157
'object-shorthand': 'error',
141158
'one-var': [ 'error', 'never' ],
142159
'prefer-arrow-callback': 'off', // Covered by prefer-arrow-functions
143160
'prefer-arrow/prefer-arrow-functions': 'error',
144-
'quote-props': [ 'error', 'consistent-as-needed' ],
161+
'@stylistic/quote-props': [ 'error', 'consistent-as-needed' ],
145162
'radix': 'error',
146-
'rest-spread-spacing': 'error',
147-
'semi-spacing': 'error',
148-
'spaced-comment': 'error',
149-
'space-unary-ops': 'error',
150-
'switch-colon-spacing': 'error',
151-
'template-curly-spacing': 'error',
163+
'@stylistic/rest-spread-spacing': 'error',
164+
'@stylistic/semi-spacing': 'error',
165+
'@stylistic/spaced-comment': 'error',
166+
'@stylistic/space-unary-ops': 'error',
167+
'@stylistic/switch-colon-spacing': 'error',
168+
'@stylistic/template-curly-spacing': 'error',
152169
'use-isnan': 'error',
153170
'valid-typeof': 'off', // Disabled as it's handled by TypeScript
154171

155172
// Disabled since we're using the equivalent typescript-eslint rule
156-
'brace-style': 'off',
157-
'comma-spacing': 'off',
158-
'func-call-spacing': 'off',
159-
'indent': 'off',
160-
'keyword-spacing': 'off',
161-
'no-duplicate-imports': 'off',
162173
'no-shadow': 'off',
163-
'object-curly-spacing': 'off',
164-
'space-before-blocks': 'off',
165-
'space-before-function-paren': 'off',
166-
'space-infix-ops': 'off',
174+
175+
'import/no-duplicates': 'off',
176+
'no-duplicate-imports': 'error',
177+
// Continue using default max-len option to avoid changing too many files that
178+
// have max-len ignore comments
179+
'@stylistic/max-len': 'off'
167180
}
168181
};
169182

src/main/ts/rules/NoEnumsInExportSpecifier.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,12 @@ export const noEnumsInExportSpecifier: Rule.RuleModule = {
2020
},
2121
ExportSpecifier: (node) => {
2222
if (node.type === 'ExportSpecifier') {
23-
const name = node.local.name;
24-
if (enumNames.hasOwnProperty(name) && enumNames[name]) {
23+
const name = node.local.type === 'Identifier' ? node.local.name : undefined;
24+
if (name && Object.prototype.hasOwnProperty.call(enumNames, name) && enumNames[name]) {
2525
context.report({ node, messageId: 'noEnumsInExportSpecifier' });
2626
}
2727
}
2828
}
2929
};
3030
}
31-
};
31+
};

src/main/ts/rules/PreferFun.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -83,9 +83,8 @@ const isIdentity = (func: FuncExpression, expr: Expression) => {
8383
};
8484

8585
const hasTypeParameters = (func: FuncExpression): boolean => {
86-
const tsFunc = func as TSESTree.CallExpression | TSESTree.ArrowFunctionExpression | TSESTree.FunctionExpression;
87-
const params = tsFunc.typeParameters;
88-
if (params !== undefined && params.type === 'TSTypeParameterDeclaration') {
86+
const params = (func as TSESTree.ArrowFunctionExpression | TSESTree.FunctionExpression).typeParameters;
87+
if (params?.type === TSESTree.AST_NODE_TYPES.TSTypeParameterDeclaration) {
8988
return params.params.length > 0;
9089
} else {
9190
return false;
@@ -205,4 +204,4 @@ export const preferFun: Rule.RuleModule = {
205204
};
206205
}
207206
}
208-
};
207+
};

0 commit comments

Comments
 (0)