Skip to content

Commit d0f3d51

Browse files
authored
chore: switch from lintit to standard style (#84)
1 parent 2ddbb6d commit d0f3d51

28 files changed

Lines changed: 681 additions & 688 deletions

bin/cmd.js

Lines changed: 49 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ const exec = require('child_process').exec
66
const fs = require('fs')
77
const http = require('http')
88
const https = require('https')
9-
const url = require('url')
109
const nopt = require('nopt')
1110
const path = require('path')
1211
const pretty = require('../lib/format-pretty')
@@ -16,42 +15,42 @@ const Tap = require('../lib/tap')
1615
const utils = require('../lib/utils')
1716
const subsystem = require('../lib/rules/subsystem')
1817
const knownOpts = {
19-
help: Boolean
20-
, version: Boolean
21-
, 'validate-metadata': Boolean
22-
, tap: Boolean
23-
, out: path
24-
, list: Boolean
25-
, 'list-subsystems': Boolean
18+
help: Boolean,
19+
version: Boolean,
20+
'validate-metadata': Boolean,
21+
tap: Boolean,
22+
out: path,
23+
list: Boolean,
24+
'list-subsystems': Boolean
2625
}
2726
const shortHand = {
28-
h: ['--help']
29-
, v: ['--version']
30-
, V: ['--validate-metadata']
31-
, t: ['--tap']
32-
, o: ['--out']
33-
, l: ['--list']
34-
, ls: ['--list-subsystems']
27+
h: ['--help'],
28+
v: ['--version'],
29+
V: ['--validate-metadata'],
30+
t: ['--tap'],
31+
o: ['--out'],
32+
l: ['--list'],
33+
ls: ['--list-subsystems']
3534
}
3635

3736
const parsed = nopt(knownOpts, shortHand)
3837
const usage = require('help')()
3938

4039
if (parsed.help) {
41-
return usage()
40+
usage()
41+
process.exit(0)
4242
}
4343

4444
if (parsed.version) {
4545
console.log('core-validate-commit', 'v' + require('../package').version)
46-
return
46+
process.exit(0)
4747
}
4848

4949
const args = parsed.argv.remain
50-
if (!args.length)
51-
args.push('HEAD')
50+
if (!args.length) { args.push('HEAD') }
5251

53-
function load(sha, cb) {
54-
const parsed = url.parse(sha)
52+
function load (sha, cb) {
53+
const parsed = new URL(sha)
5554
if (parsed.protocol) {
5655
return loadPatch(parsed, cb)
5756
}
@@ -62,7 +61,7 @@ function load(sha, cb) {
6261
})
6362
}
6463

65-
function loadPatch(uri, cb) {
64+
function loadPatch (uri, cb) {
6665
let h = http
6766
if (~uri.protocol.indexOf('https')) {
6867
h = https
@@ -91,7 +90,7 @@ const v = new Validator(parsed)
9190

9291
if (parsed['list-subsystems']) {
9392
utils.describeSubsystem(subsystem.defaults.subsystems.sort())
94-
return
93+
process.exit(0)
9594
}
9695

9796
if (parsed.list) {
@@ -104,15 +103,15 @@ if (parsed.list) {
104103
for (const rule of v.rules.values()) {
105104
utils.describeRule(rule, max)
106105
}
107-
return
106+
process.exit(0)
108107
}
109108

110109
if (parsed.tap) {
111110
const tap = new Tap()
112111
tap.pipe(process.stdout)
113112
if (parsed.out) tap.pipe(fs.createWriteStream(parsed.out))
114113
let count = 0
115-
let total = args.length
114+
const total = args.length
116115

117116
v.on('commit', (c) => {
118117
count++
@@ -121,41 +120,39 @@ if (parsed.tap) {
121120
if (count === total) {
122121
setImmediate(() => {
123122
tap.end()
124-
if (tap.status === 'fail')
125-
process.exitCode = 1
123+
if (tap.status === 'fail') { process.exitCode = 1 }
126124
})
127125
}
128126
})
129127

130-
function run() {
131-
if (!args.length) return
132-
const sha = args.shift()
133-
load(sha, (err, data) => {
134-
if (err) throw err
135-
v.lint(data)
136-
run()
137-
})
138-
}
139-
140-
run()
141-
128+
tapRun()
142129
} else {
143130
v.on('commit', (c) => {
144131
pretty(c.commit, c.messages, v)
145-
run()
132+
commitRun()
146133
})
147134

148-
function run() {
149-
if (!args.length) {
150-
process.exitCode = v.errors
151-
return
152-
}
153-
const sha = args.shift()
154-
load(sha, (err, data) => {
155-
if (err) throw err
156-
v.lint(data)
157-
})
158-
}
135+
commitRun()
136+
}
137+
138+
function tapRun () {
139+
if (!args.length) return
140+
const sha = args.shift()
141+
load(sha, (err, data) => {
142+
if (err) throw err
143+
v.lint(data)
144+
tapRun()
145+
})
146+
}
159147

160-
run()
148+
function commitRun () {
149+
if (!args.length) {
150+
process.exitCode = v.errors
151+
return
152+
}
153+
const sha = args.shift()
154+
load(sha, (err, data) => {
155+
if (err) throw err
156+
v.lint(data)
157+
})
161158
}

lib/format-pretty.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ const utils = require('./utils')
55

66
const MAX_LINE_COL_LEN = 6
77

8-
module.exports = function formatPretty(context, msgs, validator, opts) {
8+
module.exports = function formatPretty (context, msgs, validator, opts) {
99
opts = Object.assign({
1010
detailed: false
1111
}, opts)
@@ -57,7 +57,7 @@ module.exports = function formatPretty(context, msgs, validator, opts) {
5757
}
5858
}
5959

60-
function formatLength(msg, opts) {
60+
function formatLength (msg, opts) {
6161
const out = formatMessage(msg)
6262
const str = msg.string
6363
const l = str.length
@@ -68,7 +68,7 @@ function formatLength(msg, opts) {
6868
${diff}`
6969
}
7070

71-
function formatMessage(msg) {
71+
function formatMessage (msg) {
7272
const l = msg.line || 0
7373
const col = msg.column || 0
7474
const pad = utils.rightPad(`${l}:${col}`, MAX_LINE_COL_LEN)
@@ -83,6 +83,6 @@ function formatMessage(msg) {
8383
return ` ${icon} ${line} ${utils.rightPad(m, 40)} ${id}`
8484
}
8585

86-
function formatId(id) {
86+
function formatId (id) {
8787
return chalk.red(id)
8888
}

lib/format-tap.js

Lines changed: 29 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,13 @@
11
'use strict'
22

3-
module.exports = function formatTap(t, context, msgs, validator) {
3+
module.exports = function formatTap (t, context, msgs, validator) {
44
for (const m of msgs) {
55
switch (m.level) {
6-
case 'pass':
7-
const a = m.string
8-
? ` [${m.string}]`
9-
: ''
6+
case 'pass': {
7+
const a = m.string ? ` [${m.string}]` : ''
108
t.pass(`${m.id}: ${m.message}${a}`)
119
break
10+
}
1211
case 'skip':
1312
t.skip(`${m.id}: ${m.message}`)
1413
break
@@ -19,7 +18,7 @@ module.exports = function formatTap(t, context, msgs, validator) {
1918
}
2019
}
2120

22-
function onFail(context, m, validator, t) {
21+
function onFail (context, m, validator, t) {
2322
switch (m.id) {
2423
case 'line-length':
2524
case 'title-length':
@@ -34,44 +33,44 @@ function onFail(context, m, validator, t) {
3433
}
3534
}
3635

37-
function lengthFail(context, m, validator, t) {
36+
function lengthFail (context, m, validator, t) {
3837
const body = m.id === 'title-length'
3938
? context.title
4039
: context.body
4140
t.fail(`${m.id}: ${m.message}`, {
42-
found: m.string.length
43-
, compare: '<='
44-
, wanted: m.maxLength
45-
, at: {
46-
line: m.line || 0
47-
, column: m.column || 0
48-
, body: body
41+
found: m.string.length,
42+
compare: '<=',
43+
wanted: m.maxLength,
44+
at: {
45+
line: m.line || 0,
46+
column: m.column || 0,
47+
body: body
4948
}
5049
})
5150
}
5251

53-
function subsystemFail(context, m, validator, t) {
52+
function subsystemFail (context, m, validator, t) {
5453
t.fail(`${m.id}: ${m.message} (${m.string})`, {
55-
found: m.string
56-
, compare: 'indexOf() !== -1'
57-
, wanted: m.wanted || ''
58-
, at: {
59-
line: m.line || 0
60-
, column: m.column || 0
61-
, body: m.title
54+
found: m.string,
55+
compare: 'indexOf() !== -1',
56+
wanted: m.wanted || '',
57+
at: {
58+
line: m.line || 0,
59+
column: m.column || 0,
60+
body: m.title
6261
}
6362
})
6463
}
6564

66-
function defaultFail(context, m, validator, t) {
65+
function defaultFail (context, m, validator, t) {
6766
t.fail(`${m.id}: ${m.message} (${m.string})`, {
68-
found: m.string
69-
, compare: Array.isArray(m.wanted) ? 'indexOf() !== -1' : '==='
70-
, wanted: m.wanted || ''
71-
, at: {
72-
line: m.line || 0
73-
, column: m.column || 0
74-
, body: context.body
67+
found: m.string,
68+
compare: Array.isArray(m.wanted) ? 'indexOf() !== -1' : '===',
69+
wanted: m.wanted || '',
70+
at: {
71+
line: m.line || 0,
72+
column: m.column || 0,
73+
body: context.body
7574
}
7675
})
7776
}

lib/index.js

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ const BaseRule = require('./rule')
66
const RULES = require('./rules')
77

88
module.exports = class ValidateCommit extends EE {
9-
constructor(options) {
9+
constructor (options) {
1010
super()
1111

1212
this.opts = Object.assign({
@@ -20,7 +20,7 @@ module.exports = class ValidateCommit extends EE {
2020
this.loadBaseRules()
2121
}
2222

23-
loadBaseRules() {
23+
loadBaseRules () {
2424
const keys = Object.keys(RULES)
2525
for (const key of keys) {
2626
this.rules.set(key, new BaseRule(RULES[key]))
@@ -32,15 +32,15 @@ module.exports = class ValidateCommit extends EE {
3232
}
3333
}
3434

35-
disableRule(id) {
35+
disableRule (id) {
3636
if (!this.rules.has(id)) {
3737
throw new TypeError(`Invalid rule: "${id}"`)
3838
}
3939

4040
this.rules.get(id).disabled = true
4141
}
4242

43-
lint(str) {
43+
lint (str) {
4444
if (Array.isArray(str)) {
4545
for (const item of str) {
4646
this.lint(item)
@@ -54,22 +54,21 @@ module.exports = class ValidateCommit extends EE {
5454

5555
setImmediate(() => {
5656
this.emit('commit', {
57-
commit: commit
58-
, messages: this.messages.get(commit.sha) || []
57+
commit: commit,
58+
messages: this.messages.get(commit.sha) || []
5959
})
6060
})
6161
}
6262
}
6363

64-
report(opts) {
64+
report (opts) {
6565
const commit = opts.commit
6666
const sha = commit.sha
6767
if (!sha) {
6868
throw new Error('Invalid report. Missing commit sha')
6969
}
7070

71-
if (opts.data.level === 'fail')
72-
this.errors++
71+
if (opts.data.level === 'fail') { this.errors++ }
7372
const ar = this.messages.get(sha) || []
7473
ar.push(opts.data)
7574
this.messages.set(sha, ar)

lib/rule.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
'use strict'
22

33
module.exports = class Rule {
4-
constructor(opts) {
4+
constructor (opts) {
55
opts = Object.assign({
6-
options: {}
7-
, defaults: {}
8-
, meta: {}
6+
options: {},
7+
defaults: {},
8+
meta: {}
99
}, opts)
1010

1111
if (!opts.id) {
@@ -24,7 +24,7 @@ module.exports = class Rule {
2424
this._validate = opts.validate
2525
}
2626

27-
validate(commit) {
27+
validate (commit) {
2828
this._validate(commit, this)
2929
}
3030
}

0 commit comments

Comments
 (0)