@definitelytyped/dtslint 0.0.204 → 0.1.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.
- package/CHANGELOG.md +11 -0
- package/README.md +8 -11
- package/dist/createProgram.d.ts +2 -0
- package/dist/createProgram.js +66 -0
- package/dist/createProgram.js.map +1 -0
- package/dist/index.js +0 -1
- package/dist/index.js.map +1 -1
- package/dist/lint.d.ts +0 -1
- package/dist/lint.js +12 -35
- package/dist/lint.js.map +1 -1
- package/package.json +2 -6
- package/src/createProgram.ts +48 -0
- package/src/index.ts +1 -2
- package/src/lint.ts +11 -35
- package/test/index.test.ts +0 -40
- package/tsconfig.tsbuildinfo +1 -1
- package/dist/updateConfig.d.ts +0 -1
- package/dist/updateConfig.js +0 -214
- package/dist/updateConfig.js.map +0 -1
- package/dt.json +0 -3
- package/dtslint.json +0 -4
- package/src/updateConfig.ts +0 -241
- package/tslint.json +0 -17
package/CHANGELOG.md
CHANGED
package/README.md
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
`dtslint` tests a TypeScript declaration file for style and correctness.
|
|
2
|
-
It will install `typescript` and `
|
|
2
|
+
It will install `typescript` and `eslint` for you, so this is the only tool you need to test a type definition.
|
|
3
3
|
|
|
4
4
|
Lint rules new to dtslint are documented in the [docs](docs) directory.
|
|
5
5
|
|
|
@@ -101,24 +101,23 @@ For types that do not have a matching NPM package, add two properties:
|
|
|
101
101
|
1. `"nonNpm": true`
|
|
102
102
|
2. `"nonNpmDescription"`, a human-readable name for the project that is being typed.
|
|
103
103
|
|
|
104
|
-
#### `types
|
|
104
|
+
#### `types/.eslintrc.json`
|
|
105
105
|
|
|
106
|
-
|
|
107
|
-
|
|
106
|
+
An `.eslintrc.json` file is optional.
|
|
107
|
+
You can skip it if you don't need to modify any lint rule settings.
|
|
108
|
+
We recommend not adding an `.eslintrc.json` file.
|
|
108
109
|
|
|
109
110
|
```json5
|
|
110
111
|
{ "extends": "@definitelytyped/dtslint/dt.json" }
|
|
111
112
|
```
|
|
112
113
|
|
|
113
|
-
If present, this will override `dtslint`'s [
|
|
114
|
-
You can specify new lint
|
|
114
|
+
If present, this will override `dtslint`'s default "[`all`](https://github.com/microsoft/DefinitelyTyped-tools/blob/main/packages/eslint-plugin/src/configs/all.ts)" config.
|
|
115
|
+
You can specify new [lint rules](https://eslint.org/docs/latest/rules/), or disable some. An example:
|
|
115
116
|
|
|
116
117
|
```json5
|
|
117
118
|
{
|
|
118
|
-
"extends": "@definitelytyped/dtslint/dtslint.json", // Or "@definitelytyped/dtslint/dt.json" if on DefinitelyTyped
|
|
119
119
|
"rules": {
|
|
120
|
-
"
|
|
121
|
-
"indent": [true, "tabs"]
|
|
120
|
+
"@definitelytyped/no-unnecessary-generics": "off"
|
|
122
121
|
}
|
|
123
122
|
}
|
|
124
123
|
```
|
|
@@ -199,8 +198,6 @@ npm run watch
|
|
|
199
198
|
|
|
200
199
|
Use `pnpm test` to run all tests.
|
|
201
200
|
|
|
202
|
-
To run a single test: `node node_modules/tslint/bin/tslint --rules-dir dist/rules --test test/expect`.
|
|
203
|
-
|
|
204
201
|
## Code of Conduct
|
|
205
202
|
|
|
206
203
|
This project has adopted the [Microsoft Open Source Code of Conduct](https://opensource.microsoft.com/codeofconduct/). For more information see the [Code of Conduct FAQ](https://opensource.microsoft.com/codeofconduct/faq/) or contact [opencode@microsoft.com](mailto:opencode@microsoft.com) with any additional questions or comments.
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// This file is intentionally similar to TSLint's old Linter.createProgram API:
|
|
3
|
+
// https://github.com/palantir/tslint/blob/285fc1db18d1fd24680d6a2282c6445abf1566ee/src/linter.ts#L54
|
|
4
|
+
// TODO: creating a program to get a list of files is pretty heavyweight.
|
|
5
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
6
|
+
if (k2 === undefined) k2 = k;
|
|
7
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
8
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
9
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
10
|
+
}
|
|
11
|
+
Object.defineProperty(o, k2, desc);
|
|
12
|
+
}) : (function(o, m, k, k2) {
|
|
13
|
+
if (k2 === undefined) k2 = k;
|
|
14
|
+
o[k2] = m[k];
|
|
15
|
+
}));
|
|
16
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
17
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
18
|
+
}) : function(o, v) {
|
|
19
|
+
o["default"] = v;
|
|
20
|
+
});
|
|
21
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
22
|
+
if (mod && mod.__esModule) return mod;
|
|
23
|
+
var result = {};
|
|
24
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
25
|
+
__setModuleDefault(result, mod);
|
|
26
|
+
return result;
|
|
27
|
+
};
|
|
28
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
|
+
exports.createProgram = void 0;
|
|
30
|
+
const fs = __importStar(require("fs"));
|
|
31
|
+
const path = __importStar(require("path"));
|
|
32
|
+
const ts = __importStar(require("typescript"));
|
|
33
|
+
function createProgram(configFile) {
|
|
34
|
+
var _a;
|
|
35
|
+
const config = ts.readConfigFile(configFile, ts.sys.readFile);
|
|
36
|
+
if (config.error !== undefined) {
|
|
37
|
+
throw new Error(ts.formatDiagnostics([config.error], {
|
|
38
|
+
getCanonicalFileName: (f) => f,
|
|
39
|
+
getCurrentDirectory: process.cwd,
|
|
40
|
+
getNewLine: () => "\n",
|
|
41
|
+
}));
|
|
42
|
+
}
|
|
43
|
+
const parseConfigHost = {
|
|
44
|
+
fileExists: fs.existsSync,
|
|
45
|
+
readDirectory: ts.sys.readDirectory,
|
|
46
|
+
readFile: (file) => fs.readFileSync(file, "utf8"),
|
|
47
|
+
useCaseSensitiveFileNames: true,
|
|
48
|
+
};
|
|
49
|
+
const projectDirectory = path.dirname(configFile);
|
|
50
|
+
const parsed = ts.parseJsonConfigFileContent(config.config, parseConfigHost, path.resolve(projectDirectory), {
|
|
51
|
+
noEmit: true,
|
|
52
|
+
});
|
|
53
|
+
// ignore warnings and 'TS18003: No inputs were found in config file ...'
|
|
54
|
+
const errors = (_a = parsed.errors) === null || _a === void 0 ? void 0 : _a.filter((d) => d.category === ts.DiagnosticCategory.Error && d.code !== 18003);
|
|
55
|
+
if (errors === null || errors === void 0 ? void 0 : errors.length) {
|
|
56
|
+
throw new Error(ts.formatDiagnostics(errors, {
|
|
57
|
+
getCanonicalFileName: (f) => f,
|
|
58
|
+
getCurrentDirectory: process.cwd,
|
|
59
|
+
getNewLine: () => "\n",
|
|
60
|
+
}));
|
|
61
|
+
}
|
|
62
|
+
const host = ts.createCompilerHost(parsed.options, true);
|
|
63
|
+
return ts.createProgram(parsed.fileNames, parsed.options, host);
|
|
64
|
+
}
|
|
65
|
+
exports.createProgram = createProgram;
|
|
66
|
+
//# sourceMappingURL=createProgram.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"createProgram.js","sourceRoot":"","sources":["../src/createProgram.ts"],"names":[],"mappings":";AAAA,+EAA+E;AAC/E,qGAAqG;AACrG,yEAAyE;;;;;;;;;;;;;;;;;;;;;;;;;;AAEzE,uCAAyB;AACzB,2CAA6B;AAC7B,+CAAiC;AAEjC,SAAgB,aAAa,CAAC,UAAkB;;IAC9C,MAAM,MAAM,GAAG,EAAE,CAAC,cAAc,CAAC,UAAU,EAAE,EAAE,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC;IAC9D,IAAI,MAAM,CAAC,KAAK,KAAK,SAAS,EAAE;QAC9B,MAAM,IAAI,KAAK,CACb,EAAE,CAAC,iBAAiB,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,EAAE;YACn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EAAE,IAAI,CAAC,CAAC;IAEzD,OAAO,EAAE,CAAC,aAAa,CAAC,MAAM,CAAC,SAAS,EAAE,MAAM,CAAC,OAAO,EAAE,IAAI,CAAC,CAAC;AAClE,CAAC;AAvCD,sCAuCC"}
|
package/dist/index.js
CHANGED
|
@@ -152,7 +152,6 @@ function next(v) {
|
|
|
152
152
|
return typescript_versions_1.TypeScriptVersion.supported[index + 1];
|
|
153
153
|
}
|
|
154
154
|
async function testTypesVersion(dirPath, lowVersion, hiVersion, expectOnly, tsLocal, isLatest) {
|
|
155
|
-
(0, lint_1.checkTslintJson)(dirPath);
|
|
156
155
|
const tsconfigErrors = (0, checks_1.checkTsconfig)(dirPath, (0, util_1.getCompilerOptions)(dirPath));
|
|
157
156
|
if (tsconfigErrors.length > 0) {
|
|
158
157
|
throw new Error("\n\t* " + tsconfigErrors.join("\n\t* "));
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;AAEA,8EAA+F;AAC/F,iCAAkC;AAClC,4CAAoB;AACpB,+BAAqE;AAErE,kDAAoD;AACpD,qCAA2D;AAC3D,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;AAEA,8EAA+F;AAC/F,iCAAkC;AAClC,4CAAoB;AACpB,+BAAqE;AAErE,kDAAoD;AACpD,qCAA2D;AAC3D,iCAAyC;AACzC,iCAAiE;AACjE,kEAAkE;AAElE,KAAK,UAAU,IAAI;IACjB,MAAM,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;IACnC,IAAI,OAAO,GAAG,OAAO,CAAC,GAAG,EAAE,CAAC;IAC5B,IAAI,cAAc,GAAG,KAAK,CAAC;IAC3B,IAAI,UAAU,GAAG,KAAK,CAAC;IACvB,IAAI,YAAY,GAAG,KAAK,CAAC;I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,GAAG,QAAQ,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IAE3C,MAAM,aAAa,GAAG,IAAA,WAAS,EAAC,OAAO,EAAE,YAAY,CAAC,CAAC;IACvD,IAAI,CAAC,YAAE,CAAC,UAAU,CAAC,aAAa,CAAC,EAAE;QACjC,MAAM,IAAI,KAAK,CAAC,GAAG,OAAO,4CAA4C,cAAc,EAAE,CAAC,CAAC;KACzF;IAED,MAAM,SAAS,GAAG,MAAM,YAAE,CAAC,QAAQ,CAAC,QAAQ,CAAC,aAAa,EAAE,OAAO,CAAC,CAAC;IACrE,MAAM,MAAM,GAAG,SAAS,CAAC,IAAI,EAAE,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC;IAE/C,IAAI,CAAC,IAAA,kBAAU,EAAC,MAAM,EAAE,QAAQ,CAAC,EAAE;QACjC,MAAM,IAAI,KAAK,CAAC,GAAG,OAAO,yCAAyC,cAAc,EAAE,CAAC,CAAC;KACtF;AACH,CAAC;AAED,SAAS,kBAAkB,CAAC,OAAe;IACzC,IAAI,YAAE,CAAC,UAAU,CAAC,IAAA,WAAS,EAAC,OAAO,EAAE,iBAAiB,CAAC,CAAC,EAAE;QACxD,MAAM,IAAI,KAAK,CACb,GAAG,OAAO,oHAAoH,CAC/H,CAAC;KACH;AACH,CAAC"}
|
package/dist/lint.d.ts
CHANGED
|
@@ -2,5 +2,4 @@ import { TypeScriptVersion } from "@definitelytyped/typescript-versions";
|
|
|
2
2
|
import * as TsType from "typescript";
|
|
3
3
|
export declare function lint(dirPath: string, minVersion: TsVersion, maxVersion: TsVersion, isLatest: boolean, expectOnly: boolean, tsLocal: string | undefined): Promise<string | undefined>;
|
|
4
4
|
export declare function isExternalDependency(file: TsType.SourceFile, dirPath: string, program: TsType.Program): boolean;
|
|
5
|
-
export declare function checkTslintJson(dirPath: string): void;
|
|
6
5
|
export type TsVersion = TypeScriptVersion | "local";
|
package/dist/lint.js
CHANGED
|
@@ -1,33 +1,25 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.
|
|
3
|
+
exports.isExternalDependency = exports.lint = void 0;
|
|
7
4
|
const typescript_versions_1 = require("@definitelytyped/typescript-versions");
|
|
8
5
|
const utils_1 = require("@definitelytyped/utils");
|
|
9
6
|
const assert = require("assert");
|
|
10
|
-
const fs_1 = __importDefault(require("fs"));
|
|
11
7
|
const path_1 = require("path");
|
|
12
|
-
const tslint_1 = require("tslint");
|
|
13
8
|
const eslint_1 = require("eslint");
|
|
14
|
-
const
|
|
9
|
+
const createProgram_1 = require("./createProgram");
|
|
15
10
|
async function lint(dirPath, minVersion, maxVersion, isLatest, expectOnly, tsLocal) {
|
|
16
11
|
const tsconfigPath = (0, path_1.join)(dirPath, "tsconfig.json");
|
|
17
12
|
const estree = require(require.resolve("@typescript-eslint/typescript-estree", { paths: [dirPath] }));
|
|
18
13
|
process.env.TSESTREE_SINGLE_RUN = "true";
|
|
19
|
-
|
|
20
|
-
const
|
|
21
|
-
// TODO: To port expect-rule, eslint's config will also need to include [minVersion, maxVersion]
|
|
22
|
-
// Also: expect-rule should be renamed to expect-type or check-type or something
|
|
23
|
-
const esfiles = [];
|
|
14
|
+
const lintProgram = (0, createProgram_1.createProgram)(tsconfigPath);
|
|
15
|
+
const files = [];
|
|
24
16
|
for (const file of lintProgram.getSourceFiles()) {
|
|
25
17
|
if (lintProgram.isSourceFileDefaultLibrary(file)) {
|
|
26
18
|
continue;
|
|
27
19
|
}
|
|
28
20
|
const { fileName, text } = file;
|
|
29
21
|
if (!fileName.includes("node_modules")) {
|
|
30
|
-
const err = testNoLintDisables(
|
|
22
|
+
const err = testNoLintDisables(text);
|
|
31
23
|
if (err) {
|
|
32
24
|
const { pos, message } = err;
|
|
33
25
|
const place = file.getLineAndCharacterOfPosition(pos);
|
|
@@ -37,7 +29,7 @@ async function lint(dirPath, minVersion, maxVersion, isLatest, expectOnly, tsLoc
|
|
|
37
29
|
// External dependencies should have been handled by `testDependencies`;
|
|
38
30
|
// typesVersions should be handled in a separate lint
|
|
39
31
|
if (!isExternalDependency(file, dirPath, lintProgram) && (!isLatest || !isTypesVersionPath(fileName, dirPath))) {
|
|
40
|
-
|
|
32
|
+
files.push(fileName);
|
|
41
33
|
}
|
|
42
34
|
}
|
|
43
35
|
let output = "";
|
|
@@ -83,8 +75,8 @@ async function lint(dirPath, minVersion, maxVersion, isLatest, expectOnly, tsLoc
|
|
|
83
75
|
}
|
|
84
76
|
const eslint = new eslint_1.ESLint(options);
|
|
85
77
|
const formatter = await eslint.loadFormatter("stylish");
|
|
86
|
-
const
|
|
87
|
-
output += formatter.format(
|
|
78
|
+
const results = await eslint.lintFiles(files);
|
|
79
|
+
output += formatter.format(results);
|
|
88
80
|
estree.clearCaches();
|
|
89
81
|
return output;
|
|
90
82
|
}
|
|
@@ -110,7 +102,8 @@ function startsWithDirectory(filePath, dirPath) {
|
|
|
110
102
|
const normalDirPath = normalizePath(dirPath).replace(/\/$/, "");
|
|
111
103
|
return normalFilePath.startsWith(normalDirPath + "/") || normalFilePath.startsWith(normalDirPath + "\\");
|
|
112
104
|
}
|
|
113
|
-
function testNoLintDisables(
|
|
105
|
+
function testNoLintDisables(text) {
|
|
106
|
+
const disabler = "eslint-disable";
|
|
114
107
|
let lastIndex = 0;
|
|
115
108
|
while (true) {
|
|
116
109
|
const pos = text.indexOf(disabler, lastIndex);
|
|
@@ -120,31 +113,15 @@ function testNoLintDisables(disabler, text) {
|
|
|
120
113
|
const end = pos + disabler.length;
|
|
121
114
|
const nextChar = text.charAt(end);
|
|
122
115
|
const nextChar2 = text.charAt(end + 1);
|
|
123
|
-
if (nextChar !== "-" &&
|
|
124
|
-
!(disabler === "tslint:disable" && nextChar === ":") &&
|
|
125
|
-
!(disabler === "eslint-disable" && nextChar === " " && nextChar2 !== "*")) {
|
|
116
|
+
if (nextChar !== "-" && !(nextChar === " " && nextChar2 !== "*")) {
|
|
126
117
|
const message = `'${disabler}' is forbidden. ` +
|
|
127
118
|
"Per-line and per-rule disabling is allowed, for example: " +
|
|
128
|
-
"'
|
|
119
|
+
"'eslint-disable:rulename', eslint-disable-line' and 'eslint-disable-next-line' are allowed.";
|
|
129
120
|
return { pos, message };
|
|
130
121
|
}
|
|
131
122
|
lastIndex = end;
|
|
132
123
|
}
|
|
133
124
|
}
|
|
134
|
-
function checkTslintJson(dirPath) {
|
|
135
|
-
const configPath = getConfigPath(dirPath);
|
|
136
|
-
const shouldExtend = "@definitelytyped/dtslint/dt.json";
|
|
137
|
-
if (!fs_1.default.existsSync(configPath)) {
|
|
138
|
-
throw new Error(`Missing \`tslint.json\` that contains \`{ "extends": "${shouldExtend}" }\`.`);
|
|
139
|
-
}
|
|
140
|
-
if ((0, util_1.readJson)(configPath).extends !== shouldExtend) {
|
|
141
|
-
throw new Error(`'tslint.json' must extend "${shouldExtend}"`);
|
|
142
|
-
}
|
|
143
|
-
}
|
|
144
|
-
exports.checkTslintJson = checkTslintJson;
|
|
145
|
-
function getConfigPath(dirPath) {
|
|
146
|
-
return (0, path_1.join)(dirPath, "tslint.json");
|
|
147
|
-
}
|
|
148
125
|
function range(minVersion, maxVersion) {
|
|
149
126
|
if (minVersion === "local") {
|
|
150
127
|
assert(maxVersion === "local");
|
package/dist/lint.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"lint.js","sourceRoot":"","sources":["../src/lint.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"lint.js","sourceRoot":"","sources":["../src/lint.ts"],"names":[],"mappings":";;;AAAA,8EAAyE;AACzE,kDAAsE;AACtE,iCAAkC;AAClC,+BAAoD;AACpD,mCAAgC;AAGhC,mDAAgD;AAEzC,KAAK,UAAU,IAAI,CACxB,OAAe,EACf,UAAqB,EACrB,UAAqB,EACrB,QAAiB,EAC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;KACnC;IACD,MAAM,CAAC,UAAU,KAAK,OAAO,CAAC,CAAC;IAE/B,MAAM,MAAM,GAAG,uCAAiB,CAAC,SAAS,CAAC,OAAO,CAAC,UAAU,CAAC,CAAC;IAC/D,MAAM,CAAC,MAAM,IAAI,CAAC,CAAC,CAAC;IACpB,IAAI,UAAU,KAAK,uCAAiB,CAAC,MAAM,EAAE;QAC3C,OAAO,CAAC,GAAG,uCAAiB,CAAC,SAAS,CAAC,KAAK,CAAC,MAAM,CAAC,EAAE,uCAAiB,CAAC,MAAM,CAAC,CAAC;KACjF;IACD,MAAM,MAAM,GAAG,uCAAiB,CAAC,SAAS,CAAC,OAAO,CAAC,UAA+B,CAAC,CAAC;IACpF,MAAM,CAAC,MAAM,IAAI,MAAM,CAAC,CAAC;IACzB,OAAO,uCAAiB,CAAC,SAAS,CAAC,KAAK,CAAC,MAAM,EAAE,MAAM,GAAG,CAAC,CAAC,CAAC;AAC/D,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@definitelytyped/dtslint",
|
|
3
|
-
"version": "0.0
|
|
3
|
+
"version": "0.1.0",
|
|
4
4
|
"description": "Runs tests on TypeScript definition files",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"bin": "./dist/index.js",
|
|
@@ -25,11 +25,8 @@
|
|
|
25
25
|
"@typescript-eslint/utils": "^6.11.0",
|
|
26
26
|
"eslint": "^8.53.0",
|
|
27
27
|
"eslint-plugin-import": "^2.29.0",
|
|
28
|
-
"json-stable-stringify": "^1.0.2",
|
|
29
28
|
"strip-json-comments": "^3.1.1",
|
|
30
|
-
"
|
|
31
|
-
"yargs": "^17.7.2",
|
|
32
|
-
"@definitelytyped/header-parser": "0.0.193",
|
|
29
|
+
"@definitelytyped/header-parser": "0.1.0",
|
|
33
30
|
"@definitelytyped/typescript-versions": "0.0.184",
|
|
34
31
|
"@definitelytyped/utils": "0.0.191"
|
|
35
32
|
},
|
|
@@ -38,7 +35,6 @@
|
|
|
38
35
|
},
|
|
39
36
|
"devDependencies": {
|
|
40
37
|
"@types/eslint": "^8.44.7",
|
|
41
|
-
"@types/json-stable-stringify": "^1.0.36",
|
|
42
38
|
"@types/strip-json-comments": "^3.0.0",
|
|
43
39
|
"typescript": "^5.2.2"
|
|
44
40
|
},
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
// This file is intentionally similar to TSLint's old Linter.createProgram API:
|
|
2
|
+
// https://github.com/palantir/tslint/blob/285fc1db18d1fd24680d6a2282c6445abf1566ee/src/linter.ts#L54
|
|
3
|
+
// TODO: creating a program to get a list of files is pretty heavyweight.
|
|
4
|
+
|
|
5
|
+
import * as fs from "fs";
|
|
6
|
+
import * as path from "path";
|
|
7
|
+
import * as ts from "typescript";
|
|
8
|
+
|
|
9
|
+
export function createProgram(configFile: string): ts.Program {
|
|
10
|
+
const config = ts.readConfigFile(configFile, ts.sys.readFile);
|
|
11
|
+
if (config.error !== undefined) {
|
|
12
|
+
throw new Error(
|
|
13
|
+
ts.formatDiagnostics([config.error], {
|
|
14
|
+
getCanonicalFileName: (f) => f,
|
|
15
|
+
getCurrentDirectory: process.cwd,
|
|
16
|
+
getNewLine: () => "\n",
|
|
17
|
+
}),
|
|
18
|
+
);
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
const parseConfigHost: ts.ParseConfigHost = {
|
|
22
|
+
fileExists: fs.existsSync,
|
|
23
|
+
readDirectory: ts.sys.readDirectory,
|
|
24
|
+
readFile: (file) => fs.readFileSync(file, "utf8"),
|
|
25
|
+
useCaseSensitiveFileNames: true,
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
const projectDirectory = path.dirname(configFile);
|
|
29
|
+
const parsed = ts.parseJsonConfigFileContent(config.config, parseConfigHost, path.resolve(projectDirectory), {
|
|
30
|
+
noEmit: true,
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
// ignore warnings and 'TS18003: No inputs were found in config file ...'
|
|
34
|
+
const errors = parsed.errors?.filter((d) => d.category === ts.DiagnosticCategory.Error && d.code !== 18003);
|
|
35
|
+
if (errors?.length) {
|
|
36
|
+
throw new Error(
|
|
37
|
+
ts.formatDiagnostics(errors, {
|
|
38
|
+
getCanonicalFileName: (f) => f,
|
|
39
|
+
getCurrentDirectory: process.cwd,
|
|
40
|
+
getNewLine: () => "\n",
|
|
41
|
+
}),
|
|
42
|
+
);
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
const host = ts.createCompilerHost(parsed.options, true);
|
|
46
|
+
|
|
47
|
+
return ts.createProgram(parsed.fileNames, parsed.options, host);
|
|
48
|
+
}
|
package/src/index.ts
CHANGED
|
@@ -7,7 +7,7 @@ import { basename, dirname, join as joinPaths, resolve } from "path";
|
|
|
7
7
|
|
|
8
8
|
import { deepEquals } from "@definitelytyped/utils";
|
|
9
9
|
import { checkPackageJson, checkTsconfig } from "./checks";
|
|
10
|
-
import {
|
|
10
|
+
import { lint, TsVersion } from "./lint";
|
|
11
11
|
import { getCompilerOptions, packageNameFromPath } from "./util";
|
|
12
12
|
import { getTypesVersions } from "@definitelytyped/header-parser";
|
|
13
13
|
|
|
@@ -186,7 +186,6 @@ async function testTypesVersion(
|
|
|
186
186
|
tsLocal: string | undefined,
|
|
187
187
|
isLatest: boolean,
|
|
188
188
|
): Promise<void> {
|
|
189
|
-
checkTslintJson(dirPath);
|
|
190
189
|
const tsconfigErrors = checkTsconfig(dirPath, getCompilerOptions(dirPath));
|
|
191
190
|
if (tsconfigErrors.length > 0) {
|
|
192
191
|
throw new Error("\n\t* " + tsconfigErrors.join("\n\t* "));
|
package/src/lint.ts
CHANGED
|
@@ -1,13 +1,11 @@
|
|
|
1
1
|
import { TypeScriptVersion } from "@definitelytyped/typescript-versions";
|
|
2
2
|
import { typeScriptPath, withoutStart } from "@definitelytyped/utils";
|
|
3
3
|
import assert = require("assert");
|
|
4
|
-
import fs from "fs";
|
|
5
4
|
import { join as joinPaths, normalize } from "path";
|
|
6
|
-
import { Linter } from "tslint";
|
|
7
5
|
import { ESLint } from "eslint";
|
|
8
6
|
import * as TsType from "typescript";
|
|
9
7
|
|
|
10
|
-
import {
|
|
8
|
+
import { createProgram } from "./createProgram";
|
|
11
9
|
|
|
12
10
|
export async function lint(
|
|
13
11
|
dirPath: string,
|
|
@@ -22,12 +20,8 @@ export async function lint(
|
|
|
22
20
|
require.resolve("@typescript-eslint/typescript-estree", { paths: [dirPath] }),
|
|
23
21
|
) as typeof import("@typescript-eslint/typescript-estree");
|
|
24
22
|
process.env.TSESTREE_SINGLE_RUN = "true";
|
|
25
|
-
|
|
26
|
-
const
|
|
27
|
-
|
|
28
|
-
// TODO: To port expect-rule, eslint's config will also need to include [minVersion, maxVersion]
|
|
29
|
-
// Also: expect-rule should be renamed to expect-type or check-type or something
|
|
30
|
-
const esfiles = [];
|
|
23
|
+
const lintProgram = createProgram(tsconfigPath);
|
|
24
|
+
const files = [];
|
|
31
25
|
|
|
32
26
|
for (const file of lintProgram.getSourceFiles()) {
|
|
33
27
|
if (lintProgram.isSourceFileDefaultLibrary(file)) {
|
|
@@ -36,7 +30,7 @@ export async function lint(
|
|
|
36
30
|
|
|
37
31
|
const { fileName, text } = file;
|
|
38
32
|
if (!fileName.includes("node_modules")) {
|
|
39
|
-
const err = testNoLintDisables(
|
|
33
|
+
const err = testNoLintDisables(text);
|
|
40
34
|
if (err) {
|
|
41
35
|
const { pos, message } = err;
|
|
42
36
|
const place = file.getLineAndCharacterOfPosition(pos);
|
|
@@ -47,7 +41,7 @@ export async function lint(
|
|
|
47
41
|
// External dependencies should have been handled by `testDependencies`;
|
|
48
42
|
// typesVersions should be handled in a separate lint
|
|
49
43
|
if (!isExternalDependency(file, dirPath, lintProgram) && (!isLatest || !isTypesVersionPath(fileName, dirPath))) {
|
|
50
|
-
|
|
44
|
+
files.push(fileName);
|
|
51
45
|
}
|
|
52
46
|
}
|
|
53
47
|
let output = "";
|
|
@@ -97,8 +91,8 @@ export async function lint(
|
|
|
97
91
|
|
|
98
92
|
const eslint = new ESLint(options);
|
|
99
93
|
const formatter = await eslint.loadFormatter("stylish");
|
|
100
|
-
const
|
|
101
|
-
output += formatter.format(
|
|
94
|
+
const results = await eslint.lintFiles(files);
|
|
95
|
+
output += formatter.format(results);
|
|
102
96
|
estree.clearCaches();
|
|
103
97
|
|
|
104
98
|
return output;
|
|
@@ -132,7 +126,8 @@ interface Err {
|
|
|
132
126
|
pos: number;
|
|
133
127
|
message: string;
|
|
134
128
|
}
|
|
135
|
-
function testNoLintDisables(
|
|
129
|
+
function testNoLintDisables(text: string): Err | undefined {
|
|
130
|
+
const disabler = "eslint-disable";
|
|
136
131
|
let lastIndex = 0;
|
|
137
132
|
while (true) {
|
|
138
133
|
const pos = text.indexOf(disabler, lastIndex);
|
|
@@ -142,36 +137,17 @@ function testNoLintDisables(disabler: "tslint:disable" | "eslint-disable", text:
|
|
|
142
137
|
const end = pos + disabler.length;
|
|
143
138
|
const nextChar = text.charAt(end);
|
|
144
139
|
const nextChar2 = text.charAt(end + 1);
|
|
145
|
-
if (
|
|
146
|
-
nextChar !== "-" &&
|
|
147
|
-
!(disabler === "tslint:disable" && nextChar === ":") &&
|
|
148
|
-
!(disabler === "eslint-disable" && nextChar === " " && nextChar2 !== "*")
|
|
149
|
-
) {
|
|
140
|
+
if (nextChar !== "-" && !(nextChar === " " && nextChar2 !== "*")) {
|
|
150
141
|
const message =
|
|
151
142
|
`'${disabler}' is forbidden. ` +
|
|
152
143
|
"Per-line and per-rule disabling is allowed, for example: " +
|
|
153
|
-
"'
|
|
144
|
+
"'eslint-disable:rulename', eslint-disable-line' and 'eslint-disable-next-line' are allowed.";
|
|
154
145
|
return { pos, message };
|
|
155
146
|
}
|
|
156
147
|
lastIndex = end;
|
|
157
148
|
}
|
|
158
149
|
}
|
|
159
150
|
|
|
160
|
-
export function checkTslintJson(dirPath: string): void {
|
|
161
|
-
const configPath = getConfigPath(dirPath);
|
|
162
|
-
const shouldExtend = "@definitelytyped/dtslint/dt.json";
|
|
163
|
-
if (!fs.existsSync(configPath)) {
|
|
164
|
-
throw new Error(`Missing \`tslint.json\` that contains \`{ "extends": "${shouldExtend}" }\`.`);
|
|
165
|
-
}
|
|
166
|
-
if (readJson(configPath).extends !== shouldExtend) {
|
|
167
|
-
throw new Error(`'tslint.json' must extend "${shouldExtend}"`);
|
|
168
|
-
}
|
|
169
|
-
}
|
|
170
|
-
|
|
171
|
-
function getConfigPath(dirPath: string): string {
|
|
172
|
-
return joinPaths(dirPath, "tslint.json");
|
|
173
|
-
}
|
|
174
|
-
|
|
175
151
|
function range(minVersion: TsVersion, maxVersion: TsVersion): readonly TsVersion[] {
|
|
176
152
|
if (minVersion === "local") {
|
|
177
153
|
assert(maxVersion === "local");
|
package/test/index.test.ts
CHANGED
|
@@ -1,34 +1,7 @@
|
|
|
1
1
|
/// <reference types="jest" />
|
|
2
|
-
import { join } from "path";
|
|
3
|
-
import { consoleTestResultHandler, runTest } from "tslint/lib/test";
|
|
4
|
-
import { existsSync, readdirSync, statSync } from "fs";
|
|
5
2
|
import { CompilerOptionsRaw, checkTsconfig } from "../src/checks";
|
|
6
3
|
import { assertPackageIsNotDeprecated } from "../src/index";
|
|
7
4
|
|
|
8
|
-
const testDir = __dirname;
|
|
9
|
-
|
|
10
|
-
class Logger {
|
|
11
|
-
logmsg = "";
|
|
12
|
-
errormsg = "";
|
|
13
|
-
log(message: string): void {
|
|
14
|
-
this.logmsg += message;
|
|
15
|
-
}
|
|
16
|
-
error(message: string): void {
|
|
17
|
-
this.errormsg += message;
|
|
18
|
-
}
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
function testSingle(testDirectory: string) {
|
|
22
|
-
test(testDirectory, () => {
|
|
23
|
-
const logger = new Logger();
|
|
24
|
-
const result = consoleTestResultHandler(runTest(testDirectory), logger);
|
|
25
|
-
if (!result) {
|
|
26
|
-
console.log(logger.logmsg + logger.errormsg);
|
|
27
|
-
}
|
|
28
|
-
expect(result).toBeTruthy();
|
|
29
|
-
});
|
|
30
|
-
}
|
|
31
|
-
|
|
32
5
|
describe("dtslint", () => {
|
|
33
6
|
const base: CompilerOptionsRaw = {
|
|
34
7
|
module: "commonjs",
|
|
@@ -145,17 +118,4 @@ describe("dtslint", () => {
|
|
|
145
118
|
});
|
|
146
119
|
});
|
|
147
120
|
});
|
|
148
|
-
describe("rules", () => {
|
|
149
|
-
const tests = readdirSync(testDir);
|
|
150
|
-
for (const testName of tests) {
|
|
151
|
-
const testDirectory = join(testDir, testName);
|
|
152
|
-
if (existsSync(join(testDirectory, "tslint.json"))) {
|
|
153
|
-
testSingle(testDirectory);
|
|
154
|
-
} else if (statSync(testDirectory).isDirectory()) {
|
|
155
|
-
for (const subTestName of readdirSync(testDirectory)) {
|
|
156
|
-
testSingle(join(testDirectory, subTestName));
|
|
157
|
-
}
|
|
158
|
-
}
|
|
159
|
-
}
|
|
160
|
-
});
|
|
161
121
|
});
|