From 7ed099706d1175bb92b9422a4c71f7e81420ddc2 Mon Sep 17 00:00:00 2001 From: Jed Fox Date: Wed, 23 Jan 2019 07:51:47 -0500 Subject: [PATCH 01/13] docs(eslint-plugin): update rule names in the roadmap (#108) --- packages/eslint-plugin/ROADMAP.md | 144 +++++++++++++++--------------- 1 file changed, 72 insertions(+), 72 deletions(-) diff --git a/packages/eslint-plugin/ROADMAP.md b/packages/eslint-plugin/ROADMAP.md index eb0cf5e33ec4..1fce16992a9c 100644 --- a/packages/eslint-plugin/ROADMAP.md +++ b/packages/eslint-plugin/ROADMAP.md @@ -10,30 +10,30 @@ ### TypeScript-specific -| TSLint rule | | ESLint rule | -| --------------------------------- | :-: | -------------------------------------------- | -| [`adjacent-overload-signatures`] | ✅ | [`typescript/adjacent-overload-signatures`] | -| [`ban-types`] | ✅ | [`typescript/ban-types`] | -| [`member-access`] | ✅ | [`typescript/explicit-member-accessibility`] | -| [`member-ordering`] | ✅ | [`typescript/member-ordering`] | -| [`no-any`] | ✅ | [`typescript/no-explicit-any`] | -| [`no-empty-interface`] | ✅ | [`typescript/no-empty-interface`] | -| [`no-import-side-effect`] | 🔌 | [`import/no-unassigned-import`] | -| [`no-inferrable-types`] | ✅ | [`typescript/no-inferrable-types`] | -| [`no-internal-module`] | ✅ | [`typescript/prefer-namespace-keyword`] | -| [`no-magic-numbers`] | 🌟 | [`no-magic-numbers`][no-magic-numbers] | -| [`no-namespace`] | ✅ | [`typescript/no-namespace`] | -| [`no-non-null-assertion`] | ✅ | [`typescript/no-non-null-assertion`] | -| [`no-parameter-reassignment`] | ✅ | [`no-param-reassign`][no-param-reassign] | -| [`no-reference`] | ✅ | [`typescript/no-triple-slash-reference`] | -| [`no-unnecessary-type-assertion`] | 🛑 | N/A | -| [`no-var-requires`] | ✅ | [`typescript/no-var-requires`] | -| [`only-arrow-functions`] | 🔌 | [`prefer-arrow/prefer-arrow-functions`] | -| [`prefer-for-of`] | 🛑 | N/A | -| [`promise-function-async`] | 🛑 | N/A ([relevant plugin][plugin:promise]) | -| [`typedef`] | 🛑 | N/A | -| [`typedef-whitespace`] | ✅ | [`typescript/type-annotation-spacing`] | -| [`unified-signatures`] | 🛑 | N/A | +| TSLint rule | | ESLint rule | +| --------------------------------- | :-: | ---------------------------------------------------- | +| [`adjacent-overload-signatures`] | ✅ | [`@typescript-eslint/adjacent-overload-signatures`] | +| [`ban-types`] | ✅ | [`@typescript-eslint/ban-types`] | +| [`member-access`] | ✅ | [`@typescript-eslint/explicit-member-accessibility`] | +| [`member-ordering`] | ✅ | [`@typescript-eslint/member-ordering`] | +| [`no-any`] | ✅ | [`@typescript-eslint/no-explicit-any`] | +| [`no-empty-interface`] | ✅ | [`@typescript-eslint/no-empty-interface`] | +| [`no-import-side-effect`] | 🔌 | [`import/no-unassigned-import`] | +| [`no-inferrable-types`] | ✅ | [`@typescript-eslint/no-inferrable-types`] | +| [`no-internal-module`] | ✅ | [`@typescript-eslint/prefer-namespace-keyword`] | +| [`no-magic-numbers`] | 🌟 | [`no-magic-numbers`][no-magic-numbers] | +| [`no-namespace`] | ✅ | [`@typescript-eslint/no-namespace`] | +| [`no-non-null-assertion`] | ✅ | [`@typescript-eslint/no-non-null-assertion`] | +| [`no-parameter-reassignment`] | ✅ | [`no-param-reassign`][no-param-reassign] | +| [`no-reference`] | ✅ | [`@typescript-eslint/no-triple-slash-reference`] | +| [`no-unnecessary-type-assertion`] | 🛑 | N/A | +| [`no-var-requires`] | ✅ | [`@typescript-eslint/no-var-requires`] | +| [`only-arrow-functions`] | 🔌 | [`prefer-arrow/prefer-arrow-functions`] | +| [`prefer-for-of`] | 🛑 | N/A | +| [`promise-function-async`] | 🛑 | N/A ([relevant plugin][plugin:promise]) | +| [`typedef`] | 🛑 | N/A | +| [`typedef-whitespace`] | ✅ | [`@typescript-eslint/type-annotation-spacing`] | +| [`unified-signatures`] | 🛑 | N/A | ### Functionality @@ -64,9 +64,9 @@ | [`no-inferred-empty-object-type`] | 🛑 | N/A | | [`no-invalid-template-strings`] | 🌟 | [`no-template-curly-in-string`][no-template-curly-in-string] | | [`no-invalid-this`] | 🌟 | [`no-invalid-this`][no-invalid-this] | -| [`no-misused-new`] | ✅ | [`typescript/no-misused-new`] | +| [`no-misused-new`] | ✅ | [`@typescript-eslint/no-misused-new`] | | [`no-null-keyword`] | 🔌 | [`no-null/no-null`] (doesn’t handle `null` type) | -| [`no-object-literal-type-assertion`] | ✅ | [`typescript/no-object-literal-type-assertion`] | +| [`no-object-literal-type-assertion`] | ✅ | [`@typescript-eslint/no-object-literal-type-assertion`] | | [`no-return-await`] | 🌟 | [`no-return-await`][no-return-await] | | [`no-shadowed-variable`] | 🌟 | [`no-shadow`][no-shadow] | | [`no-sparse-arrays`] | 🌟 | [`no-sparse-arrays`][no-sparse-arrays] | @@ -74,14 +74,14 @@ | [`no-string-throw`] | 🌟 | [`no-throw-literal`][no-throw-literal] | | [`no-submodule-imports`] | 🌓 | [`import/no-internal-modules`] (slightly different) | | [`no-switch-case-fall-through`] | 🌟 | [`no-fallthrough`][no-fallthrough] | -| [`no-this-assignment`] | ✅ | [`typescript/no-this-alias`] | +| [`no-this-assignment`] | ✅ | [`@typescript-eslint/no-this-alias`] | | [`no-unbound-method`] | 🛑 | N/A | -| [`no-unnecessary-class`] | ✅ | [`typescript/no-extraneous-class`] | +| [`no-unnecessary-class`] | ✅ | [`@typescript-eslint/no-extraneous-class`] | | [`no-unsafe-any`] | 🛑 | N/A | | [`no-unsafe-finally`] | 🌟 | [`no-unsafe-finally`][no-unsafe-finally] | | [`no-unused-expression`] | 🌟 | [`no-unused-expression`][no-unused-expressions] | | [`no-unused-variable`] | 🌓 | [`no-unused-vars`][no-unused-vars] [2] | -| [`no-use-before-declare`] | ✅ | [`typescript/no-use-before-define`] | +| [`no-use-before-declare`] | ✅ | [`@typescript-eslint/no-use-before-define`] | | [`no-var-keyword`] | 🌟 | [`no-var`][no-var] | | [`no-void-expression`] | 🌟 | [`no-void`][no-void] | | [`prefer-conditional-expression`] | 🛑 | N/A | @@ -97,7 +97,7 @@ | [`use-isnan`] | 🌟 | [`use-isnan`][use-isnan] | [1] The ESLint rule also supports silencing with an extra set of parens (`if ((foo = bar)) {}`) -[2] Missing private class member support. [`typescript/no-unused-vars`] adds support for some TS-specific features. +[2] Missing private class member support. [`@typescript-eslint/no-unused-vars`] adds support for some TS-specific features. ### Maintainability @@ -106,7 +106,7 @@ | [`cyclomatic-complexity`] | 🌟 | [`complexity`][complexity] | | [`deprecation`] | 🌓 | [`import/no-deprecated`] [1] | | [`eofline`] | 🌟 | [`eol-last`][eol-last] | -| [`indent`] | ✅ | [`typescript/indent`] or [Prettier] | +| [`indent`] | ✅ | [`@typescript-eslint/indent`] or [Prettier] | | [`linebreak-style`] | 🌟 | [`linebreak-style`][linebreak-style] or [Prettier] | | [`max-classes-per-file`] | 🌟 | [`max-classes-per-file`][max-classes-per-file] | | [`max-file-line-count`] | 🌟 | [`max-lines`][max-lines] | @@ -128,30 +128,30 @@ | TSLint rule | | ESLint rule | | ----------------------------------- | :-: | ----------------------------------------------------------------------------------- | | [`align`] | 🛑 | N/A | -| [`array-type`] | ✅ | [`typescript/array-type`] | +| [`array-type`] | ✅ | [`@typescript-eslint/array-type`] | | [`arrow-parens`] | 🌟 | [`arrow-parens`][arrow-parens] | | [`arrow-return-shorthand`] | 🌟 | [`arrow-body-style`][arrow-body-style] | | [`binary-expression-operand-order`] | 🌟 | [`yoda`][yoda] | | [`callable-types`] | 🛑 | N/A | -| [`class-name`] | ✅ | [`typescript/class-name-casing`] | +| [`class-name`] | ✅ | [`@typescript-eslint/class-name-casing`] | | [`comment-format`] | 🌟 | [`capitalized-comments`][capitalized-comments] & [`spaced-comment`][spaced-comment] | | [`completed-docs`] | 🔌 | [`eslint-plugin-jsdoc`][plugin:jsdoc] | | [`encoding`] | 🛑 | N/A | | [`file-header`] | 🔌 | [`eslint-plugin-header`][plugin:header] or [`-file-header`][plugin:file-header] | | [`file-name-casing`] | 🔌 | [`unicorn/filename-case`] | | [`import-spacing`] | 🔌 | Use [Prettier] | -| [`interface-name`] | ✅ | [`typescript/interface-name-prefix`] | -| [`interface-over-type-literal`] | ✅ | [`typescript/prefer-interface`] | +| [`interface-name`] | ✅ | [`@typescript-eslint/interface-name-prefix`] | +| [`interface-over-type-literal`] | ✅ | [`@typescript-eslint/prefer-interface`] | | [`jsdoc-format`] | 🌓 | [`valid-jsdoc`][valid-jsdoc] or [`eslint-plugin-jsdoc`][plugin:jsdoc] | | [`match-default-export-name`] | 🛑 | N/A | | [`newline-before-return`] | 🌟 | [`padding-line-between-statements`][padding-line-between-statements] [1] | | [`newline-per-chained-call`] | 🌟 | [`newline-per-chained-call`][newline-per-chained-call] | | [`new-parens`] | 🌟 | [`new-parens`][new-parens] | -| [`no-angle-bracket-type-assertion`] | ✅ | [`typescript/no-angle-bracket-type-assertion`] | +| [`no-angle-bracket-type-assertion`] | ✅ | [`@typescript-eslint/no-angle-bracket-type-assertion`] | | [`no-boolean-literal-compare`] | 🛑 | N/A | | [`no-consecutive-blank-lines`] | 🌟 | [`no-multiple-empty-lines`][no-multiple-empty-lines] | | [`no-irregular-whitespace`] | 🌟 | [`no-irregular-whitespace`][no-irregular-whitespace] with `skipStrings: false` | -| [`no-parameter-properties`] | ✅ | [`typescript/no-parameter-properties`] | +| [`no-parameter-properties`] | ✅ | [`@typescript-eslint/no-parameter-properties`] | | [`no-redundant-jsdoc`] | 🛑 | N/A ([open issue](https://github.com/gajus/eslint-plugin-jsdoc/issues/134)) | | [`no-reference-import`] | 🛑 | N/A | | [`no-trailing-whitespace`] | 🌟 | [`no-trailing-spaces`][no-trailing-spaces] | @@ -175,12 +175,12 @@ | [`space-before-function-paren`] | 🌟 | [`space-before-function-paren`][space-after-function-paren] | | [`space-within-parens`] | 🌟 | [`space-in-parens`][space-in-parens] | | [`switch-final-break`] | 🛑 | N/A | -| [`type-literal-delimiter`] | ✅ | [`typescript/member-delimiter-style`] | +| [`type-literal-delimiter`] | ✅ | [`@typescript-eslint/member-delimiter-style`] | | [`variable-name`] | 🌟 | [2] | | [`whitespace`] | 🔌 | Use [Prettier] | [1] Recommended config: `["error", { blankLine: "always", prev: "*", next: "return" }]` -[2] [`camelcase`][camelcase], [`no-underscore-dangle`][no-underscore-dangle], [`id-blacklist`][id-blacklist], and/or [`id-match`] +[2] [`camelcase`][camelcase], [`no-underscore-dangle`][no-underscore-dangle], [`id-blacklist`][id-blacklist], and/or [`id-match`][id-match] ## tslint-microsoft-contrib rules @@ -200,10 +200,10 @@ Relevant plugins: [`chai-expect-keywords`](https://github.com/gavinaiken/eslint- ### TypeScript -| tslint-microsoft-contrib rule | | ESLint rule | -| ----------------------------- | :-: | -------------------------------------------------- | -| `prefer-array-literal` | 🌓 | [`typescript/no-array-constructor`] [1] | -| `prefer-type-cast` | 🛑 | N/A | +| tslint-microsoft-contrib rule | | ESLint rule | +| ----------------------------- | :-: | ---------------------------------------------------------- | +| `prefer-array-literal` | 🌓 | [`@typescript-eslint/no-array-constructor`] [1] | +| `prefer-type-cast` | 🛑 | N/A | [1] ESLint rule is slightly less strict, allowing `new Array()` and `Array(2)`. @@ -282,7 +282,7 @@ Relevant plugins: [`chai-expect-keywords`](https://github.com/gavinaiken/eslint- | `no-exec-script` | 🌓 | Use [`no-restricted-syntax`][no-restricted-syntax] | | `no-jquery-raw-elements` | 🛑 | N/A | | `no-unsupported-browser-code` | 🔌 | [`eslint-plugin-compat`][plugin:compat] | -| `react-this-binding-issue` | 🛑 | | +| `react-this-binding-issue` | 🛑 | N/A | | `react-tsx-curly-spacing` | 🔌 | [`react/jsx-curly-spacing`] | | `react-unused-props-and-state` | 🌓 | [`react/no-unused-state`] | @@ -557,34 +557,34 @@ Relevant plugins: [`chai-expect-keywords`](https://github.com/gavinaiken/eslint- -[`typescript/adjacent-overload-signatures`]: https://github.com/bradzacher/@typescript-eslint/eslint-plugin/blob/master/docs/rules/adjacent-overload-signatures.md -[`typescript/ban-types`]: https://github.com/bradzacher/@typescript-eslint/eslint-plugin/blob/master/docs/rules/ban-types.md -[`typescript/explicit-member-accessibility`]: https://github.com/bradzacher/@typescript-eslint/eslint-plugin/blob/master/docs/rules/explicit-member-accessibility.md -[`typescript/member-ordering`]: https://github.com/bradzacher/@typescript-eslint/eslint-plugin/blob/master/docs/rules/member-ordering.md -[`typescript/no-explicit-any`]: https://github.com/bradzacher/@typescript-eslint/eslint-plugin/blob/master/docs/rules/no-explicit-any.md -[`typescript/no-empty-interface`]: https://github.com/bradzacher/@typescript-eslint/eslint-plugin/blob/master/docs/rules/no-empty-interface.md -[`typescript/no-inferrable-types`]: https://github.com/bradzacher/@typescript-eslint/eslint-plugin/blob/master/docs/rules/no-inferrable-types.md -[`typescript/prefer-namespace-keyword`]: https://github.com/bradzacher/@typescript-eslint/eslint-plugin/blob/master/docs/rules/prefer-namespace-keyword.md -[`typescript/no-namespace`]: https://github.com/bradzacher/@typescript-eslint/eslint-plugin/blob/master/docs/rules/no-namespace.md -[`typescript/no-non-null-assertion`]: https://github.com/bradzacher/@typescript-eslint/eslint-plugin/blob/master/docs/rules/no-non-null-assertion.md -[`typescript/no-triple-slash-reference`]: https://github.com/bradzacher/@typescript-eslint/eslint-plugin/blob/master/docs/rules/no-triple-slash-reference.md -[`typescript/no-var-requires`]: https://github.com/bradzacher/@typescript-eslint/eslint-plugin/blob/master/docs/rules/no-var-requires.md -[`typescript/type-annotation-spacing`]: https://github.com/bradzacher/@typescript-eslint/eslint-plugin/blob/master/docs/rules/type-annotation-spacing.md -[`typescript/no-misused-new`]: https://github.com/bradzacher/@typescript-eslint/eslint-plugin/blob/master/docs/rules/no-misused-new.md -[`typescript/no-object-literal-type-assertion`]: https://github.com/bradzacher/@typescript-eslint/eslint-plugin/blob/master/docs/rules/no-object-literal-type-assertion.md -[`typescript/no-this-alias`]: https://github.com/bradzacher/@typescript-eslint/eslint-plugin/blob/master/docs/rules/no-this-alias.md -[`typescript/no-extraneous-class`]: https://github.com/bradzacher/@typescript-eslint/eslint-plugin/blob/master/docs/rules/no-extraneous-class.md -[`typescript/no-unused-vars`]: https://github.com/bradzacher/@typescript-eslint/eslint-plugin/blob/master/docs/rules/no-unused-vars.md -[`typescript/no-use-before-define`]: https://github.com/bradzacher/@typescript-eslint/eslint-plugin/blob/master/docs/rules/no-use-before-define.md -[`typescript/indent`]: https://github.com/bradzacher/@typescript-eslint/eslint-plugin/blob/master/docs/rules/indent.md -[`typescript/array-type`]: https://github.com/bradzacher/@typescript-eslint/eslint-plugin/blob/master/docs/rules/array-type.md -[`typescript/class-name-casing`]: https://github.com/bradzacher/@typescript-eslint/eslint-plugin/blob/master/docs/rules/class-name-casing.md -[`typescript/interface-name-prefix`]: https://github.com/bradzacher/@typescript-eslint/eslint-plugin/blob/master/docs/rules/interface-name-prefix.md -[`typescript/no-angle-bracket-type-assertion`]: https://github.com/bradzacher/@typescript-eslint/eslint-plugin/blob/master/docs/rules/no-angle-bracket-type-assertion.md -[`typescript/no-parameter-properties`]: https://github.com/bradzacher/@typescript-eslint/eslint-plugin/blob/master/docs/rules/no-parameter-properties.md -[`typescript/member-delimiter-style`]: https://github.com/bradzacher/@typescript-eslint/eslint-plugin/blob/master/docs/rules/member-delimiter-style.md -[`typescript/prefer-interface`]: https://github.com/bradzacher/@typescript-eslint/eslint-plugin/blob/master/docs/rules/prefer-interface.md -[`typescript/no-array-constructor`]: https://github.com/bradzacher/@typescript-eslint/eslint-plugin/blob/master/docs/rules/no-array-constructor.md +[`@typescript-eslint/adjacent-overload-signatures`]: https://github.com/bradzacher/@typescript-eslint/eslint-plugin/blob/master/docs/rules/adjacent-overload-signatures.md +[`@typescript-eslint/ban-types`]: https://github.com/bradzacher/@typescript-eslint/eslint-plugin/blob/master/docs/rules/ban-types.md +[`@typescript-eslint/explicit-member-accessibility`]: https://github.com/bradzacher/@typescript-eslint/eslint-plugin/blob/master/docs/rules/explicit-member-accessibility.md +[`@typescript-eslint/member-ordering`]: https://github.com/bradzacher/@typescript-eslint/eslint-plugin/blob/master/docs/rules/member-ordering.md +[`@typescript-eslint/no-explicit-any`]: https://github.com/bradzacher/@typescript-eslint/eslint-plugin/blob/master/docs/rules/no-explicit-any.md +[`@typescript-eslint/no-empty-interface`]: https://github.com/bradzacher/@typescript-eslint/eslint-plugin/blob/master/docs/rules/no-empty-interface.md +[`@typescript-eslint/no-inferrable-types`]: https://github.com/bradzacher/@typescript-eslint/eslint-plugin/blob/master/docs/rules/no-inferrable-types.md +[`@typescript-eslint/prefer-namespace-keyword`]: https://github.com/bradzacher/@typescript-eslint/eslint-plugin/blob/master/docs/rules/prefer-namespace-keyword.md +[`@typescript-eslint/no-namespace`]: https://github.com/bradzacher/@typescript-eslint/eslint-plugin/blob/master/docs/rules/no-namespace.md +[`@typescript-eslint/no-non-null-assertion`]: https://github.com/bradzacher/@typescript-eslint/eslint-plugin/blob/master/docs/rules/no-non-null-assertion.md +[`@typescript-eslint/no-triple-slash-reference`]: https://github.com/bradzacher/@typescript-eslint/eslint-plugin/blob/master/docs/rules/no-triple-slash-reference.md +[`@typescript-eslint/no-var-requires`]: https://github.com/bradzacher/@typescript-eslint/eslint-plugin/blob/master/docs/rules/no-var-requires.md +[`@typescript-eslint/type-annotation-spacing`]: https://github.com/bradzacher/@typescript-eslint/eslint-plugin/blob/master/docs/rules/type-annotation-spacing.md +[`@typescript-eslint/no-misused-new`]: https://github.com/bradzacher/@typescript-eslint/eslint-plugin/blob/master/docs/rules/no-misused-new.md +[`@typescript-eslint/no-object-literal-type-assertion`]: https://github.com/bradzacher/@typescript-eslint/eslint-plugin/blob/master/docs/rules/no-object-literal-type-assertion.md +[`@typescript-eslint/no-this-alias`]: https://github.com/bradzacher/@typescript-eslint/eslint-plugin/blob/master/docs/rules/no-this-alias.md +[`@typescript-eslint/no-extraneous-class`]: https://github.com/bradzacher/@typescript-eslint/eslint-plugin/blob/master/docs/rules/no-extraneous-class.md +[`@typescript-eslint/no-unused-vars`]: https://github.com/bradzacher/@typescript-eslint/eslint-plugin/blob/master/docs/rules/no-unused-vars.md +[`@typescript-eslint/no-use-before-define`]: https://github.com/bradzacher/@typescript-eslint/eslint-plugin/blob/master/docs/rules/no-use-before-define.md +[`@typescript-eslint/indent`]: https://github.com/bradzacher/@typescript-eslint/eslint-plugin/blob/master/docs/rules/indent.md +[`@typescript-eslint/array-type`]: https://github.com/bradzacher/@typescript-eslint/eslint-plugin/blob/master/docs/rules/array-type.md +[`@typescript-eslint/class-name-casing`]: https://github.com/bradzacher/@typescript-eslint/eslint-plugin/blob/master/docs/rules/class-name-casing.md +[`@typescript-eslint/interface-name-prefix`]: https://github.com/bradzacher/@typescript-eslint/eslint-plugin/blob/master/docs/rules/interface-name-prefix.md +[`@typescript-eslint/no-angle-bracket-type-assertion`]: https://github.com/bradzacher/@typescript-eslint/eslint-plugin/blob/master/docs/rules/no-angle-bracket-type-assertion.md +[`@typescript-eslint/no-parameter-properties`]: https://github.com/bradzacher/@typescript-eslint/eslint-plugin/blob/master/docs/rules/no-parameter-properties.md +[`@typescript-eslint/member-delimiter-style`]: https://github.com/bradzacher/@typescript-eslint/eslint-plugin/blob/master/docs/rules/member-delimiter-style.md +[`@typescript-eslint/prefer-interface`]: https://github.com/bradzacher/@typescript-eslint/eslint-plugin/blob/master/docs/rules/prefer-interface.md +[`@typescript-eslint/no-array-constructor`]: https://github.com/bradzacher/@typescript-eslint/eslint-plugin/blob/master/docs/rules/no-array-constructor.md From ba8ebb262e202103087b53c2ce3ca72c33743773 Mon Sep 17 00:00:00 2001 From: Brad Zacher Date: Wed, 23 Jan 2019 05:04:10 -0800 Subject: [PATCH 02/13] chore: add vscode shared config files (#126) --- .gitignore | 1 - .vscode/extensions.json | 8 ++++++++ .vscode/launch.json | 21 +++++++++++++++++++++ .vscode/settings.json | 26 ++++++++++++++++++++++++++ 4 files changed, 55 insertions(+), 1 deletion(-) create mode 100644 .vscode/extensions.json create mode 100644 .vscode/launch.json create mode 100644 .vscode/settings.json diff --git a/.gitignore b/.gitignore index 213ae9c36aa4..41847c7fd604 100644 --- a/.gitignore +++ b/.gitignore @@ -61,6 +61,5 @@ typings/ .next .DS_Store -.vscode .idea dist diff --git a/.vscode/extensions.json b/.vscode/extensions.json new file mode 100644 index 000000000000..0a2e1c827047 --- /dev/null +++ b/.vscode/extensions.json @@ -0,0 +1,8 @@ +{ + "recommendations": [ + "esbenp.prettier-vscode", + "dbaeumer.vscode-eslint", + "editorconfig.editorconfig" + ], + "unwantedRecommendations": ["hookyqr.beautify", "dbaeumer.jshint"] +} diff --git a/.vscode/launch.json b/.vscode/launch.json new file mode 100644 index 000000000000..18bf27ada556 --- /dev/null +++ b/.vscode/launch.json @@ -0,0 +1,21 @@ +{ + // Use IntelliSense to learn about possible attributes. + // Hover to view descriptions of existing attributes. + // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 + "version": "0.2.0", + "configurations": [ + { + "type": "node", + "request": "launch", + "name": "Jest Test Current eslint-plugin Rule", + "cwd": "${workspaceFolder}/packages/eslint-plugin/", + "program": "${workspaceFolder}/node_modules/jest/bin/jest.js", + "args": [ + "--colors", + "${workspaceFolder}/packages/eslint-plugin/tests/lib/rules/${fileBasename}" + ], + "console": "integratedTerminal", + "internalConsoleOptions": "neverOpen" + } + ] +} diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 000000000000..adcf2422e8f3 --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,26 @@ + +{ + // An array of language ids which should be validated by ESLint + "eslint.validate": [ + "javascript", + "javascriptreact", + { + "language": "typescript", + "autoFix": true + }, + { + "language": "typescriptreact", + "autoFix": true + } + ], + + // When enabled, will trim trailing whitespace when saving a file. + "files.trimTrailingWhitespace": true, + + // typescript auto-format settings + "typescript.tsdk": "node_modules/typescript/lib", + "javascript.preferences.importModuleSpecifier": "auto", + "typescript.preferences.importModuleSpecifier": "auto", + "javascript.preferences.quoteStyle": "single", + "typescript.preferences.quoteStyle": "single" +} From aa9d1e175c8dc6fc4b8c4db47648120478a71ba7 Mon Sep 17 00:00:00 2001 From: James Henry Date: Wed, 23 Jan 2019 08:54:50 -0500 Subject: [PATCH 03/13] fix(eslint-plugin): make parser services error clearer (#132) --- packages/eslint-plugin/README.md | 89 +++++++++++-------- packages/eslint-plugin/lib/util.js | 6 +- .../tests/lib/rules/restrict-plus-operands.js | 1 - packages/parser/README.md | 11 ++- 4 files changed, 68 insertions(+), 39 deletions(-) diff --git a/packages/eslint-plugin/README.md b/packages/eslint-plugin/README.md index 108dd0f994be..4f6f771d47c4 100644 --- a/packages/eslint-plugin/README.md +++ b/packages/eslint-plugin/README.md @@ -51,6 +51,23 @@ You can also enable all the recommended rules at once. Add `plugin:@typescript-e } ``` +If you want to use rules which require type information, you will need to specify a path to your tsconfig.json file in the "project" property of "parserOptions". + +```json +{ + "parser": "@typescript-eslint/parser", + "parserOptions": { + "project": "./tsconfig.json" + }, + "plugins": ["@typescript-eslint"], + "rules": { + "@typescript-eslint/restrict-plus-operands": "error" + } +} +``` + +See [@typescript-eslint/parser's README.md](../parser/README.md) for more information on the available "parserOptions". + ## Supported Rules @@ -59,41 +76,41 @@ You can also enable all the recommended rules at once. Add `plugin:@typescript-e **Key**: :heavy_check_mark: = recommended, :wrench: = fixable -| Name | Description | :heavy_check_mark: | :wrench: | -| ---- | ----------- | ------------------ | -------- | -| [`@typescript-eslint/adjacent-overload-signatures`](./docs/rules/adjacent-overload-signatures.md) | Require that member overloads be consecutive (`adjacent-overload-signatures` from TSLint) | :heavy_check_mark: | | -| [`@typescript-eslint/array-type`](./docs/rules/array-type.md) | Requires using either `T[]` or `Array` for arrays (`array-type` from TSLint) | :heavy_check_mark: | :wrench: | -| [`@typescript-eslint/ban-types`](./docs/rules/ban-types.md) | Enforces that types will not to be used (`ban-types` from TSLint) | :heavy_check_mark: | :wrench: | -| [`@typescript-eslint/camelcase`](./docs/rules/camelcase.md) | Enforce camelCase naming convention | :heavy_check_mark: | | -| [`@typescript-eslint/class-name-casing`](./docs/rules/class-name-casing.md) | Require PascalCased class and interface names (`class-name` from TSLint) | :heavy_check_mark: | | -| [`@typescript-eslint/explicit-function-return-type`](./docs/rules/explicit-function-return-type.md) | Require explicit return types on functions and class methods | :heavy_check_mark: | | -| [`@typescript-eslint/explicit-member-accessibility`](./docs/rules/explicit-member-accessibility.md) | Require explicit accessibility modifiers on class properties and methods (`member-access` from TSLint) | :heavy_check_mark: | | -| [`@typescript-eslint/generic-type-naming`](./docs/rules/generic-type-naming.md) | Enforces naming of generic type variables | | | -| [`@typescript-eslint/indent`](./docs/rules/indent.md) | Enforce consistent indentation (`indent` from TSLint) | :heavy_check_mark: | :wrench: | -| [`@typescript-eslint/interface-name-prefix`](./docs/rules/interface-name-prefix.md) | Require that interface names be prefixed with `I` (`interface-name` from TSLint) | :heavy_check_mark: | | -| [`@typescript-eslint/member-delimiter-style`](./docs/rules/member-delimiter-style.md) | Require a specific member delimiter style for interfaces and type literals | :heavy_check_mark: | :wrench: | -| [`@typescript-eslint/member-naming`](./docs/rules/member-naming.md) | Enforces naming conventions for class members by visibility. | | | -| [`@typescript-eslint/member-ordering`](./docs/rules/member-ordering.md) | Require a consistent member declaration order (`member-ordering` from TSLint) | | | -| [`@typescript-eslint/no-angle-bracket-type-assertion`](./docs/rules/no-angle-bracket-type-assertion.md) | Enforces the use of `as Type` assertions instead of `` assertions (`no-angle-bracket-type-assertion` from TSLint) | :heavy_check_mark: | | -| [`@typescript-eslint/no-array-constructor`](./docs/rules/no-array-constructor.md) | Disallow generic `Array` constructors | :heavy_check_mark: | :wrench: | -| [`@typescript-eslint/no-empty-interface`](./docs/rules/no-empty-interface.md) | Disallow the declaration of empty interfaces (`no-empty-interface` from TSLint) | :heavy_check_mark: | | -| [`@typescript-eslint/no-explicit-any`](./docs/rules/no-explicit-any.md) | Disallow usage of the `any` type (`no-any` from TSLint) | :heavy_check_mark: | | -| [`@typescript-eslint/no-extraneous-class`](./docs/rules/no-extraneous-class.md) | Forbids the use of classes as namespaces (`no-unnecessary-class` from TSLint) | | | -| [`@typescript-eslint/no-inferrable-types`](./docs/rules/no-inferrable-types.md) | Disallows explicit type declarations for variables or parameters initialized to a number, string, or boolean. (`no-inferrable-types` from TSLint) | :heavy_check_mark: | :wrench: | -| [`@typescript-eslint/no-misused-new`](./docs/rules/no-misused-new.md) | Enforce valid definition of `new` and `constructor`. (`no-misused-new` from TSLint) | :heavy_check_mark: | | -| [`@typescript-eslint/no-namespace`](./docs/rules/no-namespace.md) | Disallow the use of custom TypeScript modules and namespaces (`no-namespace` from TSLint) | :heavy_check_mark: | | -| [`@typescript-eslint/no-non-null-assertion`](./docs/rules/no-non-null-assertion.md) | Disallows non-null assertions using the `!` postfix operator (`no-non-null-assertion` from TSLint) | :heavy_check_mark: | | -| [`@typescript-eslint/no-object-literal-type-assertion`](./docs/rules/no-object-literal-type-assertion.md) | Forbids an object literal to appear in a type assertion expression (`no-object-literal-type-assertion` from TSLint) | :heavy_check_mark: | | -| [`@typescript-eslint/no-parameter-properties`](./docs/rules/no-parameter-properties.md) | Disallow the use of parameter properties in class constructors. (`no-parameter-properties` from TSLint) | :heavy_check_mark: | | -| [`@typescript-eslint/no-this-alias`](./docs/rules/no-this-alias.md) | Disallow aliasing `this` (`no-this-assignment` from TSLint) | | | -| [`@typescript-eslint/no-triple-slash-reference`](./docs/rules/no-triple-slash-reference.md) | Disallow `/// ` comments (`no-reference` from TSLint) | :heavy_check_mark: | | -| [`@typescript-eslint/no-type-alias`](./docs/rules/no-type-alias.md) | Disallow the use of type aliases (`interface-over-type-literal` from TSLint) | | | -| [`@typescript-eslint/no-unused-vars`](./docs/rules/no-unused-vars.md) | Disallow unused variables (`no-unused-variable` from TSLint) | :heavy_check_mark: | | -| [`@typescript-eslint/no-use-before-define`](./docs/rules/no-use-before-define.md) | Disallow the use of variables before they are defined | :heavy_check_mark: | | -| [`@typescript-eslint/no-var-requires`](./docs/rules/no-var-requires.md) | Disallows the use of require statements except in import statements (`no-var-requires` from TSLint) | :heavy_check_mark: | | -| [`@typescript-eslint/prefer-interface`](./docs/rules/prefer-interface.md) | Prefer an interface declaration over a type literal (type T = { ... }) (`interface-over-type-literal` from TSLint) | :heavy_check_mark: | :wrench: | -| [`@typescript-eslint/prefer-namespace-keyword`](./docs/rules/prefer-namespace-keyword.md) | Require the use of the `namespace` keyword instead of the `module` keyword to declare custom TypeScript modules. (`no-internal-module` from TSLint) | :heavy_check_mark: | :wrench: | -| [`@typescript-eslint/restrict-plus-operands`](./docs/rules/restrict-plus-operands.md) | When adding two variables, operands must both be of type number or of type string. (`restrict-plus-operands` from TSLint) | | | -| [`@typescript-eslint/type-annotation-spacing`](./docs/rules/type-annotation-spacing.md) | Require consistent spacing around type annotations (`typedef-whitespace` from TSLint) | :heavy_check_mark: | :wrench: | +| Name | Description | :heavy_check_mark: | :wrench: | +| --------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------ | -------- | +| [`@typescript-eslint/adjacent-overload-signatures`](./docs/rules/adjacent-overload-signatures.md) | Require that member overloads be consecutive (`adjacent-overload-signatures` from TSLint) | :heavy_check_mark: | | +| [`@typescript-eslint/array-type`](./docs/rules/array-type.md) | Requires using either `T[]` or `Array` for arrays (`array-type` from TSLint) | :heavy_check_mark: | :wrench: | +| [`@typescript-eslint/ban-types`](./docs/rules/ban-types.md) | Enforces that types will not to be used (`ban-types` from TSLint) | :heavy_check_mark: | :wrench: | +| [`@typescript-eslint/camelcase`](./docs/rules/camelcase.md) | Enforce camelCase naming convention | :heavy_check_mark: | | +| [`@typescript-eslint/class-name-casing`](./docs/rules/class-name-casing.md) | Require PascalCased class and interface names (`class-name` from TSLint) | :heavy_check_mark: | | +| [`@typescript-eslint/explicit-function-return-type`](./docs/rules/explicit-function-return-type.md) | Require explicit return types on functions and class methods | :heavy_check_mark: | | +| [`@typescript-eslint/explicit-member-accessibility`](./docs/rules/explicit-member-accessibility.md) | Require explicit accessibility modifiers on class properties and methods (`member-access` from TSLint) | :heavy_check_mark: | | +| [`@typescript-eslint/generic-type-naming`](./docs/rules/generic-type-naming.md) | Enforces naming of generic type variables | | | +| [`@typescript-eslint/indent`](./docs/rules/indent.md) | Enforce consistent indentation (`indent` from TSLint) | :heavy_check_mark: | :wrench: | +| [`@typescript-eslint/interface-name-prefix`](./docs/rules/interface-name-prefix.md) | Require that interface names be prefixed with `I` (`interface-name` from TSLint) | :heavy_check_mark: | | +| [`@typescript-eslint/member-delimiter-style`](./docs/rules/member-delimiter-style.md) | Require a specific member delimiter style for interfaces and type literals | :heavy_check_mark: | :wrench: | +| [`@typescript-eslint/member-naming`](./docs/rules/member-naming.md) | Enforces naming conventions for class members by visibility. | | | +| [`@typescript-eslint/member-ordering`](./docs/rules/member-ordering.md) | Require a consistent member declaration order (`member-ordering` from TSLint) | | | +| [`@typescript-eslint/no-angle-bracket-type-assertion`](./docs/rules/no-angle-bracket-type-assertion.md) | Enforces the use of `as Type` assertions instead of `` assertions (`no-angle-bracket-type-assertion` from TSLint) | :heavy_check_mark: | | +| [`@typescript-eslint/no-array-constructor`](./docs/rules/no-array-constructor.md) | Disallow generic `Array` constructors | :heavy_check_mark: | :wrench: | +| [`@typescript-eslint/no-empty-interface`](./docs/rules/no-empty-interface.md) | Disallow the declaration of empty interfaces (`no-empty-interface` from TSLint) | :heavy_check_mark: | | +| [`@typescript-eslint/no-explicit-any`](./docs/rules/no-explicit-any.md) | Disallow usage of the `any` type (`no-any` from TSLint) | :heavy_check_mark: | | +| [`@typescript-eslint/no-extraneous-class`](./docs/rules/no-extraneous-class.md) | Forbids the use of classes as namespaces (`no-unnecessary-class` from TSLint) | | | +| [`@typescript-eslint/no-inferrable-types`](./docs/rules/no-inferrable-types.md) | Disallows explicit type declarations for variables or parameters initialized to a number, string, or boolean. (`no-inferrable-types` from TSLint) | :heavy_check_mark: | :wrench: | +| [`@typescript-eslint/no-misused-new`](./docs/rules/no-misused-new.md) | Enforce valid definition of `new` and `constructor`. (`no-misused-new` from TSLint) | :heavy_check_mark: | | +| [`@typescript-eslint/no-namespace`](./docs/rules/no-namespace.md) | Disallow the use of custom TypeScript modules and namespaces (`no-namespace` from TSLint) | :heavy_check_mark: | | +| [`@typescript-eslint/no-non-null-assertion`](./docs/rules/no-non-null-assertion.md) | Disallows non-null assertions using the `!` postfix operator (`no-non-null-assertion` from TSLint) | :heavy_check_mark: | | +| [`@typescript-eslint/no-object-literal-type-assertion`](./docs/rules/no-object-literal-type-assertion.md) | Forbids an object literal to appear in a type assertion expression (`no-object-literal-type-assertion` from TSLint) | :heavy_check_mark: | | +| [`@typescript-eslint/no-parameter-properties`](./docs/rules/no-parameter-properties.md) | Disallow the use of parameter properties in class constructors. (`no-parameter-properties` from TSLint) | :heavy_check_mark: | | +| [`@typescript-eslint/no-this-alias`](./docs/rules/no-this-alias.md) | Disallow aliasing `this` (`no-this-assignment` from TSLint) | | | +| [`@typescript-eslint/no-triple-slash-reference`](./docs/rules/no-triple-slash-reference.md) | Disallow `/// ` comments (`no-reference` from TSLint) | :heavy_check_mark: | | +| [`@typescript-eslint/no-type-alias`](./docs/rules/no-type-alias.md) | Disallow the use of type aliases (`interface-over-type-literal` from TSLint) | | | +| [`@typescript-eslint/no-unused-vars`](./docs/rules/no-unused-vars.md) | Disallow unused variables (`no-unused-variable` from TSLint) | :heavy_check_mark: | | +| [`@typescript-eslint/no-use-before-define`](./docs/rules/no-use-before-define.md) | Disallow the use of variables before they are defined | :heavy_check_mark: | | +| [`@typescript-eslint/no-var-requires`](./docs/rules/no-var-requires.md) | Disallows the use of require statements except in import statements (`no-var-requires` from TSLint) | :heavy_check_mark: | | +| [`@typescript-eslint/prefer-interface`](./docs/rules/prefer-interface.md) | Prefer an interface declaration over a type literal (type T = { ... }) (`interface-over-type-literal` from TSLint) | :heavy_check_mark: | :wrench: | +| [`@typescript-eslint/prefer-namespace-keyword`](./docs/rules/prefer-namespace-keyword.md) | Require the use of the `namespace` keyword instead of the `module` keyword to declare custom TypeScript modules. (`no-internal-module` from TSLint) | :heavy_check_mark: | :wrench: | +| [`@typescript-eslint/restrict-plus-operands`](./docs/rules/restrict-plus-operands.md) | When adding two variables, operands must both be of type number or of type string. (`restrict-plus-operands` from TSLint) | | | +| [`@typescript-eslint/type-annotation-spacing`](./docs/rules/type-annotation-spacing.md) | Require consistent spacing around type annotations (`typedef-whitespace` from TSLint) | :heavy_check_mark: | :wrench: | diff --git a/packages/eslint-plugin/lib/util.js b/packages/eslint-plugin/lib/util.js index 1df02bfb9e8e..e12e15f80413 100644 --- a/packages/eslint-plugin/lib/util.js +++ b/packages/eslint-plugin/lib/util.js @@ -117,8 +117,12 @@ exports.getParserServices = context => { !context.parserServices.program || !context.parserServices.esTreeNodeToTSNodeMap ) { + /** + * The user needs to have configured "project" in their parserOptions + * for @typescript-eslint/parser + */ throw new Error( - 'This rule requires you to use `@typescript-eslint/parser`.' + `You have used a rule which requires parserServices to be generated. You must therefore provide a value for the "parserOptions.project" property for @typescript-eslint/parser.` ); } return context.parserServices; diff --git a/packages/eslint-plugin/tests/lib/rules/restrict-plus-operands.js b/packages/eslint-plugin/tests/lib/rules/restrict-plus-operands.js index a13b7cea3e47..d5a07e596982 100644 --- a/packages/eslint-plugin/tests/lib/rules/restrict-plus-operands.js +++ b/packages/eslint-plugin/tests/lib/rules/restrict-plus-operands.js @@ -22,7 +22,6 @@ const rootPath = path.join(process.cwd(), 'tests/fixtures/'); const ruleTester = new RuleTester({ parser: '@typescript-eslint/parser', parserOptions: { - generateServices: true, tsconfigRootDir: rootPath, project: './tsconfig.json' } diff --git a/packages/parser/README.md b/packages/parser/README.md index f348ae4617dc..d0a6879b4e57 100644 --- a/packages/parser/README.md +++ b/packages/parser/README.md @@ -48,6 +48,12 @@ The following additional configuration options are available by specifying them - **`useJSXTextNode`** - default `true`. Please set `false` if you use this parser on ESLint v4. If this is `false`, the parser creates the AST of JSX texts as the legacy style. +- **`project`** - default `undefined`. This option allows you to provide a path to your project's `tsconfig.json`. **This setting is required if you want to use rules which require type information**. You may want to use this setting in tandem with the `tsconfigRootDir` option below. + +- **`tsconfigRootDir`** - default `undefined`. This option allows you to provide the root directory for relative tsconfig paths specified in the `project` option above. + +- **`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 + ### .eslintrc.json ```json @@ -57,7 +63,10 @@ The following additional configuration options are available by specifying them "ecmaFeatures": { "jsx": true }, - "useJSXTextNode": true + "useJSXTextNode": true, + "project": "./tsconfig.json", + "tsconfigRootDir": "../../", + "extraFileExtensions": [".vue"] } } ``` From d8243b41893b0423bb0b29c99e076e1c4162a7a5 Mon Sep 17 00:00:00 2001 From: Armano Date: Thu, 24 Jan 2019 14:03:11 +0100 Subject: [PATCH 04/13] fix(ts-estree): include modifiers in exported node range (#133) --- .../lib/__snapshots__/javascript.ts.snap | 1006 ++++++++++++++++- .../lib/__snapshots__/typescript.ts.snap | 28 +- .../export-async-named-function.src.js | 1 + .../javascript/modules/export-const.src.js | 1 + ...export-default-async-named-function.src.js | 1 + .../javascript/modules/export-let.src.js | 1 + packages/typescript-estree/src/node-utils.ts | 14 +- .../tests/ast-alignment/fixtures-to-test.ts | 9 +- .../lib/__snapshots__/javascript.ts.snap | 1002 +++++++++++++++- .../semantic-diagnostics-enabled.ts.snap | 8 + .../lib/__snapshots__/typescript.ts.snap | 28 +- 11 files changed, 2019 insertions(+), 80 deletions(-) create mode 100644 packages/shared-fixtures/fixtures/javascript/modules/export-async-named-function.src.js create mode 100644 packages/shared-fixtures/fixtures/javascript/modules/export-const.src.js create mode 100644 packages/shared-fixtures/fixtures/javascript/modules/export-default-async-named-function.src.js create mode 100644 packages/shared-fixtures/fixtures/javascript/modules/export-let.src.js diff --git a/packages/parser/tests/lib/__snapshots__/javascript.ts.snap b/packages/parser/tests/lib/__snapshots__/javascript.ts.snap index b31c5e710a2b..3dc1ea581abe 100644 --- a/packages/parser/tests/lib/__snapshots__/javascript.ts.snap +++ b/packages/parser/tests/lib/__snapshots__/javascript.ts.snap @@ -105637,15 +105637,677 @@ Object { } `; +exports[`javascript fixtures/modules/export-async-named-function.src 1`] = ` +Object { + "body": Array [ + Object { + "declaration": Object { + "async": true, + "body": Object { + "body": Array [], + "loc": Object { + "end": Object { + "column": 30, + "line": 1, + }, + "start": Object { + "column": 28, + "line": 1, + }, + }, + "range": Array [ + 28, + 30, + ], + "type": "BlockStatement", + }, + "expression": false, + "generator": false, + "id": Object { + "loc": Object { + "end": Object { + "column": 25, + "line": 1, + }, + "start": Object { + "column": 22, + "line": 1, + }, + }, + "name": "foo", + "range": Array [ + 22, + 25, + ], + "type": "Identifier", + }, + "loc": Object { + "end": Object { + "column": 30, + "line": 1, + }, + "start": Object { + "column": 7, + "line": 1, + }, + }, + "params": Array [], + "range": Array [ + 7, + 30, + ], + "type": "FunctionDeclaration", + }, + "loc": Object { + "end": Object { + "column": 30, + "line": 1, + }, + "start": Object { + "column": 0, + "line": 1, + }, + }, + "range": Array [ + 0, + 30, + ], + "source": null, + "specifiers": Array [], + "type": "ExportNamedDeclaration", + }, + ], + "comments": Array [], + "loc": Object { + "end": Object { + "column": 0, + "line": 2, + }, + "start": Object { + "column": 0, + "line": 1, + }, + }, + "range": Array [ + 0, + 31, + ], + "sourceType": "module", + "tokens": Array [ + Object { + "loc": Object { + "end": Object { + "column": 6, + "line": 1, + }, + "start": Object { + "column": 0, + "line": 1, + }, + }, + "range": Array [ + 0, + 6, + ], + "type": "Keyword", + "value": "export", + }, + Object { + "loc": Object { + "end": Object { + "column": 12, + "line": 1, + }, + "start": Object { + "column": 7, + "line": 1, + }, + }, + "range": Array [ + 7, + 12, + ], + "type": "Identifier", + "value": "async", + }, + Object { + "loc": Object { + "end": Object { + "column": 21, + "line": 1, + }, + "start": Object { + "column": 13, + "line": 1, + }, + }, + "range": Array [ + 13, + 21, + ], + "type": "Keyword", + "value": "function", + }, + Object { + "loc": Object { + "end": Object { + "column": 25, + "line": 1, + }, + "start": Object { + "column": 22, + "line": 1, + }, + }, + "range": Array [ + 22, + 25, + ], + "type": "Identifier", + "value": "foo", + }, + Object { + "loc": Object { + "end": Object { + "column": 26, + "line": 1, + }, + "start": Object { + "column": 25, + "line": 1, + }, + }, + "range": Array [ + 25, + 26, + ], + "type": "Punctuator", + "value": "(", + }, + Object { + "loc": Object { + "end": Object { + "column": 27, + "line": 1, + }, + "start": Object { + "column": 26, + "line": 1, + }, + }, + "range": Array [ + 26, + 27, + ], + "type": "Punctuator", + "value": ")", + }, + Object { + "loc": Object { + "end": Object { + "column": 29, + "line": 1, + }, + "start": Object { + "column": 28, + "line": 1, + }, + }, + "range": Array [ + 28, + 29, + ], + "type": "Punctuator", + "value": "{", + }, + Object { + "loc": Object { + "end": Object { + "column": 30, + "line": 1, + }, + "start": Object { + "column": 29, + "line": 1, + }, + }, + "range": Array [ + 29, + 30, + ], + "type": "Punctuator", + "value": "}", + }, + ], + "type": "Program", +} +`; + +exports[`javascript fixtures/modules/export-const.src 1`] = ` +Object { + "body": Array [ + Object { + "declaration": Object { + "declarations": Array [ + Object { + "id": Object { + "loc": Object { + "end": Object { + "column": 16, + "line": 1, + }, + "start": Object { + "column": 13, + "line": 1, + }, + }, + "name": "foo", + "range": Array [ + 13, + 16, + ], + "type": "Identifier", + }, + "init": Object { + "loc": Object { + "end": Object { + "column": 20, + "line": 1, + }, + "start": Object { + "column": 19, + "line": 1, + }, + }, + "range": Array [ + 19, + 20, + ], + "raw": "2", + "type": "Literal", + "value": 2, + }, + "loc": Object { + "end": Object { + "column": 20, + "line": 1, + }, + "start": Object { + "column": 13, + "line": 1, + }, + }, + "range": Array [ + 13, + 20, + ], + "type": "VariableDeclarator", + }, + ], + "kind": "const", + "loc": Object { + "end": Object { + "column": 21, + "line": 1, + }, + "start": Object { + "column": 7, + "line": 1, + }, + }, + "range": Array [ + 7, + 21, + ], + "type": "VariableDeclaration", + }, + "loc": Object { + "end": Object { + "column": 21, + "line": 1, + }, + "start": Object { + "column": 0, + "line": 1, + }, + }, + "range": Array [ + 0, + 21, + ], + "source": null, + "specifiers": Array [], + "type": "ExportNamedDeclaration", + }, + ], + "comments": Array [], + "loc": Object { + "end": Object { + "column": 0, + "line": 2, + }, + "start": Object { + "column": 0, + "line": 1, + }, + }, + "range": Array [ + 0, + 22, + ], + "sourceType": "module", + "tokens": Array [ + Object { + "loc": Object { + "end": Object { + "column": 6, + "line": 1, + }, + "start": Object { + "column": 0, + "line": 1, + }, + }, + "range": Array [ + 0, + 6, + ], + "type": "Keyword", + "value": "export", + }, + Object { + "loc": Object { + "end": Object { + "column": 12, + "line": 1, + }, + "start": Object { + "column": 7, + "line": 1, + }, + }, + "range": Array [ + 7, + 12, + ], + "type": "Keyword", + "value": "const", + }, + Object { + "loc": Object { + "end": Object { + "column": 16, + "line": 1, + }, + "start": Object { + "column": 13, + "line": 1, + }, + }, + "range": Array [ + 13, + 16, + ], + "type": "Identifier", + "value": "foo", + }, + Object { + "loc": Object { + "end": Object { + "column": 18, + "line": 1, + }, + "start": Object { + "column": 17, + "line": 1, + }, + }, + "range": Array [ + 17, + 18, + ], + "type": "Punctuator", + "value": "=", + }, + Object { + "loc": Object { + "end": Object { + "column": 20, + "line": 1, + }, + "start": Object { + "column": 19, + "line": 1, + }, + }, + "range": Array [ + 19, + 20, + ], + "type": "Numeric", + "value": "2", + }, + Object { + "loc": Object { + "end": Object { + "column": 21, + "line": 1, + }, + "start": Object { + "column": 20, + "line": 1, + }, + }, + "range": Array [ + 20, + 21, + ], + "type": "Punctuator", + "value": ";", + }, + ], + "type": "Program", +} +`; + exports[`javascript fixtures/modules/export-default-array.src 1`] = ` Object { "body": Array [ Object { "declaration": Object { - "elements": Array [], + "elements": Array [], + "loc": Object { + "end": Object { + "column": 17, + "line": 1, + }, + "start": Object { + "column": 15, + "line": 1, + }, + }, + "range": Array [ + 15, + 17, + ], + "type": "ArrayExpression", + }, + "loc": Object { + "end": Object { + "column": 18, + "line": 1, + }, + "start": Object { + "column": 0, + "line": 1, + }, + }, + "range": Array [ + 0, + 18, + ], + "type": "ExportDefaultDeclaration", + }, + ], + "comments": Array [], + "loc": Object { + "end": Object { + "column": 0, + "line": 2, + }, + "start": Object { + "column": 0, + "line": 1, + }, + }, + "range": Array [ + 0, + 19, + ], + "sourceType": "module", + "tokens": Array [ + Object { + "loc": Object { + "end": Object { + "column": 6, + "line": 1, + }, + "start": Object { + "column": 0, + "line": 1, + }, + }, + "range": Array [ + 0, + 6, + ], + "type": "Keyword", + "value": "export", + }, + Object { + "loc": Object { + "end": Object { + "column": 14, + "line": 1, + }, + "start": Object { + "column": 7, + "line": 1, + }, + }, + "range": Array [ + 7, + 14, + ], + "type": "Keyword", + "value": "default", + }, + Object { + "loc": Object { + "end": Object { + "column": 16, + "line": 1, + }, + "start": Object { + "column": 15, + "line": 1, + }, + }, + "range": Array [ + 15, + 16, + ], + "type": "Punctuator", + "value": "[", + }, + Object { + "loc": Object { + "end": Object { + "column": 17, + "line": 1, + }, + "start": Object { + "column": 16, + "line": 1, + }, + }, + "range": Array [ + 16, + 17, + ], + "type": "Punctuator", + "value": "]", + }, + Object { + "loc": Object { + "end": Object { + "column": 18, + "line": 1, + }, + "start": Object { + "column": 17, + "line": 1, + }, + }, + "range": Array [ + 17, + 18, + ], + "type": "Punctuator", + "value": ";", + }, + ], + "type": "Program", +} +`; + +exports[`javascript fixtures/modules/export-default-async-named-function.src 1`] = ` +Object { + "body": Array [ + Object { + "declaration": Object { + "async": true, + "body": Object { + "body": Array [], + "loc": Object { + "end": Object { + "column": 38, + "line": 1, + }, + "start": Object { + "column": 36, + "line": 1, + }, + }, + "range": Array [ + 36, + 38, + ], + "type": "BlockStatement", + }, + "expression": false, + "generator": false, + "id": Object { + "loc": Object { + "end": Object { + "column": 33, + "line": 1, + }, + "start": Object { + "column": 30, + "line": 1, + }, + }, + "name": "foo", + "range": Array [ + 30, + 33, + ], + "type": "Identifier", + }, "loc": Object { "end": Object { - "column": 17, + "column": 38, "line": 1, }, "start": Object { @@ -105653,15 +106315,16 @@ Object { "line": 1, }, }, + "params": Array [], "range": Array [ 15, - 17, + 38, ], - "type": "ArrayExpression", + "type": "FunctionDeclaration", }, "loc": Object { "end": Object { - "column": 18, + "column": 38, "line": 1, }, "start": Object { @@ -105671,7 +106334,7 @@ Object { }, "range": Array [ 0, - 18, + 38, ], "type": "ExportDefaultDeclaration", }, @@ -105689,7 +106352,7 @@ Object { }, "range": Array [ 0, - 19, + 39, ], "sourceType": "module", "tokens": Array [ @@ -105732,56 +106395,128 @@ Object { Object { "loc": Object { "end": Object { - "column": 16, + "column": 20, + "line": 1, + }, + "start": Object { + "column": 15, + "line": 1, + }, + }, + "range": Array [ + 15, + 20, + ], + "type": "Identifier", + "value": "async", + }, + Object { + "loc": Object { + "end": Object { + "column": 29, + "line": 1, + }, + "start": Object { + "column": 21, + "line": 1, + }, + }, + "range": Array [ + 21, + 29, + ], + "type": "Keyword", + "value": "function", + }, + Object { + "loc": Object { + "end": Object { + "column": 33, + "line": 1, + }, + "start": Object { + "column": 30, + "line": 1, + }, + }, + "range": Array [ + 30, + 33, + ], + "type": "Identifier", + "value": "foo", + }, + Object { + "loc": Object { + "end": Object { + "column": 34, + "line": 1, + }, + "start": Object { + "column": 33, + "line": 1, + }, + }, + "range": Array [ + 33, + 34, + ], + "type": "Punctuator", + "value": "(", + }, + Object { + "loc": Object { + "end": Object { + "column": 35, "line": 1, }, "start": Object { - "column": 15, + "column": 34, "line": 1, }, }, "range": Array [ - 15, - 16, + 34, + 35, ], "type": "Punctuator", - "value": "[", + "value": ")", }, Object { "loc": Object { "end": Object { - "column": 17, + "column": 37, "line": 1, }, "start": Object { - "column": 16, + "column": 36, "line": 1, }, }, "range": Array [ - 16, - 17, + 36, + 37, ], "type": "Punctuator", - "value": "]", + "value": "{", }, Object { "loc": Object { "end": Object { - "column": 18, + "column": 38, "line": 1, }, "start": Object { - "column": 17, + "column": 37, "line": 1, }, }, "range": Array [ - 17, - 18, + 37, + 38, ], "type": "Punctuator", - "value": ";", + "value": "}", }, ], "type": "Program", @@ -109520,6 +110255,233 @@ Object { } `; +exports[`javascript fixtures/modules/export-let.src 1`] = ` +Object { + "body": Array [ + Object { + "declaration": Object { + "declarations": Array [ + Object { + "id": Object { + "loc": Object { + "end": Object { + "column": 14, + "line": 1, + }, + "start": Object { + "column": 11, + "line": 1, + }, + }, + "name": "foo", + "range": Array [ + 11, + 14, + ], + "type": "Identifier", + }, + "init": Object { + "loc": Object { + "end": Object { + "column": 18, + "line": 1, + }, + "start": Object { + "column": 17, + "line": 1, + }, + }, + "range": Array [ + 17, + 18, + ], + "raw": "2", + "type": "Literal", + "value": 2, + }, + "loc": Object { + "end": Object { + "column": 18, + "line": 1, + }, + "start": Object { + "column": 11, + "line": 1, + }, + }, + "range": Array [ + 11, + 18, + ], + "type": "VariableDeclarator", + }, + ], + "kind": "let", + "loc": Object { + "end": Object { + "column": 19, + "line": 1, + }, + "start": Object { + "column": 7, + "line": 1, + }, + }, + "range": Array [ + 7, + 19, + ], + "type": "VariableDeclaration", + }, + "loc": Object { + "end": Object { + "column": 19, + "line": 1, + }, + "start": Object { + "column": 0, + "line": 1, + }, + }, + "range": Array [ + 0, + 19, + ], + "source": null, + "specifiers": Array [], + "type": "ExportNamedDeclaration", + }, + ], + "comments": Array [], + "loc": Object { + "end": Object { + "column": 0, + "line": 2, + }, + "start": Object { + "column": 0, + "line": 1, + }, + }, + "range": Array [ + 0, + 20, + ], + "sourceType": "module", + "tokens": Array [ + Object { + "loc": Object { + "end": Object { + "column": 6, + "line": 1, + }, + "start": Object { + "column": 0, + "line": 1, + }, + }, + "range": Array [ + 0, + 6, + ], + "type": "Keyword", + "value": "export", + }, + Object { + "loc": Object { + "end": Object { + "column": 10, + "line": 1, + }, + "start": Object { + "column": 7, + "line": 1, + }, + }, + "range": Array [ + 7, + 10, + ], + "type": "Keyword", + "value": "let", + }, + Object { + "loc": Object { + "end": Object { + "column": 14, + "line": 1, + }, + "start": Object { + "column": 11, + "line": 1, + }, + }, + "range": Array [ + 11, + 14, + ], + "type": "Identifier", + "value": "foo", + }, + Object { + "loc": Object { + "end": Object { + "column": 16, + "line": 1, + }, + "start": Object { + "column": 15, + "line": 1, + }, + }, + "range": Array [ + 15, + 16, + ], + "type": "Punctuator", + "value": "=", + }, + Object { + "loc": Object { + "end": Object { + "column": 18, + "line": 1, + }, + "start": Object { + "column": 17, + "line": 1, + }, + }, + "range": Array [ + 17, + 18, + ], + "type": "Numeric", + "value": "2", + }, + Object { + "loc": Object { + "end": Object { + "column": 19, + "line": 1, + }, + "start": Object { + "column": 18, + "line": 1, + }, + }, + "range": Array [ + 18, + 19, + ], + "type": "Punctuator", + "value": ";", + }, + ], + "type": "Program", +} +`; + exports[`javascript fixtures/modules/export-named-as-default.src 1`] = ` Object { "body": Array [ diff --git a/packages/parser/tests/lib/__snapshots__/typescript.ts.snap b/packages/parser/tests/lib/__snapshots__/typescript.ts.snap index 39c74ab7586d..e2dfa3efa430 100644 --- a/packages/parser/tests/lib/__snapshots__/typescript.ts.snap +++ b/packages/parser/tests/lib/__snapshots__/typescript.ts.snap @@ -814,12 +814,12 @@ Object { "line": 3, }, "start": Object { - "column": 16, + "column": 7, "line": 1, }, }, "range": Array [ - 16, + 7, 68, ], "superClass": null, @@ -1262,12 +1262,12 @@ Object { "line": 3, }, "start": Object { - "column": 16, + "column": 7, "line": 1, }, }, "range": Array [ - 16, + 7, 86, ], "superClass": null, @@ -2567,12 +2567,12 @@ Object { "line": 3, }, "start": Object { - "column": 16, + "column": 7, "line": 1, }, }, "range": Array [ - 16, + 7, 78, ], "superClass": null, @@ -2955,12 +2955,12 @@ Object { "line": 2, }, "start": Object { - "column": 16, + "column": 7, "line": 1, }, }, "range": Array [ - 16, + 7, 31, ], "type": "TSInterfaceDeclaration", @@ -35463,7 +35463,7 @@ Object { "line": 4, }, "start": Object { - "column": 21, + "column": 7, "line": 1, }, }, @@ -35559,7 +35559,7 @@ Object { }, ], "range": Array [ - 21, + 7, 54, ], "type": "TSEnumDeclaration", @@ -35851,7 +35851,7 @@ Object { "line": 4, }, "start": Object { - "column": 15, + "column": 7, "line": 1, }, }, @@ -35947,7 +35947,7 @@ Object { }, ], "range": Array [ - 15, + 7, 48, ], "type": "TSEnumDeclaration", @@ -89438,7 +89438,7 @@ Object { "line": 1, }, "start": Object { - "column": 63, + "column": 7, "line": 1, }, }, @@ -89565,7 +89565,7 @@ Object { }, ], "range": Array [ - 63, + 7, 72, ], "type": "TSEnumDeclaration", diff --git a/packages/shared-fixtures/fixtures/javascript/modules/export-async-named-function.src.js b/packages/shared-fixtures/fixtures/javascript/modules/export-async-named-function.src.js new file mode 100644 index 000000000000..7c26b9ed6873 --- /dev/null +++ b/packages/shared-fixtures/fixtures/javascript/modules/export-async-named-function.src.js @@ -0,0 +1 @@ +export async function foo() {} diff --git a/packages/shared-fixtures/fixtures/javascript/modules/export-const.src.js b/packages/shared-fixtures/fixtures/javascript/modules/export-const.src.js new file mode 100644 index 000000000000..cc57a55e257d --- /dev/null +++ b/packages/shared-fixtures/fixtures/javascript/modules/export-const.src.js @@ -0,0 +1 @@ +export const foo = 2; diff --git a/packages/shared-fixtures/fixtures/javascript/modules/export-default-async-named-function.src.js b/packages/shared-fixtures/fixtures/javascript/modules/export-default-async-named-function.src.js new file mode 100644 index 000000000000..c40a5f27d267 --- /dev/null +++ b/packages/shared-fixtures/fixtures/javascript/modules/export-default-async-named-function.src.js @@ -0,0 +1 @@ +export default async function foo() {} diff --git a/packages/shared-fixtures/fixtures/javascript/modules/export-let.src.js b/packages/shared-fixtures/fixtures/javascript/modules/export-let.src.js new file mode 100644 index 000000000000..a3bcdb0d8122 --- /dev/null +++ b/packages/shared-fixtures/fixtures/javascript/modules/export-let.src.js @@ -0,0 +1 @@ +export let foo = 2; diff --git a/packages/typescript-estree/src/node-utils.ts b/packages/typescript-estree/src/node-utils.ts index 240c4d1c9f71..c844cf7ed20d 100644 --- a/packages/typescript-estree/src/node-utils.ts +++ b/packages/typescript-estree/src/node-utils.ts @@ -485,12 +485,14 @@ export function fixExports( ): ESTreeNode { // check for exports if (node.modifiers && node.modifiers[0].kind === SyntaxKind.ExportKeyword) { - const exportKeyword = node.modifiers[0], - nextModifier = node.modifiers[1], - lastModifier = node.modifiers[node.modifiers.length - 1], - declarationIsDefault = - nextModifier && nextModifier.kind === SyntaxKind.DefaultKeyword, - varToken = findNextToken(lastModifier, ast, ast); + const exportKeyword = node.modifiers[0]; + const nextModifier = node.modifiers[1]; + const declarationIsDefault = + nextModifier && nextModifier.kind === SyntaxKind.DefaultKeyword; + + const varToken = declarationIsDefault + ? findNextToken(nextModifier, ast, ast) + : findNextToken(exportKeyword, ast, ast); result.range[0] = varToken!.getStart(ast); result.loc = getLocFor(result.range[0], result.range[1], ast); diff --git a/packages/typescript-estree/tests/ast-alignment/fixtures-to-test.ts b/packages/typescript-estree/tests/ast-alignment/fixtures-to-test.ts index 3b1a21e43d80..522cc53a3351 100644 --- a/packages/typescript-estree/tests/ast-alignment/fixtures-to-test.ts +++ b/packages/typescript-estree/tests/ast-alignment/fixtures-to-test.ts @@ -326,7 +326,6 @@ tester.addFixturePatternConfig('typescript/basics', { /** * there is difference in range between babel and ts-estree */ - 'export-declare-const-named-enum', 'interface-with-optional-properties', /** * Babel parses it as TSQualifiedName @@ -358,7 +357,13 @@ tester.addFixturePatternConfig('typescript/basics', { * Babel parses this incorrectly * https://github.com/babel/babel/issues/9324 */ - 'type-assertion-arrow-function' + 'type-assertion-arrow-function', + /** + * Babel does not include range of declare keyword into enum range + * https://github.com/babel/babel/issues/9399 + */ + 'export-declare-const-named-enum', + 'export-declare-named-enum' ], ignoreSourceType: [ /** diff --git a/packages/typescript-estree/tests/lib/__snapshots__/javascript.ts.snap b/packages/typescript-estree/tests/lib/__snapshots__/javascript.ts.snap index 8d02532b8d7f..5a57277c9353 100644 --- a/packages/typescript-estree/tests/lib/__snapshots__/javascript.ts.snap +++ b/packages/typescript-estree/tests/lib/__snapshots__/javascript.ts.snap @@ -105312,15 +105312,674 @@ Object { } `; +exports[`javascript fixtures/modules/export-async-named-function.src 1`] = ` +Object { + "body": Array [ + Object { + "declaration": Object { + "async": true, + "body": Object { + "body": Array [], + "loc": Object { + "end": Object { + "column": 30, + "line": 1, + }, + "start": Object { + "column": 28, + "line": 1, + }, + }, + "range": Array [ + 28, + 30, + ], + "type": "BlockStatement", + }, + "expression": false, + "generator": false, + "id": Object { + "loc": Object { + "end": Object { + "column": 25, + "line": 1, + }, + "start": Object { + "column": 22, + "line": 1, + }, + }, + "name": "foo", + "range": Array [ + 22, + 25, + ], + "type": "Identifier", + }, + "loc": Object { + "end": Object { + "column": 30, + "line": 1, + }, + "start": Object { + "column": 7, + "line": 1, + }, + }, + "params": Array [], + "range": Array [ + 7, + 30, + ], + "type": "FunctionDeclaration", + }, + "loc": Object { + "end": Object { + "column": 30, + "line": 1, + }, + "start": Object { + "column": 0, + "line": 1, + }, + }, + "range": Array [ + 0, + 30, + ], + "source": null, + "specifiers": Array [], + "type": "ExportNamedDeclaration", + }, + ], + "loc": Object { + "end": Object { + "column": 0, + "line": 2, + }, + "start": Object { + "column": 0, + "line": 1, + }, + }, + "range": Array [ + 0, + 31, + ], + "sourceType": "module", + "tokens": Array [ + Object { + "loc": Object { + "end": Object { + "column": 6, + "line": 1, + }, + "start": Object { + "column": 0, + "line": 1, + }, + }, + "range": Array [ + 0, + 6, + ], + "type": "Keyword", + "value": "export", + }, + Object { + "loc": Object { + "end": Object { + "column": 12, + "line": 1, + }, + "start": Object { + "column": 7, + "line": 1, + }, + }, + "range": Array [ + 7, + 12, + ], + "type": "Identifier", + "value": "async", + }, + Object { + "loc": Object { + "end": Object { + "column": 21, + "line": 1, + }, + "start": Object { + "column": 13, + "line": 1, + }, + }, + "range": Array [ + 13, + 21, + ], + "type": "Keyword", + "value": "function", + }, + Object { + "loc": Object { + "end": Object { + "column": 25, + "line": 1, + }, + "start": Object { + "column": 22, + "line": 1, + }, + }, + "range": Array [ + 22, + 25, + ], + "type": "Identifier", + "value": "foo", + }, + Object { + "loc": Object { + "end": Object { + "column": 26, + "line": 1, + }, + "start": Object { + "column": 25, + "line": 1, + }, + }, + "range": Array [ + 25, + 26, + ], + "type": "Punctuator", + "value": "(", + }, + Object { + "loc": Object { + "end": Object { + "column": 27, + "line": 1, + }, + "start": Object { + "column": 26, + "line": 1, + }, + }, + "range": Array [ + 26, + 27, + ], + "type": "Punctuator", + "value": ")", + }, + Object { + "loc": Object { + "end": Object { + "column": 29, + "line": 1, + }, + "start": Object { + "column": 28, + "line": 1, + }, + }, + "range": Array [ + 28, + 29, + ], + "type": "Punctuator", + "value": "{", + }, + Object { + "loc": Object { + "end": Object { + "column": 30, + "line": 1, + }, + "start": Object { + "column": 29, + "line": 1, + }, + }, + "range": Array [ + 29, + 30, + ], + "type": "Punctuator", + "value": "}", + }, + ], + "type": "Program", +} +`; + +exports[`javascript fixtures/modules/export-const.src 1`] = ` +Object { + "body": Array [ + Object { + "declaration": Object { + "declarations": Array [ + Object { + "id": Object { + "loc": Object { + "end": Object { + "column": 16, + "line": 1, + }, + "start": Object { + "column": 13, + "line": 1, + }, + }, + "name": "foo", + "range": Array [ + 13, + 16, + ], + "type": "Identifier", + }, + "init": Object { + "loc": Object { + "end": Object { + "column": 20, + "line": 1, + }, + "start": Object { + "column": 19, + "line": 1, + }, + }, + "range": Array [ + 19, + 20, + ], + "raw": "2", + "type": "Literal", + "value": 2, + }, + "loc": Object { + "end": Object { + "column": 20, + "line": 1, + }, + "start": Object { + "column": 13, + "line": 1, + }, + }, + "range": Array [ + 13, + 20, + ], + "type": "VariableDeclarator", + }, + ], + "kind": "const", + "loc": Object { + "end": Object { + "column": 21, + "line": 1, + }, + "start": Object { + "column": 7, + "line": 1, + }, + }, + "range": Array [ + 7, + 21, + ], + "type": "VariableDeclaration", + }, + "loc": Object { + "end": Object { + "column": 21, + "line": 1, + }, + "start": Object { + "column": 0, + "line": 1, + }, + }, + "range": Array [ + 0, + 21, + ], + "source": null, + "specifiers": Array [], + "type": "ExportNamedDeclaration", + }, + ], + "loc": Object { + "end": Object { + "column": 0, + "line": 2, + }, + "start": Object { + "column": 0, + "line": 1, + }, + }, + "range": Array [ + 0, + 22, + ], + "sourceType": "module", + "tokens": Array [ + Object { + "loc": Object { + "end": Object { + "column": 6, + "line": 1, + }, + "start": Object { + "column": 0, + "line": 1, + }, + }, + "range": Array [ + 0, + 6, + ], + "type": "Keyword", + "value": "export", + }, + Object { + "loc": Object { + "end": Object { + "column": 12, + "line": 1, + }, + "start": Object { + "column": 7, + "line": 1, + }, + }, + "range": Array [ + 7, + 12, + ], + "type": "Keyword", + "value": "const", + }, + Object { + "loc": Object { + "end": Object { + "column": 16, + "line": 1, + }, + "start": Object { + "column": 13, + "line": 1, + }, + }, + "range": Array [ + 13, + 16, + ], + "type": "Identifier", + "value": "foo", + }, + Object { + "loc": Object { + "end": Object { + "column": 18, + "line": 1, + }, + "start": Object { + "column": 17, + "line": 1, + }, + }, + "range": Array [ + 17, + 18, + ], + "type": "Punctuator", + "value": "=", + }, + Object { + "loc": Object { + "end": Object { + "column": 20, + "line": 1, + }, + "start": Object { + "column": 19, + "line": 1, + }, + }, + "range": Array [ + 19, + 20, + ], + "type": "Numeric", + "value": "2", + }, + Object { + "loc": Object { + "end": Object { + "column": 21, + "line": 1, + }, + "start": Object { + "column": 20, + "line": 1, + }, + }, + "range": Array [ + 20, + 21, + ], + "type": "Punctuator", + "value": ";", + }, + ], + "type": "Program", +} +`; + exports[`javascript fixtures/modules/export-default-array.src 1`] = ` Object { "body": Array [ Object { "declaration": Object { - "elements": Array [], + "elements": Array [], + "loc": Object { + "end": Object { + "column": 17, + "line": 1, + }, + "start": Object { + "column": 15, + "line": 1, + }, + }, + "range": Array [ + 15, + 17, + ], + "type": "ArrayExpression", + }, + "loc": Object { + "end": Object { + "column": 18, + "line": 1, + }, + "start": Object { + "column": 0, + "line": 1, + }, + }, + "range": Array [ + 0, + 18, + ], + "type": "ExportDefaultDeclaration", + }, + ], + "loc": Object { + "end": Object { + "column": 0, + "line": 2, + }, + "start": Object { + "column": 0, + "line": 1, + }, + }, + "range": Array [ + 0, + 19, + ], + "sourceType": "module", + "tokens": Array [ + Object { + "loc": Object { + "end": Object { + "column": 6, + "line": 1, + }, + "start": Object { + "column": 0, + "line": 1, + }, + }, + "range": Array [ + 0, + 6, + ], + "type": "Keyword", + "value": "export", + }, + Object { + "loc": Object { + "end": Object { + "column": 14, + "line": 1, + }, + "start": Object { + "column": 7, + "line": 1, + }, + }, + "range": Array [ + 7, + 14, + ], + "type": "Keyword", + "value": "default", + }, + Object { + "loc": Object { + "end": Object { + "column": 16, + "line": 1, + }, + "start": Object { + "column": 15, + "line": 1, + }, + }, + "range": Array [ + 15, + 16, + ], + "type": "Punctuator", + "value": "[", + }, + Object { + "loc": Object { + "end": Object { + "column": 17, + "line": 1, + }, + "start": Object { + "column": 16, + "line": 1, + }, + }, + "range": Array [ + 16, + 17, + ], + "type": "Punctuator", + "value": "]", + }, + Object { + "loc": Object { + "end": Object { + "column": 18, + "line": 1, + }, + "start": Object { + "column": 17, + "line": 1, + }, + }, + "range": Array [ + 17, + 18, + ], + "type": "Punctuator", + "value": ";", + }, + ], + "type": "Program", +} +`; + +exports[`javascript fixtures/modules/export-default-async-named-function.src 1`] = ` +Object { + "body": Array [ + Object { + "declaration": Object { + "async": true, + "body": Object { + "body": Array [], + "loc": Object { + "end": Object { + "column": 38, + "line": 1, + }, + "start": Object { + "column": 36, + "line": 1, + }, + }, + "range": Array [ + 36, + 38, + ], + "type": "BlockStatement", + }, + "expression": false, + "generator": false, + "id": Object { + "loc": Object { + "end": Object { + "column": 33, + "line": 1, + }, + "start": Object { + "column": 30, + "line": 1, + }, + }, + "name": "foo", + "range": Array [ + 30, + 33, + ], + "type": "Identifier", + }, "loc": Object { "end": Object { - "column": 17, + "column": 38, "line": 1, }, "start": Object { @@ -105328,15 +105987,16 @@ Object { "line": 1, }, }, + "params": Array [], "range": Array [ 15, - 17, + 38, ], - "type": "ArrayExpression", + "type": "FunctionDeclaration", }, "loc": Object { "end": Object { - "column": 18, + "column": 38, "line": 1, }, "start": Object { @@ -105346,7 +106006,7 @@ Object { }, "range": Array [ 0, - 18, + 38, ], "type": "ExportDefaultDeclaration", }, @@ -105363,7 +106023,7 @@ Object { }, "range": Array [ 0, - 19, + 39, ], "sourceType": "module", "tokens": Array [ @@ -105406,56 +106066,128 @@ Object { Object { "loc": Object { "end": Object { - "column": 16, + "column": 20, + "line": 1, + }, + "start": Object { + "column": 15, + "line": 1, + }, + }, + "range": Array [ + 15, + 20, + ], + "type": "Identifier", + "value": "async", + }, + Object { + "loc": Object { + "end": Object { + "column": 29, + "line": 1, + }, + "start": Object { + "column": 21, + "line": 1, + }, + }, + "range": Array [ + 21, + 29, + ], + "type": "Keyword", + "value": "function", + }, + Object { + "loc": Object { + "end": Object { + "column": 33, + "line": 1, + }, + "start": Object { + "column": 30, + "line": 1, + }, + }, + "range": Array [ + 30, + 33, + ], + "type": "Identifier", + "value": "foo", + }, + Object { + "loc": Object { + "end": Object { + "column": 34, + "line": 1, + }, + "start": Object { + "column": 33, + "line": 1, + }, + }, + "range": Array [ + 33, + 34, + ], + "type": "Punctuator", + "value": "(", + }, + Object { + "loc": Object { + "end": Object { + "column": 35, "line": 1, }, "start": Object { - "column": 15, + "column": 34, "line": 1, }, }, "range": Array [ - 15, - 16, + 34, + 35, ], "type": "Punctuator", - "value": "[", + "value": ")", }, Object { "loc": Object { "end": Object { - "column": 17, + "column": 37, "line": 1, }, "start": Object { - "column": 16, + "column": 36, "line": 1, }, }, "range": Array [ - 16, - 17, + 36, + 37, ], "type": "Punctuator", - "value": "]", + "value": "{", }, Object { "loc": Object { "end": Object { - "column": 18, + "column": 38, "line": 1, }, "start": Object { - "column": 17, + "column": 37, "line": 1, }, }, "range": Array [ - 17, - 18, + 37, + 38, ], "type": "Punctuator", - "value": ";", + "value": "}", }, ], "type": "Program", @@ -109178,6 +109910,232 @@ Object { } `; +exports[`javascript fixtures/modules/export-let.src 1`] = ` +Object { + "body": Array [ + Object { + "declaration": Object { + "declarations": Array [ + Object { + "id": Object { + "loc": Object { + "end": Object { + "column": 14, + "line": 1, + }, + "start": Object { + "column": 11, + "line": 1, + }, + }, + "name": "foo", + "range": Array [ + 11, + 14, + ], + "type": "Identifier", + }, + "init": Object { + "loc": Object { + "end": Object { + "column": 18, + "line": 1, + }, + "start": Object { + "column": 17, + "line": 1, + }, + }, + "range": Array [ + 17, + 18, + ], + "raw": "2", + "type": "Literal", + "value": 2, + }, + "loc": Object { + "end": Object { + "column": 18, + "line": 1, + }, + "start": Object { + "column": 11, + "line": 1, + }, + }, + "range": Array [ + 11, + 18, + ], + "type": "VariableDeclarator", + }, + ], + "kind": "let", + "loc": Object { + "end": Object { + "column": 19, + "line": 1, + }, + "start": Object { + "column": 7, + "line": 1, + }, + }, + "range": Array [ + 7, + 19, + ], + "type": "VariableDeclaration", + }, + "loc": Object { + "end": Object { + "column": 19, + "line": 1, + }, + "start": Object { + "column": 0, + "line": 1, + }, + }, + "range": Array [ + 0, + 19, + ], + "source": null, + "specifiers": Array [], + "type": "ExportNamedDeclaration", + }, + ], + "loc": Object { + "end": Object { + "column": 0, + "line": 2, + }, + "start": Object { + "column": 0, + "line": 1, + }, + }, + "range": Array [ + 0, + 20, + ], + "sourceType": "module", + "tokens": Array [ + Object { + "loc": Object { + "end": Object { + "column": 6, + "line": 1, + }, + "start": Object { + "column": 0, + "line": 1, + }, + }, + "range": Array [ + 0, + 6, + ], + "type": "Keyword", + "value": "export", + }, + Object { + "loc": Object { + "end": Object { + "column": 10, + "line": 1, + }, + "start": Object { + "column": 7, + "line": 1, + }, + }, + "range": Array [ + 7, + 10, + ], + "type": "Keyword", + "value": "let", + }, + Object { + "loc": Object { + "end": Object { + "column": 14, + "line": 1, + }, + "start": Object { + "column": 11, + "line": 1, + }, + }, + "range": Array [ + 11, + 14, + ], + "type": "Identifier", + "value": "foo", + }, + Object { + "loc": Object { + "end": Object { + "column": 16, + "line": 1, + }, + "start": Object { + "column": 15, + "line": 1, + }, + }, + "range": Array [ + 15, + 16, + ], + "type": "Punctuator", + "value": "=", + }, + Object { + "loc": Object { + "end": Object { + "column": 18, + "line": 1, + }, + "start": Object { + "column": 17, + "line": 1, + }, + }, + "range": Array [ + 17, + 18, + ], + "type": "Numeric", + "value": "2", + }, + Object { + "loc": Object { + "end": Object { + "column": 19, + "line": 1, + }, + "start": Object { + "column": 18, + "line": 1, + }, + }, + "range": Array [ + 18, + 19, + ], + "type": "Punctuator", + "value": ";", + }, + ], + "type": "Program", +} +`; + exports[`javascript fixtures/modules/export-named-as-default.src 1`] = ` Object { "body": Array [ diff --git a/packages/typescript-estree/tests/lib/__snapshots__/semantic-diagnostics-enabled.ts.snap b/packages/typescript-estree/tests/lib/__snapshots__/semantic-diagnostics-enabled.ts.snap index 768b79a8fd31..e680cb92473c 100644 --- a/packages/typescript-estree/tests/lib/__snapshots__/semantic-diagnostics-enabled.ts.snap +++ b/packages/typescript-estree/tests/lib/__snapshots__/semantic-diagnostics-enabled.ts.snap @@ -790,8 +790,14 @@ exports[`Parse all fixtures with "errorOnTypeScriptSyntacticAndSemanticIssues" e exports[`Parse all fixtures with "errorOnTypeScriptSyntacticAndSemanticIssues" enabled fixtures/javascript/modules/error-strict.src 1`] = `"TEST OUTPUT: No semantic or syntactic issues found"`; +exports[`Parse all fixtures with "errorOnTypeScriptSyntacticAndSemanticIssues" enabled fixtures/javascript/modules/export-async-named-function.src 1`] = `"TEST OUTPUT: No semantic or syntactic issues found"`; + +exports[`Parse all fixtures with "errorOnTypeScriptSyntacticAndSemanticIssues" enabled fixtures/javascript/modules/export-const.src 1`] = `"TEST OUTPUT: No semantic or syntactic issues found"`; + exports[`Parse all fixtures with "errorOnTypeScriptSyntacticAndSemanticIssues" enabled fixtures/javascript/modules/export-default-array.src 1`] = `"TEST OUTPUT: No semantic or syntactic issues found"`; +exports[`Parse all fixtures with "errorOnTypeScriptSyntacticAndSemanticIssues" enabled fixtures/javascript/modules/export-default-async-named-function.src 1`] = `"TEST OUTPUT: No semantic or syntactic issues found"`; + exports[`Parse all fixtures with "errorOnTypeScriptSyntacticAndSemanticIssues" enabled fixtures/javascript/modules/export-default-class.src 1`] = `"TEST OUTPUT: No semantic or syntactic issues found"`; exports[`Parse all fixtures with "errorOnTypeScriptSyntacticAndSemanticIssues" enabled fixtures/javascript/modules/export-default-expression.src 1`] = `"TEST OUTPUT: No semantic or syntactic issues found"`; @@ -824,6 +830,8 @@ exports[`Parse all fixtures with "errorOnTypeScriptSyntacticAndSemanticIssues" e exports[`Parse all fixtures with "errorOnTypeScriptSyntacticAndSemanticIssues" enabled fixtures/javascript/modules/export-function.src 1`] = `"TEST OUTPUT: No semantic or syntactic issues found"`; +exports[`Parse all fixtures with "errorOnTypeScriptSyntacticAndSemanticIssues" enabled fixtures/javascript/modules/export-let.src 1`] = `"TEST OUTPUT: No semantic or syntactic issues found"`; + exports[`Parse all fixtures with "errorOnTypeScriptSyntacticAndSemanticIssues" enabled fixtures/javascript/modules/export-named-as-default.src 1`] = `"TEST OUTPUT: No semantic or syntactic issues found"`; exports[`Parse all fixtures with "errorOnTypeScriptSyntacticAndSemanticIssues" enabled fixtures/javascript/modules/export-named-as-specifier.src 1`] = `"TEST OUTPUT: No semantic or syntactic issues found"`; diff --git a/packages/typescript-estree/tests/lib/__snapshots__/typescript.ts.snap b/packages/typescript-estree/tests/lib/__snapshots__/typescript.ts.snap index 90ebe3e137e0..b481510bdae7 100644 --- a/packages/typescript-estree/tests/lib/__snapshots__/typescript.ts.snap +++ b/packages/typescript-estree/tests/lib/__snapshots__/typescript.ts.snap @@ -812,12 +812,12 @@ Object { "line": 3, }, "start": Object { - "column": 16, + "column": 7, "line": 1, }, }, "range": Array [ - 16, + 7, 68, ], "superClass": null, @@ -1259,12 +1259,12 @@ Object { "line": 3, }, "start": Object { - "column": 16, + "column": 7, "line": 1, }, }, "range": Array [ - 16, + 7, 86, ], "superClass": null, @@ -2561,12 +2561,12 @@ Object { "line": 3, }, "start": Object { - "column": 16, + "column": 7, "line": 1, }, }, "range": Array [ - 16, + 7, 78, ], "superClass": null, @@ -2948,12 +2948,12 @@ Object { "line": 2, }, "start": Object { - "column": 16, + "column": 7, "line": 1, }, }, "range": Array [ - 16, + 7, 31, ], "type": "TSInterfaceDeclaration", @@ -35398,7 +35398,7 @@ Object { "line": 4, }, "start": Object { - "column": 21, + "column": 7, "line": 1, }, }, @@ -35494,7 +35494,7 @@ Object { }, ], "range": Array [ - 21, + 7, 54, ], "type": "TSEnumDeclaration", @@ -35785,7 +35785,7 @@ Object { "line": 4, }, "start": Object { - "column": 15, + "column": 7, "line": 1, }, }, @@ -35881,7 +35881,7 @@ Object { }, ], "range": Array [ - 15, + 7, 48, ], "type": "TSEnumDeclaration", @@ -88748,7 +88748,7 @@ Object { "line": 1, }, "start": Object { - "column": 63, + "column": 7, "line": 1, }, }, @@ -88875,7 +88875,7 @@ Object { }, ], "range": Array [ - 63, + 7, 72, ], "type": "TSEnumDeclaration", From 9068b6276064e6729e1635ab11f7d70a543afa68 Mon Sep 17 00:00:00 2001 From: Armano Date: Sat, 26 Jan 2019 00:56:41 +0100 Subject: [PATCH 05/13] fix(ts-estree): expand optional property to include question token (#138) --- .../tests/lib/__snapshots__/typescript.ts.snap | 12 ++++++------ packages/typescript-estree/src/convert.ts | 8 ++++++++ .../tests/ast-alignment/fixtures-to-test.ts | 4 ---- .../tests/lib/__snapshots__/typescript.ts.snap | 12 ++++++------ 4 files changed, 20 insertions(+), 16 deletions(-) diff --git a/packages/parser/tests/lib/__snapshots__/typescript.ts.snap b/packages/parser/tests/lib/__snapshots__/typescript.ts.snap index e2dfa3efa430..08e944aecc31 100644 --- a/packages/parser/tests/lib/__snapshots__/typescript.ts.snap +++ b/packages/parser/tests/lib/__snapshots__/typescript.ts.snap @@ -48454,7 +48454,7 @@ Object { Object { "loc": Object { "end": Object { - "column": 13, + "column": 14, "line": 12, }, "start": Object { @@ -48466,7 +48466,7 @@ Object { "optional": true, "range": Array [ 253, - 254, + 255, ], "type": "Identifier", }, @@ -48544,7 +48544,7 @@ Object { Object { "loc": Object { "end": Object { - "column": 16, + "column": 17, "line": 13, }, "start": Object { @@ -48556,7 +48556,7 @@ Object { "optional": true, "range": Array [ 281, - 282, + 283, ], "type": "Identifier", }, @@ -53553,7 +53553,7 @@ Object { Object { "loc": Object { "end": Object { - "column": 31, + "column": 32, "line": 4, }, "start": Object { @@ -53565,7 +53565,7 @@ Object { "optional": true, "range": Array [ 73, - 76, + 77, ], "type": "Identifier", }, diff --git a/packages/typescript-estree/src/convert.ts b/packages/typescript-estree/src/convert.ts index 64120d6a8d85..ff365b187c7e 100644 --- a/packages/typescript-estree/src/convert.ts +++ b/packages/typescript-estree/src/convert.ts @@ -1315,6 +1315,14 @@ export default function convert(config: ConvertConfig): ESTreeNode | null { } if (node.questionToken) { + if (node.questionToken.end > parameter.range[1]) { + parameter.range[1] = node.questionToken.end; + parameter.loc = getLocFor( + parameter.range[0], + parameter.range[1], + ast + ); + } parameter.optional = true; } diff --git a/packages/typescript-estree/tests/ast-alignment/fixtures-to-test.ts b/packages/typescript-estree/tests/ast-alignment/fixtures-to-test.ts index 522cc53a3351..b44faf0feb64 100644 --- a/packages/typescript-estree/tests/ast-alignment/fixtures-to-test.ts +++ b/packages/typescript-estree/tests/ast-alignment/fixtures-to-test.ts @@ -323,10 +323,6 @@ tester.addFixturePatternConfig('typescript/basics', { * TODO: Investigate in more depth, potentially split up different parts of the interface */ 'interface-with-all-property-types', // babel parse errors - /** - * there is difference in range between babel and ts-estree - */ - 'interface-with-optional-properties', /** * Babel parses it as TSQualifiedName * ts parses it as MemberExpression diff --git a/packages/typescript-estree/tests/lib/__snapshots__/typescript.ts.snap b/packages/typescript-estree/tests/lib/__snapshots__/typescript.ts.snap index b481510bdae7..c5085cf91009 100644 --- a/packages/typescript-estree/tests/lib/__snapshots__/typescript.ts.snap +++ b/packages/typescript-estree/tests/lib/__snapshots__/typescript.ts.snap @@ -48344,7 +48344,7 @@ Object { Object { "loc": Object { "end": Object { - "column": 13, + "column": 14, "line": 12, }, "start": Object { @@ -48356,7 +48356,7 @@ Object { "optional": true, "range": Array [ 253, - 254, + 255, ], "type": "Identifier", }, @@ -48434,7 +48434,7 @@ Object { Object { "loc": Object { "end": Object { - "column": 16, + "column": 17, "line": 13, }, "start": Object { @@ -48446,7 +48446,7 @@ Object { "optional": true, "range": Array [ 281, - 282, + 283, ], "type": "Identifier", }, @@ -53414,7 +53414,7 @@ Object { Object { "loc": Object { "end": Object { - "column": 31, + "column": 32, "line": 4, }, "start": Object { @@ -53426,7 +53426,7 @@ Object { "optional": true, "range": Array [ 73, - 76, + 77, ], "type": "Identifier", }, From e442d280285e8acab253a5e80a7a6a6c5d1b4692 Mon Sep 17 00:00:00 2001 From: Armano Date: Sun, 27 Jan 2019 18:00:24 +0100 Subject: [PATCH 06/13] test(ts-estree): add broken test cases (#140) --- .../lib/__snapshots__/javascript.ts.snap | 1178 +++++++++++++++++ .../lib/__snapshots__/typescript.ts.snap | 392 ++++++ .../function/function-with-return.js | 3 + .../function/return-multiline-sequence.src.js | 7 + .../function/return-sequence.src.js | 3 + ...ow-function-with-optional-parameter.src.ts | 1 + .../tests/ast-alignment/fixtures-to-test.ts | 27 +- .../lib/__snapshots__/javascript.ts.snap | 1176 ++++++++++++++++ .../semantic-diagnostics-enabled.ts.snap | 6 + .../lib/__snapshots__/typescript.ts.snap | 391 ++++++ 10 files changed, 3175 insertions(+), 9 deletions(-) create mode 100644 packages/shared-fixtures/fixtures/javascript/function/function-with-return.js create mode 100644 packages/shared-fixtures/fixtures/javascript/function/return-multiline-sequence.src.js create mode 100644 packages/shared-fixtures/fixtures/javascript/function/return-sequence.src.js create mode 100644 packages/shared-fixtures/fixtures/typescript/basics/arrow-function-with-optional-parameter.src.ts diff --git a/packages/parser/tests/lib/__snapshots__/javascript.ts.snap b/packages/parser/tests/lib/__snapshots__/javascript.ts.snap index 3dc1ea581abe..6a51ccfcd4de 100644 --- a/packages/parser/tests/lib/__snapshots__/javascript.ts.snap +++ b/packages/parser/tests/lib/__snapshots__/javascript.ts.snap @@ -99362,6 +99362,1184 @@ Object { } `; +exports[`javascript fixtures/function/return-multiline-sequence.src 1`] = ` +Object { + "body": Array [ + Object { + "async": false, + "body": Object { + "body": Array [ + Object { + "argument": Object { + "expressions": Array [ + Object { + "loc": Object { + "end": Object { + "column": 5, + "line": 3, + }, + "start": Object { + "column": 4, + "line": 3, + }, + }, + "name": "x", + "range": Array [ + 40, + 41, + ], + "type": "Identifier", + }, + Object { + "loc": Object { + "end": Object { + "column": 5, + "line": 4, + }, + "start": Object { + "column": 4, + "line": 4, + }, + }, + "name": "y", + "range": Array [ + 47, + 48, + ], + "type": "Identifier", + }, + Object { + "loc": Object { + "end": Object { + "column": 5, + "line": 5, + }, + "start": Object { + "column": 4, + "line": 5, + }, + }, + "name": "z", + "range": Array [ + 54, + 55, + ], + "type": "Identifier", + }, + ], + "loc": Object { + "end": Object { + "column": 5, + "line": 5, + }, + "start": Object { + "column": 4, + "line": 3, + }, + }, + "range": Array [ + 40, + 55, + ], + "type": "SequenceExpression", + }, + "loc": Object { + "end": Object { + "column": 4, + "line": 6, + }, + "start": Object { + "column": 2, + "line": 2, + }, + }, + "range": Array [ + 27, + 60, + ], + "type": "ReturnStatement", + }, + ], + "loc": Object { + "end": Object { + "column": 1, + "line": 7, + }, + "start": Object { + "column": 23, + "line": 1, + }, + }, + "range": Array [ + 23, + 62, + ], + "type": "BlockStatement", + }, + "expression": false, + "generator": false, + "id": Object { + "loc": Object { + "end": Object { + "column": 12, + "line": 1, + }, + "start": Object { + "column": 9, + "line": 1, + }, + }, + "name": "foo", + "range": Array [ + 9, + 12, + ], + "type": "Identifier", + }, + "loc": Object { + "end": Object { + "column": 1, + "line": 7, + }, + "start": Object { + "column": 0, + "line": 1, + }, + }, + "params": Array [ + Object { + "loc": Object { + "end": Object { + "column": 15, + "line": 1, + }, + "start": Object { + "column": 14, + "line": 1, + }, + }, + "name": "x", + "range": Array [ + 14, + 15, + ], + "type": "Identifier", + }, + Object { + "loc": Object { + "end": Object { + "column": 18, + "line": 1, + }, + "start": Object { + "column": 17, + "line": 1, + }, + }, + "name": "y", + "range": Array [ + 17, + 18, + ], + "type": "Identifier", + }, + Object { + "loc": Object { + "end": Object { + "column": 21, + "line": 1, + }, + "start": Object { + "column": 20, + "line": 1, + }, + }, + "name": "z", + "range": Array [ + 20, + 21, + ], + "type": "Identifier", + }, + ], + "range": Array [ + 0, + 62, + ], + "type": "FunctionDeclaration", + }, + ], + "comments": Array [], + "loc": Object { + "end": Object { + "column": 0, + "line": 8, + }, + "start": Object { + "column": 0, + "line": 1, + }, + }, + "range": Array [ + 0, + 63, + ], + "sourceType": "module", + "tokens": Array [ + Object { + "loc": Object { + "end": Object { + "column": 8, + "line": 1, + }, + "start": Object { + "column": 0, + "line": 1, + }, + }, + "range": Array [ + 0, + 8, + ], + "type": "Keyword", + "value": "function", + }, + Object { + "loc": Object { + "end": Object { + "column": 12, + "line": 1, + }, + "start": Object { + "column": 9, + "line": 1, + }, + }, + "range": Array [ + 9, + 12, + ], + "type": "Identifier", + "value": "foo", + }, + Object { + "loc": Object { + "end": Object { + "column": 14, + "line": 1, + }, + "start": Object { + "column": 13, + "line": 1, + }, + }, + "range": Array [ + 13, + 14, + ], + "type": "Punctuator", + "value": "(", + }, + Object { + "loc": Object { + "end": Object { + "column": 15, + "line": 1, + }, + "start": Object { + "column": 14, + "line": 1, + }, + }, + "range": Array [ + 14, + 15, + ], + "type": "Identifier", + "value": "x", + }, + Object { + "loc": Object { + "end": Object { + "column": 16, + "line": 1, + }, + "start": Object { + "column": 15, + "line": 1, + }, + }, + "range": Array [ + 15, + 16, + ], + "type": "Punctuator", + "value": ",", + }, + Object { + "loc": Object { + "end": Object { + "column": 18, + "line": 1, + }, + "start": Object { + "column": 17, + "line": 1, + }, + }, + "range": Array [ + 17, + 18, + ], + "type": "Identifier", + "value": "y", + }, + Object { + "loc": Object { + "end": Object { + "column": 19, + "line": 1, + }, + "start": Object { + "column": 18, + "line": 1, + }, + }, + "range": Array [ + 18, + 19, + ], + "type": "Punctuator", + "value": ",", + }, + Object { + "loc": Object { + "end": Object { + "column": 21, + "line": 1, + }, + "start": Object { + "column": 20, + "line": 1, + }, + }, + "range": Array [ + 20, + 21, + ], + "type": "Identifier", + "value": "z", + }, + Object { + "loc": Object { + "end": Object { + "column": 22, + "line": 1, + }, + "start": Object { + "column": 21, + "line": 1, + }, + }, + "range": Array [ + 21, + 22, + ], + "type": "Punctuator", + "value": ")", + }, + Object { + "loc": Object { + "end": Object { + "column": 24, + "line": 1, + }, + "start": Object { + "column": 23, + "line": 1, + }, + }, + "range": Array [ + 23, + 24, + ], + "type": "Punctuator", + "value": "{", + }, + Object { + "loc": Object { + "end": Object { + "column": 8, + "line": 2, + }, + "start": Object { + "column": 2, + "line": 2, + }, + }, + "range": Array [ + 27, + 33, + ], + "type": "Keyword", + "value": "return", + }, + Object { + "loc": Object { + "end": Object { + "column": 10, + "line": 2, + }, + "start": Object { + "column": 9, + "line": 2, + }, + }, + "range": Array [ + 34, + 35, + ], + "type": "Punctuator", + "value": "(", + }, + Object { + "loc": Object { + "end": Object { + "column": 5, + "line": 3, + }, + "start": Object { + "column": 4, + "line": 3, + }, + }, + "range": Array [ + 40, + 41, + ], + "type": "Identifier", + "value": "x", + }, + Object { + "loc": Object { + "end": Object { + "column": 6, + "line": 3, + }, + "start": Object { + "column": 5, + "line": 3, + }, + }, + "range": Array [ + 41, + 42, + ], + "type": "Punctuator", + "value": ",", + }, + Object { + "loc": Object { + "end": Object { + "column": 5, + "line": 4, + }, + "start": Object { + "column": 4, + "line": 4, + }, + }, + "range": Array [ + 47, + 48, + ], + "type": "Identifier", + "value": "y", + }, + Object { + "loc": Object { + "end": Object { + "column": 6, + "line": 4, + }, + "start": Object { + "column": 5, + "line": 4, + }, + }, + "range": Array [ + 48, + 49, + ], + "type": "Punctuator", + "value": ",", + }, + Object { + "loc": Object { + "end": Object { + "column": 5, + "line": 5, + }, + "start": Object { + "column": 4, + "line": 5, + }, + }, + "range": Array [ + 54, + 55, + ], + "type": "Identifier", + "value": "z", + }, + Object { + "loc": Object { + "end": Object { + "column": 3, + "line": 6, + }, + "start": Object { + "column": 2, + "line": 6, + }, + }, + "range": Array [ + 58, + 59, + ], + "type": "Punctuator", + "value": ")", + }, + Object { + "loc": Object { + "end": Object { + "column": 4, + "line": 6, + }, + "start": Object { + "column": 3, + "line": 6, + }, + }, + "range": Array [ + 59, + 60, + ], + "type": "Punctuator", + "value": ";", + }, + Object { + "loc": Object { + "end": Object { + "column": 1, + "line": 7, + }, + "start": Object { + "column": 0, + "line": 7, + }, + }, + "range": Array [ + 61, + 62, + ], + "type": "Punctuator", + "value": "}", + }, + ], + "type": "Program", +} +`; + +exports[`javascript fixtures/function/return-sequence.src 1`] = ` +Object { + "body": Array [ + Object { + "async": false, + "body": Object { + "body": Array [ + Object { + "argument": Object { + "expressions": Array [ + Object { + "loc": Object { + "end": Object { + "column": 11, + "line": 2, + }, + "start": Object { + "column": 10, + "line": 2, + }, + }, + "name": "x", + "range": Array [ + 35, + 36, + ], + "type": "Identifier", + }, + Object { + "loc": Object { + "end": Object { + "column": 14, + "line": 2, + }, + "start": Object { + "column": 13, + "line": 2, + }, + }, + "name": "y", + "range": Array [ + 38, + 39, + ], + "type": "Identifier", + }, + Object { + "loc": Object { + "end": Object { + "column": 17, + "line": 2, + }, + "start": Object { + "column": 16, + "line": 2, + }, + }, + "name": "z", + "range": Array [ + 41, + 42, + ], + "type": "Identifier", + }, + ], + "loc": Object { + "end": Object { + "column": 17, + "line": 2, + }, + "start": Object { + "column": 10, + "line": 2, + }, + }, + "range": Array [ + 35, + 42, + ], + "type": "SequenceExpression", + }, + "loc": Object { + "end": Object { + "column": 19, + "line": 2, + }, + "start": Object { + "column": 2, + "line": 2, + }, + }, + "range": Array [ + 27, + 44, + ], + "type": "ReturnStatement", + }, + ], + "loc": Object { + "end": Object { + "column": 1, + "line": 3, + }, + "start": Object { + "column": 23, + "line": 1, + }, + }, + "range": Array [ + 23, + 46, + ], + "type": "BlockStatement", + }, + "expression": false, + "generator": false, + "id": Object { + "loc": Object { + "end": Object { + "column": 12, + "line": 1, + }, + "start": Object { + "column": 9, + "line": 1, + }, + }, + "name": "foo", + "range": Array [ + 9, + 12, + ], + "type": "Identifier", + }, + "loc": Object { + "end": Object { + "column": 1, + "line": 3, + }, + "start": Object { + "column": 0, + "line": 1, + }, + }, + "params": Array [ + Object { + "loc": Object { + "end": Object { + "column": 15, + "line": 1, + }, + "start": Object { + "column": 14, + "line": 1, + }, + }, + "name": "x", + "range": Array [ + 14, + 15, + ], + "type": "Identifier", + }, + Object { + "loc": Object { + "end": Object { + "column": 18, + "line": 1, + }, + "start": Object { + "column": 17, + "line": 1, + }, + }, + "name": "y", + "range": Array [ + 17, + 18, + ], + "type": "Identifier", + }, + Object { + "loc": Object { + "end": Object { + "column": 21, + "line": 1, + }, + "start": Object { + "column": 20, + "line": 1, + }, + }, + "name": "z", + "range": Array [ + 20, + 21, + ], + "type": "Identifier", + }, + ], + "range": Array [ + 0, + 46, + ], + "type": "FunctionDeclaration", + }, + ], + "comments": Array [], + "loc": Object { + "end": Object { + "column": 0, + "line": 4, + }, + "start": Object { + "column": 0, + "line": 1, + }, + }, + "range": Array [ + 0, + 47, + ], + "sourceType": "module", + "tokens": Array [ + Object { + "loc": Object { + "end": Object { + "column": 8, + "line": 1, + }, + "start": Object { + "column": 0, + "line": 1, + }, + }, + "range": Array [ + 0, + 8, + ], + "type": "Keyword", + "value": "function", + }, + Object { + "loc": Object { + "end": Object { + "column": 12, + "line": 1, + }, + "start": Object { + "column": 9, + "line": 1, + }, + }, + "range": Array [ + 9, + 12, + ], + "type": "Identifier", + "value": "foo", + }, + Object { + "loc": Object { + "end": Object { + "column": 14, + "line": 1, + }, + "start": Object { + "column": 13, + "line": 1, + }, + }, + "range": Array [ + 13, + 14, + ], + "type": "Punctuator", + "value": "(", + }, + Object { + "loc": Object { + "end": Object { + "column": 15, + "line": 1, + }, + "start": Object { + "column": 14, + "line": 1, + }, + }, + "range": Array [ + 14, + 15, + ], + "type": "Identifier", + "value": "x", + }, + Object { + "loc": Object { + "end": Object { + "column": 16, + "line": 1, + }, + "start": Object { + "column": 15, + "line": 1, + }, + }, + "range": Array [ + 15, + 16, + ], + "type": "Punctuator", + "value": ",", + }, + Object { + "loc": Object { + "end": Object { + "column": 18, + "line": 1, + }, + "start": Object { + "column": 17, + "line": 1, + }, + }, + "range": Array [ + 17, + 18, + ], + "type": "Identifier", + "value": "y", + }, + Object { + "loc": Object { + "end": Object { + "column": 19, + "line": 1, + }, + "start": Object { + "column": 18, + "line": 1, + }, + }, + "range": Array [ + 18, + 19, + ], + "type": "Punctuator", + "value": ",", + }, + Object { + "loc": Object { + "end": Object { + "column": 21, + "line": 1, + }, + "start": Object { + "column": 20, + "line": 1, + }, + }, + "range": Array [ + 20, + 21, + ], + "type": "Identifier", + "value": "z", + }, + Object { + "loc": Object { + "end": Object { + "column": 22, + "line": 1, + }, + "start": Object { + "column": 21, + "line": 1, + }, + }, + "range": Array [ + 21, + 22, + ], + "type": "Punctuator", + "value": ")", + }, + Object { + "loc": Object { + "end": Object { + "column": 24, + "line": 1, + }, + "start": Object { + "column": 23, + "line": 1, + }, + }, + "range": Array [ + 23, + 24, + ], + "type": "Punctuator", + "value": "{", + }, + Object { + "loc": Object { + "end": Object { + "column": 8, + "line": 2, + }, + "start": Object { + "column": 2, + "line": 2, + }, + }, + "range": Array [ + 27, + 33, + ], + "type": "Keyword", + "value": "return", + }, + Object { + "loc": Object { + "end": Object { + "column": 10, + "line": 2, + }, + "start": Object { + "column": 9, + "line": 2, + }, + }, + "range": Array [ + 34, + 35, + ], + "type": "Punctuator", + "value": "(", + }, + Object { + "loc": Object { + "end": Object { + "column": 11, + "line": 2, + }, + "start": Object { + "column": 10, + "line": 2, + }, + }, + "range": Array [ + 35, + 36, + ], + "type": "Identifier", + "value": "x", + }, + Object { + "loc": Object { + "end": Object { + "column": 12, + "line": 2, + }, + "start": Object { + "column": 11, + "line": 2, + }, + }, + "range": Array [ + 36, + 37, + ], + "type": "Punctuator", + "value": ",", + }, + Object { + "loc": Object { + "end": Object { + "column": 14, + "line": 2, + }, + "start": Object { + "column": 13, + "line": 2, + }, + }, + "range": Array [ + 38, + 39, + ], + "type": "Identifier", + "value": "y", + }, + Object { + "loc": Object { + "end": Object { + "column": 15, + "line": 2, + }, + "start": Object { + "column": 14, + "line": 2, + }, + }, + "range": Array [ + 39, + 40, + ], + "type": "Punctuator", + "value": ",", + }, + Object { + "loc": Object { + "end": Object { + "column": 17, + "line": 2, + }, + "start": Object { + "column": 16, + "line": 2, + }, + }, + "range": Array [ + 41, + 42, + ], + "type": "Identifier", + "value": "z", + }, + Object { + "loc": Object { + "end": Object { + "column": 18, + "line": 2, + }, + "start": Object { + "column": 17, + "line": 2, + }, + }, + "range": Array [ + 42, + 43, + ], + "type": "Punctuator", + "value": ")", + }, + Object { + "loc": Object { + "end": Object { + "column": 19, + "line": 2, + }, + "start": Object { + "column": 18, + "line": 2, + }, + }, + "range": Array [ + 43, + 44, + ], + "type": "Punctuator", + "value": ";", + }, + Object { + "loc": Object { + "end": Object { + "column": 1, + "line": 3, + }, + "start": Object { + "column": 0, + "line": 3, + }, + }, + "range": Array [ + 45, + 46, + ], + "type": "Punctuator", + "value": "}", + }, + ], + "type": "Program", +} +`; + exports[`javascript fixtures/generators/anonymous-generator.src 1`] = ` Object { "body": Array [ diff --git a/packages/parser/tests/lib/__snapshots__/typescript.ts.snap b/packages/parser/tests/lib/__snapshots__/typescript.ts.snap index 08e944aecc31..f540948a5558 100644 --- a/packages/parser/tests/lib/__snapshots__/typescript.ts.snap +++ b/packages/parser/tests/lib/__snapshots__/typescript.ts.snap @@ -3114,6 +3114,398 @@ Object { } `; +exports[`typescript fixtures/basics/arrow-function-with-optional-parameter.src 1`] = ` +Object { + "body": Array [ + Object { + "expression": Object { + "arguments": Array [], + "callee": Object { + "async": false, + "body": Object { + "left": Object { + "loc": Object { + "end": Object { + "column": 10, + "line": 1, + }, + "start": Object { + "column": 9, + "line": 1, + }, + }, + "name": "k", + "range": Array [ + 9, + 10, + ], + "type": "Identifier", + }, + "loc": Object { + "end": Object { + "column": 14, + "line": 1, + }, + "start": Object { + "column": 9, + "line": 1, + }, + }, + "operator": "+", + "range": Array [ + 9, + 14, + ], + "right": Object { + "loc": Object { + "end": Object { + "column": 14, + "line": 1, + }, + "start": Object { + "column": 13, + "line": 1, + }, + }, + "range": Array [ + 13, + 14, + ], + "raw": "1", + "type": "Literal", + "value": 1, + }, + "type": "BinaryExpression", + }, + "expression": true, + "generator": false, + "id": null, + "loc": Object { + "end": Object { + "column": 14, + "line": 1, + }, + "start": Object { + "column": 1, + "line": 1, + }, + }, + "params": Array [ + Object { + "loc": Object { + "end": Object { + "column": 4, + "line": 1, + }, + "start": Object { + "column": 2, + "line": 1, + }, + }, + "name": "k", + "optional": true, + "range": Array [ + 2, + 4, + ], + "type": "Identifier", + }, + ], + "range": Array [ + 1, + 14, + ], + "type": "ArrowFunctionExpression", + }, + "loc": Object { + "end": Object { + "column": 17, + "line": 1, + }, + "start": Object { + "column": 0, + "line": 1, + }, + }, + "range": Array [ + 0, + 17, + ], + "type": "CallExpression", + }, + "loc": Object { + "end": Object { + "column": 18, + "line": 1, + }, + "start": Object { + "column": 0, + "line": 1, + }, + }, + "range": Array [ + 0, + 18, + ], + "type": "ExpressionStatement", + }, + ], + "comments": Array [], + "loc": Object { + "end": Object { + "column": 0, + "line": 2, + }, + "start": Object { + "column": 0, + "line": 1, + }, + }, + "range": Array [ + 0, + 19, + ], + "sourceType": "module", + "tokens": Array [ + Object { + "loc": Object { + "end": Object { + "column": 1, + "line": 1, + }, + "start": Object { + "column": 0, + "line": 1, + }, + }, + "range": Array [ + 0, + 1, + ], + "type": "Punctuator", + "value": "(", + }, + Object { + "loc": Object { + "end": Object { + "column": 2, + "line": 1, + }, + "start": Object { + "column": 1, + "line": 1, + }, + }, + "range": Array [ + 1, + 2, + ], + "type": "Punctuator", + "value": "(", + }, + Object { + "loc": Object { + "end": Object { + "column": 3, + "line": 1, + }, + "start": Object { + "column": 2, + "line": 1, + }, + }, + "range": Array [ + 2, + 3, + ], + "type": "Identifier", + "value": "k", + }, + Object { + "loc": Object { + "end": Object { + "column": 4, + "line": 1, + }, + "start": Object { + "column": 3, + "line": 1, + }, + }, + "range": Array [ + 3, + 4, + ], + "type": "Punctuator", + "value": "?", + }, + Object { + "loc": Object { + "end": Object { + "column": 5, + "line": 1, + }, + "start": Object { + "column": 4, + "line": 1, + }, + }, + "range": Array [ + 4, + 5, + ], + "type": "Punctuator", + "value": ")", + }, + Object { + "loc": Object { + "end": Object { + "column": 8, + "line": 1, + }, + "start": Object { + "column": 6, + "line": 1, + }, + }, + "range": Array [ + 6, + 8, + ], + "type": "Punctuator", + "value": "=>", + }, + Object { + "loc": Object { + "end": Object { + "column": 10, + "line": 1, + }, + "start": Object { + "column": 9, + "line": 1, + }, + }, + "range": Array [ + 9, + 10, + ], + "type": "Identifier", + "value": "k", + }, + Object { + "loc": Object { + "end": Object { + "column": 12, + "line": 1, + }, + "start": Object { + "column": 11, + "line": 1, + }, + }, + "range": Array [ + 11, + 12, + ], + "type": "Punctuator", + "value": "+", + }, + Object { + "loc": Object { + "end": Object { + "column": 14, + "line": 1, + }, + "start": Object { + "column": 13, + "line": 1, + }, + }, + "range": Array [ + 13, + 14, + ], + "type": "Numeric", + "value": "1", + }, + Object { + "loc": Object { + "end": Object { + "column": 15, + "line": 1, + }, + "start": Object { + "column": 14, + "line": 1, + }, + }, + "range": Array [ + 14, + 15, + ], + "type": "Punctuator", + "value": ")", + }, + Object { + "loc": Object { + "end": Object { + "column": 16, + "line": 1, + }, + "start": Object { + "column": 15, + "line": 1, + }, + }, + "range": Array [ + 15, + 16, + ], + "type": "Punctuator", + "value": "(", + }, + Object { + "loc": Object { + "end": Object { + "column": 17, + "line": 1, + }, + "start": Object { + "column": 16, + "line": 1, + }, + }, + "range": Array [ + 16, + 17, + ], + "type": "Punctuator", + "value": ")", + }, + Object { + "loc": Object { + "end": Object { + "column": 18, + "line": 1, + }, + "start": Object { + "column": 17, + "line": 1, + }, + }, + "range": Array [ + 17, + 18, + ], + "type": "Punctuator", + "value": ";", + }, + ], + "type": "Program", +} +`; + exports[`typescript fixtures/basics/arrow-function-with-type-parameters.src 1`] = ` Object { "body": Array [ diff --git a/packages/shared-fixtures/fixtures/javascript/function/function-with-return.js b/packages/shared-fixtures/fixtures/javascript/function/function-with-return.js new file mode 100644 index 000000000000..c98a373f0c38 --- /dev/null +++ b/packages/shared-fixtures/fixtures/javascript/function/function-with-return.js @@ -0,0 +1,3 @@ +function foo () { + return 1; +} diff --git a/packages/shared-fixtures/fixtures/javascript/function/return-multiline-sequence.src.js b/packages/shared-fixtures/fixtures/javascript/function/return-multiline-sequence.src.js new file mode 100644 index 000000000000..be3070488139 --- /dev/null +++ b/packages/shared-fixtures/fixtures/javascript/function/return-multiline-sequence.src.js @@ -0,0 +1,7 @@ +function foo (x, y, z) { + return ( + x, + y, + z + ); +} diff --git a/packages/shared-fixtures/fixtures/javascript/function/return-sequence.src.js b/packages/shared-fixtures/fixtures/javascript/function/return-sequence.src.js new file mode 100644 index 000000000000..3ffe77903028 --- /dev/null +++ b/packages/shared-fixtures/fixtures/javascript/function/return-sequence.src.js @@ -0,0 +1,3 @@ +function foo (x, y, z) { + return (x, y, z); +} diff --git a/packages/shared-fixtures/fixtures/typescript/basics/arrow-function-with-optional-parameter.src.ts b/packages/shared-fixtures/fixtures/typescript/basics/arrow-function-with-optional-parameter.src.ts new file mode 100644 index 000000000000..0289f3828aa8 --- /dev/null +++ b/packages/shared-fixtures/fixtures/typescript/basics/arrow-function-with-optional-parameter.src.ts @@ -0,0 +1 @@ +((k?) => k + 1)(); diff --git a/packages/typescript-estree/tests/ast-alignment/fixtures-to-test.ts b/packages/typescript-estree/tests/ast-alignment/fixtures-to-test.ts index b44faf0feb64..e92f68f968f4 100644 --- a/packages/typescript-estree/tests/ast-alignment/fixtures-to-test.ts +++ b/packages/typescript-estree/tests/ast-alignment/fixtures-to-test.ts @@ -167,6 +167,15 @@ tester.addFixturePatternConfig('javascript/arrowFunctions', { 'error-strict-dup-params' // babel parse errors ] }); +tester.addFixturePatternConfig('javascript/function', { + ignore: [ + /** + * Babel has invalid end range of multiline SequenceExpression + * TODO: report it to babel + */ + 'return-multiline-sequence' + ] +}); tester.addFixturePatternConfig('javascript/bigIntLiterals'); tester.addFixturePatternConfig('javascript/binaryLiterals'); @@ -355,11 +364,16 @@ tester.addFixturePatternConfig('typescript/basics', { */ 'type-assertion-arrow-function', /** - * Babel does not include range of declare keyword into enum range - * https://github.com/babel/babel/issues/9399 + * PR for range of declare keyword has been merged into Babel: https://github.com/babel/babel/pull/9406 + * TODO: remove me in next babel > 7.3.1 */ 'export-declare-const-named-enum', - 'export-declare-named-enum' + 'export-declare-named-enum', + /** + * Babel does not include optional keyword into range parameter in arrow function + * TODO: report it to babel + */ + 'arrow-function-with-optional-parameter' ], ignoreSourceType: [ /** @@ -418,13 +432,8 @@ tester.addFixturePatternConfig('typescript/declare', { tester.addFixturePatternConfig('typescript/namespaces-and-modules', { fileType: 'ts', - ignore: [ - /** - * Minor AST difference - */ - 'nested-internal-module' - ], ignoreSourceType: [ + 'nested-internal-module', 'module-with-default-exports', 'ambient-module-declaration-with-import', 'declare-namespace-with-exported-function' diff --git a/packages/typescript-estree/tests/lib/__snapshots__/javascript.ts.snap b/packages/typescript-estree/tests/lib/__snapshots__/javascript.ts.snap index 5a57277c9353..85045786c853 100644 --- a/packages/typescript-estree/tests/lib/__snapshots__/javascript.ts.snap +++ b/packages/typescript-estree/tests/lib/__snapshots__/javascript.ts.snap @@ -99058,6 +99058,1182 @@ Object { } `; +exports[`javascript fixtures/function/return-multiline-sequence.src 1`] = ` +Object { + "body": Array [ + Object { + "async": false, + "body": Object { + "body": Array [ + Object { + "argument": Object { + "expressions": Array [ + Object { + "loc": Object { + "end": Object { + "column": 5, + "line": 3, + }, + "start": Object { + "column": 4, + "line": 3, + }, + }, + "name": "x", + "range": Array [ + 40, + 41, + ], + "type": "Identifier", + }, + Object { + "loc": Object { + "end": Object { + "column": 5, + "line": 4, + }, + "start": Object { + "column": 4, + "line": 4, + }, + }, + "name": "y", + "range": Array [ + 47, + 48, + ], + "type": "Identifier", + }, + Object { + "loc": Object { + "end": Object { + "column": 5, + "line": 5, + }, + "start": Object { + "column": 4, + "line": 5, + }, + }, + "name": "z", + "range": Array [ + 54, + 55, + ], + "type": "Identifier", + }, + ], + "loc": Object { + "end": Object { + "column": 5, + "line": 5, + }, + "start": Object { + "column": 4, + "line": 3, + }, + }, + "range": Array [ + 40, + 55, + ], + "type": "SequenceExpression", + }, + "loc": Object { + "end": Object { + "column": 4, + "line": 6, + }, + "start": Object { + "column": 2, + "line": 2, + }, + }, + "range": Array [ + 27, + 60, + ], + "type": "ReturnStatement", + }, + ], + "loc": Object { + "end": Object { + "column": 1, + "line": 7, + }, + "start": Object { + "column": 23, + "line": 1, + }, + }, + "range": Array [ + 23, + 62, + ], + "type": "BlockStatement", + }, + "expression": false, + "generator": false, + "id": Object { + "loc": Object { + "end": Object { + "column": 12, + "line": 1, + }, + "start": Object { + "column": 9, + "line": 1, + }, + }, + "name": "foo", + "range": Array [ + 9, + 12, + ], + "type": "Identifier", + }, + "loc": Object { + "end": Object { + "column": 1, + "line": 7, + }, + "start": Object { + "column": 0, + "line": 1, + }, + }, + "params": Array [ + Object { + "loc": Object { + "end": Object { + "column": 15, + "line": 1, + }, + "start": Object { + "column": 14, + "line": 1, + }, + }, + "name": "x", + "range": Array [ + 14, + 15, + ], + "type": "Identifier", + }, + Object { + "loc": Object { + "end": Object { + "column": 18, + "line": 1, + }, + "start": Object { + "column": 17, + "line": 1, + }, + }, + "name": "y", + "range": Array [ + 17, + 18, + ], + "type": "Identifier", + }, + Object { + "loc": Object { + "end": Object { + "column": 21, + "line": 1, + }, + "start": Object { + "column": 20, + "line": 1, + }, + }, + "name": "z", + "range": Array [ + 20, + 21, + ], + "type": "Identifier", + }, + ], + "range": Array [ + 0, + 62, + ], + "type": "FunctionDeclaration", + }, + ], + "loc": Object { + "end": Object { + "column": 0, + "line": 8, + }, + "start": Object { + "column": 0, + "line": 1, + }, + }, + "range": Array [ + 0, + 63, + ], + "sourceType": "script", + "tokens": Array [ + Object { + "loc": Object { + "end": Object { + "column": 8, + "line": 1, + }, + "start": Object { + "column": 0, + "line": 1, + }, + }, + "range": Array [ + 0, + 8, + ], + "type": "Keyword", + "value": "function", + }, + Object { + "loc": Object { + "end": Object { + "column": 12, + "line": 1, + }, + "start": Object { + "column": 9, + "line": 1, + }, + }, + "range": Array [ + 9, + 12, + ], + "type": "Identifier", + "value": "foo", + }, + Object { + "loc": Object { + "end": Object { + "column": 14, + "line": 1, + }, + "start": Object { + "column": 13, + "line": 1, + }, + }, + "range": Array [ + 13, + 14, + ], + "type": "Punctuator", + "value": "(", + }, + Object { + "loc": Object { + "end": Object { + "column": 15, + "line": 1, + }, + "start": Object { + "column": 14, + "line": 1, + }, + }, + "range": Array [ + 14, + 15, + ], + "type": "Identifier", + "value": "x", + }, + Object { + "loc": Object { + "end": Object { + "column": 16, + "line": 1, + }, + "start": Object { + "column": 15, + "line": 1, + }, + }, + "range": Array [ + 15, + 16, + ], + "type": "Punctuator", + "value": ",", + }, + Object { + "loc": Object { + "end": Object { + "column": 18, + "line": 1, + }, + "start": Object { + "column": 17, + "line": 1, + }, + }, + "range": Array [ + 17, + 18, + ], + "type": "Identifier", + "value": "y", + }, + Object { + "loc": Object { + "end": Object { + "column": 19, + "line": 1, + }, + "start": Object { + "column": 18, + "line": 1, + }, + }, + "range": Array [ + 18, + 19, + ], + "type": "Punctuator", + "value": ",", + }, + Object { + "loc": Object { + "end": Object { + "column": 21, + "line": 1, + }, + "start": Object { + "column": 20, + "line": 1, + }, + }, + "range": Array [ + 20, + 21, + ], + "type": "Identifier", + "value": "z", + }, + Object { + "loc": Object { + "end": Object { + "column": 22, + "line": 1, + }, + "start": Object { + "column": 21, + "line": 1, + }, + }, + "range": Array [ + 21, + 22, + ], + "type": "Punctuator", + "value": ")", + }, + Object { + "loc": Object { + "end": Object { + "column": 24, + "line": 1, + }, + "start": Object { + "column": 23, + "line": 1, + }, + }, + "range": Array [ + 23, + 24, + ], + "type": "Punctuator", + "value": "{", + }, + Object { + "loc": Object { + "end": Object { + "column": 8, + "line": 2, + }, + "start": Object { + "column": 2, + "line": 2, + }, + }, + "range": Array [ + 27, + 33, + ], + "type": "Keyword", + "value": "return", + }, + Object { + "loc": Object { + "end": Object { + "column": 10, + "line": 2, + }, + "start": Object { + "column": 9, + "line": 2, + }, + }, + "range": Array [ + 34, + 35, + ], + "type": "Punctuator", + "value": "(", + }, + Object { + "loc": Object { + "end": Object { + "column": 5, + "line": 3, + }, + "start": Object { + "column": 4, + "line": 3, + }, + }, + "range": Array [ + 40, + 41, + ], + "type": "Identifier", + "value": "x", + }, + Object { + "loc": Object { + "end": Object { + "column": 6, + "line": 3, + }, + "start": Object { + "column": 5, + "line": 3, + }, + }, + "range": Array [ + 41, + 42, + ], + "type": "Punctuator", + "value": ",", + }, + Object { + "loc": Object { + "end": Object { + "column": 5, + "line": 4, + }, + "start": Object { + "column": 4, + "line": 4, + }, + }, + "range": Array [ + 47, + 48, + ], + "type": "Identifier", + "value": "y", + }, + Object { + "loc": Object { + "end": Object { + "column": 6, + "line": 4, + }, + "start": Object { + "column": 5, + "line": 4, + }, + }, + "range": Array [ + 48, + 49, + ], + "type": "Punctuator", + "value": ",", + }, + Object { + "loc": Object { + "end": Object { + "column": 5, + "line": 5, + }, + "start": Object { + "column": 4, + "line": 5, + }, + }, + "range": Array [ + 54, + 55, + ], + "type": "Identifier", + "value": "z", + }, + Object { + "loc": Object { + "end": Object { + "column": 3, + "line": 6, + }, + "start": Object { + "column": 2, + "line": 6, + }, + }, + "range": Array [ + 58, + 59, + ], + "type": "Punctuator", + "value": ")", + }, + Object { + "loc": Object { + "end": Object { + "column": 4, + "line": 6, + }, + "start": Object { + "column": 3, + "line": 6, + }, + }, + "range": Array [ + 59, + 60, + ], + "type": "Punctuator", + "value": ";", + }, + Object { + "loc": Object { + "end": Object { + "column": 1, + "line": 7, + }, + "start": Object { + "column": 0, + "line": 7, + }, + }, + "range": Array [ + 61, + 62, + ], + "type": "Punctuator", + "value": "}", + }, + ], + "type": "Program", +} +`; + +exports[`javascript fixtures/function/return-sequence.src 1`] = ` +Object { + "body": Array [ + Object { + "async": false, + "body": Object { + "body": Array [ + Object { + "argument": Object { + "expressions": Array [ + Object { + "loc": Object { + "end": Object { + "column": 11, + "line": 2, + }, + "start": Object { + "column": 10, + "line": 2, + }, + }, + "name": "x", + "range": Array [ + 35, + 36, + ], + "type": "Identifier", + }, + Object { + "loc": Object { + "end": Object { + "column": 14, + "line": 2, + }, + "start": Object { + "column": 13, + "line": 2, + }, + }, + "name": "y", + "range": Array [ + 38, + 39, + ], + "type": "Identifier", + }, + Object { + "loc": Object { + "end": Object { + "column": 17, + "line": 2, + }, + "start": Object { + "column": 16, + "line": 2, + }, + }, + "name": "z", + "range": Array [ + 41, + 42, + ], + "type": "Identifier", + }, + ], + "loc": Object { + "end": Object { + "column": 17, + "line": 2, + }, + "start": Object { + "column": 10, + "line": 2, + }, + }, + "range": Array [ + 35, + 42, + ], + "type": "SequenceExpression", + }, + "loc": Object { + "end": Object { + "column": 19, + "line": 2, + }, + "start": Object { + "column": 2, + "line": 2, + }, + }, + "range": Array [ + 27, + 44, + ], + "type": "ReturnStatement", + }, + ], + "loc": Object { + "end": Object { + "column": 1, + "line": 3, + }, + "start": Object { + "column": 23, + "line": 1, + }, + }, + "range": Array [ + 23, + 46, + ], + "type": "BlockStatement", + }, + "expression": false, + "generator": false, + "id": Object { + "loc": Object { + "end": Object { + "column": 12, + "line": 1, + }, + "start": Object { + "column": 9, + "line": 1, + }, + }, + "name": "foo", + "range": Array [ + 9, + 12, + ], + "type": "Identifier", + }, + "loc": Object { + "end": Object { + "column": 1, + "line": 3, + }, + "start": Object { + "column": 0, + "line": 1, + }, + }, + "params": Array [ + Object { + "loc": Object { + "end": Object { + "column": 15, + "line": 1, + }, + "start": Object { + "column": 14, + "line": 1, + }, + }, + "name": "x", + "range": Array [ + 14, + 15, + ], + "type": "Identifier", + }, + Object { + "loc": Object { + "end": Object { + "column": 18, + "line": 1, + }, + "start": Object { + "column": 17, + "line": 1, + }, + }, + "name": "y", + "range": Array [ + 17, + 18, + ], + "type": "Identifier", + }, + Object { + "loc": Object { + "end": Object { + "column": 21, + "line": 1, + }, + "start": Object { + "column": 20, + "line": 1, + }, + }, + "name": "z", + "range": Array [ + 20, + 21, + ], + "type": "Identifier", + }, + ], + "range": Array [ + 0, + 46, + ], + "type": "FunctionDeclaration", + }, + ], + "loc": Object { + "end": Object { + "column": 0, + "line": 4, + }, + "start": Object { + "column": 0, + "line": 1, + }, + }, + "range": Array [ + 0, + 47, + ], + "sourceType": "script", + "tokens": Array [ + Object { + "loc": Object { + "end": Object { + "column": 8, + "line": 1, + }, + "start": Object { + "column": 0, + "line": 1, + }, + }, + "range": Array [ + 0, + 8, + ], + "type": "Keyword", + "value": "function", + }, + Object { + "loc": Object { + "end": Object { + "column": 12, + "line": 1, + }, + "start": Object { + "column": 9, + "line": 1, + }, + }, + "range": Array [ + 9, + 12, + ], + "type": "Identifier", + "value": "foo", + }, + Object { + "loc": Object { + "end": Object { + "column": 14, + "line": 1, + }, + "start": Object { + "column": 13, + "line": 1, + }, + }, + "range": Array [ + 13, + 14, + ], + "type": "Punctuator", + "value": "(", + }, + Object { + "loc": Object { + "end": Object { + "column": 15, + "line": 1, + }, + "start": Object { + "column": 14, + "line": 1, + }, + }, + "range": Array [ + 14, + 15, + ], + "type": "Identifier", + "value": "x", + }, + Object { + "loc": Object { + "end": Object { + "column": 16, + "line": 1, + }, + "start": Object { + "column": 15, + "line": 1, + }, + }, + "range": Array [ + 15, + 16, + ], + "type": "Punctuator", + "value": ",", + }, + Object { + "loc": Object { + "end": Object { + "column": 18, + "line": 1, + }, + "start": Object { + "column": 17, + "line": 1, + }, + }, + "range": Array [ + 17, + 18, + ], + "type": "Identifier", + "value": "y", + }, + Object { + "loc": Object { + "end": Object { + "column": 19, + "line": 1, + }, + "start": Object { + "column": 18, + "line": 1, + }, + }, + "range": Array [ + 18, + 19, + ], + "type": "Punctuator", + "value": ",", + }, + Object { + "loc": Object { + "end": Object { + "column": 21, + "line": 1, + }, + "start": Object { + "column": 20, + "line": 1, + }, + }, + "range": Array [ + 20, + 21, + ], + "type": "Identifier", + "value": "z", + }, + Object { + "loc": Object { + "end": Object { + "column": 22, + "line": 1, + }, + "start": Object { + "column": 21, + "line": 1, + }, + }, + "range": Array [ + 21, + 22, + ], + "type": "Punctuator", + "value": ")", + }, + Object { + "loc": Object { + "end": Object { + "column": 24, + "line": 1, + }, + "start": Object { + "column": 23, + "line": 1, + }, + }, + "range": Array [ + 23, + 24, + ], + "type": "Punctuator", + "value": "{", + }, + Object { + "loc": Object { + "end": Object { + "column": 8, + "line": 2, + }, + "start": Object { + "column": 2, + "line": 2, + }, + }, + "range": Array [ + 27, + 33, + ], + "type": "Keyword", + "value": "return", + }, + Object { + "loc": Object { + "end": Object { + "column": 10, + "line": 2, + }, + "start": Object { + "column": 9, + "line": 2, + }, + }, + "range": Array [ + 34, + 35, + ], + "type": "Punctuator", + "value": "(", + }, + Object { + "loc": Object { + "end": Object { + "column": 11, + "line": 2, + }, + "start": Object { + "column": 10, + "line": 2, + }, + }, + "range": Array [ + 35, + 36, + ], + "type": "Identifier", + "value": "x", + }, + Object { + "loc": Object { + "end": Object { + "column": 12, + "line": 2, + }, + "start": Object { + "column": 11, + "line": 2, + }, + }, + "range": Array [ + 36, + 37, + ], + "type": "Punctuator", + "value": ",", + }, + Object { + "loc": Object { + "end": Object { + "column": 14, + "line": 2, + }, + "start": Object { + "column": 13, + "line": 2, + }, + }, + "range": Array [ + 38, + 39, + ], + "type": "Identifier", + "value": "y", + }, + Object { + "loc": Object { + "end": Object { + "column": 15, + "line": 2, + }, + "start": Object { + "column": 14, + "line": 2, + }, + }, + "range": Array [ + 39, + 40, + ], + "type": "Punctuator", + "value": ",", + }, + Object { + "loc": Object { + "end": Object { + "column": 17, + "line": 2, + }, + "start": Object { + "column": 16, + "line": 2, + }, + }, + "range": Array [ + 41, + 42, + ], + "type": "Identifier", + "value": "z", + }, + Object { + "loc": Object { + "end": Object { + "column": 18, + "line": 2, + }, + "start": Object { + "column": 17, + "line": 2, + }, + }, + "range": Array [ + 42, + 43, + ], + "type": "Punctuator", + "value": ")", + }, + Object { + "loc": Object { + "end": Object { + "column": 19, + "line": 2, + }, + "start": Object { + "column": 18, + "line": 2, + }, + }, + "range": Array [ + 43, + 44, + ], + "type": "Punctuator", + "value": ";", + }, + Object { + "loc": Object { + "end": Object { + "column": 1, + "line": 3, + }, + "start": Object { + "column": 0, + "line": 3, + }, + }, + "range": Array [ + 45, + 46, + ], + "type": "Punctuator", + "value": "}", + }, + ], + "type": "Program", +} +`; + exports[`javascript fixtures/generators/anonymous-generator.src 1`] = ` Object { "body": Array [ diff --git a/packages/typescript-estree/tests/lib/__snapshots__/semantic-diagnostics-enabled.ts.snap b/packages/typescript-estree/tests/lib/__snapshots__/semantic-diagnostics-enabled.ts.snap index e680cb92473c..1db62d5b9140 100644 --- a/packages/typescript-estree/tests/lib/__snapshots__/semantic-diagnostics-enabled.ts.snap +++ b/packages/typescript-estree/tests/lib/__snapshots__/semantic-diagnostics-enabled.ts.snap @@ -739,6 +739,10 @@ exports[`Parse all fixtures with "errorOnTypeScriptSyntacticAndSemanticIssues" e exports[`Parse all fixtures with "errorOnTypeScriptSyntacticAndSemanticIssues" enabled fixtures/javascript/forOf/invalid-for-of-with-let-and-no-braces.src 1`] = `"TEST OUTPUT: No semantic or syntactic issues found"`; +exports[`Parse all fixtures with "errorOnTypeScriptSyntacticAndSemanticIssues" enabled fixtures/javascript/function/return-multiline-sequence.src 1`] = `"TEST OUTPUT: No semantic or syntactic issues found"`; + +exports[`Parse all fixtures with "errorOnTypeScriptSyntacticAndSemanticIssues" enabled fixtures/javascript/function/return-sequence.src 1`] = `"TEST OUTPUT: No semantic or syntactic issues found"`; + exports[`Parse all fixtures with "errorOnTypeScriptSyntacticAndSemanticIssues" enabled fixtures/javascript/generators/anonymous-generator.src 1`] = `"TEST OUTPUT: No semantic or syntactic issues found"`; exports[`Parse all fixtures with "errorOnTypeScriptSyntacticAndSemanticIssues" enabled fixtures/javascript/generators/async-generator-function.src 1`] = `"TEST OUTPUT: No semantic or syntactic issues found"`; @@ -1887,6 +1891,8 @@ Object { } `; +exports[`Parse all fixtures with "errorOnTypeScriptSyntacticAndSemanticIssues" enabled fixtures/typescript/basics/arrow-function-with-optional-parameter.src 1`] = `"TEST OUTPUT: No semantic or syntactic issues found"`; + exports[`Parse all fixtures with "errorOnTypeScriptSyntacticAndSemanticIssues" enabled fixtures/typescript/basics/arrow-function-with-type-parameters.src 1`] = `"TEST OUTPUT: No semantic or syntactic issues found"`; exports[`Parse all fixtures with "errorOnTypeScriptSyntacticAndSemanticIssues" enabled fixtures/typescript/basics/async-function-expression.src 1`] = `"TEST OUTPUT: No semantic or syntactic issues found"`; diff --git a/packages/typescript-estree/tests/lib/__snapshots__/typescript.ts.snap b/packages/typescript-estree/tests/lib/__snapshots__/typescript.ts.snap index c5085cf91009..b807e63a8220 100644 --- a/packages/typescript-estree/tests/lib/__snapshots__/typescript.ts.snap +++ b/packages/typescript-estree/tests/lib/__snapshots__/typescript.ts.snap @@ -3106,6 +3106,397 @@ Object { } `; +exports[`typescript fixtures/basics/arrow-function-with-optional-parameter.src 1`] = ` +Object { + "body": Array [ + Object { + "expression": Object { + "arguments": Array [], + "callee": Object { + "async": false, + "body": Object { + "left": Object { + "loc": Object { + "end": Object { + "column": 10, + "line": 1, + }, + "start": Object { + "column": 9, + "line": 1, + }, + }, + "name": "k", + "range": Array [ + 9, + 10, + ], + "type": "Identifier", + }, + "loc": Object { + "end": Object { + "column": 14, + "line": 1, + }, + "start": Object { + "column": 9, + "line": 1, + }, + }, + "operator": "+", + "range": Array [ + 9, + 14, + ], + "right": Object { + "loc": Object { + "end": Object { + "column": 14, + "line": 1, + }, + "start": Object { + "column": 13, + "line": 1, + }, + }, + "range": Array [ + 13, + 14, + ], + "raw": "1", + "type": "Literal", + "value": 1, + }, + "type": "BinaryExpression", + }, + "expression": true, + "generator": false, + "id": null, + "loc": Object { + "end": Object { + "column": 14, + "line": 1, + }, + "start": Object { + "column": 1, + "line": 1, + }, + }, + "params": Array [ + Object { + "loc": Object { + "end": Object { + "column": 4, + "line": 1, + }, + "start": Object { + "column": 2, + "line": 1, + }, + }, + "name": "k", + "optional": true, + "range": Array [ + 2, + 4, + ], + "type": "Identifier", + }, + ], + "range": Array [ + 1, + 14, + ], + "type": "ArrowFunctionExpression", + }, + "loc": Object { + "end": Object { + "column": 17, + "line": 1, + }, + "start": Object { + "column": 0, + "line": 1, + }, + }, + "range": Array [ + 0, + 17, + ], + "type": "CallExpression", + }, + "loc": Object { + "end": Object { + "column": 18, + "line": 1, + }, + "start": Object { + "column": 0, + "line": 1, + }, + }, + "range": Array [ + 0, + 18, + ], + "type": "ExpressionStatement", + }, + ], + "loc": Object { + "end": Object { + "column": 0, + "line": 2, + }, + "start": Object { + "column": 0, + "line": 1, + }, + }, + "range": Array [ + 0, + 19, + ], + "sourceType": "script", + "tokens": Array [ + Object { + "loc": Object { + "end": Object { + "column": 1, + "line": 1, + }, + "start": Object { + "column": 0, + "line": 1, + }, + }, + "range": Array [ + 0, + 1, + ], + "type": "Punctuator", + "value": "(", + }, + Object { + "loc": Object { + "end": Object { + "column": 2, + "line": 1, + }, + "start": Object { + "column": 1, + "line": 1, + }, + }, + "range": Array [ + 1, + 2, + ], + "type": "Punctuator", + "value": "(", + }, + Object { + "loc": Object { + "end": Object { + "column": 3, + "line": 1, + }, + "start": Object { + "column": 2, + "line": 1, + }, + }, + "range": Array [ + 2, + 3, + ], + "type": "Identifier", + "value": "k", + }, + Object { + "loc": Object { + "end": Object { + "column": 4, + "line": 1, + }, + "start": Object { + "column": 3, + "line": 1, + }, + }, + "range": Array [ + 3, + 4, + ], + "type": "Punctuator", + "value": "?", + }, + Object { + "loc": Object { + "end": Object { + "column": 5, + "line": 1, + }, + "start": Object { + "column": 4, + "line": 1, + }, + }, + "range": Array [ + 4, + 5, + ], + "type": "Punctuator", + "value": ")", + }, + Object { + "loc": Object { + "end": Object { + "column": 8, + "line": 1, + }, + "start": Object { + "column": 6, + "line": 1, + }, + }, + "range": Array [ + 6, + 8, + ], + "type": "Punctuator", + "value": "=>", + }, + Object { + "loc": Object { + "end": Object { + "column": 10, + "line": 1, + }, + "start": Object { + "column": 9, + "line": 1, + }, + }, + "range": Array [ + 9, + 10, + ], + "type": "Identifier", + "value": "k", + }, + Object { + "loc": Object { + "end": Object { + "column": 12, + "line": 1, + }, + "start": Object { + "column": 11, + "line": 1, + }, + }, + "range": Array [ + 11, + 12, + ], + "type": "Punctuator", + "value": "+", + }, + Object { + "loc": Object { + "end": Object { + "column": 14, + "line": 1, + }, + "start": Object { + "column": 13, + "line": 1, + }, + }, + "range": Array [ + 13, + 14, + ], + "type": "Numeric", + "value": "1", + }, + Object { + "loc": Object { + "end": Object { + "column": 15, + "line": 1, + }, + "start": Object { + "column": 14, + "line": 1, + }, + }, + "range": Array [ + 14, + 15, + ], + "type": "Punctuator", + "value": ")", + }, + Object { + "loc": Object { + "end": Object { + "column": 16, + "line": 1, + }, + "start": Object { + "column": 15, + "line": 1, + }, + }, + "range": Array [ + 15, + 16, + ], + "type": "Punctuator", + "value": "(", + }, + Object { + "loc": Object { + "end": Object { + "column": 17, + "line": 1, + }, + "start": Object { + "column": 16, + "line": 1, + }, + }, + "range": Array [ + 16, + 17, + ], + "type": "Punctuator", + "value": ")", + }, + Object { + "loc": Object { + "end": Object { + "column": 18, + "line": 1, + }, + "start": Object { + "column": 17, + "line": 1, + }, + }, + "range": Array [ + 17, + 18, + ], + "type": "Punctuator", + "value": ";", + }, + ], + "type": "Program", +} +`; + exports[`typescript fixtures/basics/arrow-function-with-type-parameters.src 1`] = ` Object { "body": Array [ From 5e1600308d7121fd986181cc8db589c9573d0d31 Mon Sep 17 00:00:00 2001 From: Armano Date: Sun, 27 Jan 2019 18:06:26 +0100 Subject: [PATCH 07/13] fix(parser): add visiting of type parameters in JSXOpeningElement (#150) --- .../tests/lib/rules/no-unused-vars.js | 15 +- packages/parser/src/analyze-scope.ts | 9 + packages/parser/src/visitor-keys.ts | 7 + .../fixtures/scope-analysis/import-keyword.ts | 1 + .../scope-analysis/typed-jsx-element.tsx | 1 + .../lib/__snapshots__/scope-analysis.ts.snap | 312 ++++++++++++++++++ packages/parser/tests/lib/scope-analysis.ts | 8 +- packages/parser/tests/lib/visitor-keys.ts | 28 ++ packages/typescript-estree/package.json | 1 + 9 files changed, 379 insertions(+), 3 deletions(-) create mode 100644 packages/parser/tests/fixtures/scope-analysis/import-keyword.ts create mode 100644 packages/parser/tests/fixtures/scope-analysis/typed-jsx-element.tsx create mode 100644 packages/parser/tests/lib/visitor-keys.ts diff --git a/packages/eslint-plugin/tests/lib/rules/no-unused-vars.js b/packages/eslint-plugin/tests/lib/rules/no-unused-vars.js index 726f755c3956..2fe854b2c442 100644 --- a/packages/eslint-plugin/tests/lib/rules/no-unused-vars.js +++ b/packages/eslint-plugin/tests/lib/rules/no-unused-vars.js @@ -557,7 +557,20 @@ export interface Bar extends foo.i18n {} import foo from 'foo'; import bar from 'foo'; export interface Bar extends foo.i18n {} - ` + `, + // https://github.com/typescript-eslint/typescript-eslint/issues/141 + { + filename: 'test.tsx', + code: ` +import { TypeA } from './interface'; +export const a = />; + `, + parserOptions: { + ecmaFeatures: { + jsx: true + } + } + } ], invalid: [ diff --git a/packages/parser/src/analyze-scope.ts b/packages/parser/src/analyze-scope.ts index dc17e977683b..eb9f3c92c752 100644 --- a/packages/parser/src/analyze-scope.ts +++ b/packages/parser/src/analyze-scope.ts @@ -235,6 +235,15 @@ class Referencer extends OriginalReferencer { } } + /** + * Override. + */ + JSXOpeningElement(node: any) { + this.visit(node.name); + this.visitTypeParameters(node); + this.visit(node.attributes); + } + /** * Override. * Don't create the reference object in the type mode. diff --git a/packages/parser/src/visitor-keys.ts b/packages/parser/src/visitor-keys.ts index d1dd5e616aeb..d3938529e820 100644 --- a/packages/parser/src/visitor-keys.ts +++ b/packages/parser/src/visitor-keys.ts @@ -1,6 +1,8 @@ import eslintVisitorKeys from 'eslint-visitor-keys'; export const visitorKeys = eslintVisitorKeys.unionWith({ + // Additional estree nodes. + Import: [], // Additional Properties. ArrayPattern: ['elements', 'typeAnnotation'], ArrowFunctionExpression: ['typeParameters', 'params', 'returnType', 'body'], @@ -30,6 +32,11 @@ export const visitorKeys = eslintVisitorKeys.unionWith({ RestElement: ['argument', 'typeAnnotation'], NewExpression: ['callee', 'typeParameters', 'arguments'], CallExpression: ['callee', 'typeParameters', 'arguments'], + // JSX + JSXOpeningElement: ['name', 'typeParameters', 'attributes'], + JSXClosingFragment: [], + JSXOpeningFragment: [], + JSXSpreadChild: ['expression'], // Additional Nodes. BigIntLiteral: [], diff --git a/packages/parser/tests/fixtures/scope-analysis/import-keyword.ts b/packages/parser/tests/fixtures/scope-analysis/import-keyword.ts new file mode 100644 index 000000000000..3beea868f04b --- /dev/null +++ b/packages/parser/tests/fixtures/scope-analysis/import-keyword.ts @@ -0,0 +1 @@ +import('test'); diff --git a/packages/parser/tests/fixtures/scope-analysis/typed-jsx-element.tsx b/packages/parser/tests/fixtures/scope-analysis/typed-jsx-element.tsx new file mode 100644 index 000000000000..29158b30c8dc --- /dev/null +++ b/packages/parser/tests/fixtures/scope-analysis/typed-jsx-element.tsx @@ -0,0 +1 @@ +const a = />; diff --git a/packages/parser/tests/lib/__snapshots__/scope-analysis.ts.snap b/packages/parser/tests/lib/__snapshots__/scope-analysis.ts.snap index 0644b066632e..8fd73916d216 100644 --- a/packages/parser/tests/lib/__snapshots__/scope-analysis.ts.snap +++ b/packages/parser/tests/lib/__snapshots__/scope-analysis.ts.snap @@ -5225,6 +5225,56 @@ Object { } `; +exports[`TypeScript scope analysis sourceType: module tests/fixtures/scope-analysis/import-keyword.ts 1`] = ` +Object { + "$id": 1, + "block": Object { + "range": Array [ + 0, + 16, + ], + "type": "Program", + }, + "childScopes": Array [ + Object { + "$id": 0, + "block": Object { + "range": Array [ + 0, + 16, + ], + "type": "Program", + }, + "childScopes": Array [], + "functionExpressionScope": false, + "isStrict": true, + "references": Array [], + "throughReferences": Array [], + "type": "module", + "upperScope": Object { + "$ref": 1, + }, + "variableMap": Object {}, + "variableScope": Object { + "$ref": 0, + }, + "variables": Array [], + }, + ], + "functionExpressionScope": false, + "isStrict": false, + "references": Array [], + "throughReferences": Array [], + "type": "global", + "upperScope": null, + "variableMap": Object {}, + "variableScope": Object { + "$ref": 1, + }, + "variables": Array [], +} +`; + exports[`TypeScript scope analysis sourceType: module tests/fixtures/scope-analysis/interface-type.ts 1`] = ` Object { "$id": 1, @@ -6822,6 +6872,137 @@ Object { } `; +exports[`TypeScript scope analysis sourceType: module tests/fixtures/scope-analysis/typed-jsx-element.tsx 1`] = ` +Object { + "$id": 3, + "block": Object { + "range": Array [ + 0, + 39, + ], + "type": "Program", + }, + "childScopes": Array [ + Object { + "$id": 2, + "block": Object { + "range": Array [ + 0, + 39, + ], + "type": "Program", + }, + "childScopes": Array [], + "functionExpressionScope": false, + "isStrict": true, + "references": Array [ + Object { + "$id": 1, + "from": Object { + "$ref": 2, + }, + "identifier": Object { + "name": "a", + "range": Array [ + 6, + 7, + ], + "type": "Identifier", + }, + "kind": "w", + "resolved": Object { + "$ref": 0, + }, + "writeExpr": Object { + "range": Array [ + 10, + 37, + ], + "type": "JSXElement", + }, + }, + ], + "throughReferences": Array [], + "type": "module", + "upperScope": Object { + "$ref": 3, + }, + "variableMap": Object { + "a": Object { + "$ref": 0, + }, + }, + "variableScope": Object { + "$ref": 2, + }, + "variables": Array [ + Object { + "$id": 0, + "defs": Array [ + Object { + "name": Object { + "name": "a", + "range": Array [ + 6, + 7, + ], + "type": "Identifier", + }, + "node": Object { + "range": Array [ + 6, + 37, + ], + "type": "VariableDeclarator", + }, + "parent": Object { + "range": Array [ + 0, + 38, + ], + "type": "VariableDeclaration", + }, + "type": "Variable", + }, + ], + "eslintUsed": undefined, + "identifiers": Array [ + Object { + "name": "a", + "range": Array [ + 6, + 7, + ], + "type": "Identifier", + }, + ], + "name": "a", + "references": Array [ + Object { + "$ref": 1, + }, + ], + "scope": Object { + "$ref": 2, + }, + }, + ], + }, + ], + "functionExpressionScope": false, + "isStrict": false, + "references": Array [], + "throughReferences": Array [], + "type": "global", + "upperScope": null, + "variableMap": Object {}, + "variableScope": Object { + "$ref": 3, + }, + "variables": Array [], +} +`; + exports[`TypeScript scope analysis sourceType: module tests/fixtures/scope-analysis/typeof.ts 1`] = ` Object { "$id": 4, @@ -15395,6 +15576,31 @@ Object { } `; +exports[`TypeScript scope analysis sourceType: script tests/fixtures/scope-analysis/import-keyword.ts 1`] = ` +Object { + "$id": 0, + "block": Object { + "range": Array [ + 0, + 16, + ], + "type": "Program", + }, + "childScopes": Array [], + "functionExpressionScope": false, + "isStrict": false, + "references": Array [], + "throughReferences": Array [], + "type": "global", + "upperScope": null, + "variableMap": Object {}, + "variableScope": Object { + "$ref": 0, + }, + "variables": Array [], +} +`; + exports[`TypeScript scope analysis sourceType: script tests/fixtures/scope-analysis/interface-type.ts 1`] = ` Object { "$id": 0, @@ -16775,6 +16981,112 @@ Object { } `; +exports[`TypeScript scope analysis sourceType: script tests/fixtures/scope-analysis/typed-jsx-element.tsx 1`] = ` +Object { + "$id": 2, + "block": Object { + "range": Array [ + 0, + 39, + ], + "type": "Program", + }, + "childScopes": Array [], + "functionExpressionScope": false, + "isStrict": false, + "references": Array [ + Object { + "$id": 1, + "from": Object { + "$ref": 2, + }, + "identifier": Object { + "name": "a", + "range": Array [ + 6, + 7, + ], + "type": "Identifier", + }, + "kind": "w", + "resolved": Object { + "$ref": 0, + }, + "writeExpr": Object { + "range": Array [ + 10, + 37, + ], + "type": "JSXElement", + }, + }, + ], + "throughReferences": Array [], + "type": "global", + "upperScope": null, + "variableMap": Object { + "a": Object { + "$ref": 0, + }, + }, + "variableScope": Object { + "$ref": 2, + }, + "variables": Array [ + Object { + "$id": 0, + "defs": Array [ + Object { + "name": Object { + "name": "a", + "range": Array [ + 6, + 7, + ], + "type": "Identifier", + }, + "node": Object { + "range": Array [ + 6, + 37, + ], + "type": "VariableDeclarator", + }, + "parent": Object { + "range": Array [ + 0, + 38, + ], + "type": "VariableDeclaration", + }, + "type": "Variable", + }, + ], + "eslintUsed": undefined, + "identifiers": Array [ + Object { + "name": "a", + "range": Array [ + 6, + 7, + ], + "type": "Identifier", + }, + ], + "name": "a", + "references": Array [ + Object { + "$ref": 1, + }, + ], + "scope": Object { + "$ref": 2, + }, + }, + ], +} +`; + exports[`TypeScript scope analysis sourceType: script tests/fixtures/scope-analysis/typeof.ts 1`] = ` Object { "$id": 3, diff --git a/packages/parser/tests/lib/scope-analysis.ts b/packages/parser/tests/lib/scope-analysis.ts index 8eec626225f1..b8eafccc63e9 100644 --- a/packages/parser/tests/lib/scope-analysis.ts +++ b/packages/parser/tests/lib/scope-analysis.ts @@ -159,7 +159,9 @@ describe('TypeScript scope analysis', () => { range: true, tokens: true, sourceType: 'module', - ecmaFeatures: {} + ecmaFeatures: { + jsx: path.extname(filePath) === '.tsx' + } }); const { globalScope } = scopeManager; @@ -191,7 +193,9 @@ describe('TypeScript scope analysis', () => { range: true, tokens: true, sourceType: 'script', - ecmaFeatures: {} + ecmaFeatures: { + jsx: path.extname(filePath) === '.tsx' + } }); const { globalScope } = scopeManager; diff --git a/packages/parser/tests/lib/visitor-keys.ts b/packages/parser/tests/lib/visitor-keys.ts new file mode 100644 index 000000000000..00fcde2a005e --- /dev/null +++ b/packages/parser/tests/lib/visitor-keys.ts @@ -0,0 +1,28 @@ +import { AST_NODE_TYPES } from '@typescript-eslint/typescript-estree'; +import { visitorKeys } from '../../src/visitor-keys'; + +//------------------------------------------------------------------------------ +// Setup +//------------------------------------------------------------------------------ + +const astTypes = Object.keys(AST_NODE_TYPES); +astTypes.push('TSEmptyBodyFunctionExpression'); // node created by parser.ts + +//------------------------------------------------------------------------------ +// Tests +//------------------------------------------------------------------------------ + +describe('visitor-keys', () => { + for (const type of astTypes) { + it(`type ${type} should be present in visitor-keys`, () => { + expect(visitorKeys).toHaveProperty(type); + }); + } + + it('check if there is no deprecated TS nodes', () => { + const TSTypes = Object.keys(visitorKeys).filter(type => + type.startsWith('TS') + ); + expect(astTypes).toEqual(expect.arrayContaining(TSTypes)); + }); +}); diff --git a/packages/typescript-estree/package.json b/packages/typescript-estree/package.json index a8490f513a68..3d112005adce 100644 --- a/packages/typescript-estree/package.json +++ b/packages/typescript-estree/package.json @@ -3,6 +3,7 @@ "version": "1.1.0", "description": "A parser that converts TypeScript source code into an ESTree compatible form", "main": "dist/parser.js", + "types": "dist/parser.d.ts", "files": [ "dist", "README.md", From bdf880bc2c7817852e542fb926a7fa6510c2db69 Mon Sep 17 00:00:00 2001 From: Adam Fields Date: Sun, 27 Jan 2019 12:12:45 -0500 Subject: [PATCH 08/13] chore: update peer dependencies and node engines (#151) --- packages/eslint-plugin-tslint/package.json | 3 ++- packages/eslint-plugin/package.json | 4 ++-- packages/parser/package.json | 4 ++-- 3 files changed, 6 insertions(+), 5 deletions(-) diff --git a/packages/eslint-plugin-tslint/package.json b/packages/eslint-plugin-tslint/package.json index fbe9ea5521e0..d8aeedf6ef0e 100644 --- a/packages/eslint-plugin-tslint/package.json +++ b/packages/eslint-plugin-tslint/package.json @@ -11,7 +11,7 @@ "tslint" ], "engines": { - "node": ">=6" + "node": "^6.14.0 || ^8.10.0 || >=9.10.0" }, "repository": "typescript-eslint/typescript-eslint", "bugs": { @@ -28,6 +28,7 @@ "lodash.memoize": "^4.1.2" }, "peerDependencies": { + "eslint": "^5.0.0", "tslint": "^5.0.0" }, "devDependencies": { diff --git a/packages/eslint-plugin/package.json b/packages/eslint-plugin/package.json index 7cd6f21b1ab3..7d414aa3576d 100644 --- a/packages/eslint-plugin/package.json +++ b/packages/eslint-plugin/package.json @@ -9,7 +9,7 @@ "typescript" ], "engines": { - "node": ">=6" + "node": "^6.14.0 || ^8.10.0 || >=9.10.0" }, "repository": "typescript-eslint/typescript-eslint", "bugs": { @@ -32,7 +32,7 @@ "eslint-docs": "^0.2.6" }, "peerDependencies": { - "eslint": ">=4.13.1 < 6", + "eslint": "^5.0.0", "typescript": "~3.2.1" } } diff --git a/packages/parser/package.json b/packages/parser/package.json index 23fe47afce3f..2ba2e642ebd9 100644 --- a/packages/parser/package.json +++ b/packages/parser/package.json @@ -9,7 +9,7 @@ "LICENSE" ], "engines": { - "node": ">=6.14.0" + "node": "^6.14.0 || ^8.10.0 || >=9.10.0" }, "repository": "typescript-eslint/typescript-eslint", "bugs": { @@ -32,7 +32,7 @@ "test": "jest --coverage" }, "peerDependencies": { - "eslint": ">=4.19.1", + "eslint": "^5.0.0", "typescript": "*" }, "dependencies": { From 4954ed2c476bf9654ffe020b587fd6691a985d01 Mon Sep 17 00:00:00 2001 From: Armano Date: Sun, 27 Jan 2019 18:18:11 +0100 Subject: [PATCH 09/13] refactor(ts-estree): simplify methods location calculation (#152) --- packages/typescript-estree/src/convert.ts | 66 ++++++-------------- packages/typescript-estree/src/node-utils.ts | 56 +++++++---------- 2 files changed, 39 insertions(+), 83 deletions(-) diff --git a/packages/typescript-estree/src/convert.ts b/packages/typescript-estree/src/convert.ts index ff365b187c7e..bc9e209f23ed 100644 --- a/packages/typescript-estree/src/convert.ts +++ b/packages/typescript-estree/src/convert.ts @@ -23,10 +23,10 @@ import { isComma, getBinaryExpressionType, isOptional, - findFirstMatchingToken, unescapeStringLiteralText, getDeclarationKind, - getLastModifier + getLastModifier, + getLineAndCharacterFor } from './node-utils'; import { AST_NODE_TYPES } from './ast-node-types'; import { ESTreeNode } from './temp-types-based-on-js-source'; @@ -858,38 +858,19 @@ export default function convert(config: ConvertConfig): ESTreeNode | null { case SyntaxKind.GetAccessor: case SyntaxKind.SetAccessor: case SyntaxKind.MethodDeclaration: { - const openingParen = findFirstMatchingToken( - node.name, - ast, - (token: any) => { - if (!token || !token.kind) { - return false; - } - return getTextForTokenKind(token.kind) === '('; - }, - ast - ); - - const methodLoc = ast.getLineAndCharacterOfPosition( - (openingParen as any).getStart(ast) - ), - nodeIsMethod = node.kind === SyntaxKind.MethodDeclaration, - method: ESTreeNode = { - type: AST_NODE_TYPES.FunctionExpression, - id: null, - generator: !!node.asteriskToken, - expression: false, // ESTreeNode as ESTreeNode here - async: hasModifier(SyntaxKind.AsyncKeyword, node), - body: convertChild(node.body), - range: [node.parameters.pos - 1, result.range[1]], - loc: { - start: { - line: methodLoc.line + 1, - column: methodLoc.character - }, - end: result.loc.end - } - } as any; + const method: ESTreeNode = { + type: AST_NODE_TYPES.FunctionExpression, + id: null, + generator: !!node.asteriskToken, + expression: false, // ESTreeNode as ESTreeNode here + async: hasModifier(SyntaxKind.AsyncKeyword, node), + body: convertChild(node.body), + range: [node.parameters.pos - 1, result.range[1]], + loc: { + start: getLineAndCharacterFor(node.parameters.pos - 1, ast), + end: result.loc.end + } + } as any; if (node.type) { (method as any).returnType = convertTypeAnnotation(node.type); @@ -903,7 +884,7 @@ export default function convert(config: ConvertConfig): ESTreeNode | null { key: convertChild(node.name), value: method, computed: isComputedProperty(node.name), - method: nodeIsMethod, + method: node.kind === SyntaxKind.MethodDeclaration, shorthand: false, kind: 'init' }); @@ -992,10 +973,6 @@ export default function convert(config: ConvertConfig): ESTreeNode | null { constructorToken.end ]; - const constructorLoc = ast.getLineAndCharacterOfPosition( - node.parameters.pos - 1 - ); - const constructor: ESTreeNode = { type: AST_NODE_TYPES.FunctionExpression, id: null, @@ -1006,10 +983,7 @@ export default function convert(config: ConvertConfig): ESTreeNode | null { body: convertChild(node.body), range: [node.parameters.pos - 1, result.range[1]], loc: { - start: { - line: constructorLoc.line + 1, - column: constructorLoc.character - }, + start: getLineAndCharacterFor(node.parameters.pos - 1, ast), end: result.loc.end } } as any; @@ -1906,16 +1880,12 @@ export default function convert(config: ConvertConfig): ESTreeNode | null { break; case SyntaxKind.JsxExpression: { - const eloc = ast.getLineAndCharacterOfPosition(result.range[0] + 1); const expression = node.expression ? convertChild(node.expression) : { type: AST_NODE_TYPES.JSXEmptyExpression, loc: { - start: { - line: eloc.line + 1, - column: eloc.character - }, + start: getLineAndCharacterFor(result.range[0] + 1, ast), end: { line: result.loc.end.line, column: result.loc.end.column - 1 diff --git a/packages/typescript-estree/src/node-utils.ts b/packages/typescript-estree/src/node-utils.ts index c844cf7ed20d..d79353f755e6 100644 --- a/packages/typescript-estree/src/node-utils.ts +++ b/packages/typescript-estree/src/node-utils.ts @@ -9,7 +9,8 @@ import unescape from 'lodash.unescape'; import { ESTreeNodeLoc, ESTreeNode, - ESTreeToken + ESTreeToken, + LineAndColumnData } from './temp-types-based-on-js-source'; import { AST_NODE_TYPES } from './ast-node-types'; @@ -219,6 +220,23 @@ export function getBinaryExpressionType( return AST_NODE_TYPES.BinaryExpression; } +/** + * Returns line and column data for the given positions, + * @param pos position to check + * @param ast the AST object + * @returns line and column + */ +export function getLineAndCharacterFor( + pos: number, + ast: ts.SourceFile +): LineAndColumnData { + const loc = ast.getLineAndCharacterOfPosition(pos); + return { + line: loc.line + 1, + column: loc.character + }; +} + /** * Returns line and column data for the given start and end positions, * for the given AST @@ -232,18 +250,9 @@ export function getLocFor( end: number, ast: ts.SourceFile ): ESTreeNodeLoc { - const startLoc = ast.getLineAndCharacterOfPosition(start), - endLoc = ast.getLineAndCharacterOfPosition(end); - return { - start: { - line: startLoc.line + 1, - column: startLoc.character - }, - end: { - line: endLoc.line + 1, - column: endLoc.character - } + start: getLineAndCharacterFor(start, ast), + end: getLineAndCharacterFor(end, ast) }; } @@ -389,29 +398,6 @@ export function findNextToken( } } -/** - * Find the first matching token based on the given predicate function. - * @param {ts.Node} previousToken The previous ts.Token - * @param {ts.Node} parent The parent ts.Node - * @param {Function} predicate The predicate function to apply to each checked token - * @param {ts.SourceFile} ast The TS AST - * @returns {ts.Node|undefined} a matching ts.Token - */ -export function findFirstMatchingToken( - previousToken: ts.Node | undefined, - parent: ts.Node, - predicate: (node: ts.Node) => boolean, - ast: ts.SourceFile -): ts.Node | undefined { - while (previousToken) { - if (predicate(previousToken)) { - return previousToken; - } - previousToken = findNextToken(previousToken, parent, ast); - } - return undefined; -} - /** * Find the first matching ancestor based on the given predicate function. * @param {ts.Node} node The current ts.Node From e291ec30240b109c19111d1eedb81440f3fa2670 Mon Sep 17 00:00:00 2001 From: Armano Date: Sun, 27 Jan 2019 18:25:35 +0100 Subject: [PATCH 10/13] refactor(ts-estree): remove dead legacy code (#153) --- packages/typescript-estree/src/convert.ts | 16 +--------------- 1 file changed, 1 insertion(+), 15 deletions(-) diff --git a/packages/typescript-estree/src/convert.ts b/packages/typescript-estree/src/convert.ts index bc9e209f23ed..9a7adebc8e2e 100644 --- a/packages/typescript-estree/src/convert.ts +++ b/packages/typescript-estree/src/convert.ts @@ -796,21 +796,7 @@ export default function convert(config: ConvertConfig): ESTreeNode | null { } case SyntaxKind.ComputedPropertyName: - if (parent!.kind === SyntaxKind.ObjectLiteralExpression) { - // TODO: ComputedPropertyName has no name field - Object.assign(result, { - type: AST_NODE_TYPES.Property, - key: convertChild((node as any).name), - value: convertChild((node as any).name), - computed: false, - method: false, - shorthand: true, - kind: 'init' - }); - } else { - return convertChild(node.expression); - } - break; + return convertChild(node.expression); case SyntaxKind.PropertyDeclaration: { const isAbstract = hasModifier(SyntaxKind.AbstractKeyword, node); From 5017c115f232b42285c61ae53dcf531d66a9c4b5 Mon Sep 17 00:00:00 2001 From: ikeryo1182 Date: Tue, 29 Jan 2019 07:42:39 +0700 Subject: [PATCH 11/13] chore: upgrade husky and lint-staged (#144) --- .huskyrc | 8 +++ .lintstagedrc | 6 ++ package.json | 14 +--- yarn.lock | 196 ++++++++++++++++++++++++++++++++++++++++++-------- 4 files changed, 183 insertions(+), 41 deletions(-) create mode 100644 .huskyrc create mode 100644 .lintstagedrc diff --git a/.huskyrc b/.huskyrc new file mode 100644 index 000000000000..a3f3f7002ed4 --- /dev/null +++ b/.huskyrc @@ -0,0 +1,8 @@ +{ + "hooks": { + "pre-commit": [ + "yarn test && lint-staged" + ], + "commit-msg": "commitlint -E HUSKY_GIT_PARAMS" + } +} diff --git a/.lintstagedrc b/.lintstagedrc new file mode 100644 index 000000000000..889b734ac28f --- /dev/null +++ b/.lintstagedrc @@ -0,0 +1,6 @@ +{ + "*.{ts,js,json,md}": [ + "prettier --write", + "git add" + ] +} diff --git a/package.json b/package.json index c7a27e9a643d..18059f7381ed 100644 --- a/package.json +++ b/package.json @@ -21,22 +21,14 @@ "test": "lerna run test --parallel", "build": "lerna run build", "clean": "lerna clean && lerna run clean", - "precommit": "yarn test && lint-staged", "lint": "eslint . --ext .js,.ts", "lint-fix": "eslint . --ext .js,.ts --fix", "cz": "git-cz", - "commitmsg": "commitlint -E GIT_PARAMS", "check-format": "prettier --list-different \"./**/*.{ts,js,json,md}\"", "format": "prettier --write \"./**/*.{ts,js,json,md}\"", "integration-tests": "docker-compose -f tests/integration/docker-compose.yml up", "kill-integration-test-containers": "docker-compose -f tests/integration/docker-compose.yml down -v --rmi local" }, - "lint-staged": { - "*.{ts,js,json,md}": [ - "prettier --write", - "git add" - ] - }, "config": { "commitizen": { "path": "./node_modules/cz-conventional-changelog" @@ -65,13 +57,13 @@ "@types/semver": "^5.5.0", "cz-conventional-changelog": "2.1.0", "eslint": "^5.12.1", - "eslint-plugin-jest": "^22.1.3", "eslint-plugin-eslint-plugin": "^2.0.1", + "eslint-plugin-jest": "^22.1.3", "glob": "7.1.2", - "husky": "0.14.3", + "husky": "^1.3.1", "jest": "23.6.0", "lerna": "^3.10.5", - "lint-staged": "7.3.0", + "lint-staged": "8.1.0", "lodash.isplainobject": "4.0.6", "prettier": "^1.14.3", "rimraf": "^2.6.3", diff --git a/yarn.lock b/yarn.lock index e2d917cdc557..b6a6d614dfc0 100644 --- a/yarn.lock +++ b/yarn.lock @@ -163,6 +163,20 @@ babel-runtime "6.26.0" execa "0.9.0" +"@iamstarkov/listr-update-renderer@0.4.1": + version "0.4.1" + resolved "https://registry.yarnpkg.com/@iamstarkov/listr-update-renderer/-/listr-update-renderer-0.4.1.tgz#d7c48092a2dcf90fd672b6c8b458649cb350c77e" + integrity sha512-IJyxQWsYDEkf8C8QthBn5N8tIUR9V9je6j3sMIpAkonaadjbvxmRC6RAhpa3RKxndhNnU2M6iNbtJwd7usQYIA== + dependencies: + chalk "^1.1.3" + cli-truncate "^0.2.1" + elegant-spinner "^1.0.1" + figures "^1.7.0" + indent-string "^3.0.0" + log-symbols "^1.0.2" + log-update "^2.3.0" + strip-ansi "^3.0.1" + "@lerna/add@3.10.5": version "3.10.5" resolved "https://registry.yarnpkg.com/@lerna/add/-/add-3.10.5.tgz#10dcd1069eee18a84432f826a38d6791af8a2fef" @@ -1618,6 +1632,11 @@ ci-info@^1.5.0: resolved "https://registry.yarnpkg.com/ci-info/-/ci-info-1.6.0.tgz#2ca20dbb9ceb32d4524a683303313f0304b1e497" integrity sha512-vsGdkwSCDpWmP80ncATX7iea5DWQemg1UgCW5J8tqjU3lYw4FBYuj89J0CTVomA7BEfvSZd84GmHko+MxFQU2A== +ci-info@^2.0.0: + version "2.0.0" + resolved "https://registry.yarnpkg.com/ci-info/-/ci-info-2.0.0.tgz#67a9e964be31a51e15e5010d58e6f12834002f46" + integrity sha512-5tK7EtrZ0N+OLFMthtqOj4fI2Jeb88C4CAZPu25LDVUgXJ0A3Js4PMGqrn0JU1W0Mh1/Z8wZzYPxqUrXeBboCQ== + circular-json@^0.3.1: version "0.3.3" resolved "https://registry.yarnpkg.com/circular-json/-/circular-json-0.3.3.tgz#815c99ea84f6809529d2f45791bdf82711352d66" @@ -1919,6 +1938,15 @@ core-util-is@1.0.2, core-util-is@~1.0.0: resolved "https://registry.yarnpkg.com/core-util-is/-/core-util-is-1.0.2.tgz#b5fd54220aa2bc5ab57aab7140c940754503c1a7" integrity sha1-tf1UIgqivFq1eqtxQMlAdUUDwac= +cosmiconfig@5.0.6: + version "5.0.6" + resolved "https://registry.yarnpkg.com/cosmiconfig/-/cosmiconfig-5.0.6.tgz#dca6cf680a0bd03589aff684700858c81abeeb39" + integrity sha512-6DWfizHriCrFWURP1/qyhsiFvYdlJzbCzmtFWh744+KyWsJo5+kPzUZZaMRSSItoYc0pxFX7gEO7ZC1/gN/7AQ== + dependencies: + is-directory "^0.3.1" + js-yaml "^3.9.0" + parse-json "^4.0.0" + cosmiconfig@^4.0.0: version "4.0.0" resolved "https://registry.yarnpkg.com/cosmiconfig/-/cosmiconfig-4.0.0.tgz#760391549580bbd2df1e562bc177b13c290972dc" @@ -1929,7 +1957,7 @@ cosmiconfig@^4.0.0: parse-json "^4.0.0" require-from-string "^2.0.1" -cosmiconfig@^5.0.2: +cosmiconfig@^5.0.2, cosmiconfig@^5.0.7: version "5.0.7" resolved "https://registry.yarnpkg.com/cosmiconfig/-/cosmiconfig-5.0.7.tgz#39826b292ee0d78eda137dfa3173bd1c21a43b04" integrity sha512-PcLqxTKiDmNT6pSpy4N6KtuPwb53W+2tzNvwOZw0WH9N6O0vLIBq0x8aj8Oj75ere4YcGi48bDFCL+3fRJdlNA== @@ -2136,6 +2164,18 @@ define-property@^2.0.2: is-descriptor "^1.0.2" isobject "^3.0.1" +del@^3.0.0: + version "3.0.0" + resolved "https://registry.yarnpkg.com/del/-/del-3.0.0.tgz#53ecf699ffcbcb39637691ab13baf160819766e5" + integrity sha1-U+z2mf/LyzljdpGrE7rxYIGXZuU= + dependencies: + globby "^6.1.0" + is-path-cwd "^1.0.0" + is-path-in-cwd "^1.0.0" + p-map "^1.1.1" + pify "^3.0.0" + rimraf "^2.2.8" + delayed-stream@~1.0.0: version "1.0.0" resolved "https://registry.yarnpkg.com/delayed-stream/-/delayed-stream-1.0.0.tgz#df3ae199acadfb7d440aaae0b29e2272b24ec619" @@ -2304,7 +2344,7 @@ es6-promisify@^5.0.0: dependencies: es6-promise "^4.0.3" -escape-string-regexp@^1.0.2, escape-string-regexp@^1.0.5: +escape-string-regexp@^1.0.2, escape-string-regexp@^1.0.4, escape-string-regexp@^1.0.5: version "1.0.5" resolved "https://registry.yarnpkg.com/escape-string-regexp/-/escape-string-regexp-1.0.5.tgz#1b61c0562190a8dff6ae3bb2cf0200ca130b86d4" integrity sha1-G2HAViGQqN/2rjuyzwIAyhMLhtQ= @@ -2497,7 +2537,7 @@ exec-sh@^0.2.0: dependencies: merge "^1.2.0" -execa@0.9.0, execa@^0.9.0: +execa@0.9.0: version "0.9.0" resolved "https://registry.yarnpkg.com/execa/-/execa-0.9.0.tgz#adb7ce62cf985071f60580deb4a88b9e34712d01" integrity sha512-BbUMBiX4hqiHZUA5+JujIjNb6TyAlp2D5KLheMjMluwOuzcnylDL4AxZYLLn1n2AGB49eSWwyKvvEQoRpnAtmA== @@ -2895,6 +2935,15 @@ functional-red-black-tree@^1.0.1: resolved "https://registry.yarnpkg.com/functional-red-black-tree/-/functional-red-black-tree-1.0.1.tgz#1b0ab3bd553b2a0d6399d29c0e3ea0b252078327" integrity sha1-GwqzvVU7Kg1jmdKcDj6gslIHgyc= +g-status@^2.0.2: + version "2.0.2" + resolved "https://registry.yarnpkg.com/g-status/-/g-status-2.0.2.tgz#270fd32119e8fc9496f066fe5fe88e0a6bc78b97" + integrity sha512-kQoE9qH+T1AHKgSSD0Hkv98bobE90ILQcXAF4wvGgsr7uFqNvwmh8j+Lq3l0RVt3E3HjSbv2B9biEGcEtpHLCA== + dependencies: + arrify "^1.0.1" + matcher "^1.0.0" + simple-git "^1.85.0" + gauge@~2.7.3: version "2.7.4" resolved "https://registry.yarnpkg.com/gauge/-/gauge-2.7.4.tgz#2c03405c7538c39d7eb37b317022e325fb018bf7" @@ -2964,6 +3013,11 @@ get-stdin@^4.0.1: resolved "https://registry.yarnpkg.com/get-stdin/-/get-stdin-4.0.1.tgz#b968c6b0a04384324902e8bf1a5df32579a450fe" integrity sha1-uWjGsKBDhDJJAui/Gl3zJXmkUP4= +get-stdin@^6.0.0: + version "6.0.0" + resolved "https://registry.yarnpkg.com/get-stdin/-/get-stdin-6.0.0.tgz#9e09bf712b360ab9225e812048f71fde9c89657b" + integrity sha512-jp4tHawyV7+fkkSKyvjuLZswblUtz+SQKzSWnBbii16BuZksJlU1wuBYXY75r+duh/llF1ur6oNwi+2ZzjKZ7g== + get-stream@^3.0.0: version "3.0.0" resolved "https://registry.yarnpkg.com/get-stream/-/get-stream-3.0.0.tgz#8e943d1358dc37555054ecbe2edb05aa174ede14" @@ -3102,6 +3156,17 @@ globals@^9.18.0: resolved "https://registry.yarnpkg.com/globals/-/globals-9.18.0.tgz#aa3896b3e69b487f17e31ed2143d69a8e30c2d8a" integrity sha512-S0nG3CLEQiY/ILxqtztTWH/3iRRdyBLw6KMDxnKMchrtbj2OFmehVh0WUCfW3DUrIgx/qFrJPICrq4Z4sTR9UQ== +globby@^6.1.0: + version "6.1.0" + resolved "https://registry.yarnpkg.com/globby/-/globby-6.1.0.tgz#f5a6d70e8395e21c858fb0489d64df02424d506c" + integrity sha1-9abXDoOV4hyFj7BInWTfAkJNUGw= + dependencies: + array-union "^1.0.1" + glob "^7.0.3" + object-assign "^4.0.1" + pify "^2.0.0" + pinkie-promise "^2.0.0" + globby@^8.0.1: version "8.0.2" resolved "https://registry.yarnpkg.com/globby/-/globby-8.0.2.tgz#5697619ccd95c5275dbb2d6faa42087c1a941d8d" @@ -3271,14 +3336,21 @@ humanize-ms@^1.2.1: dependencies: ms "^2.0.0" -husky@0.14.3: - version "0.14.3" - resolved "https://registry.yarnpkg.com/husky/-/husky-0.14.3.tgz#c69ed74e2d2779769a17ba8399b54ce0b63c12c3" - integrity sha512-e21wivqHpstpoiWA/Yi8eFti8E+sQDSS53cpJsPptPs295QTOQR0ZwnHo2TXy1XOpZFD9rPOd3NpmqTK6uMLJA== +husky@^1.3.1: + version "1.3.1" + resolved "https://registry.yarnpkg.com/husky/-/husky-1.3.1.tgz#26823e399300388ca2afff11cfa8a86b0033fae0" + integrity sha512-86U6sVVVf4b5NYSZ0yvv88dRgBSSXXmHaiq5pP4KDj5JVzdwKgBjEtUPOm8hcoytezFwbU+7gotXNhpHdystlg== dependencies: - is-ci "^1.0.10" - normalize-path "^1.0.0" - strip-indent "^2.0.0" + cosmiconfig "^5.0.7" + execa "^1.0.0" + find-up "^3.0.0" + get-stdin "^6.0.0" + is-ci "^2.0.0" + pkg-dir "^3.0.0" + please-upgrade-node "^3.1.1" + read-pkg "^4.0.1" + run-node "^1.0.0" + slash "^2.0.0" iconv-lite@0.4.24, iconv-lite@^0.4.24, iconv-lite@^0.4.4, iconv-lite@~0.4.13: version "0.4.24" @@ -3471,6 +3543,13 @@ is-ci@^1.0.10: dependencies: ci-info "^1.5.0" +is-ci@^2.0.0: + version "2.0.0" + resolved "https://registry.yarnpkg.com/is-ci/-/is-ci-2.0.0.tgz#6bc6334181810e04b5c22b3d589fdca55026404c" + integrity sha512-YfJT7rkpQB0updsdHLGWrvhBJfcfzNNawYDNIyQXJz0IViGf75O8EBPKSdvw2rF+LGCsX4FZ8tcr3b19LcZq4w== + dependencies: + ci-info "^2.0.0" + is-data-descriptor@^0.1.4: version "0.1.4" resolved "https://registry.yarnpkg.com/is-data-descriptor/-/is-data-descriptor-0.1.4.tgz#0b5ee648388e2c860282e793f1856fec3f301b56" @@ -3623,6 +3702,25 @@ is-observable@^1.1.0: dependencies: symbol-observable "^1.1.0" +is-path-cwd@^1.0.0: + version "1.0.0" + resolved "https://registry.yarnpkg.com/is-path-cwd/-/is-path-cwd-1.0.0.tgz#d225ec23132e89edd38fda767472e62e65f1106d" + integrity sha1-0iXsIxMuie3Tj9p2dHLmLmXxEG0= + +is-path-in-cwd@^1.0.0: + version "1.0.1" + resolved "https://registry.yarnpkg.com/is-path-in-cwd/-/is-path-in-cwd-1.0.1.tgz#5ac48b345ef675339bd6c7a48a912110b241cf52" + integrity sha512-FjV1RTW48E7CWM7eE/J2NJvAEEVektecDBVBE5Hh3nM1Jd0kvhHtX68Pr3xsDf857xt3Y4AkwVULK1Vku62aaQ== + dependencies: + is-path-inside "^1.0.0" + +is-path-inside@^1.0.0: + version "1.0.1" + resolved "https://registry.yarnpkg.com/is-path-inside/-/is-path-inside-1.0.1.tgz#8ef5b7de50437a3fdca6b4e865ef7aa55cb48036" + integrity sha1-jvW33lBDej/cprToZe96pVy0gDY= + dependencies: + path-is-inside "^1.0.1" + is-plain-obj@^1.0.0, is-plain-obj@^1.1.0: version "1.1.0" resolved "https://registry.yarnpkg.com/is-plain-obj/-/is-plain-obj-1.1.0.tgz#71a50c8429dfca773c92a390a4a03b39fcd51d3e" @@ -4417,22 +4515,25 @@ libnpmteam@^1.0.1: get-stream "^4.0.0" npm-registry-fetch "^3.8.0" -lint-staged@7.3.0: - version "7.3.0" - resolved "https://registry.yarnpkg.com/lint-staged/-/lint-staged-7.3.0.tgz#90ff33e5ca61ed3dbac35b6f6502dbefdc0db58d" - integrity sha512-AXk40M9DAiPi7f4tdJggwuKIViUplYtVj1os1MVEteW7qOkU50EOehayCfO9TsoGK24o/EsWb41yrEgfJDDjCw== +lint-staged@8.1.0: + version "8.1.0" + resolved "https://registry.yarnpkg.com/lint-staged/-/lint-staged-8.1.0.tgz#dbc3ae2565366d8f20efb9f9799d076da64863f2" + integrity sha512-yfSkyJy7EuVsaoxtUSEhrD81spdJOe/gMTGea3XaV7HyoRhTb9Gdlp6/JppRZERvKSEYXP9bjcmq6CA5oL2lYQ== dependencies: + "@iamstarkov/listr-update-renderer" "0.4.1" chalk "^2.3.1" commander "^2.14.1" - cosmiconfig "^5.0.2" + cosmiconfig "5.0.6" debug "^3.1.0" dedent "^0.7.0" - execa "^0.9.0" + del "^3.0.0" + execa "^1.0.0" find-parent-dir "^0.3.0" + g-status "^2.0.2" is-glob "^4.0.0" is-windows "^1.0.2" jest-validate "^23.5.0" - listr "^0.14.1" + listr "^0.14.2" lodash "^4.17.5" log-symbols "^2.2.0" micromatch "^3.1.8" @@ -4441,7 +4542,7 @@ lint-staged@7.3.0: path-is-inside "^1.0.2" pify "^3.0.0" please-upgrade-node "^3.0.2" - staged-git-files "1.1.1" + staged-git-files "1.1.2" string-argv "^0.0.2" stringify-object "^3.2.2" @@ -4474,7 +4575,7 @@ listr-verbose-renderer@^0.5.0: date-fns "^1.27.2" figures "^2.0.0" -listr@^0.14.1: +listr@^0.14.2: version "0.14.3" resolved "https://registry.yarnpkg.com/listr/-/listr-0.14.3.tgz#2fea909604e434be464c50bddba0d496928fa586" integrity sha512-RmAl7su35BFd/xoMamRjpIE4j3v+L28o8CT5YhAXQJm1fD+1l9ngXY8JAQRJ+tFK2i5njvi0iRUKV09vPwA0iA== @@ -4712,6 +4813,13 @@ map-visit@^1.0.0: dependencies: object-visit "^1.0.0" +matcher@^1.0.0: + version "1.1.1" + resolved "https://registry.yarnpkg.com/matcher/-/matcher-1.1.1.tgz#51d8301e138f840982b338b116bb0c09af62c1c2" + integrity sha512-+BmqxWIubKTRKNWx/ahnCkk3mG8m7OturVlqq6HiojGJTd5hVYbgZm6WzcYPCoB+KBT4Vd6R7WSRG2OADNaCjg== + dependencies: + escape-string-regexp "^1.0.4" + math-random@^1.0.1: version "1.0.4" resolved "https://registry.yarnpkg.com/math-random/-/math-random-1.0.4.tgz#5dd6943c938548267016d4e34f057583080c514c" @@ -5107,11 +5215,6 @@ normalize-package-data@^2.0.0, normalize-package-data@^2.3.0, normalize-package- semver "2 || 3 || 4 || 5" validate-npm-package-license "^3.0.1" -normalize-path@^1.0.0: - version "1.0.0" - resolved "https://registry.yarnpkg.com/normalize-path/-/normalize-path-1.0.0.tgz#32d0e472f91ff345701c15a8311018d3b0a90379" - integrity sha1-MtDkcvkf80VwHBWoMRAY07CpA3k= - normalize-path@^2.0.1, normalize-path@^2.1.1: version "2.1.1" resolved "https://registry.yarnpkg.com/normalize-path/-/normalize-path-2.1.1.tgz#1ab28b556e198363a8c1a6f7e6fa20137fe6aed9" @@ -5633,7 +5736,14 @@ pkg-dir@^2.0.0: dependencies: find-up "^2.1.0" -please-upgrade-node@^3.0.2: +pkg-dir@^3.0.0: + version "3.0.0" + resolved "https://registry.yarnpkg.com/pkg-dir/-/pkg-dir-3.0.0.tgz#2749020f239ed990881b1f71210d51eb6523bea3" + integrity sha512-/E57AYkoeQ25qkxMj5PBOVgF8Kiu/h7cYS30Z5+R7WaiCCBfLq58ZI/dSeaEKb9WVJV5n/03QwrN3IeWIFllvw== + dependencies: + find-up "^3.0.0" + +please-upgrade-node@^3.0.2, please-upgrade-node@^3.1.1: version "3.1.1" resolved "https://registry.yarnpkg.com/please-upgrade-node/-/please-upgrade-node-3.1.1.tgz#ed320051dfcc5024fae696712c8288993595e8ac" integrity sha512-KY1uHnQ2NlQHqIJQpnh/i54rKkuxCEBx+voJIS/Mvb+L2iYd2NMotwduhKTMjfC1uKoX3VXOxLjIYG66dfJTVQ== @@ -5884,6 +5994,15 @@ read-pkg@^3.0.0: normalize-package-data "^2.3.2" path-type "^3.0.0" +read-pkg@^4.0.1: + version "4.0.1" + resolved "https://registry.yarnpkg.com/read-pkg/-/read-pkg-4.0.1.tgz#963625378f3e1c4d48c85872b5a6ec7d5d093237" + integrity sha1-ljYlN48+HE1IyFhytabsfV0JMjc= + dependencies: + normalize-package-data "^2.3.2" + parse-json "^4.0.0" + pify "^3.0.0" + read@1, read@~1.0.1: version "1.0.7" resolved "https://registry.yarnpkg.com/read/-/read-1.0.7.tgz#b3da19bd052431a97671d44a42634adf710b40c4" @@ -6128,7 +6247,7 @@ right-pad@^1.0.1: resolved "https://registry.yarnpkg.com/right-pad/-/right-pad-1.0.1.tgz#8ca08c2cbb5b55e74dafa96bf7fd1a27d568c8d0" integrity sha1-jKCMLLtbVedNr6lr9/0aJ9VoyNA= -rimraf@2, rimraf@^2.5.2, rimraf@^2.5.4, rimraf@^2.6.1, rimraf@^2.6.2, rimraf@^2.6.3, rimraf@~2.6.2: +rimraf@2, rimraf@^2.2.8, rimraf@^2.5.2, rimraf@^2.5.4, rimraf@^2.6.1, rimraf@^2.6.2, rimraf@^2.6.3, rimraf@~2.6.2: version "2.6.3" resolved "https://registry.yarnpkg.com/rimraf/-/rimraf-2.6.3.tgz#b2d104fe0d8fb27cf9e0a1cda8262dd3833c6cab" integrity sha512-mwqeW5XsA2qAejG46gYdENaxXjx9onRNCfn7L0duuP4hCuTIi/QO7PDK07KJfp1d+izWPrzEJDcSqBa0OZQriA== @@ -6147,6 +6266,11 @@ run-async@^2.2.0: dependencies: is-promise "^2.1.0" +run-node@^1.0.0: + version "1.0.0" + resolved "https://registry.yarnpkg.com/run-node/-/run-node-1.0.0.tgz#46b50b946a2aa2d4947ae1d886e9856fd9cabe5e" + integrity sha512-kc120TBlQ3mih1LSzdAJXo4xn/GWS2ec0l3S+syHDXP9uRr0JAT8Qd3mdMuyjqCzeZktgP3try92cEgf9Nks8A== + run-queue@^1.0.0, run-queue@^1.0.3: version "1.0.3" resolved "https://registry.yarnpkg.com/run-queue/-/run-queue-1.0.3.tgz#e848396f057d223f24386924618e25694161ec47" @@ -6266,6 +6390,13 @@ signal-exit@^3.0.0, signal-exit@^3.0.2: resolved "https://registry.yarnpkg.com/signal-exit/-/signal-exit-3.0.2.tgz#b5fdc08f1287ea1178628e415e25132b73646c6d" integrity sha1-tf3AjxKH6hF4Yo5BXiUTK3NkbG0= +simple-git@^1.85.0: + version "1.107.0" + resolved "https://registry.yarnpkg.com/simple-git/-/simple-git-1.107.0.tgz#12cffaf261c14d6f450f7fdb86c21ccee968b383" + integrity sha512-t4OK1JRlp4ayKRfcW6owrWcRVLyHRUlhGd0uN6ZZTqfDq8a5XpcUdOKiGRNobHEuMtNqzp0vcJNvhYWwh5PsQA== + dependencies: + debug "^4.0.1" + sisteransi@^0.1.1: version "0.1.1" resolved "https://registry.yarnpkg.com/sisteransi/-/sisteransi-0.1.1.tgz#5431447d5f7d1675aac667ccd0b865a4994cb3ce" @@ -6276,6 +6407,11 @@ slash@^1.0.0: resolved "https://registry.yarnpkg.com/slash/-/slash-1.0.0.tgz#c41f2f6c39fc16d1cd17ad4b5d896114ae470d55" integrity sha1-xB8vbDn8FtHNF61LXYlhFK5HDVU= +slash@^2.0.0: + version "2.0.0" + resolved "https://registry.yarnpkg.com/slash/-/slash-2.0.0.tgz#de552851a1759df3a8f206535442f5ec4ddeab44" + integrity sha512-ZYKh3Wh2z1PpEXWr0MpSBZ0V6mZHAQfYevttO11c51CaWjGTaadiKZ+wVt1PbMlDV5qhMFslpZCemhwOK7C89A== + slice-ansi@0.0.4: version "0.0.4" resolved "https://registry.yarnpkg.com/slice-ansi/-/slice-ansi-0.0.4.tgz#edbf8903f66f7ce2f8eafd6ceed65e264c831b35" @@ -6473,10 +6609,10 @@ stack-utils@^1.0.1: resolved "https://registry.yarnpkg.com/stack-utils/-/stack-utils-1.0.2.tgz#33eba3897788558bebfc2db059dc158ec36cebb8" integrity sha512-MTX+MeG5U994cazkjd/9KNAapsHnibjMLnfXodlkXw76JEea0UiNzrqidzo1emMwk7w5Qhc9jd4Bn9TBb1MFwA== -staged-git-files@1.1.1: - version "1.1.1" - resolved "https://registry.yarnpkg.com/staged-git-files/-/staged-git-files-1.1.1.tgz#37c2218ef0d6d26178b1310719309a16a59f8f7b" - integrity sha512-H89UNKr1rQJvI1c/PIR3kiAMBV23yvR7LItZiV74HWZwzt7f3YHuujJ9nJZlt58WlFox7XQsOahexwk7nTe69A== +staged-git-files@1.1.2: + version "1.1.2" + resolved "https://registry.yarnpkg.com/staged-git-files/-/staged-git-files-1.1.2.tgz#4326d33886dc9ecfa29a6193bf511ba90a46454b" + integrity sha512-0Eyrk6uXW6tg9PYkhi/V/J4zHp33aNyi2hOCmhFLqLTIhbgqWn5jlSzI+IU0VqrZq6+DbHcabQl/WP6P3BG0QA== static-extend@^0.1.1: version "0.1.2" From aacf5b05c7f0d802bbc28222d7c95141fa0ff86c Mon Sep 17 00:00:00 2001 From: James Henry Date: Mon, 28 Jan 2019 21:25:44 -0500 Subject: [PATCH 12/13] perf(ts-estree): don't create Program in parse() (#148) --- packages/typescript-estree/src/parser.ts | 347 ++++++++++-------- .../tests/lib/__snapshots__/parse.ts.snap | 82 ++++- packages/typescript-estree/tests/lib/parse.ts | 7 +- .../tests/lib/semanticInfo.ts | 18 + .../tests/lib/warn-on-unsupported-ts.ts | 22 ++ 5 files changed, 324 insertions(+), 152 deletions(-) create mode 100644 packages/typescript-estree/tests/lib/warn-on-unsupported-ts.ts diff --git a/packages/typescript-estree/src/parser.ts b/packages/typescript-estree/src/parser.ts index ff2784aa9963..225899a106f9 100644 --- a/packages/typescript-estree/src/parser.ts +++ b/packages/typescript-estree/src/parser.ts @@ -36,7 +36,10 @@ let extra: Extra; let warnedAboutTSVersion = false; /** - * Compute the filename based on the parser options + * Compute the filename based on the parser options. + * + * Even if jsx option is set in typescript compiler, filename still has to + * contain .tsx file extension. * * @param options Parser options */ @@ -106,8 +109,6 @@ function getASTAndDefaultProject(code: string, options: ParserOptions) { * @returns {{ast: ts.SourceFile, program: ts.Program}} Returns a new source file and program corresponding to the linted code */ function createNewProgram(code: string) { - // Even if jsx option is set in typescript compiler, filename still has to - // contain .tsx file extension const FILENAME = getFileName(extra); const compilerHost = { @@ -178,6 +179,98 @@ function getProgramAndAST( ); } +function applyParserOptionsToExtra(options: ParserOptions): void { + /** + * Track range information in the AST + */ + extra.range = typeof options.range === 'boolean' && options.range; + extra.loc = typeof options.loc === 'boolean' && options.loc; + /** + * Track tokens in the AST + */ + if (typeof options.tokens === 'boolean' && options.tokens) { + extra.tokens = []; + } + /** + * Track comments in the AST + */ + if (typeof options.comment === 'boolean' && options.comment) { + extra.comment = true; + extra.comments = []; + } + /** + * Enable JSX - note the applicable file extension is still required + */ + if (typeof options.jsx === 'boolean' && options.jsx) { + extra.jsx = true; + } + /** + * The JSX AST changed the node type for string literals + * inside a JSX Element from `Literal` to `JSXText`. + * + * When value is `true`, these nodes will be parsed as type `JSXText`. + * When value is `false`, these nodes will be parsed as type `Literal`. + */ + if (typeof options.useJSXTextNode === 'boolean' && options.useJSXTextNode) { + extra.useJSXTextNode = true; + } + /** + * Allow the user to cause the parser to error if it encounters an unknown AST Node Type + * (used in testing) + */ + if ( + typeof options.errorOnUnknownASTType === 'boolean' && + options.errorOnUnknownASTType + ) { + extra.errorOnUnknownASTType = true; + } + /** + * Allow the user to override the function used for logging + */ + if (typeof options.loggerFn === 'function') { + extra.log = options.loggerFn; + } else if (options.loggerFn === false) { + extra.log = Function.prototype; + } + + if (typeof options.project === 'string') { + extra.projects = [options.project]; + } else if ( + Array.isArray(options.project) && + options.project.every(projectPath => typeof projectPath === 'string') + ) { + extra.projects = options.project; + } + + if (typeof options.tsconfigRootDir === 'string') { + extra.tsconfigRootDir = options.tsconfigRootDir; + } + + if ( + Array.isArray(options.extraFileExtensions) && + options.extraFileExtensions.every(ext => typeof ext === 'string') + ) { + extra.extraFileExtensions = options.extraFileExtensions; + } +} + +function warnAboutTSVersion(): void { + if (!isRunningSupportedTypeScriptVersion && !warnedAboutTSVersion) { + const border = '============='; + const versionWarning = [ + border, + 'WARNING: You are currently running a version of TypeScript which is not officially supported by typescript-estree.', + 'You may find that it works just fine, or you may not.', + `SUPPORTED TYPESCRIPT VERSIONS: ${SUPPORTED_TYPESCRIPT_VERSIONS}`, + `YOUR TYPESCRIPT VERSION: ${ACTIVE_TYPESCRIPT_VERSION}`, + 'Please only submit bug reports when using the officially supported version.', + border + ]; + extra.log(versionWarning.join('\n\n')); + warnedAboutTSVersion = true; + } +} + //------------------------------------------------------------------------------ // Parser //------------------------------------------------------------------------------ @@ -187,143 +280,118 @@ type AST = Program & (T['tokens'] extends true ? { tokens: ESTreeToken[] } : {}) & (T['comment'] extends true ? { comments: ESTreeComment[] } : {}); -/** - * Parses the given source code to produce a valid AST - * @param {string} code TypeScript code - * @param {boolean} shouldGenerateServices Flag determining whether to generate ast maps and program or not - * @param {ParserOptions} options configuration object for the parser - * @returns {Object} the AST - */ -function generateAST( +interface ParseAndGenerateServicesResult { + ast: AST; + services: { + program: ts.Program | undefined; + esTreeNodeToTSNodeMap: WeakMap | undefined; + tsNodeToESTreeNodeMap: WeakMap | undefined; + }; +} + +//------------------------------------------------------------------------------ +// Public +//------------------------------------------------------------------------------ + +export const version: string = packageJSON.version; + +export function parse( code: string, - options: T = {} as T, - shouldGenerateServices = false -): { - estree: AST; - program: typeof shouldGenerateServices extends true - ? ts.Program - : (ts.Program | undefined); - astMaps: typeof shouldGenerateServices extends true - ? { - esTreeNodeToTSNodeMap: WeakMap; - tsNodeToESTreeNodeMap: WeakMap; - } - : { - esTreeNodeToTSNodeMap?: WeakMap; - tsNodeToESTreeNodeMap?: WeakMap; - }; -} { + options?: T +): AST { + /** + * Reset the parse configuration + */ + resetExtra(); + /** + * Ensure users do not attempt to use parse() when they need parseAndGenerateServices() + */ + if (options && options.errorOnTypeScriptSyntacticAndSemanticIssues) { + throw new Error( + `"errorOnTypeScriptSyntacticAndSemanticIssues" is only supported for parseAndGenerateServices()` + ); + } + /** + * Ensure the source code is a string, and store a reference to it + */ if (typeof code !== 'string' && !((code as any) instanceof String)) { code = String(code); } + extra.code = code; + /** + * Apply the given parser options + */ + if (typeof options !== 'undefined') { + applyParserOptionsToExtra(options); + } + /** + * Warn if the user is using an unsupported version of TypeScript + */ + warnAboutTSVersion(); + /** + * Create a ts.SourceFile directly, no ts.Program is needed for a simple + * parse + */ + const ast = ts.createSourceFile( + getFileName(extra), + code, + ts.ScriptTarget.Latest, + /* setParentNodes */ true + ); + /** + * Convert the TypeScript AST to an ESTree-compatible one + */ + const { estree } = convert(ast, extra, false); + return estree; +} +export function parseAndGenerateServices< + T extends ParserOptions = ParserOptions +>(code: string, options: T): ParseAndGenerateServicesResult { + /** + * Reset the parse configuration + */ resetExtra(); - + /** + * Ensure the source code is a string, and store a reference to it + */ + if (typeof code !== 'string' && !((code as any) instanceof String)) { + code = String(code); + } + extra.code = code; + /** + * Apply the given parser options + */ if (typeof options !== 'undefined') { - extra.range = typeof options.range === 'boolean' && options.range; - extra.loc = typeof options.loc === 'boolean' && options.loc; - - if (typeof options.tokens === 'boolean' && options.tokens) { - extra.tokens = []; - } - - if (typeof options.comment === 'boolean' && options.comment) { - extra.comment = true; - extra.comments = []; - } - - if (typeof options.jsx === 'boolean' && options.jsx) { - extra.jsx = true; - } - - /** - * Allow the user to cause the parser to error if it encounters an unknown AST Node Type - * (used in testing). - */ - if ( - typeof options.errorOnUnknownASTType === 'boolean' && - options.errorOnUnknownASTType - ) { - extra.errorOnUnknownASTType = true; - } - - /** - * Retrieve semantic and syntactic diagnostics from the underlying TypeScript Program - * and turn them into parse errors - */ + applyParserOptionsToExtra(options); if ( - shouldGenerateServices && typeof options.errorOnTypeScriptSyntacticAndSemanticIssues === 'boolean' && options.errorOnTypeScriptSyntacticAndSemanticIssues ) { extra.errorOnTypeScriptSyntacticAndSemanticIssues = true; } - - if (typeof options.useJSXTextNode === 'boolean' && options.useJSXTextNode) { - extra.useJSXTextNode = true; - } - - /** - * Allow the user to override the function used for logging - */ - if (typeof options.loggerFn === 'function') { - extra.log = options.loggerFn; - } else if (options.loggerFn === false) { - extra.log = Function.prototype; - } - - if (typeof options.project === 'string') { - extra.projects = [options.project]; - } else if ( - Array.isArray(options.project) && - options.project.every(projectPath => typeof projectPath === 'string') - ) { - extra.projects = options.project; - } - - if (typeof options.tsconfigRootDir === 'string') { - extra.tsconfigRootDir = options.tsconfigRootDir; - } - - if ( - Array.isArray(options.extraFileExtensions) && - options.extraFileExtensions.every(ext => typeof ext === 'string') - ) { - extra.extraFileExtensions = options.extraFileExtensions; - } } - - if (!isRunningSupportedTypeScriptVersion && !warnedAboutTSVersion) { - const border = '============='; - const versionWarning = [ - border, - 'WARNING: You are currently running a version of TypeScript which is not officially supported by typescript-estree.', - 'You may find that it works just fine, or you may not.', - `SUPPORTED TYPESCRIPT VERSIONS: ${SUPPORTED_TYPESCRIPT_VERSIONS}`, - `YOUR TYPESCRIPT VERSION: ${ACTIVE_TYPESCRIPT_VERSION}`, - 'Please only submit bug reports when using the officially supported version.', - border - ]; - extra.log(versionWarning.join('\n\n')); - warnedAboutTSVersion = true; - } - + /** + * Warn if the user is using an unsupported version of TypeScript + */ + warnAboutTSVersion(); + /** + * Generate a full ts.Program in order to be able to provide parser + * services, such as type-checking + */ const shouldProvideParserServices = - shouldGenerateServices && extra.projects && extra.projects.length > 0; + extra.projects && extra.projects.length > 0; const { ast, program } = getProgramAndAST( code, options, shouldProvideParserServices ); - - extra.code = code; - /** - * Convert the AST + * Convert the TypeScript AST to an ESTree-compatible one, and optionally preserve + * mappings between converted and original AST nodes */ const { estree, astMaps } = convert(ast, extra, shouldProvideParserServices); - /** * Even if TypeScript parsed the source code ok, and we had no problems converting the AST, * there may be other syntactic or semantic issues in the code that we can optionally report on. @@ -334,42 +402,21 @@ function generateAST( throw convertError(error); } } - - return { - estree, - program: shouldProvideParserServices ? program : undefined, - astMaps: shouldProvideParserServices - ? astMaps! - : { esTreeNodeToTSNodeMap: undefined, tsNodeToESTreeNodeMap: undefined } - }; -} - -//------------------------------------------------------------------------------ -// Public -//------------------------------------------------------------------------------ - -export const version: string = packageJSON.version; - -export function parse( - code: string, - options?: T -) { - if (options && options.errorOnTypeScriptSyntacticAndSemanticIssues) { - throw new Error( - `"errorOnTypeScriptSyntacticAndSemanticIssues" is only supported for parseAndGenerateServices()` - ); - } - return generateAST(code, options).estree; -} - -export function parseAndGenerateServices(code: string, options: ParserOptions) { - const result = generateAST(code, options, /*shouldGenerateServices*/ true); + /** + * Return the converted AST and additional parser services + */ return { - ast: result.estree, + ast: estree, services: { - program: result.program, - esTreeNodeToTSNodeMap: result.astMaps.esTreeNodeToTSNodeMap, - tsNodeToESTreeNodeMap: result.astMaps.tsNodeToESTreeNodeMap + program: shouldProvideParserServices ? program : undefined, + esTreeNodeToTSNodeMap: + shouldProvideParserServices && astMaps + ? astMaps.esTreeNodeToTSNodeMap + : undefined, + tsNodeToESTreeNodeMap: + shouldProvideParserServices && astMaps + ? astMaps.tsNodeToESTreeNodeMap + : undefined } }; } diff --git a/packages/typescript-estree/tests/lib/__snapshots__/parse.ts.snap b/packages/typescript-estree/tests/lib/__snapshots__/parse.ts.snap index 4509f7441037..38e378d9f7e0 100644 --- a/packages/typescript-estree/tests/lib/__snapshots__/parse.ts.snap +++ b/packages/typescript-estree/tests/lib/__snapshots__/parse.ts.snap @@ -189,7 +189,87 @@ Object { } `; -exports[`parse() non string code should correctly convert code to string 1`] = ` +exports[`parse() non string code should correctly convert code to a string for parse() 1`] = ` +Object { + "body": Array [ + Object { + "expression": Object { + "loc": Object { + "end": Object { + "column": 5, + "line": 1, + }, + "start": Object { + "column": 0, + "line": 1, + }, + }, + "range": Array [ + 0, + 5, + ], + "raw": "12345", + "type": "Literal", + "value": 12345, + }, + "loc": Object { + "end": Object { + "column": 5, + "line": 1, + }, + "start": Object { + "column": 0, + "line": 1, + }, + }, + "range": Array [ + 0, + 5, + ], + "type": "ExpressionStatement", + }, + ], + "comments": Array [], + "loc": Object { + "end": Object { + "column": 5, + "line": 1, + }, + "start": Object { + "column": 0, + "line": 1, + }, + }, + "range": Array [ + 0, + 5, + ], + "sourceType": "script", + "tokens": Array [ + Object { + "loc": Object { + "end": Object { + "column": 5, + "line": 1, + }, + "start": Object { + "column": 0, + "line": 1, + }, + }, + "range": Array [ + 0, + 5, + ], + "type": "Numeric", + "value": "12345", + }, + ], + "type": "Program", +} +`; + +exports[`parse() non string code should correctly convert code to a string for parseAndGenerateServices() 1`] = ` Object { "body": Array [ Object { diff --git a/packages/typescript-estree/tests/lib/parse.ts b/packages/typescript-estree/tests/lib/parse.ts index 74f02d03792c..fc7e8af99a10 100644 --- a/packages/typescript-estree/tests/lib/parse.ts +++ b/packages/typescript-estree/tests/lib/parse.ts @@ -57,9 +57,14 @@ describe('parse()', () => { }; it( - 'should correctly convert code to string', + 'should correctly convert code to a string for parse()', createSnapshotTestBlock(code, config) ); + + it( + 'should correctly convert code to a string for parseAndGenerateServices()', + createSnapshotTestBlock(code, config, true) + ); }); describe('loggerFn should be propagated to ast-converter', () => { diff --git a/packages/typescript-estree/tests/lib/semanticInfo.ts b/packages/typescript-estree/tests/lib/semanticInfo.ts index eb5af8677e97..e45cae843ed5 100644 --- a/packages/typescript-estree/tests/lib/semanticInfo.ts +++ b/packages/typescript-estree/tests/lib/semanticInfo.ts @@ -17,6 +17,7 @@ import { formatSnapshotName, parseCodeAndGenerateServices } from '../../tools/test-utils'; +import { parseAndGenerateServices } from '../../src/parser'; //------------------------------------------------------------------------------ // Setup @@ -59,6 +60,23 @@ describe('semanticInfo', () => { ); }); + it(`should handle "project": "./tsconfig.json" and "project": ["./tsconfig.json"] the same`, () => { + const filename = testFiles[0]; + const code = readFileSync(filename, 'utf8'); + const options = createOptions(filename); + const optionsProjectString = { + ...options, + project: './tsconfig.json' + }; + const optionsProjectArray = { + ...options, + project: ['./tsconfig.json'] + }; + expect(parseAndGenerateServices(code, optionsProjectString)).toEqual( + parseAndGenerateServices(code, optionsProjectArray) + ); + }); + // case-specific tests it('isolated-file tests', () => { const fileName = resolve(FIXTURES_DIR, 'isolated-file.src.ts'); diff --git a/packages/typescript-estree/tests/lib/warn-on-unsupported-ts.ts b/packages/typescript-estree/tests/lib/warn-on-unsupported-ts.ts new file mode 100644 index 000000000000..d984007bf757 --- /dev/null +++ b/packages/typescript-estree/tests/lib/warn-on-unsupported-ts.ts @@ -0,0 +1,22 @@ +import semver from 'semver'; +import * as parser from '../../src/parser'; + +jest.mock('semver'); + +describe('Warn on unsupported TypeScript version', () => { + afterEach(() => { + jest.resetModules(); + jest.resetAllMocks(); + }); + + it('should warn the user if they are using an unsupported TypeScript version', () => { + (semver.satisfies as jest.Mock).mockReturnValue(false); + console.log = jest.fn(); + parser.parse(''); + expect(console.log).toHaveBeenCalledWith( + expect.stringContaining( + 'WARNING: You are currently running a version of TypeScript which is not officially supported by typescript-estree' + ) + ); + }); +}); From 5b0b3d9edbcb3ab588a34c431037d9deece30824 Mon Sep 17 00:00:00 2001 From: James Henry Date: Mon, 28 Jan 2019 21:35:58 -0500 Subject: [PATCH 13/13] chore: publish v1.1.1 --- CHANGELOG.md | 12 ++++++++++++ lerna.json | 2 +- packages/eslint-plugin-tslint/CHANGELOG.md | 4 ++++ packages/eslint-plugin-tslint/package.json | 4 ++-- packages/eslint-plugin/CHANGELOG.md | 7 +++++++ packages/eslint-plugin/package.json | 4 ++-- packages/parser/CHANGELOG.md | 8 ++++++++ packages/parser/package.json | 6 +++--- packages/shared-fixtures/CHANGELOG.md | 8 ++++++++ packages/shared-fixtures/package.json | 2 +- packages/typescript-estree/CHANGELOG.md | 11 +++++++++++ packages/typescript-estree/package.json | 4 ++-- 12 files changed, 61 insertions(+), 11 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 6fbb5db67f5c..ccbbce028b9f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,18 @@ All notable changes to this project will be documented in this file. See [Conventional Commits](https://conventionalcommits.org) for commit guidelines. +## [1.1.1](https://github.com/typescript-eslint/typescript-eslint/compare/v1.1.0...v1.1.1) (2019-01-29) + +### Bug Fixes + +- **eslint-plugin:** make parser services error clearer ([#132](https://github.com/typescript-eslint/typescript-eslint/issues/132)) ([aa9d1e1](https://github.com/typescript-eslint/typescript-eslint/commit/aa9d1e1)) +- **parser:** add visiting of type parameters in JSXOpeningElement ([#150](https://github.com/typescript-eslint/typescript-eslint/issues/150)) ([5e16003](https://github.com/typescript-eslint/typescript-eslint/commit/5e16003)) +- **ts-estree:** expand optional property to include question token ([#138](https://github.com/typescript-eslint/typescript-eslint/issues/138)) ([9068b62](https://github.com/typescript-eslint/typescript-eslint/commit/9068b62)) + +### Performance Improvements + +- **ts-estree:** don't create Program in parse() ([#148](https://github.com/typescript-eslint/typescript-eslint/issues/148)) ([aacf5b0](https://github.com/typescript-eslint/typescript-eslint/commit/aacf5b0)) + # [1.1.0](https://github.com/typescript-eslint/typescript-eslint/compare/v1.0.0...v1.1.0) (2019-01-23) ### Bug Fixes diff --git a/lerna.json b/lerna.json index 844b711bb0fe..06bbd031b2c8 100644 --- a/lerna.json +++ b/lerna.json @@ -1,5 +1,5 @@ { - "version": "1.1.0", + "version": "1.1.1", "npmClient": "yarn", "useWorkspaces": true, "stream": true diff --git a/packages/eslint-plugin-tslint/CHANGELOG.md b/packages/eslint-plugin-tslint/CHANGELOG.md index 6b4306f26855..46f2c1960d94 100644 --- a/packages/eslint-plugin-tslint/CHANGELOG.md +++ b/packages/eslint-plugin-tslint/CHANGELOG.md @@ -3,6 +3,10 @@ All notable changes to this project will be documented in this file. See [Conventional Commits](https://conventionalcommits.org) for commit guidelines. +## [1.1.1](https://github.com/typescript-eslint/typescript-eslint/compare/v1.1.0...v1.1.1) (2019-01-29) + +**Note:** Version bump only for package @typescript-eslint/eslint-plugin-tslint + # [1.1.0](https://github.com/typescript-eslint/typescript-eslint/compare/v1.0.0...v1.1.0) (2019-01-23) **Note:** Version bump only for package @typescript-eslint/eslint-plugin-tslint diff --git a/packages/eslint-plugin-tslint/package.json b/packages/eslint-plugin-tslint/package.json index d8aeedf6ef0e..b54084d620e4 100644 --- a/packages/eslint-plugin-tslint/package.json +++ b/packages/eslint-plugin-tslint/package.json @@ -1,6 +1,6 @@ { "name": "@typescript-eslint/eslint-plugin-tslint", - "version": "1.1.0", + "version": "1.1.1", "main": "dist/index.js", "typings": "src/index.ts", "description": "TSLint wrapper plugin for ESLint", @@ -34,6 +34,6 @@ "devDependencies": { "@types/eslint": "^4.16.3", "@types/lodash.memoize": "^4.1.4", - "@typescript-eslint/parser": "1.1.0" + "@typescript-eslint/parser": "1.1.1" } } diff --git a/packages/eslint-plugin/CHANGELOG.md b/packages/eslint-plugin/CHANGELOG.md index 39a512dab49e..992ae046dde3 100644 --- a/packages/eslint-plugin/CHANGELOG.md +++ b/packages/eslint-plugin/CHANGELOG.md @@ -3,6 +3,13 @@ All notable changes to this project will be documented in this file. See [Conventional Commits](https://conventionalcommits.org) for commit guidelines. +## [1.1.1](https://github.com/typescript-eslint/typescript-eslint/compare/v1.1.0...v1.1.1) (2019-01-29) + +### Bug Fixes + +- **eslint-plugin:** make parser services error clearer ([#132](https://github.com/typescript-eslint/typescript-eslint/issues/132)) ([aa9d1e1](https://github.com/typescript-eslint/typescript-eslint/commit/aa9d1e1)) +- **parser:** add visiting of type parameters in JSXOpeningElement ([#150](https://github.com/typescript-eslint/typescript-eslint/issues/150)) ([5e16003](https://github.com/typescript-eslint/typescript-eslint/commit/5e16003)) + # [1.1.0](https://github.com/typescript-eslint/typescript-eslint/compare/v1.0.0...v1.1.0) (2019-01-23) ### Bug Fixes diff --git a/packages/eslint-plugin/package.json b/packages/eslint-plugin/package.json index 7d414aa3576d..5e824cfd98c3 100644 --- a/packages/eslint-plugin/package.json +++ b/packages/eslint-plugin/package.json @@ -1,6 +1,6 @@ { "name": "@typescript-eslint/eslint-plugin", - "version": "1.1.0", + "version": "1.1.1", "description": "TypeScript plugin for ESLint", "keywords": [ "eslint", @@ -24,7 +24,7 @@ "recommended:update": "node tools/update-recommended.js" }, "dependencies": { - "@typescript-eslint/parser": "1.1.0", + "@typescript-eslint/parser": "1.1.1", "requireindex": "^1.2.0" }, "devDependencies": { diff --git a/packages/parser/CHANGELOG.md b/packages/parser/CHANGELOG.md index 3c8b8d4e4efc..f2047e5c6d25 100644 --- a/packages/parser/CHANGELOG.md +++ b/packages/parser/CHANGELOG.md @@ -3,6 +3,14 @@ All notable changes to this project will be documented in this file. See [Conventional Commits](https://conventionalcommits.org) for commit guidelines. +## [1.1.1](https://github.com/typescript-eslint/typescript-eslint/compare/v1.1.0...v1.1.1) (2019-01-29) + +### Bug Fixes + +- **eslint-plugin:** make parser services error clearer ([#132](https://github.com/typescript-eslint/typescript-eslint/issues/132)) ([aa9d1e1](https://github.com/typescript-eslint/typescript-eslint/commit/aa9d1e1)) +- **parser:** add visiting of type parameters in JSXOpeningElement ([#150](https://github.com/typescript-eslint/typescript-eslint/issues/150)) ([5e16003](https://github.com/typescript-eslint/typescript-eslint/commit/5e16003)) +- **ts-estree:** expand optional property to include question token ([#138](https://github.com/typescript-eslint/typescript-eslint/issues/138)) ([9068b62](https://github.com/typescript-eslint/typescript-eslint/commit/9068b62)) + # [1.1.0](https://github.com/typescript-eslint/typescript-eslint/compare/v1.0.0...v1.1.0) (2019-01-23) ### Bug Fixes diff --git a/packages/parser/package.json b/packages/parser/package.json index 2ba2e642ebd9..6cf42f6ce6db 100644 --- a/packages/parser/package.json +++ b/packages/parser/package.json @@ -1,6 +1,6 @@ { "name": "@typescript-eslint/parser", - "version": "1.1.0", + "version": "1.1.1", "description": "An ESLint custom parser which leverages TypeScript ESTree", "main": "dist/parser.js", "files": [ @@ -36,7 +36,7 @@ "typescript": "*" }, "dependencies": { - "@typescript-eslint/typescript-estree": "1.1.0", + "@typescript-eslint/typescript-estree": "1.1.1", "eslint-scope": "^4.0.0", "eslint-visitor-keys": "^1.0.0" }, @@ -44,6 +44,6 @@ "@types/eslint": "^4.16.5", "@types/eslint-visitor-keys": "^1.0.0", "@types/estree": "^0.0.39", - "@typescript-eslint/shared-fixtures": "1.1.0" + "@typescript-eslint/shared-fixtures": "1.1.1" } } diff --git a/packages/shared-fixtures/CHANGELOG.md b/packages/shared-fixtures/CHANGELOG.md index 3114aaabc99c..2c81f52bfe1e 100644 --- a/packages/shared-fixtures/CHANGELOG.md +++ b/packages/shared-fixtures/CHANGELOG.md @@ -3,6 +3,14 @@ All notable changes to this project will be documented in this file. See [Conventional Commits](https://conventionalcommits.org) for commit guidelines. +## [1.1.1](https://github.com/typescript-eslint/typescript-eslint/compare/v1.1.0...v1.1.1) (2019-01-29) + +**Note:** Version bump only for package @typescript-eslint/shared-fixtures + + + + + # [1.1.0](https://github.com/typescript-eslint/typescript-eslint/compare/v1.0.0...v1.1.0) (2019-01-23) diff --git a/packages/shared-fixtures/package.json b/packages/shared-fixtures/package.json index 2424070165f4..e5b8b9613aad 100644 --- a/packages/shared-fixtures/package.json +++ b/packages/shared-fixtures/package.json @@ -1,5 +1,5 @@ { "name": "@typescript-eslint/shared-fixtures", - "version": "1.1.0", + "version": "1.1.1", "private": true } diff --git a/packages/typescript-estree/CHANGELOG.md b/packages/typescript-estree/CHANGELOG.md index be11f821f745..2fcfd25aae42 100644 --- a/packages/typescript-estree/CHANGELOG.md +++ b/packages/typescript-estree/CHANGELOG.md @@ -3,6 +3,17 @@ All notable changes to this project will be documented in this file. See [Conventional Commits](https://conventionalcommits.org) for commit guidelines. +## [1.1.1](https://github.com/typescript-eslint/typescript-eslint/compare/v1.1.0...v1.1.1) (2019-01-29) + +### Bug Fixes + +- **parser:** add visiting of type parameters in JSXOpeningElement ([#150](https://github.com/typescript-eslint/typescript-eslint/issues/150)) ([5e16003](https://github.com/typescript-eslint/typescript-eslint/commit/5e16003)) +- **ts-estree:** expand optional property to include question token ([#138](https://github.com/typescript-eslint/typescript-eslint/issues/138)) ([9068b62](https://github.com/typescript-eslint/typescript-eslint/commit/9068b62)) + +### Performance Improvements + +- **ts-estree:** don't create Program in parse() ([#148](https://github.com/typescript-eslint/typescript-eslint/issues/148)) ([aacf5b0](https://github.com/typescript-eslint/typescript-eslint/commit/aacf5b0)) + # [1.1.0](https://github.com/typescript-eslint/typescript-eslint/compare/v1.0.0...v1.1.0) (2019-01-23) ### Bug Fixes diff --git a/packages/typescript-estree/package.json b/packages/typescript-estree/package.json index 3d112005adce..2be4fceecffc 100644 --- a/packages/typescript-estree/package.json +++ b/packages/typescript-estree/package.json @@ -1,6 +1,6 @@ { "name": "@typescript-eslint/typescript-estree", - "version": "1.1.0", + "version": "1.1.1", "description": "A parser that converts TypeScript source code into an ESTree compatible form", "main": "dist/parser.js", "types": "dist/parser.d.ts", @@ -42,7 +42,7 @@ "typescript": "*" }, "devDependencies": { - "@typescript-eslint/shared-fixtures": "1.1.0", + "@typescript-eslint/shared-fixtures": "1.1.1", "typescript": "~3.2.1" } }