From d482680a7dc6bb42adfb6f8ed0d918162e1289af Mon Sep 17 00:00:00 2001 From: sylvain-hamel Date: Mon, 31 Mar 2014 22:55:25 -0400 Subject: [PATCH] fix: add code style verification closes #17 --- .jscs.json | 116 +++++++++++++++++++++++++++++++++++++++++++++++ Gruntfile.coffee | 45 ++++++++++++++++++ index.js | 27 +++++------ package.json | 4 +- 4 files changed, 178 insertions(+), 14 deletions(-) create mode 100644 .jscs.json diff --git a/.jscs.json b/.jscs.json new file mode 100644 index 0000000..fb2277e --- /dev/null +++ b/.jscs.json @@ -0,0 +1,116 @@ +{ + "requireCurlyBraces": [ + "if", + "else", + "for", + "while", + "do", + "try", + "catch" + ], + "requireSpaceAfterKeywords": [ + "if", + "else", + "for", + "while", + "do", + "switch", + "return", + "try", + "catch" + ], + "disallowSpaceAfterKeywords": [], + "requireParenthesesAroundIIFE": true, + "requireSpacesInFunctionExpression": { + "beforeOpeningCurlyBrace": true + }, + "disallowSpacesInFunctionExpression": { + "beforeOpeningRoundBrace": true + }, + "requireSpacesInFunctionExpression": { + "beforeOpeningCurlyBrace": true + }, + "disallowSpacesInFunctionExpression": { + "beforeOpeningRoundBrace": true + }, + "requireBlocksOnNewline": true, + "disallowEmptyBlocks": true, + "disallowSpacesInsideObjectBrackets": true, + "disallowSpacesInsideArrayBrackets": true, + "disallowSpaceAfterObjectKeys": true, + "requireCommaBeforeLineBreak": true, + "disallowLeftStickedOperators": [ + "?", + "+", + "/", + "*", + "=", + "==", + "===", + "!=", + "!==", + ">", + ">=", + "<", + "<=" + ], + "requireRightStickedOperators": ["!"], + "disallowRightStickedOperators": [ + "?", + "+", + "/", + "*", + ":", + "=", + "==", + "===", + "!=", + "!==", + ">", + ">=", + "<", + "<=" + ], + "requireLeftStickedOperators": [","], + "disallowSpaceAfterPrefixUnaryOperators": ["++", "--", "+", "-", "~", "!"], + "disallowSpaceBeforePostfixUnaryOperators": ["++", "--"], + "requireSpaceBeforeBinaryOperators": [ + "+", + "-", + "/", + "*", + "=", + "==", + "===", + "!=", + "!==" + ], + "requireSpaceAfterBinaryOperators": [ + "+", + "-", + "/", + "*", + "=", + "==", + "===", + "!=", + "!==" + ], + "requireCamelCaseOrUpperCaseIdentifiers": true, + "disallowKeywords": ["with"], + "disallowMultipleLineStrings": true, + "validateLineBreaks": "LF", + "validateQuoteMarks": { + "mark": "'", + "escape": true + }, + "disallowMixedSpacesAndTabs": true, + "disallowTrailingWhitespace": true, + "disallowKeywordsOnNewLine": ["else"], + "requireLineFeedAtFileEnd": true, + "maximumLineLength": 100, + "requireCapitalizedConstructors": true, + "requireDotNotation": true + + +} diff --git a/Gruntfile.coffee b/Gruntfile.coffee index a264a24..2f614e8 100644 --- a/Gruntfile.coffee +++ b/Gruntfile.coffee @@ -1,3 +1,7 @@ +JSHINT_NODE = + node: true, + strict: false + module.exports = (grunt) -> # Project configuration. @@ -17,9 +21,48 @@ module.exports = (grunt) -> options: checkTravisBuild: false + # JSHint options + # http://www.jshint.com/options/ + jshint: + default: + files: + src: ['index.js'] + options: JSHINT_NODE + + options: + quotmark: 'single' + bitwise: true + freeze: true + indent: 2 + camelcase: true + strict: true + trailing: true + curly: true + eqeqeq: true + immed: true + latedef: true + newcap: true + noempty: true + unused: true + noarg: true + sub: true + undef: true + maxdepth: 4 + maxstatements: 100 + maxcomplexity: 100 + maxlen: 100 + globals: {} + + jscs: + default: files: src: ['index.js'] + options: + config: '.jscs.json' + grunt.loadNpmTasks 'grunt-npm' grunt.loadNpmTasks 'grunt-bump' grunt.loadNpmTasks 'grunt-auto-release' + grunt.loadNpmTasks 'grunt-contrib-jshint' + grunt.loadNpmTasks 'grunt-jscs-checker' grunt.registerTask 'release', 'Bump the version and publish to NPM.', (type) -> grunt.task.run [ @@ -27,3 +70,5 @@ module.exports = (grunt) -> "bump:#{type||'patch'}", 'npm-publish' ] + grunt.registerTask 'default', ['lint'] + grunt.registerTask 'lint', ['jshint', 'jscs'] diff --git a/index.js b/index.js index 2abc590..2bfc53f 100644 --- a/index.js +++ b/index.js @@ -51,8 +51,7 @@ var IEBrowser = function(baseBrowserDecorator, logger, args) { exec(wmic, function(err) { if (err) { log.error('Killing extra IE process failed. ' + err); - } - else { + } else { log.debug('Killed extra IE process ' + pid); } cb(); @@ -60,7 +59,7 @@ var IEBrowser = function(baseBrowserDecorator, logger, args) { } - this._getOptions = function (url) { + this._getOptions = function(url) { var urlObj = urlparse(url, true); handleXUaCompatible(args, urlObj); @@ -84,18 +83,20 @@ var IEBrowser = function(baseBrowserDecorator, logger, args) { }; function getInternetExplorerExe() { - var suffix = '\\Internet Explorer\\' + processName, - prefixes = [process.env['PROGRAMW6432'], process.env['PROGRAMFILES(X86)'], process.env['PROGRAMFILES']], - prefix, i; - - for (i = 0; i < prefixes.length; i++) { - prefix = prefixes[i]; - if (prefix && fs.existsSync(prefix + suffix)) { - return prefix + suffix; - } + var suffix = '\\Internet Explorer\\' + processName, + prefixes = [process.env['' + 'PROGRAMW6432'], // '' + ' trick to keep jscs happy + process.env['' + 'PROGRAMFILES(X86)'], + process.env['' + 'PROGRAMFILES']], + prefix, i; + + for (i = 0; i < prefixes.length; i++) { + prefix = prefixes[i]; + if (prefix && fs.existsSync(prefix + suffix)) { + return prefix + suffix; } + } - throw new Error("Internet Explorer not found"); + throw new Error('Internet Explorer not found'); } IEBrowser.prototype = { diff --git a/package.json b/package.json index f9b1ed1..23a4453 100644 --- a/package.json +++ b/package.json @@ -25,7 +25,9 @@ "grunt": "~0.4.1", "grunt-bump": "~0.0.7", "grunt-npm": "~0.0.2", - "grunt-auto-release": "~0.0.2" + "grunt-auto-release": "~0.0.2", + "grunt-contrib-jshint": "~0.7.2", + "grunt-jscs-checker": "~0.4.0" }, "contributors": [ "Andreas Krummsdorf ",