Skip to content

Commit f27caee

Browse files
committed
lint: validate readme constructor list
1 parent c69cac7 commit f27caee

File tree

2 files changed

+31
-1
lines changed

2 files changed

+31
-1
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
"node": ">= 0.6"
3232
},
3333
"scripts": {
34-
"lint": "eslint --plugin markdown --ext js,md .",
34+
"lint": "eslint --plugin markdown --ext js,md . && node ./scripts/lint-readme-list.js",
3535
"test": "mocha --reporter spec --bail",
3636
"test-cov": "istanbul cover node_modules/mocha/bin/_mocha -- --reporter dot",
3737
"test-travis": "istanbul cover node_modules/mocha/bin/_mocha --report lcovonly -- --reporter dot"

scripts/lint-readme-list.js

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
var assert = require('assert')
2+
var createError = require('..')
3+
var fs = require('fs')
4+
var path = require('path')
5+
var util = require('util')
6+
7+
var README_PATH = path.join(__dirname, '..', 'README.md')
8+
var README_CONTENTS = fs.readFileSync(README_PATH, 'utf-8')
9+
10+
for (var key in createError) {
11+
if (!createError.hasOwnProperty(key)) {
12+
continue
13+
}
14+
15+
if (!isNaN(key)) {
16+
continue
17+
}
18+
19+
var constructor = createError[key]
20+
var statusCode = constructor.prototype.statusCode
21+
22+
if (createError[statusCode] !== constructor) {
23+
continue
24+
}
25+
26+
var regexp = new RegExp(util.format('^\\|%d\\s*\\|%s\\s*\\|$', statusCode, key), 'm')
27+
28+
assert.ok(regexp.test(README_CONTENTS),
29+
util.format('README constructor list contains %d %s', statusCode, key))
30+
}

0 commit comments

Comments
 (0)