Skip to content
This repository has been archived by the owner on Nov 16, 2023. It is now read-only.

Commit

Permalink
Support “Minimum” in TS version line (#265)
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewbranch authored and sandersn committed Jan 6, 2020
1 parent 05257e7 commit 5f7605c
Show file tree
Hide file tree
Showing 6 changed files with 11 additions and 10 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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).
Expand Down
6 changes: 3 additions & 3 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 4 additions & 5 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ async function testTypesVersion(
): Promise<void> {
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
Expand Down Expand Up @@ -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);
}
Expand Down
1 change: 1 addition & 0 deletions src/rules/dtHeaderRule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ function walk(ctx: Lint.WalkContext<void>): 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;
}

Expand Down
2 changes: 1 addition & 1 deletion src/rules/expectRule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
Expand Down
1 change: 1 addition & 0 deletions test/dt-header/correct/types/foo/index.d.ts.lint
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@
// Project: https://github.com/bobby-headers/dt-header
// Definitions by: Jane Doe <https://github.com/janedoe>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
// Minimum TypeScript Version: 3.1

0 comments on commit 5f7605c

Please sign in to comment.