From 2dc9a9b6276c7ea4fc527e187853ba64b8ee3c86 Mon Sep 17 00:00:00 2001 From: Brad Zacher Date: Wed, 27 Mar 2019 15:15:49 -0700 Subject: [PATCH 1/8] temp commit --- packages/eslint-plugin/package.json | 2 +- .../src/rules/adjacent-overload-signatures.ts | 2 +- .../eslint-plugin/src/rules/array-type.ts | 2 +- packages/eslint-plugin/src/rules/ban-types.ts | 2 +- packages/eslint-plugin/src/rules/camelcase.ts | 2 +- .../src/rules/class-name-casing.ts | 2 +- .../rules/explicit-function-return-type.ts | 2 +- .../rules/explicit-member-accessibility.ts | 2 +- packages/eslint-plugin/src/rules/indent.ts | 2 +- .../src/rules/member-delimiter-style.ts | 2 +- .../eslint-plugin/src/rules/member-naming.ts | 2 +- .../src/rules/member-ordering.ts | 2 +- .../src/rules/no-array-constructor.ts | 2 +- .../src/rules/no-extraneous-class.ts | 2 +- .../src/rules/no-inferrable-types.ts | 2 +- .../eslint-plugin/src/rules/no-misused-new.ts | 2 +- .../eslint-plugin/src/rules/no-namespace.ts | 2 +- .../rules/no-object-literal-type-assertion.ts | 2 +- .../src/rules/no-parameter-properties.ts | 2 +- .../src/rules/no-require-imports.ts | 2 +- .../eslint-plugin/src/rules/no-this-alias.ts | 2 +- .../eslint-plugin/src/rules/no-type-alias.ts | 2 +- .../src/rules/no-unnecessary-qualifier.ts | 2 +- .../rules/no-unnecessary-type-assertion.ts | 2 +- .../eslint-plugin/src/rules/no-unused-vars.ts | 2 +- .../src/rules/no-use-before-define.ts | 2 +- .../src/rules/no-useless-constructor.ts | 2 +- .../src/rules/no-var-requires.ts | 2 +- .../src/rules/prefer-function-type.ts | 2 +- .../src/rules/prefer-interface.ts | 2 +- .../src/rules/prefer-namespace-keyword.ts | 2 +- .../src/rules/promise-function-async.ts | 2 +- .../src/rules/require-array-sort-compare.ts | 2 +- .../src/rules/restrict-plus-operands.ts | 2 +- .../src/rules/type-annotation-spacing.ts | 2 +- packages/eslint-plugin/src/util/misc.ts | 2 +- packages/eslint-plugin/tests/RuleTester.ts | 2 +- .../tests/eslint-rules/no-redeclare.test.ts | 2 +- .../tests/rules/no-array-constructor.test.ts | 2 +- .../tests/rules/no-extraneous-class.test.ts | 2 +- .../tests/rules/no-for-in-array.test.ts | 2 +- .../tests/rules/no-this-alias.test.ts | 2 +- .../rules/no-unnecessary-qualifier.test.ts | 2 +- .../tests/rules/no-use-before-define.test.ts | 2 +- .../tests/rules/prefer-function-type.test.ts | 2 +- .../eslint-plugin/typings/eslint-rules.d.ts | 26 ++++++------ packages/eslint-plugin/typings/ts-eslint.d.ts | 2 +- packages/parser/package.json | 1 + packages/parser/src/analyze-scope.ts | 13 +++--- packages/parser/src/parser.ts | 4 +- packages/parser/src/scope/scope-manager.ts | 5 +-- packages/parser/src/scope/scopes.ts | 2 +- packages/parser/tests/lib/parser.ts | 5 ++- packages/parser/tests/lib/visitor-keys.ts | 2 +- packages/parser/typings/eslint-scope.d.ts | 16 ++++---- packages/typescript-estree/package.json | 3 +- .../typescript-estree/src/ast-converter.ts | 2 +- .../typescript-estree/src/convert-comments.ts | 2 +- packages/typescript-estree/src/convert.ts | 3 +- packages/typescript-estree/src/node-utils.ts | 8 +++- .../typescript-estree/src/parser-options.ts | 11 +++-- packages/typescript-estree/src/parser.ts | 11 +++-- .../tests/ast-alignment/fixtures-to-test.ts | 2 +- .../tests/ast-alignment/parse.ts | 2 +- .../tests/ast-alignment/utils.ts | 2 +- .../tests/lib/semanticInfo.ts | 13 +++--- packages/util/LICENSE | 21 ++++++++++ packages/util/README.md | 3 ++ packages/util/package.json | 40 +++++++++++++++++++ .../ts-estree => util/src}/ast-node-types.ts | 0 .../src/ts-estree => util/src}/index.ts | 2 +- .../src/ts-estree => util/src}/ts-estree.ts | 0 .../src/ts-nodes.ts | 0 packages/util/tsconfig.build.json | 10 +++++ packages/util/tsconfig.json | 11 +++++ 75 files changed, 199 insertions(+), 113 deletions(-) create mode 100644 packages/util/LICENSE create mode 100644 packages/util/README.md create mode 100644 packages/util/package.json rename packages/{typescript-estree/src/ts-estree => util/src}/ast-node-types.ts (100%) rename packages/{typescript-estree/src/ts-estree => util/src}/index.ts (76%) rename packages/{typescript-estree/src/ts-estree => util/src}/ts-estree.ts (100%) rename packages/{typescript-estree => util}/src/ts-nodes.ts (100%) create mode 100644 packages/util/tsconfig.build.json create mode 100644 packages/util/tsconfig.json diff --git a/packages/eslint-plugin/package.json b/packages/eslint-plugin/package.json index 95c90865e32d..1323785e87bc 100644 --- a/packages/eslint-plugin/package.json +++ b/packages/eslint-plugin/package.json @@ -36,7 +36,7 @@ }, "dependencies": { "@typescript-eslint/parser": "1.4.2", - "@typescript-eslint/typescript-estree": "1.4.2", + "@typescript-eslint/util": "1.4.2", "requireindex": "^1.2.0", "tsutils": "^3.7.0" }, diff --git a/packages/eslint-plugin/src/rules/adjacent-overload-signatures.ts b/packages/eslint-plugin/src/rules/adjacent-overload-signatures.ts index 8e864c9c4a2a..313af768d5f8 100644 --- a/packages/eslint-plugin/src/rules/adjacent-overload-signatures.ts +++ b/packages/eslint-plugin/src/rules/adjacent-overload-signatures.ts @@ -1,4 +1,4 @@ -import { TSESTree, AST_NODE_TYPES } from '@typescript-eslint/typescript-estree'; +import { TSESTree, AST_NODE_TYPES } from '@typescript-eslint/util'; import * as util from '../util'; type RuleNode = diff --git a/packages/eslint-plugin/src/rules/array-type.ts b/packages/eslint-plugin/src/rules/array-type.ts index efc38b082fcd..bb6ee8639e9c 100644 --- a/packages/eslint-plugin/src/rules/array-type.ts +++ b/packages/eslint-plugin/src/rules/array-type.ts @@ -2,7 +2,7 @@ import { AST_NODE_TYPES, AST_TOKEN_TYPES, TSESTree, -} from '@typescript-eslint/typescript-estree'; +} from '@typescript-eslint/util'; import * as util from '../util'; /** diff --git a/packages/eslint-plugin/src/rules/ban-types.ts b/packages/eslint-plugin/src/rules/ban-types.ts index 77756ad15a87..298ae6f5b730 100644 --- a/packages/eslint-plugin/src/rules/ban-types.ts +++ b/packages/eslint-plugin/src/rules/ban-types.ts @@ -1,4 +1,4 @@ -import { TSESTree, AST_NODE_TYPES } from '@typescript-eslint/typescript-estree'; +import { TSESTree, AST_NODE_TYPES } from '@typescript-eslint/util'; import { ReportFixFunction } from 'ts-eslint'; import * as util from '../util'; diff --git a/packages/eslint-plugin/src/rules/camelcase.ts b/packages/eslint-plugin/src/rules/camelcase.ts index 009ba186aa16..d6989f8af5ff 100644 --- a/packages/eslint-plugin/src/rules/camelcase.ts +++ b/packages/eslint-plugin/src/rules/camelcase.ts @@ -1,4 +1,4 @@ -import { TSESTree, AST_NODE_TYPES } from '@typescript-eslint/typescript-estree'; +import { TSESTree, AST_NODE_TYPES } from '@typescript-eslint/util'; import baseRule from 'eslint/lib/rules/camelcase'; import * as util from '../util'; diff --git a/packages/eslint-plugin/src/rules/class-name-casing.ts b/packages/eslint-plugin/src/rules/class-name-casing.ts index 2e9a15ffde71..64dd05ba7201 100644 --- a/packages/eslint-plugin/src/rules/class-name-casing.ts +++ b/packages/eslint-plugin/src/rules/class-name-casing.ts @@ -1,5 +1,5 @@ import * as util from '../util'; -import { TSESTree, AST_NODE_TYPES } from '@typescript-eslint/typescript-estree'; +import { TSESTree, AST_NODE_TYPES } from '@typescript-eslint/util'; export default util.createRule({ name: 'class-name-casing', diff --git a/packages/eslint-plugin/src/rules/explicit-function-return-type.ts b/packages/eslint-plugin/src/rules/explicit-function-return-type.ts index e4f5dd46a3c5..607712997101 100644 --- a/packages/eslint-plugin/src/rules/explicit-function-return-type.ts +++ b/packages/eslint-plugin/src/rules/explicit-function-return-type.ts @@ -1,4 +1,4 @@ -import { TSESTree, AST_NODE_TYPES } from '@typescript-eslint/typescript-estree'; +import { TSESTree, AST_NODE_TYPES } from '@typescript-eslint/util'; import * as util from '../util'; type Options = [ diff --git a/packages/eslint-plugin/src/rules/explicit-member-accessibility.ts b/packages/eslint-plugin/src/rules/explicit-member-accessibility.ts index 66029faa5018..980b9954d641 100644 --- a/packages/eslint-plugin/src/rules/explicit-member-accessibility.ts +++ b/packages/eslint-plugin/src/rules/explicit-member-accessibility.ts @@ -1,4 +1,4 @@ -import { TSESTree } from '@typescript-eslint/typescript-estree'; +import { TSESTree } from '@typescript-eslint/util'; import * as util from '../util'; export default util.createRule({ diff --git a/packages/eslint-plugin/src/rules/indent.ts b/packages/eslint-plugin/src/rules/indent.ts index a3c6f5971d5e..6ff7a4688ad1 100644 --- a/packages/eslint-plugin/src/rules/indent.ts +++ b/packages/eslint-plugin/src/rules/indent.ts @@ -4,7 +4,7 @@ * This is done intentionally based on the internal implementation of the base indent rule. */ -import { TSESTree, AST_NODE_TYPES } from '@typescript-eslint/typescript-estree'; +import { TSESTree, AST_NODE_TYPES } from '@typescript-eslint/util'; import baseRule from 'eslint/lib/rules/indent'; import * as util from '../util'; diff --git a/packages/eslint-plugin/src/rules/member-delimiter-style.ts b/packages/eslint-plugin/src/rules/member-delimiter-style.ts index bfa2ca944395..1e455d11a6b2 100644 --- a/packages/eslint-plugin/src/rules/member-delimiter-style.ts +++ b/packages/eslint-plugin/src/rules/member-delimiter-style.ts @@ -1,4 +1,4 @@ -import { TSESTree, AST_NODE_TYPES } from '@typescript-eslint/typescript-estree'; +import { TSESTree, AST_NODE_TYPES } from '@typescript-eslint/util'; import * as util from '../util'; type Delimiter = 'comma' | 'none' | 'semi'; diff --git a/packages/eslint-plugin/src/rules/member-naming.ts b/packages/eslint-plugin/src/rules/member-naming.ts index 2efdf6ea3079..7c6ef6ccd599 100644 --- a/packages/eslint-plugin/src/rules/member-naming.ts +++ b/packages/eslint-plugin/src/rules/member-naming.ts @@ -1,4 +1,4 @@ -import { TSESTree } from '@typescript-eslint/typescript-estree'; +import { TSESTree } from '@typescript-eslint/util'; import * as util from '../util'; interface Config { diff --git a/packages/eslint-plugin/src/rules/member-ordering.ts b/packages/eslint-plugin/src/rules/member-ordering.ts index 6811cf5a2e42..88a11a6aa695 100644 --- a/packages/eslint-plugin/src/rules/member-ordering.ts +++ b/packages/eslint-plugin/src/rules/member-ordering.ts @@ -1,4 +1,4 @@ -import { TSESTree, AST_NODE_TYPES } from '@typescript-eslint/typescript-estree'; +import { TSESTree, AST_NODE_TYPES } from '@typescript-eslint/util'; import * as util from '../util'; type MessageIds = 'incorrectOrder'; diff --git a/packages/eslint-plugin/src/rules/no-array-constructor.ts b/packages/eslint-plugin/src/rules/no-array-constructor.ts index d6c92491be12..0911ffeed096 100644 --- a/packages/eslint-plugin/src/rules/no-array-constructor.ts +++ b/packages/eslint-plugin/src/rules/no-array-constructor.ts @@ -1,4 +1,4 @@ -import { TSESTree, AST_NODE_TYPES } from '@typescript-eslint/typescript-estree'; +import { TSESTree, AST_NODE_TYPES } from '@typescript-eslint/util'; import * as util from '../util'; export default util.createRule({ diff --git a/packages/eslint-plugin/src/rules/no-extraneous-class.ts b/packages/eslint-plugin/src/rules/no-extraneous-class.ts index 4799f211e7d6..e4f66813d0ce 100644 --- a/packages/eslint-plugin/src/rules/no-extraneous-class.ts +++ b/packages/eslint-plugin/src/rules/no-extraneous-class.ts @@ -1,4 +1,4 @@ -import { TSESTree, AST_NODE_TYPES } from '@typescript-eslint/typescript-estree'; +import { TSESTree, AST_NODE_TYPES } from '@typescript-eslint/util'; import * as util from '../util'; type Options = [ diff --git a/packages/eslint-plugin/src/rules/no-inferrable-types.ts b/packages/eslint-plugin/src/rules/no-inferrable-types.ts index 94b8533108dd..9c2bb6b02183 100644 --- a/packages/eslint-plugin/src/rules/no-inferrable-types.ts +++ b/packages/eslint-plugin/src/rules/no-inferrable-types.ts @@ -1,4 +1,4 @@ -import { TSESTree, AST_NODE_TYPES } from '@typescript-eslint/typescript-estree'; +import { TSESTree, AST_NODE_TYPES } from '@typescript-eslint/util'; import * as util from '../util'; type Options = [ diff --git a/packages/eslint-plugin/src/rules/no-misused-new.ts b/packages/eslint-plugin/src/rules/no-misused-new.ts index 5730475cd0de..f0f4d4ee1ad6 100644 --- a/packages/eslint-plugin/src/rules/no-misused-new.ts +++ b/packages/eslint-plugin/src/rules/no-misused-new.ts @@ -1,4 +1,4 @@ -import { TSESTree, AST_NODE_TYPES } from '@typescript-eslint/typescript-estree'; +import { TSESTree, AST_NODE_TYPES } from '@typescript-eslint/util'; import * as util from '../util'; export default util.createRule({ diff --git a/packages/eslint-plugin/src/rules/no-namespace.ts b/packages/eslint-plugin/src/rules/no-namespace.ts index ad6eaf611075..0ceb22c12e7d 100644 --- a/packages/eslint-plugin/src/rules/no-namespace.ts +++ b/packages/eslint-plugin/src/rules/no-namespace.ts @@ -1,4 +1,4 @@ -import { AST_NODE_TYPES, TSESTree } from '@typescript-eslint/typescript-estree'; +import { AST_NODE_TYPES, TSESTree } from '@typescript-eslint/util'; import * as util from '../util'; type Options = [ diff --git a/packages/eslint-plugin/src/rules/no-object-literal-type-assertion.ts b/packages/eslint-plugin/src/rules/no-object-literal-type-assertion.ts index a5e6e6788c96..fd484ac19d8d 100644 --- a/packages/eslint-plugin/src/rules/no-object-literal-type-assertion.ts +++ b/packages/eslint-plugin/src/rules/no-object-literal-type-assertion.ts @@ -1,4 +1,4 @@ -import { AST_NODE_TYPES, TSESTree } from '@typescript-eslint/typescript-estree'; +import { AST_NODE_TYPES, TSESTree } from '@typescript-eslint/util'; import * as util from '../util'; type Options = [ diff --git a/packages/eslint-plugin/src/rules/no-parameter-properties.ts b/packages/eslint-plugin/src/rules/no-parameter-properties.ts index 0d92c855aa8c..a0e6e5a3960f 100644 --- a/packages/eslint-plugin/src/rules/no-parameter-properties.ts +++ b/packages/eslint-plugin/src/rules/no-parameter-properties.ts @@ -1,4 +1,4 @@ -import { TSESTree, AST_NODE_TYPES } from '@typescript-eslint/typescript-estree'; +import { TSESTree, AST_NODE_TYPES } from '@typescript-eslint/util'; import * as util from '../util'; type Modifier = diff --git a/packages/eslint-plugin/src/rules/no-require-imports.ts b/packages/eslint-plugin/src/rules/no-require-imports.ts index 98039a91b7a8..6b07535edae1 100644 --- a/packages/eslint-plugin/src/rules/no-require-imports.ts +++ b/packages/eslint-plugin/src/rules/no-require-imports.ts @@ -1,4 +1,4 @@ -import { TSESTree } from '@typescript-eslint/typescript-estree'; +import { TSESTree } from '@typescript-eslint/util'; import * as util from '../util'; export default util.createRule({ diff --git a/packages/eslint-plugin/src/rules/no-this-alias.ts b/packages/eslint-plugin/src/rules/no-this-alias.ts index e98c9c39659e..4abaacf31ae3 100644 --- a/packages/eslint-plugin/src/rules/no-this-alias.ts +++ b/packages/eslint-plugin/src/rules/no-this-alias.ts @@ -1,4 +1,4 @@ -import { AST_NODE_TYPES, TSESTree } from '@typescript-eslint/typescript-estree'; +import { AST_NODE_TYPES, TSESTree } from '@typescript-eslint/util'; import * as util from '../util'; type Options = [ diff --git a/packages/eslint-plugin/src/rules/no-type-alias.ts b/packages/eslint-plugin/src/rules/no-type-alias.ts index c15795773a09..0114f9d31e67 100644 --- a/packages/eslint-plugin/src/rules/no-type-alias.ts +++ b/packages/eslint-plugin/src/rules/no-type-alias.ts @@ -1,4 +1,4 @@ -import { AST_NODE_TYPES, TSESTree } from '@typescript-eslint/typescript-estree'; +import { AST_NODE_TYPES, TSESTree } from '@typescript-eslint/util'; import { ReportDescriptor } from 'ts-eslint'; import * as util from '../util'; diff --git a/packages/eslint-plugin/src/rules/no-unnecessary-qualifier.ts b/packages/eslint-plugin/src/rules/no-unnecessary-qualifier.ts index d11b25271905..939a30358110 100644 --- a/packages/eslint-plugin/src/rules/no-unnecessary-qualifier.ts +++ b/packages/eslint-plugin/src/rules/no-unnecessary-qualifier.ts @@ -1,4 +1,4 @@ -import { TSESTree } from '@typescript-eslint/typescript-estree'; +import { TSESTree } from '@typescript-eslint/util'; import ts from 'typescript'; import * as tsutils from 'tsutils'; import * as util from '../util'; diff --git a/packages/eslint-plugin/src/rules/no-unnecessary-type-assertion.ts b/packages/eslint-plugin/src/rules/no-unnecessary-type-assertion.ts index ca86b6c9ca60..231ffe9ffcb7 100644 --- a/packages/eslint-plugin/src/rules/no-unnecessary-type-assertion.ts +++ b/packages/eslint-plugin/src/rules/no-unnecessary-type-assertion.ts @@ -1,4 +1,4 @@ -import { TSESTree } from '@typescript-eslint/typescript-estree'; +import { TSESTree } from '@typescript-eslint/util'; import * as tsutils from 'tsutils'; import ts from 'typescript'; import * as util from '../util'; diff --git a/packages/eslint-plugin/src/rules/no-unused-vars.ts b/packages/eslint-plugin/src/rules/no-unused-vars.ts index ede16241eed0..41f08b15d1bf 100644 --- a/packages/eslint-plugin/src/rules/no-unused-vars.ts +++ b/packages/eslint-plugin/src/rules/no-unused-vars.ts @@ -1,4 +1,4 @@ -import { AST_NODE_TYPES, TSESTree } from '@typescript-eslint/typescript-estree'; +import { AST_NODE_TYPES, TSESTree } from '@typescript-eslint/util'; import baseRule from 'eslint/lib/rules/no-unused-vars'; import * as util from '../util'; diff --git a/packages/eslint-plugin/src/rules/no-use-before-define.ts b/packages/eslint-plugin/src/rules/no-use-before-define.ts index 085bb02975dc..b62b9bd19473 100644 --- a/packages/eslint-plugin/src/rules/no-use-before-define.ts +++ b/packages/eslint-plugin/src/rules/no-use-before-define.ts @@ -1,4 +1,4 @@ -import { AST_NODE_TYPES, TSESTree } from '@typescript-eslint/typescript-estree'; +import { AST_NODE_TYPES, TSESTree } from '@typescript-eslint/util'; import { Scope } from 'ts-eslint'; import * as util from '../util'; diff --git a/packages/eslint-plugin/src/rules/no-useless-constructor.ts b/packages/eslint-plugin/src/rules/no-useless-constructor.ts index dcac02df8460..f79e3e301614 100644 --- a/packages/eslint-plugin/src/rules/no-useless-constructor.ts +++ b/packages/eslint-plugin/src/rules/no-useless-constructor.ts @@ -1,4 +1,4 @@ -import { TSESTree, AST_NODE_TYPES } from '@typescript-eslint/typescript-estree'; +import { TSESTree, AST_NODE_TYPES } from '@typescript-eslint/util'; import baseRule from 'eslint/lib/rules/no-useless-constructor'; import * as util from '../util'; diff --git a/packages/eslint-plugin/src/rules/no-var-requires.ts b/packages/eslint-plugin/src/rules/no-var-requires.ts index 67b61d13175a..1453d3d4ed85 100644 --- a/packages/eslint-plugin/src/rules/no-var-requires.ts +++ b/packages/eslint-plugin/src/rules/no-var-requires.ts @@ -1,4 +1,4 @@ -import { AST_NODE_TYPES } from '@typescript-eslint/typescript-estree'; +import { AST_NODE_TYPES } from '@typescript-eslint/util'; import * as util from '../util'; type Options = []; diff --git a/packages/eslint-plugin/src/rules/prefer-function-type.ts b/packages/eslint-plugin/src/rules/prefer-function-type.ts index e7a95d705e90..2cf0b9136bd0 100644 --- a/packages/eslint-plugin/src/rules/prefer-function-type.ts +++ b/packages/eslint-plugin/src/rules/prefer-function-type.ts @@ -2,7 +2,7 @@ import { AST_NODE_TYPES, TSESTree, AST_TOKEN_TYPES, -} from '@typescript-eslint/typescript-estree'; +} from '@typescript-eslint/util'; import * as util from '../util'; export default util.createRule({ diff --git a/packages/eslint-plugin/src/rules/prefer-interface.ts b/packages/eslint-plugin/src/rules/prefer-interface.ts index 10308d7e70ec..2a7efa8d132e 100644 --- a/packages/eslint-plugin/src/rules/prefer-interface.ts +++ b/packages/eslint-plugin/src/rules/prefer-interface.ts @@ -1,4 +1,4 @@ -import { TSESTree } from '@typescript-eslint/typescript-estree'; +import { TSESTree } from '@typescript-eslint/util'; import { RuleFix } from 'ts-eslint'; import * as util from '../util'; diff --git a/packages/eslint-plugin/src/rules/prefer-namespace-keyword.ts b/packages/eslint-plugin/src/rules/prefer-namespace-keyword.ts index 37eced4e545d..f40e2830829f 100644 --- a/packages/eslint-plugin/src/rules/prefer-namespace-keyword.ts +++ b/packages/eslint-plugin/src/rules/prefer-namespace-keyword.ts @@ -1,7 +1,7 @@ import { AST_NODE_TYPES, AST_TOKEN_TYPES, -} from '@typescript-eslint/typescript-estree'; +} from '@typescript-eslint/util'; import * as util from '../util'; export default util.createRule({ diff --git a/packages/eslint-plugin/src/rules/promise-function-async.ts b/packages/eslint-plugin/src/rules/promise-function-async.ts index 75d2ccdacc7e..b06f331bbda2 100644 --- a/packages/eslint-plugin/src/rules/promise-function-async.ts +++ b/packages/eslint-plugin/src/rules/promise-function-async.ts @@ -1,4 +1,4 @@ -import { TSESTree } from '@typescript-eslint/typescript-estree'; +import { TSESTree } from '@typescript-eslint/util'; import * as util from '../util'; type Options = [ diff --git a/packages/eslint-plugin/src/rules/require-array-sort-compare.ts b/packages/eslint-plugin/src/rules/require-array-sort-compare.ts index 8699c0cf0730..feb8715e57ed 100644 --- a/packages/eslint-plugin/src/rules/require-array-sort-compare.ts +++ b/packages/eslint-plugin/src/rules/require-array-sort-compare.ts @@ -1,5 +1,5 @@ import * as ts from 'typescript'; -import { TSESTree } from '@typescript-eslint/typescript-estree'; +import { TSESTree } from '@typescript-eslint/util'; import * as util from '../util'; export default util.createRule({ diff --git a/packages/eslint-plugin/src/rules/restrict-plus-operands.ts b/packages/eslint-plugin/src/rules/restrict-plus-operands.ts index 6b63f88a4f74..24c8a0334ee1 100644 --- a/packages/eslint-plugin/src/rules/restrict-plus-operands.ts +++ b/packages/eslint-plugin/src/rules/restrict-plus-operands.ts @@ -1,4 +1,4 @@ -import { TSESTree } from '@typescript-eslint/typescript-estree'; +import { TSESTree } from '@typescript-eslint/util'; import ts from 'typescript'; import * as util from '../util'; diff --git a/packages/eslint-plugin/src/rules/type-annotation-spacing.ts b/packages/eslint-plugin/src/rules/type-annotation-spacing.ts index 9deac5cd9774..d0923c91843f 100644 --- a/packages/eslint-plugin/src/rules/type-annotation-spacing.ts +++ b/packages/eslint-plugin/src/rules/type-annotation-spacing.ts @@ -1,5 +1,5 @@ import * as util from '../util'; -import { TSESTree } from '@typescript-eslint/typescript-estree'; +import { TSESTree } from '@typescript-eslint/util'; type Options = [ { diff --git a/packages/eslint-plugin/src/util/misc.ts b/packages/eslint-plugin/src/util/misc.ts index ab56cd4e694e..e60fde073788 100644 --- a/packages/eslint-plugin/src/util/misc.ts +++ b/packages/eslint-plugin/src/util/misc.ts @@ -2,7 +2,7 @@ * @fileoverview Really small utility functions that didn't deserve their own files */ -import { TSESTree, AST_NODE_TYPES } from '@typescript-eslint/typescript-estree'; +import { TSESTree, AST_NODE_TYPES } from '@typescript-eslint/util'; import RuleModule from 'ts-eslint'; import { SourceCode } from 'ts-eslint'; diff --git a/packages/eslint-plugin/tests/RuleTester.ts b/packages/eslint-plugin/tests/RuleTester.ts index d485611be444..404266ad80e9 100644 --- a/packages/eslint-plugin/tests/RuleTester.ts +++ b/packages/eslint-plugin/tests/RuleTester.ts @@ -1,5 +1,5 @@ import { ParserOptions } from '@typescript-eslint/parser'; -import { AST_NODE_TYPES } from '@typescript-eslint/typescript-estree'; +import { AST_NODE_TYPES } from '@typescript-eslint/util'; import { RuleTester as ESLintRuleTester } from 'eslint'; import * as path from 'path'; import RuleModule from 'ts-eslint'; diff --git a/packages/eslint-plugin/tests/eslint-rules/no-redeclare.test.ts b/packages/eslint-plugin/tests/eslint-rules/no-redeclare.test.ts index 6baa018ebf67..ad1d6e0a4585 100644 --- a/packages/eslint-plugin/tests/eslint-rules/no-redeclare.test.ts +++ b/packages/eslint-plugin/tests/eslint-rules/no-redeclare.test.ts @@ -1,5 +1,5 @@ import rule from 'eslint/lib/rules/no-redeclare'; -import { AST_NODE_TYPES } from '@typescript-eslint/typescript-estree'; +import { AST_NODE_TYPES } from '@typescript-eslint/util'; import { RuleTester } from '../RuleTester'; const ruleTester = new RuleTester({ diff --git a/packages/eslint-plugin/tests/rules/no-array-constructor.test.ts b/packages/eslint-plugin/tests/rules/no-array-constructor.test.ts index 5e920dd088fc..125ffd9311f9 100644 --- a/packages/eslint-plugin/tests/rules/no-array-constructor.test.ts +++ b/packages/eslint-plugin/tests/rules/no-array-constructor.test.ts @@ -1,4 +1,4 @@ -import { AST_NODE_TYPES } from '@typescript-eslint/typescript-estree'; +import { AST_NODE_TYPES } from '@typescript-eslint/util'; import rule from '../../src/rules/no-array-constructor'; import { RuleTester } from '../RuleTester'; diff --git a/packages/eslint-plugin/tests/rules/no-extraneous-class.test.ts b/packages/eslint-plugin/tests/rules/no-extraneous-class.test.ts index 0bee5ac63244..2a73f2ede881 100644 --- a/packages/eslint-plugin/tests/rules/no-extraneous-class.test.ts +++ b/packages/eslint-plugin/tests/rules/no-extraneous-class.test.ts @@ -1,4 +1,4 @@ -import { AST_NODE_TYPES } from '@typescript-eslint/typescript-estree'; +import { AST_NODE_TYPES } from '@typescript-eslint/util'; import rule from '../../src/rules/no-extraneous-class'; import { RuleTester } from '../RuleTester'; diff --git a/packages/eslint-plugin/tests/rules/no-for-in-array.test.ts b/packages/eslint-plugin/tests/rules/no-for-in-array.test.ts index ad2395a93d00..b2f6c9ba21dc 100644 --- a/packages/eslint-plugin/tests/rules/no-for-in-array.test.ts +++ b/packages/eslint-plugin/tests/rules/no-for-in-array.test.ts @@ -1,4 +1,4 @@ -import { AST_NODE_TYPES } from '@typescript-eslint/typescript-estree'; +import { AST_NODE_TYPES } from '@typescript-eslint/util'; import rule from '../../src/rules/no-for-in-array'; import { RuleTester, getFixturesRootDir } from '../RuleTester'; diff --git a/packages/eslint-plugin/tests/rules/no-this-alias.test.ts b/packages/eslint-plugin/tests/rules/no-this-alias.test.ts index ea0320ac343e..466b643acd8e 100644 --- a/packages/eslint-plugin/tests/rules/no-this-alias.test.ts +++ b/packages/eslint-plugin/tests/rules/no-this-alias.test.ts @@ -1,4 +1,4 @@ -import { AST_NODE_TYPES } from '@typescript-eslint/typescript-estree'; +import { AST_NODE_TYPES } from '@typescript-eslint/util'; import rule from '../../src/rules/no-this-alias'; import { RuleTester } from '../RuleTester'; diff --git a/packages/eslint-plugin/tests/rules/no-unnecessary-qualifier.test.ts b/packages/eslint-plugin/tests/rules/no-unnecessary-qualifier.test.ts index 6c2a18dacc89..7ff9c5f8fe87 100644 --- a/packages/eslint-plugin/tests/rules/no-unnecessary-qualifier.test.ts +++ b/packages/eslint-plugin/tests/rules/no-unnecessary-qualifier.test.ts @@ -1,7 +1,7 @@ import path from 'path'; import rule from '../../src/rules/no-unnecessary-qualifier'; import { RuleTester } from '../RuleTester'; -import { AST_NODE_TYPES } from '@typescript-eslint/typescript-estree'; +import { AST_NODE_TYPES } from '@typescript-eslint/util'; const messageId = 'unnecessaryQualifier'; const rootPath = path.join(process.cwd(), 'tests/fixtures/'); diff --git a/packages/eslint-plugin/tests/rules/no-use-before-define.test.ts b/packages/eslint-plugin/tests/rules/no-use-before-define.test.ts index e1bca791b33e..00b82dc216f7 100644 --- a/packages/eslint-plugin/tests/rules/no-use-before-define.test.ts +++ b/packages/eslint-plugin/tests/rules/no-use-before-define.test.ts @@ -1,6 +1,6 @@ import rule from '../../src/rules/no-use-before-define'; import { RuleTester } from '../RuleTester'; -import { AST_NODE_TYPES } from '@typescript-eslint/typescript-estree'; +import { AST_NODE_TYPES } from '@typescript-eslint/util'; const ruleTester = new RuleTester({ parser: '@typescript-eslint/parser', diff --git a/packages/eslint-plugin/tests/rules/prefer-function-type.test.ts b/packages/eslint-plugin/tests/rules/prefer-function-type.test.ts index 5743bcc7f4d8..610e3a70b64e 100644 --- a/packages/eslint-plugin/tests/rules/prefer-function-type.test.ts +++ b/packages/eslint-plugin/tests/rules/prefer-function-type.test.ts @@ -1,4 +1,4 @@ -import { AST_NODE_TYPES } from '@typescript-eslint/typescript-estree'; +import { AST_NODE_TYPES } from '@typescript-eslint/util'; import rule from '../../src/rules/prefer-function-type'; import { RuleTester } from '../RuleTester'; diff --git a/packages/eslint-plugin/typings/eslint-rules.d.ts b/packages/eslint-plugin/typings/eslint-rules.d.ts index b4094c05474f..747855edca3f 100644 --- a/packages/eslint-plugin/typings/eslint-rules.d.ts +++ b/packages/eslint-plugin/typings/eslint-rules.d.ts @@ -6,7 +6,7 @@ // } declare module 'eslint/lib/rules/arrow-parens' { - import { TSESTree } from '@typescript-eslint/typescript-estree'; + import { TSESTree } from '@typescript-eslint/util'; import RuleModule from 'ts-eslint'; const rule: RuleModule< @@ -28,7 +28,7 @@ declare module 'eslint/lib/rules/arrow-parens' { } declare module 'eslint/lib/rules/camelcase' { - import { TSESTree } from '@typescript-eslint/typescript-estree'; + import { TSESTree } from '@typescript-eslint/util'; import RuleModule from 'ts-eslint'; const rule: RuleModule< @@ -48,7 +48,7 @@ declare module 'eslint/lib/rules/camelcase' { } declare module 'eslint/lib/rules/indent' { - import { TSESTree } from '@typescript-eslint/typescript-estree'; + import { TSESTree } from '@typescript-eslint/util'; import RuleModule from 'ts-eslint'; type Listener = (node: TSESTree.Node) => void; @@ -146,7 +146,7 @@ declare module 'eslint/lib/rules/indent' { } declare module 'eslint/lib/rules/no-dupe-args' { - import { TSESTree } from '@typescript-eslint/typescript-estree'; + import { TSESTree } from '@typescript-eslint/util'; import RuleModule from 'ts-eslint'; const rule: RuleModule< @@ -161,7 +161,7 @@ declare module 'eslint/lib/rules/no-dupe-args' { } declare module 'eslint/lib/rules/no-implicit-globals' { - import { TSESTree } from '@typescript-eslint/typescript-estree'; + import { TSESTree } from '@typescript-eslint/util'; import RuleModule from 'ts-eslint'; const rule: RuleModule< @@ -175,7 +175,7 @@ declare module 'eslint/lib/rules/no-implicit-globals' { } declare module 'eslint/lib/rules/no-redeclare' { - import { TSESTree } from '@typescript-eslint/typescript-estree'; + import { TSESTree } from '@typescript-eslint/util'; import RuleModule from 'ts-eslint'; const rule: RuleModule< @@ -193,7 +193,7 @@ declare module 'eslint/lib/rules/no-redeclare' { } declare module 'eslint/lib/rules/no-restricted-globals' { - import { TSESTree } from '@typescript-eslint/typescript-estree'; + import { TSESTree } from '@typescript-eslint/util'; import RuleModule from 'ts-eslint'; const rule: RuleModule< @@ -212,7 +212,7 @@ declare module 'eslint/lib/rules/no-restricted-globals' { } declare module 'eslint/lib/rules/no-shadow' { - import { TSESTree } from '@typescript-eslint/typescript-estree'; + import { TSESTree } from '@typescript-eslint/util'; import RuleModule from 'ts-eslint'; const rule: RuleModule< @@ -232,7 +232,7 @@ declare module 'eslint/lib/rules/no-shadow' { } declare module 'eslint/lib/rules/no-undef' { - import { TSESTree } from '@typescript-eslint/typescript-estree'; + import { TSESTree } from '@typescript-eslint/util'; import RuleModule from 'ts-eslint'; const rule: RuleModule< @@ -250,7 +250,7 @@ declare module 'eslint/lib/rules/no-undef' { } declare module 'eslint/lib/rules/no-unused-vars' { - import { TSESTree } from '@typescript-eslint/typescript-estree'; + import { TSESTree } from '@typescript-eslint/util'; import RuleModule from 'ts-eslint'; const rule: RuleModule< @@ -275,7 +275,7 @@ declare module 'eslint/lib/rules/no-unused-vars' { } declare module 'eslint/lib/rules/no-use-before-define' { - import { TSESTree } from '@typescript-eslint/typescript-estree'; + import { TSESTree } from '@typescript-eslint/util'; import RuleModule from 'ts-eslint'; const rule: RuleModule< @@ -295,7 +295,7 @@ declare module 'eslint/lib/rules/no-use-before-define' { } declare module 'eslint/lib/rules/strict' { - import { TSESTree } from '@typescript-eslint/typescript-estree'; + import { TSESTree } from '@typescript-eslint/util'; import RuleModule from 'ts-eslint'; const rule: RuleModule< @@ -318,7 +318,7 @@ declare module 'eslint/lib/rules/strict' { } declare module 'eslint/lib/rules/no-useless-constructor' { - import { TSESTree } from '@typescript-eslint/typescript-estree'; + import { TSESTree } from '@typescript-eslint/util'; import RuleModule from 'ts-eslint'; const rule: RuleModule< diff --git a/packages/eslint-plugin/typings/ts-eslint.d.ts b/packages/eslint-plugin/typings/ts-eslint.d.ts index b757a1b59820..02e477dc25b4 100644 --- a/packages/eslint-plugin/typings/ts-eslint.d.ts +++ b/packages/eslint-plugin/typings/ts-eslint.d.ts @@ -8,7 +8,7 @@ The def is wrapped up in a fake module so that it can be used in eslint-rules.d. */ declare module 'ts-eslint' { - import { TSESTree } from '@typescript-eslint/typescript-estree'; + import { TSESTree } from '@typescript-eslint/util'; import { ParserServices } from '@typescript-eslint/parser'; import { AST, Linter, Rule } from 'eslint'; import { JSONSchema4 } from 'json-schema'; diff --git a/packages/parser/package.json b/packages/parser/package.json index 78dcd57c077d..92a52a0c9e22 100644 --- a/packages/parser/package.json +++ b/packages/parser/package.json @@ -38,6 +38,7 @@ }, "dependencies": { "@typescript-eslint/typescript-estree": "1.4.2", + "@typescript-eslint/util": "1.4.2", "eslint-scope": "^4.0.0", "eslint-visitor-keys": "^1.0.0" }, diff --git a/packages/parser/src/analyze-scope.ts b/packages/parser/src/analyze-scope.ts index 92390dbf0d34..2057bdb1ae06 100644 --- a/packages/parser/src/analyze-scope.ts +++ b/packages/parser/src/analyze-scope.ts @@ -1,16 +1,17 @@ -import { ScopeManager } from './scope/scope-manager'; +import { TSESTree, AST_NODE_TYPES } from '@typescript-eslint/util'; import { Definition, ParameterDefinition } from 'eslint-scope/lib/definition'; +import { + PatternVisitorCallback, + PatternVisitorOptions, +} from 'eslint-scope/lib/options'; import OriginalPatternVisitor from 'eslint-scope/lib/pattern-visitor'; import Reference from 'eslint-scope/lib/reference'; import OriginalReferencer from 'eslint-scope/lib/referencer'; import { getKeys as fallback } from 'eslint-visitor-keys'; + import { ParserOptions } from './parser-options'; +import { ScopeManager } from './scope/scope-manager'; import { visitorKeys as childVisitorKeys } from './visitor-keys'; -import { - PatternVisitorCallback, - PatternVisitorOptions, -} from 'eslint-scope/lib/options'; -import { TSESTree, AST_NODE_TYPES } from '@typescript-eslint/typescript-estree'; /** * Define the override function of `Scope#__define` for global augmentation. diff --git a/packages/parser/src/parser.ts b/packages/parser/src/parser.ts index fa5aa39dfdc4..92afa1567fc2 100644 --- a/packages/parser/src/parser.ts +++ b/packages/parser/src/parser.ts @@ -1,10 +1,10 @@ -import traverser from 'eslint/lib/util/traverser'; +import { AST_NODE_TYPES } from '@typescript-eslint/util'; import { - AST_NODE_TYPES, parseAndGenerateServices, ParserOptions as ParserOptionsTsESTree, ParserServices, } from '@typescript-eslint/typescript-estree'; +import traverser from 'eslint/lib/util/traverser'; import { analyzeScope } from './analyze-scope'; import { ParserOptions } from './parser-options'; import { visitorKeys } from './visitor-keys'; diff --git a/packages/parser/src/scope/scope-manager.ts b/packages/parser/src/scope/scope-manager.ts index fcdb88175cce..4d7cb156fea1 100644 --- a/packages/parser/src/scope/scope-manager.ts +++ b/packages/parser/src/scope/scope-manager.ts @@ -1,10 +1,9 @@ -import { TSESTree } from '@typescript-eslint/typescript-estree'; - +import { TSESTree } from '@typescript-eslint/util'; import EslintScopeManager, { ScopeManagerOptions, } from 'eslint-scope/lib/scope-manager'; -import { EmptyFunctionScope, EnumScope } from './scopes'; import { Scope } from 'eslint-scope/lib/scope'; +import { EmptyFunctionScope, EnumScope } from './scopes'; /** * based on eslint-scope diff --git a/packages/parser/src/scope/scopes.ts b/packages/parser/src/scope/scopes.ts index f5c27a69f798..0c44053525f0 100644 --- a/packages/parser/src/scope/scopes.ts +++ b/packages/parser/src/scope/scopes.ts @@ -1,6 +1,6 @@ +import { TSESTree } from '@typescript-eslint/util'; import { Scope } from 'eslint-scope/lib/scope'; import { ScopeManager } from './scope-manager'; -import { TSESTree } from '@typescript-eslint/typescript-estree'; /** The scope class for enum. */ export class EnumScope extends Scope { diff --git a/packages/parser/tests/lib/parser.ts b/packages/parser/tests/lib/parser.ts index 47d816fe0489..c2a25bc7802a 100644 --- a/packages/parser/tests/lib/parser.ts +++ b/packages/parser/tests/lib/parser.ts @@ -1,3 +1,4 @@ +import { AST_NODE_TYPES } from '@typescript-eslint/util'; import * as typescriptESTree from '@typescript-eslint/typescript-estree'; import { parse, parseForESLint, Syntax } from '../../src/parser'; import * as scope from '../../src/analyze-scope'; @@ -60,8 +61,8 @@ describe('parser', () => { }); }); - it('Syntax should contain a frozen object of typescriptESTree.AST_NODE_TYPES', () => { - expect(Syntax).toEqual(typescriptESTree.AST_NODE_TYPES); + it('Syntax should contain a frozen object of AST_NODE_TYPES', () => { + expect(Syntax).toEqual(AST_NODE_TYPES); expect( () => ((Syntax as any).ArrayExpression = 'foo'), ).toThrowErrorMatchingInlineSnapshot( diff --git a/packages/parser/tests/lib/visitor-keys.ts b/packages/parser/tests/lib/visitor-keys.ts index fd8ab4970f9b..ab6ca327bc05 100644 --- a/packages/parser/tests/lib/visitor-keys.ts +++ b/packages/parser/tests/lib/visitor-keys.ts @@ -1,4 +1,4 @@ -import { AST_NODE_TYPES } from '@typescript-eslint/typescript-estree'; +import { AST_NODE_TYPES } from '@typescript-eslint/util'; import { visitorKeys } from '../../src/visitor-keys'; //------------------------------------------------------------------------------ diff --git a/packages/parser/typings/eslint-scope.d.ts b/packages/parser/typings/eslint-scope.d.ts index 62172fd30b70..ef82834ca452 100644 --- a/packages/parser/typings/eslint-scope.d.ts +++ b/packages/parser/typings/eslint-scope.d.ts @@ -8,7 +8,7 @@ //----------------------------------------------------------------------- declare module 'eslint-scope/lib/options' { - import { TSESTree } from '@typescript-eslint/typescript-estree'; + import { TSESTree } from '@typescript-eslint/util'; export type PatternVisitorCallback = ( pattern: TSESTree.Identifier, info: { @@ -31,7 +31,7 @@ declare module 'eslint-scope/lib/options' { } declare module 'eslint-scope/lib/variable' { - import { TSESTree } from '@typescript-eslint/typescript-estree'; + import { TSESTree } from '@typescript-eslint/util'; import Reference from 'eslint-scope/lib/reference'; import { Definition } from 'eslint-scope/lib/definition'; @@ -45,7 +45,7 @@ declare module 'eslint-scope/lib/variable' { } declare module 'eslint-scope/lib/definition' { - import { TSESTree } from '@typescript-eslint/typescript-estree'; + import { TSESTree } from '@typescript-eslint/util'; export class Definition { type: string; @@ -78,7 +78,7 @@ declare module 'eslint-scope/lib/definition' { declare module 'eslint-scope/lib/pattern-visitor' { import ScopeManager from 'eslint-scope/lib/scope-manager'; - import { TSESTree } from '@typescript-eslint/typescript-estree'; + import { TSESTree } from '@typescript-eslint/util'; import { PatternVisitorCallback, PatternVisitorOptions, @@ -115,7 +115,7 @@ declare module 'eslint-scope/lib/pattern-visitor' { declare module 'eslint-scope/lib/referencer' { import { Scope } from 'eslint-scope/lib/scope'; import ScopeManager from 'eslint-scope/lib/scope-manager'; - import { TSESTree } from '@typescript-eslint/typescript-estree'; + import { TSESTree } from '@typescript-eslint/util'; import { PatternVisitorCallback, PatternVisitorOptions, @@ -192,7 +192,7 @@ declare module 'eslint-scope/lib/referencer' { } declare module 'eslint-scope/lib/scope' { - import { TSESTree } from '@typescript-eslint/typescript-estree'; + import { TSESTree } from '@typescript-eslint/util'; import Reference from 'eslint-scope/lib/reference'; import Variable from 'eslint-scope/lib/variable'; import ScopeManager from 'eslint-scope/lib/scope-manager'; @@ -378,7 +378,7 @@ declare module 'eslint-scope/lib/scope' { } declare module 'eslint-scope/lib/reference' { - import { TSESTree } from '@typescript-eslint/typescript-estree'; + import { TSESTree } from '@typescript-eslint/util'; import { Scope } from 'eslint-scope/lib/scope'; import Variable from 'eslint-scope/lib/variable'; @@ -402,7 +402,7 @@ declare module 'eslint-scope/lib/reference' { } declare module 'eslint-scope/lib/scope-manager' { - import { TSESTree } from '@typescript-eslint/typescript-estree'; + import { TSESTree } from '@typescript-eslint/util'; import { Scope } from 'eslint-scope/lib/scope'; import Variable from 'eslint-scope/lib/variable'; diff --git a/packages/typescript-estree/package.json b/packages/typescript-estree/package.json index 23188c301b9a..613a18238dea 100644 --- a/packages/typescript-estree/package.json +++ b/packages/typescript-estree/package.json @@ -37,7 +37,8 @@ }, "dependencies": { "lodash.unescape": "4.0.1", - "semver": "5.5.0" + "semver": "5.5.0", + "@typescript-eslint/util": "1.4.2" }, "peerDependencies": { "typescript": "*" diff --git a/packages/typescript-estree/src/ast-converter.ts b/packages/typescript-estree/src/ast-converter.ts index ac966c0889bb..fea7a6580a58 100644 --- a/packages/typescript-estree/src/ast-converter.ts +++ b/packages/typescript-estree/src/ast-converter.ts @@ -1,7 +1,7 @@ +import ts from 'typescript'; import { convertError, Converter } from './convert'; import { convertComments } from './convert-comments'; import { convertTokens } from './node-utils'; -import ts from 'typescript'; import { Extra } from './parser-options'; export default function astConverter( diff --git a/packages/typescript-estree/src/convert-comments.ts b/packages/typescript-estree/src/convert-comments.ts index 5474a71d66db..7f6c0672a884 100644 --- a/packages/typescript-estree/src/convert-comments.ts +++ b/packages/typescript-estree/src/convert-comments.ts @@ -1,6 +1,6 @@ +import { TSESTree } from '@typescript-eslint/util'; import ts from 'typescript'; import { getLocFor, getNodeContainer } from './node-utils'; -import { TSESTree } from './ts-estree'; /** * Converts a TypeScript comment to an Esprima comment. diff --git a/packages/typescript-estree/src/convert.ts b/packages/typescript-estree/src/convert.ts index d9f4486159ea..96cf81ff64aa 100644 --- a/packages/typescript-estree/src/convert.ts +++ b/packages/typescript-estree/src/convert.ts @@ -1,3 +1,4 @@ +import { AST_NODE_TYPES, TSESTree, TSNode } from '@typescript-eslint/util'; import ts from 'typescript'; import { canContainDirective, @@ -18,8 +19,6 @@ import { isOptional, unescapeStringLiteralText, } from './node-utils'; -import { AST_NODE_TYPES, TSESTree } from './ts-estree'; -import { TSNode } from './ts-nodes'; const SyntaxKind = ts.SyntaxKind; diff --git a/packages/typescript-estree/src/node-utils.ts b/packages/typescript-estree/src/node-utils.ts index b3e75f21edb3..01d5edc39b9d 100644 --- a/packages/typescript-estree/src/node-utils.ts +++ b/packages/typescript-estree/src/node-utils.ts @@ -1,6 +1,10 @@ -import ts from 'typescript'; +import { + AST_NODE_TYPES, + AST_TOKEN_TYPES, + TSESTree, +} from '@typescript-eslint/util'; import unescape from 'lodash.unescape'; -import { AST_NODE_TYPES, AST_TOKEN_TYPES, TSESTree } from './ts-estree'; +import ts from 'typescript'; const SyntaxKind = ts.SyntaxKind; diff --git a/packages/typescript-estree/src/parser-options.ts b/packages/typescript-estree/src/parser-options.ts index 9dadb456483b..4f9b0887e870 100644 --- a/packages/typescript-estree/src/parser-options.ts +++ b/packages/typescript-estree/src/parser-options.ts @@ -1,17 +1,16 @@ +import { TSESTree, TSNode } from '@typescript-eslint/util'; import { Program } from 'typescript'; -import { Token, Comment, Node } from './ts-estree/ts-estree'; -import { TSNode } from './ts-nodes'; export interface Extra { errorOnUnknownASTType: boolean; errorOnTypeScriptSyntacticAndSemanticIssues: boolean; useJSXTextNode: boolean; - tokens: null | Token[]; + tokens: null | TSESTree.Token[]; comment: boolean; code: string; range: boolean; loc: boolean; - comments: Comment[]; + comments: TSESTree.Comment[]; strict: boolean; jsx: boolean; log: Function; @@ -43,6 +42,6 @@ export interface ParserWeakMap { export interface ParserServices { program: Program | undefined; - esTreeNodeToTSNodeMap: ParserWeakMap | undefined; - tsNodeToESTreeNodeMap: ParserWeakMap | undefined; + esTreeNodeToTSNodeMap: ParserWeakMap | undefined; + tsNodeToESTreeNodeMap: ParserWeakMap | undefined; } diff --git a/packages/typescript-estree/src/parser.ts b/packages/typescript-estree/src/parser.ts index 28a0c157a29e..8c4416ef0ff4 100644 --- a/packages/typescript-estree/src/parser.ts +++ b/packages/typescript-estree/src/parser.ts @@ -1,15 +1,15 @@ -import { - calculateProjectParserOptions, - createProgram, -} from './tsconfig-parser'; +import { TSESTree } from '@typescript-eslint/util'; import semver from 'semver'; import ts from 'typescript'; import convert from './ast-converter'; import { convertError } from './convert'; import { firstDefined } from './node-utils'; -import { TSESTree } from './ts-estree'; import { Extra, ParserOptions, ParserServices } from './parser-options'; import { getFirstSemanticOrSyntacticError } from './semantic-errors'; +import { + calculateProjectParserOptions, + createProgram, +} from './tsconfig-parser'; /** * This needs to be kept in sync with the top-level README.md in the @@ -406,5 +406,4 @@ export function parseAndGenerateServices< }; } -export { AST_NODE_TYPES, AST_TOKEN_TYPES, TSESTree } from './ts-estree'; export { ParserOptions, ParserServices }; 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 7c8b4f2d5eb7..82342959932a 100644 --- a/packages/typescript-estree/tests/ast-alignment/fixtures-to-test.ts +++ b/packages/typescript-estree/tests/ast-alignment/fixtures-to-test.ts @@ -1,5 +1,5 @@ -import glob from 'glob'; import fs from 'fs'; +import glob from 'glob'; import path from 'path'; import jsxKnownIssues from '../../../shared-fixtures/jsx-known-issues'; diff --git a/packages/typescript-estree/tests/ast-alignment/parse.ts b/packages/typescript-estree/tests/ast-alignment/parse.ts index 6113f4ab5b80..84fb70f5b815 100644 --- a/packages/typescript-estree/tests/ast-alignment/parse.ts +++ b/packages/typescript-estree/tests/ast-alignment/parse.ts @@ -1,7 +1,7 @@ +import { ParserPlugin } from '@babel/parser'; import codeFrame from 'babel-code-frame'; import * as parser from '../../src/parser'; import * as parseUtils from './utils'; -import { ParserPlugin } from '@babel/parser'; function createError(message: string, line: number, column: number) { // Construct an error similar to the ones thrown by Babylon. diff --git a/packages/typescript-estree/tests/ast-alignment/utils.ts b/packages/typescript-estree/tests/ast-alignment/utils.ts index f661245be7f9..1d13119ca464 100644 --- a/packages/typescript-estree/tests/ast-alignment/utils.ts +++ b/packages/typescript-estree/tests/ast-alignment/utils.ts @@ -1,5 +1,5 @@ +import { AST_NODE_TYPES } from '@typescript-eslint/util'; import isPlainObject from 'lodash.isplainobject'; -import { AST_NODE_TYPES } from '../../src/ts-estree'; /** * By default, pretty-format (within Jest matchers) retains the names/types of nodes from the babylon AST, diff --git a/packages/typescript-estree/tests/lib/semanticInfo.ts b/packages/typescript-estree/tests/lib/semanticInfo.ts index ab7df7278a07..ba777493130d 100644 --- a/packages/typescript-estree/tests/lib/semanticInfo.ts +++ b/packages/typescript-estree/tests/lib/semanticInfo.ts @@ -9,11 +9,7 @@ import { parseCodeAndGenerateServices, } from '../../tools/test-utils'; import { parseAndGenerateServices } from '../../src/parser'; -import { - VariableDeclaration, - ClassDeclaration, - ClassProperty, -} from '../../src/ts-estree/ts-estree'; +import { TSESTree } from '@typescript-eslint/util'; const FIXTURES_DIR = './tests/fixtures/semanticInfo'; const testFiles = glob.sync(`${FIXTURES_DIR}/**/*.src.ts`); @@ -97,15 +93,16 @@ describe('semanticInfo', () => { ); expect(parseResult).toHaveProperty('services.esTreeNodeToTSNodeMap'); - const binaryExpression = (parseResult.ast.body[0] as VariableDeclaration) - .declarations[0].init!; + const binaryExpression = (parseResult.ast + .body[0] as TSESTree.VariableDeclaration).declarations[0].init!; const tsBinaryExpression = parseResult.services.esTreeNodeToTSNodeMap!.get( binaryExpression, ); expect(tsBinaryExpression.kind).toEqual(ts.SyntaxKind.BinaryExpression); const computedPropertyString = ((parseResult.ast - .body[1] as ClassDeclaration).body.body[0] as ClassProperty).key; + .body[1] as TSESTree.ClassDeclaration).body + .body[0] as TSESTree.ClassProperty).key; const tsComputedPropertyString = parseResult.services.esTreeNodeToTSNodeMap!.get( computedPropertyString, ); diff --git a/packages/util/LICENSE b/packages/util/LICENSE new file mode 100644 index 000000000000..7e7370143b26 --- /dev/null +++ b/packages/util/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2019 TypeScript ESLint and other contributors + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/packages/util/README.md b/packages/util/README.md new file mode 100644 index 000000000000..2e19dd9e95a8 --- /dev/null +++ b/packages/util/README.md @@ -0,0 +1,3 @@ +# @typescript-eslint/util + +Utilities for working with TypeScript + ESLint together diff --git a/packages/util/package.json b/packages/util/package.json new file mode 100644 index 000000000000..d6ee09b4da1a --- /dev/null +++ b/packages/util/package.json @@ -0,0 +1,40 @@ +{ + "name": "@typescript-eslint/util", + "version": "1.4.2", + "description": "Utilities for working with TypeScript + ESLint together", + "keywords": [ + "eslint", + "typescript", + "estree" + ], + "engines": { + "node": "^6.14.0 || ^8.10.0 || >=9.10.0" + }, + "files": [ + "dist", + "package.json", + "README.md", + "LICENSE" + ], + "repository": "typescript-eslint/typescript-eslint", + "bugs": { + "url": "https://github.com/typescript-eslint/typescript-eslint/issues" + }, + "license": "MIT", + "main": "dist/index.js", + "types": "dist/index.d.ts", + "scripts": { + "test": "jest --coverage", + "prebuild": "npm run clean", + "build": "tsc -p tsconfig.build.json", + "clean": "rimraf dist/", + "typecheck": "tsc --noEmit" + }, + "dependencies": { + }, + "devDependencies": { + }, + "peerDependencies": { + "typescript": "*" + } +} diff --git a/packages/typescript-estree/src/ts-estree/ast-node-types.ts b/packages/util/src/ast-node-types.ts similarity index 100% rename from packages/typescript-estree/src/ts-estree/ast-node-types.ts rename to packages/util/src/ast-node-types.ts diff --git a/packages/typescript-estree/src/ts-estree/index.ts b/packages/util/src/index.ts similarity index 76% rename from packages/typescript-estree/src/ts-estree/index.ts rename to packages/util/src/index.ts index 4a6b74aef1fc..8579cdd1686c 100644 --- a/packages/typescript-estree/src/ts-estree/index.ts +++ b/packages/util/src/index.ts @@ -1,5 +1,5 @@ import * as TSESTree from './ts-estree'; export * from './ast-node-types'; -export * from '../ts-nodes'; +export * from './ts-nodes'; export { TSESTree }; diff --git a/packages/typescript-estree/src/ts-estree/ts-estree.ts b/packages/util/src/ts-estree.ts similarity index 100% rename from packages/typescript-estree/src/ts-estree/ts-estree.ts rename to packages/util/src/ts-estree.ts diff --git a/packages/typescript-estree/src/ts-nodes.ts b/packages/util/src/ts-nodes.ts similarity index 100% rename from packages/typescript-estree/src/ts-nodes.ts rename to packages/util/src/ts-nodes.ts diff --git a/packages/util/tsconfig.build.json b/packages/util/tsconfig.build.json new file mode 100644 index 000000000000..901af460e416 --- /dev/null +++ b/packages/util/tsconfig.build.json @@ -0,0 +1,10 @@ +{ + "extends": "../../tsconfig.base.json", + "compilerOptions": { + "outDir": "./dist", + "resolveJsonModule": true + }, + "include": [ + "src", + ] +} diff --git a/packages/util/tsconfig.json b/packages/util/tsconfig.json new file mode 100644 index 000000000000..fc93e91c26d3 --- /dev/null +++ b/packages/util/tsconfig.json @@ -0,0 +1,11 @@ +{ + "extends": "./tsconfig.build.json", + "include": [ + "src", + "typings", + // include the parser's ambient typings because the parser exports them in its type defs + "../parser/typings", + "tests", + "tools" + ] +} From f3fad76062a6257b9562b1370a19f2ad5ae1bf64 Mon Sep 17 00:00:00 2001 From: Brad Zacher Date: Thu, 11 Apr 2019 10:47:09 -0700 Subject: [PATCH 2/8] Move ts-eslint into the utils package --- packages/eslint-plugin/src/rules/ban-types.ts | 5 +- .../eslint-plugin/src/rules/no-type-alias.ts | 5 +- .../src/rules/no-use-before-define.ts | 25 +- .../src/rules/prefer-interface.ts | 5 +- .../src/rules/require-array-sort-compare.ts | 2 +- .../src/rules/type-annotation-spacing.ts | 2 +- packages/eslint-plugin/src/util/createRule.ts | 17 +- .../src/util/getParserServices.ts | 4 +- packages/eslint-plugin/src/util/misc.ts | 12 +- packages/eslint-plugin/tests/RuleTester.ts | 61 +- .../eslint-plugin/tests/rules/indent.test.ts | 9 +- .../rules/type-annotation-spacing.test.ts | 7 +- .../eslint-plugin/typings/eslint-rules.d.ts | 70 +- packages/eslint-plugin/typings/ts-eslint.d.ts | 689 ------------------ packages/parser/src/analyze-scope.ts | 2 +- packages/parser/src/parser.ts | 8 +- packages/parser/src/scope/scope-manager.ts | 2 +- packages/parser/src/scope/scopes.ts | 2 +- packages/parser/tests/lib/parser.ts | 3 +- packages/parser/tests/lib/visitor-keys.ts | 2 +- packages/typescript-estree/package.json | 3 +- .../typescript-estree/src/convert-comments.ts | 2 +- packages/typescript-estree/src/convert.ts | 2 +- packages/typescript-estree/src/node-utils.ts | 2 +- .../typescript-estree/src/parser-options.ts | 2 +- packages/typescript-estree/src/parser.ts | 3 +- .../src/ts-estree}/ast-node-types.ts | 0 .../typescript-estree/src/ts-estree/index.ts | 5 + .../src/ts-estree}/ts-estree.ts | 0 .../src/ts-estree}/ts-nodes.ts | 0 .../tests/ast-alignment/utils.ts | 2 +- .../tests/lib/semanticInfo.ts | 2 +- .../typescript-estree/tsconfig.build.json | 3 +- packages/typescript-estree/tsconfig.json | 5 +- packages/util/src/index.ts | 17 +- packages/util/src/ts-eslint/ParserOptions.ts | 21 + packages/util/src/ts-eslint/Rule.ts | 382 ++++++++++ packages/util/src/ts-eslint/RuleTester.ts | 59 ++ packages/util/src/ts-eslint/Scope.ts | 106 +++ packages/util/src/ts-eslint/SourceCode.ts | 190 +++++ packages/util/src/ts-eslint/index.ts | 5 + packages/util/tsconfig.build.json | 1 + packages/util/tsconfig.json | 2 - 43 files changed, 881 insertions(+), 865 deletions(-) delete mode 100644 packages/eslint-plugin/typings/ts-eslint.d.ts rename packages/{util/src => typescript-estree/src/ts-estree}/ast-node-types.ts (100%) create mode 100644 packages/typescript-estree/src/ts-estree/index.ts rename packages/{util/src => typescript-estree/src/ts-estree}/ts-estree.ts (100%) rename packages/{util/src => typescript-estree/src/ts-estree}/ts-nodes.ts (100%) create mode 100644 packages/util/src/ts-eslint/ParserOptions.ts create mode 100644 packages/util/src/ts-eslint/Rule.ts create mode 100644 packages/util/src/ts-eslint/RuleTester.ts create mode 100644 packages/util/src/ts-eslint/Scope.ts create mode 100644 packages/util/src/ts-eslint/SourceCode.ts create mode 100644 packages/util/src/ts-eslint/index.ts diff --git a/packages/eslint-plugin/src/rules/ban-types.ts b/packages/eslint-plugin/src/rules/ban-types.ts index 298ae6f5b730..c92822f40318 100644 --- a/packages/eslint-plugin/src/rules/ban-types.ts +++ b/packages/eslint-plugin/src/rules/ban-types.ts @@ -1,5 +1,4 @@ -import { TSESTree, AST_NODE_TYPES } from '@typescript-eslint/util'; -import { ReportFixFunction } from 'ts-eslint'; +import { TSESLint, TSESTree, AST_NODE_TYPES } from '@typescript-eslint/util'; import * as util from '../util'; type Options = [ @@ -94,7 +93,7 @@ export default util.createRule({ let customMessage = ''; const bannedCfgValue = bannedTypes[node.name]; - let fix: ReportFixFunction | null = null; + let fix: TSESLint.ReportFixFunction | null = null; if (typeof bannedCfgValue === 'string') { customMessage += ` ${bannedCfgValue}`; diff --git a/packages/eslint-plugin/src/rules/no-type-alias.ts b/packages/eslint-plugin/src/rules/no-type-alias.ts index 0114f9d31e67..1773fa8da287 100644 --- a/packages/eslint-plugin/src/rules/no-type-alias.ts +++ b/packages/eslint-plugin/src/rules/no-type-alias.ts @@ -1,5 +1,4 @@ -import { AST_NODE_TYPES, TSESTree } from '@typescript-eslint/util'; -import { ReportDescriptor } from 'ts-eslint'; +import { AST_NODE_TYPES, TSESLint, TSESTree } from '@typescript-eslint/util'; import * as util from '../util'; type Options = [ @@ -193,7 +192,7 @@ export default util.createRule({ compositionType: string | undefined, isRoot: boolean, type?: string, - ): ReportDescriptor { + ): TSESLint.ReportDescriptor { if (isRoot) { return { node, diff --git a/packages/eslint-plugin/src/rules/no-use-before-define.ts b/packages/eslint-plugin/src/rules/no-use-before-define.ts index b62b9bd19473..5f6d892c5f87 100644 --- a/packages/eslint-plugin/src/rules/no-use-before-define.ts +++ b/packages/eslint-plugin/src/rules/no-use-before-define.ts @@ -1,5 +1,4 @@ -import { AST_NODE_TYPES, TSESTree } from '@typescript-eslint/util'; -import { Scope } from 'ts-eslint'; +import { AST_NODE_TYPES, TSESLint, TSESTree } from '@typescript-eslint/util'; import * as util from '../util'; const SENTINEL_TYPE = /^(?:(?:Function|Class)(?:Declaration|Expression)|ArrowFunctionExpression|CatchClause|ImportDeclaration|ExportNamedDeclaration)$/; @@ -28,14 +27,14 @@ function parseOptions(options: string | Config | null): Required { /** * Checks whether or not a given scope is a top level scope. */ -function isTopLevelScope(scope: Scope.Scope): boolean { +function isTopLevelScope(scope: TSESLint.Scope.Scope): boolean { return scope.type === 'module' || scope.type === 'global'; } /** * Checks whether or not a given variable is a function declaration. */ -function isFunction(variable: Scope.Variable): boolean { +function isFunction(variable: TSESLint.Scope.Variable): boolean { return variable.defs[0].type === 'FunctionName'; } @@ -43,8 +42,8 @@ function isFunction(variable: Scope.Variable): boolean { * Checks whether or not a given variable is a class declaration in an upper function scope. */ function isOuterClass( - variable: Scope.Variable, - reference: Scope.Reference, + variable: TSESLint.Scope.Variable, + reference: TSESLint.Scope.Reference, ): boolean { if (variable.defs[0].type !== 'ClassName') { return false; @@ -64,8 +63,8 @@ function isOuterClass( * Checks whether or not a given variable is a variable declaration in an upper function scope. */ function isOuterVariable( - variable: Scope.Variable, - reference: Scope.Reference, + variable: TSESLint.Scope.Variable, + reference: TSESLint.Scope.Reference, ): boolean { if (variable.defs[0].type !== 'Variable') { return false; @@ -102,8 +101,8 @@ function isInRange( * - for (var a of a) {} */ function isInInitializer( - variable: Scope.Variable, - reference: Scope.Reference, + variable: TSESLint.Scope.Variable, + reference: TSESLint.Scope.Reference, ): boolean { if (variable.scope !== reference.from) { return false; @@ -199,8 +198,8 @@ export default util.createRule({ * @param reference The reference to the variable */ function isForbidden( - variable: Scope.Variable, - reference: Scope.Reference, + variable: TSESLint.Scope.Variable, + reference: TSESLint.Scope.Reference, ): boolean { if (isFunction(variable)) { return !!options.functions; @@ -217,7 +216,7 @@ export default util.createRule({ /** * Finds and validates all variables in a given scope. */ - function findVariablesInScope(scope: Scope.Scope): void { + function findVariablesInScope(scope: TSESLint.Scope.Scope): void { scope.references.forEach(reference => { const variable = reference.resolved; diff --git a/packages/eslint-plugin/src/rules/prefer-interface.ts b/packages/eslint-plugin/src/rules/prefer-interface.ts index 2a7efa8d132e..d7391b674bd6 100644 --- a/packages/eslint-plugin/src/rules/prefer-interface.ts +++ b/packages/eslint-plugin/src/rules/prefer-interface.ts @@ -1,5 +1,4 @@ -import { TSESTree } from '@typescript-eslint/util'; -import { RuleFix } from 'ts-eslint'; +import { TSESLint, TSESTree } from '@typescript-eslint/util'; import * as util from '../util'; export default util.createRule({ @@ -33,7 +32,7 @@ export default util.createRule({ messageId: 'interfaceOverType', fix(fixer) { const typeNode = node.typeParameters || node.id; - const fixes: RuleFix[] = []; + const fixes: TSESLint.RuleFix[] = []; const firstToken = sourceCode.getFirstToken(node); if (firstToken) { diff --git a/packages/eslint-plugin/src/rules/require-array-sort-compare.ts b/packages/eslint-plugin/src/rules/require-array-sort-compare.ts index feb8715e57ed..63ab9806c790 100644 --- a/packages/eslint-plugin/src/rules/require-array-sort-compare.ts +++ b/packages/eslint-plugin/src/rules/require-array-sort-compare.ts @@ -1,5 +1,5 @@ -import * as ts from 'typescript'; import { TSESTree } from '@typescript-eslint/util'; +import ts from 'typescript'; import * as util from '../util'; export default util.createRule({ diff --git a/packages/eslint-plugin/src/rules/type-annotation-spacing.ts b/packages/eslint-plugin/src/rules/type-annotation-spacing.ts index d0923c91843f..4147c255499d 100644 --- a/packages/eslint-plugin/src/rules/type-annotation-spacing.ts +++ b/packages/eslint-plugin/src/rules/type-annotation-spacing.ts @@ -1,5 +1,5 @@ -import * as util from '../util'; import { TSESTree } from '@typescript-eslint/util'; +import * as util from '../util'; type Options = [ { diff --git a/packages/eslint-plugin/src/util/createRule.ts b/packages/eslint-plugin/src/util/createRule.ts index 97b0f18c51e1..75db1bace12a 100644 --- a/packages/eslint-plugin/src/util/createRule.ts +++ b/packages/eslint-plugin/src/util/createRule.ts @@ -1,9 +1,4 @@ -import RuleModule, { - RuleListener, - RuleMetaData, - RuleMetaDataDocs, - RuleContext, -} from 'ts-eslint'; +import { TSESLint } from '@typescript-eslint/util'; import { applyDefault } from './applyDefault'; // note - cannot migrate this to an import statement because it will make TSC copy the package.json to the dist folder @@ -16,19 +11,19 @@ type RemoveProps< > = Pick>; // we'll automatically add the url + tslint description for people. -type CreateRuleMetaDocs = RemoveProps & { +type CreateRuleMetaDocs = RemoveProps & { tslintName?: string; }; type CreateRuleMeta = { docs: CreateRuleMetaDocs; -} & RemoveProps, 'docs'>; +} & RemoveProps, 'docs'>; // This function will get much easier to call when this is merged https://github.com/Microsoft/TypeScript/pull/26349 // TODO - when the above rule lands; add type checking for the context.report `data` property export function createRule< TOptions extends Readonly, TMessageIds extends string, - TRuleListener extends RuleListener = RuleListener + TRuleListener extends TSESLint.RuleListener = TSESLint.RuleListener >({ name, meta, @@ -39,10 +34,10 @@ export function createRule< meta: CreateRuleMeta; defaultOptions: TOptions; create: ( - context: RuleContext, + context: TSESLint.RuleContext, optionsWithDefault: TOptions, ) => TRuleListener; -}): RuleModule { +}): TSESLint.RuleModule { return { meta: { ...meta, diff --git a/packages/eslint-plugin/src/util/getParserServices.ts b/packages/eslint-plugin/src/util/getParserServices.ts index a63297708cce..6058620a754b 100644 --- a/packages/eslint-plugin/src/util/getParserServices.ts +++ b/packages/eslint-plugin/src/util/getParserServices.ts @@ -1,5 +1,5 @@ import { ParserServices } from '@typescript-eslint/parser'; -import { RuleContext } from 'ts-eslint'; +import { TSESLint } from '@typescript-eslint/util'; type RequiredParserServices = { [k in keyof ParserServices]: Exclude @@ -11,7 +11,7 @@ type RequiredParserServices = { export function getParserServices< TMessageIds extends string, TOptions extends any[] ->(context: RuleContext): RequiredParserServices { +>(context: TSESLint.RuleContext): RequiredParserServices { if ( !context.parserServices || !context.parserServices.program || diff --git a/packages/eslint-plugin/src/util/misc.ts b/packages/eslint-plugin/src/util/misc.ts index e60fde073788..ef4c6ce67488 100644 --- a/packages/eslint-plugin/src/util/misc.ts +++ b/packages/eslint-plugin/src/util/misc.ts @@ -2,9 +2,7 @@ * @fileoverview Really small utility functions that didn't deserve their own files */ -import { TSESTree, AST_NODE_TYPES } from '@typescript-eslint/util'; -import RuleModule from 'ts-eslint'; -import { SourceCode } from 'ts-eslint'; +import { AST_NODE_TYPES, TSESLint, TSESTree } from '@typescript-eslint/util'; /** * Check if the context file name is *.ts or *.tsx @@ -27,7 +25,7 @@ export function upperCaseFirst(str: string) { return str[0].toUpperCase() + str.slice(1); } -type InferOptionsTypeFromRuleNever = T extends RuleModule< +type InferOptionsTypeFromRuleNever = T extends TSESLint.RuleModule< never, infer TOptions > @@ -36,7 +34,7 @@ type InferOptionsTypeFromRuleNever = T extends RuleModule< /** * Uses type inference to fetch the TOptions type from the given RuleModule */ -export type InferOptionsTypeFromRule = T extends RuleModule< +export type InferOptionsTypeFromRule = T extends TSESLint.RuleModule< any, infer TOptions > @@ -46,7 +44,7 @@ export type InferOptionsTypeFromRule = T extends RuleModule< /** * Uses type inference to fetch the TMessageIds type from the given RuleModule */ -export type InferMessageIdsTypeFromRule = T extends RuleModule< +export type InferMessageIdsTypeFromRule = T extends TSESLint.RuleModule< infer TMessageIds, any > @@ -71,7 +69,7 @@ export function getNameFromPropertyName( */ export function getNameFromClassMember( methodDefinition: TSESTree.MethodDefinition | TSESTree.ClassProperty, - sourceCode: SourceCode, + sourceCode: TSESLint.SourceCode, ): string { if (keyCanBeReadAsPropertyName(methodDefinition.key)) { return getNameFromPropertyName(methodDefinition.key); diff --git a/packages/eslint-plugin/tests/RuleTester.ts b/packages/eslint-plugin/tests/RuleTester.ts index 404266ad80e9..8383d6170ce6 100644 --- a/packages/eslint-plugin/tests/RuleTester.ts +++ b/packages/eslint-plugin/tests/RuleTester.ts @@ -1,61 +1,8 @@ -import { ParserOptions } from '@typescript-eslint/parser'; -import { AST_NODE_TYPES } from '@typescript-eslint/util'; +import { TSESLint } from '@typescript-eslint/util'; import { RuleTester as ESLintRuleTester } from 'eslint'; import * as path from 'path'; -import RuleModule from 'ts-eslint'; -interface ValidTestCase> { - code: string; - options?: TOptions; - filename?: string; - parserOptions?: ParserOptions; - settings?: Record; - parser?: string; - globals?: Record; - env?: { - browser?: boolean; - }; -} - -interface InvalidTestCase< - TMessageIds extends string, - TOptions extends Readonly -> extends ValidTestCase { - errors: TestCaseError[]; - output?: string; -} - -interface TestCaseError { - messageId: TMessageIds; - data?: Record; - type?: AST_NODE_TYPES; - line?: number; - column?: number; -} - -interface RunTests< - TMessageIds extends string, - TOptions extends Readonly -> { - // RuleTester.run also accepts strings for valid cases - valid: (ValidTestCase | string)[]; - invalid: InvalidTestCase[]; -} - -declare class RuleTesterTyped { - run>( - name: string, - rule: RuleModule, - tests: RunTests, - ): void; -} - -const RuleTester = (ESLintRuleTester as any) as { - new (config?: { - parser: '@typescript-eslint/parser'; - parserOptions?: ParserOptions; - }): RuleTesterTyped; -}; +const RuleTester: TSESLint.RuleTester = (ESLintRuleTester as any); function getFixturesRootDir() { return path.join(process.cwd(), 'tests/fixtures/'); @@ -63,9 +10,5 @@ function getFixturesRootDir() { export { RuleTester, - RunTests, - TestCaseError, - InvalidTestCase, - ValidTestCase, getFixturesRootDir, }; diff --git a/packages/eslint-plugin/tests/rules/indent.test.ts b/packages/eslint-plugin/tests/rules/indent.test.ts index d845a8711721..fde1d4ea09cc 100644 --- a/packages/eslint-plugin/tests/rules/indent.test.ts +++ b/packages/eslint-plugin/tests/rules/indent.test.ts @@ -1,5 +1,6 @@ +import { TSESLint } from '@typescript-eslint/util'; +import { RuleTester } from '../RuleTester'; import rule from '../../src/rules/indent'; -import { RuleTester, RunTests, TestCaseError } from '../RuleTester'; import { InferMessageIdsTypeFromRule, InferOptionsTypeFromRule, @@ -608,7 +609,7 @@ type Foo = string | { `, ], }, -].reduce>( +].reduce>( (acc, testCase) => { const indent = ' '; @@ -630,7 +631,7 @@ type Foo = string | { output: code, errors: code .split('\n') - .map | null>((line, lineNum) => { + .map | null>((line, lineNum) => { const indentCount = line.split(indent).length - 1; const spaceCount = indentCount * indent.length; @@ -649,7 +650,7 @@ type Foo = string | { }; }) .filter( - (error): error is TestCaseError => error !== null, + (error): error is TSESLint.TestCaseError => error !== null, ), }); }); diff --git a/packages/eslint-plugin/tests/rules/type-annotation-spacing.test.ts b/packages/eslint-plugin/tests/rules/type-annotation-spacing.test.ts index 05f75faf4086..52aeee549560 100644 --- a/packages/eslint-plugin/tests/rules/type-annotation-spacing.test.ts +++ b/packages/eslint-plugin/tests/rules/type-annotation-spacing.test.ts @@ -1,5 +1,6 @@ +import { TSESLint } from '@typescript-eslint/util'; +import { RuleTester } from '../RuleTester'; import rule from '../../src/rules/type-annotation-spacing'; -import { RuleTester, InvalidTestCase, ValidTestCase } from '../RuleTester'; import { InferMessageIdsTypeFromRule, InferOptionsTypeFromRule, @@ -6317,7 +6318,7 @@ type Foo = { const operators = ['+?:', '-?:']; ruleTester.run('type-annotation-spacing', rule, { - valid: operators.reduce[]>( + valid: operators.reduce[]>( (validCases, operator) => validCases.concat([ { @@ -6359,7 +6360,7 @@ ruleTester.run('type-annotation-spacing', rule, { ]), [], ), - invalid: operators.reduce[]>( + invalid: operators.reduce[]>( (invalidCases, operator) => invalidCases.concat([ // space before + after cases diff --git a/packages/eslint-plugin/typings/eslint-rules.d.ts b/packages/eslint-plugin/typings/eslint-rules.d.ts index 747855edca3f..34ffca573d27 100644 --- a/packages/eslint-plugin/typings/eslint-rules.d.ts +++ b/packages/eslint-plugin/typings/eslint-rules.d.ts @@ -1,15 +1,13 @@ // don't provide a general import case so that people have to strictly type out a declaration -// declare module 'eslint/lib/rules/*' { -// import RuleModule from 'ts-eslint'; -// const rule: RuleModule; +// declare module 'eslint/lib/rules/*' TSESLint, { +// const rule: TSESLint.RuleModule; // export = rule; // } declare module 'eslint/lib/rules/arrow-parens' { - import { TSESTree } from '@typescript-eslint/util'; - import RuleModule from 'ts-eslint'; + import { TSESLint, TSESTree } from '@typescript-eslint/util'; - const rule: RuleModule< + const rule: TSESLint.RuleModule< | 'unexpectedParens' | 'expectedParens' | 'unexpectedParensInline' @@ -28,10 +26,9 @@ declare module 'eslint/lib/rules/arrow-parens' { } declare module 'eslint/lib/rules/camelcase' { - import { TSESTree } from '@typescript-eslint/util'; - import RuleModule from 'ts-eslint'; + import { TSESLint, TSESTree } from '@typescript-eslint/util'; - const rule: RuleModule< + const rule: TSESLint.RuleModule< 'notCamelCase', [ { @@ -48,12 +45,11 @@ declare module 'eslint/lib/rules/camelcase' { } declare module 'eslint/lib/rules/indent' { - import { TSESTree } from '@typescript-eslint/util'; - import RuleModule from 'ts-eslint'; + import { TSESLint, TSESTree } from '@typescript-eslint/util'; type Listener = (node: TSESTree.Node) => void; type ElementList = number | 'first' | 'off'; - const rule: RuleModule< + const rule: TSESLint.RuleModule< 'wrongIndentation', [ 'tab' | number, @@ -146,10 +142,9 @@ declare module 'eslint/lib/rules/indent' { } declare module 'eslint/lib/rules/no-dupe-args' { - import { TSESTree } from '@typescript-eslint/util'; - import RuleModule from 'ts-eslint'; + import { TSESLint, TSESTree } from '@typescript-eslint/util'; - const rule: RuleModule< + const rule: TSESLint.RuleModule< 'unexpected', [], { @@ -161,10 +156,9 @@ declare module 'eslint/lib/rules/no-dupe-args' { } declare module 'eslint/lib/rules/no-implicit-globals' { - import { TSESTree } from '@typescript-eslint/util'; - import RuleModule from 'ts-eslint'; + import { TSESLint, TSESTree } from '@typescript-eslint/util'; - const rule: RuleModule< + const rule: TSESLint.RuleModule< never, [], { @@ -175,10 +169,9 @@ declare module 'eslint/lib/rules/no-implicit-globals' { } declare module 'eslint/lib/rules/no-redeclare' { - import { TSESTree } from '@typescript-eslint/util'; - import RuleModule from 'ts-eslint'; + import { TSESLint, TSESTree } from '@typescript-eslint/util'; - const rule: RuleModule< + const rule: TSESLint.RuleModule< never, [ { @@ -193,10 +186,9 @@ declare module 'eslint/lib/rules/no-redeclare' { } declare module 'eslint/lib/rules/no-restricted-globals' { - import { TSESTree } from '@typescript-eslint/util'; - import RuleModule from 'ts-eslint'; + import { TSESLint, TSESTree } from '@typescript-eslint/util'; - const rule: RuleModule< + const rule: TSESLint.RuleModule< never, ( | string @@ -212,10 +204,9 @@ declare module 'eslint/lib/rules/no-restricted-globals' { } declare module 'eslint/lib/rules/no-shadow' { - import { TSESTree } from '@typescript-eslint/util'; - import RuleModule from 'ts-eslint'; + import { TSESLint, TSESTree } from '@typescript-eslint/util'; - const rule: RuleModule< + const rule: TSESLint.RuleModule< never, [ { @@ -232,10 +223,9 @@ declare module 'eslint/lib/rules/no-shadow' { } declare module 'eslint/lib/rules/no-undef' { - import { TSESTree } from '@typescript-eslint/util'; - import RuleModule from 'ts-eslint'; + import { TSESLint, TSESTree } from '@typescript-eslint/util'; - const rule: RuleModule< + const rule: TSESLint.RuleModule< 'undef', [ { @@ -250,10 +240,9 @@ declare module 'eslint/lib/rules/no-undef' { } declare module 'eslint/lib/rules/no-unused-vars' { - import { TSESTree } from '@typescript-eslint/util'; - import RuleModule from 'ts-eslint'; + import { TSESLint, TSESTree } from '@typescript-eslint/util'; - const rule: RuleModule< + const rule: TSESLint.RuleModule< never, ( | 'all' @@ -275,10 +264,9 @@ declare module 'eslint/lib/rules/no-unused-vars' { } declare module 'eslint/lib/rules/no-use-before-define' { - import { TSESTree } from '@typescript-eslint/util'; - import RuleModule from 'ts-eslint'; + import { TSESLint, TSESTree } from '@typescript-eslint/util'; - const rule: RuleModule< + const rule: TSESLint.RuleModule< never, ( | 'nofunc' @@ -295,10 +283,9 @@ declare module 'eslint/lib/rules/no-use-before-define' { } declare module 'eslint/lib/rules/strict' { - import { TSESTree } from '@typescript-eslint/util'; - import RuleModule from 'ts-eslint'; + import { TSESLint, TSESTree } from '@typescript-eslint/util'; - const rule: RuleModule< + const rule: TSESLint.RuleModule< | 'function' | 'global' | 'multiple' @@ -318,10 +305,9 @@ declare module 'eslint/lib/rules/strict' { } declare module 'eslint/lib/rules/no-useless-constructor' { - import { TSESTree } from '@typescript-eslint/util'; - import RuleModule from 'ts-eslint'; + import { TSESLint, TSESTree } from '@typescript-eslint/util'; - const rule: RuleModule< + const rule: TSESLint.RuleModule< never, [], { diff --git a/packages/eslint-plugin/typings/ts-eslint.d.ts b/packages/eslint-plugin/typings/ts-eslint.d.ts deleted file mode 100644 index 02e477dc25b4..000000000000 --- a/packages/eslint-plugin/typings/ts-eslint.d.ts +++ /dev/null @@ -1,689 +0,0 @@ -/* -Redefine these types for these reasons: -1) We can better control what properties are option and what are not. -2) We have to replace definitions with our definitions which use our typescript-estree types. -3) We can better document the fields so it's easier for new contributers to understand. - -The def is wrapped up in a fake module so that it can be used in eslint-rules.d.ts -*/ - -declare module 'ts-eslint' { - import { TSESTree } from '@typescript-eslint/util'; - import { ParserServices } from '@typescript-eslint/parser'; - import { AST, Linter, Rule } from 'eslint'; - import { JSONSchema4 } from 'json-schema'; - - //#region SourceCode - - namespace SourceCode { - export interface Config { - text: string; - ast: AST.Program; - parserServices?: ParserServices; - scopeManager?: Scope.ScopeManager; - visitorKeys?: VisitorKeys; - } - - export interface VisitorKeys { - [nodeType: string]: string[]; - } - - export type FilterPredicate = ( - tokenOrComment: TSESTree.Token | TSESTree.Comment, - ) => boolean; - - export type CursorWithSkipOptions = - | number - | FilterPredicate - | { - includeComments?: boolean; - filter?: FilterPredicate; - skip?: number; - }; - - export type CursorWithCountOptions = - | number - | FilterPredicate - | { - includeComments?: boolean; - filter?: FilterPredicate; - count?: number; - }; - } - - class SourceCode { - text: string; - ast: AST.Program; - lines: string[]; - hasBOM: boolean; - parserServices: ParserServices; - scopeManager: Scope.ScopeManager; - visitorKeys: SourceCode.VisitorKeys; - - constructor(text: string, ast: AST.Program); - // eslint-disable-next-line no-dupe-class-members - constructor(config: SourceCode.Config); - - static splitLines(text: string): string[]; - - getText( - node?: TSESTree.Node, - beforeCount?: number, - afterCount?: number, - ): string; - - getLines(): string[]; - - getAllComments(): TSESTree.Comment[]; - - getComments( - node: TSESTree.Node, - ): { leading: TSESTree.Comment[]; trailing: TSESTree.Comment[] }; - - getJSDocComment(node: TSESTree.Node): TSESTree.Node | TSESTree.Token | null; - - getNodeByRangeIndex(index: number): TSESTree.Node | null; - - isSpaceBetweenTokens( - first: TSESTree.Token, - second: TSESTree.Token, - ): boolean; - - getLocFromIndex(index: number): TSESTree.LineAndColumnData; - - getIndexFromLoc(location: TSESTree.LineAndColumnData): number; - - // Inherited methods from TokenStore - // --------------------------------- - - getTokenByRangeStart( - offset: number, - options?: { includeComments?: boolean }, - ): TSESTree.Token | null; - - getFirstToken( - node: TSESTree.Node, - options?: SourceCode.CursorWithSkipOptions, - ): TSESTree.Token | null; - - getFirstTokens( - node: TSESTree.Node, - options?: SourceCode.CursorWithCountOptions, - ): TSESTree.Token[]; - - getLastToken( - node: TSESTree.Node, - options?: SourceCode.CursorWithSkipOptions, - ): TSESTree.Token | null; - - getLastTokens( - node: TSESTree.Node, - options?: SourceCode.CursorWithCountOptions, - ): TSESTree.Token[]; - - getTokenBefore( - node: TSESTree.Node | TSESTree.Token | TSESTree.Comment, - options?: SourceCode.CursorWithSkipOptions, - ): TSESTree.Token | null; - - getTokensBefore( - node: TSESTree.Node | TSESTree.Token | TSESTree.Comment, - options?: SourceCode.CursorWithCountOptions, - ): TSESTree.Token[]; - - getTokenAfter( - node: TSESTree.Node | TSESTree.Token | TSESTree.Comment, - options?: SourceCode.CursorWithSkipOptions, - ): TSESTree.Token | null; - - getTokensAfter( - node: TSESTree.Node | TSESTree.Token | TSESTree.Comment, - options?: SourceCode.CursorWithCountOptions, - ): TSESTree.Token[]; - - getFirstTokenBetween( - left: TSESTree.Node | TSESTree.Token | TSESTree.Comment, - right: TSESTree.Node | TSESTree.Token | TSESTree.Comment, - options?: SourceCode.CursorWithSkipOptions, - ): TSESTree.Token | null; - - getFirstTokensBetween( - left: TSESTree.Node | TSESTree.Token | TSESTree.Comment, - right: TSESTree.Node | TSESTree.Token | TSESTree.Comment, - options?: SourceCode.CursorWithCountOptions, - ): TSESTree.Token[]; - - getLastTokenBetween( - left: TSESTree.Node | TSESTree.Token | TSESTree.Comment, - right: TSESTree.Node | TSESTree.Token | TSESTree.Comment, - options?: SourceCode.CursorWithSkipOptions, - ): TSESTree.Token | null; - - getLastTokensBetween( - left: TSESTree.Node | TSESTree.Token | TSESTree.Comment, - right: TSESTree.Node | TSESTree.Token | TSESTree.Comment, - options?: SourceCode.CursorWithCountOptions, - ): TSESTree.Token[]; - - getTokensBetween( - left: TSESTree.Node | TSESTree.Token | TSESTree.Comment, - right: TSESTree.Node | TSESTree.Token | TSESTree.Comment, - padding?: - | number - | SourceCode.FilterPredicate - | SourceCode.CursorWithCountOptions, - ): TSESTree.Token[]; - - getTokens( - node: TSESTree.Node, - beforeCount?: number, - afterCount?: number, - ): TSESTree.Token[]; - // eslint-disable-next-line no-dupe-class-members - getTokens( - node: TSESTree.Node, - options: SourceCode.FilterPredicate | SourceCode.CursorWithCountOptions, - ): TSESTree.Token[]; - - commentsExistBetween( - left: TSESTree.Node | TSESTree.Token, - right: TSESTree.Node | TSESTree.Token, - ): boolean; - - getCommentsBefore( - nodeOrToken: TSESTree.Node | TSESTree.Token, - ): TSESTree.Comment[]; - - getCommentsAfter( - nodeOrToken: TSESTree.Node | TSESTree.Token, - ): TSESTree.Comment[]; - - getCommentsInside(node: TSESTree.Node): TSESTree.Comment[]; - } - - //#endregion SourceCode - - //#region Rule - - interface RuleMetaDataDocs { - /** - * The general category the rule falls within - */ - category: 'Best Practices' | 'Stylistic Issues' | 'Variables'; - /** - * Concise description of the rule - */ - description: string; - /** - * Extra information linking the rule to a tslint rule - */ - extraDescription?: string[]; - /** - * The recommendation level for the rule. - * Used by the build tools to generate the recommended config. - * Set to false to not include it as a recommendation - */ - recommended: 'error' | 'warn' | false; - /** - * The URL of the rule's docs - */ - url: string; - } - interface RuleMetaData { - /** - * True if the rule is deprecated, false otherwise - */ - deprecated?: boolean; - /** - * Documentation for the rule - */ - docs: RuleMetaDataDocs; - /** - * The fixer category. Omit if there is no fixer - */ - fixable?: 'code' | 'whitespace'; - /** - * A map of messages which the rule can report. - * The key is the messageId, and the string is the parameterised error string. - * See: https://eslint.org/docs/developer-guide/working-with-rules#messageids - */ - messages: Record; - /** - * The type of rule. - * - `"problem"` means the rule is identifying code that either will cause an error or may cause a confusing behavior. Developers should consider this a high priority to resolve. - * - `"suggestion"` means the rule is identifying something that could be done in a better way but no errors will occur if the code isn’t changed. - * - `"layout"` means the rule cares primarily about whitespace, semicolons, commas, and parentheses, all the parts of the program that determine how the code looks rather than how it executes. These rules work on parts of the code that aren’t specified in the AST. - */ - type: 'suggestion' | 'problem' | 'layout'; - /** - * The name of the rule this rule was replaced by, if it was deprecated. - */ - replacedBy?: string; - /** - * The options schema. Supply an empty array if there are no options. - */ - schema: JSONSchema4 | JSONSchema4[]; - } - - interface RuleFix { - range: AST.Range; - text: string; - } - - interface RuleFixer { - insertTextAfter( - nodeOrToken: TSESTree.Node | TSESTree.Token, - text: string, - ): RuleFix; - - insertTextAfterRange(range: AST.Range, text: string): RuleFix; - - insertTextBefore( - nodeOrToken: TSESTree.Node | TSESTree.Token, - text: string, - ): RuleFix; - - insertTextBeforeRange(range: AST.Range, text: string): RuleFix; - - remove(nodeOrToken: TSESTree.Node | TSESTree.Token): RuleFix; - - removeRange(range: AST.Range): RuleFix; - - replaceText( - nodeOrToken: TSESTree.Node | TSESTree.Token, - text: string, - ): RuleFix; - - replaceTextRange(range: AST.Range, text: string): RuleFix; - } - - type ReportFixFunction = (fixer: RuleFixer) => null | RuleFix | RuleFix[]; - - interface ReportDescriptor { - /** - * The parameters for the message string associated with `messageId`. - */ - data?: Record; - /** - * The fixer function. - */ - fix?: ReportFixFunction | null; - /** - * The messageId which is being reported. - */ - messageId: TMessageIds; - /** - * The Node or AST Token which the report is being attached to - */ - node: TSESTree.Node | TSESTree.Comment | TSESTree.Token; - /** - * An override of the location of the report - */ - loc?: TSESTree.SourceLocation; - } - - interface RuleContext< - TMessageIds extends string, - TOptions extends Readonly - > { - /** - * The rule ID. - */ - id: string; - /** - * An array of the configured options for this rule. - * This array does not include the rule severity. - */ - options: TOptions; - /** - * The shared settings from configuration. - * We do not have any shared settings in this plugin. - */ - settings: {}; - /** - * The name of the parser from configuration. - */ - parserPath: string; - /** - * The parser options configured for this run - */ - parserOptions: Linter.ParserOptions; - /** - * An object containing parser-provided services for rules - */ - parserServices?: ParserServices; - - /** - * Returns an array of the ancestors of the currently-traversed node, starting at - * the root of the AST and continuing through the direct parent of the current node. - * This array does not include the currently-traversed node itself. - */ - getAncestors(): TSESTree.Node[]; - - /** - * Returns a list of variables declared by the given node. - * This information can be used to track references to variables. - */ - getDeclaredVariables(node: TSESTree.Node): Scope.Variable[]; - - /** - * Returns the filename associated with the source. - */ - getFilename(): string; - - /** - * Returns the scope of the currently-traversed node. - * This information can be used track references to variables. - */ - getScope(): Scope.Scope; - - /** - * Returns a SourceCode object that you can use to work with the source that - * was passed to ESLint. - */ - getSourceCode(): SourceCode; - - /** - * Marks a variable with the given name in the current scope as used. - * This affects the no-unused-vars rule. - */ - markVariableAsUsed(name: string): boolean; - - /** - * Reports a problem in the code. - */ - report(descriptor: ReportDescriptor): void; - } - - // This isn't the correct signature, but it makes it easier to do custom unions within reusable listneers - // never will break someone's code unless they specifically type the function argument - type RuleFunction = (node: T) => void; - - interface RuleListener { - [nodeSelector: string]: RuleFunction | undefined; - ArrayExpression?: RuleFunction; - ArrayPattern?: RuleFunction; - ArrowFunctionExpression?: RuleFunction; - AssignmentPattern?: RuleFunction; - AwaitExpression?: RuleFunction; - BlockStatement?: RuleFunction; - BreakStatement?: RuleFunction; - CallExpression?: RuleFunction; - CatchClause?: RuleFunction; - ClassBody?: RuleFunction; - ClassDeclaration?: RuleFunction; - ClassExpression?: RuleFunction; - Comment?: RuleFunction; - ConditionalExpression?: RuleFunction; - ContinueStatement?: RuleFunction; - DebuggerStatement?: RuleFunction; - Decorator?: RuleFunction; - DoWhileStatement?: RuleFunction; - EmptyStatement?: RuleFunction; - ExportAllDeclaration?: RuleFunction; - ExportDefaultDeclaration?: RuleFunction; - ExportNamedDeclaration?: RuleFunction; - ExportSpecifier?: RuleFunction; - ExpressionStatement?: RuleFunction; - ForInStatement?: RuleFunction; - ForOfStatement?: RuleFunction; - ForStatement?: RuleFunction; - Identifier?: RuleFunction; - IfStatement?: RuleFunction; - Import?: RuleFunction; - ImportDeclaration?: RuleFunction; - ImportDefaultSpecifier?: RuleFunction; - ImportNamespaceSpecifier?: RuleFunction; - ImportSpecifier?: RuleFunction; - JSXAttribute?: RuleFunction; - JSXClosingElement?: RuleFunction; - JSXClosingFragment?: RuleFunction; - JSXElement?: RuleFunction; - JSXEmptyExpression?: RuleFunction; - JSXExpressionContainer?: RuleFunction; - JSXFragment?: RuleFunction; - JSXIdentifier?: RuleFunction; - JSXMemberExpression?: RuleFunction; - JSXOpeningElement?: RuleFunction; - JSXOpeningFragment?: RuleFunction; - JSXSpreadAttribute?: RuleFunction; - JSXSpreadChild?: RuleFunction; - JSXText?: RuleFunction; - LabeledStatement?: RuleFunction; - MemberExpression?: RuleFunction; - MetaProperty?: RuleFunction; - MethodDefinition?: RuleFunction; - NewExpression?: RuleFunction; - ObjectExpression?: RuleFunction; - ObjectPattern?: RuleFunction; - Program?: RuleFunction; - Property?: RuleFunction; - RestElement?: RuleFunction; - ReturnStatement?: RuleFunction; - SequenceExpression?: RuleFunction; - SpreadElement?: RuleFunction; - Super?: RuleFunction; - SwitchCase?: RuleFunction; - SwitchStatement?: RuleFunction; - TaggedTemplateExpression?: RuleFunction; - TemplateElement?: RuleFunction; - TemplateLiteral?: RuleFunction; - ThisExpression?: RuleFunction; - ThrowStatement?: RuleFunction; - Token?: RuleFunction; - TryStatement?: RuleFunction; - TSAbstractKeyword?: RuleFunction; - TSAnyKeyword?: RuleFunction; - TSArrayType?: RuleFunction; - TSAsExpression?: RuleFunction; - TSAsyncKeyword?: RuleFunction; - TSBigIntKeyword?: RuleFunction; - TSBooleanKeyword?: RuleFunction; - TSConditionalType?: RuleFunction; - TSDeclareKeyword?: RuleFunction; - TSEnumDeclaration?: RuleFunction; - TSEnumMember?: RuleFunction; - TSExportAssignment?: RuleFunction; - TSExportKeyword?: RuleFunction; - TSExternalModuleReference?: RuleFunction< - TSESTree.TSExternalModuleReference - >; - TSImportEqualsDeclaration?: RuleFunction< - TSESTree.TSImportEqualsDeclaration - >; - TSImportType?: RuleFunction; - TSIndexedAccessType?: RuleFunction; - TSIndexSignature?: RuleFunction; - TSInferType?: RuleFunction; - TSInterfaceBody?: RuleFunction; - TSInterfaceDeclaration?: RuleFunction; - TSIntersectionType?: RuleFunction; - TSLiteralType?: RuleFunction; - TSMappedType?: RuleFunction; - TSMethodSignature?: RuleFunction; - TSModuleBlock?: RuleFunction; - TSModuleDeclaration?: RuleFunction; - TSNamespaceExportDeclaration?: RuleFunction< - TSESTree.TSNamespaceExportDeclaration - >; - TSNeverKeyword?: RuleFunction; - TSNonNullExpression?: RuleFunction; - TSNullKeyword?: RuleFunction; - TSNumberKeyword?: RuleFunction; - TSObjectKeyword?: RuleFunction; - TSOptionalType?: RuleFunction; - TSParameterProperty?: RuleFunction; - TSParenthesizedType?: RuleFunction; - TSPrivateKeyword?: RuleFunction; - TSPropertySignature?: RuleFunction; - TSProtectedKeyword?: RuleFunction; - TSPublicKeyword?: RuleFunction; - TSQualifiedName?: RuleFunction; - TSReadonlyKeyword?: RuleFunction; - TSRestType?: RuleFunction; - TSStaticKeyword?: RuleFunction; - TSStringKeyword?: RuleFunction; - TSSymbolKeyword?: RuleFunction; - TSThisType?: RuleFunction; - TSTupleType?: RuleFunction; - TSTypeAliasDeclaration?: RuleFunction; - TSTypeAnnotation?: RuleFunction; - TSTypeAssertion?: RuleFunction; - TSTypeLiteral?: RuleFunction; - TSTypeOperator?: RuleFunction; - TSTypeParameter?: RuleFunction; - TSTypeParameterDeclaration?: RuleFunction< - TSESTree.TSTypeParameterDeclaration - >; - TSTypeParameterInstantiation?: RuleFunction< - TSESTree.TSTypeParameterInstantiation - >; - TSTypePredicate?: RuleFunction; - TSTypeQuery?: RuleFunction; - TSTypeReference?: RuleFunction; - TSUndefinedKeyword?: RuleFunction; - TSUnionType?: RuleFunction; - TSUnknownKeyword?: RuleFunction; - TSVoidKeyword?: RuleFunction; - VariableDeclaration?: RuleFunction; - VariableDeclarator?: RuleFunction; - WhileStatement?: RuleFunction; - WithStatement?: RuleFunction; - YieldExpression?: RuleFunction; - } - - interface RuleModule< - TMessageIds extends string, - TOptions extends Readonly, - // for extending base rules - TRuleListener extends RuleListener = RuleListener - > { - /** - * Metadata about the rule - */ - meta: RuleMetaData; - - /** - * Function which returns an object with methods that ESLint calls to “visit” - * nodes while traversing the abstract syntax tree. - */ - create(context: RuleContext): TRuleListener; - } - - //#endregion Rule - - namespace Scope { - interface ScopeManager { - scopes: Scope[]; - globalScope: Scope | null; - - acquire(node: TSESTree.Node, inner?: boolean): Scope | null; - - getDeclaredVariables(node: TSESTree.Node): Variable[]; - } - - interface Reference { - identifier: TSESTree.Identifier; - from: Scope; - resolved: Variable | null; - writeExpr: TSESTree.Node | null; - init: boolean; - - isWrite(): boolean; - - isRead(): boolean; - - isWriteOnly(): boolean; - - isReadOnly(): boolean; - - isReadWrite(): boolean; - } - - interface Variable { - name: string; - identifiers: TSESTree.Identifier[]; - references: Reference[]; - defs: Definition[]; - scope: Scope; - eslintUsed?: boolean; - } - - interface Scope { - type: - | 'block' - | 'catch' - | 'class' - | 'for' - | 'function' - | 'function-expression-name' - | 'global' - | 'module' - | 'switch' - | 'with' - | 'TDZ'; - isStrict: boolean; - upper: Scope | null; - childScopes: Scope[]; - variableScope: Scope; - block: TSESTree.Node; - variables: Variable[]; - set: Map; - references: Reference[]; - through: Reference[]; - functionExpressionScope: boolean; - } - - type DefinitionType = - | { type: 'CatchClause'; node: TSESTree.CatchClause; parent: null } - | { - type: 'ClassName'; - node: TSESTree.ClassDeclaration | TSESTree.ClassExpression; - parent: null; - } - | { - type: 'FunctionName'; - node: TSESTree.FunctionDeclaration | TSESTree.FunctionExpression; - parent: null; - } - | { type: 'ImplicitGlobalVariable'; node: TSESTree.Program; parent: null } - | { - type: 'ImportBinding'; - node: - | TSESTree.ImportSpecifier - | TSESTree.ImportDefaultSpecifier - | TSESTree.ImportNamespaceSpecifier; - parent: TSESTree.ImportDeclaration; - } - | { - type: 'Parameter'; - node: - | TSESTree.FunctionDeclaration - | TSESTree.FunctionExpression - | TSESTree.ArrowFunctionExpression; - parent: null; - } - | { type: 'TDZ'; node: any; parent: null } - | { - type: 'Variable'; - node: TSESTree.VariableDeclarator; - parent: TSESTree.VariableDeclaration; - }; - - type Definition = DefinitionType & { name: TSESTree.Identifier }; - } - - export { - ReportDescriptor, - ReportFixFunction, - RuleContext, - RuleFix, - RuleFunction, - RuleListener, - RuleMetaData, - RuleMetaDataDocs, - Scope, - SourceCode, - }; - export default RuleModule; -} diff --git a/packages/parser/src/analyze-scope.ts b/packages/parser/src/analyze-scope.ts index 2057bdb1ae06..b131104ce87b 100644 --- a/packages/parser/src/analyze-scope.ts +++ b/packages/parser/src/analyze-scope.ts @@ -1,4 +1,4 @@ -import { TSESTree, AST_NODE_TYPES } from '@typescript-eslint/util'; +import { TSESTree, AST_NODE_TYPES } from '@typescript-eslint/typescript-estree'; import { Definition, ParameterDefinition } from 'eslint-scope/lib/definition'; import { PatternVisitorCallback, diff --git a/packages/parser/src/parser.ts b/packages/parser/src/parser.ts index 92afa1567fc2..e978ea529ce7 100644 --- a/packages/parser/src/parser.ts +++ b/packages/parser/src/parser.ts @@ -1,14 +1,18 @@ -import { AST_NODE_TYPES } from '@typescript-eslint/util'; import { + AST_NODE_TYPES, parseAndGenerateServices, ParserOptions as ParserOptionsTsESTree, ParserServices, } from '@typescript-eslint/typescript-estree'; +import { + TSESLint, +} from '@typescript-eslint/util'; import traverser from 'eslint/lib/util/traverser'; import { analyzeScope } from './analyze-scope'; -import { ParserOptions } from './parser-options'; import { visitorKeys } from './visitor-keys'; +type ParserOptions = TSESLint.ParserOptions; + // note - cannot migrate this to an import statement because it will make TSC copy the package.json to the dist folder const packageJSON = require('../package.json'); diff --git a/packages/parser/src/scope/scope-manager.ts b/packages/parser/src/scope/scope-manager.ts index 4d7cb156fea1..7b7e53c9e84c 100644 --- a/packages/parser/src/scope/scope-manager.ts +++ b/packages/parser/src/scope/scope-manager.ts @@ -1,4 +1,4 @@ -import { TSESTree } from '@typescript-eslint/util'; +import { TSESTree } from '@typescript-eslint/typescript-estree'; import EslintScopeManager, { ScopeManagerOptions, } from 'eslint-scope/lib/scope-manager'; diff --git a/packages/parser/src/scope/scopes.ts b/packages/parser/src/scope/scopes.ts index 0c44053525f0..9dff225a7213 100644 --- a/packages/parser/src/scope/scopes.ts +++ b/packages/parser/src/scope/scopes.ts @@ -1,4 +1,4 @@ -import { TSESTree } from '@typescript-eslint/util'; +import { TSESTree } from '@typescript-eslint/typescript-estree'; import { Scope } from 'eslint-scope/lib/scope'; import { ScopeManager } from './scope-manager'; diff --git a/packages/parser/tests/lib/parser.ts b/packages/parser/tests/lib/parser.ts index c2a25bc7802a..c3c205509dd9 100644 --- a/packages/parser/tests/lib/parser.ts +++ b/packages/parser/tests/lib/parser.ts @@ -1,8 +1,9 @@ -import { AST_NODE_TYPES } from '@typescript-eslint/util'; import * as typescriptESTree from '@typescript-eslint/typescript-estree'; import { parse, parseForESLint, Syntax } from '../../src/parser'; import * as scope from '../../src/analyze-scope'; +const { AST_NODE_TYPES } = typescriptESTree; + describe('parser', () => { it('parse() should return just the AST from parseForESLint()', () => { const code = 'const valid = true;'; diff --git a/packages/parser/tests/lib/visitor-keys.ts b/packages/parser/tests/lib/visitor-keys.ts index ab6ca327bc05..fd8ab4970f9b 100644 --- a/packages/parser/tests/lib/visitor-keys.ts +++ b/packages/parser/tests/lib/visitor-keys.ts @@ -1,4 +1,4 @@ -import { AST_NODE_TYPES } from '@typescript-eslint/util'; +import { AST_NODE_TYPES } from '@typescript-eslint/typescript-estree'; import { visitorKeys } from '../../src/visitor-keys'; //------------------------------------------------------------------------------ diff --git a/packages/typescript-estree/package.json b/packages/typescript-estree/package.json index 613a18238dea..23188c301b9a 100644 --- a/packages/typescript-estree/package.json +++ b/packages/typescript-estree/package.json @@ -37,8 +37,7 @@ }, "dependencies": { "lodash.unescape": "4.0.1", - "semver": "5.5.0", - "@typescript-eslint/util": "1.4.2" + "semver": "5.5.0" }, "peerDependencies": { "typescript": "*" diff --git a/packages/typescript-estree/src/convert-comments.ts b/packages/typescript-estree/src/convert-comments.ts index 7f6c0672a884..431030a7c548 100644 --- a/packages/typescript-estree/src/convert-comments.ts +++ b/packages/typescript-estree/src/convert-comments.ts @@ -1,4 +1,4 @@ -import { TSESTree } from '@typescript-eslint/util'; +import { TSESTree } from './ts-estree'; import ts from 'typescript'; import { getLocFor, getNodeContainer } from './node-utils'; diff --git a/packages/typescript-estree/src/convert.ts b/packages/typescript-estree/src/convert.ts index 96cf81ff64aa..e9b5ae0d85cb 100644 --- a/packages/typescript-estree/src/convert.ts +++ b/packages/typescript-estree/src/convert.ts @@ -1,4 +1,4 @@ -import { AST_NODE_TYPES, TSESTree, TSNode } from '@typescript-eslint/util'; +import { AST_NODE_TYPES, TSESTree, TSNode } from './ts-estree'; import ts from 'typescript'; import { canContainDirective, diff --git a/packages/typescript-estree/src/node-utils.ts b/packages/typescript-estree/src/node-utils.ts index 01d5edc39b9d..4a280477bbe8 100644 --- a/packages/typescript-estree/src/node-utils.ts +++ b/packages/typescript-estree/src/node-utils.ts @@ -2,7 +2,7 @@ import { AST_NODE_TYPES, AST_TOKEN_TYPES, TSESTree, -} from '@typescript-eslint/util'; +} from './ts-estree'; import unescape from 'lodash.unescape'; import ts from 'typescript'; diff --git a/packages/typescript-estree/src/parser-options.ts b/packages/typescript-estree/src/parser-options.ts index 4f9b0887e870..c23e86b33810 100644 --- a/packages/typescript-estree/src/parser-options.ts +++ b/packages/typescript-estree/src/parser-options.ts @@ -1,4 +1,4 @@ -import { TSESTree, TSNode } from '@typescript-eslint/util'; +import { TSESTree, TSNode } from './ts-estree'; import { Program } from 'typescript'; export interface Extra { diff --git a/packages/typescript-estree/src/parser.ts b/packages/typescript-estree/src/parser.ts index 8c4416ef0ff4..a134bdca9a66 100644 --- a/packages/typescript-estree/src/parser.ts +++ b/packages/typescript-estree/src/parser.ts @@ -1,4 +1,4 @@ -import { TSESTree } from '@typescript-eslint/util'; +import { TSESTree } from './ts-estree'; import semver from 'semver'; import ts from 'typescript'; import convert from './ast-converter'; @@ -407,3 +407,4 @@ export function parseAndGenerateServices< } export { ParserOptions, ParserServices }; +export * from './ts-estree'; diff --git a/packages/util/src/ast-node-types.ts b/packages/typescript-estree/src/ts-estree/ast-node-types.ts similarity index 100% rename from packages/util/src/ast-node-types.ts rename to packages/typescript-estree/src/ts-estree/ast-node-types.ts diff --git a/packages/typescript-estree/src/ts-estree/index.ts b/packages/typescript-estree/src/ts-estree/index.ts new file mode 100644 index 000000000000..5bed681f209b --- /dev/null +++ b/packages/typescript-estree/src/ts-estree/index.ts @@ -0,0 +1,5 @@ +import * as TSESTree from './ts-estree'; + +export { TSESTree }; +export * from './ast-node-types'; +export * from './ts-nodes'; diff --git a/packages/util/src/ts-estree.ts b/packages/typescript-estree/src/ts-estree/ts-estree.ts similarity index 100% rename from packages/util/src/ts-estree.ts rename to packages/typescript-estree/src/ts-estree/ts-estree.ts diff --git a/packages/util/src/ts-nodes.ts b/packages/typescript-estree/src/ts-estree/ts-nodes.ts similarity index 100% rename from packages/util/src/ts-nodes.ts rename to packages/typescript-estree/src/ts-estree/ts-nodes.ts diff --git a/packages/typescript-estree/tests/ast-alignment/utils.ts b/packages/typescript-estree/tests/ast-alignment/utils.ts index 1d13119ca464..58a7926ca9ad 100644 --- a/packages/typescript-estree/tests/ast-alignment/utils.ts +++ b/packages/typescript-estree/tests/ast-alignment/utils.ts @@ -1,4 +1,4 @@ -import { AST_NODE_TYPES } from '@typescript-eslint/util'; +import { AST_NODE_TYPES } from '../../src/ts-estree'; import isPlainObject from 'lodash.isplainobject'; /** diff --git a/packages/typescript-estree/tests/lib/semanticInfo.ts b/packages/typescript-estree/tests/lib/semanticInfo.ts index ba777493130d..8684f5b5116b 100644 --- a/packages/typescript-estree/tests/lib/semanticInfo.ts +++ b/packages/typescript-estree/tests/lib/semanticInfo.ts @@ -9,7 +9,7 @@ import { parseCodeAndGenerateServices, } from '../../tools/test-utils'; import { parseAndGenerateServices } from '../../src/parser'; -import { TSESTree } from '@typescript-eslint/util'; +import { TSESTree } from '../../src/ts-estree'; const FIXTURES_DIR = './tests/fixtures/semanticInfo'; const testFiles = glob.sync(`${FIXTURES_DIR}/**/*.src.ts`); diff --git a/packages/typescript-estree/tsconfig.build.json b/packages/typescript-estree/tsconfig.build.json index b0fced27d72d..792172fb82f6 100644 --- a/packages/typescript-estree/tsconfig.build.json +++ b/packages/typescript-estree/tsconfig.build.json @@ -1,7 +1,8 @@ { "extends": "../../tsconfig.base.json", "compilerOptions": { - "outDir": "./dist" + "outDir": "./dist", + "rootDir": "./src" }, "include": ["src"] } diff --git a/packages/typescript-estree/tsconfig.json b/packages/typescript-estree/tsconfig.json index 1fdde9ad21c5..7edf4752f6eb 100644 --- a/packages/typescript-estree/tsconfig.json +++ b/packages/typescript-estree/tsconfig.json @@ -1,4 +1,7 @@ { - "extends": "./tsconfig.build.json", + "extends": "../../tsconfig.base.json", + "compilerOptions": { + "outDir": "./dist", + }, "include": ["src", "tests", "tools"] } diff --git a/packages/util/src/index.ts b/packages/util/src/index.ts index 8579cdd1686c..af4e6e898fa6 100644 --- a/packages/util/src/index.ts +++ b/packages/util/src/index.ts @@ -1,5 +1,14 @@ -import * as TSESTree from './ts-estree'; +import * as TSESLint from './ts-eslint'; -export * from './ast-node-types'; -export * from './ts-nodes'; -export { TSESTree }; +export { TSESLint }; + +// for convenience's sake - export the types directly from here so consumers +// don't need to reference/install both packages in their code +export { + AST_NODE_TYPES, + AST_TOKEN_TYPES, + ParserOptions, + ParserServices, + TSESTree, + TSNode, +} from '@typescript-eslint/typescript-estree'; diff --git a/packages/util/src/ts-eslint/ParserOptions.ts b/packages/util/src/ts-eslint/ParserOptions.ts new file mode 100644 index 000000000000..d374ac57b912 --- /dev/null +++ b/packages/util/src/ts-eslint/ParserOptions.ts @@ -0,0 +1,21 @@ +export interface ParserOptions { + loc?: boolean; + comment?: boolean; + range?: boolean; + tokens?: boolean; + sourceType?: 'script' | 'module'; + ecmaVersion?: number; + ecmaFeatures?: { + globalReturn?: boolean; + jsx?: boolean; + }; + // ts-estree specific + filePath?: string; + project?: string | string[]; + useJSXTextNode?: boolean; + errorOnUnknownASTType?: boolean; + errorOnTypeScriptSyntacticAndSemanticIssues?: boolean; + tsconfigRootDir?: string; + extraFileExtensions?: string[]; + warnOnUnsupportedTypeScriptVersion?: boolean; +} diff --git a/packages/util/src/ts-eslint/Rule.ts b/packages/util/src/ts-eslint/Rule.ts new file mode 100644 index 000000000000..3ec278656752 --- /dev/null +++ b/packages/util/src/ts-eslint/Rule.ts @@ -0,0 +1,382 @@ +import { + ParserServices, + TSESTree, +} from '@typescript-eslint/typescript-estree'; +import { AST, Linter } from 'eslint'; +import { JSONSchema4 } from 'json-schema'; +import { Scope } from './Scope'; +import { SourceCode } from './SourceCode'; + +interface RuleMetaDataDocs { + /** + * The general category the rule falls within + */ + category: 'Best Practices' | 'Stylistic Issues' | 'Variables'; + /** + * Concise description of the rule + */ + description: string; + /** + * Extra information linking the rule to a tslint rule + */ + extraDescription?: string[]; + /** + * The recommendation level for the rule. + * Used by the build tools to generate the recommended config. + * Set to false to not include it as a recommendation + */ + recommended: 'error' | 'warn' | false; + /** + * The URL of the rule's docs + */ + url: string; +} +interface RuleMetaData { + /** + * True if the rule is deprecated, false otherwise + */ + deprecated?: boolean; + /** + * Documentation for the rule + */ + docs: RuleMetaDataDocs; + /** + * The fixer category. Omit if there is no fixer + */ + fixable?: 'code' | 'whitespace'; + /** + * A map of messages which the rule can report. + * The key is the messageId, and the string is the parameterised error string. + * See: https://eslint.org/docs/developer-guide/working-with-rules#messageids + */ + messages: Record; + /** + * The type of rule. + * - `"problem"` means the rule is identifying code that either will cause an error or may cause a confusing behavior. Developers should consider this a high priority to resolve. + * - `"suggestion"` means the rule is identifying something that could be done in a better way but no errors will occur if the code isn’t changed. + * - `"layout"` means the rule cares primarily about whitespace, semicolons, commas, and parentheses, all the parts of the program that determine how the code looks rather than how it executes. These rules work on parts of the code that aren’t specified in the AST. + */ + type: 'suggestion' | 'problem' | 'layout'; + /** + * The name of the rule this rule was replaced by, if it was deprecated. + */ + replacedBy?: string; + /** + * The options schema. Supply an empty array if there are no options. + */ + schema: JSONSchema4 | JSONSchema4[]; +} + +interface RuleFix { + range: AST.Range; + text: string; +} + +interface RuleFixer { + insertTextAfter( + nodeOrToken: TSESTree.Node | TSESTree.Token, + text: string, + ): RuleFix; + + insertTextAfterRange(range: AST.Range, text: string): RuleFix; + + insertTextBefore( + nodeOrToken: TSESTree.Node | TSESTree.Token, + text: string, + ): RuleFix; + + insertTextBeforeRange(range: AST.Range, text: string): RuleFix; + + remove(nodeOrToken: TSESTree.Node | TSESTree.Token): RuleFix; + + removeRange(range: AST.Range): RuleFix; + + replaceText( + nodeOrToken: TSESTree.Node | TSESTree.Token, + text: string, + ): RuleFix; + + replaceTextRange(range: AST.Range, text: string): RuleFix; +} + +type ReportFixFunction = (fixer: RuleFixer) => null | RuleFix | RuleFix[]; + +interface ReportDescriptor { + /** + * The parameters for the message string associated with `messageId`. + */ + data?: Record; + /** + * The fixer function. + */ + fix?: ReportFixFunction | null; + /** + * The messageId which is being reported. + */ + messageId: TMessageIds; + /** + * The Node or AST Token which the report is being attached to + */ + node: TSESTree.Node | TSESTree.Comment | TSESTree.Token; + /** + * An override of the location of the report + */ + loc?: TSESTree.SourceLocation; +} + +interface RuleContext< + TMessageIds extends string, + TOptions extends Readonly +> { + /** + * The rule ID. + */ + id: string; + /** + * An array of the configured options for this rule. + * This array does not include the rule severity. + */ + options: TOptions; + /** + * The shared settings from configuration. + * We do not have any shared settings in this plugin. + */ + settings: {}; + /** + * The name of the parser from configuration. + */ + parserPath: string; + /** + * The parser options configured for this run + */ + parserOptions: Linter.ParserOptions; + /** + * An object containing parser-provided services for rules + */ + parserServices?: ParserServices; + + /** + * Returns an array of the ancestors of the currently-traversed node, starting at + * the root of the AST and continuing through the direct parent of the current node. + * This array does not include the currently-traversed node itself. + */ + getAncestors(): TSESTree.Node[]; + + /** + * Returns a list of variables declared by the given node. + * This information can be used to track references to variables. + */ + getDeclaredVariables(node: TSESTree.Node): Scope.Variable[]; + + /** + * Returns the filename associated with the source. + */ + getFilename(): string; + + /** + * Returns the scope of the currently-traversed node. + * This information can be used track references to variables. + */ + getScope(): Scope.Scope; + + /** + * Returns a SourceCode object that you can use to work with the source that + * was passed to ESLint. + */ + getSourceCode(): SourceCode; + + /** + * Marks a variable with the given name in the current scope as used. + * This affects the no-unused-vars rule. + */ + markVariableAsUsed(name: string): boolean; + + /** + * Reports a problem in the code. + */ + report(descriptor: ReportDescriptor): void; +} + +// This isn't the correct signature, but it makes it easier to do custom unions within reusable listneers +// never will break someone's code unless they specifically type the function argument +type RuleFunction = (node: T) => void; + +interface RuleListener { + [nodeSelector: string]: RuleFunction | undefined; + ArrayExpression?: RuleFunction; + ArrayPattern?: RuleFunction; + ArrowFunctionExpression?: RuleFunction; + AssignmentPattern?: RuleFunction; + AwaitExpression?: RuleFunction; + BlockStatement?: RuleFunction; + BreakStatement?: RuleFunction; + CallExpression?: RuleFunction; + CatchClause?: RuleFunction; + ClassBody?: RuleFunction; + ClassDeclaration?: RuleFunction; + ClassExpression?: RuleFunction; + Comment?: RuleFunction; + ConditionalExpression?: RuleFunction; + ContinueStatement?: RuleFunction; + DebuggerStatement?: RuleFunction; + Decorator?: RuleFunction; + DoWhileStatement?: RuleFunction; + EmptyStatement?: RuleFunction; + ExportAllDeclaration?: RuleFunction; + ExportDefaultDeclaration?: RuleFunction; + ExportNamedDeclaration?: RuleFunction; + ExportSpecifier?: RuleFunction; + ExpressionStatement?: RuleFunction; + ForInStatement?: RuleFunction; + ForOfStatement?: RuleFunction; + ForStatement?: RuleFunction; + Identifier?: RuleFunction; + IfStatement?: RuleFunction; + Import?: RuleFunction; + ImportDeclaration?: RuleFunction; + ImportDefaultSpecifier?: RuleFunction; + ImportNamespaceSpecifier?: RuleFunction; + ImportSpecifier?: RuleFunction; + JSXAttribute?: RuleFunction; + JSXClosingElement?: RuleFunction; + JSXClosingFragment?: RuleFunction; + JSXElement?: RuleFunction; + JSXEmptyExpression?: RuleFunction; + JSXExpressionContainer?: RuleFunction; + JSXFragment?: RuleFunction; + JSXIdentifier?: RuleFunction; + JSXMemberExpression?: RuleFunction; + JSXOpeningElement?: RuleFunction; + JSXOpeningFragment?: RuleFunction; + JSXSpreadAttribute?: RuleFunction; + JSXSpreadChild?: RuleFunction; + JSXText?: RuleFunction; + LabeledStatement?: RuleFunction; + MemberExpression?: RuleFunction; + MetaProperty?: RuleFunction; + MethodDefinition?: RuleFunction; + NewExpression?: RuleFunction; + ObjectExpression?: RuleFunction; + ObjectPattern?: RuleFunction; + Program?: RuleFunction; + Property?: RuleFunction; + RestElement?: RuleFunction; + ReturnStatement?: RuleFunction; + SequenceExpression?: RuleFunction; + SpreadElement?: RuleFunction; + Super?: RuleFunction; + SwitchCase?: RuleFunction; + SwitchStatement?: RuleFunction; + TaggedTemplateExpression?: RuleFunction; + TemplateElement?: RuleFunction; + TemplateLiteral?: RuleFunction; + ThisExpression?: RuleFunction; + ThrowStatement?: RuleFunction; + Token?: RuleFunction; + TryStatement?: RuleFunction; + TSAbstractKeyword?: RuleFunction; + TSAnyKeyword?: RuleFunction; + TSArrayType?: RuleFunction; + TSAsExpression?: RuleFunction; + TSAsyncKeyword?: RuleFunction; + TSBigIntKeyword?: RuleFunction; + TSBooleanKeyword?: RuleFunction; + TSConditionalType?: RuleFunction; + TSDeclareKeyword?: RuleFunction; + TSEnumDeclaration?: RuleFunction; + TSEnumMember?: RuleFunction; + TSExportAssignment?: RuleFunction; + TSExportKeyword?: RuleFunction; + TSExternalModuleReference?: RuleFunction; + TSImportEqualsDeclaration?: RuleFunction; + TSImportType?: RuleFunction; + TSIndexedAccessType?: RuleFunction; + TSIndexSignature?: RuleFunction; + TSInferType?: RuleFunction; + TSInterfaceBody?: RuleFunction; + TSInterfaceDeclaration?: RuleFunction; + TSIntersectionType?: RuleFunction; + TSLiteralType?: RuleFunction; + TSMappedType?: RuleFunction; + TSMethodSignature?: RuleFunction; + TSModuleBlock?: RuleFunction; + TSModuleDeclaration?: RuleFunction; + TSNamespaceExportDeclaration?: RuleFunction< + TSESTree.TSNamespaceExportDeclaration + >; + TSNeverKeyword?: RuleFunction; + TSNonNullExpression?: RuleFunction; + TSNullKeyword?: RuleFunction; + TSNumberKeyword?: RuleFunction; + TSObjectKeyword?: RuleFunction; + TSOptionalType?: RuleFunction; + TSParameterProperty?: RuleFunction; + TSParenthesizedType?: RuleFunction; + TSPrivateKeyword?: RuleFunction; + TSPropertySignature?: RuleFunction; + TSProtectedKeyword?: RuleFunction; + TSPublicKeyword?: RuleFunction; + TSQualifiedName?: RuleFunction; + TSReadonlyKeyword?: RuleFunction; + TSRestType?: RuleFunction; + TSStaticKeyword?: RuleFunction; + TSStringKeyword?: RuleFunction; + TSSymbolKeyword?: RuleFunction; + TSThisType?: RuleFunction; + TSTupleType?: RuleFunction; + TSTypeAliasDeclaration?: RuleFunction; + TSTypeAnnotation?: RuleFunction; + TSTypeAssertion?: RuleFunction; + TSTypeLiteral?: RuleFunction; + TSTypeOperator?: RuleFunction; + TSTypeParameter?: RuleFunction; + TSTypeParameterDeclaration?: RuleFunction< + TSESTree.TSTypeParameterDeclaration + >; + TSTypeParameterInstantiation?: RuleFunction< + TSESTree.TSTypeParameterInstantiation + >; + TSTypePredicate?: RuleFunction; + TSTypeQuery?: RuleFunction; + TSTypeReference?: RuleFunction; + TSUndefinedKeyword?: RuleFunction; + TSUnionType?: RuleFunction; + TSUnknownKeyword?: RuleFunction; + TSVoidKeyword?: RuleFunction; + VariableDeclaration?: RuleFunction; + VariableDeclarator?: RuleFunction; + WhileStatement?: RuleFunction; + WithStatement?: RuleFunction; + YieldExpression?: RuleFunction; +} + +interface RuleModule< + TMessageIds extends string, + TOptions extends Readonly, + // for extending base rules + TRuleListener extends RuleListener = RuleListener +> { + /** + * Metadata about the rule + */ + meta: RuleMetaData; + + /** + * Function which returns an object with methods that ESLint calls to “visit” + * nodes while traversing the abstract syntax tree. + */ + create(context: RuleContext): TRuleListener; +} + +export { + ReportDescriptor, + ReportFixFunction, + RuleContext, + RuleFix, + RuleFixer, + RuleFunction, + RuleListener, + RuleMetaData, + RuleMetaDataDocs, + RuleModule, +}; diff --git a/packages/util/src/ts-eslint/RuleTester.ts b/packages/util/src/ts-eslint/RuleTester.ts new file mode 100644 index 000000000000..d774cdc67602 --- /dev/null +++ b/packages/util/src/ts-eslint/RuleTester.ts @@ -0,0 +1,59 @@ +import { + AST_NODE_TYPES, +} from '@typescript-eslint/typescript-estree'; +import { ParserOptions } from './ParserOptions'; +import { RuleModule } from './Rule'; + +interface ValidTestCase> { + code: string; + options?: TOptions; + filename?: string; + parserOptions?: ParserOptions; + settings?: Record; + parser?: string; + globals?: Record; + env?: { + browser?: boolean; + }; +} + +interface InvalidTestCase< + TMessageIds extends string, + TOptions extends Readonly +> extends ValidTestCase { + errors: TestCaseError[]; + output?: string; +} + +interface TestCaseError { + messageId: TMessageIds; + data?: Record; + type?: AST_NODE_TYPES; + line?: number; + column?: number; +} + +interface RunTests< + TMessageIds extends string, + TOptions extends Readonly +> { + // RuleTester.run also accepts strings for valid cases + valid: (ValidTestCase | string)[]; + invalid: InvalidTestCase[]; +} +interface RuleTesterConfig { + parser: '@typescript-eslint/parser'; + parserOptions?: ParserOptions; +} +interface RuleTester { + // eslint-disable-next-line @typescript-eslint/no-misused-new + new (config?: RuleTesterConfig): RuleTester; + + run>( + name: string, + rule: RuleModule, + tests: RunTests, + ): void; +} + +export { InvalidTestCase, RuleTester, RuleTesterConfig, RunTests, TestCaseError, ValidTestCase }; diff --git a/packages/util/src/ts-eslint/Scope.ts b/packages/util/src/ts-eslint/Scope.ts new file mode 100644 index 000000000000..e6922d9df190 --- /dev/null +++ b/packages/util/src/ts-eslint/Scope.ts @@ -0,0 +1,106 @@ +/* eslint-disable @typescript-eslint/no-namespace */ + +import { TSESTree } from '@typescript-eslint/typescript-estree'; + +namespace Scope { + export interface ScopeManager { + scopes: Scope[]; + globalScope: Scope | null; + + acquire(node: TSESTree.Node, inner?: boolean): Scope | null; + + getDeclaredVariables(node: TSESTree.Node): Variable[]; + } + + export interface Reference { + identifier: TSESTree.Identifier; + from: Scope; + resolved: Variable | null; + writeExpr: TSESTree.Node | null; + init: boolean; + + isWrite(): boolean; + + isRead(): boolean; + + isWriteOnly(): boolean; + + isReadOnly(): boolean; + + isReadWrite(): boolean; + } + + export interface Variable { + name: string; + identifiers: TSESTree.Identifier[]; + references: Reference[]; + defs: Definition[]; + scope: Scope; + eslintUsed?: boolean; + } + + export interface Scope { + type: + | 'block' + | 'catch' + | 'class' + | 'for' + | 'function' + | 'function-expression-name' + | 'global' + | 'module' + | 'switch' + | 'with' + | 'TDZ'; + isStrict: boolean; + upper: Scope | null; + childScopes: Scope[]; + variableScope: Scope; + block: TSESTree.Node; + variables: Variable[]; + set: Map; + references: Reference[]; + through: Reference[]; + functionExpressionScope: boolean; + } + + export type DefinitionType = + | { type: 'CatchClause'; node: TSESTree.CatchClause; parent: null } + | { + type: 'ClassName'; + node: TSESTree.ClassDeclaration | TSESTree.ClassExpression; + parent: null; + } + | { + type: 'FunctionName'; + node: TSESTree.FunctionDeclaration | TSESTree.FunctionExpression; + parent: null; + } + | { type: 'ImplicitGlobalVariable'; node: TSESTree.Program; parent: null } + | { + type: 'ImportBinding'; + node: + | TSESTree.ImportSpecifier + | TSESTree.ImportDefaultSpecifier + | TSESTree.ImportNamespaceSpecifier; + parent: TSESTree.ImportDeclaration; + } + | { + type: 'Parameter'; + node: + | TSESTree.FunctionDeclaration + | TSESTree.FunctionExpression + | TSESTree.ArrowFunctionExpression; + parent: null; + } + | { type: 'TDZ'; node: any; parent: null } + | { + type: 'Variable'; + node: TSESTree.VariableDeclarator; + parent: TSESTree.VariableDeclaration; + }; + + export type Definition = DefinitionType & { name: TSESTree.Identifier }; +} + +export { Scope }; diff --git a/packages/util/src/ts-eslint/SourceCode.ts b/packages/util/src/ts-eslint/SourceCode.ts new file mode 100644 index 000000000000..702acd44d143 --- /dev/null +++ b/packages/util/src/ts-eslint/SourceCode.ts @@ -0,0 +1,190 @@ +/* eslint-disable @typescript-eslint/no-namespace, no-redeclare */ + +import { ParserServices, TSESTree } from '@typescript-eslint/typescript-estree'; +import { AST } from 'eslint'; +import { Scope } from './Scope'; + +namespace SourceCode { + export interface Config { + text: string; + ast: AST.Program; + parserServices?: ParserServices; + scopeManager?: Scope.ScopeManager; + visitorKeys?: VisitorKeys; + } + + export interface VisitorKeys { + [nodeType: string]: string[]; + } + + export type FilterPredicate = ( + tokenOrComment: TSESTree.Token | TSESTree.Comment, + ) => boolean; + + export type CursorWithSkipOptions = + | number + | FilterPredicate + | { + includeComments?: boolean; + filter?: FilterPredicate; + skip?: number; + }; + + export type CursorWithCountOptions = + | number + | FilterPredicate + | { + includeComments?: boolean; + filter?: FilterPredicate; + count?: number; + }; +} + +declare class SourceCode { + text: string; + ast: AST.Program; + lines: string[]; + hasBOM: boolean; + parserServices: ParserServices; + scopeManager: Scope.ScopeManager; + visitorKeys: SourceCode.VisitorKeys; + + constructor(text: string, ast: AST.Program); + // eslint-disable-next-line no-dupe-class-members + constructor(config: SourceCode.Config); + + static splitLines(text: string): string[]; + + getText( + node?: TSESTree.Node, + beforeCount?: number, + afterCount?: number, + ): string; + + getLines(): string[]; + + getAllComments(): TSESTree.Comment[]; + + getComments( + node: TSESTree.Node, + ): { leading: TSESTree.Comment[]; trailing: TSESTree.Comment[] }; + + getJSDocComment(node: TSESTree.Node): TSESTree.Node | TSESTree.Token | null; + + getNodeByRangeIndex(index: number): TSESTree.Node | null; + + isSpaceBetweenTokens(first: TSESTree.Token, second: TSESTree.Token): boolean; + + getLocFromIndex(index: number): TSESTree.LineAndColumnData; + + getIndexFromLoc(location: TSESTree.LineAndColumnData): number; + + // Inherited methods from TokenStore + // --------------------------------- + + getTokenByRangeStart( + offset: number, + options?: { includeComments?: boolean }, + ): TSESTree.Token | null; + + getFirstToken( + node: TSESTree.Node, + options?: SourceCode.CursorWithSkipOptions, + ): TSESTree.Token | null; + + getFirstTokens( + node: TSESTree.Node, + options?: SourceCode.CursorWithCountOptions, + ): TSESTree.Token[]; + + getLastToken( + node: TSESTree.Node, + options?: SourceCode.CursorWithSkipOptions, + ): TSESTree.Token | null; + + getLastTokens( + node: TSESTree.Node, + options?: SourceCode.CursorWithCountOptions, + ): TSESTree.Token[]; + + getTokenBefore( + node: TSESTree.Node | TSESTree.Token | TSESTree.Comment, + options?: SourceCode.CursorWithSkipOptions, + ): TSESTree.Token | null; + + getTokensBefore( + node: TSESTree.Node | TSESTree.Token | TSESTree.Comment, + options?: SourceCode.CursorWithCountOptions, + ): TSESTree.Token[]; + + getTokenAfter( + node: TSESTree.Node | TSESTree.Token | TSESTree.Comment, + options?: SourceCode.CursorWithSkipOptions, + ): TSESTree.Token | null; + + getTokensAfter( + node: TSESTree.Node | TSESTree.Token | TSESTree.Comment, + options?: SourceCode.CursorWithCountOptions, + ): TSESTree.Token[]; + + getFirstTokenBetween( + left: TSESTree.Node | TSESTree.Token | TSESTree.Comment, + right: TSESTree.Node | TSESTree.Token | TSESTree.Comment, + options?: SourceCode.CursorWithSkipOptions, + ): TSESTree.Token | null; + + getFirstTokensBetween( + left: TSESTree.Node | TSESTree.Token | TSESTree.Comment, + right: TSESTree.Node | TSESTree.Token | TSESTree.Comment, + options?: SourceCode.CursorWithCountOptions, + ): TSESTree.Token[]; + + getLastTokenBetween( + left: TSESTree.Node | TSESTree.Token | TSESTree.Comment, + right: TSESTree.Node | TSESTree.Token | TSESTree.Comment, + options?: SourceCode.CursorWithSkipOptions, + ): TSESTree.Token | null; + + getLastTokensBetween( + left: TSESTree.Node | TSESTree.Token | TSESTree.Comment, + right: TSESTree.Node | TSESTree.Token | TSESTree.Comment, + options?: SourceCode.CursorWithCountOptions, + ): TSESTree.Token[]; + + getTokensBetween( + left: TSESTree.Node | TSESTree.Token | TSESTree.Comment, + right: TSESTree.Node | TSESTree.Token | TSESTree.Comment, + padding?: + | number + | SourceCode.FilterPredicate + | SourceCode.CursorWithCountOptions, + ): TSESTree.Token[]; + + getTokens( + node: TSESTree.Node, + beforeCount?: number, + afterCount?: number, + ): TSESTree.Token[]; + // eslint-disable-next-line no-dupe-class-members + getTokens( + node: TSESTree.Node, + options: SourceCode.FilterPredicate | SourceCode.CursorWithCountOptions, + ): TSESTree.Token[]; + + commentsExistBetween( + left: TSESTree.Node | TSESTree.Token, + right: TSESTree.Node | TSESTree.Token, + ): boolean; + + getCommentsBefore( + nodeOrToken: TSESTree.Node | TSESTree.Token, + ): TSESTree.Comment[]; + + getCommentsAfter( + nodeOrToken: TSESTree.Node | TSESTree.Token, + ): TSESTree.Comment[]; + + getCommentsInside(node: TSESTree.Node): TSESTree.Comment[]; +} + +export { SourceCode }; diff --git a/packages/util/src/ts-eslint/index.ts b/packages/util/src/ts-eslint/index.ts new file mode 100644 index 000000000000..591a516738d6 --- /dev/null +++ b/packages/util/src/ts-eslint/index.ts @@ -0,0 +1,5 @@ +export * from './ParserOptions'; +export * from './Rule'; +export * from './RuleTester'; +export * from './Scope'; +export * from './SourceCode'; diff --git a/packages/util/tsconfig.build.json b/packages/util/tsconfig.build.json index 901af460e416..f08482677f40 100644 --- a/packages/util/tsconfig.build.json +++ b/packages/util/tsconfig.build.json @@ -2,6 +2,7 @@ "extends": "../../tsconfig.base.json", "compilerOptions": { "outDir": "./dist", + "rootDir": "./src", "resolveJsonModule": true }, "include": [ diff --git a/packages/util/tsconfig.json b/packages/util/tsconfig.json index fc93e91c26d3..7418d4448682 100644 --- a/packages/util/tsconfig.json +++ b/packages/util/tsconfig.json @@ -3,8 +3,6 @@ "include": [ "src", "typings", - // include the parser's ambient typings because the parser exports them in its type defs - "../parser/typings", "tests", "tools" ] From cd9adccf20015f65372e40bba6cd5e1c08605fba Mon Sep 17 00:00:00 2001 From: Brad Zacher Date: Thu, 11 Apr 2019 15:03:57 -0700 Subject: [PATCH 3/8] move createRule into the util package --- packages/eslint-plugin/src/rules/await-thenable.ts | 4 ++-- packages/eslint-plugin/src/util/index.ts | 9 ++++++--- packages/typescript-estree/src/parser-options.ts | 2 ++ .../util => util/src/eslint-utils}/applyDefault.ts | 0 .../util => util/src/eslint-utils}/createRule.ts | 14 +++++++------- .../util => util/src/eslint-utils}/deepMerge.ts | 0 packages/util/src/eslint-utils/index.ts | 3 +++ packages/util/src/index.ts | 3 ++- 8 files changed, 22 insertions(+), 13 deletions(-) rename packages/{eslint-plugin/src/util => util/src/eslint-utils}/applyDefault.ts (100%) rename packages/{eslint-plugin/src/util => util/src/eslint-utils}/createRule.ts (75%) rename packages/{eslint-plugin/src/util => util/src/eslint-utils}/deepMerge.ts (100%) create mode 100644 packages/util/src/eslint-utils/index.ts diff --git a/packages/eslint-plugin/src/rules/await-thenable.ts b/packages/eslint-plugin/src/rules/await-thenable.ts index 7a2371078889..95df45534ca1 100644 --- a/packages/eslint-plugin/src/rules/await-thenable.ts +++ b/packages/eslint-plugin/src/rules/await-thenable.ts @@ -26,9 +26,9 @@ export default util.createRule({ return { AwaitExpression(node) { - const originalNode = parserServices.esTreeNodeToTSNodeMap.get( + const originalNode = parserServices.esTreeNodeToTSNodeMap.get( node, - ) as ts.AwaitExpression; + ); const type = checker.getTypeAtLocation(originalNode.expression); if ( diff --git a/packages/eslint-plugin/src/util/index.ts b/packages/eslint-plugin/src/util/index.ts index 56890ae19fce..0a6d859453ff 100644 --- a/packages/eslint-plugin/src/util/index.ts +++ b/packages/eslint-plugin/src/util/index.ts @@ -1,6 +1,9 @@ -export * from './applyDefault'; -export * from './createRule'; -export * from './deepMerge'; +import { ESLintUtils } from '@typescript-eslint/util'; + export * from './getParserServices'; export * from './misc'; export * from './types'; + +// this is done for convenience - saves migrating all of the old rules +const { applyDefault, createRule, deepMerge, isObjectNotArray } = ESLintUtils; +export { applyDefault, createRule, deepMerge, isObjectNotArray }; diff --git a/packages/typescript-estree/src/parser-options.ts b/packages/typescript-estree/src/parser-options.ts index c23e86b33810..f067b3e1e0bb 100644 --- a/packages/typescript-estree/src/parser-options.ts +++ b/packages/typescript-estree/src/parser-options.ts @@ -35,6 +35,8 @@ export interface ParserOptions { extraFileExtensions?: string[]; } +// This lets us use generics to type the return value, and removes the need to +// handle the undefined type in the get method export interface ParserWeakMap { get(key: TKey): TValue; has(key: any): boolean; diff --git a/packages/eslint-plugin/src/util/applyDefault.ts b/packages/util/src/eslint-utils/applyDefault.ts similarity index 100% rename from packages/eslint-plugin/src/util/applyDefault.ts rename to packages/util/src/eslint-utils/applyDefault.ts diff --git a/packages/eslint-plugin/src/util/createRule.ts b/packages/util/src/eslint-utils/createRule.ts similarity index 75% rename from packages/eslint-plugin/src/util/createRule.ts rename to packages/util/src/eslint-utils/createRule.ts index 5f816c04c38d..a392c7000fee 100644 --- a/packages/eslint-plugin/src/util/createRule.ts +++ b/packages/util/src/eslint-utils/createRule.ts @@ -1,4 +1,4 @@ -import { TSESLint } from '@typescript-eslint/util'; +import { RuleMetaData, RuleMetaDataDocs, RuleListener, RuleContext, RuleModule } from '../ts-eslint/Rule'; import { applyDefault } from './applyDefault'; // note - cannot migrate this to an import statement because it will make TSC copy the package.json to the dist folder @@ -11,19 +11,19 @@ type RemoveProps< > = Pick>; // we'll automatically add the url + tslint description for people. -type CreateRuleMetaDocs = RemoveProps & { +type CreateRuleMetaDocs = RemoveProps & { tslintName?: string; }; type CreateRuleMeta = { docs: CreateRuleMetaDocs; -} & RemoveProps, 'docs'>; +} & RemoveProps, 'docs'>; // This function will get much easier to call when this is merged https://github.com/Microsoft/TypeScript/pull/26349 -// TODO - when the above rule lands; add type checking for the context.report `data` property +// TODO - when the above PR lands; add type checking for the context.report `data` property export function createRule< TOptions extends any[], TMessageIds extends string, - TRuleListener extends TSESLint.RuleListener = TSESLint.RuleListener + TRuleListener extends RuleListener = RuleListener >({ name, meta, @@ -34,10 +34,10 @@ export function createRule< meta: CreateRuleMeta; defaultOptions: TOptions; create: ( - context: TSESLint.RuleContext, + context: RuleContext, optionsWithDefault: TOptions, ) => TRuleListener; -}): TSESLint.RuleModule { +}): RuleModule { return { meta: { ...meta, diff --git a/packages/eslint-plugin/src/util/deepMerge.ts b/packages/util/src/eslint-utils/deepMerge.ts similarity index 100% rename from packages/eslint-plugin/src/util/deepMerge.ts rename to packages/util/src/eslint-utils/deepMerge.ts diff --git a/packages/util/src/eslint-utils/index.ts b/packages/util/src/eslint-utils/index.ts new file mode 100644 index 000000000000..742b3a900fca --- /dev/null +++ b/packages/util/src/eslint-utils/index.ts @@ -0,0 +1,3 @@ +export * from './applyDefault'; +export * from './createRule'; +export * from './deepMerge'; diff --git a/packages/util/src/index.ts b/packages/util/src/index.ts index af4e6e898fa6..9de8c6920368 100644 --- a/packages/util/src/index.ts +++ b/packages/util/src/index.ts @@ -1,6 +1,7 @@ +import * as ESLintUtils from './eslint-utils'; import * as TSESLint from './ts-eslint'; -export { TSESLint }; +export { ESLintUtils, TSESLint }; // for convenience's sake - export the types directly from here so consumers // don't need to reference/install both packages in their code From f935bf6229a43a5cfcb6978b104601c6be93a779 Mon Sep 17 00:00:00 2001 From: Brad Zacher Date: Thu, 11 Apr 2019 15:05:36 -0700 Subject: [PATCH 4/8] run prettier --- packages/eslint-plugin/src/rules/await-thenable.ts | 6 +++--- .../src/rules/prefer-namespace-keyword.ts | 5 +---- .../eslint-plugin/src/util/getParserServices.ts | 4 +++- packages/eslint-plugin/tests/RuleTester.ts | 7 ++----- packages/eslint-plugin/tests/rules/indent.test.ts | 3 ++- packages/parser/src/parser.ts | 4 +--- packages/typescript-estree/src/node-utils.ts | 6 +----- packages/typescript-estree/tsconfig.json | 2 +- packages/util/package.json | 3 +-- packages/util/src/eslint-utils/createRule.ts | 8 +++++++- packages/util/src/ts-eslint/Rule.ts | 8 ++------ packages/util/src/ts-eslint/RuleTester.ts | 13 +++++++++---- packages/util/tsconfig.build.json | 4 +--- packages/util/tsconfig.json | 7 +------ 14 files changed, 35 insertions(+), 45 deletions(-) diff --git a/packages/eslint-plugin/src/rules/await-thenable.ts b/packages/eslint-plugin/src/rules/await-thenable.ts index 95df45534ca1..31f1624b8394 100644 --- a/packages/eslint-plugin/src/rules/await-thenable.ts +++ b/packages/eslint-plugin/src/rules/await-thenable.ts @@ -26,9 +26,9 @@ export default util.createRule({ return { AwaitExpression(node) { - const originalNode = parserServices.esTreeNodeToTSNodeMap.get( - node, - ); + const originalNode = parserServices.esTreeNodeToTSNodeMap.get< + ts.AwaitExpression + >(node); const type = checker.getTypeAtLocation(originalNode.expression); if ( diff --git a/packages/eslint-plugin/src/rules/prefer-namespace-keyword.ts b/packages/eslint-plugin/src/rules/prefer-namespace-keyword.ts index f40e2830829f..a3552b8ca57e 100644 --- a/packages/eslint-plugin/src/rules/prefer-namespace-keyword.ts +++ b/packages/eslint-plugin/src/rules/prefer-namespace-keyword.ts @@ -1,7 +1,4 @@ -import { - AST_NODE_TYPES, - AST_TOKEN_TYPES, -} from '@typescript-eslint/util'; +import { AST_NODE_TYPES, AST_TOKEN_TYPES } from '@typescript-eslint/util'; import * as util from '../util'; export default util.createRule({ diff --git a/packages/eslint-plugin/src/util/getParserServices.ts b/packages/eslint-plugin/src/util/getParserServices.ts index 6058620a754b..e1a1358c9d66 100644 --- a/packages/eslint-plugin/src/util/getParserServices.ts +++ b/packages/eslint-plugin/src/util/getParserServices.ts @@ -11,7 +11,9 @@ type RequiredParserServices = { export function getParserServices< TMessageIds extends string, TOptions extends any[] ->(context: TSESLint.RuleContext): RequiredParserServices { +>( + context: TSESLint.RuleContext, +): RequiredParserServices { if ( !context.parserServices || !context.parserServices.program || diff --git a/packages/eslint-plugin/tests/RuleTester.ts b/packages/eslint-plugin/tests/RuleTester.ts index 8383d6170ce6..5f049bf7258e 100644 --- a/packages/eslint-plugin/tests/RuleTester.ts +++ b/packages/eslint-plugin/tests/RuleTester.ts @@ -2,13 +2,10 @@ import { TSESLint } from '@typescript-eslint/util'; import { RuleTester as ESLintRuleTester } from 'eslint'; import * as path from 'path'; -const RuleTester: TSESLint.RuleTester = (ESLintRuleTester as any); +const RuleTester: TSESLint.RuleTester = ESLintRuleTester as any; function getFixturesRootDir() { return path.join(process.cwd(), 'tests/fixtures/'); } -export { - RuleTester, - getFixturesRootDir, -}; +export { RuleTester, getFixturesRootDir }; diff --git a/packages/eslint-plugin/tests/rules/indent.test.ts b/packages/eslint-plugin/tests/rules/indent.test.ts index 9f35cae6d939..4c47e85ce133 100644 --- a/packages/eslint-plugin/tests/rules/indent.test.ts +++ b/packages/eslint-plugin/tests/rules/indent.test.ts @@ -650,7 +650,8 @@ type Foo = string | { }; }) .filter( - (error): error is TSESLint.TestCaseError => error !== null, + (error): error is TSESLint.TestCaseError => + error !== null, ), }); }); diff --git a/packages/parser/src/parser.ts b/packages/parser/src/parser.ts index e978ea529ce7..4106facd0177 100644 --- a/packages/parser/src/parser.ts +++ b/packages/parser/src/parser.ts @@ -4,9 +4,7 @@ import { ParserOptions as ParserOptionsTsESTree, ParserServices, } from '@typescript-eslint/typescript-estree'; -import { - TSESLint, -} from '@typescript-eslint/util'; +import { TSESLint } from '@typescript-eslint/util'; import traverser from 'eslint/lib/util/traverser'; import { analyzeScope } from './analyze-scope'; import { visitorKeys } from './visitor-keys'; diff --git a/packages/typescript-estree/src/node-utils.ts b/packages/typescript-estree/src/node-utils.ts index 7b03f8dd6a6c..30f4c855b45d 100644 --- a/packages/typescript-estree/src/node-utils.ts +++ b/packages/typescript-estree/src/node-utils.ts @@ -1,8 +1,4 @@ -import { - AST_NODE_TYPES, - AST_TOKEN_TYPES, - TSESTree, -} from './ts-estree'; +import { AST_NODE_TYPES, AST_TOKEN_TYPES, TSESTree } from './ts-estree'; import unescape from 'lodash.unescape'; import ts from 'typescript'; diff --git a/packages/typescript-estree/tsconfig.json b/packages/typescript-estree/tsconfig.json index 7edf4752f6eb..e389d7edef33 100644 --- a/packages/typescript-estree/tsconfig.json +++ b/packages/typescript-estree/tsconfig.json @@ -1,7 +1,7 @@ { "extends": "../../tsconfig.base.json", "compilerOptions": { - "outDir": "./dist", + "outDir": "./dist" }, "include": ["src", "tests", "tools"] } diff --git a/packages/util/package.json b/packages/util/package.json index 77923001a9dd..00f67d786f43 100644 --- a/packages/util/package.json +++ b/packages/util/package.json @@ -33,8 +33,7 @@ "dependencies": { "@typescript-eslint/typescript-estree": "1.6.0" }, - "devDependencies": { - }, + "devDependencies": {}, "peerDependencies": { "typescript": "*" } diff --git a/packages/util/src/eslint-utils/createRule.ts b/packages/util/src/eslint-utils/createRule.ts index a392c7000fee..074ff2177727 100644 --- a/packages/util/src/eslint-utils/createRule.ts +++ b/packages/util/src/eslint-utils/createRule.ts @@ -1,4 +1,10 @@ -import { RuleMetaData, RuleMetaDataDocs, RuleListener, RuleContext, RuleModule } from '../ts-eslint/Rule'; +import { + RuleMetaData, + RuleMetaDataDocs, + RuleListener, + RuleContext, + RuleModule, +} from '../ts-eslint/Rule'; import { applyDefault } from './applyDefault'; // note - cannot migrate this to an import statement because it will make TSC copy the package.json to the dist folder diff --git a/packages/util/src/ts-eslint/Rule.ts b/packages/util/src/ts-eslint/Rule.ts index 5633e6df85ef..fdbea5d342a6 100644 --- a/packages/util/src/ts-eslint/Rule.ts +++ b/packages/util/src/ts-eslint/Rule.ts @@ -300,12 +300,8 @@ interface RuleListener { TSEnumMember?: RuleFunction; TSExportAssignment?: RuleFunction; TSExportKeyword?: RuleFunction; - TSExternalModuleReference?: RuleFunction< - TSESTree.TSExternalModuleReference - >; - TSImportEqualsDeclaration?: RuleFunction< - TSESTree.TSImportEqualsDeclaration - >; + TSExternalModuleReference?: RuleFunction; + TSImportEqualsDeclaration?: RuleFunction; TSImportType?: RuleFunction; TSIndexedAccessType?: RuleFunction; TSIndexSignature?: RuleFunction; diff --git a/packages/util/src/ts-eslint/RuleTester.ts b/packages/util/src/ts-eslint/RuleTester.ts index 9ce48ceac760..4a7c76b117c1 100644 --- a/packages/util/src/ts-eslint/RuleTester.ts +++ b/packages/util/src/ts-eslint/RuleTester.ts @@ -1,6 +1,4 @@ -import { - AST_NODE_TYPES, -} from '@typescript-eslint/typescript-estree'; +import { AST_NODE_TYPES } from '@typescript-eslint/typescript-estree'; import { ParserOptions } from './ParserOptions'; import { RuleModule } from './Rule'; @@ -65,4 +63,11 @@ interface RuleTester { ): void; } -export { InvalidTestCase, RuleTester, RuleTesterConfig, RunTests, TestCaseError, ValidTestCase }; +export { + InvalidTestCase, + RuleTester, + RuleTesterConfig, + RunTests, + TestCaseError, + ValidTestCase, +}; diff --git a/packages/util/tsconfig.build.json b/packages/util/tsconfig.build.json index f08482677f40..0ce1565b0d05 100644 --- a/packages/util/tsconfig.build.json +++ b/packages/util/tsconfig.build.json @@ -5,7 +5,5 @@ "rootDir": "./src", "resolveJsonModule": true }, - "include": [ - "src", - ] + "include": ["src"] } diff --git a/packages/util/tsconfig.json b/packages/util/tsconfig.json index 7418d4448682..fb7e21da237d 100644 --- a/packages/util/tsconfig.json +++ b/packages/util/tsconfig.json @@ -1,9 +1,4 @@ { "extends": "./tsconfig.build.json", - "include": [ - "src", - "typings", - "tests", - "tools" - ] + "include": ["src", "typings", "tests", "tools"] } From db1bc9d8bd95fb89df26974d63eb7098868af2c0 Mon Sep 17 00:00:00 2001 From: Brad Zacher Date: Thu, 11 Apr 2019 15:24:12 -0700 Subject: [PATCH 5/8] move util tests to the correct package --- packages/eslint-plugin/tests/util.test.ts | 112 ------------------ packages/util/jest.config.js | 13 ++ .../tests/eslint-utils/applyDefault.test.ts | 59 +++++++++ .../util/tests/eslint-utils/deepMerge.test.ts | 60 ++++++++++ packages/util/tsconfig.json | 6 +- yarn.lock | 6 +- 6 files changed, 140 insertions(+), 116 deletions(-) create mode 100644 packages/util/jest.config.js create mode 100644 packages/util/tests/eslint-utils/applyDefault.test.ts create mode 100644 packages/util/tests/eslint-utils/deepMerge.test.ts diff --git a/packages/eslint-plugin/tests/util.test.ts b/packages/eslint-plugin/tests/util.test.ts index 957b50b286e3..59c820d28b9c 100644 --- a/packages/eslint-plugin/tests/util.test.ts +++ b/packages/eslint-plugin/tests/util.test.ts @@ -69,118 +69,6 @@ describe('isDefinitionFile', () => { }); }); -describe('deepMerge', () => { - it('creates a brand new object', () => { - const a = {}; - const b = {}; - const result = util.deepMerge(a, b); - - assert.notStrictEqual(result, a); - assert.notStrictEqual(result, b); - }); - - it('deeply merges objects', () => { - const a = { - stringA1: 'asdf', - numberA1: 1, - boolA1: true, - arrayA1: [1, 2, 3], - objA1: { - stringA2: 'fsda', - numberA2: 2, - boolA2: false, - arrayA2: [3, 2, 1], - objA2: {}, - }, - }; - const b = { - stringB1: 'asdf', - numberB1: 1, - boolB1: true, - arrayB1: [1, 2, 3], - objB1: { - stringB2: 'fsda', - numberB2: 2, - boolB2: false, - arrayB2: [3, 2, 1], - objB2: {}, - }, - }; - - assert.deepStrictEqual(util.deepMerge(a, b), Object.assign({}, a, b)); - }); - - it('deeply overwrites properties in the first one with the second', () => { - const a = { - prop1: { - prop2: 'hi', - }, - }; - const b = { - prop1: { - prop2: 'bye', - }, - }; - - assert.deepStrictEqual(util.deepMerge(a, b), b); - }); -}); - -describe('applyDefault', () => { - it('returns a clone of the default if no options given', () => { - const defaults = [ - { - prop: 'setting', - }, - ]; - const user = null; - const result = util.applyDefault(defaults, user); - - assert.deepStrictEqual(result, defaults); - assert.notStrictEqual(result, defaults); - }); - - it('returns applies a deepMerge to each element in the array', () => { - const defaults = [ - { - prop: 'setting1', - other: 'other', - }, - { - prop: 'setting2', - }, - ] as Record[]; - const user = [ - { - prop: 'new', - other: 'something', - }, - ] as Record[]; - const result = util.applyDefault(defaults, user); - - assert.deepStrictEqual(result, [ - { - prop: 'new', - other: 'something', - }, - { - prop: 'setting2', - }, - ]); - assert.notStrictEqual(result, defaults); - assert.notStrictEqual(result, user); - }); - - it('returns a brand new array', () => { - const defaults: undefined[] = []; - const user: undefined[] = []; - const result = util.applyDefault(defaults, user); - - assert.notStrictEqual(result, defaults); - assert.notStrictEqual(result, user); - }); -}); - describe('upperCaseFirst', () => { it('upper cases first', () => { assert.strictEqual(util.upperCaseFirst('hello'), 'Hello'); diff --git a/packages/util/jest.config.js b/packages/util/jest.config.js new file mode 100644 index 000000000000..b64d433b01aa --- /dev/null +++ b/packages/util/jest.config.js @@ -0,0 +1,13 @@ +'use strict'; + +module.exports = { + testEnvironment: 'node', + transform: { + '^.+\\.tsx?$': 'ts-jest', + }, + testRegex: './tests/.+\\.test\\.ts$', + collectCoverage: false, + collectCoverageFrom: ['src/**/*.{js,jsx,ts,tsx}'], + moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx', 'json', 'node'], + coverageReporters: ['text-summary', 'lcov'], +}; diff --git a/packages/util/tests/eslint-utils/applyDefault.test.ts b/packages/util/tests/eslint-utils/applyDefault.test.ts new file mode 100644 index 000000000000..3caa86ae45a6 --- /dev/null +++ b/packages/util/tests/eslint-utils/applyDefault.test.ts @@ -0,0 +1,59 @@ +import assert from 'assert'; + +import * as util from '../../src/eslint-utils/applyDefault'; + +describe('applyDefault', () => { + it('returns a clone of the default if no options given', () => { + const defaults = [ + { + prop: 'setting', + }, + ]; + const user = null; + const result = util.applyDefault(defaults, user); + + assert.deepStrictEqual(result, defaults); + assert.notStrictEqual(result, defaults); + }); + + it('returns applies a deepMerge to each element in the array', () => { + const defaults = [ + { + prop: 'setting1', + other: 'other', + }, + { + prop: 'setting2', + }, + ] as Record[]; + const user = [ + { + prop: 'new', + other: 'something', + }, + ] as Record[]; + const result = util.applyDefault(defaults, user); + + assert.deepStrictEqual(result, [ + { + prop: 'new', + other: 'something', + }, + { + prop: 'setting2', + }, + ]); + assert.notStrictEqual(result, defaults); + assert.notStrictEqual(result, user); + }); + + it('returns a brand new array', () => { + const defaults: undefined[] = []; + const user: undefined[] = []; + const result = util.applyDefault(defaults, user); + + assert.notStrictEqual(result, defaults); + assert.notStrictEqual(result, user); + }); +}); + diff --git a/packages/util/tests/eslint-utils/deepMerge.test.ts b/packages/util/tests/eslint-utils/deepMerge.test.ts new file mode 100644 index 000000000000..27e55c996a92 --- /dev/null +++ b/packages/util/tests/eslint-utils/deepMerge.test.ts @@ -0,0 +1,60 @@ +import assert from 'assert'; + +import * as util from '../../src/eslint-utils/deepMerge'; + +describe('deepMerge', () => { + it('creates a brand new object', () => { + const a = {}; + const b = {}; + const result = util.deepMerge(a, b); + + assert.notStrictEqual(result, a); + assert.notStrictEqual(result, b); + }); + + it('deeply merges objects', () => { + const a = { + stringA1: 'asdf', + numberA1: 1, + boolA1: true, + arrayA1: [1, 2, 3], + objA1: { + stringA2: 'fsda', + numberA2: 2, + boolA2: false, + arrayA2: [3, 2, 1], + objA2: {}, + }, + }; + const b = { + stringB1: 'asdf', + numberB1: 1, + boolB1: true, + arrayB1: [1, 2, 3], + objB1: { + stringB2: 'fsda', + numberB2: 2, + boolB2: false, + arrayB2: [3, 2, 1], + objB2: {}, + }, + }; + + assert.deepStrictEqual(util.deepMerge(a, b), Object.assign({}, a, b)); + }); + + it('deeply overwrites properties in the first one with the second', () => { + const a = { + prop1: { + prop2: 'hi', + }, + }; + const b = { + prop1: { + prop2: 'bye', + }, + }; + + assert.deepStrictEqual(util.deepMerge(a, b), b); + }); +}); diff --git a/packages/util/tsconfig.json b/packages/util/tsconfig.json index fb7e21da237d..f469d044ef4b 100644 --- a/packages/util/tsconfig.json +++ b/packages/util/tsconfig.json @@ -1,4 +1,8 @@ { - "extends": "./tsconfig.build.json", + "extends": "../../tsconfig.base.json", + "compilerOptions": { + "outDir": "./dist", + "resolveJsonModule": true + }, "include": ["src", "typings", "tests", "tools"] } diff --git a/yarn.lock b/yarn.lock index d26da3f9306d..2ce95340e17b 100644 --- a/yarn.lock +++ b/yarn.lock @@ -7053,9 +7053,9 @@ typedarray@^0.0.6: integrity sha1-hnrHTjhkGHsdPUfZlqeOxciDB3c= "typescript@>=3.2.1 <3.5.0": - version "3.4.1" - resolved "https://registry.yarnpkg.com/typescript/-/typescript-3.4.1.tgz#b6691be11a881ffa9a05765a205cb7383f3b63c6" - integrity sha512-3NSMb2VzDQm8oBTLH6Nj55VVtUEpe/rgkIzMir0qVoLyjDZlnMBva0U6vDiV3IH+sl/Yu6oP5QwsAQtHPmDd2Q== + version "3.4.3" + resolved "https://registry.yarnpkg.com/typescript/-/typescript-3.4.3.tgz#0eb320e4ace9b10eadf5bc6103286b0f8b7c224f" + integrity sha512-FFgHdPt4T/duxx6Ndf7hwgMZZjZpB+U0nMNGVCYPq0rEzWKjEDobm4J6yb3CS7naZ0yURFqdw9Gwc7UOh/P9oQ== uglify-js@^3.1.4: version "3.4.9" From 77f3eabd7fde4a87407999f0914ee7238b305d75 Mon Sep 17 00:00:00 2001 From: Brad Zacher Date: Thu, 11 Apr 2019 15:34:39 -0700 Subject: [PATCH 6/8] switch to * as ts within typescript-estree to better support external users --- .eslintignore | 1 - packages/typescript-estree/src/ast-converter.ts | 4 ++-- packages/typescript-estree/src/convert-comments.ts | 4 ++-- packages/typescript-estree/src/convert.ts | 4 ++-- packages/typescript-estree/src/node-utils.ts | 4 ++-- packages/typescript-estree/src/parser-options.ts | 2 +- packages/typescript-estree/src/parser.ts | 4 ++-- packages/typescript-estree/src/semantic-errors.ts | 2 +- packages/typescript-estree/src/ts-estree/ts-nodes.ts | 2 +- packages/typescript-estree/src/tsconfig-parser.ts | 2 +- 10 files changed, 14 insertions(+), 15 deletions(-) diff --git a/.eslintignore b/.eslintignore index c1536a77bd33..92693b863825 100644 --- a/.eslintignore +++ b/.eslintignore @@ -5,5 +5,4 @@ fixtures shared-fixtures coverage -packages/typescript-estree/src/estree packages/eslint-plugin-tslint/tests diff --git a/packages/typescript-estree/src/ast-converter.ts b/packages/typescript-estree/src/ast-converter.ts index fea7a6580a58..03d1253f5274 100644 --- a/packages/typescript-estree/src/ast-converter.ts +++ b/packages/typescript-estree/src/ast-converter.ts @@ -1,11 +1,11 @@ -import ts from 'typescript'; +import { SourceFile } from 'typescript'; import { convertError, Converter } from './convert'; import { convertComments } from './convert-comments'; import { convertTokens } from './node-utils'; import { Extra } from './parser-options'; export default function astConverter( - ast: ts.SourceFile, + ast: SourceFile, extra: Extra, shouldProvideParserServices: boolean, ) { diff --git a/packages/typescript-estree/src/convert-comments.ts b/packages/typescript-estree/src/convert-comments.ts index 431030a7c548..026500da7d35 100644 --- a/packages/typescript-estree/src/convert-comments.ts +++ b/packages/typescript-estree/src/convert-comments.ts @@ -1,6 +1,6 @@ -import { TSESTree } from './ts-estree'; -import ts from 'typescript'; +import * as ts from 'typescript'; // leave this as * as ts so people using util package don't need syntheticDefaultImports import { getLocFor, getNodeContainer } from './node-utils'; +import { TSESTree } from './ts-estree'; /** * Converts a TypeScript comment to an Esprima comment. diff --git a/packages/typescript-estree/src/convert.ts b/packages/typescript-estree/src/convert.ts index e9b5ae0d85cb..d26afded2f3a 100644 --- a/packages/typescript-estree/src/convert.ts +++ b/packages/typescript-estree/src/convert.ts @@ -1,5 +1,4 @@ -import { AST_NODE_TYPES, TSESTree, TSNode } from './ts-estree'; -import ts from 'typescript'; +import * as ts from 'typescript'; // leave this as * as ts so people using util package don't need syntheticDefaultImports import { canContainDirective, createError, @@ -19,6 +18,7 @@ import { isOptional, unescapeStringLiteralText, } from './node-utils'; +import { AST_NODE_TYPES, TSESTree, TSNode } from './ts-estree'; const SyntaxKind = ts.SyntaxKind; diff --git a/packages/typescript-estree/src/node-utils.ts b/packages/typescript-estree/src/node-utils.ts index 30f4c855b45d..955e52312be0 100644 --- a/packages/typescript-estree/src/node-utils.ts +++ b/packages/typescript-estree/src/node-utils.ts @@ -1,6 +1,6 @@ -import { AST_NODE_TYPES, AST_TOKEN_TYPES, TSESTree } from './ts-estree'; import unescape from 'lodash.unescape'; -import ts from 'typescript'; +import * as ts from 'typescript'; // leave this as * as ts so people using util package don't need syntheticDefaultImports +import { AST_NODE_TYPES, AST_TOKEN_TYPES, TSESTree } from './ts-estree'; const SyntaxKind = ts.SyntaxKind; diff --git a/packages/typescript-estree/src/parser-options.ts b/packages/typescript-estree/src/parser-options.ts index f067b3e1e0bb..ee8060e7a64c 100644 --- a/packages/typescript-estree/src/parser-options.ts +++ b/packages/typescript-estree/src/parser-options.ts @@ -1,5 +1,5 @@ -import { TSESTree, TSNode } from './ts-estree'; import { Program } from 'typescript'; +import { TSESTree, TSNode } from './ts-estree'; export interface Extra { errorOnUnknownASTType: boolean; diff --git a/packages/typescript-estree/src/parser.ts b/packages/typescript-estree/src/parser.ts index 42b501f68cb9..5deff2ac905e 100644 --- a/packages/typescript-estree/src/parser.ts +++ b/packages/typescript-estree/src/parser.ts @@ -1,11 +1,11 @@ -import { TSESTree } from './ts-estree'; import semver from 'semver'; -import ts from 'typescript'; +import * as ts from 'typescript'; // leave this as * as ts so people using util package don't need syntheticDefaultImports import convert from './ast-converter'; import { convertError } from './convert'; import { firstDefined } from './node-utils'; import { Extra, ParserOptions, ParserServices } from './parser-options'; import { getFirstSemanticOrSyntacticError } from './semantic-errors'; +import { TSESTree } from './ts-estree'; import { calculateProjectParserOptions, createProgram, diff --git a/packages/typescript-estree/src/semantic-errors.ts b/packages/typescript-estree/src/semantic-errors.ts index 4486532c09d9..15339f96e25c 100644 --- a/packages/typescript-estree/src/semantic-errors.ts +++ b/packages/typescript-estree/src/semantic-errors.ts @@ -1,4 +1,4 @@ -import ts from 'typescript'; +import * as ts from 'typescript'; // leave this as * as ts so people using util package don't need syntheticDefaultImports interface SemanticOrSyntacticError extends ts.Diagnostic { message: string; diff --git a/packages/typescript-estree/src/ts-estree/ts-nodes.ts b/packages/typescript-estree/src/ts-estree/ts-nodes.ts index b917584cf380..b4298fa1530a 100644 --- a/packages/typescript-estree/src/ts-estree/ts-nodes.ts +++ b/packages/typescript-estree/src/ts-estree/ts-nodes.ts @@ -1,4 +1,4 @@ -import ts from 'typescript'; +import * as ts from 'typescript'; // leave this as * as ts so people using util package don't need syntheticDefaultImports export type TSNode = ts.Node & ( diff --git a/packages/typescript-estree/src/tsconfig-parser.ts b/packages/typescript-estree/src/tsconfig-parser.ts index d953b39d8ead..4d5000caab6e 100644 --- a/packages/typescript-estree/src/tsconfig-parser.ts +++ b/packages/typescript-estree/src/tsconfig-parser.ts @@ -1,5 +1,5 @@ import path from 'path'; -import ts from 'typescript'; +import * as ts from 'typescript'; // leave this as * as ts so people using util package don't need syntheticDefaultImports import { Extra } from './parser-options'; //------------------------------------------------------------------------------ From ddf079148dede815488a88eabe53352d7bb396e4 Mon Sep 17 00:00:00 2001 From: Brad Zacher Date: Thu, 11 Apr 2019 17:05:12 -0700 Subject: [PATCH 7/8] yarn format --- packages/util/tests/eslint-utils/applyDefault.test.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/packages/util/tests/eslint-utils/applyDefault.test.ts b/packages/util/tests/eslint-utils/applyDefault.test.ts index 3caa86ae45a6..3ff4a843ec2e 100644 --- a/packages/util/tests/eslint-utils/applyDefault.test.ts +++ b/packages/util/tests/eslint-utils/applyDefault.test.ts @@ -56,4 +56,3 @@ describe('applyDefault', () => { assert.notStrictEqual(result, user); }); }); - From d3bd94f36b7656cb5fd7272e0f9b27eb745aa2d4 Mon Sep 17 00:00:00 2001 From: Brad Zacher Date: Wed, 8 May 2019 18:39:14 -0700 Subject: [PATCH 8/8] rename to experimental-utils, update readme --- packages/eslint-plugin/package.json | 2 +- .../src/rules/adjacent-overload-signatures.ts | 5 ++- .../eslint-plugin/src/rules/array-type.ts | 2 +- packages/eslint-plugin/src/rules/ban-types.ts | 6 +++- packages/eslint-plugin/src/rules/camelcase.ts | 5 ++- .../src/rules/class-name-casing.ts | 5 ++- .../rules/explicit-function-return-type.ts | 5 ++- .../rules/explicit-member-accessibility.ts | 5 ++- .../src/rules/func-call-spacing.ts | 2 +- packages/eslint-plugin/src/rules/indent.ts | 5 ++- .../src/rules/member-delimiter-style.ts | 5 ++- .../eslint-plugin/src/rules/member-naming.ts | 2 +- .../src/rules/member-ordering.ts | 5 ++- .../src/rules/no-array-constructor.ts | 5 ++- .../src/rules/no-extra-parens.ts | 5 ++- .../src/rules/no-extraneous-class.ts | 5 ++- .../src/rules/no-inferrable-types.ts | 5 ++- .../src/rules/no-magic-numbers.ts | 5 ++- .../eslint-plugin/src/rules/no-misused-new.ts | 5 ++- .../eslint-plugin/src/rules/no-namespace.ts | 5 ++- .../rules/no-object-literal-type-assertion.ts | 5 ++- .../src/rules/no-parameter-properties.ts | 5 ++- .../src/rules/no-require-imports.ts | 2 +- .../eslint-plugin/src/rules/no-this-alias.ts | 5 ++- .../eslint-plugin/src/rules/no-type-alias.ts | 6 +++- .../src/rules/no-unnecessary-qualifier.ts | 2 +- .../rules/no-unnecessary-type-assertion.ts | 2 +- .../eslint-plugin/src/rules/no-unused-vars.ts | 5 ++- .../src/rules/no-use-before-define.ts | 6 +++- .../src/rules/no-useless-constructor.ts | 5 ++- .../src/rules/no-var-requires.ts | 2 +- .../eslint-plugin/src/rules/prefer-for-of.ts | 6 +++- .../src/rules/prefer-function-type.ts | 2 +- .../src/rules/prefer-includes.ts | 2 +- .../src/rules/prefer-interface.ts | 2 +- .../src/rules/prefer-namespace-keyword.ts | 5 ++- .../rules/prefer-string-starts-ends-with.ts | 2 +- .../src/rules/promise-function-async.ts | 2 +- .../src/rules/require-array-sort-compare.ts | 2 +- .../src/rules/restrict-plus-operands.ts | 2 +- packages/eslint-plugin/src/rules/semi.ts | 6 +++- .../src/rules/type-annotation-spacing.ts | 2 +- .../eslint-plugin/src/rules/unbound-method.ts | 5 ++- .../src/rules/unified-signatures.ts | 5 ++- packages/eslint-plugin/src/util/createRule.ts | 2 +- .../src/util/getParserServices.ts | 2 +- packages/eslint-plugin/src/util/index.ts | 2 +- packages/eslint-plugin/src/util/misc.ts | 6 +++- packages/eslint-plugin/tests/RuleTester.ts | 2 +- .../tests/eslint-rules/no-redeclare.test.ts | 2 +- .../tests/rules/func-call-spacing.test.ts | 2 +- .../eslint-plugin/tests/rules/indent.test.ts | 2 +- .../tests/rules/no-array-constructor.test.ts | 2 +- .../tests/rules/no-extraneous-class.test.ts | 2 +- .../tests/rules/no-for-in-array.test.ts | 2 +- .../tests/rules/no-this-alias.test.ts | 2 +- .../rules/no-unnecessary-qualifier.test.ts | 2 +- .../tests/rules/no-use-before-define.test.ts | 2 +- .../tests/rules/prefer-function-type.test.ts | 2 +- .../eslint-plugin/tests/rules/semi.test.ts | 2 +- .../rules/type-annotation-spacing.test.ts | 2 +- .../eslint-plugin/typings/eslint-rules.d.ts | 32 +++++++++---------- .../eslint-plugin/typings/eslint-utils.d.ts | 2 +- packages/{util => experimental-utils}/LICENSE | 0 .../{util => experimental-utils}/README.md | 18 ++++++++--- .../jest.config.js | 0 .../{util => experimental-utils}/package.json | 4 +-- .../src/eslint-utils/RuleCreator.ts | 0 .../src/eslint-utils/applyDefault.ts | 0 .../src/eslint-utils/deepMerge.ts | 0 .../src/eslint-utils/index.ts | 0 .../{util => experimental-utils}/src/index.ts | 0 .../src/ts-eslint/AST.ts | 0 .../src/ts-eslint/Linter.ts | 0 .../src/ts-eslint/ParserOptions.ts | 0 .../src/ts-eslint/Rule.ts | 0 .../src/ts-eslint/RuleTester.ts | 0 .../src/ts-eslint/Scope.ts | 0 .../src/ts-eslint/SourceCode.ts | 0 .../src/ts-eslint/index.ts | 0 .../tests/eslint-utils/applyDefault.test.ts | 0 .../tests/eslint-utils/deepMerge.test.ts | 0 .../tsconfig.build.json | 0 .../tsconfig.json | 0 packages/parser/package.json | 2 +- packages/parser/src/parser.ts | 6 ++-- packages/parser/typings/eslint-scope.d.ts | 16 +++++----- .../typescript-estree/src/parser-options.ts | 2 +- packages/typescript-estree/src/parser.ts | 20 ++++++------ .../typescript-estree/tests/lib/comments.ts | 4 +-- .../typescript-estree/tests/lib/javascript.ts | 4 +-- packages/typescript-estree/tests/lib/jsx.ts | 4 +-- packages/typescript-estree/tests/lib/parse.ts | 10 +++--- .../tests/lib/semantic-diagnostics-enabled.ts | 2 +- .../tests/lib/semanticInfo.ts | 4 +-- packages/typescript-estree/tests/lib/tsx.ts | 4 +-- .../typescript-estree/tests/lib/typescript.ts | 4 +-- .../typescript-estree/tools/test-utils.ts | 8 ++--- 98 files changed, 231 insertions(+), 130 deletions(-) rename packages/{util => experimental-utils}/LICENSE (100%) rename packages/{util => experimental-utils}/README.md (73%) rename packages/{util => experimental-utils}/jest.config.js (100%) rename packages/{util => experimental-utils}/package.json (84%) rename packages/{util => experimental-utils}/src/eslint-utils/RuleCreator.ts (100%) rename packages/{util => experimental-utils}/src/eslint-utils/applyDefault.ts (100%) rename packages/{util => experimental-utils}/src/eslint-utils/deepMerge.ts (100%) rename packages/{util => experimental-utils}/src/eslint-utils/index.ts (100%) rename packages/{util => experimental-utils}/src/index.ts (100%) rename packages/{util => experimental-utils}/src/ts-eslint/AST.ts (100%) rename packages/{util => experimental-utils}/src/ts-eslint/Linter.ts (100%) rename packages/{util => experimental-utils}/src/ts-eslint/ParserOptions.ts (100%) rename packages/{util => experimental-utils}/src/ts-eslint/Rule.ts (100%) rename packages/{util => experimental-utils}/src/ts-eslint/RuleTester.ts (100%) rename packages/{util => experimental-utils}/src/ts-eslint/Scope.ts (100%) rename packages/{util => experimental-utils}/src/ts-eslint/SourceCode.ts (100%) rename packages/{util => experimental-utils}/src/ts-eslint/index.ts (100%) rename packages/{util => experimental-utils}/tests/eslint-utils/applyDefault.test.ts (100%) rename packages/{util => experimental-utils}/tests/eslint-utils/deepMerge.test.ts (100%) rename packages/{util => experimental-utils}/tsconfig.build.json (100%) rename packages/{util => experimental-utils}/tsconfig.json (100%) diff --git a/packages/eslint-plugin/package.json b/packages/eslint-plugin/package.json index f01a9975af64..4f9985402a2f 100644 --- a/packages/eslint-plugin/package.json +++ b/packages/eslint-plugin/package.json @@ -36,7 +36,7 @@ }, "dependencies": { "@typescript-eslint/parser": "1.7.0", - "@typescript-eslint/util": "1.7.0", + "@typescript-eslint/experimental-utils": "1.7.0", "eslint-utils": "^1.3.1", "regexpp": "^2.0.1", "requireindex": "^1.2.0", diff --git a/packages/eslint-plugin/src/rules/adjacent-overload-signatures.ts b/packages/eslint-plugin/src/rules/adjacent-overload-signatures.ts index 313af768d5f8..80c8b1315877 100644 --- a/packages/eslint-plugin/src/rules/adjacent-overload-signatures.ts +++ b/packages/eslint-plugin/src/rules/adjacent-overload-signatures.ts @@ -1,4 +1,7 @@ -import { TSESTree, AST_NODE_TYPES } from '@typescript-eslint/util'; +import { + TSESTree, + AST_NODE_TYPES, +} from '@typescript-eslint/experimental-utils'; import * as util from '../util'; type RuleNode = diff --git a/packages/eslint-plugin/src/rules/array-type.ts b/packages/eslint-plugin/src/rules/array-type.ts index 0fbc6a6e890f..62ace5d43171 100644 --- a/packages/eslint-plugin/src/rules/array-type.ts +++ b/packages/eslint-plugin/src/rules/array-type.ts @@ -2,7 +2,7 @@ import { AST_NODE_TYPES, AST_TOKEN_TYPES, TSESTree, -} from '@typescript-eslint/util'; +} from '@typescript-eslint/experimental-utils'; import * as util from '../util'; /** diff --git a/packages/eslint-plugin/src/rules/ban-types.ts b/packages/eslint-plugin/src/rules/ban-types.ts index c92822f40318..25c0a08f3ab1 100644 --- a/packages/eslint-plugin/src/rules/ban-types.ts +++ b/packages/eslint-plugin/src/rules/ban-types.ts @@ -1,4 +1,8 @@ -import { TSESLint, TSESTree, AST_NODE_TYPES } from '@typescript-eslint/util'; +import { + TSESLint, + TSESTree, + AST_NODE_TYPES, +} from '@typescript-eslint/experimental-utils'; import * as util from '../util'; type Options = [ diff --git a/packages/eslint-plugin/src/rules/camelcase.ts b/packages/eslint-plugin/src/rules/camelcase.ts index 49e7d3290b93..f3cb5948e5d0 100644 --- a/packages/eslint-plugin/src/rules/camelcase.ts +++ b/packages/eslint-plugin/src/rules/camelcase.ts @@ -1,4 +1,7 @@ -import { TSESTree, AST_NODE_TYPES } from '@typescript-eslint/util'; +import { + TSESTree, + AST_NODE_TYPES, +} from '@typescript-eslint/experimental-utils'; import baseRule from 'eslint/lib/rules/camelcase'; import * as util from '../util'; diff --git a/packages/eslint-plugin/src/rules/class-name-casing.ts b/packages/eslint-plugin/src/rules/class-name-casing.ts index 88f072b4ad5b..829f29f24b84 100644 --- a/packages/eslint-plugin/src/rules/class-name-casing.ts +++ b/packages/eslint-plugin/src/rules/class-name-casing.ts @@ -1,4 +1,7 @@ -import { TSESTree, AST_NODE_TYPES } from '@typescript-eslint/util'; +import { + TSESTree, + AST_NODE_TYPES, +} from '@typescript-eslint/experimental-utils'; import * as util from '../util'; export default util.createRule({ diff --git a/packages/eslint-plugin/src/rules/explicit-function-return-type.ts b/packages/eslint-plugin/src/rules/explicit-function-return-type.ts index 8510f288524c..b83a2b19a69e 100644 --- a/packages/eslint-plugin/src/rules/explicit-function-return-type.ts +++ b/packages/eslint-plugin/src/rules/explicit-function-return-type.ts @@ -1,4 +1,7 @@ -import { TSESTree, AST_NODE_TYPES } from '@typescript-eslint/util'; +import { + TSESTree, + AST_NODE_TYPES, +} from '@typescript-eslint/experimental-utils'; import * as util from '../util'; type Options = [ diff --git a/packages/eslint-plugin/src/rules/explicit-member-accessibility.ts b/packages/eslint-plugin/src/rules/explicit-member-accessibility.ts index d09e647a6e28..d760f18ea94b 100644 --- a/packages/eslint-plugin/src/rules/explicit-member-accessibility.ts +++ b/packages/eslint-plugin/src/rules/explicit-member-accessibility.ts @@ -1,4 +1,7 @@ -import { AST_NODE_TYPES, TSESTree } from '@typescript-eslint/util'; +import { + AST_NODE_TYPES, + TSESTree, +} from '@typescript-eslint/experimental-utils'; import * as util from '../util'; type AccessibilityLevel = diff --git a/packages/eslint-plugin/src/rules/func-call-spacing.ts b/packages/eslint-plugin/src/rules/func-call-spacing.ts index f676cd00370b..fd3958874807 100644 --- a/packages/eslint-plugin/src/rules/func-call-spacing.ts +++ b/packages/eslint-plugin/src/rules/func-call-spacing.ts @@ -1,4 +1,4 @@ -import { TSESTree } from '@typescript-eslint/util'; +import { TSESTree } from '@typescript-eslint/experimental-utils'; import { isOpeningParenToken } from 'eslint-utils'; import * as util from '../util'; diff --git a/packages/eslint-plugin/src/rules/indent.ts b/packages/eslint-plugin/src/rules/indent.ts index ebc154769dee..6a7a5c31e139 100644 --- a/packages/eslint-plugin/src/rules/indent.ts +++ b/packages/eslint-plugin/src/rules/indent.ts @@ -4,7 +4,10 @@ * This is done intentionally based on the internal implementation of the base indent rule. */ -import { TSESTree, AST_NODE_TYPES } from '@typescript-eslint/util'; +import { + TSESTree, + AST_NODE_TYPES, +} from '@typescript-eslint/experimental-utils'; import baseRule from 'eslint/lib/rules/indent'; import * as util from '../util'; diff --git a/packages/eslint-plugin/src/rules/member-delimiter-style.ts b/packages/eslint-plugin/src/rules/member-delimiter-style.ts index 1e455d11a6b2..326a0d961e52 100644 --- a/packages/eslint-plugin/src/rules/member-delimiter-style.ts +++ b/packages/eslint-plugin/src/rules/member-delimiter-style.ts @@ -1,4 +1,7 @@ -import { TSESTree, AST_NODE_TYPES } from '@typescript-eslint/util'; +import { + TSESTree, + AST_NODE_TYPES, +} from '@typescript-eslint/experimental-utils'; import * as util from '../util'; type Delimiter = 'comma' | 'none' | 'semi'; diff --git a/packages/eslint-plugin/src/rules/member-naming.ts b/packages/eslint-plugin/src/rules/member-naming.ts index 7c0639e7224f..35effc3d0c74 100644 --- a/packages/eslint-plugin/src/rules/member-naming.ts +++ b/packages/eslint-plugin/src/rules/member-naming.ts @@ -1,4 +1,4 @@ -import { TSESTree } from '@typescript-eslint/util'; +import { TSESTree } from '@typescript-eslint/experimental-utils'; import * as util from '../util'; interface Config { diff --git a/packages/eslint-plugin/src/rules/member-ordering.ts b/packages/eslint-plugin/src/rules/member-ordering.ts index 88a11a6aa695..ffcc6985073a 100644 --- a/packages/eslint-plugin/src/rules/member-ordering.ts +++ b/packages/eslint-plugin/src/rules/member-ordering.ts @@ -1,4 +1,7 @@ -import { TSESTree, AST_NODE_TYPES } from '@typescript-eslint/util'; +import { + TSESTree, + AST_NODE_TYPES, +} from '@typescript-eslint/experimental-utils'; import * as util from '../util'; type MessageIds = 'incorrectOrder'; diff --git a/packages/eslint-plugin/src/rules/no-array-constructor.ts b/packages/eslint-plugin/src/rules/no-array-constructor.ts index 0911ffeed096..5de11364ab81 100644 --- a/packages/eslint-plugin/src/rules/no-array-constructor.ts +++ b/packages/eslint-plugin/src/rules/no-array-constructor.ts @@ -1,4 +1,7 @@ -import { TSESTree, AST_NODE_TYPES } from '@typescript-eslint/util'; +import { + TSESTree, + AST_NODE_TYPES, +} from '@typescript-eslint/experimental-utils'; import * as util from '../util'; export default util.createRule({ diff --git a/packages/eslint-plugin/src/rules/no-extra-parens.ts b/packages/eslint-plugin/src/rules/no-extra-parens.ts index de0c4ef627f6..c1fee748708a 100644 --- a/packages/eslint-plugin/src/rules/no-extra-parens.ts +++ b/packages/eslint-plugin/src/rules/no-extra-parens.ts @@ -1,4 +1,7 @@ -import { TSESTree, AST_NODE_TYPES } from '@typescript-eslint/util'; +import { + TSESTree, + AST_NODE_TYPES, +} from '@typescript-eslint/experimental-utils'; import baseRule from 'eslint/lib/rules/no-extra-parens'; import * as util from '../util'; diff --git a/packages/eslint-plugin/src/rules/no-extraneous-class.ts b/packages/eslint-plugin/src/rules/no-extraneous-class.ts index e4f66813d0ce..3ce57c29999f 100644 --- a/packages/eslint-plugin/src/rules/no-extraneous-class.ts +++ b/packages/eslint-plugin/src/rules/no-extraneous-class.ts @@ -1,4 +1,7 @@ -import { TSESTree, AST_NODE_TYPES } from '@typescript-eslint/util'; +import { + TSESTree, + AST_NODE_TYPES, +} from '@typescript-eslint/experimental-utils'; import * as util from '../util'; type Options = [ diff --git a/packages/eslint-plugin/src/rules/no-inferrable-types.ts b/packages/eslint-plugin/src/rules/no-inferrable-types.ts index 9c2bb6b02183..27a08dc2dbe9 100644 --- a/packages/eslint-plugin/src/rules/no-inferrable-types.ts +++ b/packages/eslint-plugin/src/rules/no-inferrable-types.ts @@ -1,4 +1,7 @@ -import { TSESTree, AST_NODE_TYPES } from '@typescript-eslint/util'; +import { + TSESTree, + AST_NODE_TYPES, +} from '@typescript-eslint/experimental-utils'; import * as util from '../util'; type Options = [ diff --git a/packages/eslint-plugin/src/rules/no-magic-numbers.ts b/packages/eslint-plugin/src/rules/no-magic-numbers.ts index 8e50c068da78..49689213992d 100644 --- a/packages/eslint-plugin/src/rules/no-magic-numbers.ts +++ b/packages/eslint-plugin/src/rules/no-magic-numbers.ts @@ -3,7 +3,10 @@ * @author Scott O'Hara */ -import { TSESTree, AST_NODE_TYPES } from '@typescript-eslint/util'; +import { + TSESTree, + AST_NODE_TYPES, +} from '@typescript-eslint/experimental-utils'; import baseRule from 'eslint/lib/rules/no-magic-numbers'; import * as util from '../util'; import { JSONSchema4 } from 'json-schema'; diff --git a/packages/eslint-plugin/src/rules/no-misused-new.ts b/packages/eslint-plugin/src/rules/no-misused-new.ts index f0f4d4ee1ad6..56c5eb5f2964 100644 --- a/packages/eslint-plugin/src/rules/no-misused-new.ts +++ b/packages/eslint-plugin/src/rules/no-misused-new.ts @@ -1,4 +1,7 @@ -import { TSESTree, AST_NODE_TYPES } from '@typescript-eslint/util'; +import { + TSESTree, + AST_NODE_TYPES, +} from '@typescript-eslint/experimental-utils'; import * as util from '../util'; export default util.createRule({ diff --git a/packages/eslint-plugin/src/rules/no-namespace.ts b/packages/eslint-plugin/src/rules/no-namespace.ts index 0ceb22c12e7d..2ab66102dd46 100644 --- a/packages/eslint-plugin/src/rules/no-namespace.ts +++ b/packages/eslint-plugin/src/rules/no-namespace.ts @@ -1,4 +1,7 @@ -import { AST_NODE_TYPES, TSESTree } from '@typescript-eslint/util'; +import { + AST_NODE_TYPES, + TSESTree, +} from '@typescript-eslint/experimental-utils'; import * as util from '../util'; type Options = [ diff --git a/packages/eslint-plugin/src/rules/no-object-literal-type-assertion.ts b/packages/eslint-plugin/src/rules/no-object-literal-type-assertion.ts index d7689431ec75..d946c8792572 100644 --- a/packages/eslint-plugin/src/rules/no-object-literal-type-assertion.ts +++ b/packages/eslint-plugin/src/rules/no-object-literal-type-assertion.ts @@ -1,4 +1,7 @@ -import { AST_NODE_TYPES, TSESTree } from '@typescript-eslint/util'; +import { + AST_NODE_TYPES, + TSESTree, +} from '@typescript-eslint/experimental-utils'; import * as util from '../util'; type Options = [ diff --git a/packages/eslint-plugin/src/rules/no-parameter-properties.ts b/packages/eslint-plugin/src/rules/no-parameter-properties.ts index a0e6e5a3960f..6d1ffa80870f 100644 --- a/packages/eslint-plugin/src/rules/no-parameter-properties.ts +++ b/packages/eslint-plugin/src/rules/no-parameter-properties.ts @@ -1,4 +1,7 @@ -import { TSESTree, AST_NODE_TYPES } from '@typescript-eslint/util'; +import { + TSESTree, + AST_NODE_TYPES, +} from '@typescript-eslint/experimental-utils'; import * as util from '../util'; type Modifier = diff --git a/packages/eslint-plugin/src/rules/no-require-imports.ts b/packages/eslint-plugin/src/rules/no-require-imports.ts index 6b07535edae1..69b4887c925f 100644 --- a/packages/eslint-plugin/src/rules/no-require-imports.ts +++ b/packages/eslint-plugin/src/rules/no-require-imports.ts @@ -1,4 +1,4 @@ -import { TSESTree } from '@typescript-eslint/util'; +import { TSESTree } from '@typescript-eslint/experimental-utils'; import * as util from '../util'; export default util.createRule({ diff --git a/packages/eslint-plugin/src/rules/no-this-alias.ts b/packages/eslint-plugin/src/rules/no-this-alias.ts index 4abaacf31ae3..30201acf6a02 100644 --- a/packages/eslint-plugin/src/rules/no-this-alias.ts +++ b/packages/eslint-plugin/src/rules/no-this-alias.ts @@ -1,4 +1,7 @@ -import { AST_NODE_TYPES, TSESTree } from '@typescript-eslint/util'; +import { + AST_NODE_TYPES, + TSESTree, +} from '@typescript-eslint/experimental-utils'; import * as util from '../util'; type Options = [ diff --git a/packages/eslint-plugin/src/rules/no-type-alias.ts b/packages/eslint-plugin/src/rules/no-type-alias.ts index 73a03086b9c7..b4a4274c274a 100644 --- a/packages/eslint-plugin/src/rules/no-type-alias.ts +++ b/packages/eslint-plugin/src/rules/no-type-alias.ts @@ -1,4 +1,8 @@ -import { AST_NODE_TYPES, TSESLint, TSESTree } from '@typescript-eslint/util'; +import { + AST_NODE_TYPES, + TSESLint, + TSESTree, +} from '@typescript-eslint/experimental-utils'; import * as util from '../util'; type Options = [ diff --git a/packages/eslint-plugin/src/rules/no-unnecessary-qualifier.ts b/packages/eslint-plugin/src/rules/no-unnecessary-qualifier.ts index 939a30358110..f382e7262e08 100644 --- a/packages/eslint-plugin/src/rules/no-unnecessary-qualifier.ts +++ b/packages/eslint-plugin/src/rules/no-unnecessary-qualifier.ts @@ -1,4 +1,4 @@ -import { TSESTree } from '@typescript-eslint/util'; +import { TSESTree } from '@typescript-eslint/experimental-utils'; import ts from 'typescript'; import * as tsutils from 'tsutils'; import * as util from '../util'; diff --git a/packages/eslint-plugin/src/rules/no-unnecessary-type-assertion.ts b/packages/eslint-plugin/src/rules/no-unnecessary-type-assertion.ts index 231ffe9ffcb7..4371156c965c 100644 --- a/packages/eslint-plugin/src/rules/no-unnecessary-type-assertion.ts +++ b/packages/eslint-plugin/src/rules/no-unnecessary-type-assertion.ts @@ -1,4 +1,4 @@ -import { TSESTree } from '@typescript-eslint/util'; +import { TSESTree } from '@typescript-eslint/experimental-utils'; import * as tsutils from 'tsutils'; import ts from 'typescript'; import * as util from '../util'; diff --git a/packages/eslint-plugin/src/rules/no-unused-vars.ts b/packages/eslint-plugin/src/rules/no-unused-vars.ts index 41f08b15d1bf..9fc32f6fc1c5 100644 --- a/packages/eslint-plugin/src/rules/no-unused-vars.ts +++ b/packages/eslint-plugin/src/rules/no-unused-vars.ts @@ -1,4 +1,7 @@ -import { AST_NODE_TYPES, TSESTree } from '@typescript-eslint/util'; +import { + AST_NODE_TYPES, + TSESTree, +} from '@typescript-eslint/experimental-utils'; import baseRule from 'eslint/lib/rules/no-unused-vars'; import * as util from '../util'; diff --git a/packages/eslint-plugin/src/rules/no-use-before-define.ts b/packages/eslint-plugin/src/rules/no-use-before-define.ts index 5f6d892c5f87..c18e8e0cc11a 100644 --- a/packages/eslint-plugin/src/rules/no-use-before-define.ts +++ b/packages/eslint-plugin/src/rules/no-use-before-define.ts @@ -1,4 +1,8 @@ -import { AST_NODE_TYPES, TSESLint, TSESTree } from '@typescript-eslint/util'; +import { + AST_NODE_TYPES, + TSESLint, + TSESTree, +} from '@typescript-eslint/experimental-utils'; import * as util from '../util'; const SENTINEL_TYPE = /^(?:(?:Function|Class)(?:Declaration|Expression)|ArrowFunctionExpression|CatchClause|ImportDeclaration|ExportNamedDeclaration)$/; diff --git a/packages/eslint-plugin/src/rules/no-useless-constructor.ts b/packages/eslint-plugin/src/rules/no-useless-constructor.ts index f79e3e301614..e6b48a055ed1 100644 --- a/packages/eslint-plugin/src/rules/no-useless-constructor.ts +++ b/packages/eslint-plugin/src/rules/no-useless-constructor.ts @@ -1,4 +1,7 @@ -import { TSESTree, AST_NODE_TYPES } from '@typescript-eslint/util'; +import { + TSESTree, + AST_NODE_TYPES, +} from '@typescript-eslint/experimental-utils'; import baseRule from 'eslint/lib/rules/no-useless-constructor'; import * as util from '../util'; diff --git a/packages/eslint-plugin/src/rules/no-var-requires.ts b/packages/eslint-plugin/src/rules/no-var-requires.ts index 1453d3d4ed85..a8acccd8af95 100644 --- a/packages/eslint-plugin/src/rules/no-var-requires.ts +++ b/packages/eslint-plugin/src/rules/no-var-requires.ts @@ -1,4 +1,4 @@ -import { AST_NODE_TYPES } from '@typescript-eslint/util'; +import { AST_NODE_TYPES } from '@typescript-eslint/experimental-utils'; import * as util from '../util'; type Options = []; diff --git a/packages/eslint-plugin/src/rules/prefer-for-of.ts b/packages/eslint-plugin/src/rules/prefer-for-of.ts index 6a985f533ce1..8e829b48e9c7 100644 --- a/packages/eslint-plugin/src/rules/prefer-for-of.ts +++ b/packages/eslint-plugin/src/rules/prefer-for-of.ts @@ -1,4 +1,8 @@ -import { AST_NODE_TYPES, TSESLint, TSESTree } from '@typescript-eslint/util'; +import { + AST_NODE_TYPES, + TSESLint, + TSESTree, +} from '@typescript-eslint/experimental-utils'; import * as util from '../util'; export default util.createRule({ diff --git a/packages/eslint-plugin/src/rules/prefer-function-type.ts b/packages/eslint-plugin/src/rules/prefer-function-type.ts index 11261397485e..95f1a8ee3cab 100644 --- a/packages/eslint-plugin/src/rules/prefer-function-type.ts +++ b/packages/eslint-plugin/src/rules/prefer-function-type.ts @@ -2,7 +2,7 @@ import { AST_NODE_TYPES, AST_TOKEN_TYPES, TSESTree, -} from '@typescript-eslint/util'; +} from '@typescript-eslint/experimental-utils'; import * as util from '../util'; export default util.createRule({ diff --git a/packages/eslint-plugin/src/rules/prefer-includes.ts b/packages/eslint-plugin/src/rules/prefer-includes.ts index 06cfa2e95b01..2db17e11d1dd 100644 --- a/packages/eslint-plugin/src/rules/prefer-includes.ts +++ b/packages/eslint-plugin/src/rules/prefer-includes.ts @@ -1,4 +1,4 @@ -import { TSESTree } from '@typescript-eslint/util'; +import { TSESTree } from '@typescript-eslint/experimental-utils'; import { getStaticValue } from 'eslint-utils'; import { AST as RegExpAST, parseRegExpLiteral } from 'regexpp'; import ts from 'typescript'; diff --git a/packages/eslint-plugin/src/rules/prefer-interface.ts b/packages/eslint-plugin/src/rules/prefer-interface.ts index d7391b674bd6..6efbf62d6a65 100644 --- a/packages/eslint-plugin/src/rules/prefer-interface.ts +++ b/packages/eslint-plugin/src/rules/prefer-interface.ts @@ -1,4 +1,4 @@ -import { TSESLint, TSESTree } from '@typescript-eslint/util'; +import { TSESLint, TSESTree } from '@typescript-eslint/experimental-utils'; import * as util from '../util'; export default util.createRule({ diff --git a/packages/eslint-plugin/src/rules/prefer-namespace-keyword.ts b/packages/eslint-plugin/src/rules/prefer-namespace-keyword.ts index a3552b8ca57e..9d60e0eed4fc 100644 --- a/packages/eslint-plugin/src/rules/prefer-namespace-keyword.ts +++ b/packages/eslint-plugin/src/rules/prefer-namespace-keyword.ts @@ -1,4 +1,7 @@ -import { AST_NODE_TYPES, AST_TOKEN_TYPES } from '@typescript-eslint/util'; +import { + AST_NODE_TYPES, + AST_TOKEN_TYPES, +} from '@typescript-eslint/experimental-utils'; import * as util from '../util'; export default util.createRule({ diff --git a/packages/eslint-plugin/src/rules/prefer-string-starts-ends-with.ts b/packages/eslint-plugin/src/rules/prefer-string-starts-ends-with.ts index c8937802996b..565a4cb83db2 100644 --- a/packages/eslint-plugin/src/rules/prefer-string-starts-ends-with.ts +++ b/packages/eslint-plugin/src/rules/prefer-string-starts-ends-with.ts @@ -1,4 +1,4 @@ -import { TSESLint, TSESTree } from '@typescript-eslint/util'; +import { TSESLint, TSESTree } from '@typescript-eslint/experimental-utils'; import { isNotClosingParenToken, getPropertyName, diff --git a/packages/eslint-plugin/src/rules/promise-function-async.ts b/packages/eslint-plugin/src/rules/promise-function-async.ts index b06f331bbda2..0eb96e991437 100644 --- a/packages/eslint-plugin/src/rules/promise-function-async.ts +++ b/packages/eslint-plugin/src/rules/promise-function-async.ts @@ -1,4 +1,4 @@ -import { TSESTree } from '@typescript-eslint/util'; +import { TSESTree } from '@typescript-eslint/experimental-utils'; import * as util from '../util'; type Options = [ diff --git a/packages/eslint-plugin/src/rules/require-array-sort-compare.ts b/packages/eslint-plugin/src/rules/require-array-sort-compare.ts index 63ab9806c790..a9745be16e02 100644 --- a/packages/eslint-plugin/src/rules/require-array-sort-compare.ts +++ b/packages/eslint-plugin/src/rules/require-array-sort-compare.ts @@ -1,4 +1,4 @@ -import { TSESTree } from '@typescript-eslint/util'; +import { TSESTree } from '@typescript-eslint/experimental-utils'; import ts from 'typescript'; import * as util from '../util'; diff --git a/packages/eslint-plugin/src/rules/restrict-plus-operands.ts b/packages/eslint-plugin/src/rules/restrict-plus-operands.ts index ec5501370783..9a3a42c8f32a 100644 --- a/packages/eslint-plugin/src/rules/restrict-plus-operands.ts +++ b/packages/eslint-plugin/src/rules/restrict-plus-operands.ts @@ -1,4 +1,4 @@ -import { TSESTree } from '@typescript-eslint/util'; +import { TSESTree } from '@typescript-eslint/experimental-utils'; import ts from 'typescript'; import * as util from '../util'; diff --git a/packages/eslint-plugin/src/rules/semi.ts b/packages/eslint-plugin/src/rules/semi.ts index 93c73692f20c..6e40651dd2e8 100644 --- a/packages/eslint-plugin/src/rules/semi.ts +++ b/packages/eslint-plugin/src/rules/semi.ts @@ -1,4 +1,8 @@ -import { TSESTree, TSESLint, AST_NODE_TYPES } from '@typescript-eslint/util'; +import { + TSESTree, + TSESLint, + AST_NODE_TYPES, +} from '@typescript-eslint/experimental-utils'; import baseRule from 'eslint/lib/rules/semi'; import * as util from '../util'; diff --git a/packages/eslint-plugin/src/rules/type-annotation-spacing.ts b/packages/eslint-plugin/src/rules/type-annotation-spacing.ts index 4147c255499d..19ef206119f6 100644 --- a/packages/eslint-plugin/src/rules/type-annotation-spacing.ts +++ b/packages/eslint-plugin/src/rules/type-annotation-spacing.ts @@ -1,4 +1,4 @@ -import { TSESTree } from '@typescript-eslint/util'; +import { TSESTree } from '@typescript-eslint/experimental-utils'; import * as util from '../util'; type Options = [ diff --git a/packages/eslint-plugin/src/rules/unbound-method.ts b/packages/eslint-plugin/src/rules/unbound-method.ts index 1ff93883fb76..5c1305b6acb4 100644 --- a/packages/eslint-plugin/src/rules/unbound-method.ts +++ b/packages/eslint-plugin/src/rules/unbound-method.ts @@ -1,4 +1,7 @@ -import { AST_NODE_TYPES, TSESTree } from '@typescript-eslint/util'; +import { + AST_NODE_TYPES, + TSESTree, +} from '@typescript-eslint/experimental-utils'; import * as tsutils from 'tsutils'; import ts from 'typescript'; import * as util from '../util'; diff --git a/packages/eslint-plugin/src/rules/unified-signatures.ts b/packages/eslint-plugin/src/rules/unified-signatures.ts index 8bfd3112ba7f..d4ea472be5e1 100644 --- a/packages/eslint-plugin/src/rules/unified-signatures.ts +++ b/packages/eslint-plugin/src/rules/unified-signatures.ts @@ -1,4 +1,7 @@ -import { AST_NODE_TYPES, TSESTree } from '@typescript-eslint/util'; +import { + AST_NODE_TYPES, + TSESTree, +} from '@typescript-eslint/experimental-utils'; import * as util from '../util'; interface Failure { diff --git a/packages/eslint-plugin/src/util/createRule.ts b/packages/eslint-plugin/src/util/createRule.ts index 6a937135dfcc..5982f04c3d5c 100644 --- a/packages/eslint-plugin/src/util/createRule.ts +++ b/packages/eslint-plugin/src/util/createRule.ts @@ -1,4 +1,4 @@ -import { ESLintUtils } from '@typescript-eslint/util'; +import { ESLintUtils } from '@typescript-eslint/experimental-utils'; // note - cannot migrate this to an import statement because it will make TSC copy the package.json to the dist folder const version = require('../../package.json').version; diff --git a/packages/eslint-plugin/src/util/getParserServices.ts b/packages/eslint-plugin/src/util/getParserServices.ts index e1a1358c9d66..2cc8b4981596 100644 --- a/packages/eslint-plugin/src/util/getParserServices.ts +++ b/packages/eslint-plugin/src/util/getParserServices.ts @@ -1,5 +1,5 @@ import { ParserServices } from '@typescript-eslint/parser'; -import { TSESLint } from '@typescript-eslint/util'; +import { TSESLint } from '@typescript-eslint/experimental-utils'; type RequiredParserServices = { [k in keyof ParserServices]: Exclude diff --git a/packages/eslint-plugin/src/util/index.ts b/packages/eslint-plugin/src/util/index.ts index c13b8400d9e4..b1aae71b3571 100644 --- a/packages/eslint-plugin/src/util/index.ts +++ b/packages/eslint-plugin/src/util/index.ts @@ -1,4 +1,4 @@ -import { ESLintUtils } from '@typescript-eslint/util'; +import { ESLintUtils } from '@typescript-eslint/experimental-utils'; export * from './astUtils'; export * from './createRule'; diff --git a/packages/eslint-plugin/src/util/misc.ts b/packages/eslint-plugin/src/util/misc.ts index 7bc89cdda451..0e80a716b3c8 100644 --- a/packages/eslint-plugin/src/util/misc.ts +++ b/packages/eslint-plugin/src/util/misc.ts @@ -2,7 +2,11 @@ * @fileoverview Really small utility functions that didn't deserve their own files */ -import { AST_NODE_TYPES, TSESLint, TSESTree } from '@typescript-eslint/util'; +import { + AST_NODE_TYPES, + TSESLint, + TSESTree, +} from '@typescript-eslint/experimental-utils'; /** * Check if the context file name is *.ts or *.tsx diff --git a/packages/eslint-plugin/tests/RuleTester.ts b/packages/eslint-plugin/tests/RuleTester.ts index 5f049bf7258e..73e1e0e539a0 100644 --- a/packages/eslint-plugin/tests/RuleTester.ts +++ b/packages/eslint-plugin/tests/RuleTester.ts @@ -1,4 +1,4 @@ -import { TSESLint } from '@typescript-eslint/util'; +import { TSESLint } from '@typescript-eslint/experimental-utils'; import { RuleTester as ESLintRuleTester } from 'eslint'; import * as path from 'path'; diff --git a/packages/eslint-plugin/tests/eslint-rules/no-redeclare.test.ts b/packages/eslint-plugin/tests/eslint-rules/no-redeclare.test.ts index ad1d6e0a4585..1a1fb94a462d 100644 --- a/packages/eslint-plugin/tests/eslint-rules/no-redeclare.test.ts +++ b/packages/eslint-plugin/tests/eslint-rules/no-redeclare.test.ts @@ -1,5 +1,5 @@ import rule from 'eslint/lib/rules/no-redeclare'; -import { AST_NODE_TYPES } from '@typescript-eslint/util'; +import { AST_NODE_TYPES } from '@typescript-eslint/experimental-utils'; import { RuleTester } from '../RuleTester'; const ruleTester = new RuleTester({ diff --git a/packages/eslint-plugin/tests/rules/func-call-spacing.test.ts b/packages/eslint-plugin/tests/rules/func-call-spacing.test.ts index 56b22fe48c9c..d0b8afe9b194 100644 --- a/packages/eslint-plugin/tests/rules/func-call-spacing.test.ts +++ b/packages/eslint-plugin/tests/rules/func-call-spacing.test.ts @@ -1,4 +1,4 @@ -import { TSESLint } from '@typescript-eslint/util'; +import { TSESLint } from '@typescript-eslint/experimental-utils'; import rule, { MessageIds, Options } from '../../src/rules/func-call-spacing'; import { RuleTester } from '../RuleTester'; diff --git a/packages/eslint-plugin/tests/rules/indent.test.ts b/packages/eslint-plugin/tests/rules/indent.test.ts index 4c47e85ce133..3326de2e7802 100644 --- a/packages/eslint-plugin/tests/rules/indent.test.ts +++ b/packages/eslint-plugin/tests/rules/indent.test.ts @@ -1,4 +1,4 @@ -import { TSESLint } from '@typescript-eslint/util'; +import { TSESLint } from '@typescript-eslint/experimental-utils'; import { RuleTester } from '../RuleTester'; import rule from '../../src/rules/indent'; import { diff --git a/packages/eslint-plugin/tests/rules/no-array-constructor.test.ts b/packages/eslint-plugin/tests/rules/no-array-constructor.test.ts index 125ffd9311f9..6b8570bb4a45 100644 --- a/packages/eslint-plugin/tests/rules/no-array-constructor.test.ts +++ b/packages/eslint-plugin/tests/rules/no-array-constructor.test.ts @@ -1,4 +1,4 @@ -import { AST_NODE_TYPES } from '@typescript-eslint/util'; +import { AST_NODE_TYPES } from '@typescript-eslint/experimental-utils'; import rule from '../../src/rules/no-array-constructor'; import { RuleTester } from '../RuleTester'; diff --git a/packages/eslint-plugin/tests/rules/no-extraneous-class.test.ts b/packages/eslint-plugin/tests/rules/no-extraneous-class.test.ts index 2a73f2ede881..1d2742ed0402 100644 --- a/packages/eslint-plugin/tests/rules/no-extraneous-class.test.ts +++ b/packages/eslint-plugin/tests/rules/no-extraneous-class.test.ts @@ -1,4 +1,4 @@ -import { AST_NODE_TYPES } from '@typescript-eslint/util'; +import { AST_NODE_TYPES } from '@typescript-eslint/experimental-utils'; import rule from '../../src/rules/no-extraneous-class'; import { RuleTester } from '../RuleTester'; diff --git a/packages/eslint-plugin/tests/rules/no-for-in-array.test.ts b/packages/eslint-plugin/tests/rules/no-for-in-array.test.ts index b2f6c9ba21dc..44a40942c9fa 100644 --- a/packages/eslint-plugin/tests/rules/no-for-in-array.test.ts +++ b/packages/eslint-plugin/tests/rules/no-for-in-array.test.ts @@ -1,4 +1,4 @@ -import { AST_NODE_TYPES } from '@typescript-eslint/util'; +import { AST_NODE_TYPES } from '@typescript-eslint/experimental-utils'; import rule from '../../src/rules/no-for-in-array'; import { RuleTester, getFixturesRootDir } from '../RuleTester'; diff --git a/packages/eslint-plugin/tests/rules/no-this-alias.test.ts b/packages/eslint-plugin/tests/rules/no-this-alias.test.ts index 466b643acd8e..c1ddce12186f 100644 --- a/packages/eslint-plugin/tests/rules/no-this-alias.test.ts +++ b/packages/eslint-plugin/tests/rules/no-this-alias.test.ts @@ -1,4 +1,4 @@ -import { AST_NODE_TYPES } from '@typescript-eslint/util'; +import { AST_NODE_TYPES } from '@typescript-eslint/experimental-utils'; import rule from '../../src/rules/no-this-alias'; import { RuleTester } from '../RuleTester'; diff --git a/packages/eslint-plugin/tests/rules/no-unnecessary-qualifier.test.ts b/packages/eslint-plugin/tests/rules/no-unnecessary-qualifier.test.ts index 7ff9c5f8fe87..53a349e552ee 100644 --- a/packages/eslint-plugin/tests/rules/no-unnecessary-qualifier.test.ts +++ b/packages/eslint-plugin/tests/rules/no-unnecessary-qualifier.test.ts @@ -1,7 +1,7 @@ import path from 'path'; import rule from '../../src/rules/no-unnecessary-qualifier'; import { RuleTester } from '../RuleTester'; -import { AST_NODE_TYPES } from '@typescript-eslint/util'; +import { AST_NODE_TYPES } from '@typescript-eslint/experimental-utils'; const messageId = 'unnecessaryQualifier'; const rootPath = path.join(process.cwd(), 'tests/fixtures/'); diff --git a/packages/eslint-plugin/tests/rules/no-use-before-define.test.ts b/packages/eslint-plugin/tests/rules/no-use-before-define.test.ts index 00b82dc216f7..7a0324308b2c 100644 --- a/packages/eslint-plugin/tests/rules/no-use-before-define.test.ts +++ b/packages/eslint-plugin/tests/rules/no-use-before-define.test.ts @@ -1,6 +1,6 @@ import rule from '../../src/rules/no-use-before-define'; import { RuleTester } from '../RuleTester'; -import { AST_NODE_TYPES } from '@typescript-eslint/util'; +import { AST_NODE_TYPES } from '@typescript-eslint/experimental-utils'; const ruleTester = new RuleTester({ parser: '@typescript-eslint/parser', diff --git a/packages/eslint-plugin/tests/rules/prefer-function-type.test.ts b/packages/eslint-plugin/tests/rules/prefer-function-type.test.ts index 610e3a70b64e..a472d8619fe3 100644 --- a/packages/eslint-plugin/tests/rules/prefer-function-type.test.ts +++ b/packages/eslint-plugin/tests/rules/prefer-function-type.test.ts @@ -1,4 +1,4 @@ -import { AST_NODE_TYPES } from '@typescript-eslint/util'; +import { AST_NODE_TYPES } from '@typescript-eslint/experimental-utils'; import rule from '../../src/rules/prefer-function-type'; import { RuleTester } from '../RuleTester'; diff --git a/packages/eslint-plugin/tests/rules/semi.test.ts b/packages/eslint-plugin/tests/rules/semi.test.ts index 71d673e5d021..83bc750a2353 100644 --- a/packages/eslint-plugin/tests/rules/semi.test.ts +++ b/packages/eslint-plugin/tests/rules/semi.test.ts @@ -1,4 +1,4 @@ -import { TSESLint } from '@typescript-eslint/util'; +import { TSESLint } from '@typescript-eslint/experimental-utils'; import rule, { MessageIds, Options } from '../../src/rules/semi'; import { RuleTester } from '../RuleTester'; diff --git a/packages/eslint-plugin/tests/rules/type-annotation-spacing.test.ts b/packages/eslint-plugin/tests/rules/type-annotation-spacing.test.ts index 52aeee549560..6559c9b71408 100644 --- a/packages/eslint-plugin/tests/rules/type-annotation-spacing.test.ts +++ b/packages/eslint-plugin/tests/rules/type-annotation-spacing.test.ts @@ -1,4 +1,4 @@ -import { TSESLint } from '@typescript-eslint/util'; +import { TSESLint } from '@typescript-eslint/experimental-utils'; import { RuleTester } from '../RuleTester'; import rule from '../../src/rules/type-annotation-spacing'; import { diff --git a/packages/eslint-plugin/typings/eslint-rules.d.ts b/packages/eslint-plugin/typings/eslint-rules.d.ts index e7500e88dbbb..16857732b0ea 100644 --- a/packages/eslint-plugin/typings/eslint-rules.d.ts +++ b/packages/eslint-plugin/typings/eslint-rules.d.ts @@ -5,7 +5,7 @@ // } declare module 'eslint/lib/rules/arrow-parens' { - import { TSESLint, TSESTree } from '@typescript-eslint/util'; + import { TSESLint, TSESTree } from '@typescript-eslint/experimental-utils'; const rule: TSESLint.RuleModule< | 'unexpectedParens' @@ -26,7 +26,7 @@ declare module 'eslint/lib/rules/arrow-parens' { } declare module 'eslint/lib/rules/camelcase' { - import { TSESLint, TSESTree } from '@typescript-eslint/util'; + import { TSESLint, TSESTree } from '@typescript-eslint/experimental-utils'; const rule: TSESLint.RuleModule< 'notCamelCase', @@ -45,7 +45,7 @@ declare module 'eslint/lib/rules/camelcase' { } declare module 'eslint/lib/rules/indent' { - import { TSESLint, TSESTree } from '@typescript-eslint/util'; + import { TSESLint, TSESTree } from '@typescript-eslint/experimental-utils'; type Listener = (node: TSESTree.Node) => void; type ElementList = number | 'first' | 'off'; @@ -142,7 +142,7 @@ declare module 'eslint/lib/rules/indent' { } declare module 'eslint/lib/rules/no-dupe-args' { - import { TSESLint, TSESTree } from '@typescript-eslint/util'; + import { TSESLint, TSESTree } from '@typescript-eslint/experimental-utils'; const rule: TSESLint.RuleModule< 'unexpected', @@ -156,7 +156,7 @@ declare module 'eslint/lib/rules/no-dupe-args' { } declare module 'eslint/lib/rules/no-implicit-globals' { - import { TSESLint, TSESTree } from '@typescript-eslint/util'; + import { TSESLint, TSESTree } from '@typescript-eslint/experimental-utils'; const rule: TSESLint.RuleModule< never, @@ -169,7 +169,7 @@ declare module 'eslint/lib/rules/no-implicit-globals' { } declare module 'eslint/lib/rules/no-magic-numbers' { - import { TSESLint, TSESTree } from '@typescript-eslint/util'; + import { TSESLint, TSESTree } from '@typescript-eslint/experimental-utils'; const rule: TSESLint.RuleModule< 'noMagic', @@ -190,7 +190,7 @@ declare module 'eslint/lib/rules/no-magic-numbers' { } declare module 'eslint/lib/rules/no-redeclare' { - import { TSESLint, TSESTree } from '@typescript-eslint/util'; + import { TSESLint, TSESTree } from '@typescript-eslint/experimental-utils'; const rule: TSESLint.RuleModule< never, @@ -207,7 +207,7 @@ declare module 'eslint/lib/rules/no-redeclare' { } declare module 'eslint/lib/rules/no-restricted-globals' { - import { TSESLint, TSESTree } from '@typescript-eslint/util'; + import { TSESLint, TSESTree } from '@typescript-eslint/experimental-utils'; const rule: TSESLint.RuleModule< never, @@ -225,7 +225,7 @@ declare module 'eslint/lib/rules/no-restricted-globals' { } declare module 'eslint/lib/rules/no-shadow' { - import { TSESLint, TSESTree } from '@typescript-eslint/util'; + import { TSESLint, TSESTree } from '@typescript-eslint/experimental-utils'; const rule: TSESLint.RuleModule< never, @@ -244,7 +244,7 @@ declare module 'eslint/lib/rules/no-shadow' { } declare module 'eslint/lib/rules/no-undef' { - import { TSESLint, TSESTree } from '@typescript-eslint/util'; + import { TSESLint, TSESTree } from '@typescript-eslint/experimental-utils'; const rule: TSESLint.RuleModule< 'undef', @@ -261,7 +261,7 @@ declare module 'eslint/lib/rules/no-undef' { } declare module 'eslint/lib/rules/no-unused-vars' { - import { TSESLint, TSESTree } from '@typescript-eslint/util'; + import { TSESLint, TSESTree } from '@typescript-eslint/experimental-utils'; const rule: TSESLint.RuleModule< never, @@ -285,7 +285,7 @@ declare module 'eslint/lib/rules/no-unused-vars' { } declare module 'eslint/lib/rules/no-use-before-define' { - import { TSESLint, TSESTree } from '@typescript-eslint/util'; + import { TSESLint, TSESTree } from '@typescript-eslint/experimental-utils'; const rule: TSESLint.RuleModule< never, @@ -304,7 +304,7 @@ declare module 'eslint/lib/rules/no-use-before-define' { } declare module 'eslint/lib/rules/strict' { - import { TSESLint, TSESTree } from '@typescript-eslint/util'; + import { TSESLint, TSESTree } from '@typescript-eslint/experimental-utils'; const rule: TSESLint.RuleModule< | 'function' @@ -326,7 +326,7 @@ declare module 'eslint/lib/rules/strict' { } declare module 'eslint/lib/rules/no-useless-constructor' { - import { TSESLint, TSESTree } from '@typescript-eslint/util'; + import { TSESLint, TSESTree } from '@typescript-eslint/experimental-utils'; const rule: TSESLint.RuleModule< never, @@ -339,7 +339,7 @@ declare module 'eslint/lib/rules/no-useless-constructor' { } declare module 'eslint/lib/rules/no-extra-parens' { - import { TSESLint, TSESTree } from '@typescript-eslint/util'; + import { TSESLint, TSESTree } from '@typescript-eslint/experimental-utils'; const rule: TSESLint.RuleModule< 'unexpected', @@ -361,7 +361,7 @@ declare module 'eslint/lib/rules/no-extra-parens' { } declare module 'eslint/lib/rules/semi' { - import { TSESLint, TSESTree } from '@typescript-eslint/util'; + import { TSESLint, TSESTree } from '@typescript-eslint/experimental-utils'; const rule: TSESLint.RuleModule< never, diff --git a/packages/eslint-plugin/typings/eslint-utils.d.ts b/packages/eslint-plugin/typings/eslint-utils.d.ts index 3e55e8f8f606..e7cefb09367f 100644 --- a/packages/eslint-plugin/typings/eslint-utils.d.ts +++ b/packages/eslint-plugin/typings/eslint-utils.d.ts @@ -1,5 +1,5 @@ declare module 'eslint-utils' { - import { TSESLint, TSESTree } from '@typescript-eslint/util'; + import { TSESLint, TSESTree } from '@typescript-eslint/experimental-utils'; export function getFunctionHeadLocation( node: diff --git a/packages/util/LICENSE b/packages/experimental-utils/LICENSE similarity index 100% rename from packages/util/LICENSE rename to packages/experimental-utils/LICENSE diff --git a/packages/util/README.md b/packages/experimental-utils/README.md similarity index 73% rename from packages/util/README.md rename to packages/experimental-utils/README.md index 030e824ae8e6..45ecc1a64f86 100644 --- a/packages/util/README.md +++ b/packages/experimental-utils/README.md @@ -1,8 +1,18 @@ -# @typescript-eslint/util +# @typescript-eslint/experimental-utils -Utilities for working with TypeScript + ESLint together +(Experimental) Utilities for working with TypeScript + ESLint together. -Exports: +## Note + +This package has inherited its version number from the @typescript-eslint project. +Meaning that even though this package is `1.x.y`, you shouldn't expect 100% stability between minor version bumps. +i.e. treat it as a `0.x.y` package. + +Feel free to use it now, and let us know what utilities you need or send us PRs with utilities you build on top of it. + +Once it is stable, it will be renamed to `@typescript-eslint/util` for a `2.0.0` release. + +## Exports | Name | Description | | --------------------------- | ---------------------------------------------------------------------------------------------- | @@ -14,8 +24,6 @@ Exports: | [`ESLintUtils.RuleCreator`] | A function for creating strictly typed eslint rules with TypeScript. | | [`ParserServices`] | The parser services provided when parsing a file using `@typescript-eslint/typescript-estree`. | -## ESLintUtils - [`AST_NODE_TYPES`](../packages/typescript-estree/src/ts-estree/ast-node-types.ts) [`AST_TOKEN_TYPES`](../packages/typescript-estree/src/ts-estree/ast-node-types.ts) [`ESLintUtils`](./src/eslint-utils) diff --git a/packages/util/jest.config.js b/packages/experimental-utils/jest.config.js similarity index 100% rename from packages/util/jest.config.js rename to packages/experimental-utils/jest.config.js diff --git a/packages/util/package.json b/packages/experimental-utils/package.json similarity index 84% rename from packages/util/package.json rename to packages/experimental-utils/package.json index 48c8a567612f..d1ab0c20078c 100644 --- a/packages/util/package.json +++ b/packages/experimental-utils/package.json @@ -1,7 +1,7 @@ { - "name": "@typescript-eslint/util", + "name": "@typescript-eslint/experimental-utils", "version": "1.7.0", - "description": "Utilities for working with TypeScript + ESLint together", + "description": "(Experimental) Utilities for working with TypeScript + ESLint together", "keywords": [ "eslint", "typescript", diff --git a/packages/util/src/eslint-utils/RuleCreator.ts b/packages/experimental-utils/src/eslint-utils/RuleCreator.ts similarity index 100% rename from packages/util/src/eslint-utils/RuleCreator.ts rename to packages/experimental-utils/src/eslint-utils/RuleCreator.ts diff --git a/packages/util/src/eslint-utils/applyDefault.ts b/packages/experimental-utils/src/eslint-utils/applyDefault.ts similarity index 100% rename from packages/util/src/eslint-utils/applyDefault.ts rename to packages/experimental-utils/src/eslint-utils/applyDefault.ts diff --git a/packages/util/src/eslint-utils/deepMerge.ts b/packages/experimental-utils/src/eslint-utils/deepMerge.ts similarity index 100% rename from packages/util/src/eslint-utils/deepMerge.ts rename to packages/experimental-utils/src/eslint-utils/deepMerge.ts diff --git a/packages/util/src/eslint-utils/index.ts b/packages/experimental-utils/src/eslint-utils/index.ts similarity index 100% rename from packages/util/src/eslint-utils/index.ts rename to packages/experimental-utils/src/eslint-utils/index.ts diff --git a/packages/util/src/index.ts b/packages/experimental-utils/src/index.ts similarity index 100% rename from packages/util/src/index.ts rename to packages/experimental-utils/src/index.ts diff --git a/packages/util/src/ts-eslint/AST.ts b/packages/experimental-utils/src/ts-eslint/AST.ts similarity index 100% rename from packages/util/src/ts-eslint/AST.ts rename to packages/experimental-utils/src/ts-eslint/AST.ts diff --git a/packages/util/src/ts-eslint/Linter.ts b/packages/experimental-utils/src/ts-eslint/Linter.ts similarity index 100% rename from packages/util/src/ts-eslint/Linter.ts rename to packages/experimental-utils/src/ts-eslint/Linter.ts diff --git a/packages/util/src/ts-eslint/ParserOptions.ts b/packages/experimental-utils/src/ts-eslint/ParserOptions.ts similarity index 100% rename from packages/util/src/ts-eslint/ParserOptions.ts rename to packages/experimental-utils/src/ts-eslint/ParserOptions.ts diff --git a/packages/util/src/ts-eslint/Rule.ts b/packages/experimental-utils/src/ts-eslint/Rule.ts similarity index 100% rename from packages/util/src/ts-eslint/Rule.ts rename to packages/experimental-utils/src/ts-eslint/Rule.ts diff --git a/packages/util/src/ts-eslint/RuleTester.ts b/packages/experimental-utils/src/ts-eslint/RuleTester.ts similarity index 100% rename from packages/util/src/ts-eslint/RuleTester.ts rename to packages/experimental-utils/src/ts-eslint/RuleTester.ts diff --git a/packages/util/src/ts-eslint/Scope.ts b/packages/experimental-utils/src/ts-eslint/Scope.ts similarity index 100% rename from packages/util/src/ts-eslint/Scope.ts rename to packages/experimental-utils/src/ts-eslint/Scope.ts diff --git a/packages/util/src/ts-eslint/SourceCode.ts b/packages/experimental-utils/src/ts-eslint/SourceCode.ts similarity index 100% rename from packages/util/src/ts-eslint/SourceCode.ts rename to packages/experimental-utils/src/ts-eslint/SourceCode.ts diff --git a/packages/util/src/ts-eslint/index.ts b/packages/experimental-utils/src/ts-eslint/index.ts similarity index 100% rename from packages/util/src/ts-eslint/index.ts rename to packages/experimental-utils/src/ts-eslint/index.ts diff --git a/packages/util/tests/eslint-utils/applyDefault.test.ts b/packages/experimental-utils/tests/eslint-utils/applyDefault.test.ts similarity index 100% rename from packages/util/tests/eslint-utils/applyDefault.test.ts rename to packages/experimental-utils/tests/eslint-utils/applyDefault.test.ts diff --git a/packages/util/tests/eslint-utils/deepMerge.test.ts b/packages/experimental-utils/tests/eslint-utils/deepMerge.test.ts similarity index 100% rename from packages/util/tests/eslint-utils/deepMerge.test.ts rename to packages/experimental-utils/tests/eslint-utils/deepMerge.test.ts diff --git a/packages/util/tsconfig.build.json b/packages/experimental-utils/tsconfig.build.json similarity index 100% rename from packages/util/tsconfig.build.json rename to packages/experimental-utils/tsconfig.build.json diff --git a/packages/util/tsconfig.json b/packages/experimental-utils/tsconfig.json similarity index 100% rename from packages/util/tsconfig.json rename to packages/experimental-utils/tsconfig.json diff --git a/packages/parser/package.json b/packages/parser/package.json index 0a3fbca0f190..98abcc4f0b01 100644 --- a/packages/parser/package.json +++ b/packages/parser/package.json @@ -37,7 +37,7 @@ }, "dependencies": { "@typescript-eslint/typescript-estree": "1.7.0", - "@typescript-eslint/util": "1.7.0", + "@typescript-eslint/experimental-utils": "1.7.0", "eslint-scope": "^4.0.0", "eslint-visitor-keys": "^1.0.0" }, diff --git a/packages/parser/src/parser.ts b/packages/parser/src/parser.ts index d0d563e2bf4b..71478ee2ad62 100644 --- a/packages/parser/src/parser.ts +++ b/packages/parser/src/parser.ts @@ -1,10 +1,10 @@ import { AST_NODE_TYPES, parseAndGenerateServices, - TSEStreeOptions, + TSESTreeOptions, ParserServices, } from '@typescript-eslint/typescript-estree'; -import { TSESLint } from '@typescript-eslint/util'; +import { TSESLint } from '@typescript-eslint/experimental-utils'; import traverser from 'eslint/lib/util/traverser'; import { analyzeScope } from './analyze-scope'; import { visitorKeys } from './visitor-keys'; @@ -59,7 +59,7 @@ export function parseForESLint( options.ecmaFeatures = {}; } - const parserOptions: TSEStreeOptions = {}; + const parserOptions: TSESTreeOptions = {}; Object.assign(parserOptions, options, { useJSXTextNode: validateBoolean(options.useJSXTextNode, true), jsx: validateBoolean(options.ecmaFeatures.jsx), diff --git a/packages/parser/typings/eslint-scope.d.ts b/packages/parser/typings/eslint-scope.d.ts index ef82834ca452..ec876c63716a 100644 --- a/packages/parser/typings/eslint-scope.d.ts +++ b/packages/parser/typings/eslint-scope.d.ts @@ -8,7 +8,7 @@ //----------------------------------------------------------------------- declare module 'eslint-scope/lib/options' { - import { TSESTree } from '@typescript-eslint/util'; + import { TSESTree } from '@typescript-eslint/experimental-utils'; export type PatternVisitorCallback = ( pattern: TSESTree.Identifier, info: { @@ -31,7 +31,7 @@ declare module 'eslint-scope/lib/options' { } declare module 'eslint-scope/lib/variable' { - import { TSESTree } from '@typescript-eslint/util'; + import { TSESTree } from '@typescript-eslint/experimental-utils'; import Reference from 'eslint-scope/lib/reference'; import { Definition } from 'eslint-scope/lib/definition'; @@ -45,7 +45,7 @@ declare module 'eslint-scope/lib/variable' { } declare module 'eslint-scope/lib/definition' { - import { TSESTree } from '@typescript-eslint/util'; + import { TSESTree } from '@typescript-eslint/experimental-utils'; export class Definition { type: string; @@ -78,7 +78,7 @@ declare module 'eslint-scope/lib/definition' { declare module 'eslint-scope/lib/pattern-visitor' { import ScopeManager from 'eslint-scope/lib/scope-manager'; - import { TSESTree } from '@typescript-eslint/util'; + import { TSESTree } from '@typescript-eslint/experimental-utils'; import { PatternVisitorCallback, PatternVisitorOptions, @@ -115,7 +115,7 @@ declare module 'eslint-scope/lib/pattern-visitor' { declare module 'eslint-scope/lib/referencer' { import { Scope } from 'eslint-scope/lib/scope'; import ScopeManager from 'eslint-scope/lib/scope-manager'; - import { TSESTree } from '@typescript-eslint/util'; + import { TSESTree } from '@typescript-eslint/experimental-utils'; import { PatternVisitorCallback, PatternVisitorOptions, @@ -192,7 +192,7 @@ declare module 'eslint-scope/lib/referencer' { } declare module 'eslint-scope/lib/scope' { - import { TSESTree } from '@typescript-eslint/util'; + import { TSESTree } from '@typescript-eslint/experimental-utils'; import Reference from 'eslint-scope/lib/reference'; import Variable from 'eslint-scope/lib/variable'; import ScopeManager from 'eslint-scope/lib/scope-manager'; @@ -378,7 +378,7 @@ declare module 'eslint-scope/lib/scope' { } declare module 'eslint-scope/lib/reference' { - import { TSESTree } from '@typescript-eslint/util'; + import { TSESTree } from '@typescript-eslint/experimental-utils'; import { Scope } from 'eslint-scope/lib/scope'; import Variable from 'eslint-scope/lib/variable'; @@ -402,7 +402,7 @@ declare module 'eslint-scope/lib/reference' { } declare module 'eslint-scope/lib/scope-manager' { - import { TSESTree } from '@typescript-eslint/util'; + import { TSESTree } from '@typescript-eslint/experimental-utils'; import { Scope } from 'eslint-scope/lib/scope'; import Variable from 'eslint-scope/lib/variable'; diff --git a/packages/typescript-estree/src/parser-options.ts b/packages/typescript-estree/src/parser-options.ts index 448c7bce649b..585effea268e 100644 --- a/packages/typescript-estree/src/parser-options.ts +++ b/packages/typescript-estree/src/parser-options.ts @@ -20,7 +20,7 @@ export interface Extra { preserveNodeMaps?: boolean; } -export interface TSEStreeOptions { +export interface TSESTreeOptions { range?: boolean; loc?: boolean; tokens?: boolean; diff --git a/packages/typescript-estree/src/parser.ts b/packages/typescript-estree/src/parser.ts index d250d3cc1e21..1a963859d969 100644 --- a/packages/typescript-estree/src/parser.ts +++ b/packages/typescript-estree/src/parser.ts @@ -3,7 +3,7 @@ import * as ts from 'typescript'; // leave this as * as ts so people using util import convert from './ast-converter'; import { convertError } from './convert'; import { firstDefined } from './node-utils'; -import { Extra, TSEStreeOptions, ParserServices } from './parser-options'; +import { Extra, TSESTreeOptions, ParserServices } from './parser-options'; import { getFirstSemanticOrSyntacticError } from './semantic-errors'; import { TSESTree } from './ts-estree'; import { @@ -66,7 +66,7 @@ function resetExtra(): void { * @param options The config object * @returns If found, returns the source file corresponding to the code and the containing program */ -function getASTFromProject(code: string, options: TSEStreeOptions) { +function getASTFromProject(code: string, options: TSESTreeOptions) { return firstDefined( calculateProjectParserOptions( code, @@ -87,7 +87,7 @@ function getASTFromProject(code: string, options: TSEStreeOptions) { * @param options The config object * @returns If found, returns the source file corresponding to the code and the containing program */ -function getASTAndDefaultProject(code: string, options: TSEStreeOptions) { +function getASTAndDefaultProject(code: string, options: TSESTreeOptions) { const fileName = options.filePath || getFileName(options); const program = createProgram(code, fileName, extra); const ast = program && program.getSourceFile(fileName); @@ -159,7 +159,7 @@ function createNewProgram(code: string) { */ function getProgramAndAST( code: string, - options: TSEStreeOptions, + options: TSESTreeOptions, shouldProvideParserServices: boolean, ) { return ( @@ -169,7 +169,7 @@ function getProgramAndAST( ); } -function applyParserOptionsToExtra(options: TSEStreeOptions): void { +function applyParserOptionsToExtra(options: TSESTreeOptions): void { /** * Track range information in the AST */ @@ -277,12 +277,12 @@ function warnAboutTSVersion(): void { // Parser //------------------------------------------------------------------------------ -type AST = TSESTree.Program & +type AST = TSESTree.Program & (T['range'] extends true ? { range: [number, number] } : {}) & (T['tokens'] extends true ? { tokens: TSESTree.Token[] } : {}) & (T['comment'] extends true ? { comments: TSESTree.Comment[] } : {}); -export interface ParseAndGenerateServicesResult { +export interface ParseAndGenerateServicesResult { ast: AST; services: ParserServices; } @@ -293,7 +293,7 @@ export interface ParseAndGenerateServicesResult { export const version: string = require('../package.json').version; -export function parse( +export function parse( code: string, options?: T, ): AST { @@ -344,7 +344,7 @@ export function parse( } export function parseAndGenerateServices< - T extends TSEStreeOptions = TSEStreeOptions + T extends TSESTreeOptions = TSESTreeOptions >(code: string, options: T): ParseAndGenerateServicesResult { /** * Reset the parse configuration @@ -427,5 +427,5 @@ export function parseAndGenerateServices< }; } -export { TSEStreeOptions, ParserServices }; +export { TSESTreeOptions, ParserServices }; export * from './ts-estree'; diff --git a/packages/typescript-estree/tests/lib/comments.ts b/packages/typescript-estree/tests/lib/comments.ts index 8ca9267ace79..68f9cd800d3b 100644 --- a/packages/typescript-estree/tests/lib/comments.ts +++ b/packages/typescript-estree/tests/lib/comments.ts @@ -1,7 +1,7 @@ import { readFileSync } from 'fs'; import glob from 'glob'; import { extname } from 'path'; -import { TSEStreeOptions } from '../../src/parser-options'; +import { TSESTreeOptions } from '../../src/parser-options'; import { createSnapshotTestBlock, formatSnapshotName, @@ -16,7 +16,7 @@ describe('Comments', () => { testFiles.forEach(filename => { const code = readFileSync(filename, 'utf8'); const fileExtension = extname(filename); - const config: TSEStreeOptions = { + const config: TSESTreeOptions = { loc: true, range: true, tokens: true, diff --git a/packages/typescript-estree/tests/lib/javascript.ts b/packages/typescript-estree/tests/lib/javascript.ts index a22a2085ca35..1cce991c0f43 100644 --- a/packages/typescript-estree/tests/lib/javascript.ts +++ b/packages/typescript-estree/tests/lib/javascript.ts @@ -1,6 +1,6 @@ import { readFileSync } from 'fs'; import glob from 'glob'; -import { TSEStreeOptions } from '../../src/parser-options'; +import { TSESTreeOptions } from '../../src/parser-options'; import { createSnapshotTestBlock, formatSnapshotName, @@ -13,7 +13,7 @@ const testFiles = glob.sync(`${FIXTURES_DIR}/**/*.src.js`); describe('javascript', () => { testFiles.forEach(filename => { const code = readFileSync(filename, 'utf8'); - const config: TSEStreeOptions = { + const config: TSESTreeOptions = { loc: true, range: true, tokens: true, diff --git a/packages/typescript-estree/tests/lib/jsx.ts b/packages/typescript-estree/tests/lib/jsx.ts index 706526903024..52b6debdf6b4 100644 --- a/packages/typescript-estree/tests/lib/jsx.ts +++ b/packages/typescript-estree/tests/lib/jsx.ts @@ -1,6 +1,6 @@ import { readFileSync } from 'fs'; import glob from 'glob'; -import { TSEStreeOptions } from '../../src/parser-options'; +import { TSESTreeOptions } from '../../src/parser-options'; import { createSnapshotTestBlock, formatSnapshotName, @@ -29,7 +29,7 @@ describe('JSX', () => { ): (filename: string) => void { return filename => { const code = readFileSync(filename, 'utf8'); - const config: TSEStreeOptions = { + const config: TSESTreeOptions = { loc: true, range: true, tokens: true, diff --git a/packages/typescript-estree/tests/lib/parse.ts b/packages/typescript-estree/tests/lib/parse.ts index 343aa2cb3dc7..3c34f7055565 100644 --- a/packages/typescript-estree/tests/lib/parse.ts +++ b/packages/typescript-estree/tests/lib/parse.ts @@ -1,6 +1,6 @@ import * as parser from '../../src/parser'; import * as astConverter from '../../src/ast-converter'; -import { TSEStreeOptions } from '../../src/parser-options'; +import { TSESTreeOptions } from '../../src/parser-options'; import { createSnapshotTestBlock } from '../../tools/test-utils'; describe('parse()', () => { @@ -23,7 +23,7 @@ describe('parse()', () => { describe('general', () => { const code = 'let foo = bar;'; - const config: TSEStreeOptions = { + const config: TSESTreeOptions = { comment: true, tokens: true, range: true, @@ -38,7 +38,7 @@ describe('parse()', () => { describe('non string code', () => { const code = (12345 as any) as string; - const config: TSEStreeOptions = { + const config: TSESTreeOptions = { comment: true, tokens: true, range: true, @@ -97,7 +97,7 @@ describe('parse()', () => { describe('errorOnTypeScriptSyntacticAndSemanticIssues', () => { const code = '@test const foo = 2'; - const options: TSEStreeOptions = { + const options: TSESTreeOptions = { comment: true, tokens: true, range: true, @@ -130,7 +130,7 @@ describe('parse()', () => { describe('preserveNodeMaps', () => { const code = 'var a = true'; - const baseConfig: TSEStreeOptions = { + const baseConfig: TSESTreeOptions = { comment: true, tokens: true, range: true, diff --git a/packages/typescript-estree/tests/lib/semantic-diagnostics-enabled.ts b/packages/typescript-estree/tests/lib/semantic-diagnostics-enabled.ts index 1ce15db9491b..fc05b04ec58b 100644 --- a/packages/typescript-estree/tests/lib/semantic-diagnostics-enabled.ts +++ b/packages/typescript-estree/tests/lib/semantic-diagnostics-enabled.ts @@ -16,7 +16,7 @@ describe('Parse all fixtures with "errorOnTypeScriptSyntacticAndSemanticIssues" testFiles.forEach(filename => { const code = readFileSync(filename, 'utf8'); const fileExtension = extname(filename); - const config: parser.TSEStreeOptions = { + const config: parser.TSESTreeOptions = { loc: true, range: true, tokens: true, diff --git a/packages/typescript-estree/tests/lib/semanticInfo.ts b/packages/typescript-estree/tests/lib/semanticInfo.ts index f06a19aaaff6..189816f08c64 100644 --- a/packages/typescript-estree/tests/lib/semanticInfo.ts +++ b/packages/typescript-estree/tests/lib/semanticInfo.ts @@ -2,7 +2,7 @@ import { readFileSync } from 'fs'; import glob from 'glob'; import { extname, join, resolve } from 'path'; import ts from 'typescript'; -import { TSEStreeOptions } from '../../src/parser-options'; +import { TSESTreeOptions } from '../../src/parser-options'; import { createSnapshotTestBlock, formatSnapshotName, @@ -14,7 +14,7 @@ import { TSESTree } from '../../src/ts-estree'; const FIXTURES_DIR = './tests/fixtures/semanticInfo'; const testFiles = glob.sync(`${FIXTURES_DIR}/**/*.src.ts`); -function createOptions(fileName: string): TSEStreeOptions & { cwd?: string } { +function createOptions(fileName: string): TSESTreeOptions & { cwd?: string } { return { loc: true, range: true, diff --git a/packages/typescript-estree/tests/lib/tsx.ts b/packages/typescript-estree/tests/lib/tsx.ts index b1389db877c7..84160d2b4b85 100644 --- a/packages/typescript-estree/tests/lib/tsx.ts +++ b/packages/typescript-estree/tests/lib/tsx.ts @@ -1,7 +1,7 @@ import { readFileSync } from 'fs'; import glob from 'glob'; import { extname } from 'path'; -import { TSEStreeOptions } from '../../src/parser-options'; +import { TSESTreeOptions } from '../../src/parser-options'; import { createSnapshotTestBlock, formatSnapshotName, @@ -16,7 +16,7 @@ describe('TSX', () => { testFiles.forEach(filename => { const code = readFileSync(filename, 'utf8'); const fileExtension = extname(filename); - const config: TSEStreeOptions = { + const config: TSESTreeOptions = { loc: true, range: true, tokens: true, diff --git a/packages/typescript-estree/tests/lib/typescript.ts b/packages/typescript-estree/tests/lib/typescript.ts index 2823d2b2ef71..2e5e70b04cf6 100644 --- a/packages/typescript-estree/tests/lib/typescript.ts +++ b/packages/typescript-estree/tests/lib/typescript.ts @@ -1,7 +1,7 @@ import { readFileSync } from 'fs'; import glob from 'glob'; import { extname } from 'path'; -import { TSEStreeOptions } from '../../src/parser-options'; +import { TSESTreeOptions } from '../../src/parser-options'; import { createSnapshotTestBlock, formatSnapshotName, @@ -16,7 +16,7 @@ describe('typescript', () => { testFiles.forEach(filename => { const code = readFileSync(filename, 'utf8'); const fileExtension = extname(filename); - const config: TSEStreeOptions = { + const config: TSESTreeOptions = { loc: true, range: true, tokens: true, diff --git a/packages/typescript-estree/tools/test-utils.ts b/packages/typescript-estree/tools/test-utils.ts index fccf74aeb4c6..f1c587df237b 100644 --- a/packages/typescript-estree/tools/test-utils.ts +++ b/packages/typescript-estree/tools/test-utils.ts @@ -1,5 +1,5 @@ import * as parser from '../src/parser'; -import { TSEStreeOptions } from '../src/parser-options'; +import { TSESTreeOptions } from '../src/parser-options'; /** * Returns a raw copy of the given AST @@ -19,7 +19,7 @@ export function getRaw(ast: any) { export function parseCodeAndGenerateServices( code: string, - config: TSEStreeOptions, + config: TSESTreeOptions, ) { return parser.parseAndGenerateServices(code, config); } @@ -28,13 +28,13 @@ export function parseCodeAndGenerateServices( * Returns a function which can be used as the callback of a Jest test() block, * and which performs an assertion on the snapshot for the given code and config. * @param {string} code The source code to parse - * @param {TSEStreeOptions} config the parser configuration + * @param {TSESTreeOptions} config the parser configuration * @param {boolean} generateServices Flag determining whether to generate ast maps and program or not * @returns {jest.ProvidesCallback} callback for Jest it() block */ export function createSnapshotTestBlock( code: string, - config: TSEStreeOptions, + config: TSESTreeOptions, generateServices?: true, ) { /**