Skip to content
Merged
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
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,16 @@ $ core-validate-commit <sha>

# validate since <sha>
$ git rev-list <sha>..HEAD | xargs core-validate-commit

# list all rules
$ core-validate-commit --list
fixes-url enforce format of Fixes URLs
line-length enforce max length of lines in commit body
metadata-end enforce that metadata is at the end of commit messages
pr-url enforce PR-URL
reviewers enforce having reviewers
subsystem enforce subsystem validity
title-length enforce max length of commit title
```

## Test
Expand Down
16 changes: 16 additions & 0 deletions bin/cmd.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,20 @@ const pretty = require('../lib/format-pretty')
const formatTap = require('../lib/format-tap')
const Validator = require('../lib')
const Tap = require('../lib/tap')
const utils = require('../lib/utils')
const knownOpts = { help: Boolean
, version: Boolean
, 'validate-metadata': Boolean
, tap: Boolean
, out: path
, list: Boolean
}
const shortHand = { h: ['--help']
, v: ['--version']
, V: ['--validate-metadata']
, t: ['--tap']
, o: ['--out']
, l: ['--list']
}

const parsed = nopt(knownOpts, shortHand)
Expand Down Expand Up @@ -79,6 +82,19 @@ function loadPatch(uri, cb) {

const v = new Validator(parsed)

if (parsed.list) {
const ruleNames = Array.from(v.rules.keys())
const max = ruleNames.reduce((m, item) => {
if (item.length > m) m = item.length
return m
}, 0)

for (const rule of v.rules.values()) {
utils.describeRule(rule, max)
}
return
}

if (parsed.tap) {
const stream = parsed.out
? fs.createWriteStream(parsed.out)
Expand Down
1 change: 1 addition & 0 deletions bin/usage.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ core-validate-commit - Validate the commit message for a particular commit in no
-v, --version show version
-V, --validate-metadata validate PR-URL and revieweres (on by default)
-t, --tap output in tap format
-l, --list list rules and their descriptions

examples:
Validate a single sha:
Expand Down
16 changes: 16 additions & 0 deletions lib/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,14 @@ exports.rightPad = function rightPad(str, max) {
return str
}

exports.leftPad = function leftPad(str, max) {
const diff = max - str.length + 1
if (diff > 0) {
return `${' '.repeat(diff)}${str}`
}
return str
}

exports.header = (sha, status) => {
switch (status) {
case 'skip':
Expand All @@ -29,3 +37,11 @@ exports.header = (sha, status) => {
return `${X} ${chalk.underline(sha)}`
}
}

exports.describeRule = function describeRule(rule, max = 20) {
if (rule.meta && rule.meta.description) {
const desc = rule.meta.description
const title = exports.leftPad(rule.id, max)
console.log(' %s %s', chalk.red(title), chalk.dim(desc))
}
}