diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 0000000..c2cdfb8 --- /dev/null +++ b/.editorconfig @@ -0,0 +1,21 @@ +# EditorConfig helps developers define and maintain consistent +# coding styles between different editors and IDEs +# editorconfig.org + +root = true + + +[*] + +# Change these settings to your own preference +indent_style = space +indent_size = 2 + +# We recommend you to keep these unchanged +end_of_line = lf +charset = utf-8 +trim_trailing_whitespace = true +insert_final_newline = true + +[*.md] +trim_trailing_whitespace = false diff --git a/.eslintrc b/.eslintrc new file mode 100644 index 0000000..7275491 --- /dev/null +++ b/.eslintrc @@ -0,0 +1,155 @@ +env: + mocha: true + node: true + +# globals: + ######################### + ## Only add globals if you're absolutely certain they need to be globals + ########################## + # console: true + +######################### +## set to 0 to allow +## set to 1 to disallow as warning +## set to 2 to disallow as error +######################### +rules: + ######################### + ## Optional Rules + ######################### + # Disallow use of `console` + no-console: 2 + + # Disallow warning comments + no-warning-comments: + - 1 + - terms + - todo + - fixme + location + - anywhere + + # Warns when variables are defined but never used + no-unused-vars: 1 + + # Enforces comma style (first or last) + comma-style: + - 2 + - last + + # Enforces one true `this` variable + consistent-this: + - 2 + - self + # Allows dangling underscores in identifiers + no-underscore-dangle: 2 + + # Enforces function expressions to have a name + func-names: 0 + + # Set maximum depth of nested callbacks + max-nested-callbacks: + - 1 + - 3 + + ######################### + ## Core Rules + ########################## + # Enforces camel case names + camelcase: 2 + + # Prohibit use of == and != in favor of === and !== + eqeqeq: 2 + + # Suppresses warnings about == null comparisons + no-eq-null: 2 + + # No mixing tabs and spaces, with 2 spaces only + no-mixed-spaces-and-tabs: 2 + + # Prohibits use of a variable before it is defined + no-use-before-define: 2 + + # Requires capitalized names for constructor functions + new-cap: 2 + + # Prohibits use of explicitly undeclared variables + no-undef: 2 + + # Enforces Use Strict at the top of function scope + strict: + - 2 + - global + + # Requires variable declarations to be at the top + vars-on-top: 2 + + # Enforce curly braces around blocks in loops and conditionals + curly: 2 + + # Prohibits the use of immediate function invocations w/o wrapping in parentheses + wrap-iife: 2 + + # Prohibits `argument.caller` and `argument.callee` + no-caller: 2 + + # Requires all `for in` loops to filter object's items + guard-for-in: 2 + + # Prohibits comparing a variable against itself + no-self-compare: 2 + + # Prohibits use of `undefined` variable + no-undefined: 0 + + # Prohibits nested ternaries + no-nested-ternary: 2 + + # Enforces a space before blocks + space-before-blocks: + - 2 + - always + + # Enforces spaces following keywords + space-after-keywords: + - 2 + - always + - checkFunctionKeyword: true + + # Enforces quoted property names + quote-props: + - 2 + - always + + # Enforces padded blocks + padded-blocks: + - 1 + - never + + # Enforce functions as expressions + func-style: + - 2 + - expression + + # Require brace style + brace-style: + - 2 + - stroustrup + + # Prohibits Yoda conditions + yoda: + - 2 + - never + + # Enforce use of single quotation marks for strings. + quotes: + - 2 + - single + + # Enforces space inside of brackets (except property name) + space-in-brackets: + - 2 + - always + - propertyName: false + singleValue: false + diff --git a/package.json b/package.json index 6c75efb..7d7a8ff 100644 --- a/package.json +++ b/package.json @@ -28,6 +28,7 @@ "vinyl-sourcemaps-apply": "~0.1.1" }, "devDependencies": { + "eslint": "^0.17.1", "gulp-sourcemaps": "^1.5.1", "jshint": "^2.6.3", "mocha": "^2.2.1", diff --git a/test/lint.js b/test/lint.js new file mode 100644 index 0000000..1183f3b --- /dev/null +++ b/test/lint.js @@ -0,0 +1,49 @@ +'use strict'; + +var eslint = require('eslint'); +var should = require('should'); + +var cli = new eslint.CLIEngine(); +var formatter = cli.getFormatter(); + +var report; + +describe('style-guide', function() { + it('index.js should follow our lint style guide', function(done) { + report = cli.executeOnFiles(['index.js']); + if (report.errorCount > 0 || report.warningCount > 0) { + console.log(formatter(report.results)); + } + + should(report.errorCount).equal(0); + should(report.warningCount).equal(0); + done(); + }); + + it('test/main.js should follow our lint style guide', function(done) { + report = cli.executeOnFiles(['test/main.js']); + if (report.errorCount > 0 || report.warningCount > 0) { + console.log(formatter(report.results)); + } + + should(report.errorCount).equal(0); + should(report.warningCount).equal(0); + done(); + }); + + it('test/lint.js should follow our lint style guide', function(done) { + cli = new eslint.CLIEngine({ + 'rules': { + 'no-console': 0 + } + }); + report = cli.executeOnFiles(['test/lint.js']); + if (report.errorCount > 0 || report.warningCount > 0) { + console.log(formatter(report.results)); + } + + should(report.errorCount).equal(0); + should(report.warningCount).equal(0); + done(); + }); +});