From 7e0d19cd7af7f0b0d74e8269c4a84a67efd54183 Mon Sep 17 00:00:00 2001 From: Itms Date: Sat, 28 Oct 2017 15:30:37 +0000 Subject: [PATCH] Linting with Coala. This new script and the associated configuration files lint our source code (JS and C++). This will be extended in the future, refs #4833. Reviewed By: Imarok Differential Revision: https://code.wildfiregames.com/D213 This was SVN commit r20364. --- .coafile | 10 +++ build/jenkins/lint-config/eslintrc.json | 95 +++++++++++++++++++++++++ build/jenkins/lint-config/jshintrc.json | 11 +++ build/jenkins/lint-patch.sh | 12 ++++ 4 files changed, 128 insertions(+) create mode 100644 .coafile create mode 100644 build/jenkins/lint-config/eslintrc.json create mode 100644 build/jenkins/lint-config/jshintrc.json create mode 100755 build/jenkins/lint-patch.sh diff --git a/.coafile b/.coafile new file mode 100644 index 0000000000..7e1e519026 --- /dev/null +++ b/.coafile @@ -0,0 +1,10 @@ +[Source] +bears = CPPCheckBear +files = source/**.(cpp|h) +ignore = source/third_party/** + +[JS] +bears = ESLintBear, JSHintBear +eslint_config = build/jenkins/lint-config/eslintrc.json +jshint_config = build/jenkins/lint-config/jshintrc.json +files = binaries/data/**.js diff --git a/build/jenkins/lint-config/eslintrc.json b/build/jenkins/lint-config/eslintrc.json new file mode 100644 index 0000000000..b2fe884251 --- /dev/null +++ b/build/jenkins/lint-config/eslintrc.json @@ -0,0 +1,95 @@ +{ + "parserOptions": { + "ecmaVersion": 6 + }, + "plugins": [ + "brace-rules" + ], + "rules": { + "no-cond-assign": 1, + "no-constant-condition": 1, + "no-dupe-args": 1, + "no-dupe-keys": 1, + "no-duplicate-case": 1, + "no-empty": 1, + "no-extra-boolean-cast": 0, + "no-extra-parens": 0, + "no-extra-semi": 1, + "no-func-assign": 1, + "no-negated-in-lhs": 1, + "no-obj-calls": 1, + "no-unreachable": 1, + "use-isnan": 1, + "valid-jsdoc": 0, + "valid-typeof": 1, + + "block-scoped-var": 0, + "consistent-return": 1, + "curly": ["warn", "multi"], + "default-case": 1, + "dot-notation": 1, + "no-else-return": 1, + "no-invalid-this": 1, + "no-lone-blocks": 1, + "no-loop-func": 0, + "no-multi-spaces": ["warn", { "ignoreEOLComments": true }], + "no-new": 1, + "no-redeclare": 0, + "no-return-assign": 1, + "no-self-assign": 1, + "no-self-compare": 1, + "no-unmodified-loop-condition": 1, + "no-unused-expressions": 1, + "no-unused-labels": 1, + "no-useless-concat": 0, + "yoda": 1, + + "no-delete-var": 1, + "no-label-var": 1, + "no-shadow-restricted-names": 1, + "no-shadow": 1, + "no-undef": 0, + "no-undef-init": 1, + "no-unused-vars": 0, + + "comma-spacing": 1, + "indent": ["warn", "tab", { "outerIIFEBody": 0 }], + "key-spacing": 1, + "new-cap": 0, + "new-parens": 1, + "no-mixed-spaces-and-tabs": ["warn", "smart-tabs"], + "no-multi-assign": 1, + "no-trailing-spaces": 1, + "no-unneeded-ternary": 1, + "object-curly-spacing": ["warn", "always"], + "operator-assignment": 1, + "operator-linebreak": ["warn", "after"], + "quote-props": 1, + "semi": 1, + "semi-spacing": 1, + "space-before-function-paren": ["warn", "never"], + "space-in-parens": 1, + "space-unary-ops": 1, + "spaced-comment": ["warn", "always"], + + "no-class-assign": 1, + "no-const-assign": 1, + "no-dupe-class-members" : 1, + "prefer-const": 0, + + "brace-rules/brace-on-same-line": ["warn", { + "FunctionDeclaration": "never", + "FunctionExpression": "ignore", + "ArrowFunctionExpression": "always", + "IfStatement": "never", + "TryStatement": "ignore", + "CatchClause": "ignore", + "DoWhileStatement": "never", + "WhileStatement": "never", + "ForStatement": "never", + "ForInStatement": "never", + "ForOfStatement": "never", + "SwitchStatement": "never" + }, { "allowSingleLine": true }] + } +} diff --git a/build/jenkins/lint-config/jshintrc.json b/build/jenkins/lint-config/jshintrc.json new file mode 100644 index 0000000000..ea2eba5ce9 --- /dev/null +++ b/build/jenkins/lint-config/jshintrc.json @@ -0,0 +1,11 @@ +{ + "esversion": 6, + "eqeqeq": false, + "freeze": true, + "latedef": "nofunc", + "loopfunc": true, + "noarg": true, + "nonbsp": true, + "undef": false, + "unused": false +} diff --git a/build/jenkins/lint-patch.sh b/build/jenkins/lint-patch.sh new file mode 100755 index 0000000000..5235984ccc --- /dev/null +++ b/build/jenkins/lint-patch.sh @@ -0,0 +1,12 @@ +#!/bin/sh + +# Lint errors should not count as build failures +set +e +set -v + +# Move to the root of the repository (this script is in build/jenkins/) +cd "$(dirname $0)"/../../ + +arc patch --diff "$DIFF_ID" --force + +svn st | grep '^[AM]' | cut -c 9- | xargs coala --ci --flush-cache --limit-files > .phabricator-comment