Comparing version 2.1.1 to 2.2.0
#!/usr/bin/env node | ||
var minimist = require('minimist') | ||
var standard = require('../') | ||
var flag = process.argv[2] | ||
var argv = minimist(process.argv.slice(2), { | ||
boolean: [ 'help', 'bare', 'verbose', 'version' ], | ||
alias: { | ||
help: 'h', | ||
verbose: 'v' | ||
} | ||
}) | ||
if (flag === '--version') { | ||
if (argv.help) { | ||
console.log(function () { | ||
/* | ||
Usage: | ||
standard <flags> | ||
Flags: | ||
-v, --verbose Show error codes (so you can ignore specific rules) | ||
--version Display the current version | ||
-h, --help Display the help and usage details | ||
Report bugs: https://github.com/feross/standard/issues | ||
*/ | ||
}.toString().split(/\n/).slice(2, -2).join('\n')) | ||
process.exit(0) | ||
} | ||
if (argv.version) { | ||
console.log(require('../package.json').version) | ||
@@ -14,4 +39,5 @@ process.exit(0) | ||
cwd: process.cwd(), | ||
bare: flag === '--bare' || flag === '-b', | ||
verbose: flag === '--verbose' || flag === '-v' | ||
bare: argv.bare, | ||
stdin: !process.stdin.isTTY, | ||
verbose: argv.verbose | ||
}) |
@@ -25,4 +25,5 @@ #!/usr/bin/env node | ||
'https://github.com/feross/bittorrent-dht.git', | ||
'https://github.com/feross/buffer.git' | ||
// 'https://github.com/mafintosh/level-temp.git' | ||
'https://github.com/feross/buffer.git', | ||
'https://github.com/feross/studynotes.git', | ||
'https://github.com/mafintosh/level-temp.git' | ||
] | ||
@@ -29,0 +30,0 @@ |
98
index.js
@@ -5,2 +5,3 @@ var cp = require('child_process') | ||
var Minimatch = require('minimatch').Minimatch | ||
var parallel = require('run-parallel') | ||
var path = require('path') | ||
@@ -39,3 +40,12 @@ var split = require('split') | ||
module.exports = function (opts) { | ||
/** | ||
* JavaScript Standard Style | ||
* @param {Object} opts options object | ||
* @param {string|Array.<String>} opts.ignore files to ignore | ||
* @param {string} opts.cwd current working directory | ||
* @param {boolean} opts.verbose show error codes | ||
* @param {boolean} opts.bare show raw linter output (for debugging) | ||
* @param {boolean} opts.stdin check text from stdin instead of filesystem | ||
*/ | ||
module.exports = function standard (opts) { | ||
if (!opts) opts = {} | ||
@@ -56,52 +66,64 @@ var errors = [] | ||
if (opts.ignore) ignore = ignore.concat(opts.ignore) | ||
var jshintArgs = ['--config', JSHINT_RC, '--reporter', JSHINT_REPORTER] | ||
ignore = ignore.map(function (pattern) { | ||
return new Minimatch(pattern) | ||
}) | ||
var jscsReporter = opts.verbose ? JSCS_REPORTER_VERBOSE : JSCS_REPORTER | ||
var jscsArgs = ['--config', JSCS_RC, '--reporter', jscsReporter] | ||
glob('**/*.js', { | ||
cwd: opts.cwd || process.cwd() | ||
}, function (err, files) { | ||
if (err) return error(err) | ||
files = files.filter(function (file) { | ||
return !ignore.some(function (mm) { | ||
return mm.match(file) | ||
}) | ||
}) | ||
var eslintReporter = opts.verbose ? ESLINT_REPORTER_VERBOSE : ESLINT_REPORTER | ||
var eslintArgs = ['--config', ESLINT_RC, '--format', eslintReporter] | ||
var jshintArgs = ['--config', JSHINT_RC, '--reporter', JSHINT_REPORTER] | ||
var jscsReporter = opts.verbose ? JSCS_REPORTER_VERBOSE : JSCS_REPORTER | ||
var jscsArgs = ['--config', JSCS_RC, '--reporter', jscsReporter] | ||
var eslintReporter = opts.verbose ? ESLINT_REPORTER_VERBOSE : ESLINT_REPORTER | ||
var eslintArgs = ['--config', ESLINT_RC, '--format', eslintReporter] | ||
if (opts.verbose) { | ||
jshintArgs.push('--verbose') | ||
jscsArgs.push('--verbose') | ||
} | ||
if (opts.verbose) { | ||
jshintArgs.push('--verbose') | ||
jscsArgs.push('--verbose') | ||
} | ||
if (opts.stdin) { | ||
// stdin | ||
jshintArgs.push('-') | ||
eslintArgs.push('--stdin') | ||
lint() | ||
} else { | ||
// traverse filesystem | ||
if (opts.ignore) ignore = ignore.concat(opts.ignore) | ||
jshintArgs = jshintArgs.concat(files) | ||
jscsArgs = jscsArgs.concat(files) | ||
eslintArgs = eslintArgs.concat(files) | ||
ignore = ignore.map(function (pattern) { | ||
return new Minimatch(pattern) | ||
}) | ||
spawn(JSHINT, jshintArgs, function (err1) { | ||
spawn(JSCS, jscsArgs, function (err2) { | ||
spawn(ESLINT, eslintArgs, function (err3) { | ||
done(err1 || err2 || err3) | ||
glob('**/*.js', { | ||
cwd: opts.cwd || process.cwd() | ||
}, function (err, files) { | ||
if (err) return error(err) | ||
files = files.filter(function (file) { | ||
return !ignore.some(function (mm) { | ||
return mm.match(file) | ||
}) | ||
}) | ||
jshintArgs = jshintArgs.concat(files) | ||
jscsArgs = jscsArgs.concat(files) | ||
eslintArgs = eslintArgs.concat(files) | ||
lint() | ||
}) | ||
}) | ||
} | ||
function lint () { | ||
parallel([ | ||
spawn.bind(undefined, JSHINT, jshintArgs), | ||
spawn.bind(undefined, JSCS, jscsArgs), | ||
spawn.bind(undefined, ESLINT, eslintArgs) | ||
], function (err, r) { | ||
if (err) return error(err) | ||
if (r.some(Boolean)) printErrors() | ||
}) | ||
} | ||
function spawn (command, args, cb) { | ||
var child = cp.spawn(command, args) | ||
child.on('error', error) | ||
child.on('error', cb) | ||
child.on('close', function (code) { | ||
if (code !== 0) cb(new Error('non-zero exit code: ' + code)) | ||
else cb(null) | ||
cb(null, code) | ||
}) | ||
if (opts.stdin) process.stdin.pipe(child.stdin) | ||
stderrPipe(child.stdout) | ||
stderrPipe(child.stderr) | ||
return child | ||
} | ||
@@ -118,4 +140,3 @@ | ||
function done (err) { | ||
if (!err) return | ||
function printErrors () { | ||
if (opts.bare) { | ||
@@ -131,2 +152,5 @@ errors.forEach(function (str) { | ||
errors | ||
.map(function (str) { // normalize stdin "filename" | ||
return str.replace(/^(<text>|input)/, 'stdin') | ||
}) | ||
.filter(function (str) { // de-duplicate errors | ||
@@ -133,0 +157,0 @@ if (errMap[str]) return false |
@@ -8,3 +8,2 @@ module.exports = function (results) { | ||
var msg = message.message | ||
if (msg[msg.length - 1] === '.') msg = msg.substring(0, msg.length - 1) | ||
@@ -11,0 +10,0 @@ output += result.filePath |
@@ -8,3 +8,2 @@ module.exports = function (results) { | ||
var msg = message.message | ||
if (msg[msg.length - 1] === '.') msg = msg.substring(0, msg.length - 1) | ||
@@ -11,0 +10,0 @@ output += result.filePath |
{ | ||
"name": "standard", | ||
"description": "JavaScript Standard Style", | ||
"version": "2.1.1", | ||
"version": "2.2.0", | ||
"author": { | ||
@@ -23,2 +23,4 @@ "name": "Feross Aboukhadijeh", | ||
"minimatch": "^2.0.1", | ||
"minimist": "^1.1.0", | ||
"run-parallel": "^1.0.0", | ||
"split": "^0.3.2" | ||
@@ -30,3 +32,2 @@ }, | ||
"rimraf": "^2.2.8", | ||
"run-parallel": "^1.0.0", | ||
"run-series": "^1.0.2" | ||
@@ -59,3 +60,3 @@ }, | ||
"scripts": { | ||
"test": "standard && node ./bin/test.js" | ||
"test": "./bin/cmd.js && node ./bin/test.js" | ||
}, | ||
@@ -62,0 +63,0 @@ "standard": { |
@@ -134,2 +134,8 @@ # JavaScript Standard Style | ||
### Is there an automatic formatter? | ||
Yes, try using [Max Ogden](https://github.com/maxogden)'s experimental auto formatter | ||
**[`standard-format`](https://github.com/maxogden/standard-format)** to fix the easier | ||
cases. | ||
### How do I hide a certain warning? | ||
@@ -136,0 +142,0 @@ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
25078
4
321
184
9
+ Addedminimist@^1.1.0
+ Addedrun-parallel@^1.0.0
+ Addedqueue-microtask@1.2.3(transitive)
+ Addedrun-parallel@1.2.0(transitive)