use ts-es-tree-typings, support import-equals

This commit is contained in:
Johannes Rieken 2019-12-30 14:08:44 +01:00
parent 11f9af09d7
commit 4db80066b4
14 changed files with 123 additions and 38 deletions

View File

@ -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 ')

View File

@ -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 ')

View File

@ -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,

View File

@ -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,

View File

@ -29,7 +29,7 @@ module.exports = new class NoNlsInStandaloneEditorRule {
}
if (/vs(\/|\\)nls/.test(path)) {
context.report({
node,
loc: node.loc,
messageId: 'noNls'
});
}

View File

@ -37,7 +37,7 @@ export = new class NoNlsInStandaloneEditorRule implements eslint.Rule.RuleModule
/vs(\/|\\)nls/.test(path)
) {
context.report({
node,
loc: node.loc,
messageId: 'noNls'
});
}

View File

@ -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'
});
}

View File

@ -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'
});
}

View File

@ -48,7 +48,7 @@ module.exports = new (_a = class TranslationRemind {
});
if (!resourceDefined) {
context.report({
node,
loc: node.loc,
messageId: 'missing',
data: { resource }
});

View File

@ -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 }
});

View File

@ -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;

View File

@ -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(<estree.SimpleLiteral>node, node.value);
validateImport(node, node.value);
}
}
return {
// import ??? from 'module'
ImportDeclaration: (node: estree.Node) => {
_checkImport((<estree.ImportDeclaration>node).source);
ImportDeclaration: (node: any) => {
_checkImport((<TSESTree.ImportDeclaration>node).source);
},
// import('module').then(...)
CallExpression: (node: estree.Node) => {
const { callee, arguments: args } = <estree.CallExpression>node;
CallExpression: (node: any) => {
const { callee, arguments: args } = <TSESTree.CallExpression>node;
if ((<any>callee.type) === 'Import' && args.length > 0 && args[0]?.type === 'Literal') {
_checkImport(<estree.SimpleLiteral>args[0]);
_checkImport(args[0]);
}
},
// import foo = ...
[AST_NODE_TYPES.TSImportEqualsDeclaration]: (node: any) => {
const { moduleReference } = (<TSESTree.TSImportEqualsDeclaration>node);
if (moduleReference.type === AST_NODE_TYPES.TSExternalModuleReference) {
_checkImport((<TSESTree.Literal>(<TSESTree.TSExternalModuleReference>moduleReference).expression));
}
},
// export ?? from 'module'
ExportAllDeclaration: (node: estree.Node) => {
_checkImport((<estree.ExportAllDeclaration>node).source);
ExportAllDeclaration: (node: any) => {
_checkImport((<TSESTree.ExportAllDeclaration>node).source);
},
// export {foo} from 'module'
ExportNamedDeclaration: (node: estree.Node) => {
_checkImport((<ExportNamedDeclaration>node).source);
}
ExportNamedDeclaration: (node: any) => {
_checkImport((<TSESTree.ExportNamedDeclaration>node).source);
},
};
}

View File

@ -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",

View File

@ -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"