From 4db80066b44f623c6a3a540062973fcaa7e71787 Mon Sep 17 00:00:00 2001 From: Johannes Rieken Date: Mon, 30 Dec 2019 14:08:44 +0100 Subject: [PATCH] use ts-es-tree-typings, support import-equals --- build/lib/eslint/code-import-patterns.js | 2 +- build/lib/eslint/code-import-patterns.ts | 6 +- build/lib/eslint/code-layering.js | 2 +- build/lib/eslint/code-layering.ts | 2 +- .../code-no-nls-in-standalone-editor.js | 2 +- .../code-no-nls-in-standalone-editor.ts | 2 +- build/lib/eslint/code-no-standalone-editor.js | 2 +- build/lib/eslint/code-no-standalone-editor.ts | 2 +- build/lib/eslint/code-translation-remind.js | 2 +- build/lib/eslint/code-translation-remind.ts | 6 +- build/lib/eslint/utils.js | 10 ++- build/lib/eslint/utils.ts | 44 +++++------ build/package.json | 1 + build/yarn.lock | 78 ++++++++++++++++++- 14 files changed, 123 insertions(+), 38 deletions(-) diff --git a/build/lib/eslint/code-import-patterns.js b/build/lib/eslint/code-import-patterns.js index 144f7cc9b62..8292f7d46cf 100644 --- a/build/lib/eslint/code-import-patterns.js +++ b/build/lib/eslint/code-import-patterns.js @@ -47,7 +47,7 @@ module.exports = new class { if (!matched) { // None of the restrictions matched context.report({ - node, + loc: node.loc, messageId: 'badImport', data: { restrictions: restrictions.join(' or ') diff --git a/build/lib/eslint/code-import-patterns.ts b/build/lib/eslint/code-import-patterns.ts index eac15ebfa05..ae29e471080 100644 --- a/build/lib/eslint/code-import-patterns.ts +++ b/build/lib/eslint/code-import-patterns.ts @@ -4,7 +4,7 @@ *--------------------------------------------------------------------------------------------*/ import * as eslint from 'eslint'; -import * as estree from 'estree'; +import { TSESTree } from '@typescript-eslint/experimental-utils'; import { join } from 'path'; import * as minimatch from 'minimatch'; import { createImportRuleListener } from './utils'; @@ -37,7 +37,7 @@ export = new class implements eslint.Rule.RuleModule { return {}; } - private _checkImport(context: eslint.Rule.RuleContext, config: ImportPatternsConfig, node: estree.Node, path: string) { + private _checkImport(context: eslint.Rule.RuleContext, config: ImportPatternsConfig, node: TSESTree.Node, path: string) { // resolve relative paths if (path[0] === '.') { @@ -62,7 +62,7 @@ export = new class implements eslint.Rule.RuleModule { if (!matched) { // None of the restrictions matched context.report({ - node, + loc: node.loc, messageId: 'badImport', data: { restrictions: restrictions.join(' or ') diff --git a/build/lib/eslint/code-layering.js b/build/lib/eslint/code-layering.js index a033ca96c04..8c1ce8f80c4 100644 --- a/build/lib/eslint/code-layering.js +++ b/build/lib/eslint/code-layering.js @@ -52,7 +52,7 @@ module.exports = new class { if (config.disallowed.has(part)) { // BAD - wrong layer context.report({ - node, + loc: node.loc, messageId: 'layerbreaker', data: { from: part, diff --git a/build/lib/eslint/code-layering.ts b/build/lib/eslint/code-layering.ts index 83775e9adbd..539d13f79f1 100644 --- a/build/lib/eslint/code-layering.ts +++ b/build/lib/eslint/code-layering.ts @@ -66,7 +66,7 @@ export = new class implements eslint.Rule.RuleModule { if (config!.disallowed.has(part)) { // BAD - wrong layer context.report({ - node, + loc: node.loc, messageId: 'layerbreaker', data: { from: part, diff --git a/build/lib/eslint/code-no-nls-in-standalone-editor.js b/build/lib/eslint/code-no-nls-in-standalone-editor.js index 176c0250a07..735b87c3961 100644 --- a/build/lib/eslint/code-no-nls-in-standalone-editor.js +++ b/build/lib/eslint/code-no-nls-in-standalone-editor.js @@ -29,7 +29,7 @@ module.exports = new class NoNlsInStandaloneEditorRule { } if (/vs(\/|\\)nls/.test(path)) { context.report({ - node, + loc: node.loc, messageId: 'noNls' }); } diff --git a/build/lib/eslint/code-no-nls-in-standalone-editor.ts b/build/lib/eslint/code-no-nls-in-standalone-editor.ts index 4bf0495853f..69063fe5842 100644 --- a/build/lib/eslint/code-no-nls-in-standalone-editor.ts +++ b/build/lib/eslint/code-no-nls-in-standalone-editor.ts @@ -37,7 +37,7 @@ export = new class NoNlsInStandaloneEditorRule implements eslint.Rule.RuleModule /vs(\/|\\)nls/.test(path) ) { context.report({ - node, + loc: node.loc, messageId: 'noNls' }); } diff --git a/build/lib/eslint/code-no-standalone-editor.js b/build/lib/eslint/code-no-standalone-editor.js index 576bc60f580..617b2483dd1 100644 --- a/build/lib/eslint/code-no-standalone-editor.js +++ b/build/lib/eslint/code-no-standalone-editor.js @@ -31,7 +31,7 @@ module.exports = new class NoNlsInStandaloneEditorRule { || /vs(\/|\\)editor(\/|\\)editor.main/.test(path) || /vs(\/|\\)editor(\/|\\)editor.worker/.test(path)) { context.report({ - node, + loc: node.loc, messageId: 'badImport' }); } diff --git a/build/lib/eslint/code-no-standalone-editor.ts b/build/lib/eslint/code-no-standalone-editor.ts index 5d42c826644..52fbbea043f 100644 --- a/build/lib/eslint/code-no-standalone-editor.ts +++ b/build/lib/eslint/code-no-standalone-editor.ts @@ -39,7 +39,7 @@ export = new class NoNlsInStandaloneEditorRule implements eslint.Rule.RuleModule || /vs(\/|\\)editor(\/|\\)editor.worker/.test(path) ) { context.report({ - node, + loc: node.loc, messageId: 'badImport' }); } diff --git a/build/lib/eslint/code-translation-remind.js b/build/lib/eslint/code-translation-remind.js index 1f181d88848..34071d76ef0 100644 --- a/build/lib/eslint/code-translation-remind.js +++ b/build/lib/eslint/code-translation-remind.js @@ -48,7 +48,7 @@ module.exports = new (_a = class TranslationRemind { }); if (!resourceDefined) { context.report({ - node, + loc: node.loc, messageId: 'missing', data: { resource } }); diff --git a/build/lib/eslint/code-translation-remind.ts b/build/lib/eslint/code-translation-remind.ts index a95840c86f8..d482d3ff461 100644 --- a/build/lib/eslint/code-translation-remind.ts +++ b/build/lib/eslint/code-translation-remind.ts @@ -4,7 +4,7 @@ *--------------------------------------------------------------------------------------------*/ import * as eslint from 'eslint'; -import * as estree from 'estree'; +import { TSESTree } from '@typescript-eslint/experimental-utils'; import { readFileSync } from 'fs'; import { createImportRuleListener } from './utils'; @@ -25,7 +25,7 @@ export = new class TranslationRemind implements eslint.Rule.RuleModule { return createImportRuleListener((node, path) => this._checkImport(context, node, path)); } - private _checkImport(context: eslint.Rule.RuleContext, node: estree.Node, path: string) { + private _checkImport(context: eslint.Rule.RuleContext, node: TSESTree.Node, path: string) { if (path !== TranslationRemind.NLS_MODULE) { return; @@ -59,7 +59,7 @@ export = new class TranslationRemind implements eslint.Rule.RuleModule { if (!resourceDefined) { context.report({ - node, + loc: node.loc, messageId: 'missing', data: { resource } }); diff --git a/build/lib/eslint/utils.js b/build/lib/eslint/utils.js index c3ccd6f4552..1cdd1837e89 100644 --- a/build/lib/eslint/utils.js +++ b/build/lib/eslint/utils.js @@ -4,6 +4,7 @@ * Licensed under the MIT License. See License.txt in the project root for license information. *--------------------------------------------------------------------------------------------*/ Object.defineProperty(exports, "__esModule", { value: true }); +const experimental_utils_1 = require("@typescript-eslint/experimental-utils"); function createImportRuleListener(validateImport) { function _checkImport(node) { if (node && node.type === 'Literal' && typeof node.value === 'string') { @@ -23,6 +24,13 @@ function createImportRuleListener(validateImport) { _checkImport(args[0]); } }, + // import foo = ... + [experimental_utils_1.AST_NODE_TYPES.TSImportEqualsDeclaration]: (node) => { + const { moduleReference } = node; + if (moduleReference.type === experimental_utils_1.AST_NODE_TYPES.TSExternalModuleReference) { + _checkImport(moduleReference.expression); + } + }, // export ?? from 'module' ExportAllDeclaration: (node) => { _checkImport(node.source); @@ -30,7 +38,7 @@ function createImportRuleListener(validateImport) { // export {foo} from 'module' ExportNamedDeclaration: (node) => { _checkImport(node.source); - } + }, }; } exports.createImportRuleListener = createImportRuleListener; diff --git a/build/lib/eslint/utils.ts b/build/lib/eslint/utils.ts index d992cb18e71..c48e174b702 100644 --- a/build/lib/eslint/utils.ts +++ b/build/lib/eslint/utils.ts @@ -4,43 +4,43 @@ *--------------------------------------------------------------------------------------------*/ import * as eslint from 'eslint'; -import * as estree from 'estree'; +import { TSESTree, AST_NODE_TYPES } from '@typescript-eslint/experimental-utils'; -//https://github.com/estree/estree/blob/master/es2015.md#exportnameddeclaration -declare interface ExportNamedDeclaration { - type: "ExportNamedDeclaration"; - declaration: estree.Declaration | null; - specifiers: [estree.ExportSpecifier]; - source: estree.Literal | null; -} +export function createImportRuleListener(validateImport: (node: TSESTree.Literal, value: string) => any): eslint.Rule.RuleListener { -export function createImportRuleListener(validateImport: (node: estree.SimpleLiteral, value: string) => any): eslint.Rule.RuleListener { - - function _checkImport(node: estree.Literal | null) { + function _checkImport(node: TSESTree.Node | null) { if (node && node.type === 'Literal' && typeof node.value === 'string') { - validateImport(node, node.value); + validateImport(node, node.value); } } return { // import ??? from 'module' - ImportDeclaration: (node: estree.Node) => { - _checkImport((node).source); + ImportDeclaration: (node: any) => { + _checkImport((node).source); }, // import('module').then(...) - CallExpression: (node: estree.Node) => { - const { callee, arguments: args } = node; + CallExpression: (node: any) => { + const { callee, arguments: args } = node; if ((callee.type) === 'Import' && args.length > 0 && args[0]?.type === 'Literal') { - _checkImport(args[0]); + _checkImport(args[0]); + } + }, + // import foo = ... + [AST_NODE_TYPES.TSImportEqualsDeclaration]: (node: any) => { + const { moduleReference } = (node); + if (moduleReference.type === AST_NODE_TYPES.TSExternalModuleReference) { + _checkImport(((moduleReference).expression)); } }, // export ?? from 'module' - ExportAllDeclaration: (node: estree.Node) => { - _checkImport((node).source); + ExportAllDeclaration: (node: any) => { + _checkImport((node).source); }, // export {foo} from 'module' - ExportNamedDeclaration: (node: estree.Node) => { - _checkImport((node).source); - } + ExportNamedDeclaration: (node: any) => { + _checkImport((node).source); + }, + }; } diff --git a/build/package.json b/build/package.json index ae55442cb18..24570a9648e 100644 --- a/build/package.json +++ b/build/package.json @@ -29,6 +29,7 @@ "@types/through2": "^2.0.34", "@types/underscore": "^1.8.9", "@types/xml2js": "0.0.33", + "@typescript-eslint/experimental-utils": "~2.13.0", "applicationinsights": "1.0.8", "azure-storage": "^2.1.0", "github-releases": "^0.4.1", diff --git a/build/yarn.lock b/build/yarn.lock index c8f1d29a920..b98261cbfc1 100644 --- a/build/yarn.lock +++ b/build/yarn.lock @@ -197,7 +197,7 @@ resolved "https://registry.yarnpkg.com/@types/js-beautify/-/js-beautify-1.8.0.tgz#0369d3d0e1f35a6aec07cb4da2ee2bcda111367c" integrity sha512-/siF86XrwDKLuHe8l7h6NhrAWgLdgqbxmjZv9NvGWmgYRZoTipkjKiWb0SQHy/jcR+ee0GvbG6uGd+LEBMGNvA== -"@types/json-schema@*": +"@types/json-schema@*", "@types/json-schema@^7.0.3": version "7.0.4" resolved "https://registry.yarnpkg.com/@types/json-schema/-/json-schema-7.0.4.tgz#38fd73ddfd9b55abb1e1b2ed578cb55bd7b7d339" integrity sha512-8+KAKzEvSUdeo+kmqnKrqgeE+LcA0tjYWFY7RPProVYwnqDjukzO+3b6dLD56rYX5TdWejnEOLJYOIeh4CXKuA== @@ -330,6 +330,28 @@ resolved "https://registry.yarnpkg.com/@types/xml2js/-/xml2js-0.0.33.tgz#20c5dd6460245284d64a55690015b95e409fb7de" integrity sha1-IMXdZGAkUoTWSlVpABW5XkCft94= +"@typescript-eslint/experimental-utils@~2.13.0": + version "2.13.0" + resolved "https://registry.yarnpkg.com/@typescript-eslint/experimental-utils/-/experimental-utils-2.13.0.tgz#958614faa6f77599ee2b241740e0ea402482533d" + integrity sha512-+Hss3clwa6aNiC8ZjA45wEm4FutDV5HsVXPl/rDug1THq6gEtOYRGLqS3JlTk7mSnL5TbJz0LpEbzbPnKvY6sw== + dependencies: + "@types/json-schema" "^7.0.3" + "@typescript-eslint/typescript-estree" "2.13.0" + eslint-scope "^5.0.0" + +"@typescript-eslint/typescript-estree@2.13.0": + version "2.13.0" + resolved "https://registry.yarnpkg.com/@typescript-eslint/typescript-estree/-/typescript-estree-2.13.0.tgz#a2e746867da772c857c13853219fced10d2566bc" + integrity sha512-t21Mg5cc8T3ADEUGwDisHLIubgXKjuNRbkpzDMLb7/JMmgCe/gHM9FaaujokLey+gwTuLF5ndSQ7/EfQqrQx4g== + dependencies: + debug "^4.1.1" + eslint-visitor-keys "^1.1.0" + glob "^7.1.6" + is-glob "^4.0.1" + lodash.unescape "4.0.1" + semver "^6.3.0" + tsutils "^3.17.1" + acorn@4.X: version "4.0.13" resolved "https://registry.yarnpkg.com/acorn/-/acorn-4.0.13.tgz#105495ae5361d697bd195c825192e1ad7f253787" @@ -923,11 +945,36 @@ escape-string-regexp@^1.0.2, escape-string-regexp@^1.0.5: resolved "https://registry.yarnpkg.com/escape-string-regexp/-/escape-string-regexp-1.0.5.tgz#1b61c0562190a8dff6ae3bb2cf0200ca130b86d4" integrity sha1-G2HAViGQqN/2rjuyzwIAyhMLhtQ= +eslint-scope@^5.0.0: + version "5.0.0" + resolved "https://registry.yarnpkg.com/eslint-scope/-/eslint-scope-5.0.0.tgz#e87c8887c73e8d1ec84f1ca591645c358bfc8fb9" + integrity sha512-oYrhJW7S0bxAFDvWqzvMPRm6pcgcnWc4QnofCAqRTRfQC0JcwenzGglTtsLyIuuWFfkqDG9vz67cnttSd53djw== + dependencies: + esrecurse "^4.1.0" + estraverse "^4.1.1" + +eslint-visitor-keys@^1.1.0: + version "1.1.0" + resolved "https://registry.yarnpkg.com/eslint-visitor-keys/-/eslint-visitor-keys-1.1.0.tgz#e2a82cea84ff246ad6fb57f9bde5b46621459ec2" + integrity sha512-8y9YjtM1JBJU/A9Kc+SbaOV4y29sSWckBwMHa+FGtVj5gN/sbnKDf6xJUl+8g7FAij9LVaP8C24DUiH/f/2Z9A== + esprima@^4.0.0: version "4.0.1" resolved "https://registry.yarnpkg.com/esprima/-/esprima-4.0.1.tgz#13b04cdb3e6c5d19df91ab6987a8695619b0aa71" integrity sha512-eGuFFw7Upda+g4p+QHvnW0RyTX/SVeJBDM/gCtMARO0cLuT2HcEKnTPvhjV6aGeqrCB/sbNop0Kszm0jsaWU4A== +esrecurse@^4.1.0: + version "4.2.1" + resolved "https://registry.yarnpkg.com/esrecurse/-/esrecurse-4.2.1.tgz#007a3b9fdbc2b3bb87e4879ea19c92fdbd3942cf" + integrity sha512-64RBB++fIOAXPw3P9cy89qfMlvZEXZkqqJkjqqXIvzP5ezRZjW+lPWjw35UX/3EhUPFYbg5ER4JYgDw4007/DQ== + dependencies: + estraverse "^4.1.0" + +estraverse@^4.1.0, estraverse@^4.1.1: + version "4.3.0" + resolved "https://registry.yarnpkg.com/estraverse/-/estraverse-4.3.0.tgz#398ad3f3c5a24948be7725e83d11a7de28cdbd1d" + integrity sha512-39nnKffWz8xN1BU/2c79n9nB9HDzo0niYUqx6xyqUnyoAnQyyWpOTdZEeiCch8BBu515t4wp9ZmgVfVhn9EBpw== + esutils@^2.0.2: version "2.0.2" resolved "https://registry.yarnpkg.com/esutils/-/esutils-2.0.2.tgz#0abf4f1caa5bcb1f7a9d8acc6dea4faaa04bac9b" @@ -1120,6 +1167,18 @@ glob@^7.1.3: once "^1.3.0" path-is-absolute "^1.0.0" +glob@^7.1.6: + version "7.1.6" + resolved "https://registry.yarnpkg.com/glob/-/glob-7.1.6.tgz#141f33b81a7c2492e125594307480c46679278a6" + integrity sha512-LwaxwyZ72Lk7vZINtNNrywX0ZuLyStrdDtabefZKAY5ZGJhVtgdznluResxNmPitE0SAO+O26sWTHeKSI2wMBA== + dependencies: + fs.realpath "^1.0.0" + inflight "^1.0.4" + inherits "2" + minimatch "^3.0.4" + once "^1.3.0" + path-is-absolute "^1.0.0" + globby@^10.0.1: version "10.0.1" resolved "https://registry.yarnpkg.com/globby/-/globby-10.0.1.tgz#4782c34cb75dd683351335c5829cc3420e606b22" @@ -1659,6 +1718,11 @@ lodash.templatesettings@^3.0.0: lodash._reinterpolate "^3.0.0" lodash.escape "^3.0.0" +lodash.unescape@4.0.1: + version "4.0.1" + resolved "https://registry.yarnpkg.com/lodash.unescape/-/lodash.unescape-4.0.1.tgz#bf2249886ce514cda112fae9218cdc065211fc9c" + integrity sha1-vyJJiGzlFM2hEvrpIYzcBlIR/Jw= + lodash@^4.15.0, lodash@^4.17.10: version "4.17.11" resolved "https://registry.yarnpkg.com/lodash/-/lodash-4.17.11.tgz#b39ea6229ef607ecd89e2c8df12536891cac9b8d" @@ -2183,6 +2247,11 @@ semver@^5.5.0: resolved "https://registry.yarnpkg.com/semver/-/semver-5.7.1.tgz#a954f931aeba508d307bbf069eff0c01c96116f7" integrity sha512-sauaDf/PZdVgrLTNYHRtpXa1iRiKcaebiKQ1BJdpQlWH2lCvexQdX55snPFyK7QzpudqbCI0qXFfOasHdyNDGQ== +semver@^6.3.0: + version "6.3.0" + resolved "https://registry.yarnpkg.com/semver/-/semver-6.3.0.tgz#ee0a64c8af5e8ceea67687b133761e1becbd1d3d" + integrity sha512-b39TBaTSfV6yBrapU89p5fKekE2m/NwnDocOVruQFS1/veMgdzuPcnOM34M6CwxW8jH/lxEa5rBoDeUwu5HHTw== + shebang-command@^1.2.0: version "1.2.0" resolved "https://registry.yarnpkg.com/shebang-command/-/shebang-command-1.2.0.tgz#44aac65b695b03398968c39f363fee5deafdf1ea" @@ -2434,6 +2503,13 @@ tsutils@^2.27.2: dependencies: tslib "^1.8.1" +tsutils@^3.17.1: + version "3.17.1" + resolved "https://registry.yarnpkg.com/tsutils/-/tsutils-3.17.1.tgz#ed719917f11ca0dee586272b2ac49e015a2dd759" + integrity sha512-kzeQ5B8H3w60nFY2g8cJIuH7JDpsALXySGtwGJ0p2LSjLgay3NdIpqq5SoOBe46bKDW2iq25irHCr8wjomUS2g== + dependencies: + tslib "^1.8.1" + tunnel-agent@^0.6.0: version "0.6.0" resolved "https://registry.yarnpkg.com/tunnel-agent/-/tunnel-agent-0.6.0.tgz#27a5dea06b36b04a0a9966774b290868f0fc40fd"