From 6de19d3357706903c0ba7a73ef35aac6bfe048e7 Mon Sep 17 00:00:00 2001 From: Brad Zacher Date: Mon, 8 Jul 2019 05:43:47 -0700 Subject: [PATCH 1/8] fix(typescript-estree): fix `async` identifier token typed as `Keyword` (#681) --- .../lib/__snapshots__/typescript.ts.snap | 608 +++++++ .../basics/keyword-variables.src.ts | 13 + packages/typescript-estree/src/node-utils.ts | 23 +- .../semantic-diagnostics-enabled.ts.snap | 2 + .../lib/__snapshots__/typescript.ts.snap | 1436 +++++++++++++++++ 5 files changed, 2071 insertions(+), 11 deletions(-) create mode 100644 packages/shared-fixtures/fixtures/typescript/basics/keyword-variables.src.ts diff --git a/packages/parser/tests/lib/__snapshots__/typescript.ts.snap b/packages/parser/tests/lib/__snapshots__/typescript.ts.snap index aab28814499..2e00218b783 100644 --- a/packages/parser/tests/lib/__snapshots__/typescript.ts.snap +++ b/packages/parser/tests/lib/__snapshots__/typescript.ts.snap @@ -18534,6 +18534,614 @@ Object { } `; +exports[`typescript fixtures/basics/keyword-variables.src 1`] = ` +Object { + "$id": 11, + "block": Object { + "range": Array [ + 0, + 154, + ], + "type": "Program", + }, + "childScopes": Array [ + Object { + "$id": 10, + "block": Object { + "range": Array [ + 0, + 154, + ], + "type": "Program", + }, + "childScopes": Array [], + "functionExpressionScope": false, + "isStrict": true, + "references": Array [ + Object { + "$id": 5, + "from": Object { + "$ref": 10, + }, + "identifier": Object { + "name": "get", + "range": Array [ + 6, + 9, + ], + "type": "Identifier", + }, + "kind": "w", + "resolved": Object { + "$ref": 0, + }, + "writeExpr": Object { + "range": Array [ + 12, + 13, + ], + "type": "Literal", + }, + }, + Object { + "$id": 6, + "from": Object { + "$ref": 10, + }, + "identifier": Object { + "name": "set", + "range": Array [ + 21, + 24, + ], + "type": "Identifier", + }, + "kind": "w", + "resolved": Object { + "$ref": 1, + }, + "writeExpr": Object { + "range": Array [ + 27, + 28, + ], + "type": "Literal", + }, + }, + Object { + "$id": 7, + "from": Object { + "$ref": 10, + }, + "identifier": Object { + "name": "module", + "range": Array [ + 36, + 42, + ], + "type": "Identifier", + }, + "kind": "w", + "resolved": Object { + "$ref": 2, + }, + "writeExpr": Object { + "range": Array [ + 45, + 46, + ], + "type": "Literal", + }, + }, + Object { + "$id": 8, + "from": Object { + "$ref": 10, + }, + "identifier": Object { + "name": "type", + "range": Array [ + 54, + 58, + ], + "type": "Identifier", + }, + "kind": "w", + "resolved": Object { + "$ref": 3, + }, + "writeExpr": Object { + "range": Array [ + 61, + 62, + ], + "type": "Literal", + }, + }, + Object { + "$id": 9, + "from": Object { + "$ref": 10, + }, + "identifier": Object { + "name": "async", + "range": Array [ + 70, + 75, + ], + "type": "Identifier", + }, + "kind": "w", + "resolved": Object { + "$ref": 4, + }, + "writeExpr": Object { + "range": Array [ + 78, + 79, + ], + "type": "Literal", + }, + }, + ], + "throughReferences": Array [], + "type": "module", + "upperScope": Object { + "$ref": 11, + }, + "variableMap": Object { + "async": Object { + "$ref": 4, + }, + "get": Object { + "$ref": 0, + }, + "module": Object { + "$ref": 2, + }, + "set": Object { + "$ref": 1, + }, + "type": Object { + "$ref": 3, + }, + }, + "variableScope": Object { + "$ref": 10, + }, + "variables": Array [ + Object { + "$id": 0, + "defs": Array [ + Object { + "name": Object { + "name": "get", + "range": Array [ + 6, + 9, + ], + "type": "Identifier", + }, + "node": Object { + "range": Array [ + 6, + 13, + ], + "type": "VariableDeclarator", + }, + "parent": Object { + "range": Array [ + 0, + 14, + ], + "type": "VariableDeclaration", + }, + "type": "Variable", + }, + Object { + "name": Object { + "name": "get", + "range": Array [ + 93, + 96, + ], + "type": "Identifier", + }, + "node": Object { + "range": Array [ + 93, + 96, + ], + "type": "ImportSpecifier", + }, + "parent": Object { + "range": Array [ + 82, + 153, + ], + "type": "ImportDeclaration", + }, + "type": "ImportBinding", + }, + ], + "eslintUsed": undefined, + "identifiers": Array [ + Object { + "name": "get", + "range": Array [ + 6, + 9, + ], + "type": "Identifier", + }, + Object { + "name": "get", + "range": Array [ + 93, + 96, + ], + "type": "Identifier", + }, + ], + "name": "get", + "references": Array [ + Object { + "$ref": 5, + }, + ], + "scope": Object { + "$ref": 10, + }, + }, + Object { + "$id": 1, + "defs": Array [ + Object { + "name": Object { + "name": "set", + "range": Array [ + 21, + 24, + ], + "type": "Identifier", + }, + "node": Object { + "range": Array [ + 21, + 28, + ], + "type": "VariableDeclarator", + }, + "parent": Object { + "range": Array [ + 15, + 29, + ], + "type": "VariableDeclaration", + }, + "type": "Variable", + }, + Object { + "name": Object { + "name": "set", + "range": Array [ + 100, + 103, + ], + "type": "Identifier", + }, + "node": Object { + "range": Array [ + 100, + 103, + ], + "type": "ImportSpecifier", + }, + "parent": Object { + "range": Array [ + 82, + 153, + ], + "type": "ImportDeclaration", + }, + "type": "ImportBinding", + }, + ], + "eslintUsed": undefined, + "identifiers": Array [ + Object { + "name": "set", + "range": Array [ + 21, + 24, + ], + "type": "Identifier", + }, + Object { + "name": "set", + "range": Array [ + 100, + 103, + ], + "type": "Identifier", + }, + ], + "name": "set", + "references": Array [ + Object { + "$ref": 6, + }, + ], + "scope": Object { + "$ref": 10, + }, + }, + Object { + "$id": 2, + "defs": Array [ + Object { + "name": Object { + "name": "module", + "range": Array [ + 36, + 42, + ], + "type": "Identifier", + }, + "node": Object { + "range": Array [ + 36, + 46, + ], + "type": "VariableDeclarator", + }, + "parent": Object { + "range": Array [ + 30, + 47, + ], + "type": "VariableDeclaration", + }, + "type": "Variable", + }, + Object { + "name": Object { + "name": "module", + "range": Array [ + 107, + 113, + ], + "type": "Identifier", + }, + "node": Object { + "range": Array [ + 107, + 113, + ], + "type": "ImportSpecifier", + }, + "parent": Object { + "range": Array [ + 82, + 153, + ], + "type": "ImportDeclaration", + }, + "type": "ImportBinding", + }, + ], + "eslintUsed": undefined, + "identifiers": Array [ + Object { + "name": "module", + "range": Array [ + 36, + 42, + ], + "type": "Identifier", + }, + Object { + "name": "module", + "range": Array [ + 107, + 113, + ], + "type": "Identifier", + }, + ], + "name": "module", + "references": Array [ + Object { + "$ref": 7, + }, + ], + "scope": Object { + "$ref": 10, + }, + }, + Object { + "$id": 3, + "defs": Array [ + Object { + "name": Object { + "name": "type", + "range": Array [ + 54, + 58, + ], + "type": "Identifier", + }, + "node": Object { + "range": Array [ + 54, + 62, + ], + "type": "VariableDeclarator", + }, + "parent": Object { + "range": Array [ + 48, + 63, + ], + "type": "VariableDeclaration", + }, + "type": "Variable", + }, + Object { + "name": Object { + "name": "type", + "range": Array [ + 117, + 121, + ], + "type": "Identifier", + }, + "node": Object { + "range": Array [ + 117, + 121, + ], + "type": "ImportSpecifier", + }, + "parent": Object { + "range": Array [ + 82, + 153, + ], + "type": "ImportDeclaration", + }, + "type": "ImportBinding", + }, + ], + "eslintUsed": undefined, + "identifiers": Array [ + Object { + "name": "type", + "range": Array [ + 54, + 58, + ], + "type": "Identifier", + }, + Object { + "name": "type", + "range": Array [ + 117, + 121, + ], + "type": "Identifier", + }, + ], + "name": "type", + "references": Array [ + Object { + "$ref": 8, + }, + ], + "scope": Object { + "$ref": 10, + }, + }, + Object { + "$id": 4, + "defs": Array [ + Object { + "name": Object { + "name": "async", + "range": Array [ + 70, + 75, + ], + "type": "Identifier", + }, + "node": Object { + "range": Array [ + 70, + 79, + ], + "type": "VariableDeclarator", + }, + "parent": Object { + "range": Array [ + 64, + 80, + ], + "type": "VariableDeclaration", + }, + "type": "Variable", + }, + Object { + "name": Object { + "name": "async", + "range": Array [ + 125, + 130, + ], + "type": "Identifier", + }, + "node": Object { + "range": Array [ + 125, + 130, + ], + "type": "ImportSpecifier", + }, + "parent": Object { + "range": Array [ + 82, + 153, + ], + "type": "ImportDeclaration", + }, + "type": "ImportBinding", + }, + ], + "eslintUsed": undefined, + "identifiers": Array [ + Object { + "name": "async", + "range": Array [ + 70, + 75, + ], + "type": "Identifier", + }, + Object { + "name": "async", + "range": Array [ + 125, + 130, + ], + "type": "Identifier", + }, + ], + "name": "async", + "references": Array [ + Object { + "$ref": 9, + }, + ], + "scope": Object { + "$ref": 10, + }, + }, + ], + }, + ], + "functionExpressionScope": false, + "isStrict": false, + "references": Array [], + "throughReferences": Array [], + "type": "global", + "upperScope": null, + "variableMap": Object {}, + "variableScope": Object { + "$ref": 11, + }, + "variables": Array [], +} +`; + exports[`typescript fixtures/basics/nested-type-arguments.src 1`] = ` Object { "$id": 2, diff --git a/packages/shared-fixtures/fixtures/typescript/basics/keyword-variables.src.ts b/packages/shared-fixtures/fixtures/typescript/basics/keyword-variables.src.ts new file mode 100644 index 00000000000..f4cbb3212bf --- /dev/null +++ b/packages/shared-fixtures/fixtures/typescript/basics/keyword-variables.src.ts @@ -0,0 +1,13 @@ +const get = 1; +const set = 1; +const module = 1; +const type = 1; +const async = 1; + +import { + get, + set, + module, + type, + async, +} from 'fake-module'; diff --git a/packages/typescript-estree/src/node-utils.ts b/packages/typescript-estree/src/node-utils.ts index d682bb091b4..a8d1b137d1c 100644 --- a/packages/typescript-estree/src/node-utils.ts +++ b/packages/typescript-estree/src/node-utils.ts @@ -455,6 +455,7 @@ export function getTokenType(token: any): AST_TOKEN_TYPES { case SyntaxKind.SetKeyword: case SyntaxKind.TypeKeyword: case SyntaxKind.ModuleKeyword: + case SyntaxKind.AsyncKeyword: return AST_TOKEN_TYPES.Identifier; default: @@ -550,17 +551,17 @@ export function convertToken( ast: ts.SourceFile, ): TSESTree.Token { const start = - token.kind === SyntaxKind.JsxText - ? token.getFullStart() - : token.getStart(ast), - end = token.getEnd(), - value = ast.text.slice(start, end), - newToken: TSESTree.Token = { - type: getTokenType(token), - value, - range: [start, end], - loc: getLocFor(start, end, ast), - }; + token.kind === SyntaxKind.JsxText + ? token.getFullStart() + : token.getStart(ast); + const end = token.getEnd(); + const value = ast.text.slice(start, end); + const newToken: TSESTree.Token = { + type: getTokenType(token), + value, + range: [start, end], + loc: getLocFor(start, end, ast), + }; if (newToken.type === 'RegularExpression') { newToken.regex = { diff --git a/packages/typescript-estree/tests/lib/__snapshots__/semantic-diagnostics-enabled.ts.snap b/packages/typescript-estree/tests/lib/__snapshots__/semantic-diagnostics-enabled.ts.snap index 227932cd936..7af41c0f302 100644 --- a/packages/typescript-estree/tests/lib/__snapshots__/semantic-diagnostics-enabled.ts.snap +++ b/packages/typescript-estree/tests/lib/__snapshots__/semantic-diagnostics-enabled.ts.snap @@ -1883,6 +1883,8 @@ exports[`Parse all fixtures with "errorOnTypeScriptSyntacticAndSemanticIssues" e exports[`Parse all fixtures with "errorOnTypeScriptSyntacticAndSemanticIssues" enabled fixtures/typescript/basics/keyof-operator.src 1`] = `"TEST OUTPUT: No semantic or syntactic issues found"`; +exports[`Parse all fixtures with "errorOnTypeScriptSyntacticAndSemanticIssues" enabled fixtures/typescript/basics/keyword-variables.src 1`] = `"TEST OUTPUT: No semantic or syntactic issues found"`; + exports[`Parse all fixtures with "errorOnTypeScriptSyntacticAndSemanticIssues" enabled fixtures/typescript/basics/nested-type-arguments.src 1`] = `"TEST OUTPUT: No semantic or syntactic issues found"`; exports[`Parse all fixtures with "errorOnTypeScriptSyntacticAndSemanticIssues" enabled fixtures/typescript/basics/never-type-param.src 1`] = `"TEST OUTPUT: No semantic or syntactic issues found"`; diff --git a/packages/typescript-estree/tests/lib/__snapshots__/typescript.ts.snap b/packages/typescript-estree/tests/lib/__snapshots__/typescript.ts.snap index c8f0cf9e364..0859b036250 100644 --- a/packages/typescript-estree/tests/lib/__snapshots__/typescript.ts.snap +++ b/packages/typescript-estree/tests/lib/__snapshots__/typescript.ts.snap @@ -58608,6 +58608,1442 @@ Object { } `; +exports[`typescript fixtures/basics/keyword-variables.src 1`] = ` +Object { + "body": Array [ + Object { + "declarations": Array [ + Object { + "id": Object { + "loc": Object { + "end": Object { + "column": 9, + "line": 1, + }, + "start": Object { + "column": 6, + "line": 1, + }, + }, + "name": "get", + "range": Array [ + 6, + 9, + ], + "type": "Identifier", + }, + "init": Object { + "loc": Object { + "end": Object { + "column": 13, + "line": 1, + }, + "start": Object { + "column": 12, + "line": 1, + }, + }, + "range": Array [ + 12, + 13, + ], + "raw": "1", + "type": "Literal", + "value": 1, + }, + "loc": Object { + "end": Object { + "column": 13, + "line": 1, + }, + "start": Object { + "column": 6, + "line": 1, + }, + }, + "range": Array [ + 6, + 13, + ], + "type": "VariableDeclarator", + }, + ], + "kind": "const", + "loc": Object { + "end": Object { + "column": 14, + "line": 1, + }, + "start": Object { + "column": 0, + "line": 1, + }, + }, + "range": Array [ + 0, + 14, + ], + "type": "VariableDeclaration", + }, + Object { + "declarations": Array [ + Object { + "id": Object { + "loc": Object { + "end": Object { + "column": 9, + "line": 2, + }, + "start": Object { + "column": 6, + "line": 2, + }, + }, + "name": "set", + "range": Array [ + 21, + 24, + ], + "type": "Identifier", + }, + "init": Object { + "loc": Object { + "end": Object { + "column": 13, + "line": 2, + }, + "start": Object { + "column": 12, + "line": 2, + }, + }, + "range": Array [ + 27, + 28, + ], + "raw": "1", + "type": "Literal", + "value": 1, + }, + "loc": Object { + "end": Object { + "column": 13, + "line": 2, + }, + "start": Object { + "column": 6, + "line": 2, + }, + }, + "range": Array [ + 21, + 28, + ], + "type": "VariableDeclarator", + }, + ], + "kind": "const", + "loc": Object { + "end": Object { + "column": 14, + "line": 2, + }, + "start": Object { + "column": 0, + "line": 2, + }, + }, + "range": Array [ + 15, + 29, + ], + "type": "VariableDeclaration", + }, + Object { + "declarations": Array [ + Object { + "id": Object { + "loc": Object { + "end": Object { + "column": 12, + "line": 3, + }, + "start": Object { + "column": 6, + "line": 3, + }, + }, + "name": "module", + "range": Array [ + 36, + 42, + ], + "type": "Identifier", + }, + "init": Object { + "loc": Object { + "end": Object { + "column": 16, + "line": 3, + }, + "start": Object { + "column": 15, + "line": 3, + }, + }, + "range": Array [ + 45, + 46, + ], + "raw": "1", + "type": "Literal", + "value": 1, + }, + "loc": Object { + "end": Object { + "column": 16, + "line": 3, + }, + "start": Object { + "column": 6, + "line": 3, + }, + }, + "range": Array [ + 36, + 46, + ], + "type": "VariableDeclarator", + }, + ], + "kind": "const", + "loc": Object { + "end": Object { + "column": 17, + "line": 3, + }, + "start": Object { + "column": 0, + "line": 3, + }, + }, + "range": Array [ + 30, + 47, + ], + "type": "VariableDeclaration", + }, + Object { + "declarations": Array [ + Object { + "id": Object { + "loc": Object { + "end": Object { + "column": 10, + "line": 4, + }, + "start": Object { + "column": 6, + "line": 4, + }, + }, + "name": "type", + "range": Array [ + 54, + 58, + ], + "type": "Identifier", + }, + "init": Object { + "loc": Object { + "end": Object { + "column": 14, + "line": 4, + }, + "start": Object { + "column": 13, + "line": 4, + }, + }, + "range": Array [ + 61, + 62, + ], + "raw": "1", + "type": "Literal", + "value": 1, + }, + "loc": Object { + "end": Object { + "column": 14, + "line": 4, + }, + "start": Object { + "column": 6, + "line": 4, + }, + }, + "range": Array [ + 54, + 62, + ], + "type": "VariableDeclarator", + }, + ], + "kind": "const", + "loc": Object { + "end": Object { + "column": 15, + "line": 4, + }, + "start": Object { + "column": 0, + "line": 4, + }, + }, + "range": Array [ + 48, + 63, + ], + "type": "VariableDeclaration", + }, + Object { + "declarations": Array [ + Object { + "id": Object { + "loc": Object { + "end": Object { + "column": 11, + "line": 5, + }, + "start": Object { + "column": 6, + "line": 5, + }, + }, + "name": "async", + "range": Array [ + 70, + 75, + ], + "type": "Identifier", + }, + "init": Object { + "loc": Object { + "end": Object { + "column": 15, + "line": 5, + }, + "start": Object { + "column": 14, + "line": 5, + }, + }, + "range": Array [ + 78, + 79, + ], + "raw": "1", + "type": "Literal", + "value": 1, + }, + "loc": Object { + "end": Object { + "column": 15, + "line": 5, + }, + "start": Object { + "column": 6, + "line": 5, + }, + }, + "range": Array [ + 70, + 79, + ], + "type": "VariableDeclarator", + }, + ], + "kind": "const", + "loc": Object { + "end": Object { + "column": 16, + "line": 5, + }, + "start": Object { + "column": 0, + "line": 5, + }, + }, + "range": Array [ + 64, + 80, + ], + "type": "VariableDeclaration", + }, + Object { + "loc": Object { + "end": Object { + "column": 21, + "line": 13, + }, + "start": Object { + "column": 0, + "line": 7, + }, + }, + "range": Array [ + 82, + 153, + ], + "source": Object { + "loc": Object { + "end": Object { + "column": 20, + "line": 13, + }, + "start": Object { + "column": 7, + "line": 13, + }, + }, + "range": Array [ + 139, + 152, + ], + "raw": "'fake-module'", + "type": "Literal", + "value": "fake-module", + }, + "specifiers": Array [ + Object { + "imported": Object { + "loc": Object { + "end": Object { + "column": 5, + "line": 8, + }, + "start": Object { + "column": 2, + "line": 8, + }, + }, + "name": "get", + "range": Array [ + 93, + 96, + ], + "type": "Identifier", + }, + "loc": Object { + "end": Object { + "column": 5, + "line": 8, + }, + "start": Object { + "column": 2, + "line": 8, + }, + }, + "local": Object { + "loc": Object { + "end": Object { + "column": 5, + "line": 8, + }, + "start": Object { + "column": 2, + "line": 8, + }, + }, + "name": "get", + "range": Array [ + 93, + 96, + ], + "type": "Identifier", + }, + "range": Array [ + 93, + 96, + ], + "type": "ImportSpecifier", + }, + Object { + "imported": Object { + "loc": Object { + "end": Object { + "column": 5, + "line": 9, + }, + "start": Object { + "column": 2, + "line": 9, + }, + }, + "name": "set", + "range": Array [ + 100, + 103, + ], + "type": "Identifier", + }, + "loc": Object { + "end": Object { + "column": 5, + "line": 9, + }, + "start": Object { + "column": 2, + "line": 9, + }, + }, + "local": Object { + "loc": Object { + "end": Object { + "column": 5, + "line": 9, + }, + "start": Object { + "column": 2, + "line": 9, + }, + }, + "name": "set", + "range": Array [ + 100, + 103, + ], + "type": "Identifier", + }, + "range": Array [ + 100, + 103, + ], + "type": "ImportSpecifier", + }, + Object { + "imported": Object { + "loc": Object { + "end": Object { + "column": 8, + "line": 10, + }, + "start": Object { + "column": 2, + "line": 10, + }, + }, + "name": "module", + "range": Array [ + 107, + 113, + ], + "type": "Identifier", + }, + "loc": Object { + "end": Object { + "column": 8, + "line": 10, + }, + "start": Object { + "column": 2, + "line": 10, + }, + }, + "local": Object { + "loc": Object { + "end": Object { + "column": 8, + "line": 10, + }, + "start": Object { + "column": 2, + "line": 10, + }, + }, + "name": "module", + "range": Array [ + 107, + 113, + ], + "type": "Identifier", + }, + "range": Array [ + 107, + 113, + ], + "type": "ImportSpecifier", + }, + Object { + "imported": Object { + "loc": Object { + "end": Object { + "column": 6, + "line": 11, + }, + "start": Object { + "column": 2, + "line": 11, + }, + }, + "name": "type", + "range": Array [ + 117, + 121, + ], + "type": "Identifier", + }, + "loc": Object { + "end": Object { + "column": 6, + "line": 11, + }, + "start": Object { + "column": 2, + "line": 11, + }, + }, + "local": Object { + "loc": Object { + "end": Object { + "column": 6, + "line": 11, + }, + "start": Object { + "column": 2, + "line": 11, + }, + }, + "name": "type", + "range": Array [ + 117, + 121, + ], + "type": "Identifier", + }, + "range": Array [ + 117, + 121, + ], + "type": "ImportSpecifier", + }, + Object { + "imported": Object { + "loc": Object { + "end": Object { + "column": 7, + "line": 12, + }, + "start": Object { + "column": 2, + "line": 12, + }, + }, + "name": "async", + "range": Array [ + 125, + 130, + ], + "type": "Identifier", + }, + "loc": Object { + "end": Object { + "column": 7, + "line": 12, + }, + "start": Object { + "column": 2, + "line": 12, + }, + }, + "local": Object { + "loc": Object { + "end": Object { + "column": 7, + "line": 12, + }, + "start": Object { + "column": 2, + "line": 12, + }, + }, + "name": "async", + "range": Array [ + 125, + 130, + ], + "type": "Identifier", + }, + "range": Array [ + 125, + 130, + ], + "type": "ImportSpecifier", + }, + ], + "type": "ImportDeclaration", + }, + ], + "loc": Object { + "end": Object { + "column": 0, + "line": 14, + }, + "start": Object { + "column": 0, + "line": 1, + }, + }, + "range": Array [ + 0, + 154, + ], + "sourceType": "module", + "tokens": Array [ + Object { + "loc": Object { + "end": Object { + "column": 5, + "line": 1, + }, + "start": Object { + "column": 0, + "line": 1, + }, + }, + "range": Array [ + 0, + 5, + ], + "type": "Keyword", + "value": "const", + }, + Object { + "loc": Object { + "end": Object { + "column": 9, + "line": 1, + }, + "start": Object { + "column": 6, + "line": 1, + }, + }, + "range": Array [ + 6, + 9, + ], + "type": "Identifier", + "value": "get", + }, + Object { + "loc": Object { + "end": Object { + "column": 11, + "line": 1, + }, + "start": Object { + "column": 10, + "line": 1, + }, + }, + "range": Array [ + 10, + 11, + ], + "type": "Punctuator", + "value": "=", + }, + Object { + "loc": Object { + "end": Object { + "column": 13, + "line": 1, + }, + "start": Object { + "column": 12, + "line": 1, + }, + }, + "range": Array [ + 12, + 13, + ], + "type": "Numeric", + "value": "1", + }, + Object { + "loc": Object { + "end": Object { + "column": 14, + "line": 1, + }, + "start": Object { + "column": 13, + "line": 1, + }, + }, + "range": Array [ + 13, + 14, + ], + "type": "Punctuator", + "value": ";", + }, + Object { + "loc": Object { + "end": Object { + "column": 5, + "line": 2, + }, + "start": Object { + "column": 0, + "line": 2, + }, + }, + "range": Array [ + 15, + 20, + ], + "type": "Keyword", + "value": "const", + }, + Object { + "loc": Object { + "end": Object { + "column": 9, + "line": 2, + }, + "start": Object { + "column": 6, + "line": 2, + }, + }, + "range": Array [ + 21, + 24, + ], + "type": "Identifier", + "value": "set", + }, + Object { + "loc": Object { + "end": Object { + "column": 11, + "line": 2, + }, + "start": Object { + "column": 10, + "line": 2, + }, + }, + "range": Array [ + 25, + 26, + ], + "type": "Punctuator", + "value": "=", + }, + Object { + "loc": Object { + "end": Object { + "column": 13, + "line": 2, + }, + "start": Object { + "column": 12, + "line": 2, + }, + }, + "range": Array [ + 27, + 28, + ], + "type": "Numeric", + "value": "1", + }, + Object { + "loc": Object { + "end": Object { + "column": 14, + "line": 2, + }, + "start": Object { + "column": 13, + "line": 2, + }, + }, + "range": Array [ + 28, + 29, + ], + "type": "Punctuator", + "value": ";", + }, + Object { + "loc": Object { + "end": Object { + "column": 5, + "line": 3, + }, + "start": Object { + "column": 0, + "line": 3, + }, + }, + "range": Array [ + 30, + 35, + ], + "type": "Keyword", + "value": "const", + }, + Object { + "loc": Object { + "end": Object { + "column": 12, + "line": 3, + }, + "start": Object { + "column": 6, + "line": 3, + }, + }, + "range": Array [ + 36, + 42, + ], + "type": "Identifier", + "value": "module", + }, + Object { + "loc": Object { + "end": Object { + "column": 14, + "line": 3, + }, + "start": Object { + "column": 13, + "line": 3, + }, + }, + "range": Array [ + 43, + 44, + ], + "type": "Punctuator", + "value": "=", + }, + Object { + "loc": Object { + "end": Object { + "column": 16, + "line": 3, + }, + "start": Object { + "column": 15, + "line": 3, + }, + }, + "range": Array [ + 45, + 46, + ], + "type": "Numeric", + "value": "1", + }, + Object { + "loc": Object { + "end": Object { + "column": 17, + "line": 3, + }, + "start": Object { + "column": 16, + "line": 3, + }, + }, + "range": Array [ + 46, + 47, + ], + "type": "Punctuator", + "value": ";", + }, + Object { + "loc": Object { + "end": Object { + "column": 5, + "line": 4, + }, + "start": Object { + "column": 0, + "line": 4, + }, + }, + "range": Array [ + 48, + 53, + ], + "type": "Keyword", + "value": "const", + }, + Object { + "loc": Object { + "end": Object { + "column": 10, + "line": 4, + }, + "start": Object { + "column": 6, + "line": 4, + }, + }, + "range": Array [ + 54, + 58, + ], + "type": "Identifier", + "value": "type", + }, + Object { + "loc": Object { + "end": Object { + "column": 12, + "line": 4, + }, + "start": Object { + "column": 11, + "line": 4, + }, + }, + "range": Array [ + 59, + 60, + ], + "type": "Punctuator", + "value": "=", + }, + Object { + "loc": Object { + "end": Object { + "column": 14, + "line": 4, + }, + "start": Object { + "column": 13, + "line": 4, + }, + }, + "range": Array [ + 61, + 62, + ], + "type": "Numeric", + "value": "1", + }, + Object { + "loc": Object { + "end": Object { + "column": 15, + "line": 4, + }, + "start": Object { + "column": 14, + "line": 4, + }, + }, + "range": Array [ + 62, + 63, + ], + "type": "Punctuator", + "value": ";", + }, + Object { + "loc": Object { + "end": Object { + "column": 5, + "line": 5, + }, + "start": Object { + "column": 0, + "line": 5, + }, + }, + "range": Array [ + 64, + 69, + ], + "type": "Keyword", + "value": "const", + }, + Object { + "loc": Object { + "end": Object { + "column": 11, + "line": 5, + }, + "start": Object { + "column": 6, + "line": 5, + }, + }, + "range": Array [ + 70, + 75, + ], + "type": "Identifier", + "value": "async", + }, + Object { + "loc": Object { + "end": Object { + "column": 13, + "line": 5, + }, + "start": Object { + "column": 12, + "line": 5, + }, + }, + "range": Array [ + 76, + 77, + ], + "type": "Punctuator", + "value": "=", + }, + Object { + "loc": Object { + "end": Object { + "column": 15, + "line": 5, + }, + "start": Object { + "column": 14, + "line": 5, + }, + }, + "range": Array [ + 78, + 79, + ], + "type": "Numeric", + "value": "1", + }, + Object { + "loc": Object { + "end": Object { + "column": 16, + "line": 5, + }, + "start": Object { + "column": 15, + "line": 5, + }, + }, + "range": Array [ + 79, + 80, + ], + "type": "Punctuator", + "value": ";", + }, + Object { + "loc": Object { + "end": Object { + "column": 6, + "line": 7, + }, + "start": Object { + "column": 0, + "line": 7, + }, + }, + "range": Array [ + 82, + 88, + ], + "type": "Keyword", + "value": "import", + }, + Object { + "loc": Object { + "end": Object { + "column": 8, + "line": 7, + }, + "start": Object { + "column": 7, + "line": 7, + }, + }, + "range": Array [ + 89, + 90, + ], + "type": "Punctuator", + "value": "{", + }, + Object { + "loc": Object { + "end": Object { + "column": 5, + "line": 8, + }, + "start": Object { + "column": 2, + "line": 8, + }, + }, + "range": Array [ + 93, + 96, + ], + "type": "Identifier", + "value": "get", + }, + Object { + "loc": Object { + "end": Object { + "column": 6, + "line": 8, + }, + "start": Object { + "column": 5, + "line": 8, + }, + }, + "range": Array [ + 96, + 97, + ], + "type": "Punctuator", + "value": ",", + }, + Object { + "loc": Object { + "end": Object { + "column": 5, + "line": 9, + }, + "start": Object { + "column": 2, + "line": 9, + }, + }, + "range": Array [ + 100, + 103, + ], + "type": "Identifier", + "value": "set", + }, + Object { + "loc": Object { + "end": Object { + "column": 6, + "line": 9, + }, + "start": Object { + "column": 5, + "line": 9, + }, + }, + "range": Array [ + 103, + 104, + ], + "type": "Punctuator", + "value": ",", + }, + Object { + "loc": Object { + "end": Object { + "column": 8, + "line": 10, + }, + "start": Object { + "column": 2, + "line": 10, + }, + }, + "range": Array [ + 107, + 113, + ], + "type": "Identifier", + "value": "module", + }, + Object { + "loc": Object { + "end": Object { + "column": 9, + "line": 10, + }, + "start": Object { + "column": 8, + "line": 10, + }, + }, + "range": Array [ + 113, + 114, + ], + "type": "Punctuator", + "value": ",", + }, + Object { + "loc": Object { + "end": Object { + "column": 6, + "line": 11, + }, + "start": Object { + "column": 2, + "line": 11, + }, + }, + "range": Array [ + 117, + 121, + ], + "type": "Identifier", + "value": "type", + }, + Object { + "loc": Object { + "end": Object { + "column": 7, + "line": 11, + }, + "start": Object { + "column": 6, + "line": 11, + }, + }, + "range": Array [ + 121, + 122, + ], + "type": "Punctuator", + "value": ",", + }, + Object { + "loc": Object { + "end": Object { + "column": 7, + "line": 12, + }, + "start": Object { + "column": 2, + "line": 12, + }, + }, + "range": Array [ + 125, + 130, + ], + "type": "Identifier", + "value": "async", + }, + Object { + "loc": Object { + "end": Object { + "column": 8, + "line": 12, + }, + "start": Object { + "column": 7, + "line": 12, + }, + }, + "range": Array [ + 130, + 131, + ], + "type": "Punctuator", + "value": ",", + }, + Object { + "loc": Object { + "end": Object { + "column": 1, + "line": 13, + }, + "start": Object { + "column": 0, + "line": 13, + }, + }, + "range": Array [ + 132, + 133, + ], + "type": "Punctuator", + "value": "}", + }, + Object { + "loc": Object { + "end": Object { + "column": 6, + "line": 13, + }, + "start": Object { + "column": 2, + "line": 13, + }, + }, + "range": Array [ + 134, + 138, + ], + "type": "Identifier", + "value": "from", + }, + Object { + "loc": Object { + "end": Object { + "column": 20, + "line": 13, + }, + "start": Object { + "column": 7, + "line": 13, + }, + }, + "range": Array [ + 139, + 152, + ], + "type": "String", + "value": "'fake-module'", + }, + Object { + "loc": Object { + "end": Object { + "column": 21, + "line": 13, + }, + "start": Object { + "column": 20, + "line": 13, + }, + }, + "range": Array [ + 152, + 153, + ], + "type": "Punctuator", + "value": ";", + }, + ], + "type": "Program", +} +`; + exports[`typescript fixtures/basics/nested-type-arguments.src 1`] = ` Object { "body": Array [ From e0aeb184049084748e613b8d181d97ce19aaaa37 Mon Sep 17 00:00:00 2001 From: Brad Zacher Date: Mon, 8 Jul 2019 07:31:27 -0700 Subject: [PATCH 2/8] feat(eslint-plugin): [explicit-function-return-type] add handling for usage as arguments (#680) --- .../rules/explicit-function-return-type.md | 3 + .../rules/explicit-function-return-type.ts | 18 ++- .../explicit-function-return-type.test.ts | 119 ++++++++++++++++++ 3 files changed, 139 insertions(+), 1 deletion(-) diff --git a/packages/eslint-plugin/docs/rules/explicit-function-return-type.md b/packages/eslint-plugin/docs/rules/explicit-function-return-type.md index a20aa83c7a5..9aacb0acafc 100644 --- a/packages/eslint-plugin/docs/rules/explicit-function-return-type.md +++ b/packages/eslint-plugin/docs/rules/explicit-function-return-type.md @@ -138,6 +138,9 @@ let objectPropAs = { let objectPropCast = { foo: () => 1, }; + +declare functionWithArg(arg: () => number); +functionWithArg(() => 1); ``` ### allowHigherOrderFunctions 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 876f42517d6..d5176a43af5 100644 --- a/packages/eslint-plugin/src/rules/explicit-function-return-type.ts +++ b/packages/eslint-plugin/src/rules/explicit-function-return-type.ts @@ -187,6 +187,21 @@ export default util.createRule({ ); } + /** + * Checks if a node belongs to: + * `foo(() => 1)` + */ + function isFunctionArgument( + parent: TSESTree.Node, + child: TSESTree.Node, + ): boolean { + return ( + parent.type === AST_NODE_TYPES.CallExpression && + // make sure this isn't an IIFE + parent.callee !== child + ); + } + /** * Checks if a function declaration/expression has a return type. */ @@ -232,7 +247,8 @@ export default util.createRule({ isTypeCast(node.parent) || isVariableDeclaratorWithTypeAnnotation(node.parent) || isClassPropertyWithTypeAnnotation(node.parent) || - isPropertyOfObjectWithType(node.parent) + isPropertyOfObjectWithType(node.parent) || + isFunctionArgument(node.parent, node) ) { return; } diff --git a/packages/eslint-plugin/tests/rules/explicit-function-return-type.test.ts b/packages/eslint-plugin/tests/rules/explicit-function-return-type.test.ts index 1b9209b7abf..eb67f620be1 100644 --- a/packages/eslint-plugin/tests/rules/explicit-function-return-type.test.ts +++ b/packages/eslint-plugin/tests/rules/explicit-function-return-type.test.ts @@ -245,6 +245,42 @@ function FunctionDeclaration() { `, options: [{ allowHigherOrderFunctions: true }], }, + // https://github.com/typescript-eslint/typescript-eslint/issues/679 + { + filename: 'test.ts', + code: ` +declare function foo(arg: () => void): void +foo(() => 1) +foo(() => {}) +foo(() => null) +foo(() => true) +foo(() => '') + `, + options: [ + { + allowTypedFunctionExpressions: true, + }, + ], + }, + { + filename: 'test.ts', + code: ` +class Accumulator { + private count: number = 0; + + public accumulate(fn: () => number): void { + this.count += fn(); + } +} + +new Accumulator().accumulate(() => 1); + `, + options: [ + { + allowTypedFunctionExpressions: true, + }, + ], + }, ], invalid: [ { @@ -550,5 +586,88 @@ function FunctionDeclaration() { }, ], }, + // https://github.com/typescript-eslint/typescript-eslint/issues/679 + { + filename: 'test.ts', + code: ` +declare function foo(arg: () => void): void +foo(() => 1) +foo(() => {}) +foo(() => null) +foo(() => true) +foo(() => '') + `, + options: [ + { + allowTypedFunctionExpressions: false, + }, + ], + errors: [ + { + messageId: 'missingReturnType', + line: 3, + }, + { + messageId: 'missingReturnType', + line: 4, + }, + { + messageId: 'missingReturnType', + line: 5, + }, + { + messageId: 'missingReturnType', + line: 6, + }, + { + messageId: 'missingReturnType', + line: 7, + }, + ], + }, + { + filename: 'test.ts', + code: ` +class Accumulator { + private count: number = 0; + + public accumulate(fn: () => number): void { + this.count += fn(); + } +} + +new Accumulator().accumulate(() => 1); + `, + options: [ + { + allowTypedFunctionExpressions: false, + }, + ], + errors: [ + { + messageId: 'missingReturnType', + line: 10, + column: 30, + }, + ], + }, + { + filename: 'test.ts', + code: ` +(() => true)() + `, + options: [ + { + allowTypedFunctionExpressions: false, + }, + ], + errors: [ + { + messageId: 'missingReturnType', + line: 2, + column: 2, + }, + ], + }, ], }); From b30e78d894806638417cd99c6d3fe4a74cbde7ec Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Thu, 11 Jul 2019 08:03:56 -0700 Subject: [PATCH 3/8] chore(deps): bump lodash.template from 4.4.0 to 4.5.0 (#693) Bumps [lodash.template](https://github.com/lodash/lodash) from 4.4.0 to 4.5.0. - [Release notes](https://github.com/lodash/lodash/releases) - [Commits](https://github.com/lodash/lodash/compare/4.4.0...4.5.0) Signed-off-by: dependabot[bot] --- yarn.lock | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/yarn.lock b/yarn.lock index 53025c9063a..c6bebb98da3 100644 --- a/yarn.lock +++ b/yarn.lock @@ -4712,7 +4712,7 @@ locate-path@^3.0.0: p-locate "^3.0.0" path-exists "^3.0.0" -lodash._reinterpolate@~3.0.0: +lodash._reinterpolate@^3.0.0: version "3.0.0" resolved "https://registry.yarnpkg.com/lodash._reinterpolate/-/lodash._reinterpolate-3.0.0.tgz#0ccf2d89166af03b3663c796538b75ac6e114d9d" integrity sha1-DM8tiRZq8Ds2Y8eWU4t1rG4RTZ0= @@ -4758,19 +4758,19 @@ lodash.sortby@^4.7.0: integrity sha1-7dFMgk4sycHgsKG0K7UhBRakJDg= lodash.template@^4.0.2: - version "4.4.0" - resolved "https://registry.yarnpkg.com/lodash.template/-/lodash.template-4.4.0.tgz#e73a0385c8355591746e020b99679c690e68fba0" - integrity sha1-5zoDhcg1VZF0bgILmWecaQ5o+6A= + version "4.5.0" + resolved "https://registry.yarnpkg.com/lodash.template/-/lodash.template-4.5.0.tgz#f976195cf3f347d0d5f52483569fe8031ccce8ab" + integrity sha512-84vYFxIkmidUiFxidA/KjjH9pAycqW+h980j7Fuz5qxRtO9pgB7MDFTdys1N7A5mcucRiDyEq4fusljItR1T/A== dependencies: - lodash._reinterpolate "~3.0.0" + lodash._reinterpolate "^3.0.0" lodash.templatesettings "^4.0.0" lodash.templatesettings@^4.0.0: - version "4.1.0" - resolved "https://registry.yarnpkg.com/lodash.templatesettings/-/lodash.templatesettings-4.1.0.tgz#2b4d4e95ba440d915ff08bc899e4553666713316" - integrity sha1-K01OlbpEDZFf8IvImeRVNmZxMxY= + version "4.2.0" + resolved "https://registry.yarnpkg.com/lodash.templatesettings/-/lodash.templatesettings-4.2.0.tgz#e481310f049d3cf6d47e912ad09313b154f0fb33" + integrity sha512-stgLz+i3Aa9mZgnjr/O+v9ruKZsPsndy7qPZOchbqk2cnTU1ZaldKK+v7m54WoKIyxiuMZTKT2H81F8BeAc3ZQ== dependencies: - lodash._reinterpolate "~3.0.0" + lodash._reinterpolate "^3.0.0" lodash.unescape@4.0.1: version "4.0.1" From cd96c3875e90580c67023d2483c44da76a572eec Mon Sep 17 00:00:00 2001 From: James Henry Date: Fri, 12 Jul 2019 12:52:29 +0000 Subject: [PATCH 4/8] chore: publish v1.12.0 --- CHANGELOG.md | 22 ++++++++++++++++++++++ lerna.json | 2 +- packages/eslint-plugin-tslint/CHANGELOG.md | 11 +++++++++++ packages/eslint-plugin-tslint/package.json | 6 +++--- packages/eslint-plugin/CHANGELOG.md | 21 +++++++++++++++++++++ packages/eslint-plugin/package.json | 4 ++-- packages/experimental-utils/CHANGELOG.md | 8 ++++++++ packages/experimental-utils/package.json | 4 ++-- packages/parser/CHANGELOG.md | 11 +++++++++++ packages/parser/package.json | 8 ++++---- packages/shared-fixtures/CHANGELOG.md | 11 +++++++++++ packages/shared-fixtures/package.json | 2 +- packages/typescript-estree/CHANGELOG.md | 17 +++++++++++++++++ packages/typescript-estree/package.json | 4 ++-- 14 files changed, 116 insertions(+), 15 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 36abcf4782d..f2df49f1cc6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,28 @@ All notable changes to this project will be documented in this file. See [Conventional Commits](https://conventionalcommits.org) for commit guidelines. +# [1.12.0](https://github.com/typescript-eslint/typescript-eslint/compare/v1.11.0...v1.12.0) (2019-07-12) + + +### Bug Fixes + +* **eslint-plugin:** handle `const;` ([#633](https://github.com/typescript-eslint/typescript-eslint/issues/633)) ([430d628](https://github.com/typescript-eslint/typescript-eslint/commit/430d628)), closes [#441](https://github.com/typescript-eslint/typescript-eslint/issues/441) +* **typescript-estree:** fix `async` identifier token typed as `Keyword` ([#681](https://github.com/typescript-eslint/typescript-eslint/issues/681)) ([6de19d3](https://github.com/typescript-eslint/typescript-eslint/commit/6de19d3)) + + +### Features + +* **eslint-plugin:** [ban-types] Support namespaced type ([#616](https://github.com/typescript-eslint/typescript-eslint/issues/616)) ([e325b72](https://github.com/typescript-eslint/typescript-eslint/commit/e325b72)) +* **eslint-plugin:** [explicit-function-return-type] add handling for usage as arguments ([#680](https://github.com/typescript-eslint/typescript-eslint/issues/680)) ([e0aeb18](https://github.com/typescript-eslint/typescript-eslint/commit/e0aeb18)) +* **eslint-plugin:** [no-explicit-any] Add an optional fixer ([#609](https://github.com/typescript-eslint/typescript-eslint/issues/609)) ([606fc70](https://github.com/typescript-eslint/typescript-eslint/commit/606fc70)) +* **eslint-plugin:** Add rule no-reference-import ([#625](https://github.com/typescript-eslint/typescript-eslint/issues/625)) ([af70a59](https://github.com/typescript-eslint/typescript-eslint/commit/af70a59)) +* **eslint-plugin:** add rule strict-boolean-expressions ([#579](https://github.com/typescript-eslint/typescript-eslint/issues/579)) ([34e7d1e](https://github.com/typescript-eslint/typescript-eslint/commit/34e7d1e)) +* **eslint-plugin:** added new rule prefer-readonly ([#555](https://github.com/typescript-eslint/typescript-eslint/issues/555)) ([76b89a5](https://github.com/typescript-eslint/typescript-eslint/commit/76b89a5)) + + + + + # [1.11.0](https://github.com/typescript-eslint/typescript-eslint/compare/v1.10.2...v1.11.0) (2019-06-23) diff --git a/lerna.json b/lerna.json index b1a0c8942fb..d494e08b3c9 100644 --- a/lerna.json +++ b/lerna.json @@ -1,5 +1,5 @@ { - "version": "1.11.0", + "version": "1.12.0", "npmClient": "yarn", "useWorkspaces": true, "stream": true diff --git a/packages/eslint-plugin-tslint/CHANGELOG.md b/packages/eslint-plugin-tslint/CHANGELOG.md index 26731119b1d..c0e725bdfcb 100644 --- a/packages/eslint-plugin-tslint/CHANGELOG.md +++ b/packages/eslint-plugin-tslint/CHANGELOG.md @@ -3,6 +3,17 @@ All notable changes to this project will be documented in this file. See [Conventional Commits](https://conventionalcommits.org) for commit guidelines. +# [1.12.0](https://github.com/typescript-eslint/typescript-eslint/compare/v1.11.0...v1.12.0) (2019-07-12) + + +### Features + +* **eslint-plugin:** added new rule prefer-readonly ([#555](https://github.com/typescript-eslint/typescript-eslint/issues/555)) ([76b89a5](https://github.com/typescript-eslint/typescript-eslint/commit/76b89a5)) + + + + + # [1.11.0](https://github.com/typescript-eslint/typescript-eslint/compare/v1.10.2...v1.11.0) (2019-06-23) **Note:** Version bump only for package @typescript-eslint/eslint-plugin-tslint diff --git a/packages/eslint-plugin-tslint/package.json b/packages/eslint-plugin-tslint/package.json index d62e4996099..f370f0c5847 100644 --- a/packages/eslint-plugin-tslint/package.json +++ b/packages/eslint-plugin-tslint/package.json @@ -1,6 +1,6 @@ { "name": "@typescript-eslint/eslint-plugin-tslint", - "version": "1.11.0", + "version": "1.12.0", "main": "dist/index.js", "typings": "src/index.ts", "description": "TSLint wrapper plugin for ESLint", @@ -31,7 +31,7 @@ "typecheck": "tsc --noEmit" }, "dependencies": { - "@typescript-eslint/experimental-utils": "1.11.0", + "@typescript-eslint/experimental-utils": "1.12.0", "lodash.memoize": "^4.1.2" }, "peerDependencies": { @@ -41,6 +41,6 @@ "devDependencies": { "@types/json-schema": "^7.0.3", "@types/lodash.memoize": "^4.1.4", - "@typescript-eslint/parser": "1.11.0" + "@typescript-eslint/parser": "1.12.0" } } diff --git a/packages/eslint-plugin/CHANGELOG.md b/packages/eslint-plugin/CHANGELOG.md index 497ba5cb783..e5a04d77763 100644 --- a/packages/eslint-plugin/CHANGELOG.md +++ b/packages/eslint-plugin/CHANGELOG.md @@ -3,6 +3,27 @@ All notable changes to this project will be documented in this file. See [Conventional Commits](https://conventionalcommits.org) for commit guidelines. +# [1.12.0](https://github.com/typescript-eslint/typescript-eslint/compare/v1.11.0...v1.12.0) (2019-07-12) + + +### Bug Fixes + +* **eslint-plugin:** handle `const;` ([#633](https://github.com/typescript-eslint/typescript-eslint/issues/633)) ([430d628](https://github.com/typescript-eslint/typescript-eslint/commit/430d628)), closes [#441](https://github.com/typescript-eslint/typescript-eslint/issues/441) + + +### Features + +* **eslint-plugin:** [ban-types] Support namespaced type ([#616](https://github.com/typescript-eslint/typescript-eslint/issues/616)) ([e325b72](https://github.com/typescript-eslint/typescript-eslint/commit/e325b72)) +* **eslint-plugin:** [explicit-function-return-type] add handling for usage as arguments ([#680](https://github.com/typescript-eslint/typescript-eslint/issues/680)) ([e0aeb18](https://github.com/typescript-eslint/typescript-eslint/commit/e0aeb18)) +* **eslint-plugin:** [no-explicit-any] Add an optional fixer ([#609](https://github.com/typescript-eslint/typescript-eslint/issues/609)) ([606fc70](https://github.com/typescript-eslint/typescript-eslint/commit/606fc70)) +* **eslint-plugin:** Add rule no-reference-import ([#625](https://github.com/typescript-eslint/typescript-eslint/issues/625)) ([af70a59](https://github.com/typescript-eslint/typescript-eslint/commit/af70a59)) +* **eslint-plugin:** add rule strict-boolean-expressions ([#579](https://github.com/typescript-eslint/typescript-eslint/issues/579)) ([34e7d1e](https://github.com/typescript-eslint/typescript-eslint/commit/34e7d1e)) +* **eslint-plugin:** added new rule prefer-readonly ([#555](https://github.com/typescript-eslint/typescript-eslint/issues/555)) ([76b89a5](https://github.com/typescript-eslint/typescript-eslint/commit/76b89a5)) + + + + + # [1.11.0](https://github.com/typescript-eslint/typescript-eslint/compare/v1.10.2...v1.11.0) (2019-06-23) diff --git a/packages/eslint-plugin/package.json b/packages/eslint-plugin/package.json index d530f86a12b..28dcc098a7f 100644 --- a/packages/eslint-plugin/package.json +++ b/packages/eslint-plugin/package.json @@ -1,6 +1,6 @@ { "name": "@typescript-eslint/eslint-plugin", - "version": "1.11.0", + "version": "1.12.0", "description": "TypeScript plugin for ESLint", "keywords": [ "eslint", @@ -41,7 +41,7 @@ "typecheck": "tsc --noEmit" }, "dependencies": { - "@typescript-eslint/experimental-utils": "1.11.0", + "@typescript-eslint/experimental-utils": "1.12.0", "eslint-utils": "^1.3.1", "functional-red-black-tree": "^1.0.1", "regexpp": "^2.0.1", diff --git a/packages/experimental-utils/CHANGELOG.md b/packages/experimental-utils/CHANGELOG.md index 0726874992f..40646cc4204 100644 --- a/packages/experimental-utils/CHANGELOG.md +++ b/packages/experimental-utils/CHANGELOG.md @@ -3,6 +3,14 @@ All notable changes to this project will be documented in this file. See [Conventional Commits](https://conventionalcommits.org) for commit guidelines. +# [1.12.0](https://github.com/typescript-eslint/typescript-eslint/compare/v1.11.0...v1.12.0) (2019-07-12) + +**Note:** Version bump only for package @typescript-eslint/experimental-utils + + + + + # [1.11.0](https://github.com/typescript-eslint/typescript-eslint/compare/v1.10.2...v1.11.0) (2019-06-23) diff --git a/packages/experimental-utils/package.json b/packages/experimental-utils/package.json index fa86431a8e0..d0a85ed8a90 100644 --- a/packages/experimental-utils/package.json +++ b/packages/experimental-utils/package.json @@ -1,6 +1,6 @@ { "name": "@typescript-eslint/experimental-utils", - "version": "1.11.0", + "version": "1.12.0", "description": "(Experimental) Utilities for working with TypeScript + ESLint together", "keywords": [ "eslint", @@ -36,7 +36,7 @@ "typecheck": "tsc --noEmit" }, "dependencies": { - "@typescript-eslint/typescript-estree": "1.11.0", + "@typescript-eslint/typescript-estree": "1.12.0", "eslint-scope": "^4.0.0" }, "peerDependencies": { diff --git a/packages/parser/CHANGELOG.md b/packages/parser/CHANGELOG.md index 3ed7f17edcf..78926d846a9 100644 --- a/packages/parser/CHANGELOG.md +++ b/packages/parser/CHANGELOG.md @@ -3,6 +3,17 @@ All notable changes to this project will be documented in this file. See [Conventional Commits](https://conventionalcommits.org) for commit guidelines. +# [1.12.0](https://github.com/typescript-eslint/typescript-eslint/compare/v1.11.0...v1.12.0) (2019-07-12) + + +### Bug Fixes + +* **typescript-estree:** fix `async` identifier token typed as `Keyword` ([#681](https://github.com/typescript-eslint/typescript-eslint/issues/681)) ([6de19d3](https://github.com/typescript-eslint/typescript-eslint/commit/6de19d3)) + + + + + # [1.11.0](https://github.com/typescript-eslint/typescript-eslint/compare/v1.10.2...v1.11.0) (2019-06-23) diff --git a/packages/parser/package.json b/packages/parser/package.json index e683453843b..cc6b85720b0 100644 --- a/packages/parser/package.json +++ b/packages/parser/package.json @@ -1,6 +1,6 @@ { "name": "@typescript-eslint/parser", - "version": "1.11.0", + "version": "1.12.0", "description": "An ESLint custom parser which leverages TypeScript ESTree", "main": "dist/parser.js", "files": [ @@ -42,11 +42,11 @@ }, "dependencies": { "@types/eslint-visitor-keys": "^1.0.0", - "@typescript-eslint/experimental-utils": "1.11.0", - "@typescript-eslint/typescript-estree": "1.11.0", + "@typescript-eslint/experimental-utils": "1.12.0", + "@typescript-eslint/typescript-estree": "1.12.0", "eslint-visitor-keys": "^1.0.0" }, "devDependencies": { - "@typescript-eslint/shared-fixtures": "1.11.0" + "@typescript-eslint/shared-fixtures": "1.12.0" } } diff --git a/packages/shared-fixtures/CHANGELOG.md b/packages/shared-fixtures/CHANGELOG.md index 9cdeac70951..06c3ba92d00 100644 --- a/packages/shared-fixtures/CHANGELOG.md +++ b/packages/shared-fixtures/CHANGELOG.md @@ -3,6 +3,17 @@ All notable changes to this project will be documented in this file. See [Conventional Commits](https://conventionalcommits.org) for commit guidelines. +# [1.12.0](https://github.com/typescript-eslint/typescript-eslint/compare/v1.11.0...v1.12.0) (2019-07-12) + + +### Bug Fixes + +* **typescript-estree:** fix `async` identifier token typed as `Keyword` ([#681](https://github.com/typescript-eslint/typescript-eslint/issues/681)) ([6de19d3](https://github.com/typescript-eslint/typescript-eslint/commit/6de19d3)) + + + + + # [1.11.0](https://github.com/typescript-eslint/typescript-eslint/compare/v1.10.2...v1.11.0) (2019-06-23) diff --git a/packages/shared-fixtures/package.json b/packages/shared-fixtures/package.json index 28caabd65f4..080975e7bb2 100644 --- a/packages/shared-fixtures/package.json +++ b/packages/shared-fixtures/package.json @@ -1,5 +1,5 @@ { "name": "@typescript-eslint/shared-fixtures", - "version": "1.11.0", + "version": "1.12.0", "private": true } diff --git a/packages/typescript-estree/CHANGELOG.md b/packages/typescript-estree/CHANGELOG.md index 4f3c7cd4956..183ff3c672d 100644 --- a/packages/typescript-estree/CHANGELOG.md +++ b/packages/typescript-estree/CHANGELOG.md @@ -3,6 +3,23 @@ All notable changes to this project will be documented in this file. See [Conventional Commits](https://conventionalcommits.org) for commit guidelines. +# [1.12.0](https://github.com/typescript-eslint/typescript-eslint/compare/v1.11.0...v1.12.0) (2019-07-12) + + +### Bug Fixes + +* **eslint-plugin:** handle `const;` ([#633](https://github.com/typescript-eslint/typescript-eslint/issues/633)) ([430d628](https://github.com/typescript-eslint/typescript-eslint/commit/430d628)), closes [#441](https://github.com/typescript-eslint/typescript-eslint/issues/441) +* **typescript-estree:** fix `async` identifier token typed as `Keyword` ([#681](https://github.com/typescript-eslint/typescript-eslint/issues/681)) ([6de19d3](https://github.com/typescript-eslint/typescript-eslint/commit/6de19d3)) + + +### Features + +* **eslint-plugin:** added new rule prefer-readonly ([#555](https://github.com/typescript-eslint/typescript-eslint/issues/555)) ([76b89a5](https://github.com/typescript-eslint/typescript-eslint/commit/76b89a5)) + + + + + # [1.11.0](https://github.com/typescript-eslint/typescript-eslint/compare/v1.10.2...v1.11.0) (2019-06-23) diff --git a/packages/typescript-estree/package.json b/packages/typescript-estree/package.json index 61ccbddf858..33079d27f03 100644 --- a/packages/typescript-estree/package.json +++ b/packages/typescript-estree/package.json @@ -1,6 +1,6 @@ { "name": "@typescript-eslint/typescript-estree", - "version": "1.11.0", + "version": "1.12.0", "description": "A parser that converts TypeScript source code into an ESTree compatible form", "main": "dist/parser.js", "types": "dist/parser.d.ts", @@ -46,6 +46,6 @@ }, "devDependencies": { "@babel/types": "^7.3.2", - "@typescript-eslint/shared-fixtures": "1.11.0" + "@typescript-eslint/shared-fixtures": "1.12.0" } } From a5398ce9a071c83d47c88456224f4cd419f081cc Mon Sep 17 00:00:00 2001 From: Brad Zacher Date: Fri, 12 Jul 2019 08:55:29 -0700 Subject: [PATCH 5/8] fix: Correct `@types/json-schema` dependency (#675) --- packages/eslint-plugin-tslint/package.json | 1 - packages/eslint-plugin/package.json | 1 + packages/experimental-utils/package.json | 1 + 3 files changed, 2 insertions(+), 1 deletion(-) diff --git a/packages/eslint-plugin-tslint/package.json b/packages/eslint-plugin-tslint/package.json index f370f0c5847..d541fe3a64f 100644 --- a/packages/eslint-plugin-tslint/package.json +++ b/packages/eslint-plugin-tslint/package.json @@ -39,7 +39,6 @@ "tslint": "^5.0.0" }, "devDependencies": { - "@types/json-schema": "^7.0.3", "@types/lodash.memoize": "^4.1.4", "@typescript-eslint/parser": "1.12.0" } diff --git a/packages/eslint-plugin/package.json b/packages/eslint-plugin/package.json index 28dcc098a7f..d9b6ea316b4 100644 --- a/packages/eslint-plugin/package.json +++ b/packages/eslint-plugin/package.json @@ -48,6 +48,7 @@ "tsutils": "^3.7.0" }, "devDependencies": { + "@types/json-schema": "^7.0.3", "@types/marked": "^0.6.5", "chalk": "^2.4.2", "marked": "^0.6.2" diff --git a/packages/experimental-utils/package.json b/packages/experimental-utils/package.json index d0a85ed8a90..1965dd8bae4 100644 --- a/packages/experimental-utils/package.json +++ b/packages/experimental-utils/package.json @@ -36,6 +36,7 @@ "typecheck": "tsc --noEmit" }, "dependencies": { + "@types/json-schema": "^7.0.3", "@typescript-eslint/typescript-estree": "1.12.0", "eslint-scope": "^4.0.0" }, From c2ad091c2a91349c0db1991925f5f3098b942d58 Mon Sep 17 00:00:00 2001 From: Brad Zacher Date: Fri, 12 Jul 2019 09:57:08 -0700 Subject: [PATCH 6/8] chore(eslint-plugin): add config validation script to CI (#649) * chore(eslint-plugin): add config validation script to CI * chore: correct docs --- azure-pipelines.yml | 6 +++- package.json | 3 +- packages/eslint-plugin/README.md | 3 +- packages/eslint-plugin/package.json | 5 ++- packages/eslint-plugin/src/configs/all.json | 1 + .../src/rules/consistent-type-definitions.ts | 2 +- .../tools/{validate-docs => }/log.ts | 0 .../tools/validate-configs/checkConfigAll.ts | 35 +++++++++++++++++++ .../checkConfigRecommended.ts | 35 +++++++++++++++++++ .../tools/validate-configs/index.ts | 22 ++++++++++++ .../validate-docs/check-for-rule-docs.ts | 2 +- .../validate-docs/validate-table-rules.ts | 2 +- .../validate-docs/validate-table-structure.ts | 2 +- 13 files changed, 107 insertions(+), 11 deletions(-) rename packages/eslint-plugin/tools/{validate-docs => }/log.ts (100%) create mode 100644 packages/eslint-plugin/tools/validate-configs/checkConfigAll.ts create mode 100644 packages/eslint-plugin/tools/validate-configs/checkConfigRecommended.ts create mode 100644 packages/eslint-plugin/tools/validate-configs/index.ts diff --git a/azure-pipelines.yml b/azure-pipelines.yml index 8dcbd9ea422..68b6badba15 100644 --- a/azure-pipelines.yml +++ b/azure-pipelines.yml @@ -32,9 +32,13 @@ jobs: displayName: 'Run linting' - script: | - yarn docs:check + yarn check:docs displayName: 'Validate documentation' + - script: | + yarn check:configs + displayName: 'Validate plugin configs' + - script: | yarn test displayName: 'Run unit tests' diff --git a/package.json b/package.json index 2f0d94d38bd..4b199bff017 100644 --- a/package.json +++ b/package.json @@ -20,7 +20,8 @@ "build": "lerna run build", "clean": "lerna clean && lerna run clean", "cz": "git-cz", - "docs:check": "lerna run docs:check", + "check:docs": "lerna run check:docs", + "check:configs": "lerna run check:configs", "generate-contributors": "yarn ts-node ./tools/generate-contributors.ts && yarn all-contributors generate", "format": "prettier --write \"./**/*.{ts,js,json,md}\"", "format-check": "prettier --list-different \"./**/*.{ts,js,json,md}\"", diff --git a/packages/eslint-plugin/README.md b/packages/eslint-plugin/README.md index c436e32be6c..e958c1a01f2 100644 --- a/packages/eslint-plugin/README.md +++ b/packages/eslint-plugin/README.md @@ -116,7 +116,6 @@ Then you should add `airbnb` (or `airbnb-base`) to your `extends` section of `.e ## Supported Rules - **Key**: :heavy_check_mark: = recommended, :wrench: = fixable, :thought_balloon: = requires type information @@ -131,7 +130,7 @@ Then you should add `airbnb` (or `airbnb-base`) to your `extends` section of `.e | [`@typescript-eslint/ban-types`](./docs/rules/ban-types.md) | Enforces that types will not to be used | :heavy_check_mark: | :wrench: | | | [`@typescript-eslint/camelcase`](./docs/rules/camelcase.md) | Enforce camelCase naming convention | :heavy_check_mark: | | | | [`@typescript-eslint/class-name-casing`](./docs/rules/class-name-casing.md) | Require PascalCased class and interface names | :heavy_check_mark: | | | -| [`@typescript-eslint/consistent-type-definitions`](./docs/rules/consistent-type-definitions.md) | Consistent with type definition either `interface` or `type` | :heavy_check_mark: | :wrench: | | +| [`@typescript-eslint/consistent-type-definitions`](./docs/rules/consistent-type-definitions.md) | Consistent with type definition either `interface` or `type` | | :wrench: | | | [`@typescript-eslint/explicit-function-return-type`](./docs/rules/explicit-function-return-type.md) | Require explicit return types on functions and class methods | :heavy_check_mark: | | | | [`@typescript-eslint/explicit-member-accessibility`](./docs/rules/explicit-member-accessibility.md) | Require explicit accessibility modifiers on class properties and methods | :heavy_check_mark: | | | | [`@typescript-eslint/func-call-spacing`](./docs/rules/func-call-spacing.md) | Require or disallow spacing between function identifiers and their invocations | | :wrench: | | diff --git a/packages/eslint-plugin/package.json b/packages/eslint-plugin/package.json index d9b6ea316b4..499ebfca95f 100644 --- a/packages/eslint-plugin/package.json +++ b/packages/eslint-plugin/package.json @@ -30,13 +30,12 @@ "main": "dist/index.js", "scripts": { "build": "tsc -p tsconfig.build.json", + "check:docs": "ts-node --files ./tools/validate-docs/index.ts", + "check:configs": "ts-node --files ./tools/validate-configs/index.ts", "clean": "rimraf dist/", - "docs": "eslint-docs", - "docs:check": "ts-node --files ./tools/validate-docs/index.ts", "format": "prettier --write \"./**/*.{ts,js,json,md}\" --ignore-path ../../.prettierignore", "generate:configs": "ts-node --files tools/generate-configs.ts", "prebuild": "npm run clean", - "recommended:update": "ts-node tools/update-recommended.ts", "test": "jest --coverage", "typecheck": "tsc --noEmit" }, diff --git a/packages/eslint-plugin/src/configs/all.json b/packages/eslint-plugin/src/configs/all.json index cd5b2bb9cbe..5fd043c4c11 100644 --- a/packages/eslint-plugin/src/configs/all.json +++ b/packages/eslint-plugin/src/configs/all.json @@ -64,6 +64,7 @@ "@typescript-eslint/restrict-plus-operands": "error", "semi": "off", "@typescript-eslint/semi": "error", + "@typescript-eslint/strict-boolean-expressions": "error", "@typescript-eslint/triple-slash-reference": "error", "@typescript-eslint/type-annotation-spacing": "error", "@typescript-eslint/unbound-method": "error", diff --git a/packages/eslint-plugin/src/rules/consistent-type-definitions.ts b/packages/eslint-plugin/src/rules/consistent-type-definitions.ts index eea12b9cf84..01fa92dd3d0 100644 --- a/packages/eslint-plugin/src/rules/consistent-type-definitions.ts +++ b/packages/eslint-plugin/src/rules/consistent-type-definitions.ts @@ -9,7 +9,7 @@ export default util.createRule({ description: 'Consistent with type definition either `interface` or `type`', category: 'Stylistic Issues', - recommended: 'error', + recommended: false, }, messages: { interfaceOverType: 'Use an `interface` instead of a `type`', diff --git a/packages/eslint-plugin/tools/validate-docs/log.ts b/packages/eslint-plugin/tools/log.ts similarity index 100% rename from packages/eslint-plugin/tools/validate-docs/log.ts rename to packages/eslint-plugin/tools/log.ts diff --git a/packages/eslint-plugin/tools/validate-configs/checkConfigAll.ts b/packages/eslint-plugin/tools/validate-configs/checkConfigAll.ts new file mode 100644 index 00000000000..84981b8816e --- /dev/null +++ b/packages/eslint-plugin/tools/validate-configs/checkConfigAll.ts @@ -0,0 +1,35 @@ +import plugin from '../../src/index'; +import { logRule } from '../log'; + +const prefix = '@typescript-eslint/'; + +function checkConfigAll() { + const { rules } = plugin; + + const all = plugin.configs.all.rules; + const allNames = new Set(Object.keys(all)); + + return Object.entries(rules).reduce((acc, [ruleName, rule]) => { + if (!rule.meta.deprecated) { + const prefixed = `${prefix}${ruleName}` as keyof typeof all; + if (allNames.has(prefixed)) { + if (all[prefixed] !== 'error') { + logRule( + false, + ruleName, + 'incorrect setting compared to the rule meta.', + ); + return true; + } + } else { + logRule(false, ruleName, 'missing in the config.'); + return true; + } + } + + logRule(true, ruleName); + return acc; + }, false); +} + +export { checkConfigAll }; diff --git a/packages/eslint-plugin/tools/validate-configs/checkConfigRecommended.ts b/packages/eslint-plugin/tools/validate-configs/checkConfigRecommended.ts new file mode 100644 index 00000000000..21f2faa876d --- /dev/null +++ b/packages/eslint-plugin/tools/validate-configs/checkConfigRecommended.ts @@ -0,0 +1,35 @@ +import plugin from '../../src/index'; +import { logRule } from '../log'; + +const prefix = '@typescript-eslint/'; + +function checkConfigRecommended() { + const { rules } = plugin; + + const recommended = plugin.configs.recommended.rules; + const recommendedNames = new Set(Object.keys(recommended)); + + return Object.entries(rules).reduce((acc, [ruleName, rule]) => { + if (!rule.meta.deprecated && rule.meta.docs.recommended !== false) { + const prefixed = `${prefix}${ruleName}` as keyof typeof recommended; + if (recommendedNames.has(prefixed)) { + if (recommended[prefixed] !== rule.meta.docs.recommended) { + logRule( + false, + ruleName, + 'incorrect setting compared to the rule meta.', + ); + return true; + } + } else { + logRule(false, ruleName, 'missing in the config.'); + return true; + } + } + + logRule(true, ruleName); + return acc; + }, false); +} + +export { checkConfigRecommended }; diff --git a/packages/eslint-plugin/tools/validate-configs/index.ts b/packages/eslint-plugin/tools/validate-configs/index.ts new file mode 100644 index 00000000000..cb64df53648 --- /dev/null +++ b/packages/eslint-plugin/tools/validate-configs/index.ts @@ -0,0 +1,22 @@ +import chalk from 'chalk'; +import { checkConfigRecommended } from './checkConfigRecommended'; +import { checkConfigAll } from './checkConfigAll'; + +let hasErrors = false; +console.log(chalk.underline('Checking config "recommended"')); +hasErrors = checkConfigRecommended() || hasErrors; + +console.log(); +console.log(chalk.underline('Checking config "all"')); +hasErrors = checkConfigAll() || hasErrors; + +if (hasErrors) { + console.log('\n\n'); + console.error( + chalk.bold.bgRed.white('There were errors found in the configs'), + ); + console.error(`Please run ${chalk.inverse('yarn generate:configs')}`); + console.log('\n\n'); + // eslint-disable-next-line no-process-exit + process.exit(1); +} diff --git a/packages/eslint-plugin/tools/validate-docs/check-for-rule-docs.ts b/packages/eslint-plugin/tools/validate-docs/check-for-rule-docs.ts index eeb67c9d528..158af4513f3 100644 --- a/packages/eslint-plugin/tools/validate-docs/check-for-rule-docs.ts +++ b/packages/eslint-plugin/tools/validate-docs/check-for-rule-docs.ts @@ -1,7 +1,7 @@ import { TSESLint } from '@typescript-eslint/experimental-utils'; import fs from 'fs'; import path from 'path'; -import { logRule } from './log'; +import { logRule } from '../log'; function checkForRuleDocs( rules: Record>>, diff --git a/packages/eslint-plugin/tools/validate-docs/validate-table-rules.ts b/packages/eslint-plugin/tools/validate-docs/validate-table-rules.ts index 1ab532e3160..4e9405a653d 100644 --- a/packages/eslint-plugin/tools/validate-docs/validate-table-rules.ts +++ b/packages/eslint-plugin/tools/validate-docs/validate-table-rules.ts @@ -3,7 +3,7 @@ import chalk from 'chalk'; import fs from 'fs'; import marked from 'marked'; import path from 'path'; -import { logRule } from './log'; +import { logRule } from '../log'; function validateTableRules( rules: Record>>, diff --git a/packages/eslint-plugin/tools/validate-docs/validate-table-structure.ts b/packages/eslint-plugin/tools/validate-docs/validate-table-structure.ts index 02da5a66151..377769741c3 100644 --- a/packages/eslint-plugin/tools/validate-docs/validate-table-structure.ts +++ b/packages/eslint-plugin/tools/validate-docs/validate-table-structure.ts @@ -1,7 +1,7 @@ import { TSESLint } from '@typescript-eslint/experimental-utils'; import chalk from 'chalk'; import marked from 'marked'; -import { logError } from './log'; +import { logError } from '../log'; function validateTableStructure( rules: Record>>, From 9836fb7ac283ac4a7ce66164d7953c82f7580eb0 Mon Sep 17 00:00:00 2001 From: Erik Engervall Date: Sat, 13 Jul 2019 23:53:38 +0200 Subject: [PATCH 7/8] docs: readme typo (#701) --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 6900259d278..eabb3ee2eac 100644 --- a/README.md +++ b/README.md @@ -139,7 +139,7 @@ Babel does now support parsing (but not type-checking) TypeScript source code. T The key trade-off can be summarized as: `babel-eslint` supports additional syntax which TypeScript itself does not, but `typescript-eslint` supports creating rules based on type information, which is not available to babel because there is no type-checker. -Because they are therefore separate projects powered by different underlying tooling, they are currently not intended to be used together. +Because they are separate projects powered by different underlying tooling, they are currently not intended to be used together. Some of the people involved in `typescript-eslint` are also involved in Babel and `babel-eslint`, and in this project we are working hard to align on the AST format for non-standard JavaScript syntax. This is an ongoing effort. From ceb2d32030cfa032613f8b862821421d6979e9dc Mon Sep 17 00:00:00 2001 From: Mike Harder Date: Mon, 15 Jul 2019 21:13:21 -0700 Subject: [PATCH 8/8] fix(eslint-plugin): remove imports from typescript-estree (#706) Fixes #705 --- .../eslint-plugin/src/rules/prefer-readonly.ts | 5 ++++- .../src/rules/prefer-regexp-exec.ts | 2 +- .../src/rules/triple-slash-reference.ts | 17 ++++++----------- 3 files changed, 11 insertions(+), 13 deletions(-) diff --git a/packages/eslint-plugin/src/rules/prefer-readonly.ts b/packages/eslint-plugin/src/rules/prefer-readonly.ts index 24685d30676..c82aaf45ab3 100644 --- a/packages/eslint-plugin/src/rules/prefer-readonly.ts +++ b/packages/eslint-plugin/src/rules/prefer-readonly.ts @@ -2,7 +2,10 @@ import * as tsutils from 'tsutils'; import ts from 'typescript'; import * as util from '../util'; import { typeIsOrHasBaseType } from '../util'; -import { TSESTree, AST_NODE_TYPES } from '@typescript-eslint/typescript-estree'; +import { + TSESTree, + AST_NODE_TYPES, +} from '@typescript-eslint/experimental-utils'; type MessageIds = 'preferReadonly'; diff --git a/packages/eslint-plugin/src/rules/prefer-regexp-exec.ts b/packages/eslint-plugin/src/rules/prefer-regexp-exec.ts index ffcf5aef975..dae7b8f13c1 100644 --- a/packages/eslint-plugin/src/rules/prefer-regexp-exec.ts +++ b/packages/eslint-plugin/src/rules/prefer-regexp-exec.ts @@ -1,4 +1,4 @@ -import { TSESTree } from '@typescript-eslint/typescript-estree'; +import { TSESTree } from '@typescript-eslint/experimental-utils'; import { createRule, getParserServices, getTypeName } from '../util'; import { getStaticValue } from 'eslint-utils'; diff --git a/packages/eslint-plugin/src/rules/triple-slash-reference.ts b/packages/eslint-plugin/src/rules/triple-slash-reference.ts index 286f445c966..906efaa7db8 100644 --- a/packages/eslint-plugin/src/rules/triple-slash-reference.ts +++ b/packages/eslint-plugin/src/rules/triple-slash-reference.ts @@ -1,10 +1,5 @@ import * as util from '../util'; -import { - Literal, - Node, - TSExternalModuleReference, -} from '@typescript-eslint/typescript-estree/dist/ts-estree/ts-estree'; -import { TSESTree } from '@typescript-eslint/typescript-estree'; +import { TSESTree } from '@typescript-eslint/experimental-utils'; type Options = [ { @@ -55,14 +50,14 @@ export default util.createRule({ }, ], create(context, [{ lib, path, types }]) { - let programNode: Node; + let programNode: TSESTree.Node; const sourceCode = context.getSourceCode(); const references: ({ comment: TSESTree.Comment; importName: string; })[] = []; - function hasMatchingReference(source: Literal) { + function hasMatchingReference(source: TSESTree.Literal) { references.forEach(reference => { if (reference.importName === source.value) { context.report({ @@ -78,14 +73,14 @@ export default util.createRule({ return { ImportDeclaration(node) { if (programNode) { - const source = node.source as Literal; + const source = node.source as TSESTree.Literal; hasMatchingReference(source); } }, TSImportEqualsDeclaration(node) { if (programNode) { - const source = (node.moduleReference as TSExternalModuleReference) - .expression as Literal; + const source = (node.moduleReference as TSESTree.TSExternalModuleReference) + .expression as TSESTree.Literal; hasMatchingReference(source); } },