diff --git a/package.json b/package.json index 5bc16cab..53cf85d4 100644 --- a/package.json +++ b/package.json @@ -27,6 +27,7 @@ "fix": "npm run lint -- --fix", "lint": "tslint --project . --format stylish", "prepublish": "npm run build", + "prettier": "prettier --write 'src/**/*.ts'", "test": "jest", "test-ci": "npm run build && jest", "watch": "npm run build -- --watch" @@ -47,9 +48,12 @@ "fs-extra": "^6.0.1", "jest": "^23.1.0", "jest-runner-tslint": "^1.0.5", + "prettier": "1.13.5", "rimraf": "^2.5.4", "ts-jest": "^22.4.6", "tslint": "^5.10.0", + "tslint-config-prettier": "^1.13.0", + "tslint-plugin-prettier": "^1.3.0", "typescript": "^2.9.2" }, "engines": { @@ -89,9 +93,19 @@ { "runner": "jest-runner-tslint", "displayName": "lint", - "moduleFileExtensions": ["ts"], - "testMatch": ["/src/**/*.ts"] + "moduleFileExtensions": [ + "ts" + ], + "testMatch": [ + "/src/**/*.ts" + ] } ] + }, + "prettier": { + "printWidth": 120, + "tabWidth": 2, + "singleQuote": false, + "trailingComma": "es5" } } diff --git a/src/changelog.spec.ts b/src/changelog.spec.ts index cb14d705..652ceb88 100644 --- a/src/changelog.spec.ts +++ b/src/changelog.spec.ts @@ -47,18 +47,33 @@ describe("Changelog", () => { summary: "chore(release): releasing component", date: "2017-01-01", }, - { sha: "a0000004", refName: "", summary: "Merge pull request #2 from my-feature", date: "2017-01-01" }, - { sha: "a0000003", refName: "", summary: "feat(module) Add new module (#2)", date: "2017-01-01" }, - { sha: "a0000002", refName: "", summary: "refactor(module) Simplify implementation", date: "2017-01-01" }, - { sha: "a0000001", refName: "tag: v0.1.0", summary: "chore(release): releasing component", date: "2017-01-01" }, + { + sha: "a0000004", + refName: "", + summary: "Merge pull request #2 from my-feature", + date: "2017-01-01", + }, + { + sha: "a0000003", + refName: "", + summary: "feat(module) Add new module (#2)", + date: "2017-01-01", + }, + { + sha: "a0000002", + refName: "", + summary: "refactor(module) Simplify implementation", + date: "2017-01-01", + }, + { + sha: "a0000001", + refName: "tag: v0.1.0", + summary: "chore(release): releasing component", + date: "2017-01-01", + }, ]); - require("./git").listTagNames.mockImplementation(() => [ - "v0.2.0", - "v0.1.1", - "v0.1.0", - "v0.0.1", - ]); + require("./git").listTagNames.mockImplementation(() => ["v0.2.0", "v0.1.1", "v0.1.0", "v0.0.1"]); require("./git").changedPaths.mockImplementation(() => []); @@ -73,10 +88,7 @@ describe("Changelog", () => { "https://api.github.com/repos/lerna/lerna-changelog/issues/2": { number: 2, title: "This is the commit title for the issue (#2)", - labels: [ - { name: "Type: New Feature" }, - { name: "Status: In Progress" }, - ], + labels: [{ name: "Type: New Feature" }, { name: "Status: In Progress" }], user: usersCache["https://api.github.com/users/test-user"], }, }; @@ -135,22 +147,31 @@ describe("Changelog", () => { }); const testCommits = [ - { commitSHA: "a0000004", githubIssue: { user: { login: "test-user-1" } } }, - { commitSHA: "a0000003", githubIssue: { user: { login: "test-user-2" } } }, + { + commitSHA: "a0000004", + githubIssue: { user: { login: "test-user-1" } }, + }, + { + commitSHA: "a0000003", + githubIssue: { user: { login: "test-user-2" } }, + }, { commitSHA: "a0000002", githubIssue: { user: { login: "user-bot" } } }, { commitSHA: "a0000001" }, ]; const committers = await changelog.getCommitters(testCommits); - expect(committers).toEqual([{ - login: "test-user-1", - html_url: "https://github.com/test-user-1", - name: "Test User 1", - }, { - login: "test-user-2", - html_url: "https://github.com/test-user-2", - name: "Test User 2", - }]); + expect(committers).toEqual([ + { + login: "test-user-1", + html_url: "https://github.com/test-user-1", + name: "Test User 1", + }, + { + login: "test-user-2", + html_url: "https://github.com/test-user-2", + name: "Test User 2", + }, + ]); }); }); }); diff --git a/src/changelog.ts b/src/changelog.ts index 853188ce..9ea4b505 100644 --- a/src/changelog.ts +++ b/src/changelog.ts @@ -4,8 +4,8 @@ import progressBar from "./progress-bar"; import * as Configuration from "./configuration"; import findPullRequestId from "./find-pull-request-id"; import * as Git from "./git"; -import GithubAPI, {GitHubUserResponse} from "./github-api"; -import {CommitInfo, Release} from "./interfaces"; +import GithubAPI, { GitHubUserResponse } from "./github-api"; +import { CommitInfo, Release } from "./interfaces"; import MarkdownRenderer from "./markdown-renderer"; const UNRELEASED_TAG = "___unreleased___"; @@ -113,7 +113,7 @@ export default class Changelog { } } - return Object.keys(committers).map((k) => committers[k]); + return Object.keys(committers).map(k => committers[k]); } private ignoreCommitter(login: string): boolean { @@ -126,7 +126,7 @@ export default class Changelog { private async toCommitInfos(commits: Git.CommitListItem[]): Promise { const allTags = await Git.listTagNames(); - return commits.map((commit) => { + return commits.map(commit => { const { sha, refName, summary: message, date } = commit; let tagsInCommit; @@ -152,15 +152,19 @@ export default class Changelog { private async downloadIssueData(commitInfos: CommitInfo[]) { progressBar.init(commitInfos.length); - await pMap(commitInfos, async (commitInfo: CommitInfo) => { - progressBar.setTitle(commitInfo.commitSHA); + await pMap( + commitInfos, + async (commitInfo: CommitInfo) => { + progressBar.setTitle(commitInfo.commitSHA); - if (commitInfo.issueNumber) { - commitInfo.githubIssue = await this.github.getIssueData(this.config.repo, commitInfo.issueNumber); - } + if (commitInfo.issueNumber) { + commitInfo.githubIssue = await this.github.getIssueData(this.config.repo, commitInfo.issueNumber); + } - progressBar.tick(); - }, { concurrency: 5 }); + progressBar.tick(); + }, + { concurrency: 5 } + ); progressBar.terminate(); } @@ -191,7 +195,7 @@ export default class Changelog { } } - return Object.keys(releaseMap).map((tag) => releaseMap[tag]); + return Object.keys(releaseMap).map(tag => releaseMap[tag]); } private getToday() { @@ -203,24 +207,28 @@ export default class Changelog { for (const commit of commits) { if (!commit.githubIssue || !commit.githubIssue.labels) continue; - const labels = commit.githubIssue.labels.map((label) => label.name.toLowerCase()); + const labels = commit.githubIssue.labels.map(label => label.name.toLowerCase()); commit.categories = Object.keys(this.config.labels) - .filter((label) => labels.indexOf(label.toLowerCase()) !== -1) - .map((label) => this.config.labels[label]); + .filter(label => labels.indexOf(label.toLowerCase()) !== -1) + .map(label => this.config.labels[label]); } } private async fillInPackages(commits: CommitInfo[]) { progressBar.init(commits.length); - await pMap(commits, async (commit: CommitInfo) => { - progressBar.setTitle(commit.commitSHA); + await pMap( + commits, + async (commit: CommitInfo) => { + progressBar.setTitle(commit.commitSHA); - commit.packages = await this.getListOfUniquePackages(commit.commitSHA); + commit.packages = await this.getListOfUniquePackages(commit.commitSHA); - progressBar.tick(); - }, { concurrency: 5 }); + progressBar.tick(); + }, + { concurrency: 5 } + ); progressBar.terminate(); } diff --git a/src/cli.ts b/src/cli.ts index 0656e7f0..819411b9 100644 --- a/src/cli.ts +++ b/src/cli.ts @@ -18,17 +18,13 @@ export async function run() { desc: "A git tag that determines the upper bound of the range of commits", }, }) - .example( - "lerna-changelog", - "create a changelog for the changes after the latest available tag", - ) + .example("lerna-changelog", "create a changelog for the changes after the latest available tag") .example( "lerna-changelog --tag-from 0.1.0 --tag-to 0.3.0", - "create a changelog for the changes in all tags within the given range", + "create a changelog for the changes in all tags within the given range" ) .version() - .help() - .argv; + .help().argv; let options = { tagFrom: argv["tag-from"], @@ -36,9 +32,8 @@ export async function run() { }; try { - let result = await (new Changelog(options)).createMarkdown(); + let result = await new Changelog(options).createMarkdown(); console.log(result); - } catch (e) { if (e instanceof ConfigurationError) { console.log(chalk.red(e.message)); diff --git a/src/configuration.spec.ts b/src/configuration.spec.ts index b4deb9cd..ae426bc0 100644 --- a/src/configuration.spec.ts +++ b/src/configuration.spec.ts @@ -86,19 +86,23 @@ describe("Configuration", function() { tests.forEach(([input, output]) => { it(`'${input}' -> '${output}'`, function() { - expect(findRepoFromPkg({ - repository: { - type: "git", - url: input, - }, - })).toEqual(output); + expect( + findRepoFromPkg({ + repository: { + type: "git", + url: input, + }, + }) + ).toEqual(output); }); }); it(`works with shorthand 'repository' syntax`, function() { - expect(findRepoFromPkg({ - repository: "https://github.com/babel/ember-cli-babel", - })).toEqual("babel/ember-cli-babel"); + expect( + findRepoFromPkg({ + repository: "https://github.com/babel/ember-cli-babel", + }) + ).toEqual("babel/ember-cli-babel"); }); }); }); diff --git a/src/configuration.ts b/src/configuration.ts index eac5f182..393ba02a 100644 --- a/src/configuration.ts +++ b/src/configuration.ts @@ -16,7 +16,7 @@ export function fromPath(rootPath: string): any { if (!config) { throw new ConfigurationError( "Missing changelog config in `lerna.json`.\n" + - "See docs for setup: https://github.com/lerna/lerna-changelog#readme", + "See docs for setup: https://github.com/lerna/lerna-changelog#readme" ); } diff --git a/src/find-pull-request-id.spec.ts b/src/find-pull-request-id.spec.ts index b82da747..51515a10 100644 --- a/src/find-pull-request-id.spec.ts +++ b/src/find-pull-request-id.spec.ts @@ -4,19 +4,22 @@ import findPullRequestId from "./find-pull-request-id"; describe("findPullRequestId", function() { it("finds the id in a GitHub merge commit", function() { - const message = "Merge pull request #42 from Turbo87/pkg-config\n\nRead \"changelog\" config key from \"package.json\" too"; + const message = + 'Merge pull request #42 from Turbo87/pkg-config\n\nRead "changelog" config key from "package.json" too'; const result = findPullRequestId(message); expect(result).toEqual("42"); }); it("finds the id in a GitHub squash-merge commit", function() { - const message = "Adjust \"lint\" script (#48)\n\n* bin/cli: Use \"const\" instead of \"var\"\n\n* package.json: Adjust \"lint\" script"; + const message = + 'Adjust "lint" script (#48)\n\n* bin/cli: Use "const" instead of "var"\n\n* package.json: Adjust "lint" script'; const result = findPullRequestId(message); expect(result).toEqual("48"); }); it("finds the id in a homu merge commit", function() { - const message = "Auto merge of #7056 - fixTypos:fix_typos, r=Turbo87\n\nfix_typos\n\nThis PR is part of a campaign to fix a lot of typos on github!\nYou can see the progress on https://github.com/fixTypos/fix_typos/\n\nhttps://github.com/client9/misspell"; + const message = + "Auto merge of #7056 - fixTypos:fix_typos, r=Turbo87\n\nfix_typos\n\nThis PR is part of a campaign to fix a lot of typos on github!\nYou can see the progress on https://github.com/fixTypos/fix_typos/\n\nhttps://github.com/client9/misspell"; const result = findPullRequestId(message); expect(result).toEqual("7056"); }); diff --git a/src/functional/markdown-full.spec.ts b/src/functional/markdown-full.spec.ts index 3fafc332..95a70bb3 100644 --- a/src/functional/markdown-full.spec.ts +++ b/src/functional/markdown-full.spec.ts @@ -1,6 +1,6 @@ /* tslint:disable:max-line-length */ -import {CommitListItem} from "../git"; +import { CommitListItem } from "../git"; jest.mock("../../src/progress-bar"); jest.mock("../../src/changelog"); @@ -9,32 +9,99 @@ jest.mock("../git"); jest.mock("../fetch"); const listOfCommits: CommitListItem[] = [ - { sha: "a0000015", refName: "", summary: "chore: making of episode viii", date: "2015-12-18" }, - { sha: "a0000014", refName: "", summary: "feat: infiltration (#7)", date: "2015-12-18" }, - { sha: "a0000013", refName: "HEAD -> master, tag: v6.0.0, origin/master, origin/HEAD", summary: "chore(release): releasing component", date: "1983-05-25" }, - { sha: "a0000012", refName: "", summary: "Merge pull request #6 from return-of-the-jedi", date: "1983-05-25" }, - { sha: "a0000011", refName: "", summary: "feat: I am your father (#5)", date: "1983-05-25" }, - { sha: "a0000010", refName: "", summary: "fix(han-solo): unfreezes (#4)", date: "1983-05-25" }, - { sha: "a0000009", refName: "tag: v5.0.0", summary: "chore(release): releasing component", date: "1980-05-17" }, - { sha: "a0000008", refName: "", summary: "Merge pull request #3 from empire-strikes-back", date: "1980-05-17" }, - { sha: "a0000007", refName: "", summary: "fix: destroy rebels base", date: "1980-05-17" }, - { sha: "a0000006", refName: "", summary: "chore: the end of Alderaan (#2)", date: "1980-05-17" }, - { sha: "a0000005", refName: "", summary: "refactor(death-star): add deflector shield", date: "1980-05-17" }, - { sha: "a0000004", refName: "tag: v4.0.0", summary: "chore(release): releasing component", date: "1977-05-25" }, - { sha: "a0000003", refName: "", summary: "Merge pull request #1 from star-wars", date: "1977-05-25" }, - { sha: "a0000002", refName: "tag: v0.1.0", summary: "chore(release): releasing component", date: "1966-01-01" }, - { sha: "a0000001", refName: "", summary: "fix: some random fix which will be ignored", date: "1966-01-01" }, + { + sha: "a0000015", + refName: "", + summary: "chore: making of episode viii", + date: "2015-12-18", + }, + { + sha: "a0000014", + refName: "", + summary: "feat: infiltration (#7)", + date: "2015-12-18", + }, + { + sha: "a0000013", + refName: "HEAD -> master, tag: v6.0.0, origin/master, origin/HEAD", + summary: "chore(release): releasing component", + date: "1983-05-25", + }, + { + sha: "a0000012", + refName: "", + summary: "Merge pull request #6 from return-of-the-jedi", + date: "1983-05-25", + }, + { + sha: "a0000011", + refName: "", + summary: "feat: I am your father (#5)", + date: "1983-05-25", + }, + { + sha: "a0000010", + refName: "", + summary: "fix(han-solo): unfreezes (#4)", + date: "1983-05-25", + }, + { + sha: "a0000009", + refName: "tag: v5.0.0", + summary: "chore(release): releasing component", + date: "1980-05-17", + }, + { + sha: "a0000008", + refName: "", + summary: "Merge pull request #3 from empire-strikes-back", + date: "1980-05-17", + }, + { + sha: "a0000007", + refName: "", + summary: "fix: destroy rebels base", + date: "1980-05-17", + }, + { + sha: "a0000006", + refName: "", + summary: "chore: the end of Alderaan (#2)", + date: "1980-05-17", + }, + { + sha: "a0000005", + refName: "", + summary: "refactor(death-star): add deflector shield", + date: "1980-05-17", + }, + { + sha: "a0000004", + refName: "tag: v4.0.0", + summary: "chore(release): releasing component", + date: "1977-05-25", + }, + { + sha: "a0000003", + refName: "", + summary: "Merge pull request #1 from star-wars", + date: "1977-05-25", + }, + { + sha: "a0000002", + refName: "tag: v0.1.0", + summary: "chore(release): releasing component", + date: "1966-01-01", + }, + { + sha: "a0000001", + refName: "", + summary: "fix: some random fix which will be ignored", + date: "1966-01-01", + }, ]; -const listOfTags = [ - "v6.0.0", - "v5.0.0", - "v4.0.0", - "v3.0.0", - "v2.0.0", - "v1.0.0", - "v0.1.0", -]; +const listOfTags = ["v6.0.0", "v5.0.0", "v4.0.0", "v3.0.0", "v2.0.0", "v1.0.0", "v0.1.0"]; const listOfPackagesForEachCommit: { [id: string]: string[] } = { a0000001: ["packages/random/foo.js"], @@ -50,10 +117,7 @@ const listOfPackagesForEachCommit: { [id: string]: string[] } = { a0000011: ["packages/return-of-the-jedi/vader-luke.js"], a0000012: ["packages/return-of-the-jedi/leia.js"], a0000013: ["packages/return-of-the-jedi/package.json"], - a0000014: [ - "packages/the-force-awakens/mission.js", - "packages/rogue-one/mission.js", - ], + a0000014: ["packages/the-force-awakens/mission.js", "packages/rogue-one/mission.js"], a0000015: ["packages/untitled/script.md"], }; @@ -71,10 +135,7 @@ const listOfFileForEachCommit: { [id: string]: string[] } = { a0000011: ["return-of-the-jedi/vader-luke.js"], a0000012: ["return-of-the-jedi/leia.js"], a0000013: ["return-of-the-jedi/package.json"], - a0000014: [ - "the-force-awakens/mission.js", - "rogue-one/mission.js", - ], + a0000014: ["the-force-awakens/mission.js", "rogue-one/mission.js"], a0000015: ["untitled/script.md"], }; @@ -124,9 +185,7 @@ const issuesCache = { "https://api.github.com/repos/lerna/lerna-changelog/issues/1": { number: 1, title: "feat: May the force be with you", - labels: [ - { name: "Type: New Feature" }, - ], + labels: [{ name: "Type: New Feature" }], pull_request: { html_url: "https://github.com/lerna/lerna-changelog/pull/1", }, @@ -135,9 +194,7 @@ const issuesCache = { "https://api.github.com/repos/lerna/lerna-changelog/issues/2": { number: 2, title: "chore: Terminate her... immediately!", - labels: [ - { name: "Type: Breaking Change" }, - ], + labels: [{ name: "Type: Breaking Change" }], pull_request: { html_url: "https://github.com/lerna/lerna-changelog/pull/2", }, @@ -146,9 +203,7 @@ const issuesCache = { "https://api.github.com/repos/lerna/lerna-changelog/issues/3": { number: 3, title: "fix: Get me the rebels base!", - labels: [ - { name: "Type: Bug" }, - ], + labels: [{ name: "Type: Bug" }], pull_request: { html_url: "https://github.com/lerna/lerna-changelog/pull/3", }, @@ -157,10 +212,7 @@ const issuesCache = { "https://api.github.com/repos/lerna/lerna-changelog/issues/4": { number: 4, title: "fix: RRRAARRWHHGWWR", - labels: [ - { name: "Type: Bug" }, - { name: "Type: Maintenance" }, - ], + labels: [{ name: "Type: Bug" }, { name: "Type: Maintenance" }], pull_request: { html_url: "https://github.com/lerna/lerna-changelog/pull/4", }, @@ -169,9 +221,7 @@ const issuesCache = { "https://api.github.com/repos/lerna/lerna-changelog/issues/5": { number: 5, title: "feat: I am your father", - labels: [ - { name: "Type: New Feature" }, - ], + labels: [{ name: "Type: New Feature" }], pull_request: { html_url: "https://github.com/lerna/lerna-changelog/pull/5", }, @@ -180,9 +230,7 @@ const issuesCache = { "https://api.github.com/repos/lerna/lerna-changelog/issues/6": { number: 6, title: "refactor: he is my brother", - labels: [ - { name: "Type: Enhancement" }, - ], + labels: [{ name: "Type: Enhancement" }], pull_request: { html_url: "https://github.com/lerna/lerna-changelog/pull/6", }, @@ -191,10 +239,7 @@ const issuesCache = { "https://api.github.com/repos/lerna/lerna-changelog/issues/7": { number: 7, title: "feat: that is not how the Force works!", - labels: [ - { name: "Type: New Feature" }, - { name: "Type: Enhancement" }, - ], + labels: [{ name: "Type: New Feature" }, { name: "Type: Enhancement" }], pull_request: { html_url: "https://github.com/lerna/lerna-changelog/pull/7", }, @@ -237,10 +282,30 @@ describe("createMarkdown", () => { require("../git").changedPaths.mockImplementation((sha: string) => listOfPackagesForEachCommit[sha]); require("../git").lastTag.mockImplementation(() => "v8.0.0"); require("../git").listCommits.mockImplementation(() => [ - { sha: "a0000004", refName: "tag: a-new-hope@4.0.0, tag: empire-strikes-back@5.0.0, tag: return-of-the-jedi@6.0.0", summary: "chore(release): releasing component", date: "1977-05-25" }, - { sha: "a0000003", refName: "", summary: "Merge pull request #1 from star-wars", date: "1977-05-25" }, - { sha: "a0000002", refName: "tag: v0.1.0", summary: "chore(release): releasing component", date: "1966-01-01" }, - { sha: "a0000001", refName: "", summary: "fix: some random fix which will be ignored", date: "1966-01-01" }, + { + sha: "a0000004", + refName: "tag: a-new-hope@4.0.0, tag: empire-strikes-back@5.0.0, tag: return-of-the-jedi@6.0.0", + summary: "chore(release): releasing component", + date: "1977-05-25", + }, + { + sha: "a0000003", + refName: "", + summary: "Merge pull request #1 from star-wars", + date: "1977-05-25", + }, + { + sha: "a0000002", + refName: "tag: v0.1.0", + summary: "chore(release): releasing component", + date: "1966-01-01", + }, + { + sha: "a0000001", + refName: "", + summary: "fix: some random fix which will be ignored", + date: "1966-01-01", + }, ]); require("../git").listTagNames.mockImplementation(() => [ "a-new-hope@4.0.0", diff --git a/src/git.ts b/src/git.ts index 37daa860..7372fa4c 100644 --- a/src/git.ts +++ b/src/git.ts @@ -1,7 +1,7 @@ const execa = require("execa"); export async function changedPaths(sha: string): Promise { - const result = await execa("git", ["show", "-m", "--name-only" , "--pretty=format:", "--first-parent", sha]); + const result = await execa("git", ["show", "-m", "--name-only", "--pretty=format:", "--first-parent", sha]); return result.stdout.split("\n"); } @@ -9,7 +9,10 @@ export async function changedPaths(sha: string): Promise { * All existing tags in the repository */ export function listTagNames(): string[] { - return execa.sync("git", ["tag"]).stdout.split("\n").filter(Boolean); + return execa + .sync("git", ["tag"]) + .stdout.split("\n") + .filter(Boolean); } /** @@ -29,8 +32,9 @@ export interface CommitListItem { export function listCommits(from: string, to: string = ""): CommitListItem[] { // Prints ";;;" // This format is used in `getCommitInfos` for easily analize the commit. - return execa.sync("git", ["log", "--oneline", "--pretty=%h;%D;%s;%cd", "--date=short", `${from}..${to}`]).stdout - .split("\n") + return execa + .sync("git", ["log", "--oneline", "--pretty=%h;%D;%s;%cd", "--date=short", `${from}..${to}`]) + .stdout.split("\n") .filter(Boolean) .map((commit: string) => { const parts = commit.split(";"); diff --git a/src/index.ts b/src/index.ts index 35c6c878..90af90f6 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,7 +1,4 @@ import Changelog from "./changelog"; import ConfigurationError from "./configuration-error"; -export { - Changelog, - ConfigurationError, -}; +export { Changelog, ConfigurationError }; diff --git a/src/interfaces.ts b/src/interfaces.ts index f076e8ef..1452cc6c 100644 --- a/src/interfaces.ts +++ b/src/interfaces.ts @@ -1,4 +1,4 @@ -import {GitHubIssueResponse, GitHubUserResponse} from "./github-api"; +import { GitHubIssueResponse, GitHubUserResponse } from "./github-api"; export interface CommitInfo { commitSHA: string; diff --git a/src/markdown-renderer.spec.ts b/src/markdown-renderer.spec.ts index 03a5999f..1ac6f6ce 100644 --- a/src/markdown-renderer.spec.ts +++ b/src/markdown-renderer.spec.ts @@ -1,4 +1,4 @@ -import {CommitInfo} from "./interfaces"; +import { CommitInfo } from "./interfaces"; import MarkdownRenderer from "./markdown-renderer"; const BASIC_COMMIT = { diff --git a/src/markdown-renderer.ts b/src/markdown-renderer.ts index cfb9958f..5cf3d4b3 100644 --- a/src/markdown-renderer.ts +++ b/src/markdown-renderer.ts @@ -1,5 +1,5 @@ -import {GitHubUserResponse} from "./github-api"; -import {CommitInfo, Release} from "./interfaces"; +import { GitHubUserResponse } from "./github-api"; +import { CommitInfo, Release } from "./interfaces"; const UNRELEASED_TAG = "___unreleased___"; const COMMIT_FIX_REGEX = /(fix|close|resolve)(e?s|e?d)? [T#](\d+)/i; @@ -23,7 +23,7 @@ export default class MarkdownRenderer { public renderMarkdown(releases: Release[]) { return `\n${releases - .map((release) => this.renderRelease(release)) + .map(release => this.renderRelease(release)) .filter(Boolean) .join("\n\n\n")}`; } @@ -31,7 +31,7 @@ export default class MarkdownRenderer { public renderRelease(release: Release): string | undefined { // Group commits in release by category const categories = this.groupByCategory(release.commits); - const categoriesWithCommits = categories.filter((category) => category.commits.length > 0); + const categoriesWithCommits = categories.filter(category => category.commits.length > 0); // Skip this iteration if there are no commits available for the release if (categoriesWithCommits.length === 0) return ""; @@ -72,23 +72,23 @@ export default class MarkdownRenderer { const packageNames = Object.keys(commitsByPackage); - return packageNames.map((packageName) => { - const pkgCommits = commitsByPackage[packageName]; - return `* ${packageName}\n${this.renderContributionList(pkgCommits, " ")}`; - }).join("\n"); + return packageNames + .map(packageName => { + const pkgCommits = commitsByPackage[packageName]; + return `* ${packageName}\n${this.renderContributionList(pkgCommits, " ")}`; + }) + .join("\n"); } public renderPackageNames(packageNames: string[]) { - return packageNames.length > 0 - ? packageNames.map((pkg) => `\`${pkg}\``).join(", ") - : "Other"; + return packageNames.length > 0 ? packageNames.map(pkg => `\`${pkg}\``).join(", ") : "Other"; } public renderContributionList(commits: CommitInfo[], prefix: string = ""): string { return commits - .map((commit) => this.renderContribution(commit)) + .map(commit => this.renderContribution(commit)) .filter(Boolean) - .map((rendered) => `${prefix}* ${rendered}`) + .map(rendered => `${prefix}* ${rendered}`) .join("\n"); } @@ -103,10 +103,7 @@ export default class MarkdownRenderer { } if (issue.title && issue.title.match(COMMIT_FIX_REGEX)) { - issue.title = issue.title.replace( - COMMIT_FIX_REGEX, - `Closes [#$3](${this.options.baseIssueUrl}$3)`, - ); + issue.title = issue.title.replace(COMMIT_FIX_REGEX, `Closes [#$3](${this.options.baseIssueUrl}$3)`); } markdown += `${issue.title}. ([@${issue.user.login}](${issue.user.html_url}))`; @@ -116,7 +113,7 @@ export default class MarkdownRenderer { } public renderContributorList(contributors: GitHubUserResponse[]) { - const renderedContributors = contributors.map((contributor) => `- ${this.renderContributor(contributor)}`).sort(); + const renderedContributors = contributors.map(contributor => `- ${this.renderContributor(contributor)}`).sort(); return `#### Committers: ${contributors.length}\n${renderedContributors.join("\n")}`; } @@ -131,15 +128,14 @@ export default class MarkdownRenderer { } private hasPackages(commits: CommitInfo[]) { - return commits.some((commit) => commit.packages !== undefined && commit.packages.length > 0); + return commits.some(commit => commit.packages !== undefined && commit.packages.length > 0); } private groupByCategory(allCommits: CommitInfo[]): CategoryInfo[] { - return this.options.categories.map((name) => { + return this.options.categories.map(name => { // Keep only the commits that have a matching label with the one // provided in the lerna.json config. - let commits = allCommits - .filter((commit) => commit.categories && commit.categories.indexOf(name) !== -1); + let commits = allCommits.filter(commit => commit.categories && commit.categories.indexOf(name) !== -1); return { name, commits }; }); diff --git a/tslint.json b/tslint.json index 98c4a404..eced3cae 100644 --- a/tslint.json +++ b/tslint.json @@ -1,10 +1,14 @@ { "defaultSeverity": "error", "extends": [ - "tslint:recommended" + "tslint:recommended", + "tslint-config-prettier" ], "jsRules": {}, + "rulesDirectory": ["tslint-plugin-prettier"], "rules": { + "prettier": true, + "arrow-parens": false, "curly": false, "interface-name": false, @@ -13,10 +17,6 @@ "object-literal-sort-keys": false, "only-arrow-functions": false, "ordered-imports": false, - "prefer-const": false, - "quotemark": { - "options": "double" - } - }, - "rulesDirectory": [] + "prefer-const": false + } } diff --git a/yarn.lock b/yarn.lock index 4eabc947..4adbebd3 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1168,6 +1168,13 @@ escodegen@^1.9.0: optionalDependencies: source-map "~0.6.1" +eslint-plugin-prettier@^2.2.0: + version "2.6.0" + resolved "https://registry.yarnpkg.com/eslint-plugin-prettier/-/eslint-plugin-prettier-2.6.0.tgz#33e4e228bdb06142d03c560ce04ec23f6c767dd7" + dependencies: + fast-diff "^1.1.1" + jest-docblock "^21.0.0" + esprima@^2.6.0: version "2.7.3" resolved "https://registry.yarnpkg.com/esprima/-/esprima-2.7.3.tgz#96e3b70d5779f6ad49cd032673d1c312767ba581" @@ -1312,6 +1319,10 @@ fast-deep-equal@^1.0.0: version "1.1.0" resolved "https://registry.yarnpkg.com/fast-deep-equal/-/fast-deep-equal-1.1.0.tgz#c053477817c86b51daa853c81e059b733d023614" +fast-diff@^1.1.1: + version "1.1.2" + resolved "https://registry.yarnpkg.com/fast-diff/-/fast-diff-1.1.2.tgz#4b62c42b8e03de3f848460b639079920695d0154" + fast-json-stable-stringify@^2.0.0: version "2.0.0" resolved "https://registry.yarnpkg.com/fast-json-stable-stringify/-/fast-json-stable-stringify-2.0.0.tgz#d5142c0caee6b1189f87d3a76111064f86c8bbf2" @@ -2141,6 +2152,10 @@ jest-diff@^23.0.1: jest-get-type "^22.1.0" pretty-format "^23.0.1" +jest-docblock@^21.0.0: + version "21.2.0" + resolved "https://registry.yarnpkg.com/jest-docblock/-/jest-docblock-21.2.0.tgz#51529c3b30d5fd159da60c27ceedc195faf8d414" + jest-docblock@^23.0.1: version "23.0.1" resolved "https://registry.yarnpkg.com/jest-docblock/-/jest-docblock-23.0.1.tgz#deddd18333be5dc2415260a04ef3fce9276b5725" @@ -3226,6 +3241,10 @@ preserve@^0.2.0: version "0.2.0" resolved "https://registry.yarnpkg.com/preserve/-/preserve-0.2.0.tgz#815ed1f6ebc65926f865b310c0713bcb3315ce4b" +prettier@1.13.5: + version "1.13.5" + resolved "https://registry.yarnpkg.com/prettier/-/prettier-1.13.5.tgz#7ae2076998c8edce79d63834e9b7b09fead6bfd0" + pretty-format@^22.4.0, pretty-format@^22.4.3: version "22.4.3" resolved "https://registry.yarnpkg.com/pretty-format/-/pretty-format-22.4.3.tgz#f873d780839a9c02e9664c8a082e9ee79eaac16f" @@ -4024,10 +4043,21 @@ ts-jest@^22.4.6: source-map-support "^0.5.5" yargs "^11.0.0" -tslib@^1.8.0, tslib@^1.8.1: +tslib@^1.7.1, tslib@^1.8.0, tslib@^1.8.1: version "1.9.2" resolved "https://registry.yarnpkg.com/tslib/-/tslib-1.9.2.tgz#8be0cc9a1f6dc7727c38deb16c2ebd1a2892988e" +tslint-config-prettier@^1.13.0: + version "1.13.0" + resolved "https://registry.yarnpkg.com/tslint-config-prettier/-/tslint-config-prettier-1.13.0.tgz#189e821931ad89e0364e4e292d5c44a14e90ecd6" + +tslint-plugin-prettier@^1.3.0: + version "1.3.0" + resolved "https://registry.yarnpkg.com/tslint-plugin-prettier/-/tslint-plugin-prettier-1.3.0.tgz#7eb65d19ea786a859501a42491b78c5de2031a3f" + dependencies: + eslint-plugin-prettier "^2.2.0" + tslib "^1.7.1" + tslint@^5.10.0, tslint@^5.8.0: version "5.10.0" resolved "https://registry.yarnpkg.com/tslint/-/tslint-5.10.0.tgz#11e26bccb88afa02dd0d9956cae3d4540b5f54c3"