Skip to content

Commit

Permalink
fix: 🐛 --lint shouldn't fail on merge commit message (fixes folke#50)
Browse files Browse the repository at this point in the history
  • Loading branch information
folke committed Apr 9, 2020
1 parent 1cd11ed commit 8ba3987
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 3 deletions.
45 changes: 45 additions & 0 deletions __tests__/lint.ts
@@ -0,0 +1,45 @@
import { Cli } from "../src/cli"

test("should ", async () => {
const cli = await Cli.create(["", ""], true)
const valid = `style: 🎨 prettier 2.0
Merge branch 'master' of github.com:folke/devmoji
style: 🎨 Prettier 2.0
chore(release): 2.1.8 [skip ci]
fix(deps): update dependency chalk to v4 (#49)
chore(deps): update all non-major dependencies (#48)
chore(release): 2.1.7 [skip ci]
fix: 🐛 🔒️ upgrade minimist which had a security vulnerability
chore(deps): update all non-major dependencies (#47)
chore(deps): update dependency prettier to v2 (#46)
chore(deps): update all non-major dependencies (#45)
chore(deps): update dependency rollup to v2.1.0 (#44)
chore(deps): update all non-major dependencies to v2.24.0 (#43)
chore(release): 2.1.6 [skip ci]
fix: 🐛 new rollup version and commanderjs
chore(deps): update all non-major dependencies (#37)
chore(deps): update all non-major dependencies (#34)
chore(release): 2.1.5 [skip ci]
docs: fixed config example
chore(deps): update dependency rollup to v2 (#35)`
.split("\n")
.map((s) => s.trim())
for (const msg of valid) {
expect(cli.lint(msg)).toHaveLength(0)
}

const invalid = `Style: 🎨 prettier 2.0
Merging branch 'master' of github.com:folke/devmoji
style 🎨 Prettier 2.0
chorerelease): 2.1.8 [skip ci]
fix(deps) update dependency chalk to v4 (#49)
chore(depS): update all non-major dependencies (#48)
2.1.7 [skip ci]
🔒️ upgrade minimist which had a security vulnerability
update all non-major dependencies (#47)`
.split("\n")
.map((s) => s.trim())
for (const msg of invalid) {
expect(cli.lint(msg)).not.toHaveLength(0)
}
})
11 changes: 8 additions & 3 deletions src/cli.ts
Expand Up @@ -18,6 +18,8 @@ export class Cli {

lint(text: string) {
text = text.split("\n")[0]
if (text.startsWith("Merge branch")) return []

const errors = []
const match = /^(?<type>:?[a-z-]+)(?:\((?<scope>[a-z-]+)\))?(!?):\s+(?<description>.*)/iu.exec(
text
Expand Down Expand Up @@ -55,8 +57,7 @@ export class Cli {
errors.push("Get help at https://www.conventionalcommits.org/")
}

errors.forEach((e) => console.error(chalk.red("✖"), e))
if (errors.length) process.exit(1)
return errors
}

format(
Expand All @@ -67,7 +68,11 @@ export class Cli {
color = this.opts.color
) {
if (processCommit && this.opts.lint && !processLog) {
this.lint(text)
const errors = this.lint(text)
if (errors.length) {
errors.forEach((e) => console.error(chalk.red("✖"), e))
process.exit(1)
}
}
if (processLog) text = this.commits.formatLog(text)
else if (processCommit)
Expand Down

0 comments on commit 8ba3987

Please sign in to comment.