Skip to content

feat(*): change TypeScript version range to >=3.2.1 <3.4.0 #184

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

Merged
merged 4 commits into from
Feb 4, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.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 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.**

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,6 @@
"rimraf": "^2.6.3",
"ts-jest": "^23.10.4",
"tslint": "^5.11.0",
"typescript": "~3.2.1"
"typescript": ">=3.2.1 <3.4.0"
}
}
2 changes: 1 addition & 1 deletion packages/eslint-plugin/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,6 @@
},
"peerDependencies": {
"eslint": "^5.0.0",
"typescript": "~3.2.1"
"typescript": "*"
}
}
2 changes: 2 additions & 0 deletions packages/parser/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions packages/parser/src/parser-options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,5 @@ export interface ParserOptions {
errorOnTypeScriptSyntacticAndSemanticIssues?: boolean;
tsconfigRootDir?: string;
extraFileExtensions?: string[];
warnOnUnsupportedTypeScriptVersion?: boolean;
}
12 changes: 12 additions & 0 deletions packages/parser/src/parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
21 changes: 21 additions & 0 deletions packages/parser/tests/lib/parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,4 +84,25 @@ describe('parser', () => {
`"Cannot assign to read only property 'ArrayExpression' of object '#<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
});
});
});
3 changes: 1 addition & 2 deletions packages/typescript-estree/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@
"typescript": "*"
},
"devDependencies": {
"@typescript-eslint/shared-fixtures": "1.2.0",
"typescript": "~3.2.1"
"@typescript-eslint/shared-fixtures": "1.2.0"
}
}
10 changes: 6 additions & 4 deletions packages/typescript-estree/src/parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -287,7 +289,7 @@ interface ParseAndGenerateServicesResult<T extends ParserOptions> {
// Public
//------------------------------------------------------------------------------

export const version: string = packageJSON.version;
export const version: string = require('../package.json').version;

export function parse<T extends ParserOptions = ParserOptions>(
code: string,
Expand Down
8 changes: 4 additions & 4 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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.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==

uglify-js@^3.1.4:
version "3.4.9"
Expand Down