@definitelytyped/dtslint 0.0.158-next.2 → 0.0.158-next.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/checks.d.ts +1 -1
- package/dist/lint.d.ts +1 -1
- package/dist/lint.js +1 -1
- package/dist/lint.js.map +1 -1
- package/dist/rules/expectRule.d.ts +2 -2
- package/dist/rules/expectRule.js +1 -1
- package/dist/rules/expectRule.js.map +1 -1
- package/dist/rules/no-import-default-of-export-equals.d.ts +4 -0
- package/dist/rules/no-import-default-of-export-equals.js +82 -0
- package/dist/rules/no-import-default-of-export-equals.js.map +1 -0
- package/dist/rules/no-single-element-tuple-type.d.ts +5 -0
- package/dist/rules/no-single-element-tuple-type.js +30 -0
- package/dist/rules/no-single-element-tuple-type.js.map +1 -0
- package/dist/rules/no-unnecessary-generics.d.ts +1 -1
- package/dist/rules/noPaddingRule.js +1 -1
- package/dist/rules/noPaddingRule.js.map +1 -1
- package/dist/rules/noRedundantJsdoc2Rule.js +4 -2
- package/dist/rules/noRedundantJsdoc2Rule.js.map +1 -1
- package/dist/rules/noRelativeImportInTestRule.js +1 -1
- package/dist/rules/noRelativeImportInTestRule.js.map +1 -1
- package/dist/rules/noSingleDeclareModuleRule.js +1 -1
- package/dist/rules/noSingleDeclareModuleRule.js.map +1 -1
- package/dist/rules/npmNamingRule.d.ts +1 -1
- package/dist/rules/npmNamingRule.js +1 -1
- package/dist/rules/npmNamingRule.js.map +1 -1
- package/dist/rules/strictExportDeclareModifiersRule.js +9 -5
- package/dist/rules/strictExportDeclareModifiersRule.js.map +1 -1
- package/dist/rules/voidReturnRule.js +1 -1
- package/dist/rules/voidReturnRule.js.map +1 -1
- package/dist/util.d.ts +0 -2
- package/dist/util.js +1 -52
- package/dist/util.js.map +1 -1
- package/package.json +5 -5
- package/src/rules/no-import-default-of-export-equals.ts +62 -0
- package/src/rules/no-single-element-tuple-type.ts +31 -0
- package/src/rules/noRedundantJsdoc2Rule.ts +2 -1
- package/src/rules/strictExportDeclareModifiersRule.ts +8 -8
- package/src/util.ts +0 -27
- package/test/no-import-default-of-export-equals.test.ts +48 -0
- package/test/no-single-element-tuple-type.test.ts +28 -0
- package/test/tsconfig.no-import-default-of-export-equals.json +11 -0
- package/tsconfig.tsbuildinfo +1 -1
- package/dist/rules/noImportDefaultOfExportEqualsRule.d.ts +0 -7
- package/dist/rules/noImportDefaultOfExportEqualsRule.js +0 -75
- package/dist/rules/noImportDefaultOfExportEqualsRule.js.map +0 -1
- package/dist/rules/noSingleElementTupleTypeRule.d.ts +0 -6
- package/dist/rules/noSingleElementTupleTypeRule.js +0 -54
- package/dist/rules/noSingleElementTupleTypeRule.js.map +0 -1
- package/src/rules/noImportDefaultOfExportEqualsRule.ts +0 -58
- package/src/rules/noSingleElementTupleTypeRule.ts +0 -32
- package/test/no-import-default-of-export-equals/bad-ambient-modules/test.d.ts.lint +0 -11
- package/test/no-import-default-of-export-equals/bad-ambient-modules/tsconfig.json +0 -1
- package/test/no-import-default-of-export-equals/bad-ambient-modules/tslint.json +0 -6
- package/test/no-import-default-of-export-equals/bad-external-modules/a.d.ts +0 -2
- package/test/no-import-default-of-export-equals/bad-external-modules/b.d.ts.lint +0 -4
- package/test/no-import-default-of-export-equals/bad-external-modules/tsconfig.json +0 -1
- package/test/no-import-default-of-export-equals/bad-external-modules/tslint.json +0 -7
- package/test/no-import-default-of-export-equals/good-ambient-modules/test.d.ts.lint +0 -9
- package/test/no-import-default-of-export-equals/good-ambient-modules/tsconfig.json +0 -1
- package/test/no-import-default-of-export-equals/good-ambient-modules/tslint.json +0 -6
- package/test/no-single-element-tuple-type/test.ts.lint +0 -5
- package/test/no-single-element-tuple-type/tslint.json +0 -6
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"voidReturnRule.js","sourceRoot":"","sources":["../../src/rules/voidReturnRule.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,6CAA+B;AAC/B,+CA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,CAAC"}
|
package/dist/util.d.ts
CHANGED
|
@@ -4,8 +4,6 @@ export declare const createRule: <TOptions extends readonly unknown[], TMessageI
|
|
|
4
4
|
export declare function readJson(path: string): Promise<any>;
|
|
5
5
|
export declare function failure(ruleName: string, s: string): string;
|
|
6
6
|
export declare function getCommonDirectoryName(files: readonly string[]): string;
|
|
7
|
-
export declare function eachModuleStatement(sourceFile: ts.SourceFile, action: (statement: ts.Statement) => void): void;
|
|
8
|
-
export declare function getModuleDeclarationStatements(node: ts.ModuleDeclaration): readonly ts.Statement[] | undefined;
|
|
9
7
|
export declare function getCompilerOptions(dirPath: string): Promise<ts.CompilerOptions>;
|
|
10
8
|
export declare function withoutPrefix(s: string, prefix: string): string | undefined;
|
|
11
9
|
export declare function last<T>(a: readonly T[]): T;
|
package/dist/util.js
CHANGED
|
@@ -1,35 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
-
if (mod && mod.__esModule) return mod;
|
|
20
|
-
var result = {};
|
|
21
|
-
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
-
__setModuleDefault(result, mod);
|
|
23
|
-
return result;
|
|
24
|
-
};
|
|
25
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
-
exports.isMainFile = exports.mapDefinedAsync = exports.assertDefined = exports.last = exports.withoutPrefix = exports.getCompilerOptions = exports.
|
|
3
|
+
exports.isMainFile = exports.mapDefinedAsync = exports.assertDefined = exports.last = exports.withoutPrefix = exports.getCompilerOptions = exports.getCommonDirectoryName = exports.failure = exports.readJson = exports.createRule = void 0;
|
|
27
4
|
const utils_1 = require("@typescript-eslint/utils");
|
|
28
5
|
const assert = require("assert");
|
|
29
6
|
const fs_extra_1 = require("fs-extra");
|
|
30
7
|
const path_1 = require("path");
|
|
31
8
|
const stripJsonComments = require("strip-json-comments");
|
|
32
|
-
const ts = __importStar(require("typescript"));
|
|
33
9
|
exports.createRule = utils_1.ESLintUtils.RuleCreator((name) => `https://github.com/microsoft/DefinitelyTyped-tools/tree/master/packages/dtslint/src/rules/${name}.ts`);
|
|
34
10
|
async function readJson(path) {
|
|
35
11
|
const text = await (0, fs_extra_1.readFile)(path, "utf-8");
|
|
@@ -53,33 +29,6 @@ function getCommonDirectoryName(files) {
|
|
|
53
29
|
return (0, path_1.basename)(minDir);
|
|
54
30
|
}
|
|
55
31
|
exports.getCommonDirectoryName = getCommonDirectoryName;
|
|
56
|
-
function eachModuleStatement(sourceFile, action) {
|
|
57
|
-
if (!sourceFile.isDeclarationFile) {
|
|
58
|
-
return;
|
|
59
|
-
}
|
|
60
|
-
for (const node of sourceFile.statements) {
|
|
61
|
-
if (ts.isModuleDeclaration(node)) {
|
|
62
|
-
const statements = getModuleDeclarationStatements(node);
|
|
63
|
-
if (statements) {
|
|
64
|
-
for (const statement of statements) {
|
|
65
|
-
action(statement);
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
else {
|
|
70
|
-
action(node);
|
|
71
|
-
}
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
exports.eachModuleStatement = eachModuleStatement;
|
|
75
|
-
function getModuleDeclarationStatements(node) {
|
|
76
|
-
let { body } = node;
|
|
77
|
-
while (body && body.kind === ts.SyntaxKind.ModuleDeclaration) {
|
|
78
|
-
body = body.body;
|
|
79
|
-
}
|
|
80
|
-
return body && ts.isModuleBlock(body) ? body.statements : undefined;
|
|
81
|
-
}
|
|
82
|
-
exports.getModuleDeclarationStatements = getModuleDeclarationStatements;
|
|
83
32
|
async function getCompilerOptions(dirPath) {
|
|
84
33
|
const tsconfigPath = (0, path_1.join)(dirPath, "tsconfig.json");
|
|
85
34
|
if (!(await (0, fs_extra_1.pathExists)(tsconfigPath))) {
|
package/dist/util.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"util.js","sourceRoot":"","sources":["../src/util.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"util.js","sourceRoot":"","sources":["../src/util.ts"],"names":[],"mappings":";;;AAAA,oDAAuD;AACvD,iCAAkC;AAClC,uCAAgD;AAChD,+BAA+C;AAC/C,yDAA0D;AAG7C,QAAA,UAAU,GAAG,mBAAW,CAAC,WAAW,CAC/C,CAAC,IAAI,EAAE,EAAE,CAAC,6FAA6F,IAAI,KAAK,CACjH,CAAC;AAEK,KAAK,UAAU,QAAQ,CAAC,IAAY;IACzC,MAAM,IAAI,GAAG,MAAM,IAAA,mBAAQ,EAAC,IAAI,EAAE,OAAO,CAAC,CAAC;IAC3C,OAAO,IAAI,CAAC,KAAK,CAAC,iBAAiB,CAAC,IAAI,CAAC,CAAC,CAAC;AAC7C,CAAC;AAHD,4BAGC;AAED,SAAgB,OAAO,CAAC,QAAgB,EAAE,CAAS;IACjD,OAAO,GAAG,CAAC,8FAA8F,QAAQ,KAAK,CAAC;AACzH,CAAC;AAFD,0BAEC;AAED,SAAgB,sBAAsB,CAAC,KAAwB;IAC7D,IAA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AO,CAAC,CAAC;AACX,CAAC;AALD,sCAKC;AAEM,KAAK,UAAU,eAAe,CAAO,GAAgB,EAAE,MAAwC;IACpG,MAAM,GAAG,GAAG,EAAE,CAAC;IACf,KAAK,MAAM,CAAC,IAAI,GAAG,EAAE;QACnB,MAAM,GAAG,GAAG,MAAM,MAAM,CAAC,CAAC,CAAC,CAAC;QAC5B,IAAI,GAAG,KAAK,SAAS,EAAE;YACrB,GAAG,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;SACf;KACF;IACD,OAAO,GAAG,CAAC;AACb,CAAC;AATD,0CASC;AAED,SAAgB,UAAU,CAAC,QAAgB,EAAE,WAAoB;IAC/D,2GAA2G;IAC3G,IAAI,QAAQ,KAAK,YAAY,EAAE;QAC7B,OAAO,IAAI,CAAC;KACb;IAED,IAAI,IAAA,eAAQ,EAAC,QAAQ,CAAC,KAAK,YAAY,EAAE;QACvC,OAAO,KAAK,CAAC;KACd;IAED,IAAI,MAAM,GAAG,IAAA,cAAO,EAAC,QAAQ,CAAC,CAAC;IAC/B,sDAAsD;IACtD,oEAAoE;IACpE,IAAI,WAAW,IAAI,cAAc,CAAC,IAAI,CAAC,IAAA,eAAQ,EAAC,MAAM,CAAC,CAAC,EAAE;QACxD,MAAM,GAAG,IAAA,cAAO,EAAC,MAAM,CAAC,CAAC;KAC1B;IAED,iEAAiE;IACjE,OAAO,IAAA,eAAQ,EAAC,IAAA,cAAO,EAAC,MAAM,CAAC,CAAC,KAAK,OAAO,CAAC;AAC/C,CAAC;AAnBD,gCAmBC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@definitelytyped/dtslint",
|
|
3
|
-
"version": "0.0.158-next.
|
|
3
|
+
"version": "0.0.158-next.4",
|
|
4
4
|
"description": "Runs tests on TypeScript definition files",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"bin": "./dist/index.js",
|
|
@@ -22,7 +22,7 @@
|
|
|
22
22
|
"test": "../../node_modules/.bin/jest --config ../../jest.config.js packages/dtslint"
|
|
23
23
|
},
|
|
24
24
|
"dependencies": {
|
|
25
|
-
"@definitelytyped/dts-critic": "^0.0.
|
|
25
|
+
"@definitelytyped/dts-critic": "^0.0.158-next.4",
|
|
26
26
|
"@definitelytyped/header-parser": "^0.0.157",
|
|
27
27
|
"@definitelytyped/typescript-versions": "^0.0.157",
|
|
28
28
|
"@definitelytyped/utils": "^0.0.157",
|
|
@@ -39,18 +39,18 @@
|
|
|
39
39
|
"yargs": "^15.1.0"
|
|
40
40
|
},
|
|
41
41
|
"peerDependencies": {
|
|
42
|
-
"typescript": ">= 3.0.0-dev || >= 3.1.0-dev || >= 3.2.0-dev || >= 3.3.0-dev || >= 3.4.0-dev || >= 3.5.0-dev || >= 3.6.0-dev || >= 3.7.0-dev || >= 3.8.0-dev || >= 3.9.0-dev || >= 4.0.0-dev"
|
|
42
|
+
"typescript": ">= 3.0.0-dev || >= 3.1.0-dev || >= 3.2.0-dev || >= 3.3.0-dev || >= 3.4.0-dev || >= 3.5.0-dev || >= 3.6.0-dev || >= 3.7.0-dev || >= 3.8.0-dev || >= 3.9.0-dev || >= 4.0.0-dev || >=5.0.0-dev"
|
|
43
43
|
},
|
|
44
44
|
"devDependencies": {
|
|
45
45
|
"@types/eslint": "^8.4.2",
|
|
46
46
|
"@types/fs-extra": "^5.0.2",
|
|
47
47
|
"@types/json-stable-stringify": "^1.0.32",
|
|
48
48
|
"@types/strip-json-comments": "^0.0.28",
|
|
49
|
-
"typescript": "
|
|
49
|
+
"typescript": "^5.0.2"
|
|
50
50
|
},
|
|
51
51
|
"engines": {
|
|
52
52
|
"node": ">=10.0.0"
|
|
53
53
|
},
|
|
54
54
|
"license": "MIT",
|
|
55
|
-
"gitHead": "
|
|
55
|
+
"gitHead": "e4c9437b79c4b229e0b9774f42c399472995d315"
|
|
56
56
|
}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import { createRule } from "../util";
|
|
2
|
+
import { ESLintUtils } from "@typescript-eslint/utils";
|
|
3
|
+
import * as ts from "typescript";
|
|
4
|
+
|
|
5
|
+
const rule = createRule({
|
|
6
|
+
name: "no-import-default-of-export-equals",
|
|
7
|
+
defaultOptions: [],
|
|
8
|
+
meta: {
|
|
9
|
+
type: "problem",
|
|
10
|
+
docs: {
|
|
11
|
+
description: "Forbid a default import to reference an `export =` module.",
|
|
12
|
+
recommended: "error",
|
|
13
|
+
},
|
|
14
|
+
messages: {
|
|
15
|
+
noImportDefaultOfExportEquals: `The module {{moduleName}} uses \`export = \`. Import with \`import {{importName}} = require({{moduleName}})\`.`,
|
|
16
|
+
},
|
|
17
|
+
schema: [],
|
|
18
|
+
},
|
|
19
|
+
create(context) {
|
|
20
|
+
const parserServices = ESLintUtils.getParserServices(context);
|
|
21
|
+
const checker = parserServices.program.getTypeChecker();
|
|
22
|
+
return {
|
|
23
|
+
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
24
|
+
ImportDeclaration(node) {
|
|
25
|
+
const defaultName = node.specifiers.find((spec) => spec.type === "ImportDefaultSpecifier")?.local;
|
|
26
|
+
if (!defaultName) {
|
|
27
|
+
return;
|
|
28
|
+
}
|
|
29
|
+
const importName = defaultName.name;
|
|
30
|
+
const source = parserServices.esTreeNodeToTSNodeMap.get(node.source);
|
|
31
|
+
const sym = checker.getSymbolAtLocation(source);
|
|
32
|
+
if (
|
|
33
|
+
sym?.declarations?.some((d) => getStatements(d)?.some((s) => ts.isExportAssignment(s) && !!s.isExportEquals))
|
|
34
|
+
) {
|
|
35
|
+
context.report({
|
|
36
|
+
messageId: "noImportDefaultOfExportEquals",
|
|
37
|
+
data: { moduleName: node.source, importName },
|
|
38
|
+
node: defaultName,
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
},
|
|
42
|
+
};
|
|
43
|
+
},
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
function getStatements(decl: ts.Declaration): readonly ts.Statement[] | undefined {
|
|
47
|
+
return ts.isSourceFile(decl)
|
|
48
|
+
? decl.statements
|
|
49
|
+
: ts.isModuleDeclaration(decl)
|
|
50
|
+
? getModuleDeclarationStatements(decl)
|
|
51
|
+
: undefined;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
function getModuleDeclarationStatements(node: ts.ModuleDeclaration): readonly ts.Statement[] | undefined {
|
|
55
|
+
let { body } = node;
|
|
56
|
+
while (body && body.kind === ts.SyntaxKind.ModuleDeclaration) {
|
|
57
|
+
body = body.body;
|
|
58
|
+
}
|
|
59
|
+
return body && ts.isModuleBlock(body) ? body.statements : undefined;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
export = rule;
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { createRule } from "../util";
|
|
2
|
+
import { TSESTree } from "@typescript-eslint/utils";
|
|
3
|
+
|
|
4
|
+
const rule = createRule({
|
|
5
|
+
name: "no-single-element-tuple-type",
|
|
6
|
+
defaultOptions: [],
|
|
7
|
+
meta: {
|
|
8
|
+
type: "problem",
|
|
9
|
+
docs: {
|
|
10
|
+
description: "Forbids `[T]`, which should be `T[]`.",
|
|
11
|
+
recommended: "error",
|
|
12
|
+
},
|
|
13
|
+
messages: {
|
|
14
|
+
singleElementTupleType: `Type [T] is a single-element tuple type. You probably meant T[].`,
|
|
15
|
+
},
|
|
16
|
+
schema: [],
|
|
17
|
+
},
|
|
18
|
+
create(context) {
|
|
19
|
+
return {
|
|
20
|
+
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
21
|
+
"TSTupleType[elementTypes.length=1]"(node: TSESTree.TSTupleType) {
|
|
22
|
+
context.report({
|
|
23
|
+
messageId: "singleElementTupleType",
|
|
24
|
+
node,
|
|
25
|
+
});
|
|
26
|
+
},
|
|
27
|
+
};
|
|
28
|
+
},
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
export = rule;
|
|
@@ -222,7 +222,8 @@ function removeTypeExpression(
|
|
|
222
222
|
function isInAmbientContext(node: ts.Node): boolean {
|
|
223
223
|
return ts.isSourceFile(node)
|
|
224
224
|
? node.isDeclarationFile
|
|
225
|
-
:
|
|
225
|
+
: (ts.canHaveModifiers(node) && ts.getModifiers(node)?.some((m) => m.kind === ts.SyntaxKind.DeclareKeyword)) ||
|
|
226
|
+
isInAmbientContext(node.parent!);
|
|
226
227
|
}
|
|
227
228
|
|
|
228
229
|
const redundantTags = new Set([
|
|
@@ -54,7 +54,7 @@ function walk(ctx: Lint.WalkContext<void>): void {
|
|
|
54
54
|
// `declare global` and `declare module "foo"` OK. `declare namespace N` not OK, should be `export namespace`.
|
|
55
55
|
if (!isDeclareGlobalOrExternalModuleDeclaration(node)) {
|
|
56
56
|
if (isDeclare(node)) {
|
|
57
|
-
fail(mod(node, ts.SyntaxKind.DeclareKeyword)
|
|
57
|
+
fail(mod(node, ts.SyntaxKind.DeclareKeyword)!, "'declare' keyword is redundant here.");
|
|
58
58
|
}
|
|
59
59
|
if (autoExportEnabled && !isExport(node)) {
|
|
60
60
|
fail(
|
|
@@ -76,7 +76,7 @@ function walk(ctx: Lint.WalkContext<void>): void {
|
|
|
76
76
|
node.kind === ts.SyntaxKind.InterfaceDeclaration ||
|
|
77
77
|
node.kind === ts.SyntaxKind.TypeAliasDeclaration
|
|
78
78
|
) {
|
|
79
|
-
fail(mod(node, ts.SyntaxKind.DeclareKeyword)
|
|
79
|
+
fail(mod(node, ts.SyntaxKind.DeclareKeyword)!, "'declare' keyword is redundant here.");
|
|
80
80
|
}
|
|
81
81
|
}
|
|
82
82
|
}
|
|
@@ -85,8 +85,8 @@ function walk(ctx: Lint.WalkContext<void>): void {
|
|
|
85
85
|
ctx.addFailureAtNode(node, failure(Rule.metadata.ruleName, reason));
|
|
86
86
|
}
|
|
87
87
|
|
|
88
|
-
function mod(node: ts.Statement, kind: ts.SyntaxKind): ts.Node {
|
|
89
|
-
return node.
|
|
88
|
+
function mod(node: ts.Statement, kind: ts.SyntaxKind): ts.Node | undefined {
|
|
89
|
+
return ts.canHaveModifiers(node) ? ts.getModifiers(node)?.find((m) => m.kind === kind) : undefined;
|
|
90
90
|
}
|
|
91
91
|
|
|
92
92
|
function checkModule(moduleDeclaration: ts.ModuleDeclaration): void {
|
|
@@ -110,7 +110,7 @@ function walk(ctx: Lint.WalkContext<void>): void {
|
|
|
110
110
|
// Compiler will error for 'declare' here anyway, so just check for 'export'.
|
|
111
111
|
if (isExport(s) && autoExportEnabled && !isDefault(s)) {
|
|
112
112
|
fail(
|
|
113
|
-
mod(s, ts.SyntaxKind.ExportKeyword)
|
|
113
|
+
mod(s, ts.SyntaxKind.ExportKeyword)!,
|
|
114
114
|
"'export' keyword is redundant here because " +
|
|
115
115
|
"all declarations in this module are exported automatically. " +
|
|
116
116
|
"If you have a good reason to export some declarations and not others, " +
|
|
@@ -138,15 +138,15 @@ function isModuleDeclaration(node: ts.Node): node is ts.ModuleDeclaration {
|
|
|
138
138
|
}
|
|
139
139
|
|
|
140
140
|
function isDeclare(node: ts.Node): boolean {
|
|
141
|
-
return
|
|
141
|
+
return ts.canHaveModifiers(node) && !!ts.getModifiers(node)?.some((m) => m.kind === ts.SyntaxKind.DeclareKeyword);
|
|
142
142
|
}
|
|
143
143
|
|
|
144
144
|
function isExport(node: ts.Node): boolean {
|
|
145
|
-
return
|
|
145
|
+
return ts.canHaveModifiers(node) && !!ts.getModifiers(node)?.some((m) => m.kind === ts.SyntaxKind.ExportKeyword);
|
|
146
146
|
}
|
|
147
147
|
|
|
148
148
|
function isDefault(node: ts.Node): boolean {
|
|
149
|
-
return
|
|
149
|
+
return ts.canHaveModifiers(node) && !!ts.getModifiers(node)?.some((m) => m.kind === ts.SyntaxKind.DefaultKeyword);
|
|
150
150
|
}
|
|
151
151
|
|
|
152
152
|
// tslint:disable-next-line:max-line-length
|
package/src/util.ts
CHANGED
|
@@ -31,33 +31,6 @@ export function getCommonDirectoryName(files: readonly string[]): string {
|
|
|
31
31
|
return basename(minDir);
|
|
32
32
|
}
|
|
33
33
|
|
|
34
|
-
export function eachModuleStatement(sourceFile: ts.SourceFile, action: (statement: ts.Statement) => void): void {
|
|
35
|
-
if (!sourceFile.isDeclarationFile) {
|
|
36
|
-
return;
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
for (const node of sourceFile.statements) {
|
|
40
|
-
if (ts.isModuleDeclaration(node)) {
|
|
41
|
-
const statements = getModuleDeclarationStatements(node);
|
|
42
|
-
if (statements) {
|
|
43
|
-
for (const statement of statements) {
|
|
44
|
-
action(statement);
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
} else {
|
|
48
|
-
action(node);
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
export function getModuleDeclarationStatements(node: ts.ModuleDeclaration): readonly ts.Statement[] | undefined {
|
|
54
|
-
let { body } = node;
|
|
55
|
-
while (body && body.kind === ts.SyntaxKind.ModuleDeclaration) {
|
|
56
|
-
body = body.body;
|
|
57
|
-
}
|
|
58
|
-
return body && ts.isModuleBlock(body) ? body.statements : undefined;
|
|
59
|
-
}
|
|
60
|
-
|
|
61
34
|
export async function getCompilerOptions(dirPath: string): Promise<ts.CompilerOptions> {
|
|
62
35
|
const tsconfigPath = join(dirPath, "tsconfig.json");
|
|
63
36
|
if (!(await pathExists(tsconfigPath))) {
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { ESLintUtils } from "@typescript-eslint/utils";
|
|
2
|
+
|
|
3
|
+
import * as noImportDefaultOfExportEquals from "../src/rules/no-import-default-of-export-equals";
|
|
4
|
+
|
|
5
|
+
const ruleTester = new ESLintUtils.RuleTester({
|
|
6
|
+
parser: "@typescript-eslint/parser",
|
|
7
|
+
parserOptions: {
|
|
8
|
+
ecmaVersion: 2018,
|
|
9
|
+
tsconfigRootDir: __dirname,
|
|
10
|
+
project: "./tsconfig.no-import-default-of-export-equals.json",
|
|
11
|
+
},
|
|
12
|
+
});
|
|
13
|
+
|
|
14
|
+
ruleTester.run("no-import-default-of-export-equals", noImportDefaultOfExportEquals, {
|
|
15
|
+
invalid: [
|
|
16
|
+
{
|
|
17
|
+
filename: "index.d.ts",
|
|
18
|
+
code: `declare module "a" {
|
|
19
|
+
interface I {}
|
|
20
|
+
export = I;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
declare module "b" {
|
|
24
|
+
import a from "a";
|
|
25
|
+
}`,
|
|
26
|
+
errors: [
|
|
27
|
+
{
|
|
28
|
+
line: 7,
|
|
29
|
+
messageId: "noImportDefaultOfExportEquals",
|
|
30
|
+
},
|
|
31
|
+
],
|
|
32
|
+
},
|
|
33
|
+
],
|
|
34
|
+
valid: [
|
|
35
|
+
{
|
|
36
|
+
filename: "index.d.ts",
|
|
37
|
+
code: `declare module "a" {
|
|
38
|
+
interface I {}
|
|
39
|
+
export default I;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
declare module "b" {
|
|
43
|
+
import a from "a";
|
|
44
|
+
}
|
|
45
|
+
`,
|
|
46
|
+
},
|
|
47
|
+
],
|
|
48
|
+
});
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { ESLintUtils } from "@typescript-eslint/utils";
|
|
2
|
+
|
|
3
|
+
import * as noDeclareCurrentPackage from "../src/rules/no-single-element-tuple-type";
|
|
4
|
+
|
|
5
|
+
const ruleTester = new ESLintUtils.RuleTester({
|
|
6
|
+
parser: "@typescript-eslint/parser",
|
|
7
|
+
});
|
|
8
|
+
|
|
9
|
+
ruleTester.run("no-single-element-tuple-type", noDeclareCurrentPackage, {
|
|
10
|
+
invalid: [
|
|
11
|
+
{
|
|
12
|
+
code: `type Test<T> = [T];`,
|
|
13
|
+
errors: [
|
|
14
|
+
{
|
|
15
|
+
line: 1,
|
|
16
|
+
messageId: "singleElementTupleType",
|
|
17
|
+
},
|
|
18
|
+
],
|
|
19
|
+
},
|
|
20
|
+
],
|
|
21
|
+
valid: [
|
|
22
|
+
`type Test = number[];`,
|
|
23
|
+
`type Test<T> = T;`,
|
|
24
|
+
`type Test<T> = T[];`,
|
|
25
|
+
`type Test<T> = [T, number];`,
|
|
26
|
+
`type Test<T> = [T, T];`,
|
|
27
|
+
],
|
|
28
|
+
});
|