@definitelytyped/dtslint 0.0.141 → 0.0.142-next.12
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/rules/no-any-union.d.ts +4 -0
- package/dist/rules/no-any-union.js +34 -0
- package/dist/rules/no-any-union.js.map +1 -0
- package/dist/rules/no-unnecessary-generics.d.ts +8 -0
- package/dist/rules/no-unnecessary-generics.js +135 -0
- package/dist/rules/no-unnecessary-generics.js.map +1 -0
- package/dist/rules/prefer-declare-function.d.ts +5 -0
- package/dist/rules/prefer-declare-function.js +35 -0
- package/dist/rules/prefer-declare-function.js.map +1 -0
- package/dtslint.json +0 -3
- package/package.json +3 -3
- package/src/rules/no-any-union.ts +34 -0
- package/src/rules/no-unnecessary-generics.ts +126 -0
- package/src/rules/prefer-declare-function.ts +37 -0
- package/test/no-any-union.test.ts +22 -0
- package/test/no-unnecessary-generics.test.ts +152 -0
- package/test/prefer-declare-function.test.ts +66 -0
- package/test/tsconfig.json +8 -0
- package/tsconfig.tsbuildinfo +1 -1
- package/dist/rules/noAnyUnionRule.d.ts +0 -7
- package/dist/rules/noAnyUnionRule.js +0 -53
- package/dist/rules/noAnyUnionRule.js.map +0 -1
- package/dist/rules/noUnnecessaryGenericsRule.d.ts +0 -8
- package/dist/rules/noUnnecessaryGenericsRule.js +0 -134
- package/dist/rules/noUnnecessaryGenericsRule.js.map +0 -1
- package/dist/rules/preferDeclareFunctionRule.d.ts +0 -7
- package/dist/rules/preferDeclareFunctionRule.js +0 -56
- package/dist/rules/preferDeclareFunctionRule.js.map +0 -1
- package/src/rules/noAnyUnionRule.ts +0 -33
- package/src/rules/noUnnecessaryGenericsRule.ts +0 -115
- package/src/rules/preferDeclareFunctionRule.ts +0 -36
- package/test/no-any-union/test.d.ts.lint +0 -4
- package/test/no-any-union/tslint.json +0 -6
- package/test/no-unnecessary-generics/test.ts.lint +0 -38
- package/test/no-unnecessary-generics/tsconfig.json +0 -1
- package/test/no-unnecessary-generics/tslint.json +0 -6
- package/test/prefer-declare-function/test.d.ts.lint +0 -10
- package/test/prefer-declare-function/tslint.json +0 -6
|
@@ -1,56 +0,0 @@
|
|
|
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
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
-
exports.Rule = void 0;
|
|
27
|
-
const Lint = __importStar(require("tslint"));
|
|
28
|
-
const ts = __importStar(require("typescript"));
|
|
29
|
-
const util_1 = require("../util");
|
|
30
|
-
class Rule extends Lint.Rules.AbstractRule {
|
|
31
|
-
apply(sourceFile) {
|
|
32
|
-
return this.applyWithFunction(sourceFile, walk);
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
exports.Rule = Rule;
|
|
36
|
-
Rule.metadata = {
|
|
37
|
-
ruleName: "prefer-declare-function",
|
|
38
|
-
description: "Forbids `export const x = () => void`.",
|
|
39
|
-
optionsDescription: "Not configurable.",
|
|
40
|
-
options: null,
|
|
41
|
-
type: "style",
|
|
42
|
-
typescriptOnly: true,
|
|
43
|
-
};
|
|
44
|
-
Rule.FAILURE_STRING = (0, util_1.failure)(Rule.metadata.ruleName, "Use a function declaration instead of a variable of function type.");
|
|
45
|
-
function walk(ctx) {
|
|
46
|
-
(0, util_1.eachModuleStatement)(ctx.sourceFile, (statement) => {
|
|
47
|
-
if (ts.isVariableStatement(statement)) {
|
|
48
|
-
for (const varDecl of statement.declarationList.declarations) {
|
|
49
|
-
if (varDecl.type !== undefined && varDecl.type.kind === ts.SyntaxKind.FunctionType) {
|
|
50
|
-
ctx.addFailureAtNode(varDecl, Rule.FAILURE_STRING);
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
});
|
|
55
|
-
}
|
|
56
|
-
//# sourceMappingURL=preferDeclareFunctionRule.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"preferDeclareFunctionRule.js","sourceRoot":"","sources":["../../src/rules/preferDeclareFunctionRule.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,6CAA+B;AAC/B,+CAAiC;AAEjC,kCAAuD;AAEvD,MAAa,IAAK,SAAQ,IAAI,CAAC,KAAK,CAAC,YAAY;IAe/C,KAAK,CAAC,UAAyB;QAC7B,OAAO,IAAI,CAAC,iBAAiB,CAAC,UAAU,EAAE,IAAI,CAAC,CAAC;IAClD,CAAC;;AAjBH,oBAkBC;AAjBQ,aAAQ,GAAuB;IACpC,QAAQ,EAAE,yBAAyB;IACnC,WAAW,EAAE,wCAAwC;IACrD,kBAAkB,EAAE,mBAAmB;IACvC,OAAO,EAAE,IAAI;IACb,IAAI,EAAE,OAAO;IACb,cAAc,EAAE,IAAI;CACrB,CAAC;AAEK,mBAAc,GAAG,IAAA,cAAO,EAC7B,IAAI,CAAC,QAAQ,CAAC,QAAQ,EACtB,oEAAoE,CACrE,CAAC;AAOJ,SAAS,IAAI,CAAC,GAA2B;IACvC,IAAA,0BAAmB,EAAC,GAAG,CAAC,UAAU,EAAE,CAAC,SAAS,EAAE,EAAE;QAChD,IAAI,EAAE,CAAC,mBAAmB,CAAC,SAAS,CAAC,EAAE;YACrC,KAAK,MAAM,OAAO,IAAI,SAAS,CAAC,eAAe,CAAC,YAAY,EAAE;gBAC5D,IAAI,OAAO,CAAC,IAAI,KAAK,SAAS,IAAI,OAAO,CAAC,IAAI,CAAC,IAAI,KAAK,EAAE,CAAC,UAAU,CAAC,YAAY,EAAE;oBAClF,GAAG,CAAC,gBAAgB,CAAC,OAAO,EAAE,IAAI,CAAC,cAAc,CAAC,CAAC;iBACpD;aACF;SACF;IACH,CAAC,CAAC,CAAC;AACL,CAAC"}
|
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
import * as Lint from "tslint";
|
|
2
|
-
import * as ts from "typescript";
|
|
3
|
-
|
|
4
|
-
import { failure } from "../util";
|
|
5
|
-
|
|
6
|
-
export class Rule extends Lint.Rules.AbstractRule {
|
|
7
|
-
static metadata: Lint.IRuleMetadata = {
|
|
8
|
-
ruleName: "no-any-union",
|
|
9
|
-
description: "Forbid a union to contain `any`",
|
|
10
|
-
optionsDescription: "Not configurable.",
|
|
11
|
-
options: null,
|
|
12
|
-
type: "functionality",
|
|
13
|
-
typescriptOnly: true,
|
|
14
|
-
};
|
|
15
|
-
|
|
16
|
-
static FAILURE_STRING = failure(
|
|
17
|
-
Rule.metadata.ruleName,
|
|
18
|
-
"Including `any` in a union will override all other members of the union."
|
|
19
|
-
);
|
|
20
|
-
|
|
21
|
-
apply(sourceFile: ts.SourceFile): Lint.RuleFailure[] {
|
|
22
|
-
return this.applyWithFunction(sourceFile, walk);
|
|
23
|
-
}
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
function walk(ctx: Lint.WalkContext<void>): void {
|
|
27
|
-
ctx.sourceFile.forEachChild(function recur(node) {
|
|
28
|
-
if (node.kind === ts.SyntaxKind.AnyKeyword && ts.isUnionTypeNode(node.parent!)) {
|
|
29
|
-
ctx.addFailureAtNode(node, Rule.FAILURE_STRING);
|
|
30
|
-
}
|
|
31
|
-
node.forEachChild(recur);
|
|
32
|
-
});
|
|
33
|
-
}
|
|
@@ -1,115 +0,0 @@
|
|
|
1
|
-
import * as Lint from "tslint";
|
|
2
|
-
import * as ts from "typescript";
|
|
3
|
-
|
|
4
|
-
import { failure } from "../util";
|
|
5
|
-
|
|
6
|
-
export class Rule extends Lint.Rules.TypedRule {
|
|
7
|
-
static metadata: Lint.IRuleMetadata = {
|
|
8
|
-
ruleName: "no-unnecessary-generics",
|
|
9
|
-
description: "Forbids signatures using a generic parameter only once.",
|
|
10
|
-
optionsDescription: "Not configurable.",
|
|
11
|
-
options: null,
|
|
12
|
-
type: "style",
|
|
13
|
-
typescriptOnly: true,
|
|
14
|
-
};
|
|
15
|
-
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
16
|
-
static FAILURE_STRING(typeParameter: string) {
|
|
17
|
-
return failure(Rule.metadata.ruleName, `Type parameter ${typeParameter} is used only once.`);
|
|
18
|
-
}
|
|
19
|
-
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
20
|
-
static FAILURE_STRING_NEVER(typeParameter: string) {
|
|
21
|
-
return failure(Rule.metadata.ruleName, `Type parameter ${typeParameter} is never used.`);
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
applyWithProgram(sourceFile: ts.SourceFile, program: ts.Program): Lint.RuleFailure[] {
|
|
25
|
-
return this.applyWithFunction(sourceFile, (ctx) => walk(ctx, program.getTypeChecker()));
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
function walk(ctx: Lint.WalkContext<void>, checker: ts.TypeChecker): void {
|
|
30
|
-
const { sourceFile } = ctx;
|
|
31
|
-
sourceFile.forEachChild(function cb(node) {
|
|
32
|
-
if (ts.isFunctionLike(node)) {
|
|
33
|
-
checkSignature(node);
|
|
34
|
-
}
|
|
35
|
-
node.forEachChild(cb);
|
|
36
|
-
});
|
|
37
|
-
|
|
38
|
-
function checkSignature(sig: ts.SignatureDeclaration) {
|
|
39
|
-
if (!sig.typeParameters) {
|
|
40
|
-
return;
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
for (const tp of sig.typeParameters) {
|
|
44
|
-
const typeParameter = tp.name.text;
|
|
45
|
-
const res = getSoleUse(sig, assertDefined(checker.getSymbolAtLocation(tp.name)), checker);
|
|
46
|
-
switch (res.type) {
|
|
47
|
-
case "ok":
|
|
48
|
-
break;
|
|
49
|
-
case "sole":
|
|
50
|
-
ctx.addFailureAtNode(res.soleUse, Rule.FAILURE_STRING(typeParameter));
|
|
51
|
-
break;
|
|
52
|
-
case "never":
|
|
53
|
-
ctx.addFailureAtNode(tp, Rule.FAILURE_STRING_NEVER(typeParameter));
|
|
54
|
-
break;
|
|
55
|
-
default:
|
|
56
|
-
assertNever(res);
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
type Result = { type: "ok" | "never" } | { type: "sole"; soleUse: ts.Identifier };
|
|
63
|
-
function getSoleUse(sig: ts.SignatureDeclaration, typeParameterSymbol: ts.Symbol, checker: ts.TypeChecker): Result {
|
|
64
|
-
const exit = {};
|
|
65
|
-
let soleUse: ts.Identifier | undefined;
|
|
66
|
-
|
|
67
|
-
try {
|
|
68
|
-
if (sig.typeParameters) {
|
|
69
|
-
for (const tp of sig.typeParameters) {
|
|
70
|
-
if (tp.constraint) {
|
|
71
|
-
recur(tp.constraint);
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
for (const param of sig.parameters) {
|
|
76
|
-
if (param.type) {
|
|
77
|
-
recur(param.type);
|
|
78
|
-
}
|
|
79
|
-
}
|
|
80
|
-
if (sig.type) {
|
|
81
|
-
recur(sig.type);
|
|
82
|
-
}
|
|
83
|
-
} catch (err) {
|
|
84
|
-
if (err === exit) {
|
|
85
|
-
return { type: "ok" };
|
|
86
|
-
}
|
|
87
|
-
throw err;
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
return soleUse ? { type: "sole", soleUse } : { type: "never" };
|
|
91
|
-
|
|
92
|
-
function recur(node: ts.Node): void {
|
|
93
|
-
if (ts.isIdentifier(node)) {
|
|
94
|
-
if (checker.getSymbolAtLocation(node) === typeParameterSymbol) {
|
|
95
|
-
if (soleUse === undefined) {
|
|
96
|
-
soleUse = node;
|
|
97
|
-
} else {
|
|
98
|
-
throw exit;
|
|
99
|
-
}
|
|
100
|
-
}
|
|
101
|
-
} else {
|
|
102
|
-
node.forEachChild(recur);
|
|
103
|
-
}
|
|
104
|
-
}
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
function assertDefined<T>(value: T | undefined): T {
|
|
108
|
-
if (value === undefined) {
|
|
109
|
-
throw new Error("unreachable");
|
|
110
|
-
}
|
|
111
|
-
return value;
|
|
112
|
-
}
|
|
113
|
-
function assertNever(_: never) {
|
|
114
|
-
throw new Error("unreachable");
|
|
115
|
-
}
|
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
import * as Lint from "tslint";
|
|
2
|
-
import * as ts from "typescript";
|
|
3
|
-
|
|
4
|
-
import { eachModuleStatement, failure } from "../util";
|
|
5
|
-
|
|
6
|
-
export class Rule extends Lint.Rules.AbstractRule {
|
|
7
|
-
static metadata: Lint.IRuleMetadata = {
|
|
8
|
-
ruleName: "prefer-declare-function",
|
|
9
|
-
description: "Forbids `export const x = () => void`.",
|
|
10
|
-
optionsDescription: "Not configurable.",
|
|
11
|
-
options: null,
|
|
12
|
-
type: "style",
|
|
13
|
-
typescriptOnly: true,
|
|
14
|
-
};
|
|
15
|
-
|
|
16
|
-
static FAILURE_STRING = failure(
|
|
17
|
-
Rule.metadata.ruleName,
|
|
18
|
-
"Use a function declaration instead of a variable of function type."
|
|
19
|
-
);
|
|
20
|
-
|
|
21
|
-
apply(sourceFile: ts.SourceFile): Lint.RuleFailure[] {
|
|
22
|
-
return this.applyWithFunction(sourceFile, walk);
|
|
23
|
-
}
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
function walk(ctx: Lint.WalkContext<void>): void {
|
|
27
|
-
eachModuleStatement(ctx.sourceFile, (statement) => {
|
|
28
|
-
if (ts.isVariableStatement(statement)) {
|
|
29
|
-
for (const varDecl of statement.declarationList.declarations) {
|
|
30
|
-
if (varDecl.type !== undefined && varDecl.type.kind === ts.SyntaxKind.FunctionType) {
|
|
31
|
-
ctx.addFailureAtNode(varDecl, Rule.FAILURE_STRING);
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
});
|
|
36
|
-
}
|
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
interface I {
|
|
2
|
-
<T>(value: T): void;
|
|
3
|
-
~ [0]
|
|
4
|
-
m<T>(x: T): void;
|
|
5
|
-
~ [0]
|
|
6
|
-
}
|
|
7
|
-
|
|
8
|
-
class C {
|
|
9
|
-
constructor<T>(x: T) {}
|
|
10
|
-
~ [0]
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
type Fn = <T>() => T;
|
|
14
|
-
~ [0]
|
|
15
|
-
type Ctr = new<T>() => T;
|
|
16
|
-
~ [0]
|
|
17
|
-
|
|
18
|
-
function f<T>(): T { }
|
|
19
|
-
~ [0]
|
|
20
|
-
|
|
21
|
-
const f = function<T>(): T {};
|
|
22
|
-
~ [0]
|
|
23
|
-
const f2 = <T>(): T => {};
|
|
24
|
-
~ [0]
|
|
25
|
-
|
|
26
|
-
function f<T>(x: { T: number }): void;
|
|
27
|
-
~ [Type parameter T is never used. See: https://github.com/microsoft/DefinitelyTyped-tools/blob/master/packages/dtslint/docs/no-unnecessary-generics.md]
|
|
28
|
-
|
|
29
|
-
function f<T, U extends T>(u: U): U;
|
|
30
|
-
~ [0]
|
|
31
|
-
|
|
32
|
-
// OK:
|
|
33
|
-
// Uses type parameter twice
|
|
34
|
-
function foo<T>(m: Map<T, T>): void {}
|
|
35
|
-
// `T` appears in a constraint, so it appears twice.
|
|
36
|
-
function f<T, U extends T>(t: T, u: U): U;
|
|
37
|
-
|
|
38
|
-
[0]: Type parameter T is used only once. See: https://github.com/microsoft/DefinitelyTyped-tools/blob/master/packages/dtslint/docs/no-unnecessary-generics.md
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{}
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
export const x: () => void;
|
|
2
|
-
~~~~~~~~~~~~~ [0]
|
|
3
|
-
|
|
4
|
-
namespace N {
|
|
5
|
-
const x: () => void;
|
|
6
|
-
~~~~~~~~~~~~~ [0]
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
[0]: Use a function declaration instead of a variable of function type. See: https://github.com/microsoft/DefinitelyTyped-tools/blob/master/packages/dtslint/docs/prefer-declare-function.md
|