@definitelytyped/dtslint 0.0.182 → 0.0.184
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 +22 -0
- package/README.md +68 -28
- package/dist/checks.d.ts +4 -3
- package/dist/checks.js +90 -97
- package/dist/checks.js.map +1 -1
- package/dist/index.js +24 -58
- package/dist/index.js.map +1 -1
- package/dist/lint.d.ts +1 -1
- package/dist/lint.js +12 -20
- package/dist/lint.js.map +1 -1
- package/dist/rules/npmNamingRule.js +0 -9
- package/dist/rules/npmNamingRule.js.map +1 -1
- package/dist/updateConfig.js +1 -1
- package/dist/updateConfig.js.map +1 -1
- package/dist/util.d.ts +3 -4
- package/dist/util.js +11 -21
- package/dist/util.js.map +1 -1
- package/package.json +7 -6
- package/src/checks.ts +77 -119
- package/src/index.ts +25 -71
- package/src/lint.ts +17 -31
- package/src/rules/npmNamingRule.ts +0 -9
- package/src/updateConfig.ts +1 -1
- package/src/util.ts +10 -21
- package/test/index.test.ts +100 -31
- package/test/npm-naming/code/types/dts-critic/index.d.ts +0 -5
- package/test/npm-naming/code/types/dts-critic/package.json +17 -0
- package/test/npm-naming/name/types/wenceslas/index.d.ts +1 -4
- package/test/npm-naming/name/types/wenceslas/index.d.ts.lint +2 -6
- package/test/npm-naming/name/types/wenceslas/package.json +17 -0
- package/tsconfig.tsbuildinfo +1 -1
package/src/index.ts
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
|
|
3
|
-
import { parseTypeScriptVersionLine } from "@definitelytyped/header-parser";
|
|
4
3
|
import { AllTypeScriptVersion, TypeScriptVersion } from "@definitelytyped/typescript-versions";
|
|
5
4
|
import assert = require("assert");
|
|
6
|
-
import {
|
|
5
|
+
import { readFile, existsSync } from "fs-extra";
|
|
7
6
|
import { basename, dirname, join as joinPaths, resolve } from "path";
|
|
8
7
|
|
|
9
8
|
import { cleanTypeScriptInstalls, installAllTypeScriptVersions, installTypeScriptNext } from "@definitelytyped/utils";
|
|
10
9
|
import { checkPackageJson, checkTsconfig } from "./checks";
|
|
11
10
|
import { checkTslintJson, lint, TsVersion } from "./lint";
|
|
12
|
-
import { getCompilerOptions,
|
|
11
|
+
import { getCompilerOptions, packageNameFromPath } from "./util";
|
|
12
|
+
import { getTypesVersions } from "@definitelytyped/header-parser";
|
|
13
13
|
|
|
14
14
|
async function main(): Promise<void> {
|
|
15
15
|
const args = process.argv.slice(2);
|
|
@@ -130,50 +130,23 @@ async function runTests(
|
|
|
130
130
|
expectOnly: boolean,
|
|
131
131
|
tsLocal: string | undefined
|
|
132
132
|
): Promise<void> {
|
|
133
|
-
|
|
133
|
+
// Assert that we're really on DefinitelyTyped.
|
|
134
|
+
const dtRoot = findDTRoot(dirPath);
|
|
135
|
+
const packageName = packageNameFromPath(dirPath);
|
|
136
|
+
assertPathIsInDefinitelyTyped(dirPath, dtRoot);
|
|
137
|
+
assertPathIsNotBanned(packageName);
|
|
138
|
+
assertPackageIsNotDeprecated(packageName, await readFile(joinPaths(dtRoot, "notNeededPackages.json"), "utf-8"));
|
|
134
139
|
|
|
135
|
-
const
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
// Someone may have copied text from DefinitelyTyped to their type definition and included a header,
|
|
140
|
-
// so assert that we're really on DefinitelyTyped.
|
|
141
|
-
const dtRoot = findDTRoot(dirPath);
|
|
142
|
-
const packageName = basename(dirPath);
|
|
143
|
-
assertPathIsInDefinitelyTyped(dirPath, dtRoot);
|
|
144
|
-
assertPathIsNotBanned(packageName);
|
|
145
|
-
assertPackageIsNotDeprecated(packageName, await readFile(joinPaths(dtRoot, "notNeededPackages.json"), "utf-8"));
|
|
140
|
+
const typesVersions = getTypesVersions(dirPath);
|
|
141
|
+
const packageJson = checkPackageJson(dirPath, typesVersions);
|
|
142
|
+
if (Array.isArray(packageJson)) {
|
|
143
|
+
throw new Error("\n\t* " + packageJson.join("\n\t* "));
|
|
146
144
|
}
|
|
147
145
|
|
|
148
|
-
const
|
|
149
|
-
if (name === "tsconfig.json" || name === "tslint.json" || name === "tsutils") {
|
|
150
|
-
return undefined;
|
|
151
|
-
}
|
|
152
|
-
const version = withoutPrefix(name, "ts");
|
|
153
|
-
if (version === undefined || !(await stat(joinPaths(dirPath, name))).isDirectory()) {
|
|
154
|
-
return undefined;
|
|
155
|
-
}
|
|
156
|
-
|
|
157
|
-
if (!TypeScriptVersion.isTypeScriptVersion(version)) {
|
|
158
|
-
throw new Error(`There is an entry named ${name}, but ${version} is not a valid TypeScript version.`);
|
|
159
|
-
}
|
|
160
|
-
if (!TypeScriptVersion.isRedirectable(version)) {
|
|
161
|
-
throw new Error(`At ${dirPath}/${name}: TypeScript version directories only available starting with ts3.1.`);
|
|
162
|
-
}
|
|
163
|
-
return version;
|
|
164
|
-
});
|
|
165
|
-
|
|
166
|
-
if (dt) {
|
|
167
|
-
await checkPackageJson(dirPath, typesVersions);
|
|
168
|
-
}
|
|
169
|
-
|
|
170
|
-
const minVersion = maxVersion(
|
|
171
|
-
getMinimumTypeScriptVersionFromComment(indexText),
|
|
172
|
-
TypeScriptVersion.lowest
|
|
173
|
-
) as TypeScriptVersion;
|
|
146
|
+
const minVersion = maxVersion(packageJson.minimumTypeScriptVersion, TypeScriptVersion.lowest);
|
|
174
147
|
if (onlyTestTsNext || tsLocal) {
|
|
175
148
|
const tsVersion = tsLocal ? "local" : TypeScriptVersion.latest;
|
|
176
|
-
await testTypesVersion(dirPath, tsVersion, tsVersion,
|
|
149
|
+
await testTypesVersion(dirPath, tsVersion, tsVersion, expectOnly, tsLocal, /*isLatest*/ true);
|
|
177
150
|
} else {
|
|
178
151
|
// For example, typesVersions of [3.2, 3.5, 3.6] will have
|
|
179
152
|
// associated ts3.2, ts3.5, ts3.6 directories, for
|
|
@@ -194,18 +167,14 @@ async function runTests(
|
|
|
194
167
|
if (lows.length > 1) {
|
|
195
168
|
console.log("testing from", low, "to", hi, "in", versionPath);
|
|
196
169
|
}
|
|
197
|
-
await testTypesVersion(versionPath, low, hi,
|
|
170
|
+
await testTypesVersion(versionPath, low, hi, expectOnly, undefined, isLatest);
|
|
198
171
|
}
|
|
199
172
|
}
|
|
200
173
|
}
|
|
201
174
|
|
|
202
|
-
function maxVersion(v1:
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
if (!v1) return v2;
|
|
206
|
-
if (!v2) return v1;
|
|
207
|
-
if (parseFloat(v1) >= parseFloat(v2)) return v1;
|
|
208
|
-
return v2;
|
|
175
|
+
function maxVersion(v1: AllTypeScriptVersion, v2: TypeScriptVersion): TypeScriptVersion {
|
|
176
|
+
// Note: For v1 to be later than v2, it must be a current Typescript version. So the type assertion is safe.
|
|
177
|
+
return parseFloat(v1) >= parseFloat(v2) ? (v1 as TypeScriptVersion) : v2;
|
|
209
178
|
}
|
|
210
179
|
|
|
211
180
|
function next(v: TypeScriptVersion): TypeScriptVersion {
|
|
@@ -219,17 +188,15 @@ async function testTypesVersion(
|
|
|
219
188
|
dirPath: string,
|
|
220
189
|
lowVersion: TsVersion,
|
|
221
190
|
hiVersion: TsVersion,
|
|
222
|
-
isOlderVersion: boolean,
|
|
223
|
-
dt: boolean,
|
|
224
191
|
expectOnly: boolean,
|
|
225
192
|
tsLocal: string | undefined,
|
|
226
193
|
isLatest: boolean
|
|
227
194
|
): Promise<void> {
|
|
228
|
-
|
|
229
|
-
checkTsconfig(
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
195
|
+
checkTslintJson(dirPath);
|
|
196
|
+
const tsconfigErrors = checkTsconfig(dirPath, getCompilerOptions(dirPath));
|
|
197
|
+
if (tsconfigErrors.length > 0) {
|
|
198
|
+
throw new Error("\n\t* " + tsconfigErrors.join("\n\t* "));
|
|
199
|
+
}
|
|
233
200
|
const err = await lint(dirPath, lowVersion, hiVersion, isLatest, expectOnly, tsLocal);
|
|
234
201
|
if (err) {
|
|
235
202
|
throw new Error(err);
|
|
@@ -288,20 +255,7 @@ If you want to re-add @types/${packageName}, please remove its entry from notNee
|
|
|
288
255
|
}
|
|
289
256
|
}
|
|
290
257
|
|
|
291
|
-
|
|
292
|
-
const match = text.match(/\/\/ (?:Minimum )?TypeScript Version: /);
|
|
293
|
-
if (!match) {
|
|
294
|
-
return undefined;
|
|
295
|
-
}
|
|
296
|
-
|
|
297
|
-
let line = text.slice(match.index, text.indexOf("\n", match.index));
|
|
298
|
-
if (line.endsWith("\r")) {
|
|
299
|
-
line = line.slice(0, line.length - 1);
|
|
300
|
-
}
|
|
301
|
-
return parseTypeScriptVersionLine(line);
|
|
302
|
-
}
|
|
303
|
-
|
|
304
|
-
if (!module.parent) {
|
|
258
|
+
if (require.main === module) {
|
|
305
259
|
main().catch((err) => {
|
|
306
260
|
console.error(err.stack);
|
|
307
261
|
process.exit(1);
|
package/src/lint.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { TypeScriptVersion } from "@definitelytyped/typescript-versions";
|
|
2
|
-
import { typeScriptPath } from "@definitelytyped/utils";
|
|
2
|
+
import { typeScriptPath, withoutStart } from "@definitelytyped/utils";
|
|
3
3
|
import assert = require("assert");
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
4
|
+
import { pathExistsSync } from "fs-extra";
|
|
5
|
+
import { join as joinPaths, normalize } from "path";
|
|
6
6
|
import { Configuration, Linter } from "tslint";
|
|
7
7
|
import { ESLint } from "eslint";
|
|
8
8
|
import * as TsType from "typescript";
|
|
@@ -10,7 +10,7 @@ type Configuration = typeof Configuration;
|
|
|
10
10
|
type IConfigurationFile = Configuration.IConfigurationFile;
|
|
11
11
|
|
|
12
12
|
import { getProgram, Options as ExpectOptions } from "./rules/expectRule";
|
|
13
|
-
import { readJson
|
|
13
|
+
import { readJson } from "./util";
|
|
14
14
|
|
|
15
15
|
export async function lint(
|
|
16
16
|
dirPath: string,
|
|
@@ -37,7 +37,7 @@ export async function lint(
|
|
|
37
37
|
const configPath = expectOnly ? joinPaths(__dirname, "..", "dtslint-expect-only.json") : getConfigPath(dirPath);
|
|
38
38
|
// TODO: To port expect-rule, eslint's config will also need to include [minVersion, maxVersion]
|
|
39
39
|
// Also: expect-rule should be renamed to expect-type or check-type or something
|
|
40
|
-
const config =
|
|
40
|
+
const config = getLintConfig(configPath, tsconfigPath, minVersion, maxVersion, tsLocal);
|
|
41
41
|
const esfiles = [];
|
|
42
42
|
|
|
43
43
|
for (const file of lintProgram.getSourceFiles()) {
|
|
@@ -108,15 +108,12 @@ function testDependencies(
|
|
|
108
108
|
(d) => d.code === 2307 && d.messageText.toString().includes("Cannot find module")
|
|
109
109
|
);
|
|
110
110
|
if (cannotFindDepsDiags && cannotFindDepsDiags.file) {
|
|
111
|
-
const path = cannotFindDepsDiags.file.fileName;
|
|
112
|
-
const typesFolder = dirname(path);
|
|
113
|
-
|
|
114
111
|
return `
|
|
115
|
-
A module look-up failed, this often occurs when you need to run \`
|
|
112
|
+
A module look-up failed, this often occurs when you need to run \`pnpm install\` on a dependent module before you can lint.
|
|
116
113
|
|
|
117
114
|
Before you debug, first try running:
|
|
118
115
|
|
|
119
|
-
|
|
116
|
+
pnpm install -w --filter '...{./types/${dirPath}}...'
|
|
120
117
|
|
|
121
118
|
Then re-run. Full error logs are below.
|
|
122
119
|
|
|
@@ -140,7 +137,7 @@ function normalizePath(file: string) {
|
|
|
140
137
|
function isTypesVersionPath(fileName: string, dirPath: string) {
|
|
141
138
|
const normalFileName = normalizePath(fileName);
|
|
142
139
|
const normalDirPath = normalizePath(dirPath);
|
|
143
|
-
const subdirPath =
|
|
140
|
+
const subdirPath = withoutStart(normalFileName, normalDirPath);
|
|
144
141
|
return subdirPath && /^\/ts\d+\.\d/.test(subdirPath);
|
|
145
142
|
}
|
|
146
143
|
|
|
@@ -179,25 +176,14 @@ function testNoLintDisables(disabler: "tslint:disable" | "eslint-disable", text:
|
|
|
179
176
|
}
|
|
180
177
|
}
|
|
181
178
|
|
|
182
|
-
export
|
|
179
|
+
export function checkTslintJson(dirPath: string): void {
|
|
183
180
|
const configPath = getConfigPath(dirPath);
|
|
184
|
-
const shouldExtend =
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
if (!(await pathExists(configPath))) {
|
|
189
|
-
if (dt) {
|
|
190
|
-
throw new Error(
|
|
191
|
-
`On DefinitelyTyped, must include \`tslint.json\` containing \`{ "extends": "${shouldExtend}" }\`.\n` +
|
|
192
|
-
"This was inferred as a DefinitelyTyped package because it contains a `// Type definitions for` header."
|
|
193
|
-
);
|
|
194
|
-
}
|
|
195
|
-
return;
|
|
181
|
+
const shouldExtend = "@definitelytyped/dtslint/dt.json";
|
|
182
|
+
if (!pathExistsSync(configPath)) {
|
|
183
|
+
throw new Error(`Missing \`tslint.json\` that contains \`{ "extends": "${shouldExtend}" }\`.`);
|
|
196
184
|
}
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
if (!validateExtends(tslintJson.extends)) {
|
|
200
|
-
throw new Error(`If 'tslint.json' is present, it should extend "${shouldExtend}"`);
|
|
185
|
+
if (readJson(configPath).extends !== shouldExtend) {
|
|
186
|
+
throw new Error(`'tslint.json' must extend "${shouldExtend}"`);
|
|
201
187
|
}
|
|
202
188
|
}
|
|
203
189
|
|
|
@@ -205,14 +191,14 @@ function getConfigPath(dirPath: string): string {
|
|
|
205
191
|
return joinPaths(dirPath, "tslint.json");
|
|
206
192
|
}
|
|
207
193
|
|
|
208
|
-
|
|
194
|
+
function getLintConfig(
|
|
209
195
|
expectedConfigPath: string,
|
|
210
196
|
tsconfigPath: string,
|
|
211
197
|
minVersion: TsVersion,
|
|
212
198
|
maxVersion: TsVersion,
|
|
213
199
|
tsLocal: string | undefined
|
|
214
|
-
):
|
|
215
|
-
const configExists =
|
|
200
|
+
): IConfigurationFile {
|
|
201
|
+
const configExists = pathExistsSync(expectedConfigPath);
|
|
216
202
|
const configPath = configExists ? expectedConfigPath : joinPaths(__dirname, "..", "dtslint.json");
|
|
217
203
|
// Second param to `findConfiguration` doesn't matter, since config path is provided.
|
|
218
204
|
const config = Configuration.findConfiguration(configPath, "").results;
|
|
@@ -172,13 +172,6 @@ function toCriticOptions(options: ConfigOptions): Options {
|
|
|
172
172
|
|
|
173
173
|
function walk(ctx: Lint.WalkContext<CriticOptions>): void {
|
|
174
174
|
const { sourceFile } = ctx;
|
|
175
|
-
const { text } = sourceFile;
|
|
176
|
-
const lookFor = (search: string, explanation: string) => {
|
|
177
|
-
const idx = text.indexOf(search);
|
|
178
|
-
if (idx !== -1) {
|
|
179
|
-
ctx.addFailureAt(idx, search.length, failure(Rule.metadata.ruleName, explanation));
|
|
180
|
-
}
|
|
181
|
-
};
|
|
182
175
|
if (isMainFile(sourceFile.fileName, /*allowNested*/ false)) {
|
|
183
176
|
try {
|
|
184
177
|
const optionsWithSuggestions = toOptionsWithSuggestions(ctx.options);
|
|
@@ -189,8 +182,6 @@ function walk(ctx: Lint.WalkContext<CriticOptions>): void {
|
|
|
189
182
|
case ErrorKind.NoMatchingNpmPackage:
|
|
190
183
|
case ErrorKind.NoMatchingNpmVersion:
|
|
191
184
|
case ErrorKind.NonNpmHasMatchingPackage:
|
|
192
|
-
lookFor("// Type definitions for", errorMessage(error, ctx.options));
|
|
193
|
-
break;
|
|
194
185
|
case ErrorKind.DtsPropertyNotInJs:
|
|
195
186
|
case ErrorKind.DtsSignatureNotInJs:
|
|
196
187
|
case ErrorKind.JsPropertyNotInDts:
|
package/src/updateConfig.ts
CHANGED
package/src/util.ts
CHANGED
|
@@ -1,11 +1,15 @@
|
|
|
1
1
|
import assert = require("assert");
|
|
2
|
-
import {
|
|
2
|
+
import { pathExistsSync, readFileSync } from "fs-extra";
|
|
3
3
|
import { basename, dirname, join } from "path";
|
|
4
4
|
import stripJsonComments = require("strip-json-comments");
|
|
5
5
|
import * as ts from "typescript";
|
|
6
6
|
|
|
7
|
-
export
|
|
8
|
-
const
|
|
7
|
+
export function packageNameFromPath(path: string): string {
|
|
8
|
+
const base = basename(path);
|
|
9
|
+
return /^v\d+(\.\d+)?$/.exec(base) || /^ts\d\.\d/.exec(base) ? basename(dirname(path)) : base;
|
|
10
|
+
}
|
|
11
|
+
export function readJson(path: string) {
|
|
12
|
+
const text = readFileSync(path, "utf-8");
|
|
9
13
|
return JSON.parse(stripJsonComments(text));
|
|
10
14
|
}
|
|
11
15
|
|
|
@@ -13,16 +17,12 @@ export function failure(ruleName: string, s: string): string {
|
|
|
13
17
|
return `${s} See: https://github.com/microsoft/DefinitelyTyped-tools/blob/master/packages/dtslint/docs/${ruleName}.md`;
|
|
14
18
|
}
|
|
15
19
|
|
|
16
|
-
export
|
|
20
|
+
export function getCompilerOptions(dirPath: string): ts.CompilerOptions {
|
|
17
21
|
const tsconfigPath = join(dirPath, "tsconfig.json");
|
|
18
|
-
if (!(
|
|
22
|
+
if (!pathExistsSync(tsconfigPath)) {
|
|
19
23
|
throw new Error(`Need a 'tsconfig.json' file in ${dirPath}`);
|
|
20
24
|
}
|
|
21
|
-
return
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
export function withoutPrefix(s: string, prefix: string): string | undefined {
|
|
25
|
-
return s.startsWith(prefix) ? s.slice(prefix.length) : undefined;
|
|
25
|
+
return readJson(tsconfigPath).compilerOptions as ts.CompilerOptions;
|
|
26
26
|
}
|
|
27
27
|
|
|
28
28
|
export function last<T>(a: readonly T[]): T {
|
|
@@ -30,17 +30,6 @@ export function last<T>(a: readonly T[]): T {
|
|
|
30
30
|
return a[a.length - 1];
|
|
31
31
|
}
|
|
32
32
|
|
|
33
|
-
export async function mapDefinedAsync<T, U>(arr: Iterable<T>, mapper: (t: T) => Promise<U | undefined>): Promise<U[]> {
|
|
34
|
-
const out = [];
|
|
35
|
-
for (const a of arr) {
|
|
36
|
-
const res = await mapper(a);
|
|
37
|
-
if (res !== undefined) {
|
|
38
|
-
out.push(res);
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
return out;
|
|
42
|
-
}
|
|
43
|
-
|
|
44
33
|
export function isMainFile(fileName: string, allowNested: boolean) {
|
|
45
34
|
// Linter may be run with cwd of the package. We want `index.d.ts` but not `submodule/index.d.ts` to match.
|
|
46
35
|
if (fileName === "index.d.ts") {
|
package/test/index.test.ts
CHANGED
|
@@ -37,43 +37,112 @@ describe("dtslint", () => {
|
|
|
37
37
|
noImplicitThis: true,
|
|
38
38
|
strictNullChecks: true,
|
|
39
39
|
strictFunctionTypes: true,
|
|
40
|
-
baseUrl: "../",
|
|
41
|
-
typeRoots: ["../"],
|
|
42
40
|
types: [],
|
|
43
41
|
noEmit: true,
|
|
44
42
|
forceConsistentCasingInFileNames: true,
|
|
45
43
|
};
|
|
46
44
|
describe("checks", () => {
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
"
|
|
50
|
-
|
|
45
|
+
describe("checkTsconfig", () => {
|
|
46
|
+
it("disallows unknown compiler options", () => {
|
|
47
|
+
expect(checkTsconfig("test", { ...base, completelyInvented: true })).toEqual([
|
|
48
|
+
"Unexpected compiler option completelyInvented",
|
|
49
|
+
]);
|
|
50
|
+
});
|
|
51
|
+
it("allows exactOptionalPropertyTypes: true", () => {
|
|
52
|
+
expect(checkTsconfig("test", { ...base, exactOptionalPropertyTypes: true })).toEqual([]);
|
|
53
|
+
});
|
|
54
|
+
it("allows module: node16", () => {
|
|
55
|
+
expect(checkTsconfig("test", { ...base, module: "node16" })).toEqual([]);
|
|
56
|
+
});
|
|
57
|
+
it("allows `paths`", () => {
|
|
58
|
+
expect(checkTsconfig("test", { ...base, paths: { boom: ["../boom/index.d.ts"] } })).toEqual([]);
|
|
59
|
+
});
|
|
60
|
+
it("disallows missing `module`", () => {
|
|
61
|
+
const options = { ...base };
|
|
62
|
+
delete options.module;
|
|
63
|
+
expect(checkTsconfig("test", options)).toEqual([
|
|
64
|
+
'Must specify "module" to `"module": "commonjs"` or `"module": "node16"`.',
|
|
65
|
+
]);
|
|
66
|
+
});
|
|
67
|
+
it("disallows exactOptionalPropertyTypes: false", () => {
|
|
68
|
+
expect(checkTsconfig("test", { ...base, exactOptionalPropertyTypes: false })).toEqual([
|
|
69
|
+
'When "exactOptionalPropertyTypes" is present, it must be set to `true`.',
|
|
70
|
+
]);
|
|
71
|
+
});
|
|
72
|
+
it("allows paths: self-reference", () => {
|
|
73
|
+
expect(checkTsconfig("react-native", { ...base, paths: { "react-native": ["./index.d.ts"] } })).toEqual([]);
|
|
74
|
+
});
|
|
75
|
+
it("allows paths: matching ../reference/index.d.ts", () => {
|
|
76
|
+
expect(
|
|
77
|
+
checkTsconfig("reactive-dep", { ...base, paths: { "react-native": ["../react-native/index.d.ts"] } })
|
|
78
|
+
).toEqual([]);
|
|
79
|
+
expect(
|
|
80
|
+
checkTsconfig("reactive-dep", {
|
|
81
|
+
...base,
|
|
82
|
+
paths: { "react-native": ["../react-native/index.d.ts"], react: ["../react/v16/index.d.ts"] },
|
|
83
|
+
})
|
|
84
|
+
).toEqual([]);
|
|
85
|
+
});
|
|
86
|
+
it("forbids paths: mapping to multiple things", () => {
|
|
87
|
+
expect(
|
|
88
|
+
checkTsconfig("reactive-dep", {
|
|
89
|
+
...base,
|
|
90
|
+
paths: { "react-native": ["./index.d.ts", "../react-native/v0.68/index.d.ts"] },
|
|
91
|
+
})
|
|
92
|
+
).toEqual([`reactive-dep/tsconfig.json: "paths" must map each module specifier to only one file.`]);
|
|
93
|
+
});
|
|
94
|
+
it("allows paths: matching ../reference/version/index.d.ts", () => {
|
|
95
|
+
expect(checkTsconfig("reactive-dep", { ...base, paths: { react: ["../react/v16/index.d.ts"] } })).toEqual([]);
|
|
96
|
+
expect(
|
|
97
|
+
checkTsconfig("reactive-dep", { ...base, paths: { "react-native": ["../react-native/v0.69/index.d.ts"] } })
|
|
98
|
+
).toEqual([]);
|
|
99
|
+
expect(
|
|
100
|
+
checkTsconfig("reactive-dep/v1", {
|
|
101
|
+
...base,
|
|
102
|
+
paths: { "react-native": ["../../react-native/v0.69/index.d.ts"] },
|
|
103
|
+
})
|
|
104
|
+
).toEqual([]);
|
|
105
|
+
});
|
|
106
|
+
it("forbids paths: mapping to self-contained file", () => {
|
|
107
|
+
expect(checkTsconfig("rrrr", { ...base, paths: { "react-native": ["./other.d.ts"] } })).toEqual([
|
|
108
|
+
`rrrr/tsconfig.json: "paths" must map 'react-native' to react-native's index.d.ts.`,
|
|
109
|
+
]);
|
|
110
|
+
});
|
|
111
|
+
it("forbids paths: mismatching ../NOT/index.d.ts", () => {
|
|
112
|
+
expect(checkTsconfig("rrrr", { ...base, paths: { "react-native": ["../cocoa/index.d.ts"] } })).toEqual([
|
|
113
|
+
`rrrr/tsconfig.json: "paths" must map 'react-native' to react-native's index.d.ts.`,
|
|
114
|
+
]);
|
|
115
|
+
});
|
|
116
|
+
it("forbids paths: mismatching ../react-native/NOT.d.ts", () => {
|
|
117
|
+
expect(checkTsconfig("rrrr", { ...base, paths: { "react-native": ["../react-native/other.d.ts"] } })).toEqual([
|
|
118
|
+
`rrrr/tsconfig.json: "paths" must map 'react-native' to react-native's index.d.ts.`,
|
|
119
|
+
]);
|
|
120
|
+
});
|
|
121
|
+
it("forbids paths: mismatching ../react-native/NOT/index.d.ts", () => {
|
|
122
|
+
expect(
|
|
123
|
+
checkTsconfig("rrrr", { ...base, paths: { "react-native": ["../react-native/deep/index.d.ts"] } })
|
|
124
|
+
).toEqual([`rrrr/tsconfig.json: "paths" must map 'react-native' to react-native's index.d.ts.`]);
|
|
125
|
+
});
|
|
126
|
+
it("forbids paths: mismatching ../react-native/version/NOT/index.d.ts", () => {
|
|
127
|
+
expect(
|
|
128
|
+
checkTsconfig("rrrr", { ...base, paths: { "react-native": ["../react-native/v0.68/deep/index.d.ts"] } })
|
|
129
|
+
).toEqual([`rrrr/tsconfig.json: "paths" must map 'react-native' to react-native's index.d.ts.`]);
|
|
130
|
+
});
|
|
131
|
+
it("forbids paths: mismatching ../react-native/version/NOT.d.ts", () => {
|
|
132
|
+
expect(
|
|
133
|
+
checkTsconfig("rrrr", { ...base, paths: { "react-native": ["../react-native/v0.70/other.d.ts"] } })
|
|
134
|
+
).toEqual([`rrrr/tsconfig.json: "paths" must map 'react-native' to react-native's index.d.ts.`]);
|
|
135
|
+
});
|
|
51
136
|
});
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
expect(() => checkTsconfig(options, { relativeBaseUrl: "../" })).toThrow(
|
|
62
|
-
'Must specify "module" to `"module": "commonjs"` or `"module": "node16"`.'
|
|
63
|
-
);
|
|
64
|
-
});
|
|
65
|
-
it("disallows exactOptionalPropertyTypes: false", () => {
|
|
66
|
-
expect(() => checkTsconfig({ ...base, exactOptionalPropertyTypes: false }, { relativeBaseUrl: "../" })).toThrow(
|
|
67
|
-
'When "exactOptionalPropertyTypes" is present, it must be set to `true`.'
|
|
68
|
-
);
|
|
69
|
-
});
|
|
70
|
-
it("disallows packages that are in notNeededPackages.json", () => {
|
|
71
|
-
expect(() => assertPackageIsNotDeprecated("foo", '{ "packages": { "foo": { } } }')).toThrow(
|
|
72
|
-
"notNeededPackages.json has an entry for foo."
|
|
73
|
-
);
|
|
74
|
-
});
|
|
75
|
-
it("allows packages that are not in notNeededPackages.json", () => {
|
|
76
|
-
expect(assertPackageIsNotDeprecated("foo", '{ "packages": { "bar": { } } }')).toBeUndefined();
|
|
137
|
+
describe("assertPackageIsNotDeprecated", () => {
|
|
138
|
+
it("disallows packages that are in notNeededPackages.json", () => {
|
|
139
|
+
expect(() => assertPackageIsNotDeprecated("foo", '{ "packages": { "foo": { } } }')).toThrow(
|
|
140
|
+
"notNeededPackages.json has an entry for foo."
|
|
141
|
+
);
|
|
142
|
+
});
|
|
143
|
+
it("allows packages that are not in notNeededPackages.json", () => {
|
|
144
|
+
expect(assertPackageIsNotDeprecated("foo", '{ "packages": { "bar": { } } }')).toBeUndefined();
|
|
145
|
+
});
|
|
77
146
|
});
|
|
78
147
|
});
|
|
79
148
|
describe("rules", () => {
|
|
@@ -1,6 +1 @@
|
|
|
1
|
-
// Type definitions for package dts-critic 1.0
|
|
2
|
-
// Project: https://https://github.com/DefinitelyTyped/dts-critic
|
|
3
|
-
// Definitions by: Jane Doe <https://github.com/janedoe>
|
|
4
|
-
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
|
5
|
-
|
|
6
1
|
export default dtsCritic();
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
{
|
|
2
|
+
"private": true,
|
|
3
|
+
"name": "@types/dts-critic",
|
|
4
|
+
"version": "1.0.9999",
|
|
5
|
+
"projects": [
|
|
6
|
+
"https://github.com/microsoft/TypeScript"
|
|
7
|
+
],
|
|
8
|
+
"devDependencies": {
|
|
9
|
+
"@types/dts-critic": "workspace:."
|
|
10
|
+
},
|
|
11
|
+
"owners": [
|
|
12
|
+
{
|
|
13
|
+
"name": "Jane Doe",
|
|
14
|
+
"githubUsername": "janedoe"
|
|
15
|
+
}
|
|
16
|
+
]
|
|
17
|
+
}
|
|
@@ -1,6 +1,2 @@
|
|
|
1
|
-
//
|
|
2
|
-
|
|
3
|
-
// Project: https://github.com/bobby-headers/dt-header
|
|
4
|
-
// Definitions by: Jane Doe <https://github.com/janedoe>
|
|
5
|
-
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
|
6
|
-
[0]: Declaration file must have a matching npm package. To resolve this error, either: 1. Change the name to match an npm package. 2. Add a Definitely Typed header with the first line // Type definitions for non-npm package wenceslas-browser Add -browser to the end of your name to make sure it doesn't conflict with existing npm packages. If you won't fix this error now or you think this error is wrong, you can disable this check by adding the following options to your project's tslint.json file under "rules": "npm-naming": false See: https://github.com/microsoft/DefinitelyTyped-tools/blob/master/packages/dtslint/docs/npm-naming.md
|
|
1
|
+
// hi
|
|
2
|
+
~ [Declaration file must have a matching npm package. To resolve this error, either: 1. Change the name to match an npm package. 2. Add `"nonNpm": true` to the package.json to indicate that this is not an npm package. Ensure the package name is descriptive enough to avoid conflicts with future npm packages. If you won't fix this error now or you think this error is wrong, you can disable this check by adding the following options to your project's tslint.json file under "rules": "npm-naming": false See: https://github.com/microsoft/DefinitelyTyped-tools/blob/master/packages/dtslint/docs/npm-naming.md]
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
{
|
|
2
|
+
"private": true,
|
|
3
|
+
"name": "@types/wenceslas",
|
|
4
|
+
"version": "0.0.9999",
|
|
5
|
+
"projects": [
|
|
6
|
+
"https://github.com/bobby-headers/dt-header"
|
|
7
|
+
],
|
|
8
|
+
"devDependencies": {
|
|
9
|
+
"@types/wenceslas": "workspace:."
|
|
10
|
+
},
|
|
11
|
+
"owners": [
|
|
12
|
+
{
|
|
13
|
+
"name": "Jane Doe",
|
|
14
|
+
"githubUsername": "janedoe"
|
|
15
|
+
}
|
|
16
|
+
]
|
|
17
|
+
}
|