mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-05-17 11:24:29 -05:00
Merge branch 'master' into vfs
This commit is contained in:
@@ -164,7 +164,7 @@ namespace Commands {
|
||||
}
|
||||
});
|
||||
};
|
||||
listAuthors.description = "List known and unknown authors for a given spec";
|
||||
listAuthors.description = "List known and unknown authors for a given spec, e.g. 'node authors.js listAuthors origin/release-2.6..origin/release-2.7'";
|
||||
}
|
||||
|
||||
var args = process.argv.slice(2);
|
||||
|
||||
@@ -11,34 +11,39 @@ interface PackageJson {
|
||||
|
||||
function main(): void {
|
||||
const sys = ts.sys;
|
||||
if (sys.args.length < 2) {
|
||||
if (sys.args.length < 3) {
|
||||
sys.write("Usage:" + sys.newLine)
|
||||
sys.write("\tnode configureNightly.js <package.json location> <file containing version>" + sys.newLine);
|
||||
sys.write("\tnode configureNightly.js <dev|insiders> <package.json location> <file containing version>" + sys.newLine);
|
||||
return;
|
||||
}
|
||||
|
||||
const tag = sys.args[0];
|
||||
if (tag !== "dev" && tag !== "insiders") {
|
||||
throw new Error(`Unexpected tag name '${tag}'.`);
|
||||
}
|
||||
|
||||
// Acquire the version from the package.json file and modify it appropriately.
|
||||
const packageJsonFilePath = ts.normalizePath(sys.args[0]);
|
||||
const packageJsonFilePath = ts.normalizePath(sys.args[1]);
|
||||
const packageJsonValue: PackageJson = JSON.parse(sys.readFile(packageJsonFilePath));
|
||||
|
||||
const { majorMinor, patch } = parsePackageJsonVersion(packageJsonValue.version);
|
||||
const nightlyPatch = getNightlyPatch(patch);
|
||||
const prereleasePatch = getPrereleasePatch(tag, patch);
|
||||
|
||||
// Acquire and modify the source file that exposes the version string.
|
||||
const tsFilePath = ts.normalizePath(sys.args[1]);
|
||||
const tsFilePath = ts.normalizePath(sys.args[2]);
|
||||
const tsFileContents = ts.sys.readFile(tsFilePath);
|
||||
const modifiedTsFileContents = updateTsFile(tsFilePath, tsFileContents, majorMinor, patch, nightlyPatch);
|
||||
const modifiedTsFileContents = updateTsFile(tsFilePath, tsFileContents, majorMinor, patch, prereleasePatch);
|
||||
|
||||
// Ensure we are actually changing something - the user probably wants to know that the update failed.
|
||||
if (tsFileContents === modifiedTsFileContents) {
|
||||
let err = `\n '${tsFilePath}' was not updated while configuring for a nightly publish.\n `;
|
||||
let err = `\n '${tsFilePath}' was not updated while configuring for a prerelease publish for '${tag}'.\n `;
|
||||
err += `Ensure that you have not already run this script; otherwise, erase your changes using 'git checkout -- "${tsFilePath}"'.`;
|
||||
throw err + "\n";
|
||||
throw new Error(err + "\n");
|
||||
}
|
||||
|
||||
// Finally write the changes to disk.
|
||||
// Modify the package.json structure
|
||||
packageJsonValue.version = `${majorMinor}.${nightlyPatch}`;
|
||||
packageJsonValue.version = `${majorMinor}.${prereleasePatch}`;
|
||||
sys.writeFile(packageJsonFilePath, JSON.stringify(packageJsonValue, /*replacer:*/ undefined, /*space:*/ 4))
|
||||
sys.writeFile(tsFilePath, modifiedTsFileContents);
|
||||
}
|
||||
@@ -69,7 +74,7 @@ function parsePackageJsonVersion(versionString: string): { majorMinor: string, p
|
||||
}
|
||||
|
||||
/** e.g. 0-dev.20170707 */
|
||||
function getNightlyPatch(plainPatch: string): string {
|
||||
function getPrereleasePatch(tag: string, plainPatch: string): string {
|
||||
// We're going to append a representation of the current time at the end of the current version.
|
||||
// String.prototype.toISOString() returns a 24-character string formatted as 'YYYY-MM-DDTHH:mm:ss.sssZ',
|
||||
// but we'd prefer to just remove separators and limit ourselves to YYYYMMDD.
|
||||
@@ -77,7 +82,7 @@ function getNightlyPatch(plainPatch: string): string {
|
||||
const now = new Date();
|
||||
const timeStr = now.toISOString().replace(/:|T|\.|-/g, "").slice(0, 8);
|
||||
|
||||
return `${plainPatch}-dev.${timeStr}`;
|
||||
return `${plainPatch}-${tag}.${timeStr}`;
|
||||
}
|
||||
|
||||
main();
|
||||
54
scripts/tslint/rules/noDoubleSpaceRule.ts
Normal file
54
scripts/tslint/rules/noDoubleSpaceRule.ts
Normal file
@@ -0,0 +1,54 @@
|
||||
import * as Lint from "tslint/lib";
|
||||
import * as ts from "typescript";
|
||||
|
||||
export class Rule extends Lint.Rules.AbstractRule {
|
||||
public apply(sourceFile: ts.SourceFile): Lint.RuleFailure[] {
|
||||
return this.applyWithFunction(sourceFile, walk);
|
||||
}
|
||||
}
|
||||
|
||||
function walk(ctx: Lint.WalkContext<void>): void {
|
||||
const { sourceFile } = ctx;
|
||||
const lines = sourceFile.text.split("\n");
|
||||
const strings = getLiterals(sourceFile);
|
||||
lines.forEach((line, idx) => {
|
||||
// Skip indentation.
|
||||
const firstNonSpace = /\S/.exec(line);
|
||||
if (firstNonSpace === null) {
|
||||
return;
|
||||
}
|
||||
// Allow common uses of double spaces
|
||||
// * To align `=` or `!=` signs
|
||||
// * To align comments at the end of lines
|
||||
// * To indent inside a comment
|
||||
// * To use two spaces after a period
|
||||
// * To include aligned `->` in a comment
|
||||
const rgx = /[^/*. ] [^-!/= ]/g;
|
||||
rgx.lastIndex = firstNonSpace.index;
|
||||
const doubleSpace = rgx.exec(line);
|
||||
// Also allow to align comments after `@param`
|
||||
if (doubleSpace !== null && !line.includes("@param")) {
|
||||
const pos = lines.slice(0, idx).reduce((len, line) => len + 1 + line.length, 0) + doubleSpace.index;
|
||||
if (!strings.some(s => s.getStart() <= pos && s.end > pos)) {
|
||||
ctx.addFailureAt(pos + 1, 2, "Use only one space.");
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function getLiterals(sourceFile: ts.SourceFile): ReadonlyArray<ts.Node> {
|
||||
const out: ts.Node[] = [];
|
||||
sourceFile.forEachChild(function cb(node) {
|
||||
switch (node.kind) {
|
||||
case ts.SyntaxKind.StringLiteral:
|
||||
case ts.SyntaxKind.TemplateHead:
|
||||
case ts.SyntaxKind.TemplateMiddle:
|
||||
case ts.SyntaxKind.TemplateTail:
|
||||
case ts.SyntaxKind.NoSubstitutionTemplateLiteral:
|
||||
case ts.SyntaxKind.RegularExpressionLiteral:
|
||||
out.push(node);
|
||||
}
|
||||
node.forEachChild(cb);
|
||||
});
|
||||
return out;
|
||||
}
|
||||
@@ -2,7 +2,7 @@ import * as Lint from "tslint/lib";
|
||||
import * as ts from "typescript";
|
||||
|
||||
export class Rule extends Lint.Rules.AbstractRule {
|
||||
public static FAILURE_STRING = "The '|' and '&' operators must be surrounded by single spaces";
|
||||
public static FAILURE_STRING = "The '|' and '&' operators must be surrounded by spaces";
|
||||
|
||||
public apply(sourceFile: ts.SourceFile): Lint.RuleFailure[] {
|
||||
return this.applyWithFunction(sourceFile, walk);
|
||||
@@ -11,26 +11,20 @@ export class Rule extends Lint.Rules.AbstractRule {
|
||||
|
||||
function walk(ctx: Lint.WalkContext<void>): void {
|
||||
const { sourceFile } = ctx;
|
||||
ts.forEachChild(sourceFile, recur);
|
||||
function recur(node: ts.Node): void {
|
||||
if (node.kind === ts.SyntaxKind.UnionType || node.kind === ts.SyntaxKind.IntersectionType) {
|
||||
check((node as ts.UnionOrIntersectionTypeNode).types);
|
||||
sourceFile.forEachChild(function cb(node: ts.Node): void {
|
||||
if (ts.isUnionTypeNode(node) || ts.isIntersectionTypeNode(node)) {
|
||||
check(node);
|
||||
}
|
||||
ts.forEachChild(node, recur);
|
||||
}
|
||||
node.forEachChild(cb);
|
||||
});
|
||||
|
||||
function check(types: ReadonlyArray<ts.TypeNode>): void {
|
||||
let expectedStart = types[0].end + 2; // space, | or &
|
||||
for (let i = 1; i < types.length; i++) {
|
||||
const currentType = types[i];
|
||||
if (expectedStart !== currentType.pos || currentType.getLeadingTriviaWidth() !== 1) {
|
||||
const previousTypeEndPos = sourceFile.getLineAndCharacterOfPosition(types[i - 1].end);
|
||||
const currentTypeStartPos = sourceFile.getLineAndCharacterOfPosition(currentType.pos);
|
||||
if (previousTypeEndPos.line === currentTypeStartPos.line) {
|
||||
ctx.addFailureAtNode(currentType, Rule.FAILURE_STRING);
|
||||
}
|
||||
function check(node: ts.UnionTypeNode | ts.IntersectionTypeNode): void {
|
||||
const list = node.getChildren().find(child => child.kind === ts.SyntaxKind.SyntaxList)!;
|
||||
for (const child of list.getChildren()) {
|
||||
if ((child.kind === ts.SyntaxKind.BarToken || child.kind === ts.SyntaxKind.AmpersandToken)
|
||||
&& (/\S/.test(sourceFile.text[child.getStart(sourceFile) - 1]) || /\S/.test(sourceFile.text[child.end]))) {
|
||||
ctx.addFailureAtNode(child, Rule.FAILURE_STRING);
|
||||
}
|
||||
expectedStart = currentType.end + 2;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user