tooling: automatically test for code style Currently taking a look if our js coding guidelines are followed is done manually during the main code review of a PR. This takes a lot of time for the reviewer and often results in 1-2 more iterations until the patch is landed, just taking the style issues into account.
Additionally there are sometimes so much style issues that it gets hard to focus on the real issues, e.g. the architecture of a patch or the overall implementation. This PR enables a precheck that allows to automatically detect if our styleguide was followed. The errors can now get cleaned up before the review, saving time of the reviewer and the submitter. As most style issues won't appear any more in a review the review focus will change to a discussion that is more related to the actual implementation, probably resulting in better reviews and overall code quality. PR: #326 PR-URL: https://github.com/apache/couchdb-fauxton/pull/326 Reviewed-By: garren smith <garren.sm...@gmail.com> Project: http://git-wip-us.apache.org/repos/asf/couchdb-fauxton/repo Commit: http://git-wip-us.apache.org/repos/asf/couchdb-fauxton/commit/ae16ad93 Tree: http://git-wip-us.apache.org/repos/asf/couchdb-fauxton/tree/ae16ad93 Diff: http://git-wip-us.apache.org/repos/asf/couchdb-fauxton/diff/ae16ad93 Branch: refs/heads/master Commit: ae16ad93cfe5097b759655603c253e413ecfe6a6 Parents: c54822a Author: Robert Kowalski <r...@kowalski.gd> Authored: Sun Mar 22 22:20:21 2015 +0100 Committer: Robert Kowalski <robertkowal...@apache.org> Committed: Wed Mar 25 11:12:02 2015 +0100 ---------------------------------------------------------------------- .jscsrc | 42 ++++++++++++++++++++++++++++++++++++++++++ package.json | 14 ++++++++------ 2 files changed, 50 insertions(+), 6 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/couchdb-fauxton/blob/ae16ad93/.jscsrc ---------------------------------------------------------------------- diff --git a/.jscsrc b/.jscsrc new file mode 100644 index 0000000..4a4ffbb --- /dev/null +++ b/.jscsrc @@ -0,0 +1,42 @@ +{ + "disallowEmptyBlocks": true, + "disallowKeywordsOnNewLine": ["else"], + "disallowTrailingWhitespace": true, + "validateIndentation": 2, + "fileExtensions": [".js", ".jsx"], + "excludeFiles": [ + "app/**/*.react.js", + "app/addons/.module-cache", + "app/addons/pouchdb/pouchdb.mapreduce.js", + "app/addons/pouchdb/pouch.collate.js", + "app/load_addons.js" + ], + "disallowMixedSpacesAndTabs": true, + "requireSpaceBeforeBinaryOperators": [ + "=", "+=", "-=", "*=", "/=", "%=", "<<=", ">>=", ">>>=", + "&=", "|=", "^=", "+=", + + "+", "-", "*", "/", "%", "<<", ">>", ">>>", "&", + "|", "^", "&&", "||", "===", "==", ">=", + "<=", "<", ">", "!=", "!==" + ], + "requireSpaceAfterBinaryOperators": true, + "requireSpacesInConditionalExpression": true, + "requireSpaceBeforeBlockStatements": true, + "requireLineFeedAtFileEnd": true, + "requireSpacesInFunctionExpression": { + "beforeOpeningCurlyBrace": true + }, + "requireSpaceAfterKeywords": [ + "if", + "else", + "for", + "while", + "do", + "switch", + "return", + "try", + "catch", + "function" + ] +} http://git-wip-us.apache.org/repos/asf/couchdb-fauxton/blob/ae16ad93/package.json ---------------------------------------------------------------------- diff --git a/package.json b/package.json index f1dc99c..3169bad 100644 --- a/package.json +++ b/package.json @@ -10,6 +10,7 @@ "async": "~0.2.6", "couchapp": "~0.11.0", "grunt": "~0.4.1", + "grunt-chmod": "^1.0.3", "grunt-cli": "~0.1.6", "grunt-contrib-clean": "~0.4.1", "grunt-contrib-concat": "~0.3.0", @@ -24,20 +25,21 @@ "grunt-couchapp": "~0.2.1", "grunt-exec": "~0.4.0", "grunt-init": "~0.2.0", + "grunt-md5": "^0.1.11", + "grunt-mocha-phantomjs": "~0.3.0", "grunt-shell": "^1.1.1", "http-proxy": "~1.1.4", + "jsxcs": "~0.2.1", + "nano": "~5.12.0", + "nightwatch": "~0.5.33", "react-tools": "^0.12.0", "send": "~0.1.1", "underscore": "~1.4.2", "url": "~0.7.9", - "urls": "~0.0.3", - "grunt-mocha-phantomjs": "~0.3.0", - "nightwatch": "~0.5.33", - "nano": "~5.12.0", - "grunt-chmod": "^1.0.3", - "grunt-md5": "^0.1.11" + "urls": "~0.0.3" }, "scripts": { + "stylecheck": "jsxcs app && jsxcs test/nightwatch_tests && jsxcs tasks && jsxcs Gruntfile.js", "test": "grunt test", "couchdebug": "grunt couchdebug", "couchdb": "grunt couchdb"