diff options
author | Forrest L Norvell <forrest@npmjs.com> | 2015-06-23 08:18:52 +0300 |
---|---|---|
committer | Rebecca Turner <me@re-becca.org> | 2015-06-26 03:27:33 +0300 |
commit | b50be6aff34a739ca43de65f546e743d1a9975b9 (patch) | |
tree | 3153fd3a271245b8a05a9be196286fbe31fc9d44 /test/tap/config-meta.js | |
parent | 7c5ebe0552b7b5d0cdca34d28c4f16fe794ff2ff (diff) |
src: make the npm source comply with `standard`
This is a huge set of mostly mechanical changes. Going forward, all
changes to the npm source base are expected to comply with `standard`,
and it's been integrated into the test suite to enforce that. There are
a few notes below about specific classes of changes that need to be
handled specially for npm's code base.
standard: "Expected error to be handled."
`standard` only expects errors spelled "err" to be handled.
`npm-registry-mock` never actually invokes its callback with an error,
so in some cases I just changed it to be spelled "er" and called it
good.
standard: "Expected a "break" statement before 'case'."
This behavior is actually on purpose, and I don't feel like rewriting
the affected code right now (or, you know, ever). So I added code
comments disabling the checks in the three applicable changes.
standard: "x is a function."
Rebinding functions created via declarations (as opposed to expressions)
is a no-no?
PR-URL: https://github.com/npm/npm/pull/8668
Diffstat (limited to 'test/tap/config-meta.js')
-rw-r--r-- | test/tap/config-meta.js | 101 |
1 files changed, 52 insertions, 49 deletions
diff --git a/test/tap/config-meta.js b/test/tap/config-meta.js index 3da27a872..bb40e2038 100644 --- a/test/tap/config-meta.js +++ b/test/tap/config-meta.js @@ -4,34 +4,34 @@ // b) Documented // c) Defined in the `npmconf` package. -var test = require("tap").test -var fs = require("fs") -var path = require("path") -var root = path.resolve(__dirname, "..", "..") -var lib = path.resolve(root, "lib") -var nm = path.resolve(root, "node_modules") -var doc = path.resolve(root, "doc/misc/npm-config.md") +var test = require('tap').test +var fs = require('fs') +var path = require('path') +var root = path.resolve(__dirname, '..', '..') +var lib = path.resolve(root, 'lib') +var nm = path.resolve(root, 'node_modules') +var doc = path.resolve(root, 'doc/misc/npm-config.md') var FILES = [] var CONFS = {} var DOC = {} var exceptions = [ - path.resolve(lib, "adduser.js"), - path.resolve(lib, "config.js"), - path.resolve(lib, "publish.js"), - path.resolve(lib, "utils", "lifecycle.js"), - path.resolve(lib, "utils", "map-to-registry.js"), - path.resolve(nm, "npm-registry-client", "lib", "publish.js"), - path.resolve(nm, "npm-registry-client", "lib", "request.js") + path.resolve(lib, 'adduser.js'), + path.resolve(lib, 'config.js'), + path.resolve(lib, 'publish.js'), + path.resolve(lib, 'utils', 'lifecycle.js'), + path.resolve(lib, 'utils', 'map-to-registry.js'), + path.resolve(nm, 'npm-registry-client', 'lib', 'publish.js'), + path.resolve(nm, 'npm-registry-client', 'lib', 'request.js') ] -test("get files", function (t) { +test('get files', function (t) { walk(nm) walk(lib) - t.pass("got files") + t.pass('got files') t.end() - function walk(lib) { + function walk (lib) { var files = fs.readdirSync(lib).map(function (f) { return path.resolve(lib, f) }) @@ -41,86 +41,89 @@ test("get files", function (t) { } catch (er) { return } - if (s.isDirectory()) + if (s.isDirectory()) { walk(f) - else if (f.match(/\.js$/)) + } else if (f.match(/\.js$/)) { FILES.push(f) + } }) } }) -test("get lines", function (t) { +test('get lines', function (t) { FILES.forEach(function (f) { - var lines = fs.readFileSync(f, "utf8").split(/\r|\n/) + var lines = fs.readFileSync(f, 'utf8').split(/\r|\n/) lines.forEach(function (l, i) { var matches = l.split(/conf(?:ig)?\.get\(/g) matches.shift() matches.forEach(function (m) { - m = m.split(")").shift() - var literal = m.match(/^['"].+?['"]/) + m = m.split(')').shift() + var literal = m.match(/^[''].+?['']/) if (literal) { m = literal[0].slice(1, -1) - if (!m.match(/^\_/) && m !== "argv") + if (!m.match(/^\_/) && m !== 'argv') { CONFS[m] = { file: f, line: i } + } } else if (exceptions.indexOf(f) === -1) { - t.fail("non-string-literal config used in " + f + ":" + i) + t.fail('non-string-literal config used in ' + f + ':' + i) } }) }) }) - t.pass("got lines") + t.pass('got lines') t.end() }) -test("get docs", function (t) { - var d = fs.readFileSync(doc, "utf8").split(/\r|\n/) - // walk down until the "## Config Settings" section - for (var i = 0; i < d.length && d[i] !== "## Config Settings"; i++); +test('get docs', function (t) { + var d = fs.readFileSync(doc, 'utf8').split(/\r|\n/) + // walk down until the '## Config Settings' section + for (var i = 0; i < d.length && d[i] !== '## Config Settings'; i++); i++ // now gather up all the ^###\s lines until the next ^##\s for (; i < d.length && !d[i].match(/^## /); i++) { - if (d[i].match(/^### /)) - DOC[ d[i].replace(/^### /, "").trim() ] = true + if (d[i].match(/^### /)) { + DOC[ d[i].replace(/^### /, '').trim() ] = true + } } - t.pass("read the docs") + t.pass('read the docs') t.end() }) -test("check configs", function (t) { - var defs = require("../../lib/config/defaults.js") +test('check configs', function (t) { + var defs = require('../../lib/config/defaults.js') var types = Object.keys(defs.types) var defaults = Object.keys(defs.defaults) for (var c1 in CONFS) { if (CONFS[c1].file.indexOf(lib) === 0) { - t.ok(DOC[c1], "should be documented " + c1 + " " - + CONFS[c1].file + ":" + CONFS[c1].line) - t.ok(types.indexOf(c1) !== -1, "should be defined in npmconf " + c1) - t.ok(defaults.indexOf(c1) !== -1, "should have default in npmconf " + c1) + t.ok(DOC[c1], 'should be documented ' + c1 + ' ' + + CONFS[c1].file + ':' + CONFS[c1].line) + t.ok(types.indexOf(c1) !== -1, 'should be defined in npmconf ' + c1) + t.ok(defaults.indexOf(c1) !== -1, 'should have default in npmconf ' + c1) } } for (var c2 in DOC) { - if (c2 !== "versions" && c2 !== "version" && c2 !== "init.version") { - t.ok(CONFS[c2], "config in doc should be used somewhere " + c2) - t.ok(types.indexOf(c2) !== -1, "should be defined in npmconf " + c2) - t.ok(defaults.indexOf(c2) !== -1, "should have default in npmconf " + c2) + if (c2 !== 'versions' && c2 !== 'version' && c2 !== 'init.version') { + t.ok(CONFS[c2], 'config in doc should be used somewhere ' + c2) + t.ok(types.indexOf(c2) !== -1, 'should be defined in npmconf ' + c2) + t.ok(defaults.indexOf(c2) !== -1, 'should have default in npmconf ' + c2) } } types.forEach(function (c) { - if (!c.match(/^\_/) && c !== "argv" && !c.match(/^versions?$/)) { - t.ok(DOC[c], "defined type should be documented " + c) - t.ok(CONFS[c], "defined type should be used " + c) + if (!c.match(/^\_/) && c !== 'argv' && !c.match(/^versions?$/)) { + t.ok(DOC[c], 'defined type should be documented ' + c) + t.ok(CONFS[c], 'defined type should be used ' + c) } }) defaults.forEach(function (c) { - if (!c.match(/^\_/) && c !== "argv" && !c.match(/^versions?$/)) { - t.ok(DOC[c], "defaulted type should be documented " + c) - t.ok(CONFS[c], "defaulted type should be used " + c) + if (!c.match(/^\_/) && c !== 'argv' && !c.match(/^versions?$/)) { + t.ok(DOC[c], 'defaulted type should be documented ' + c) + t.ok(CONFS[c], 'defaulted type should be used ' + c) } }) |