From 82143fa623313579c884a1ae3a52ac49b0353600 Mon Sep 17 00:00:00 2001 From: James Henry Date: Fri, 1 Feb 2019 08:10:19 -0500 Subject: [PATCH 1/2] feat(*): bump TypeScript version to ~3.3.1 --- README.md | 2 +- package.json | 2 +- packages/eslint-plugin/package.json | 2 +- packages/typescript-estree/package.json | 2 +- yarn.lock | 8 ++++---- 5 files changed, 8 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index 75e75658d069..648a8d21cd0d 100644 --- a/README.md +++ b/README.md @@ -44,7 +44,7 @@ The `canary` (latest master) version is: We will always endeavor to support the latest stable version of TypeScript. -The version of TypeScript currently supported by this parser is `~3.2.1`. 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. +The version of TypeScript currently supported by this parser is `~3.3.1`. 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. If you use a non-supported version of TypeScript, the parser will log a warning to the console. diff --git a/package.json b/package.json index 18059f7381ed..cccfdac4c072 100644 --- a/package.json +++ b/package.json @@ -69,6 +69,6 @@ "rimraf": "^2.6.3", "ts-jest": "^23.10.4", "tslint": "^5.11.0", - "typescript": "~3.2.1" + "typescript": "~3.3.1" } } diff --git a/packages/eslint-plugin/package.json b/packages/eslint-plugin/package.json index b0bf9f288e0e..e710176c4250 100644 --- a/packages/eslint-plugin/package.json +++ b/packages/eslint-plugin/package.json @@ -34,6 +34,6 @@ }, "peerDependencies": { "eslint": "^5.0.0", - "typescript": "~3.2.1" + "typescript": "*" } } diff --git a/packages/typescript-estree/package.json b/packages/typescript-estree/package.json index 5c7f52edf274..0e8b2e0fe6b3 100644 --- a/packages/typescript-estree/package.json +++ b/packages/typescript-estree/package.json @@ -43,6 +43,6 @@ }, "devDependencies": { "@typescript-eslint/shared-fixtures": "1.2.0", - "typescript": "~3.2.1" + "typescript": "~3.3.1" } } diff --git a/yarn.lock b/yarn.lock index 6980f52cafb8..8ece1e228794 100644 --- a/yarn.lock +++ b/yarn.lock @@ -7056,10 +7056,10 @@ typedarray@^0.0.6: resolved "https://registry.yarnpkg.com/typedarray/-/typedarray-0.0.6.tgz#867ac74e3864187b1d3d47d996a78ec5c8830777" integrity sha1-hnrHTjhkGHsdPUfZlqeOxciDB3c= -typescript@~3.2.1: - version "3.2.2" - resolved "https://registry.yarnpkg.com/typescript/-/typescript-3.2.2.tgz#fe8101c46aa123f8353523ebdcf5730c2ae493e5" - integrity sha512-VCj5UiSyHBjwfYacmDuc/NOk4QQixbE+Wn7MFJuS0nRuPQbof132Pw4u53dm264O8LPc2MVsc7RJNml5szurkg== +typescript@~3.3.1: + version "3.3.1" + resolved "https://registry.yarnpkg.com/typescript/-/typescript-3.3.1.tgz#6de14e1db4b8a006ac535e482c8ba018c55f750b" + integrity sha512-cTmIDFW7O0IHbn1DPYjkiebHxwtCMU+eTy30ZtJNBPF9j2O1ITu5XH2YnBeVRKWHqF+3JQwWJv0Q0aUgX8W7IA== uglify-js@^3.1.4: version "3.4.9" From f82553d83bd4b1b621c45eface01ec03f7eef022 Mon Sep 17 00:00:00 2001 From: James Henry Date: Mon, 4 Feb 2019 09:30:32 -0500 Subject: [PATCH 2/2] chore: updates --- README.md | 8 +++++--- package.json | 2 +- packages/parser/README.md | 2 ++ packages/parser/src/parser-options.ts | 1 + packages/parser/src/parser.ts | 12 ++++++++++++ packages/parser/tests/lib/parser.ts | 21 +++++++++++++++++++++ packages/typescript-estree/package.json | 3 +-- packages/typescript-estree/src/parser.ts | 10 ++++++---- yarn.lock | 2 +- 9 files changed, 50 insertions(+), 11 deletions(-) diff --git a/README.md b/README.md index 648a8d21cd0d..fb5dbbcababd 100644 --- a/README.md +++ b/README.md @@ -42,11 +42,13 @@ The `canary` (latest master) version is: ## Supported TypeScript Version -We will always endeavor to support the latest stable version of TypeScript. +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 of TypeScript currently supported by this parser is `~3.3.1`. 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. +**The version range of TypeScript currently supported by this parser is `>=3.2.1 <3.4.0`.** -If you use a non-supported version of TypeScript, the parser will log a warning to the console. +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. + +If you use a non-supported version of TypeScript, the parser will log a warning to the console. If you want to disable this warning, you can configure this in your `parserOptions`. See: [`@typescript-eslint/parser`](./packages/parser/) and [`@typescript-eslint/typescript-estree`](./packages/typescript-estree/). **Please ensure that you are using a supported version before submitting any issues/bug reports.** diff --git a/package.json b/package.json index a94187f67bf7..db01c0bf521c 100644 --- a/package.json +++ b/package.json @@ -69,6 +69,6 @@ "rimraf": "^2.6.3", "ts-jest": "^23.10.4", "tslint": "^5.11.0", - "typescript": "~3.3.1" + "typescript": ">=3.2.1 <3.4.0" } } diff --git a/packages/parser/README.md b/packages/parser/README.md index d0a6879b4e57..78d17e6388fb 100644 --- a/packages/parser/README.md +++ b/packages/parser/README.md @@ -54,6 +54,8 @@ The following additional configuration options are available by specifying them - **`extraFileExtensions`** - default `undefined`. This option allows you to provide one or more additional file extensions which should be considered in the TypeScript Program compilation. E.g. a `.vue` file +- **`warnOnUnsupportedTypeScriptVersion`** - default `true`. This option allows you to toggle the warning that the parser will give you if you use a version of TypeScript which is not explicitly supported + ### .eslintrc.json ```json diff --git a/packages/parser/src/parser-options.ts b/packages/parser/src/parser-options.ts index 95d6e54c182c..d374ac57b912 100644 --- a/packages/parser/src/parser-options.ts +++ b/packages/parser/src/parser-options.ts @@ -17,4 +17,5 @@ export interface ParserOptions { errorOnTypeScriptSyntacticAndSemanticIssues?: boolean; tsconfigRootDir?: string; extraFileExtensions?: string[]; + warnOnUnsupportedTypeScriptVersion?: boolean; } diff --git a/packages/parser/src/parser.ts b/packages/parser/src/parser.ts index 2dd32b383625..be3c3e7506ef 100644 --- a/packages/parser/src/parser.ts +++ b/packages/parser/src/parser.ts @@ -75,6 +75,18 @@ export function parseForESLint( } } + /** + * Allow the user to suppress the warning from typescript-estree if they are using an unsupported + * version of TypeScript + */ + const warnOnUnsupportedTypeScriptVersion = validateBoolean( + options.warnOnUnsupportedTypeScriptVersion, + true + ); + if (!warnOnUnsupportedTypeScriptVersion) { + parserOptions.loggerFn = false; + } + const { ast, services } = parseAndGenerateServices(code, parserOptions); ast.sourceType = options.sourceType; diff --git a/packages/parser/tests/lib/parser.ts b/packages/parser/tests/lib/parser.ts index 332be8b6e43c..6a844baae22e 100644 --- a/packages/parser/tests/lib/parser.ts +++ b/packages/parser/tests/lib/parser.ts @@ -84,4 +84,25 @@ describe('parser', () => { `"Cannot assign to read only property 'ArrayExpression' of object '#'"` ); }); + + it('`warnOnUnsupportedTypeScriptVersion: false` should set `loggerFn: false` on typescript-estree', () => { + const code = 'const valid = true;'; + const spy = jest.spyOn(typescriptESTree, 'parseAndGenerateServices'); + parseForESLint(code, { warnOnUnsupportedTypeScriptVersion: true }); + expect(spy).toHaveBeenCalledWith(code, { + ecmaFeatures: {}, + jsx: false, + sourceType: 'script', + useJSXTextNode: true + }); + parseForESLint(code, { warnOnUnsupportedTypeScriptVersion: false }); + expect(spy).toHaveBeenCalledWith(code, { + ecmaFeatures: {}, + jsx: false, + sourceType: 'script', + useJSXTextNode: true, + loggerFn: false, + warnOnUnsupportedTypeScriptVersion: false + }); + }); }); diff --git a/packages/typescript-estree/package.json b/packages/typescript-estree/package.json index 0e8b2e0fe6b3..50432ba4d214 100644 --- a/packages/typescript-estree/package.json +++ b/packages/typescript-estree/package.json @@ -42,7 +42,6 @@ "typescript": "*" }, "devDependencies": { - "@typescript-eslint/shared-fixtures": "1.2.0", - "typescript": "~3.3.1" + "@typescript-eslint/shared-fixtures": "1.2.0" } } diff --git a/packages/typescript-estree/src/parser.ts b/packages/typescript-estree/src/parser.ts index 3c9680df06d4..ca3d27db77e1 100644 --- a/packages/typescript-estree/src/parser.ts +++ b/packages/typescript-estree/src/parser.ts @@ -18,9 +18,11 @@ import * as es from './typedefs'; import { Extra, ParserOptions } from './parser-options'; import { getFirstSemanticOrSyntacticError } from './semantic-errors'; -const packageJSON = require('../package.json'); - -const SUPPORTED_TYPESCRIPT_VERSIONS = packageJSON.devDependencies.typescript; +/** + * 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.4.0'; const ACTIVE_TYPESCRIPT_VERSION = ts.version; const isRunningSupportedTypeScriptVersion = semver.satisfies( ACTIVE_TYPESCRIPT_VERSION, @@ -287,7 +289,7 @@ interface ParseAndGenerateServicesResult { // Public //------------------------------------------------------------------------------ -export const version: string = packageJSON.version; +export const version: string = require('../package.json').version; export function parse( code: string, diff --git a/yarn.lock b/yarn.lock index e56cedb297c9..51d8518fb375 100644 --- a/yarn.lock +++ b/yarn.lock @@ -7056,7 +7056,7 @@ typedarray@^0.0.6: resolved "https://registry.yarnpkg.com/typedarray/-/typedarray-0.0.6.tgz#867ac74e3864187b1d3d47d996a78ec5c8830777" integrity sha1-hnrHTjhkGHsdPUfZlqeOxciDB3c= -typescript@~3.3.1: +"typescript@>=3.2.1 <3.4.0": version "3.3.1" resolved "https://registry.yarnpkg.com/typescript/-/typescript-3.3.1.tgz#6de14e1db4b8a006ac535e482c8ba018c55f750b" integrity sha512-cTmIDFW7O0IHbn1DPYjkiebHxwtCMU+eTy30ZtJNBPF9j2O1ITu5XH2YnBeVRKWHqF+3JQwWJv0Q0aUgX8W7IA==