Skip to content
This repository has been archived by the owner on Mar 25, 2021. It is now read-only.

Ran Prettier across the project #4230

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 24 additions & 13 deletions scripts/buildDocs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ const ruleDocumentation: IDocumentation = {
globPattern: "../lib/rules/*Rule.js",
nameMetadataKey: "ruleName",
pageGenerator: generateRuleFile,
subDirectory: path.join(DOCS_DIR, "rules"),
subDirectory: path.join(DOCS_DIR, "rules")
};

/**
Expand All @@ -104,7 +104,7 @@ const formatterDocumentation: IDocumentation = {
globPattern: "../lib/formatters/*Formatter.js",
nameMetadataKey: "formatterName",
pageGenerator: generateFormatterFile,
subDirectory: path.join(DOCS_DIR, "formatters"),
subDirectory: path.join(DOCS_DIR, "formatters")
};

/**
Expand All @@ -114,7 +114,8 @@ function buildDocumentation(documentation: IDocumentation) {
// Create each module's documentation file.
const modulePaths = glob.sync(documentation.globPattern);
const metadataJson = modulePaths.map((modulePath: string) =>
buildSingleModuleDocumentation(documentation, modulePath));
buildSingleModuleDocumentation(documentation, modulePath)
);

// Delete outdated directories
const rulesDirs = metadataJson.map((metadata: any) => metadata[documentation.nameMetadataKey]);
Expand All @@ -133,17 +134,21 @@ function deleteOutdatedDocumentation(directory: string, rulesDirs: string[]) {
// find if the thing at particular location is a directory
const isDirectory = (source: string) => fs.lstatSync(source).isDirectory();
// get all subdirectories in source directory
const getDirectories = (source: string) => fs.readdirSync(source).filter((name) => isDirectory(path.join(source, name)));
const getDirectories = (source: string) =>
fs.readdirSync(source).filter(name => isDirectory(path.join(source, name)));

const subDirs = getDirectories(directory);
const outdatedDirs = subDirs.filter((dir) => rulesDirs.indexOf(dir) < 0);
outdatedDirs.forEach((outdatedDir) => rimraf.sync(path.join(directory, outdatedDir)));
const outdatedDirs = subDirs.filter(dir => rulesDirs.indexOf(dir) < 0);
outdatedDirs.forEach(outdatedDir => rimraf.sync(path.join(directory, outdatedDir)));
}

/**
* Produces documentation for a single file/module.
*/
function buildSingleModuleDocumentation(documentation: IDocumentation, modulePath: string): Metadata {
function buildSingleModuleDocumentation(
documentation: IDocumentation,
modulePath: string
): Metadata {
// Load the module.
// tslint:disable-next-line:no-var-requires
const module = require(modulePath);
Expand Down Expand Up @@ -180,7 +185,7 @@ function generateJekyllData(metadata: any, layout: string, type: string, name: s
return {
...metadata,
layout,
title: `${type}: ${name}`,
title: `${type}: ${name}`
};
}

Expand All @@ -191,8 +196,9 @@ function generateJekyllData(metadata: any, layout: string, type: string, name: s
function generateRuleFile(metadata: IRuleMetadata): string {
if (metadata.optionExamples) {
metadata = { ...metadata };
metadata.optionExamples = (metadata.optionExamples as any[]).map((example) =>
typeof example === "string" ? example : stringify(example));
metadata.optionExamples = (metadata.optionExamples as any[]).map(
example => (typeof example === "string" ? example : stringify(example))
);
}

if (metadata.codeExamples) {
Expand All @@ -208,16 +214,21 @@ function generateRuleFile(metadata: IRuleMetadata): string {

const yamlData = generateJekyllData(metadata, "rule", "Rule", metadata.ruleName);
yamlData.optionsJSON = JSON.stringify(metadata.options, undefined, 2);
return `---\n${yaml.safeDump(yamlData, {lineWidth: 140} as any)}---`;
return `---\n${yaml.safeDump(yamlData, { lineWidth: 140 } as any)}---`;
}

/**
* Based off a formatter's metadata, generates a Jekyll "HTML" file
* that only consists of a YAML front matter block.
*/
function generateFormatterFile(metadata: IFormatterMetadata): string {
const yamlData = generateJekyllData(metadata, "formatter", "TSLint formatter", metadata.formatterName);
return `---\n${yaml.safeDump(yamlData, {lineWidth: 140} as any)}---`;
const yamlData = generateJekyllData(
metadata,
"formatter",
"TSLint formatter",
metadata.formatterName
);
return `---\n${yaml.safeDump(yamlData, { lineWidth: 140 } as any)}---`;
}

buildDocumentation(ruleDocumentation);
Expand Down
178 changes: 97 additions & 81 deletions scripts/generate-changelog.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,111 +33,125 @@ import { camelize } from "../lib/utils";
const github = new GitHubApi({
host: "api.github.com",
protocol: "https",
timeout: 5000,
timeout: 5000
});

const repoInfo = {
owner: "palantir",
repo: "tslint",
repo: "tslint"
};

const tokenFile = path.join(os.homedir(), "github_token.txt");

// authenticate
const auth: GitHubApi.Auth = {
token: fs.readFileSync(tokenFile, "utf8").toString().trim(),
type: "oauth",
token: fs
.readFileSync(tokenFile, "utf8")
.toString()
.trim(),
type: "oauth"
};
console.log("Using OAuth token " + auth.token + "\n");

// process.env.NODE_TLS_REJECT_UNAUTHORIZED = "0"; // ignores TLS certificate error
github.authenticate(auth);

const commits: ICommit[] = [];
github.repos.getLatestRelease(repoInfo).then((value) => {
console.log("Getting commits " + value.tag_name + "..master");
// get the commits between the most recent release and the head of master
return github.repos.compareCommits({
base: value.tag_name,
head: "master",
...repoInfo,
});
}).then((value) => {
// for each commit, get the PR, and extract changelog entries
const promises: Array<Promise<any>> = [];
for (const commitInfo of value.commits) {
const commit: ICommit = {
fields: [],
sha: commitInfo.sha,
submitter: commitInfo.commit.author.name != null ? commitInfo.commit.author.name : commitInfo.author.login,
title: commitInfo.commit.message,
};
commits.push(commit);

// check for a pull request number in the commit title
const match = (commitInfo.commit.message as string).match(/\(#(\d+)\)/);
if (match && match.length > 1) {
commit.pushRequestNum = Number.parseInt(match[1], 10);

// get the PR text
promises.push(github.issues.get({
number: commit.pushRequestNum,
...repoInfo,
}).then((comment) => {
// extract the changelog entries
const lines = (comment.body as string).split("\r\n");
for (const line of lines) {
const fieldMatch = line.match(/^(\[[a-z\-]+\])/);
if (fieldMatch) {
commit.fields.push({
tag: fieldMatch[1],
text: addLinks(line) + " (#" + commit.pushRequestNum + ")",
});
}
}
}));
github.repos
.getLatestRelease(repoInfo)
.then(value => {
console.log("Getting commits " + value.tag_name + "..master");
// get the commits between the most recent release and the head of master
return github.repos.compareCommits({
base: value.tag_name,
head: "master",
...repoInfo
});
})
.then(value => {
// for each commit, get the PR, and extract changelog entries
const promises: Array<Promise<any>> = [];
for (const commitInfo of value.commits) {
const commit: ICommit = {
fields: [],
sha: commitInfo.sha,
submitter:
commitInfo.commit.author.name != null
? commitInfo.commit.author.name
: commitInfo.author.login,
title: commitInfo.commit.message
};
commits.push(commit);

// check for a pull request number in the commit title
const match = (commitInfo.commit.message as string).match(/\(#(\d+)\)/);
if (match && match.length > 1) {
commit.pushRequestNum = Number.parseInt(match[1], 10);

// get the PR text
promises.push(
github.issues
.get({
number: commit.pushRequestNum,
...repoInfo
})
.then(comment => {
// extract the changelog entries
const lines = (comment.body as string).split("\r\n");
for (const line of lines) {
const fieldMatch = line.match(/^(\[[a-z\-]+\])/);
if (fieldMatch) {
commit.fields.push({
tag: fieldMatch[1],
text: addLinks(line) + " (#" + commit.pushRequestNum + ")"
});
}
}
})
);
}
}

}
return Promise.all(promises);
}).then(() => {
const entries: IField[] = [];
const noFields: string[] = [];
const contributors = new Set<string>();
for (const commit of commits) {
if (commit.fields.length > 0) {
for (const field of commit.fields) {
if (field.tag !== "[no-log]") {
entries.push(field);
return Promise.all(promises);
})
.then(() => {
const entries: IField[] = [];
const noFields: string[] = [];
const contributors = new Set<string>();
for (const commit of commits) {
if (commit.fields.length > 0) {
for (const field of commit.fields) {
if (field.tag !== "[no-log]") {
entries.push(field);
}
}
} else {
noFields.push(commit.title);
}
} else {
noFields.push(commit.title);
contributors.add(commit.submitter);
}
contributors.add(commit.submitter);
}
entries.sort((a, b) => {
return a.tag.localeCompare(b.tag);
});
entries.sort((a, b) => {
return a.tag.localeCompare(b.tag);
});

console.log("\n---- formatted changelog entries: ----");
for (const entry of entries) {
console.log("- " + entry.text);
}
console.log("\n---- formatted changelog entries: ----");
for (const entry of entries) {
console.log("- " + entry.text);
}

console.log("\n---- PRs with missing changelog entries: ----");
for (const missing of noFields) {
console.log("- " + missing.replace(/[\r\n]+/, "\r\n "));
}
console.log("\n---- PRs with missing changelog entries: ----");
for (const missing of noFields) {
console.log("- " + missing.replace(/[\r\n]+/, "\r\n "));
}

console.log("\n---- thanks ----");
console.log("Thanks to our contributors!");
contributors.forEach((contributor) => {
console.log("- " + contributor);
console.log("\n---- thanks ----");
console.log("Thanks to our contributors!");
contributors.forEach(contributor => {
console.log("- " + contributor);
});
})
.catch(error => {
console.log("Error:" + error);
});
}).catch((error) => {
console.log("Error:" + error);
});

const cache = new Map<string, boolean>();

Expand All @@ -159,7 +173,9 @@ function addLinks(text: string): string {
let match = regex.exec(text);
while (match !== null) {
if (isRule(match[1])) {
result += text.slice(lastIndex, match.index) + `[${match[0]}](https://palantir.github.io/tslint/rules/${match[1]}/)`;
result +=
text.slice(lastIndex, match.index) +
`[${match[0]}](https://palantir.github.io/tslint/rules/${match[1]}/)`;
lastIndex = regex.lastIndex;
}
match = regex.exec(text);
Expand Down
Loading