@definitelytyped/dtslint 0.0.95-next.1 → 0.0.97-next.0

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.
Files changed (95) hide show
  1. package/README.md +1 -1
  2. package/bin/src/checks.d.ts +7 -0
  3. package/bin/src/checks.js +133 -0
  4. package/bin/src/checks.js.map +1 -0
  5. package/bin/src/index.d.ts +2 -0
  6. package/bin/src/index.js +233 -0
  7. package/bin/src/index.js.map +1 -0
  8. package/bin/src/lint.d.ts +6 -0
  9. package/bin/src/lint.js +194 -0
  10. package/bin/src/lint.js.map +1 -0
  11. package/bin/src/rules/dtHeaderRule.d.ts +6 -0
  12. package/bin/src/rules/dtHeaderRule.js +62 -0
  13. package/bin/src/rules/dtHeaderRule.js.map +1 -0
  14. package/bin/src/rules/expectRule.d.ts +23 -0
  15. package/bin/src/rules/expectRule.js +346 -0
  16. package/bin/src/rules/expectRule.js.map +1 -0
  17. package/bin/src/rules/exportJustNamespaceRule.d.ts +7 -0
  18. package/bin/src/rules/exportJustNamespaceRule.js +105 -0
  19. package/bin/src/rules/exportJustNamespaceRule.js.map +1 -0
  20. package/bin/src/rules/noAnyUnionRule.d.ts +7 -0
  21. package/bin/src/rules/noAnyUnionRule.js +49 -0
  22. package/bin/src/rules/noAnyUnionRule.js.map +1 -0
  23. package/bin/src/rules/noBadReferenceRule.d.ts +8 -0
  24. package/bin/src/rules/noBadReferenceRule.js +54 -0
  25. package/bin/src/rules/noBadReferenceRule.js.map +1 -0
  26. package/bin/src/rules/noConstEnumRule.d.ts +7 -0
  27. package/bin/src/rules/noConstEnumRule.js +51 -0
  28. package/bin/src/rules/noConstEnumRule.js.map +1 -0
  29. package/bin/src/rules/noDeadReferenceRule.d.ts +7 -0
  30. package/bin/src/rules/noDeadReferenceRule.js +62 -0
  31. package/bin/src/rules/noDeadReferenceRule.js.map +1 -0
  32. package/bin/src/rules/noDeclareCurrentPackageRule.d.ts +6 -0
  33. package/bin/src/rules/noDeclareCurrentPackageRule.js +56 -0
  34. package/bin/src/rules/noDeclareCurrentPackageRule.js.map +1 -0
  35. package/bin/src/rules/noImportDefaultOfExportEqualsRule.d.ts +7 -0
  36. package/bin/src/rules/noImportDefaultOfExportEqualsRule.js +71 -0
  37. package/bin/src/rules/noImportDefaultOfExportEqualsRule.js.map +1 -0
  38. package/bin/src/rules/noOutsideDependenciesRule.d.ts +6 -0
  39. package/bin/src/rules/noOutsideDependenciesRule.js +52 -0
  40. package/bin/src/rules/noOutsideDependenciesRule.js.map +1 -0
  41. package/bin/src/rules/noPaddingRule.d.ts +7 -0
  42. package/bin/src/rules/noPaddingRule.js +98 -0
  43. package/bin/src/rules/noPaddingRule.js.map +1 -0
  44. package/bin/src/rules/noRedundantJsdoc2Rule.d.ts +10 -0
  45. package/bin/src/rules/noRedundantJsdoc2Rule.js +245 -0
  46. package/bin/src/rules/noRedundantJsdoc2Rule.js.map +1 -0
  47. package/bin/src/rules/noRelativeImportInTestRule.d.ts +11 -0
  48. package/bin/src/rules/noRelativeImportInTestRule.js +60 -0
  49. package/bin/src/rules/noRelativeImportInTestRule.js.map +1 -0
  50. package/bin/src/rules/noSelfImportRule.d.ts +6 -0
  51. package/bin/src/rules/noSelfImportRule.js +51 -0
  52. package/bin/src/rules/noSelfImportRule.js.map +1 -0
  53. package/bin/src/rules/noSingleDeclareModuleRule.d.ts +7 -0
  54. package/bin/src/rules/noSingleDeclareModuleRule.js +68 -0
  55. package/bin/src/rules/noSingleDeclareModuleRule.js.map +1 -0
  56. package/bin/src/rules/noSingleElementTupleTypeRule.d.ts +6 -0
  57. package/bin/src/rules/noSingleElementTupleTypeRule.js +50 -0
  58. package/bin/src/rules/noSingleElementTupleTypeRule.js.map +1 -0
  59. package/bin/src/rules/noUnnecessaryGenericsRule.d.ts +8 -0
  60. package/bin/src/rules/noUnnecessaryGenericsRule.js +130 -0
  61. package/bin/src/rules/noUnnecessaryGenericsRule.js.map +1 -0
  62. package/bin/src/rules/noUselessFilesRule.d.ts +7 -0
  63. package/bin/src/rules/noUselessFilesRule.js +46 -0
  64. package/bin/src/rules/noUselessFilesRule.js.map +1 -0
  65. package/bin/src/rules/npmNamingRule.d.ts +21 -0
  66. package/bin/src/rules/npmNamingRule.js +291 -0
  67. package/bin/src/rules/npmNamingRule.js.map +1 -0
  68. package/bin/src/rules/preferDeclareFunctionRule.d.ts +7 -0
  69. package/bin/src/rules/preferDeclareFunctionRule.js +52 -0
  70. package/bin/src/rules/preferDeclareFunctionRule.js.map +1 -0
  71. package/bin/src/rules/redundantUndefinedRule.d.ts +6 -0
  72. package/bin/src/rules/redundantUndefinedRule.js +55 -0
  73. package/bin/src/rules/redundantUndefinedRule.js.map +1 -0
  74. package/bin/src/rules/strictExportDeclareModifiersRule.d.ts +6 -0
  75. package/bin/src/rules/strictExportDeclareModifiersRule.js +162 -0
  76. package/bin/src/rules/strictExportDeclareModifiersRule.js.map +1 -0
  77. package/bin/src/rules/trimFileRule.d.ts +8 -0
  78. package/bin/src/rules/trimFileRule.js +51 -0
  79. package/bin/src/rules/trimFileRule.js.map +1 -0
  80. package/bin/src/rules/voidReturnRule.d.ts +7 -0
  81. package/bin/src/rules/voidReturnRule.js +85 -0
  82. package/bin/src/rules/voidReturnRule.js.map +1 -0
  83. package/bin/src/suggestions.d.ts +12 -0
  84. package/bin/src/suggestions.js +62 -0
  85. package/bin/src/suggestions.js.map +1 -0
  86. package/bin/src/updateConfig.d.ts +1 -0
  87. package/bin/src/updateConfig.js +220 -0
  88. package/bin/src/updateConfig.js.map +1 -0
  89. package/bin/src/util.d.ts +12 -0
  90. package/bin/src/util.js +130 -0
  91. package/bin/src/util.js.map +1 -0
  92. package/bin/tsconfig.tsbuildinfo +1 -0
  93. package/dtslint-expect-only.json +1 -1
  94. package/dtslint.json +1 -1
  95. package/package.json +7 -6
@@ -0,0 +1,6 @@
1
+ import * as Lint from "tslint";
2
+ import * as ts from "typescript";
3
+ export declare class Rule extends Lint.Rules.AbstractRule {
4
+ static metadata: Lint.IRuleMetadata;
5
+ apply(sourceFile: ts.SourceFile): Lint.RuleFailure[];
6
+ }
@@ -0,0 +1,162 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
5
+ }) : (function(o, m, k, k2) {
6
+ if (k2 === undefined) k2 = k;
7
+ o[k2] = m[k];
8
+ }));
9
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
10
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
11
+ }) : function(o, v) {
12
+ o["default"] = v;
13
+ });
14
+ var __importStar = (this && this.__importStar) || function (mod) {
15
+ if (mod && mod.__esModule) return mod;
16
+ var result = {};
17
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
18
+ __setModuleDefault(result, mod);
19
+ return result;
20
+ };
21
+ Object.defineProperty(exports, "__esModule", { value: true });
22
+ exports.Rule = void 0;
23
+ const Lint = __importStar(require("tslint"));
24
+ const ts = __importStar(require("typescript"));
25
+ const util_1 = require("../util");
26
+ class Rule extends Lint.Rules.AbstractRule {
27
+ apply(sourceFile) {
28
+ return this.applyWithFunction(sourceFile, walk);
29
+ }
30
+ }
31
+ exports.Rule = Rule;
32
+ Rule.metadata = {
33
+ ruleName: "strict-export-declare-modifiers",
34
+ description: "Enforces strict rules about where the 'export' and 'declare' modifiers may appear.",
35
+ optionsDescription: "Not configurable.",
36
+ options: null,
37
+ type: "style",
38
+ typescriptOnly: true
39
+ };
40
+ function walk(ctx) {
41
+ const { sourceFile } = ctx;
42
+ const isExternal = sourceFile.isDeclarationFile &&
43
+ !sourceFile.statements.some(s => s.kind === ts.SyntaxKind.ExportAssignment ||
44
+ (s.kind === ts.SyntaxKind.ExportDeclaration && !!s.exportClause)) &&
45
+ ts.isExternalModule(sourceFile);
46
+ for (const node of sourceFile.statements) {
47
+ if (isExternal) {
48
+ checkInExternalModule(node, isAutomaticExport(sourceFile));
49
+ }
50
+ else {
51
+ checkInOther(node, sourceFile.isDeclarationFile);
52
+ }
53
+ if (isModuleDeclaration(node) && (sourceFile.isDeclarationFile || isDeclare(node))) {
54
+ checkModule(node);
55
+ }
56
+ }
57
+ function checkInExternalModule(node, autoExportEnabled) {
58
+ // Ignore certain node kinds (these can't have 'export' or 'default' modifiers)
59
+ switch (node.kind) {
60
+ case ts.SyntaxKind.ImportDeclaration:
61
+ case ts.SyntaxKind.ImportEqualsDeclaration:
62
+ case ts.SyntaxKind.ExportDeclaration:
63
+ case ts.SyntaxKind.NamespaceExportDeclaration:
64
+ return;
65
+ }
66
+ // `declare global` and `declare module "foo"` OK. `declare namespace N` not OK, should be `export namespace`.
67
+ if (!isDeclareGlobalOrExternalModuleDeclaration(node)) {
68
+ if (isDeclare(node)) {
69
+ fail(mod(node, ts.SyntaxKind.DeclareKeyword), "'declare' keyword is redundant here.");
70
+ }
71
+ if (autoExportEnabled && !isExport(node)) {
72
+ fail(node.name || node, "All declarations in this module are exported automatically. " +
73
+ "Prefer to explicitly write 'export' for clarity. " +
74
+ "If you have a good reason not to export this declaration, " +
75
+ "add 'export {}' to the module to shut off automatic exporting.");
76
+ }
77
+ }
78
+ }
79
+ function checkInOther(node, inDeclarationFile) {
80
+ // Compiler will enforce presence of 'declare' where necessary. But types do not need 'declare'.
81
+ if (isDeclare(node)) {
82
+ if ((isExport(node) && inDeclarationFile) ||
83
+ node.kind === ts.SyntaxKind.InterfaceDeclaration ||
84
+ node.kind === ts.SyntaxKind.TypeAliasDeclaration) {
85
+ fail(mod(node, ts.SyntaxKind.DeclareKeyword), "'declare' keyword is redundant here.");
86
+ }
87
+ }
88
+ }
89
+ function fail(node, reason) {
90
+ ctx.addFailureAtNode(node, util_1.failure(Rule.metadata.ruleName, reason));
91
+ }
92
+ function mod(node, kind) {
93
+ return node.modifiers.find(m => m.kind === kind);
94
+ }
95
+ function checkModule(moduleDeclaration) {
96
+ const body = moduleDeclaration.body;
97
+ if (!body) {
98
+ return;
99
+ }
100
+ switch (body.kind) {
101
+ case ts.SyntaxKind.ModuleDeclaration:
102
+ checkModule(body);
103
+ break;
104
+ case ts.SyntaxKind.ModuleBlock:
105
+ checkBlock(body, isAutomaticExport(moduleDeclaration));
106
+ break;
107
+ }
108
+ }
109
+ function checkBlock(block, autoExportEnabled) {
110
+ for (const s of block.statements) {
111
+ // Compiler will error for 'declare' here anyway, so just check for 'export'.
112
+ if (isExport(s) && autoExportEnabled && !isDefault(s)) {
113
+ fail(mod(s, ts.SyntaxKind.ExportKeyword), "'export' keyword is redundant here because " +
114
+ "all declarations in this module are exported automatically. " +
115
+ "If you have a good reason to export some declarations and not others, " +
116
+ "add 'export {}' to the module to shut off automatic exporting.");
117
+ }
118
+ if (isModuleDeclaration(s)) {
119
+ checkModule(s);
120
+ }
121
+ }
122
+ }
123
+ }
124
+ function isDeclareGlobalOrExternalModuleDeclaration(node) {
125
+ return (isModuleDeclaration(node) &&
126
+ (node.name.kind === ts.SyntaxKind.StringLiteral ||
127
+ (node.name.kind === ts.SyntaxKind.Identifier && node.name.text === "global")));
128
+ }
129
+ function isModuleDeclaration(node) {
130
+ return node.kind === ts.SyntaxKind.ModuleDeclaration;
131
+ }
132
+ function isDeclare(node) {
133
+ return Lint.hasModifier(node.modifiers, ts.SyntaxKind.DeclareKeyword);
134
+ }
135
+ function isExport(node) {
136
+ return Lint.hasModifier(node.modifiers, ts.SyntaxKind.ExportKeyword);
137
+ }
138
+ function isDefault(node) {
139
+ return Lint.hasModifier(node.modifiers, ts.SyntaxKind.DefaultKeyword);
140
+ }
141
+ // tslint:disable-next-line:max-line-length
142
+ // Copied from https://github.com/Microsoft/TypeScript/blob/dd9b8cab34a3e389e924d768eb656cf50656f582/src/compiler/binder.ts#L1571-L1581
143
+ function hasExportDeclarations(node) {
144
+ const body = node.kind === ts.SyntaxKind.SourceFile ? node : node.body;
145
+ if (body && (body.kind === ts.SyntaxKind.SourceFile || body.kind === ts.SyntaxKind.ModuleBlock)) {
146
+ for (const stat of body.statements) {
147
+ if (stat.kind === ts.SyntaxKind.ExportDeclaration || stat.kind === ts.SyntaxKind.ExportAssignment) {
148
+ return true;
149
+ }
150
+ }
151
+ }
152
+ return false;
153
+ }
154
+ function isAutomaticExport(node) {
155
+ // We'd like to just test ts.NodeFlags.ExportContext, but we don't run the
156
+ // binder, so that flag won't be set, so duplicate the logic instead. :(
157
+ //
158
+ // ts.NodeFlags.Ambient is @internal, but all modules that get here should
159
+ // be ambient.
160
+ return !hasExportDeclarations(node);
161
+ }
162
+ //# sourceMappingURL=strictExportDeclareModifiersRule.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"strictExportDeclareModifiersRule.js","sourceRoot":"","sources":["../../../src/rules/strictExportDeclareModifiersRule.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;AAAA,6CAA+B;AAC/B,+CAAiC;AAEjC,kCAAkC;AAElC,MAAa,IAAK,SAAQ,IAAI,CAAC,KAAK,CAAC,YAAY;IAU/C,KAAK,CAAC,UAAyB;QAC7B,OAAO,IAAI,CAAC,iBAAiB,CAAC,UAAU,EAAE,IAAI,CAAC,CAAC;IAClD,CAAC;;AAZH,oBAaC;AAZQ,aAAQ,GAAuB;IACpC,QAAQ,EAAE,iCAAiC;IAC3C,WAAW,EAAE,oFAAoF;IACjG,kBAAkB,EAAE,mBAAmB;IACvC,OAAO,EAAE,IAAI;IACb,IAAI,EAAE,OAAO;IACb,cAAc,EAAE,IAAI;CACrB,CAAC;AAOJ,SAAS,IAAI,CAAC,GAA2B;IACvC,MAAM,EAAE,UAAU,EAAE,GAAG,GAAG,CAAC;IAC3B,MAAM,UAAU,GACd,UAAU,CAAC,iBAAiB;QAC5B,CAAC,UAAU,CAAC,UAAU,CAAC,IAAI,CACzB,CAAC,CAAC,EAAE,CACF,CAAC,CAAC,IAAI,KAAK,EAAE,CAAC,UAAU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ED,SAAS,SAAS,CAAC,IAAa;IAC9B,OAAO,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC,SAAS,EAAE,EAAE,CAAC,UAAU,CAAC,cAAc,CAAC,CAAC;AACxE,CAAC;AAED,2CAA2C;AAC3C,uIAAuI;AACvI,SAAS,qBAAqB,CAAC,IAA0C;IACvE,MAAM,IAAI,GAAG,IAAI,CAAC,IAAI,KAAK,EAAE,CAAC,UAAU,CAAC,UAAU,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC;IACvE,IAAI,IAAI,IAAI,CAAC,IAAI,CAAC,IAAI,KAAK,EAAE,CAAC,UAAU,CAAC,UAAU,IAAI,IAAI,CAAC,IAAI,KAAK,EAAE,CAAC,UAAU,CAAC,WAAW,CAAC,EAAE;QAC/F,KAAK,MAAM,IAAI,IAAK,IAAqB,CAAC,UAAU,EAAE;YACpD,IAAI,IAAI,CAAC,IAAI,KAAK,EAAE,CAAC,UAAU,CAAC,iBAAiB,IAAI,IAAI,CAAC,IAAI,KAAK,EAAE,CAAC,UAAU,CAAC,gBAAgB,EAAE;gBACjG,OAAO,IAAI,CAAC;aACb;SACF;KACF;IACD,OAAO,KAAK,CAAC;AACf,CAAC;AAED,SAAS,iBAAiB,CAAC,IAA0C;IACnE,0EAA0E;IAC1E,wEAAwE;IACxE,EAAE;IACF,0EAA0E;IAC1E,cAAc;IACd,OAAO,CAAC,qBAAqB,CAAC,IAAI,CAAC,CAAC;AACtC,CAAC"}
@@ -0,0 +1,8 @@
1
+ import * as Lint from "tslint";
2
+ import * as ts from "typescript";
3
+ export declare class Rule extends Lint.Rules.AbstractRule {
4
+ static metadata: Lint.IRuleMetadata;
5
+ static FAILURE_STRING_LEADING: string;
6
+ static FAILURE_STRING_TRAILING: string;
7
+ apply(sourceFile: ts.SourceFile): Lint.RuleFailure[];
8
+ }
@@ -0,0 +1,51 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
5
+ }) : (function(o, m, k, k2) {
6
+ if (k2 === undefined) k2 = k;
7
+ o[k2] = m[k];
8
+ }));
9
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
10
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
11
+ }) : function(o, v) {
12
+ o["default"] = v;
13
+ });
14
+ var __importStar = (this && this.__importStar) || function (mod) {
15
+ if (mod && mod.__esModule) return mod;
16
+ var result = {};
17
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
18
+ __setModuleDefault(result, mod);
19
+ return result;
20
+ };
21
+ Object.defineProperty(exports, "__esModule", { value: true });
22
+ exports.Rule = void 0;
23
+ const Lint = __importStar(require("tslint"));
24
+ const util_1 = require("../util");
25
+ class Rule extends Lint.Rules.AbstractRule {
26
+ apply(sourceFile) {
27
+ return this.applyWithFunction(sourceFile, walk);
28
+ }
29
+ }
30
+ exports.Rule = Rule;
31
+ Rule.metadata = {
32
+ ruleName: "trim-file",
33
+ description: "Forbids leading/trailing blank lines in a file. Allows file to end in '\n'.",
34
+ optionsDescription: "Not configurable.",
35
+ options: null,
36
+ type: "style",
37
+ typescriptOnly: false
38
+ };
39
+ Rule.FAILURE_STRING_LEADING = util_1.failure(Rule.metadata.ruleName, "File should not begin with a blank line.");
40
+ Rule.FAILURE_STRING_TRAILING = util_1.failure(Rule.metadata.ruleName, "File should not end with a blank line. (Ending in one newline OK, ending in two newlines not OK.)");
41
+ function walk(ctx) {
42
+ const { sourceFile: { text } } = ctx;
43
+ if (text.startsWith("\r") || text.startsWith("\n")) {
44
+ ctx.addFailureAt(0, 0, Rule.FAILURE_STRING_LEADING);
45
+ }
46
+ if (text.endsWith("\n\n") || text.endsWith("\r\n\r\n")) {
47
+ const start = text.endsWith("\r\n") ? text.length - 2 : text.length - 1;
48
+ ctx.addFailureAt(start, 0, Rule.FAILURE_STRING_TRAILING);
49
+ }
50
+ }
51
+ //# sourceMappingURL=trimFileRule.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"trimFileRule.js","sourceRoot":"","sources":["../../../src/rules/trimFileRule.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;AAAA,6CAA+B;AAG/B,kCAAkC;AAElC,MAAa,IAAK,SAAQ,IAAI,CAAC,KAAK,CAAC,YAAY;IAgB/C,KAAK,CAAC,UAAyB;QAC7B,OAAO,IAAI,CAAC,iBAAiB,CAAC,UAAU,EAAE,IAAI,CAAC,CAAC;IAClD,CAAC;;AAlBH,oBAmBC;AAlBQ,aAAQ,GAAuB;IACpC,QAAQ,EAAE,WAAW;IACrB,WAAW,EAAE,6EAA6E;IAC1F,kBAAkB,EAAE,mBAAmB;IACvC,OAAO,EAAE,IAAI;IACb,IAAI,EAAE,OAAO;IACb,cAAc,EAAE,KAAK;CACtB,CAAC;AAEK,2BAAsB,GAAG,cAAO,CAAC,IAAI,CAAC,QAAQ,CAAC,QAAQ,EAAE,0CAA0C,CAAC,CAAC;AACrG,4BAAuB,GAAG,cAAO,CACtC,IAAI,CAAC,QAAQ,CAAC,QAAQ,EACtB,mGAAmG,CACpG,CAAC;AAOJ,SAAS,IAAI,CAAC,GAA2B;IACvC,MAAM,EACJ,UAAU,EAAE,EAAE,IAAI,EAAE,EACrB,GAAG,GAAG,CAAC;IACR,IAAI,IAAI,CAAC,UAAU,CAAC,IAAI,CAAC,IAAI,IAAI,CAAC,UAAU,CAAC,IAAI,CAAC,EAAE;QAClD,GAAG,CAAC,YAAY,CAAC,CAAC,EAAE,CAAC,EAAE,IAAI,CAAC,sBAAsB,CAAC,CAAC;KACrD;IAED,IAAI,IAAI,CAAC,QAAQ,CAAC,MAAM,CAAC,IAAI,IAAI,CAAC,QAAQ,CAAC,UAAU,CAAC,EAAE;QACtD,MAAM,KAAK,GAAG,IAAI,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,MAAM,GAAG,CAAC,CAAC;QACxE,GAAG,CAAC,YAAY,CAAC,KAAK,EAAE,CAAC,EAAE,IAAI,CAAC,uBAAuB,CAAC,CAAC;KAC1D;AACH,CAAC"}
@@ -0,0 +1,7 @@
1
+ import * as Lint from "tslint";
2
+ import * as ts from "typescript";
3
+ export declare class Rule extends Lint.Rules.AbstractRule {
4
+ static metadata: Lint.IRuleMetadata;
5
+ static FAILURE_STRING: string;
6
+ apply(sourceFile: ts.SourceFile): Lint.RuleFailure[];
7
+ }
@@ -0,0 +1,85 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
5
+ }) : (function(o, m, k, k2) {
6
+ if (k2 === undefined) k2 = k;
7
+ o[k2] = m[k];
8
+ }));
9
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
10
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
11
+ }) : function(o, v) {
12
+ o["default"] = v;
13
+ });
14
+ var __importStar = (this && this.__importStar) || function (mod) {
15
+ if (mod && mod.__esModule) return mod;
16
+ var result = {};
17
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
18
+ __setModuleDefault(result, mod);
19
+ return result;
20
+ };
21
+ Object.defineProperty(exports, "__esModule", { value: true });
22
+ exports.Rule = void 0;
23
+ const Lint = __importStar(require("tslint"));
24
+ const ts = __importStar(require("typescript"));
25
+ const util_1 = require("../util");
26
+ class Rule extends Lint.Rules.AbstractRule {
27
+ apply(sourceFile) {
28
+ return this.applyWithFunction(sourceFile, walk);
29
+ }
30
+ }
31
+ exports.Rule = Rule;
32
+ Rule.metadata = {
33
+ ruleName: "void-return",
34
+ description: "`void` may only be used as a return type.",
35
+ rationale: "style",
36
+ optionsDescription: "Not configurable.",
37
+ options: null,
38
+ type: "style",
39
+ typescriptOnly: true
40
+ };
41
+ Rule.FAILURE_STRING = util_1.failure(Rule.metadata.ruleName, "Use the `void` type for return types only. Otherwise, use `undefined`.");
42
+ function walk(ctx) {
43
+ ctx.sourceFile.forEachChild(function cb(node) {
44
+ if (node.kind === ts.SyntaxKind.VoidKeyword && !mayContainVoid(node.parent) && !isReturnType(node)) {
45
+ ctx.addFailureAtNode(node, Rule.FAILURE_STRING);
46
+ }
47
+ else {
48
+ node.forEachChild(cb);
49
+ }
50
+ });
51
+ }
52
+ function mayContainVoid({ kind }) {
53
+ switch (kind) {
54
+ case ts.SyntaxKind.TypeReference:
55
+ case ts.SyntaxKind.ExpressionWithTypeArguments:
56
+ case ts.SyntaxKind.NewExpression:
57
+ case ts.SyntaxKind.CallExpression:
58
+ case ts.SyntaxKind.TypeParameter: // Allow f<T = void>
59
+ return true;
60
+ default:
61
+ return false;
62
+ }
63
+ }
64
+ function isReturnType(node) {
65
+ let parent = node.parent;
66
+ if (parent.kind === ts.SyntaxKind.UnionType) {
67
+ [node, parent] = [parent, parent.parent];
68
+ }
69
+ return isSignatureDeclaration(parent) && parent.type === node;
70
+ }
71
+ function isSignatureDeclaration(node) {
72
+ switch (node.kind) {
73
+ case ts.SyntaxKind.ArrowFunction:
74
+ case ts.SyntaxKind.CallSignature:
75
+ case ts.SyntaxKind.FunctionDeclaration:
76
+ case ts.SyntaxKind.FunctionExpression:
77
+ case ts.SyntaxKind.FunctionType:
78
+ case ts.SyntaxKind.MethodDeclaration:
79
+ case ts.SyntaxKind.MethodSignature:
80
+ return true;
81
+ default:
82
+ return false;
83
+ }
84
+ }
85
+ //# sourceMappingURL=voidReturnRule.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"voidReturnRule.js","sourceRoot":"","sources":["../../../src/rules/voidReturnRule.ts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AAC,UAAU,CAAC,cAAc,CAAC;QAClC,KAAK,EAAE,CAAC,UAAU,CAAC,aAAa,EAAE,oBAAoB;YACpD,OAAO,IAAI,CAAC;QACd;YACE,OAAO,KAAK,CAAC;KAChB;AACH,CAAC;AAED,SAAS,YAAY,CAAC,IAAa;IACjC,IAAI,MAAM,GAAG,IAAI,CAAC,MAAO,CAAC;IAC1B,IAAI,MAAM,CAAC,IAAI,KAAK,EAAE,CAAC,UAAU,CAAC,SAAS,EAAE;QAC3C,CAAC,IAAI,EAAE,MAAM,CAAC,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,MAAO,CAAC,CAAC;KAC3C;IACD,OAAO,sBAAsB,CAAC,MAAM,CAAC,IAAI,MAAM,CAAC,IAAI,KAAK,IAAI,CAAC;AAChE,CAAC;AAED,SAAS,sBAAsB,CAAC,IAAa;IAC3C,QAAQ,IAAI,CAAC,IAAI,EAAE;QACjB,KAAK,EAAE,CAAC,UAAU,CAAC,aAAa,CAAC;QACjC,KAAK,EAAE,CAAC,UAAU,CAAC,aAAa,CAAC;QACjC,KAAK,EAAE,CAAC,UAAU,CAAC,mBAAmB,CAAC;QACvC,KAAK,EAAE,CAAC,UAAU,CAAC,kBAAkB,CAAC;QACtC,KAAK,EAAE,CAAC,UAAU,CAAC,YAAY,CAAC;QAChC,KAAK,EAAE,CAAC,UAAU,CAAC,iBAAiB,CAAC;QACrC,KAAK,EAAE,CAAC,UAAU,CAAC,eAAe;YAChC,OAAO,IAAI,CAAC;QACd;YACE,OAAO,KAAK,CAAC;KAChB;AACH,CAAC"}
@@ -0,0 +1,12 @@
1
+ import { WalkContext } from "tslint";
2
+ export interface Suggestion {
3
+ fileName: string;
4
+ ruleName: string;
5
+ message: string;
6
+ start?: number;
7
+ width?: number;
8
+ }
9
+ /**
10
+ * A rule should call this function to provide a suggestion instead of a lint failure.
11
+ */
12
+ export declare function addSuggestion<T>(ctx: WalkContext<T>, message: string, start?: number, width?: number): void;
@@ -0,0 +1,62 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.addSuggestion = void 0;
4
+ const fs = require("fs");
5
+ const os = require("os");
6
+ const path = require("path");
7
+ const suggestionsDir = path.join(os.homedir(), ".dts", "suggestions");
8
+ // Packages for which suggestions were already added in this run of dtslint.
9
+ const existingPackages = new Set();
10
+ /**
11
+ * A rule should call this function to provide a suggestion instead of a lint failure.
12
+ */
13
+ function addSuggestion(ctx, message, start, width) {
14
+ const suggestion = {
15
+ fileName: ctx.sourceFile.fileName,
16
+ ruleName: ctx.ruleName,
17
+ message,
18
+ start,
19
+ width
20
+ };
21
+ const packageName = dtPackageName(ctx.sourceFile.fileName);
22
+ if (!packageName) {
23
+ return;
24
+ }
25
+ let flag = "a";
26
+ if (!existingPackages.has(packageName)) {
27
+ flag = "w";
28
+ existingPackages.add(packageName);
29
+ }
30
+ try {
31
+ if (!fs.existsSync(suggestionsDir)) {
32
+ fs.mkdirSync(suggestionsDir, { recursive: true });
33
+ }
34
+ fs.writeFileSync(path.join(suggestionsDir, packageName + ".txt"), flag === "a" ? "\n" + formatSuggestion(suggestion) : formatSuggestion(suggestion), { flag, encoding: "utf8" });
35
+ }
36
+ catch (e) {
37
+ console.log(`Could not write suggestions for package ${packageName}. ${e.message || ""}`);
38
+ }
39
+ }
40
+ exports.addSuggestion = addSuggestion;
41
+ const dtPath = path.join("DefinitelyTyped", "types");
42
+ function dtPackageName(filePath) {
43
+ const dtIndex = filePath.indexOf(dtPath);
44
+ if (dtIndex === -1) {
45
+ return undefined;
46
+ }
47
+ const basePath = filePath.substr(dtIndex + dtPath.length);
48
+ const dirs = basePath.split(path.sep).filter(dir => dir !== "");
49
+ if (dirs.length === 0) {
50
+ return undefined;
51
+ }
52
+ const packageName = dirs[0];
53
+ // Check if this is an old version of a package.
54
+ if (dirs.length > 1 && /^v\d+(\.\d+)?$/.test(dirs[1])) {
55
+ return packageName + dirs[1];
56
+ }
57
+ return packageName;
58
+ }
59
+ function formatSuggestion(suggestion) {
60
+ return JSON.stringify(suggestion, /*replacer*/ undefined, 0);
61
+ }
62
+ //# sourceMappingURL=suggestions.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"suggestions.js","sourceRoot":"","sources":["../../src/suggestions.ts"],"names":[],"mappings":";;;AAAA,yBAA0B;AAC1B,yBAA0B;AAC1B,6BAA8B;AAG9B,MAAM,cAAc,GAAG,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC,OAAO,EAAE,EAAE,MAAM,EAAE,aAAa,CAAC,CAAC;AAUtE,4EAA4E;AAC5E,MAAM,gBAAgB,GAAG,IAAI,GAAG,EAAE,CAAC;AAEnC;;GAEG;AACH,SAAgB,aAAa,CAAI,GAAmB,EAAE,OAAe,EAAE,KAAc,EAAE,KAAc;IACnG,MAAM,UAAU,GAAe;QAC7B,QAAQ,EAAE,GAAG,CAAC,UAAU,CAAC,QAAQ;QACjC,QAAQ,EAAE,GAAG,CAAC,QAAQ;QACtB,OAAO;QACP,KAAK;QACL,KAAK;KACN,CAAC;IAEF,MAAM,WAAW,GAAG,aAAa,CAAC,GAAG,CAAC,UAAU,CAAC,QAAQ,CAAC,CAAC;IAC3D,IAAI,CAAC,WAAW,EAAE;QAChB,OAAO;KACR;IACD,IAAI,IAAI,GAAG,GAAG,CAAC;IACf,IAAI,CAAC,gBAAgB,CAAC,GAAG,CAAC,WAAW,CAAC,EAAE;QACtC,IAAI,GAAG,GAAG,CAAC;QACX,gBAAgB,CAAC,GAAG,CAAC,WAAW,CAAC,CAAC;KACnC;IACD,IAAI;QACF,IAAI,CAAC,EAAE,CAAC,UAAU,CAAC,cAAc,CAAC,EAAE;YAClC,EAAE,CAAC,SAAS,CAAC,cAAc,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAAC;SACnD;QACD,EAAE,CAAC,aAAa,CACd,IAAI,CAAC,IAAI,CAAC,cAAc,EAAE,WAAW,GAAG,MAAM,CAAC,EAC/C,IAAI,KAAK,GAAG,CAAC,CAAC,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E,YAAY,CAAC,SAAS,EAAE,CAAC,CAAC,CAAC;AAC/D,CAAC"}
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,220 @@
1
+ "use strict";
2
+ // This is a stand-alone script that updates TSLint configurations for DefinitelyTyped packages.
3
+ // It runs all rules specified in `dt.json`, and updates the existing configuration for a package
4
+ // by adding rule exemptions only for the rules that caused a lint failure.
5
+ // For example, if a configuration specifies `"no-trailing-whitespace": false` and this rule
6
+ // no longer produces an error, then it will not be disabled in the new configuration.
7
+ // If you update or create a rule and now it causes new failures in DT, you can update the `dt.json`
8
+ // configuration with your rule, then register a disabler function for your rule
9
+ // (check `disableRules` function below), then run this script with your rule as argument.
10
+ Object.defineProperty(exports, "__esModule", { value: true });
11
+ const cp = require("child_process");
12
+ const fs = require("fs");
13
+ const stringify = require("json-stable-stringify");
14
+ const path = require("path");
15
+ const tslint_1 = require("tslint");
16
+ const yargs = require("yargs");
17
+ const lint_1 = require("./lint");
18
+ const npmNamingRule_1 = require("./rules/npmNamingRule");
19
+ // Rule "expect" needs TypeScript version information, which this script doesn't collect.
20
+ const ignoredRules = ["expect"];
21
+ function main() {
22
+ const args = yargs
23
+ .usage(`\`$0 --dt=path-to-dt\` or \`$0 --package=path-to-dt-package\`
24
+ 'dt.json' is used as the base tslint config for running the linter.`)
25
+ .option("package", {
26
+ describe: "Path of DT package.",
27
+ type: "string",
28
+ conflicts: "dt"
29
+ })
30
+ .option("dt", {
31
+ describe: "Path of local DefinitelyTyped repository.",
32
+ type: "string",
33
+ conflicts: "package"
34
+ })
35
+ .option("rules", {
36
+ describe: "Names of the rules to be updated. Leave this empty to update all rules.",
37
+ type: "array",
38
+ string: true,
39
+ default: []
40
+ })
41
+ .check(arg => {
42
+ if (!arg.package && !arg.dt) {
43
+ throw new Error("You must provide either argument 'package' or 'dt'.");
44
+ }
45
+ const unsupportedRules = arg.rules.filter(rule => ignoredRules.includes(rule));
46
+ if (unsupportedRules.length > 0) {
47
+ throw new Error(`Rules ${unsupportedRules.join(", ")} are not supported at the moment.`);
48
+ }
49
+ return true;
50
+ }).argv;
51
+ if (args.package) {
52
+ updatePackage(args.package, dtConfig(args.rules));
53
+ }
54
+ else if (args.dt) {
55
+ updateAll(args.dt, dtConfig(args.rules));
56
+ }
57
+ }
58
+ const dtConfigPath = "dt.json";
59
+ function dtConfig(updatedRules) {
60
+ const config = tslint_1.Configuration.findConfiguration(dtConfigPath).results;
61
+ if (!config) {
62
+ throw new Error(`Could not load config at ${dtConfigPath}.`);
63
+ }
64
+ // Disable ignored or non-updated rules.
65
+ for (const entry of config.rules.entries()) {
66
+ const [rule, ruleOpts] = entry;
67
+ if (ignoredRules.includes(rule) || (updatedRules.length > 0 && !updatedRules.includes(rule))) {
68
+ ruleOpts.ruleSeverity = "off";
69
+ }
70
+ }
71
+ return config;
72
+ }
73
+ function updateAll(dtPath, config) {
74
+ const packages = fs.readdirSync(path.join(dtPath, "types"));
75
+ for (const pkg of packages) {
76
+ updatePackage(path.join(dtPath, "types", pkg), config);
77
+ }
78
+ }
79
+ function updatePackage(pkgPath, baseConfig) {
80
+ installDependencies(pkgPath);
81
+ const packages = walkPackageDir(pkgPath);
82
+ const linterOpts = {
83
+ fix: false
84
+ };
85
+ for (const pkg of packages) {
86
+ const results = pkg.lint(linterOpts, baseConfig);
87
+ if (results.failures.length > 0) {
88
+ const disabledRules = disableRules(results.failures);
89
+ const newConfig = mergeConfigRules(pkg.config(), disabledRules, baseConfig);
90
+ pkg.updateConfig(newConfig);
91
+ }
92
+ }
93
+ }
94
+ function installDependencies(pkgPath) {
95
+ if (fs.existsSync(path.join(pkgPath, "package.json"))) {
96
+ cp.execSync("npm install --ignore-scripts --no-shrinkwrap --no-package-lock --no-bin-links", {
97
+ encoding: "utf8",
98
+ cwd: pkgPath
99
+ });
100
+ }
101
+ }
102
+ function mergeConfigRules(config, newRules, baseConfig) {
103
+ const activeRules = [];
104
+ baseConfig.rules.forEach((ruleOpts, ruleName) => {
105
+ if (ruleOpts.ruleSeverity !== "off") {
106
+ activeRules.push(ruleName);
107
+ }
108
+ });
109
+ const oldRules = config.rules || {};
110
+ let newRulesConfig = {};
111
+ for (const rule of Object.keys(oldRules)) {
112
+ if (activeRules.includes(rule)) {
113
+ continue;
114
+ }
115
+ newRulesConfig[rule] = oldRules[rule];
116
+ }
117
+ newRulesConfig = { ...newRulesConfig, ...newRules };
118
+ return { ...config, rules: newRulesConfig };
119
+ }
120
+ /**
121
+ * Represents a package from the linter's perspective.
122
+ * For example, `DefinitelyTyped/types/react` and `DefinitelyTyped/types/react/v15` are different
123
+ * packages.
124
+ */
125
+ class LintPackage {
126
+ constructor(rootDir) {
127
+ this.rootDir = rootDir;
128
+ this.files = [];
129
+ this.program = tslint_1.Linter.createProgram(path.join(this.rootDir, "tsconfig.json"));
130
+ }
131
+ config() {
132
+ return tslint_1.Configuration.readConfigurationFile(path.join(this.rootDir, "tslint.json"));
133
+ }
134
+ addFile(filePath) {
135
+ const file = this.program.getSourceFile(filePath);
136
+ if (file) {
137
+ this.files.push(file);
138
+ }
139
+ }
140
+ lint(opts, config) {
141
+ const linter = new tslint_1.Linter(opts, this.program);
142
+ for (const file of this.files) {
143
+ if (ignoreFile(file, this.rootDir, this.program)) {
144
+ continue;
145
+ }
146
+ linter.lint(file.fileName, file.text, config);
147
+ }
148
+ return linter.getResult();
149
+ }
150
+ updateConfig(config) {
151
+ fs.writeFileSync(path.join(this.rootDir, "tslint.json"), stringify(config, { space: 4 }), {
152
+ encoding: "utf8",
153
+ flag: "w"
154
+ });
155
+ }
156
+ }
157
+ function ignoreFile(file, dirPath, program) {
158
+ return program.isSourceFileDefaultLibrary(file) || lint_1.isExternalDependency(file, path.resolve(dirPath), program);
159
+ }
160
+ function walkPackageDir(rootDir) {
161
+ const packages = [];
162
+ function walk(curPackage, dir) {
163
+ for (const ent of fs.readdirSync(dir, { encoding: "utf8", withFileTypes: true })) {
164
+ const entPath = path.join(dir, ent.name);
165
+ if (ent.isFile()) {
166
+ curPackage.addFile(entPath);
167
+ }
168
+ else if (ent.isDirectory() && ent.name !== "node_modules") {
169
+ if (isVersionDir(ent.name)) {
170
+ const newPackage = new LintPackage(entPath);
171
+ packages.push(newPackage);
172
+ walk(newPackage, entPath);
173
+ }
174
+ else {
175
+ walk(curPackage, entPath);
176
+ }
177
+ }
178
+ }
179
+ }
180
+ const lintPackage = new LintPackage(rootDir);
181
+ packages.push(lintPackage);
182
+ walk(lintPackage, rootDir);
183
+ return packages;
184
+ }
185
+ /**
186
+ * Returns true if directory name matches a TypeScript or package version directory.
187
+ * Examples: `ts3.5`, `v11`, `v0.6` are all version names.
188
+ */
189
+ function isVersionDir(dirName) {
190
+ return /^ts\d+\.\d$/.test(dirName) || /^v\d+(\.\d+)?$/.test(dirName);
191
+ }
192
+ const defaultDisabler = () => {
193
+ return false;
194
+ };
195
+ function disableRules(allFailures) {
196
+ const ruleToFailures = new Map();
197
+ for (const failure of allFailures) {
198
+ const failureJson = failure.toJson();
199
+ if (ruleToFailures.has(failureJson.ruleName)) {
200
+ ruleToFailures.get(failureJson.ruleName).push(failureJson);
201
+ }
202
+ else {
203
+ ruleToFailures.set(failureJson.ruleName, [failureJson]);
204
+ }
205
+ }
206
+ const newRulesConfig = {};
207
+ ruleToFailures.forEach((failures, rule) => {
208
+ if (ignoredRules.includes(rule)) {
209
+ return;
210
+ }
211
+ const disabler = rule === "npm-naming" ? npmNamingRule_1.disabler : defaultDisabler;
212
+ const opts = disabler(failures);
213
+ newRulesConfig[rule] = opts;
214
+ });
215
+ return newRulesConfig;
216
+ }
217
+ if (!module.parent) {
218
+ main();
219
+ }
220
+ //# sourceMappingURL=updateConfig.js.map