Permalink
Browse files

initial commit

  • Loading branch information...
1 parent 3784242 commit 0a7e9afcfd6e973e40dea18c47df518afc4c7df5 @feross committed Jan 27, 2015
Showing with 274 additions and 0 deletions.
  1. +71 −0 .jscsrc
  2. +25 −0 .jshintrc
  3. +4 −0 .travis.yml
  4. +20 −0 LICENSE
  5. +66 −0 README.md
  6. +4 −0 bin/cmd.js
  7. +69 −0 index.js
  8. +15 −0 jscs-reporter.js
View
@@ -0,0 +1,71 @@
+{
+ "disallowKeywordsOnNewLine": ["else"],
+ "disallowKeywords": ["with"],
+ "disallowMixedSpacesAndTabs": true,
+ "disallowMultipleLineBreaks": true,
+ "disallowMultipleLineStrings": true,
+ "disallowMultipleVarDecl": "exceptUndefined",
+ "disallowNewlineBeforeBlockStatements": true,
+ "disallowOperatorBeforeLineBreak": ["."],
+ "disallowPaddingNewlinesInBlocks": true,
+ "disallowQuotedKeysInObjects": "allButReserved",
+ "disallowSemicolons": true,
+ "disallowSpaceAfterObjectKeys": true,
+ "disallowSpaceAfterPrefixUnaryOperators": ["++", "--", "+", "-", "~", "!"],
+ "disallowSpaceBeforePostfixUnaryOperators": ["++", "--"],
+ "disallowSpacesInCallExpression": true,
+ "disallowSpacesInsideParentheses": true,
+ "disallowTrailingComma": true,
+ "disallowTrailingWhitespace": true,
+ "disallowYodaConditions": true,
+ "requireBlocksOnNewline": 1,
+ "requireCapitalizedConstructors": true,
+ "requireCommaBeforeLineBreak": true,
+ "requireDotNotation": true,
+ "requireLineFeedAtFileEnd": true,
+ "requireOperatorBeforeLineBreak": ["=", "+", "-", "/", "*", "==", "===", "!=", "!==", ">", ">=", "<", "<="],
+ "requireParenthesesAroundIIFE": true,
+ "requireSpaceAfterBinaryOperators": true,
+ "requireSpaceAfterKeywords": true,
+ "requireSpaceAfterLineComment": true,
+ "requireSpaceBeforeBinaryOperators": true,
+ "requireSpaceBeforeBlockStatements": true,
+ "requireSpaceBeforeKeywords": ["else", "while", "catch"],
+ "requireSpaceBeforeObjectValues": true,
+ "requireSpaceBetweenArguments": true,
+ "requireSpacesInAnonymousFunctionExpression": {
+ "beforeOpeningRoundBrace": true,
+ "beforeOpeningCurlyBrace": true
+ },
+ "requireSpacesInConditionalExpression": {
+ "afterTest": true,
+ "beforeConsequent": true,
+ "afterConsequent": true,
+ "beforeAlternate": true
+ },
+ "requireSpacesInForStatement": true,
+ "requireSpacesInFunctionDeclaration": {
+ "beforeOpeningRoundBrace": true,
+ "beforeOpeningCurlyBrace": true
+ },
+ "requireSpacesInFunctionExpression": {
+ "beforeOpeningRoundBrace": true,
+ "beforeOpeningCurlyBrace": true
+ },
+ "requireSpacesInFunction": {
+ "beforeOpeningRoundBrace": true,
+ "beforeOpeningCurlyBrace": true
+ },
+ "requireSpacesInNamedFunctionExpression": {
+ "beforeOpeningRoundBrace": true,
+ "beforeOpeningCurlyBrace": true
+ },
+ "safeContextKeyword": ["self"],
+ "validateIndentation": 2,
+ "validateLineBreaks": "LF",
+ "validateParameterSeparator": ", ",
+ "validateQuoteMarks": {
+ "mark": "'",
+ "escape": true
+ }
+}
View
@@ -0,0 +1,25 @@
+{
+ "asi": true,
+ "browser": true,
+ "devel": true,
+ "eqeqeq": true,
+ "eqnull": true,
+ "expr": true,
+ "globals": {
+ "chrome": false,
+ "FileList": false
+ },
+ "immed": true,
+ "latedef": "nofunc",
+ "laxbreak": true,
+ "loopfunc": true,
+ "newcap": true,
+ "noarg": true,
+ "node": true,
+ "predef": [
+ "escape",
+ "unescape"
+ ],
+ "strict": false,
+ "undef": true
+}
View
@@ -0,0 +1,4 @@
+language: node_js
+node_js:
+- '0.10'
+- '0.11'
View
@@ -0,0 +1,20 @@
+The MIT License (MIT)
+
+Copyright (c) Feross Aboukhadijeh
+
+Permission is hereby granted, free of charge, to any person obtaining a copy of
+this software and associated documentation files (the "Software"), to deal in
+the Software without restriction, including without limitation the rights to
+use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
+the Software, and to permit persons to whom the Software is furnished to do so,
+subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in all
+copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
+FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
+COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
+IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
View
@@ -0,0 +1,66 @@
+# standard [![travis][travis-image]][travis-url] [![npm][npm-image]][npm-url] [![downloads][downloads-image]][downloads-url]
+
+[travis-image]: https://img.shields.io/travis/feross/standard.svg?style=flat
+[travis-url]: https://travis-ci.org/feross/standard
+[npm-image]: https://img.shields.io/npm/v/standard.svg?style=flat
+[npm-url]: https://npmjs.org/package/standard
+[downloads-image]: https://img.shields.io/npm/dm/standard.svg?style=flat
+[downloads-url]: https://npmjs.org/package/standard
+
+### Enforce code style standards
+
+## install
+
+```bash
+npm install standard
+```
+
+## usage
+
+The easiest way to use `standard` is to install it globally as a Node command line
+program. To do so, simply run the following command in your terminal (flag `-g` installs
+`standard` globally on your system, omit it if you want to install in the current working
+directory):
+
+```bash
+npm install standard -g
+```
+
+After you've done that you should be able to use the `standard` program. The simplest use
+case would be checking the style of all JavaScript files in the current working directory:
+
+```bash
+$ standard
+Error: Code style check failed:
+ /Users/feross/code/webtorrent/lib/torrent.js:950:11: Expected '===' and instead saw '=='.
+```
+
+### what you might do if you're clever
+
+1. Add it to `package.json`
+
+ ```json
+ {
+ "name": "my-cool-package",
+ "devDependencies": {
+ "standard": "*"
+ },
+ "scripts": {
+ "test": "standard && node my-normal-tests.js"
+ }
+ }
+ ```
+
+2. Check style automatically when you run `npm test`
+
+ ```bash
+ $ npm test
+ Error: Code style check failed:
+ /Users/feross/code/webtorrent/lib/torrent.js:950:11: Expected '===' and instead saw '=='.
+ ```
+
+3. Never give style feedback on a pull request again!
+
+## license
+
+MIT. Copyright (c) [Feross Aboukhadijeh](http://feross.org).
View
@@ -0,0 +1,4 @@
+#!/usr/bin/env node
+
+var standard = require('../')
+standard(process.cwd())
View
@@ -0,0 +1,69 @@
+var cp = require('child_process')
+var find = require('find')
+var path = require('path')
+var split = require('split')
+
+var JSHINT = path.join(__dirname, 'node_modules', '.bin', 'jshint')
+var JSHINTRC = path.join(__dirname, '.jshintrc')
+
+var JSCS = path.join(__dirname, 'node_modules', '.bin', 'jscs')
+var JSCSRC = path.join(__dirname, '.jscsrc')
+var JSCS_REPORTER = path.join(__dirname, 'jscs-reporter.js')
+
+module.exports = function (dir) {
+ find.file(/\.js$/, dir || process.cwd(), function (files) {
+ files = files.filter(function (file) {
+ return !/\/node_modules\/|\.min.js$/.test(file)
+ })
+
+ var jshintArgs = ['--config', JSHINTRC, '--reporter', 'unix'].concat(files)
+ var jscsArgs = ['--config', JSCSRC, '--reporter', JSCS_REPORTER].concat(files)
+
+ var jshint = spawn(JSHINT, jshintArgs, function (jshintErr) {
+ var jscs = spawn(JSCS, jscsArgs, function (jscsErr) {
+ if (jshintErr || jscsErr) {
+ process.exit(1)
+ }
+ })
+
+ stderrPipe(jscs.stdout)
+ stderrPipe(jscs.stderr)
+ })
+
+ stderrPipe(jshint.stdout)
+ stderrPipe(jshint.stderr)
+ })
+ .error(function (err) {
+ if (err) error(err)
+ })
+}
+
+function spawn (command, args, cb) {
+ var child = cp.spawn(command, args)
+ child.on('error', error)
+ child.on('close', function (code) {
+ if (code !== 0) cb(new Error('non-zero exit code: ' + code))
+ else cb(null)
+ })
+ return child
+}
+
+function error (err) {
+ console.error(err.stack || err.message || err)
+ process.exit(1)
+}
+
+var errored = false
+function stderrPipe (readable) {
+ readable
+ .pipe(split())
+ .on('data', function (line) {
+ if (line === '') return
+ if (/^\d+ errors?/.test(line)) return
+ if (!errored) {
+ errored = true
+ console.error('Error: Code style check failed:')
+ }
+ console.error(' ' + line)
+ })
+}
View
@@ -0,0 +1,15 @@
+var util = require('util')
+module.exports = function (errorsCollection) {
+ var errorCount = 0
+ errorsCollection.forEach(function (errors) {
+ var file = errors.getFilename()
+ if (!errors.isEmpty()) {
+ errors.getErrorList().forEach(function (error) {
+ errorCount++
+ console.log(util.format(
+ '%s:%d:%d: %s', file, error.line, error.column, error.message
+ ))
+ })
+ }
+ })
+}

0 comments on commit 0a7e9af

Please sign in to comment.