@definitelytyped/dtslint 0.0.197 → 0.0.198
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 +6 -0
- package/dist/lint.js +41 -70
- package/dist/lint.js.map +1 -1
- package/dist/util.d.ts +0 -1
- package/dist/util.js +1 -7
- package/dist/util.js.map +1 -1
- package/dtslint.json +0 -1
- package/package.json +2 -2
- package/src/lint.ts +45 -87
- package/src/util.ts +0 -6
- package/tsconfig.tsbuildinfo +1 -1
- package/dist/rules/expectRule.d.ts +0 -22
- package/dist/rules/expectRule.js +0 -387
- package/dist/rules/expectRule.js.map +0 -1
- package/dtslint-expect-only.json +0 -6
- package/src/rules/expectRule.ts +0 -455
- package/test/expect/expectType.ts.lint +0 -39
- package/test/expect/tsconfig.json +0 -1
- package/test/expect/tslint.json +0 -6
package/CHANGELOG.md
CHANGED
package/dist/lint.js
CHANGED
|
@@ -11,7 +11,6 @@ const fs_1 = __importDefault(require("fs"));
|
|
|
11
11
|
const path_1 = require("path");
|
|
12
12
|
const tslint_1 = require("tslint");
|
|
13
13
|
const eslint_1 = require("eslint");
|
|
14
|
-
const expectRule_1 = require("./rules/expectRule");
|
|
15
14
|
const util_1 = require("./util");
|
|
16
15
|
async function lint(dirPath, minVersion, maxVersion, isLatest, expectOnly, tsLocal) {
|
|
17
16
|
const tsconfigPath = (0, path_1.join)(dirPath, "tsconfig.json");
|
|
@@ -19,17 +18,12 @@ async function lint(dirPath, minVersion, maxVersion, isLatest, expectOnly, tsLoc
|
|
|
19
18
|
process.env.TSESTREE_SINGLE_RUN = "true";
|
|
20
19
|
// TODO: To remove tslint, replace this with a ts.createProgram (probably)
|
|
21
20
|
const lintProgram = tslint_1.Linter.createProgram(tsconfigPath);
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
return errors;
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
const linter = new tslint_1.Linter({ fix: false, formatter: "stylish" }, lintProgram);
|
|
29
|
-
const configPath = expectOnly ? (0, path_1.join)(__dirname, "..", "dtslint-expect-only.json") : getConfigPath(dirPath);
|
|
21
|
+
// tslint no longer checks ExpectType; skip linting entirely if we're only checking ExpectType.
|
|
22
|
+
const linter = !expectOnly ? new tslint_1.Linter({ fix: false, formatter: "stylish" }, lintProgram) : undefined;
|
|
23
|
+
const configPath = getConfigPath(dirPath);
|
|
30
24
|
// TODO: To port expect-rule, eslint's config will also need to include [minVersion, maxVersion]
|
|
31
25
|
// Also: expect-rule should be renamed to expect-type or check-type or something
|
|
32
|
-
const config = getLintConfig(configPath
|
|
26
|
+
const config = getLintConfig(configPath);
|
|
33
27
|
const esfiles = [];
|
|
34
28
|
for (const file of lintProgram.getSourceFiles()) {
|
|
35
29
|
if (lintProgram.isSourceFileDefaultLibrary(file)) {
|
|
@@ -47,60 +41,49 @@ async function lint(dirPath, minVersion, maxVersion, isLatest, expectOnly, tsLoc
|
|
|
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
|
-
linter.lint(fileName, text, config);
|
|
44
|
+
linter === null || linter === void 0 ? void 0 : linter.lint(fileName, text, config);
|
|
51
45
|
esfiles.push(fileName);
|
|
52
46
|
}
|
|
53
47
|
}
|
|
54
|
-
const result = linter.getResult();
|
|
55
|
-
let output = result.failures.length ? result.output : "";
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
48
|
+
const result = linter === null || linter === void 0 ? void 0 : linter.getResult();
|
|
49
|
+
let output = (result === null || result === void 0 ? void 0 : result.failures.length) ? result.output : "";
|
|
50
|
+
const versionsToTest = range(minVersion, maxVersion).map((versionName) => ({
|
|
51
|
+
versionName,
|
|
52
|
+
path: (0, utils_1.typeScriptPath)(versionName, tsLocal),
|
|
53
|
+
}));
|
|
54
|
+
const options = {
|
|
55
|
+
cwd: dirPath,
|
|
56
|
+
overrideConfig: {
|
|
57
|
+
overrides: [
|
|
58
|
+
{
|
|
59
|
+
files: ["*.ts", "*.cts", "*.mts", "*.tsx"],
|
|
60
|
+
rules: {
|
|
61
|
+
"@definitelytyped/expect": ["error", { versionsToTest }],
|
|
62
|
+
},
|
|
63
|
+
},
|
|
64
|
+
],
|
|
65
|
+
},
|
|
66
|
+
};
|
|
67
|
+
if (expectOnly) {
|
|
68
|
+
// Disable the regular config, instead load only the plugins and use just the rule above.
|
|
69
|
+
// TODO(jakebailey): share this with eslint-plugin
|
|
70
|
+
options.useEslintrc = false;
|
|
71
|
+
options.overrideConfig.plugins = ["@definitelytyped", "@typescript-eslint", "jsdoc"];
|
|
72
|
+
const override = options.overrideConfig.overrides[0];
|
|
73
|
+
override.parser = "@typescript-eslint/parser";
|
|
74
|
+
override.parserOptions = {
|
|
75
|
+
project: true,
|
|
76
|
+
warnOnUnsupportedTypeScriptVersion: false,
|
|
77
|
+
};
|
|
65
78
|
}
|
|
79
|
+
const eslint = new eslint_1.ESLint(options);
|
|
80
|
+
const formatter = await eslint.loadFormatter("stylish");
|
|
81
|
+
const eresults = await eslint.lintFiles(esfiles);
|
|
82
|
+
output += formatter.format(eresults);
|
|
83
|
+
estree.clearCaches();
|
|
66
84
|
return output;
|
|
67
85
|
}
|
|
68
86
|
exports.lint = lint;
|
|
69
|
-
function testDependencies(version, dirPath, lintProgram, tsLocal) {
|
|
70
|
-
const tsconfigPath = (0, path_1.join)(dirPath, "tsconfig.json");
|
|
71
|
-
assert(version !== "local" || tsLocal);
|
|
72
|
-
const ts = require((0, utils_1.typeScriptPath)(version, tsLocal));
|
|
73
|
-
const program = (0, expectRule_1.getProgram)(tsconfigPath, ts, version, lintProgram);
|
|
74
|
-
const diagnostics = ts
|
|
75
|
-
.getPreEmitDiagnostics(program)
|
|
76
|
-
.filter((d) => !d.file || isExternalDependency(d.file, dirPath, program));
|
|
77
|
-
if (!diagnostics.length) {
|
|
78
|
-
return undefined;
|
|
79
|
-
}
|
|
80
|
-
const showDiags = ts.formatDiagnostics(diagnostics, {
|
|
81
|
-
getCanonicalFileName: (f) => f,
|
|
82
|
-
getCurrentDirectory: () => dirPath,
|
|
83
|
-
getNewLine: () => "\n",
|
|
84
|
-
});
|
|
85
|
-
const message = `Errors in typescript@${version} for external dependencies:\n${showDiags}`;
|
|
86
|
-
// Add an edge-case for someone needing to `npm install` in react when they first edit a DT module which depends on it - #226
|
|
87
|
-
const cannotFindDepsDiags = diagnostics.find((d) => d.code === 2307 && d.messageText.toString().includes("Cannot find module"));
|
|
88
|
-
if (cannotFindDepsDiags && cannotFindDepsDiags.file) {
|
|
89
|
-
return `
|
|
90
|
-
A module look-up failed, this often occurs when you need to run \`pnpm install\` on a dependent module before you can lint.
|
|
91
|
-
|
|
92
|
-
Before you debug, first try running:
|
|
93
|
-
|
|
94
|
-
pnpm install -w --filter '...{./types/${dirPath}}...'
|
|
95
|
-
|
|
96
|
-
Then re-run. Full error logs are below.
|
|
97
|
-
|
|
98
|
-
${message}`;
|
|
99
|
-
}
|
|
100
|
-
else {
|
|
101
|
-
return message;
|
|
102
|
-
}
|
|
103
|
-
}
|
|
104
87
|
function isExternalDependency(file, dirPath, program) {
|
|
105
88
|
return !startsWithDirectory(file.fileName, dirPath) || program.isSourceFileFromExternalLibrary(file);
|
|
106
89
|
}
|
|
@@ -157,7 +140,7 @@ exports.checkTslintJson = checkTslintJson;
|
|
|
157
140
|
function getConfigPath(dirPath) {
|
|
158
141
|
return (0, path_1.join)(dirPath, "tslint.json");
|
|
159
142
|
}
|
|
160
|
-
function getLintConfig(expectedConfigPath
|
|
143
|
+
function getLintConfig(expectedConfigPath) {
|
|
161
144
|
const configExists = fs_1.default.existsSync(expectedConfigPath);
|
|
162
145
|
const configPath = configExists ? expectedConfigPath : (0, path_1.join)(__dirname, "..", "dtslint.json");
|
|
163
146
|
// Second param to `findConfiguration` doesn't matter, since config path is provided.
|
|
@@ -165,18 +148,6 @@ function getLintConfig(expectedConfigPath, tsconfigPath, minVersion, maxVersion,
|
|
|
165
148
|
if (!config) {
|
|
166
149
|
throw new Error(`Could not load config at ${configPath}`);
|
|
167
150
|
}
|
|
168
|
-
const expectRule = config.rules.get("expect");
|
|
169
|
-
if (!expectRule || expectRule.ruleSeverity !== "error") {
|
|
170
|
-
throw new Error("'expect' rule should be enabled, else compile errors are ignored");
|
|
171
|
-
}
|
|
172
|
-
if (expectRule) {
|
|
173
|
-
const versionsToTest = range(minVersion, maxVersion).map((versionName) => ({
|
|
174
|
-
versionName,
|
|
175
|
-
path: (0, utils_1.typeScriptPath)(versionName, tsLocal),
|
|
176
|
-
}));
|
|
177
|
-
const expectOptions = { tsconfigPath, versionsToTest };
|
|
178
|
-
expectRule.ruleArguments = [expectOptions];
|
|
179
|
-
}
|
|
180
151
|
return config;
|
|
181
152
|
}
|
|
182
153
|
function range(minVersion, maxVersion) {
|
package/dist/lint.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"lint.js","sourceRoot":"","sources":["../src/lint.ts"],"names":[],"mappings":";;;;;;AAAA,8EAAyE;AACzE,kDAAsE;AACtE,iCAAkC;AAClC,4CAAoB;AACpB,+BAAoD;AACpD,mCAA+C;AAC/C,mCAAgC;AAKhC,
|
|
1
|
+
{"version":3,"file":"lint.js","sourceRoot":"","sources":["../src/lint.ts"],"names":[],"mappings":";;;;;;AAAA,8EAAyE;AACzE,kDAAsE;AACtE,iCAAkC;AAClC,4CAAoB;AACpB,+BAAoD;AACpD,mCAA+C;AAC/C,mCAAgC;AAKhC,iCAAkC;AAE3B,KAAK,UAAU,IAAI,CACxB,OAAe,EACf,UAAqB,EACrB,UAAqB,EACrB,QAAiB,EACjB,UAAmB,EACnB,OAA2B;IAE3B,MAAM,YAAY,GAAG,IAAA,WAAS,EAAC,OAAO,EAAE,eAAe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AAC,UAAU,KAAK,OAAO,CAAC,CAAC;QAC/B,OAAO,CAAC,OAAO,CAAC,CAAC;KAClB;IACD,IAAI,UAAU,KAAK,uCAAiB,CAAC,MAAM,EAAE;QAC3C,MAAM,CAAC,UAAU,KAAK,uCAAiB,CAAC,MAAM,CAAC,CAAC;QAChD,OAAO,CAAC,uCAAiB,CAAC,MAAM,CAAC,CAAC;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/dist/util.d.ts
CHANGED
|
@@ -3,5 +3,4 @@ export declare function packageNameFromPath(path: string): string;
|
|
|
3
3
|
export declare function readJson(path: string): any;
|
|
4
4
|
export declare function failure(ruleName: string, s: string): string;
|
|
5
5
|
export declare function getCompilerOptions(dirPath: string): ts.CompilerOptions;
|
|
6
|
-
export declare function last<T>(a: readonly T[]): T;
|
|
7
6
|
export declare function isMainFile(fileName: string, allowNested: boolean): boolean;
|
package/dist/util.js
CHANGED
|
@@ -3,8 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.isMainFile = exports.
|
|
7
|
-
const assert = require("assert");
|
|
6
|
+
exports.isMainFile = exports.getCompilerOptions = exports.failure = exports.readJson = exports.packageNameFromPath = void 0;
|
|
8
7
|
const fs_1 = __importDefault(require("fs"));
|
|
9
8
|
const path_1 = require("path");
|
|
10
9
|
const stripJsonComments = require("strip-json-comments");
|
|
@@ -30,11 +29,6 @@ function getCompilerOptions(dirPath) {
|
|
|
30
29
|
return readJson(tsconfigPath).compilerOptions;
|
|
31
30
|
}
|
|
32
31
|
exports.getCompilerOptions = getCompilerOptions;
|
|
33
|
-
function last(a) {
|
|
34
|
-
assert(a.length !== 0);
|
|
35
|
-
return a[a.length - 1];
|
|
36
|
-
}
|
|
37
|
-
exports.last = last;
|
|
38
32
|
function isMainFile(fileName, allowNested) {
|
|
39
33
|
// Linter may be run with cwd of the package. We want `index.d.ts` but not `submodule/index.d.ts` to match.
|
|
40
34
|
if (fileName === "index.d.ts") {
|
package/dist/util.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"util.js","sourceRoot":"","sources":["../src/util.ts"],"names":[],"mappings":";;;;;;AAAA,
|
|
1
|
+
{"version":3,"file":"util.js","sourceRoot":"","sources":["../src/util.ts"],"names":[],"mappings":";;;;;;AAAA,4CAAoB;AACpB,+BAA+C;AAC/C,yDAA0D;AAG1D,SAAgB,mBAAmB,CAAC,IAAY;IAC9C,MAAM,IAAI,GAAG,IAAA,eAAQ,EAAC,IAAI,CAAC,CAAC;IAC5B,OAAO,gBAAgB,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,WAAW,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,IAAA,eAAQ,EAAC,IAAA,cAAO,EAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC;AAChG,CAAC;AAHD,kDAGC;AACD,SAAgB,QAAQ,C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HANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@definitelytyped/dtslint",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.198",
|
|
4
4
|
"description": "Runs tests on TypeScript definition files",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"bin": "./dist/index.js",
|
|
@@ -30,8 +30,8 @@
|
|
|
30
30
|
"tslint": "5.14.0",
|
|
31
31
|
"yargs": "^17.7.2",
|
|
32
32
|
"@definitelytyped/dts-critic": "0.0.191",
|
|
33
|
-
"@definitelytyped/typescript-versions": "0.0.182",
|
|
34
33
|
"@definitelytyped/header-parser": "0.0.190",
|
|
34
|
+
"@definitelytyped/typescript-versions": "0.0.182",
|
|
35
35
|
"@definitelytyped/utils": "0.0.188"
|
|
36
36
|
},
|
|
37
37
|
"peerDependencies": {
|
package/src/lint.ts
CHANGED
|
@@ -9,7 +9,6 @@ import * as TsType from "typescript";
|
|
|
9
9
|
type Configuration = typeof Configuration;
|
|
10
10
|
type IConfigurationFile = Configuration.IConfigurationFile;
|
|
11
11
|
|
|
12
|
-
import { getProgram, Options as ExpectOptions } from "./rules/expectRule";
|
|
13
12
|
import { readJson } from "./util";
|
|
14
13
|
|
|
15
14
|
export async function lint(
|
|
@@ -26,18 +25,12 @@ export async function lint(
|
|
|
26
25
|
// TODO: To remove tslint, replace this with a ts.createProgram (probably)
|
|
27
26
|
const lintProgram = Linter.createProgram(tsconfigPath);
|
|
28
27
|
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
return errors;
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
const linter = new Linter({ fix: false, formatter: "stylish" }, lintProgram);
|
|
37
|
-
const configPath = expectOnly ? joinPaths(__dirname, "..", "dtslint-expect-only.json") : getConfigPath(dirPath);
|
|
28
|
+
// tslint no longer checks ExpectType; skip linting entirely if we're only checking ExpectType.
|
|
29
|
+
const linter = !expectOnly ? new Linter({ fix: false, formatter: "stylish" }, lintProgram) : undefined;
|
|
30
|
+
const configPath = getConfigPath(dirPath);
|
|
38
31
|
// TODO: To port expect-rule, eslint's config will also need to include [minVersion, maxVersion]
|
|
39
32
|
// Also: expect-rule should be renamed to expect-type or check-type or something
|
|
40
|
-
const config = getLintConfig(configPath
|
|
33
|
+
const config = getLintConfig(configPath);
|
|
41
34
|
const esfiles = [];
|
|
42
35
|
|
|
43
36
|
for (const file of lintProgram.getSourceFiles()) {
|
|
@@ -58,69 +51,52 @@ export async function lint(
|
|
|
58
51
|
// External dependencies should have been handled by `testDependencies`;
|
|
59
52
|
// typesVersions should be handled in a separate lint
|
|
60
53
|
if (!isExternalDependency(file, dirPath, lintProgram) && (!isLatest || !isTypesVersionPath(fileName, dirPath))) {
|
|
61
|
-
linter
|
|
54
|
+
linter?.lint(fileName, text, config);
|
|
62
55
|
esfiles.push(fileName);
|
|
63
56
|
}
|
|
64
57
|
}
|
|
65
|
-
const result = linter
|
|
66
|
-
let output = result
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
.
|
|
93
|
-
.
|
|
94
|
-
|
|
95
|
-
|
|
58
|
+
const result = linter?.getResult();
|
|
59
|
+
let output = result?.failures.length ? result.output : "";
|
|
60
|
+
|
|
61
|
+
const versionsToTest = range(minVersion, maxVersion).map((versionName) => ({
|
|
62
|
+
versionName,
|
|
63
|
+
path: typeScriptPath(versionName, tsLocal),
|
|
64
|
+
}));
|
|
65
|
+
|
|
66
|
+
const options: ESLint.Options = {
|
|
67
|
+
cwd: dirPath,
|
|
68
|
+
overrideConfig: {
|
|
69
|
+
overrides: [
|
|
70
|
+
{
|
|
71
|
+
files: ["*.ts", "*.cts", "*.mts", "*.tsx"],
|
|
72
|
+
rules: {
|
|
73
|
+
"@definitelytyped/expect": ["error", { versionsToTest }],
|
|
74
|
+
},
|
|
75
|
+
},
|
|
76
|
+
],
|
|
77
|
+
},
|
|
78
|
+
};
|
|
79
|
+
|
|
80
|
+
if (expectOnly) {
|
|
81
|
+
// Disable the regular config, instead load only the plugins and use just the rule above.
|
|
82
|
+
// TODO(jakebailey): share this with eslint-plugin
|
|
83
|
+
options.useEslintrc = false;
|
|
84
|
+
options.overrideConfig!.plugins = ["@definitelytyped", "@typescript-eslint", "jsdoc"];
|
|
85
|
+
const override = options.overrideConfig!.overrides![0];
|
|
86
|
+
override.parser = "@typescript-eslint/parser";
|
|
87
|
+
override.parserOptions = {
|
|
88
|
+
project: true,
|
|
89
|
+
warnOnUnsupportedTypeScriptVersion: false,
|
|
90
|
+
};
|
|
96
91
|
}
|
|
97
92
|
|
|
98
|
-
const
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
93
|
+
const eslint = new ESLint(options);
|
|
94
|
+
const formatter = await eslint.loadFormatter("stylish");
|
|
95
|
+
const eresults = await eslint.lintFiles(esfiles);
|
|
96
|
+
output += formatter.format(eresults);
|
|
97
|
+
estree.clearCaches();
|
|
103
98
|
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
// Add an edge-case for someone needing to `npm install` in react when they first edit a DT module which depends on it - #226
|
|
107
|
-
const cannotFindDepsDiags = diagnostics.find(
|
|
108
|
-
(d) => d.code === 2307 && d.messageText.toString().includes("Cannot find module"),
|
|
109
|
-
);
|
|
110
|
-
if (cannotFindDepsDiags && cannotFindDepsDiags.file) {
|
|
111
|
-
return `
|
|
112
|
-
A module look-up failed, this often occurs when you need to run \`pnpm install\` on a dependent module before you can lint.
|
|
113
|
-
|
|
114
|
-
Before you debug, first try running:
|
|
115
|
-
|
|
116
|
-
pnpm install -w --filter '...{./types/${dirPath}}...'
|
|
117
|
-
|
|
118
|
-
Then re-run. Full error logs are below.
|
|
119
|
-
|
|
120
|
-
${message}`;
|
|
121
|
-
} else {
|
|
122
|
-
return message;
|
|
123
|
-
}
|
|
99
|
+
return output;
|
|
124
100
|
}
|
|
125
101
|
|
|
126
102
|
export function isExternalDependency(file: TsType.SourceFile, dirPath: string, program: TsType.Program): boolean {
|
|
@@ -191,13 +167,7 @@ function getConfigPath(dirPath: string): string {
|
|
|
191
167
|
return joinPaths(dirPath, "tslint.json");
|
|
192
168
|
}
|
|
193
169
|
|
|
194
|
-
function getLintConfig(
|
|
195
|
-
expectedConfigPath: string,
|
|
196
|
-
tsconfigPath: string,
|
|
197
|
-
minVersion: TsVersion,
|
|
198
|
-
maxVersion: TsVersion,
|
|
199
|
-
tsLocal: string | undefined,
|
|
200
|
-
): IConfigurationFile {
|
|
170
|
+
function getLintConfig(expectedConfigPath: string): IConfigurationFile {
|
|
201
171
|
const configExists = fs.existsSync(expectedConfigPath);
|
|
202
172
|
const configPath = configExists ? expectedConfigPath : joinPaths(__dirname, "..", "dtslint.json");
|
|
203
173
|
// Second param to `findConfiguration` doesn't matter, since config path is provided.
|
|
@@ -206,18 +176,6 @@ function getLintConfig(
|
|
|
206
176
|
throw new Error(`Could not load config at ${configPath}`);
|
|
207
177
|
}
|
|
208
178
|
|
|
209
|
-
const expectRule = config.rules.get("expect");
|
|
210
|
-
if (!expectRule || expectRule.ruleSeverity !== "error") {
|
|
211
|
-
throw new Error("'expect' rule should be enabled, else compile errors are ignored");
|
|
212
|
-
}
|
|
213
|
-
if (expectRule) {
|
|
214
|
-
const versionsToTest = range(minVersion, maxVersion).map((versionName) => ({
|
|
215
|
-
versionName,
|
|
216
|
-
path: typeScriptPath(versionName, tsLocal),
|
|
217
|
-
}));
|
|
218
|
-
const expectOptions: ExpectOptions = { tsconfigPath, versionsToTest };
|
|
219
|
-
expectRule.ruleArguments = [expectOptions];
|
|
220
|
-
}
|
|
221
179
|
return config;
|
|
222
180
|
}
|
|
223
181
|
|
package/src/util.ts
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import assert = require("assert");
|
|
2
1
|
import fs from "fs";
|
|
3
2
|
import { basename, dirname, join } from "path";
|
|
4
3
|
import stripJsonComments = require("strip-json-comments");
|
|
@@ -25,11 +24,6 @@ export function getCompilerOptions(dirPath: string): ts.CompilerOptions {
|
|
|
25
24
|
return readJson(tsconfigPath).compilerOptions as ts.CompilerOptions;
|
|
26
25
|
}
|
|
27
26
|
|
|
28
|
-
export function last<T>(a: readonly T[]): T {
|
|
29
|
-
assert(a.length !== 0);
|
|
30
|
-
return a[a.length - 1];
|
|
31
|
-
}
|
|
32
|
-
|
|
33
27
|
export function isMainFile(fileName: string, allowNested: boolean) {
|
|
34
28
|
// Linter may be run with cwd of the package. We want `index.d.ts` but not `submodule/index.d.ts` to match.
|
|
35
29
|
if (fileName === "index.d.ts") {
|