Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: support TypeScript 4.8 #5551

Merged
merged 8 commits into from Aug 29, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
12 changes: 8 additions & 4 deletions .eslintrc.js
@@ -1,12 +1,13 @@
module.exports = {
root: true,
plugins: [
'eslint-plugin',
'@typescript-eslint',
'jest',
'import',
'eslint-comments',
'@typescript-eslint/internal',
'deprecation',
'eslint-comments',
'eslint-plugin',
'import',
'jest',
'simple-import-sort',
],
env: {
Expand Down Expand Up @@ -41,6 +42,9 @@ module.exports = {
EXPERIMENTAL_useSourceOfProjectReferenceRedirect: false,
},
rules: {
// make sure we're not leveraging any deprecated APIs
'deprecation/deprecation': 'error',

//
// our plugin :D
//
Expand Down
2 changes: 1 addition & 1 deletion README.md
Expand Up @@ -51,7 +51,7 @@ The latest version under the `canary` tag **(latest commit to `main`)** is:

### Supported TypeScript Version

**The version range of TypeScript currently supported by this parser is `>=3.3.1 <4.8.0`.**
**The version range of TypeScript currently supported by this parser is `>=3.3.1 <4.9.0`.**

These versions are what we test against.

Expand Down
11 changes: 7 additions & 4 deletions package.json
Expand Up @@ -33,11 +33,12 @@
"generate-contributors": "yarn ts-node --transpile-only ./tools/generate-contributors.ts",
"generate-sponsors": "yarn ts-node --transpile-only ./tools/generate-sponsors.ts",
"generate-website-dts": "yarn ts-node --transpile-only ./tools/generate-website-dts.ts",
"generate-lib": "nx generate-lib @typescript-eslint/scope-manager",
"lint-fix": "eslint . --fix",
"lint-markdown-fix": "yarn lint-markdown --fix",
"lint-markdown": "markdownlint \"**/*.md\" --config=.markdownlint.json --ignore-path=.markdownlintignore",
"lint": "cross-env NODE_OPTIONS=\"--max-old-space-size=16384\" eslint .",
"postinstall": "yarn husky install && yarn build",
"postinstall": "yarn patch-package && yarn husky install && yarn build",
"pre-commit": "yarn lint-staged",
"start": "nx run website:start",
"test": "nx run-many --target=test --all --parallel",
Expand Down Expand Up @@ -77,9 +78,10 @@
"cross-env": "^7.0.3",
"cross-fetch": "^3.1.5",
"cspell": "^5.20.0",
"downlevel-dts": "^0.9.0",
"downlevel-dts": ">=0.10.0",
"enhanced-resolve": "^5.9.3",
"eslint": "^8.15.0",
"eslint-plugin-deprecation": "^1.3.2",
"eslint-plugin-eslint-comments": "^3.2.0",
"eslint-plugin-eslint-plugin": "^5.0.1",
"eslint-plugin-import": "^2.26.0",
Expand All @@ -96,16 +98,17 @@
"make-dir": "^3.1.0",
"markdownlint-cli": "^0.31.1",
"ncp": "^2.0.0",
"patch-package": "^6.4.7",
"prettier": "2.7.1",
"pretty-format": "^28.1.0",
"rimraf": "^3.0.2",
"tmp": "^0.2.1",
"ts-node": "^10.7.0",
"tslint": "^6.1.3",
"typescript": ">=3.3.1 <4.8.0"
"typescript": ">=3.3.1 <4.9.0"
},
"resolutions": {
"typescript": "4.7.4",
"typescript": "4.8.2",
"@types/node": "^17.0.31",
"pretty-format": "^28.1.0",
"//": "Pin jest to v28 across the repo",
Expand Down
Expand Up @@ -157,7 +157,7 @@ export default createRule<Options, MessageIds>({
return format(code, {
...prettierConfig,
parser: 'typescript',
}).trimRight(); // prettier will insert a new line at the end of the code
}).trimEnd(); // prettier will insert a new line at the end of the code
} catch (ex) {
// adapted from https://github.com/prettier/eslint-plugin-prettier/blob/185b1064d3dd674538456fb2fad97fbfcde49e0d/eslint-plugin-prettier.js#L242-L257
if (!(ex instanceof SyntaxError)) {
Expand Down Expand Up @@ -282,9 +282,9 @@ export default createRule<Options, MessageIds>({
const lines = text.split('\n');
const lastLine = lines[lines.length - 1];
// prettier will trim out the end of line on save, but eslint will check before then
const isStartEmpty = lines[0].trimRight() === '';
const isStartEmpty = lines[0].trimEnd() === '';
// last line can be indented
const isEndEmpty = lastLine.trimLeft() === '';
const isEndEmpty = lastLine.trimStart() === '';
if (!isStartEmpty || !isEndEmpty) {
// multiline template strings must have an empty first/last line
return context.report({
Expand Down
Expand Up @@ -15,7 +15,7 @@ const printNodeModifiers = (
): string =>
`${node.accessibility ?? ''}${
node.static ? ' static' : ''
} ${final} `.trimLeft();
} ${final} `.trimStart();

const isSupportedLiteral = (
node: TSESTree.Node,
Expand Down
2 changes: 2 additions & 0 deletions packages/eslint-plugin/src/rules/comma-spacing.ts
Expand Up @@ -110,6 +110,7 @@ export default createRule<Options, MessageIds>({
if (
prevToken &&
isTokenOnSameLine(prevToken, commaToken) &&
// eslint-disable-next-line deprecation/deprecation -- TODO - switch once our min ESLint version is 6.7.0
bradzacher marked this conversation as resolved.
Show resolved Hide resolved
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry if I'm forgetting something obvious, what was the line in the sand on ESLint versions here? Is it documented somewhere else?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh I see I found it on eslint.org, isSpaceBetweenTokens() - replaced by isSpaceBetween()

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah it's marked as deprecated in our types.
in the next major we'll probably do a massive bump to a higher ESLint version (maybe 6.7?) to enable us to switch to these new APIs and clean house as well.

spaceBefore !== sourceCode.isSpaceBetweenTokens(prevToken, commaToken)
) {
context.report({
Expand Down Expand Up @@ -139,6 +140,7 @@ export default createRule<Options, MessageIds>({
if (
nextToken &&
isTokenOnSameLine(commaToken, nextToken) &&
// eslint-disable-next-line deprecation/deprecation -- TODO - switch once our min ESLint version is 6.7.0
spaceAfter !== sourceCode.isSpaceBetweenTokens(commaToken, nextToken)
) {
context.report({
Expand Down
12 changes: 7 additions & 5 deletions packages/eslint-plugin/src/rules/dot-notation.ts
Expand Up @@ -4,6 +4,7 @@ import * as tsutils from 'tsutils';
import { getESLintCoreRule } from '../util/getESLintCoreRule';
import {
createRule,
getModifiers,
getParserServices,
InferMessageIdsTypeFromRule,
InferOptionsTypeFromRule,
Expand Down Expand Up @@ -95,13 +96,14 @@ export default createRule<Options, MessageIds>({
const propertySymbol = typeChecker.getSymbolAtLocation(
esTreeNodeToTSNodeMap.get(node.property),
);
const modifierKind =
propertySymbol?.getDeclarations()?.[0]?.modifiers?.[0].kind;
const modifierKind = getModifiers(
propertySymbol?.getDeclarations()?.[0],
)?.[0].kind;
if (
(allowPrivateClassPropertyAccess &&
modifierKind == ts.SyntaxKind.PrivateKeyword) ||
modifierKind === ts.SyntaxKind.PrivateKeyword) ||
(allowProtectedClassPropertyAccess &&
modifierKind == ts.SyntaxKind.ProtectedKeyword)
modifierKind === ts.SyntaxKind.ProtectedKeyword)
) {
return;
}
Expand All @@ -115,7 +117,7 @@ export default createRule<Options, MessageIds>({
const indexType = objectType
.getNonNullableType()
.getStringIndexType();
if (indexType != undefined) {
if (indexType !== undefined) {
return;
}
}
Expand Down
2 changes: 1 addition & 1 deletion packages/eslint-plugin/src/rules/prefer-optional-chain.ts
Expand Up @@ -230,7 +230,7 @@ export default util.createRule({
break;
}
const { rightText, shouldBreak } = breakIfInvalid({
rightNode: current.right as ValidChainTarget,
rightNode: current.right,
previousLeftText,
});
if (shouldBreak) {
Expand Down
1 change: 1 addition & 0 deletions packages/eslint-plugin/src/rules/space-before-blocks.ts
Expand Up @@ -46,6 +46,7 @@ export default util.createRule<Options, MessageIds>({
): void {
const precedingToken = sourceCode.getTokenBefore(node);
if (precedingToken && util.isTokenOnSameLine(precedingToken, node)) {
// eslint-disable-next-line deprecation/deprecation -- TODO - switch once our min ESLint version is 6.7.0
const hasSpace = sourceCode.isSpaceBetweenTokens(
precedingToken,
node as TSESTree.Token,
Expand Down
Expand Up @@ -146,6 +146,7 @@ export default util.createRule<Options, MessageIds>({
rightToken = sourceCode.getFirstToken(node, util.isOpeningParenToken)!;
leftToken = sourceCode.getTokenBefore(rightToken)!;
}
// eslint-disable-next-line deprecation/deprecation -- TODO - switch once our min ESLint version is 6.7.0
const hasSpacing = sourceCode.isSpaceBetweenTokens(leftToken, rightToken);

if (hasSpacing && functionConfig === 'never') {
Expand Down
Expand Up @@ -180,6 +180,7 @@ export default util.createRule<Options, MessageIds>({

if (type === ':' && previousToken.value === '?') {
if (
// eslint-disable-next-line deprecation/deprecation -- TODO - switch once our min ESLint version is 6.7.0
sourceCode.isSpaceBetweenTokens(previousToken, punctuatorTokenStart)
) {
context.report({
Expand Down
3 changes: 2 additions & 1 deletion packages/eslint-plugin/src/rules/unbound-method.ts
Expand Up @@ -2,6 +2,7 @@ import { AST_NODE_TYPES, TSESTree } from '@typescript-eslint/utils';
import * as tsutils from 'tsutils';
import * as ts from 'typescript';
import * as util from '../util';
import { getModifiers } from '../util';

//------------------------------------------------------------------------------
// Rule Definition
Expand Down Expand Up @@ -285,7 +286,7 @@ function checkMethod(
!(
ignoreStatic &&
tsutils.hasModifier(
valueDeclaration.modifiers,
getModifiers(valueDeclaration),
ts.SyntaxKind.StaticKeyword,
)
),
Expand Down
6 changes: 3 additions & 3 deletions packages/eslint-plugin/src/util/index.ts
Expand Up @@ -7,11 +7,11 @@ export * from './getFunctionHeadLoc';
export * from './getOperatorPrecedence';
export * from './getThisExpression';
export * from './getWrappingFixer';
export * from './misc';
export * from './objectIterators';
export * from './isNodeEqual';
export * from './isNullLiteral';
export * from './isUndefinedIdentifier';
export * from './isNodeEqual';
export * from './misc';
export * from './objectIterators';

// this is done for convenience - saves migrating all of the old rules
export * from '@typescript-eslint/type-utils';
Expand Down
Expand Up @@ -69,7 +69,7 @@ ruleTester.run('consistent-type-assertions', rule, {
],
}),
...batchedSingleLineTests({
code: `${OBJECT_LITERAL_AS_CASTS.trimRight()}${OBJECT_LITERAL_ARGUMENT_AS_CASTS}`,
code: `${OBJECT_LITERAL_AS_CASTS.trimEnd()}${OBJECT_LITERAL_ARGUMENT_AS_CASTS}`,
options: [
{
assertionStyle: 'as',
Expand All @@ -78,7 +78,7 @@ ruleTester.run('consistent-type-assertions', rule, {
],
}),
...batchedSingleLineTests({
code: `${OBJECT_LITERAL_ANGLE_BRACKET_CASTS.trimRight()}${OBJECT_LITERAL_ARGUMENT_ANGLE_BRACKET_CASTS}`,
code: `${OBJECT_LITERAL_ANGLE_BRACKET_CASTS.trimEnd()}${OBJECT_LITERAL_ARGUMENT_ANGLE_BRACKET_CASTS}`,
options: [
{
assertionStyle: 'angle-bracket',
Expand Down Expand Up @@ -287,7 +287,7 @@ ruleTester.run('consistent-type-assertions', rule, {
],
}),
...batchedSingleLineTests({
code: `${OBJECT_LITERAL_AS_CASTS.trimRight()}${OBJECT_LITERAL_ARGUMENT_AS_CASTS}`,
code: `${OBJECT_LITERAL_AS_CASTS.trimEnd()}${OBJECT_LITERAL_ARGUMENT_AS_CASTS}`,
options: [
{
assertionStyle: 'as',
Expand Down Expand Up @@ -330,7 +330,7 @@ ruleTester.run('consistent-type-assertions', rule, {
],
}),
...batchedSingleLineTests({
code: `${OBJECT_LITERAL_ANGLE_BRACKET_CASTS.trimRight()}${OBJECT_LITERAL_ARGUMENT_ANGLE_BRACKET_CASTS}`,
code: `${OBJECT_LITERAL_ANGLE_BRACKET_CASTS.trimEnd()}${OBJECT_LITERAL_ARGUMENT_ANGLE_BRACKET_CASTS}`,
options: [
{
assertionStyle: 'angle-bracket',
Expand Down
20 changes: 10 additions & 10 deletions packages/eslint-plugin/tests/rules/prefer-as-const.test.ts
Expand Up @@ -217,7 +217,7 @@ ruleTester.run('prefer-as-const', rule, {
class foo {
bar: 'baz' = 'baz';
}
`.trimRight(),
`,
output: null,
errors: [
{
Expand All @@ -231,7 +231,7 @@ class foo {
class foo {
bar = 'baz' as const;
}
`.trimRight(),
`,
},
],
},
Expand All @@ -242,7 +242,7 @@ class foo {
class foo {
bar: 2 = 2;
}
`.trimRight(),
`,
output: null,
errors: [
{
Expand All @@ -256,7 +256,7 @@ class foo {
class foo {
bar = 2 as const;
}
`.trimRight(),
`,
},
],
},
Expand All @@ -267,12 +267,12 @@ class foo {
class foo {
foo = <'bar'>'bar';
}
`.trimRight(),
`,
output: `
class foo {
foo = <const>'bar';
}
`.trimRight(),
`,
errors: [
{
messageId: 'preferConstAssertion',
Expand All @@ -286,12 +286,12 @@ class foo {
class foo {
foo = 'bar' as 'bar';
}
`.trimRight(),
`,
output: `
class foo {
foo = 'bar' as const;
}
`.trimRight(),
`,
errors: [
{
messageId: 'preferConstAssertion',
Expand All @@ -305,12 +305,12 @@ class foo {
class foo {
foo = 5 as 5;
}
`.trimRight(),
`,
output: `
class foo {
foo = 5 as const;
}
`.trimRight(),
`,
errors: [
{
messageId: 'preferConstAssertion',
Expand Down
3 changes: 0 additions & 3 deletions packages/scope-manager/src/lib/dom.iterable.ts
Expand Up @@ -30,9 +30,6 @@ export const dom_iterable = {
Headers: TYPE,
IDBDatabase: TYPE,
IDBObjectStore: TYPE,
MIDIInputMap: TYPE,
MIDIOutput: TYPE,
MIDIOutputMap: TYPE,
MediaKeyStatusMap: TYPE,
MediaList: TYPE,
MessageEvent: TYPE,
Expand Down