From 5d2b9626d86ca0ef14c2a45c233f096f356bccbd Mon Sep 17 00:00:00 2001 From: Damian Pieczynski Date: Fri, 7 Jun 2019 02:44:12 +0200 Subject: [PATCH] feat(*): support TypeScript versions >=3.2.1 <3.6.0 (#597) --- README.md | 2 +- package.json | 2 +- .../src/rules/indent-new-do-not-use/index.ts | 2 +- packages/eslint-plugin/src/rules/semi.ts | 2 +- packages/eslint-plugin/tests/configs/all.test.ts | 10 +++------- .../tools/validate-docs/check-for-rule-docs.ts | 4 ++-- .../tools/validate-docs/validate-table-rules.ts | 4 ++-- .../tools/validate-docs/validate-table-structure.ts | 4 ++-- .../src/eslint-utils/RuleCreator.ts | 10 ++-------- .../experimental-utils/src/eslint-utils/deepMerge.ts | 11 ++++------- packages/typescript-estree/src/parser.ts | 2 +- .../tests/lib/__snapshots__/convert.ts.snap | 2 +- yarn.lock | 8 ++++---- 13 files changed, 25 insertions(+), 38 deletions(-) diff --git a/README.md b/README.md index cf4261d695b..d0efc0b4919 100644 --- a/README.md +++ b/README.md @@ -203,7 +203,7 @@ The `canary` (latest master) version is: We will always endeavor to support the latest stable version of TypeScript. Sometimes, but not always, changes in TypeScript will not require breaking changes in this project, and so we are able to support more than one version of TypeScript. -**The version range of TypeScript currently supported by this parser is `>=3.2.1 <3.5.0`.** +**The version range of TypeScript currently supported by this parser is `>=3.2.1 <3.6.0`.** This is reflected in the `devDependency` requirement within the package.json file, and it is what the tests will be run against. We have an open `peerDependency` requirement in order to allow for experimentation on newer/beta versions of TypeScript. diff --git a/package.json b/package.json index e74b25def8d..2f0d94d38bd 100644 --- a/package.json +++ b/package.json @@ -78,6 +78,6 @@ "ts-jest": "^24.0.0", "ts-node": "^8.0.1", "tslint": "^5.11.0", - "typescript": ">=3.2.1 <3.5.0" + "typescript": ">=3.2.1 <3.6.0" } } diff --git a/packages/eslint-plugin/src/rules/indent-new-do-not-use/index.ts b/packages/eslint-plugin/src/rules/indent-new-do-not-use/index.ts index 1944fdf2bf5..14088c55378 100644 --- a/packages/eslint-plugin/src/rules/indent-new-do-not-use/index.ts +++ b/packages/eslint-plugin/src/rules/indent-new-do-not-use/index.ts @@ -1588,7 +1588,7 @@ export default createRule({ ); // For each ignored node selector, set up a listener to collect it into the `ignoredNodes` set. - const ignoredNodes = new Set(); + const ignoredNodes = new Set(); /** * Ignores a node diff --git a/packages/eslint-plugin/src/rules/semi.ts b/packages/eslint-plugin/src/rules/semi.ts index 6e40651dd2e..8130088eb30 100644 --- a/packages/eslint-plugin/src/rules/semi.ts +++ b/packages/eslint-plugin/src/rules/semi.ts @@ -52,7 +52,7 @@ export default util.createRule({ AST_NODE_TYPES.TSImportEqualsDeclaration, AST_NODE_TYPES.TSTypeAliasDeclaration, ].reduce((acc, node) => { - acc[node] = checkForSemicolon; + acc[node as string] = checkForSemicolon; return acc; }, {}); diff --git a/packages/eslint-plugin/tests/configs/all.test.ts b/packages/eslint-plugin/tests/configs/all.test.ts index 425e3a1426a..871576f2543 100644 --- a/packages/eslint-plugin/tests/configs/all.test.ts +++ b/packages/eslint-plugin/tests/configs/all.test.ts @@ -1,10 +1,6 @@ import rules from '../../src/rules'; import allConfig from '../../src/configs/all.json'; -import { TSESLint } from '@typescript-eslint/experimental-utils'; -interface IndexRules { - [name: string]: TSESLint.RuleModule; -} interface JsonRules { [name: string]: string; } @@ -12,10 +8,10 @@ interface JsonRules { describe('all.json config', () => { const RULE_NAME_PREFIX = '@typescript-eslint/'; - const typedRules: IndexRules = rules; - const notDeprecatedRuleNames = Object.keys(typedRules).reduce( + const rulesNames = Object.keys(rules) as (keyof typeof rules)[]; + const notDeprecatedRuleNames = rulesNames.reduce( (collection, name) => { - if (!typedRules[name].meta.deprecated) { + if (!rules[name].meta.deprecated) { collection.push(`${RULE_NAME_PREFIX}${name}`); } return collection; diff --git a/packages/eslint-plugin/tools/validate-docs/check-for-rule-docs.ts b/packages/eslint-plugin/tools/validate-docs/check-for-rule-docs.ts index be97971186c..6012d46a3f1 100644 --- a/packages/eslint-plugin/tools/validate-docs/check-for-rule-docs.ts +++ b/packages/eslint-plugin/tools/validate-docs/check-for-rule-docs.ts @@ -3,8 +3,8 @@ import fs from 'fs'; import path from 'path'; import { logRule } from './log'; -function checkForRuleDocs( - rules: Record>, +function checkForRuleDocs( + rules: Record>, ): boolean { const ruleDocs = new Set( fs.readdirSync(path.resolve(__dirname, '../../docs/rules')), diff --git a/packages/eslint-plugin/tools/validate-docs/validate-table-rules.ts b/packages/eslint-plugin/tools/validate-docs/validate-table-rules.ts index 98dd40437d9..5268bc67556 100644 --- a/packages/eslint-plugin/tools/validate-docs/validate-table-rules.ts +++ b/packages/eslint-plugin/tools/validate-docs/validate-table-rules.ts @@ -5,8 +5,8 @@ import marked from 'marked'; import path from 'path'; import { logRule } from './log'; -function validateTableRules( - rules: Record>, +function validateTableRules( + rules: Record>, rulesTable: marked.Tokens.Table, ): boolean { let hasErrors = false; diff --git a/packages/eslint-plugin/tools/validate-docs/validate-table-structure.ts b/packages/eslint-plugin/tools/validate-docs/validate-table-structure.ts index 5c4cdbdb68b..4b5bb4151f4 100644 --- a/packages/eslint-plugin/tools/validate-docs/validate-table-structure.ts +++ b/packages/eslint-plugin/tools/validate-docs/validate-table-structure.ts @@ -3,8 +3,8 @@ import chalk from 'chalk'; import marked from 'marked'; import { logError } from './log'; -function validateTableStructure( - rules: Record>, +function validateTableStructure( + rules: Record>, rulesTable: marked.Tokens.Table, ): boolean { const ruleNames = Object.keys(rules).sort(); diff --git a/packages/experimental-utils/src/eslint-utils/RuleCreator.ts b/packages/experimental-utils/src/eslint-utils/RuleCreator.ts index c1e381af72e..28b00b7ed9c 100644 --- a/packages/experimental-utils/src/eslint-utils/RuleCreator.ts +++ b/packages/experimental-utils/src/eslint-utils/RuleCreator.ts @@ -7,17 +7,11 @@ import { } from '../ts-eslint/Rule'; import { applyDefault } from './applyDefault'; -// Utility type to remove a list of properties from an object -type RemoveProps< - TObj extends Record, - TKeys extends keyof TObj -> = Pick>; - // we'll automatically add the url + tslint description for people. -type CreateRuleMetaDocs = RemoveProps; +type CreateRuleMetaDocs = Omit; type CreateRuleMeta = { docs: CreateRuleMetaDocs; -} & RemoveProps, 'docs'>; +} & Omit, 'docs'>; export function RuleCreator(urlCreator: (ruleName: string) => string) { // This function will get much easier to call when this is merged https://github.com/Microsoft/TypeScript/pull/26349 diff --git a/packages/experimental-utils/src/eslint-utils/deepMerge.ts b/packages/experimental-utils/src/eslint-utils/deepMerge.ts index 3ae3518e9f2..0685fa9b0f8 100644 --- a/packages/experimental-utils/src/eslint-utils/deepMerge.ts +++ b/packages/experimental-utils/src/eslint-utils/deepMerge.ts @@ -1,4 +1,4 @@ -export type ObjectLike = Record; +type ObjectLike = Record; /** * Check if the variable contains an object stricly rejecting arrays @@ -16,14 +16,11 @@ export function isObjectNotArray(obj: T | any[]): obj is T { * @param second The second object * @returns a new object */ -export function deepMerge( - first: ObjectLike = {}, - second: ObjectLike = {}, -): T { +export function deepMerge(first: ObjectLike = {}, second: ObjectLike = {}) { // get the unique set of keys across both objects const keys = new Set(Object.keys(first).concat(Object.keys(second))); - return Array.from(keys).reduce( + return Array.from(keys).reduce( (acc, key) => { const firstHasKey = key in first; const secondHasKey = key in second; @@ -44,6 +41,6 @@ export function deepMerge( return acc; }, - {} as T, + {} as ObjectLike, ); } diff --git a/packages/typescript-estree/src/parser.ts b/packages/typescript-estree/src/parser.ts index 1a963859d96..81825267fcb 100644 --- a/packages/typescript-estree/src/parser.ts +++ b/packages/typescript-estree/src/parser.ts @@ -15,7 +15,7 @@ import { * This needs to be kept in sync with the top-level README.md in the * typescript-eslint monorepo */ -const SUPPORTED_TYPESCRIPT_VERSIONS = '>=3.2.1 <3.5.0'; +const SUPPORTED_TYPESCRIPT_VERSIONS = '>=3.2.1 <3.6.0'; const ACTIVE_TYPESCRIPT_VERSION = ts.version; const isRunningSupportedTypeScriptVersion = semver.satisfies( ACTIVE_TYPESCRIPT_VERSION, diff --git a/packages/typescript-estree/tests/lib/__snapshots__/convert.ts.snap b/packages/typescript-estree/tests/lib/__snapshots__/convert.ts.snap index edb333d7c83..354bdd90f27 100644 --- a/packages/typescript-estree/tests/lib/__snapshots__/convert.ts.snap +++ b/packages/typescript-estree/tests/lib/__snapshots__/convert.ts.snap @@ -34,7 +34,7 @@ Object { }, "isDeclarationFile": false, "languageVariant": 1, - "languageVersion": 7, + "languageVersion": 8, "libReferenceDirectives": Array [], "lineMap": Array [ null, diff --git a/yarn.lock b/yarn.lock index 25bfac9a586..53025c9063a 100644 --- a/yarn.lock +++ b/yarn.lock @@ -7155,10 +7155,10 @@ typedarray@^0.0.6: resolved "https://registry.yarnpkg.com/typedarray/-/typedarray-0.0.6.tgz#867ac74e3864187b1d3d47d996a78ec5c8830777" integrity sha1-hnrHTjhkGHsdPUfZlqeOxciDB3c= -"typescript@>=3.2.1 <3.5.0": - version "3.4.5" - resolved "https://registry.yarnpkg.com/typescript/-/typescript-3.4.5.tgz#2d2618d10bb566572b8d7aad5180d84257d70a99" - integrity sha512-YycBxUb49UUhdNMU5aJ7z5Ej2XGmaIBL0x34vZ82fn3hGvD+bgrMrVDpatgz2f7YxUMJxMkbWxJZeAvDxVe7Vw== +"typescript@>=3.2.1 <3.6.0": + version "3.5.1" + resolved "https://registry.yarnpkg.com/typescript/-/typescript-3.5.1.tgz#ba72a6a600b2158139c5dd8850f700e231464202" + integrity sha512-64HkdiRv1yYZsSe4xC1WVgamNigVYjlssIoaH2HcZF0+ijsk5YK2g0G34w9wJkze8+5ow4STd22AynfO6ZYYLw== uglify-js@^3.1.4: version "3.5.10"