diff --git a/README.md b/README.md index 264a5ff2..e2809c3f 100644 --- a/README.md +++ b/README.md @@ -109,7 +109,7 @@ Normally packages will be tested using TypeScript 2.0. To use a newer version, specify it by including a comment like so: ```ts -// TypeScript Version: 2.1 +// Minimum TypeScript Version: 2.1 ``` For DefinitelyTyped packages, this should go just under the header (on line 5). diff --git a/package-lock.json b/package-lock.json index 1c2f66f3..9aad2754 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1005,9 +1005,9 @@ "integrity": "sha1-WuaBd/GS1EViadEIr6k/+HQ/T2Q=" }, "typescript": { - "version": "3.8.0-dev.20191030", - "resolved": "https://registry.npmjs.org/typescript/-/typescript-3.8.0-dev.20191030.tgz", - "integrity": "sha512-H4ICJQz3KmUy1V7MyBK+YjTDNTHPGuSIbCYxgJbhn/klrgs2P3jBuuS9neb5hpRNe4WU+dtXzPbfrl19czJgiw==" + "version": "3.8.0-dev.20200104", + "resolved": "https://registry.npmjs.org/typescript/-/typescript-3.8.0-dev.20200104.tgz", + "integrity": "sha512-Zdb8X1uzvUPrRvRBqega83NxqCuN/kyxuXG1u8BV10mGOqfwQb0SreSDoDDM1zUgrqFZ93neVh3DVyWTvx6XlA==" }, "universalify": { "version": "0.1.2", diff --git a/src/index.ts b/src/index.ts index 259c3be8..59dc6e1a 100644 --- a/src/index.ts +++ b/src/index.ts @@ -195,7 +195,7 @@ async function testTypesVersion( ): Promise { const minVersionFromComment = getTypeScriptVersionFromComment(indexText); if (minVersionFromComment !== undefined && inTypesVersionDirectory) { - throw new Error(`Already in the \`ts${lowVersion}\` directory, don't need \`// TypeScript Version\`.`); + throw new Error(`Already in the \`ts${lowVersion}\` directory, don't need \`// Minimum TypeScript Version\`.`); } const minVersion = lowVersion || minVersionFromComment && TypeScriptVersion.isSupported(minVersionFromComment) && minVersionFromComment @@ -238,13 +238,12 @@ function assertPathIsNotBanned(dirPath: string) { } function getTypeScriptVersionFromComment(text: string): AllTypeScriptVersion | undefined { - const searchString = "// TypeScript Version: "; - const x = text.indexOf(searchString); - if (x === -1) { + const match = text.match(/\/\/ (?:Minimum)? TypeScript Version: /); + if (!match) { return undefined; } - let line = text.slice(x, text.indexOf("\n", x)); + let line = text.slice(match.index, text.indexOf("\n", match.index)); if (line.endsWith("\r")) { line = line.slice(0, line.length - 1); } diff --git a/src/rules/dtHeaderRule.ts b/src/rules/dtHeaderRule.ts index b8cb1acd..8be8a615 100644 --- a/src/rules/dtHeaderRule.ts +++ b/src/rules/dtHeaderRule.ts @@ -30,6 +30,7 @@ function walk(ctx: Lint.WalkContext): void { if (!isMainFile(sourceFile.fileName, /*allowNested*/ true)) { lookFor("// Type definitions for", "Header should only be in `index.d.ts` of the root."); lookFor("// TypeScript Version", "TypeScript version should be specified under header in `index.d.ts`."); + lookFor("// Minimum TypeScript Version", "TypeScript version should be specified under header in `index.d.ts`."); return; } diff --git a/src/rules/expectRule.ts b/src/rules/expectRule.ts index b238dd13..ba9c5dd3 100644 --- a/src/rules/expectRule.ts +++ b/src/rules/expectRule.ts @@ -211,7 +211,7 @@ function walk( const msg = `Compile error in typescript@${versionName} but not in typescript@${nextHigherVersion}.\n`; const explain = nextHigherVersion === "next" ? "TypeScript@next features not yet supported." - : `Fix with a comment '// TypeScript Version: ${nextHigherVersion}' just under the header.`; + : `Fix with a comment '// Minimum TypeScript Version: ${nextHigherVersion}' just under the header.`; return msg + explain; } } diff --git a/test/dt-header/correct/types/foo/index.d.ts.lint b/test/dt-header/correct/types/foo/index.d.ts.lint index ae1ed782..96bd3849 100644 --- a/test/dt-header/correct/types/foo/index.d.ts.lint +++ b/test/dt-header/correct/types/foo/index.d.ts.lint @@ -2,3 +2,4 @@ // Project: https://github.com/bobby-headers/dt-header // Definitions by: Jane Doe // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped +// Minimum TypeScript Version: 3.1