Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
feat: support TypeScript 4.8 (#5551)
  • Loading branch information
bradzacher committed Aug 29, 2022
1 parent 14b33a4 commit 81450ed
Show file tree
Hide file tree
Showing 48 changed files with 516 additions and 259 deletions.
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
1 change: 1 addition & 0 deletions .github/actions/prepare-install/action.yml
Expand Up @@ -44,3 +44,4 @@ runs:
run: |
yarn --ignore-engines --frozen-lockfile --ignore-scripts
yarn check-clean-workspace-after-install
yarn patch-package
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
4 changes: 0 additions & 4 deletions _redirects

This file was deleted.

25 changes: 25 additions & 0 deletions netlify.toml
@@ -0,0 +1,25 @@
# https://docs.netlify.com/configure-builds/file-based-configuration/#build-settings
[build]
base = ""
publish = "packages/website/build"
command = "NX_VERBOSE_LOGGING=true yarn patch-package && yarn nx build website"
[build.environment]
NETLIFY_USE_YARN = "true"
YARN_FLAGS = "--ignore-scripts"

# https://docs.netlify.com/configure-builds/file-based-configuration/#redirects
[[redirects]]
from = "/docs/linting"
to = "/docs"

[[redirects]]
from = "/docs/linting/type-linting"
to = "/docs/linting/typed-linting"

[[redirects]]
from = "/docs/linting/monorepo"
to = "/docs/linting/typed-linting/monorepos"

[[redirects]]
from = "/docs/linting/tslint"
to = "/docs/linting/troubleshooting/tslint"
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
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

0 comments on commit 81450ed

Please sign in to comment.