From 637a4dc1f9093b755b1edd65a07b3ac308015e25 Mon Sep 17 00:00:00 2001 From: Laurent Cozic Date: Sun, 29 Sep 2019 22:01:10 +0000 Subject: [PATCH] Improve eslint rules and run them from CI --- .eslintrc.js | 32 ++++++++++++++++++++++++-------- .travis.yml | 17 +++++++++++++++-- package.json | 3 ++- 3 files changed, 41 insertions(+), 11 deletions(-) diff --git a/.eslintrc.js b/.eslintrc.js index 97ace4efd..598e5ffc3 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -33,14 +33,22 @@ module.exports = { "sourceType": "module", }, 'rules': { + // ------------------------------- + // Code correctness + // ------------------------------- "react/jsx-uses-react": "error", "react/jsx-uses-vars": "error", - // Ignore all unused function arguments, because in some - // case they are kept to indicate the function signature. - //"no-unused-vars": ["error", { "argsIgnorePattern": ".*" }], - "@typescript-eslint/no-unused-vars": ["error"], + "no-unused-vars": "error", "no-constant-condition": 0, "no-prototype-builtins": 0, + // This error is always a false positive so far since it detects + // possible race conditions in contexts where we know it cannot happen. + "require-atomic-updates": 0, + "no-lonely-if": "error", + + // ------------------------------- + // Formatting + // ------------------------------- "space-in-parens": ["error", "never"], "semi": ["error", "always"], "eol-last": ["error", "always"], @@ -49,11 +57,19 @@ module.exports = { "comma-dangle": ["error", "always-multiline"], "no-trailing-spaces": "error", "linebreak-style": ["error", "unix"], - // This error is always a false positive so far since it detects - // possible race conditions in contexts where we know it cannot happen. - "require-atomic-updates": 0, "prefer-template": ["error"], - "template-curly-spacing": ["error", "never"] + "template-curly-spacing": ["error", "never"], + "key-spacing": ["error", { + "beforeColon": false, + "afterColon": true, + "mode": "strict" + }], + "block-spacing": ["error"], + "brace-style": ["error", "1tbs"], + "no-spaced-func": ["error"], + "func-call-spacing": ["error"], + "space-before-function-paren": ["error", "never"], + "object-property-newline": ["error"] }, "plugins": [ "react", diff --git a/.travis.yml b/.travis.yml index c93e08df7..3e5152d08 100644 --- a/.travis.yml +++ b/.travis.yml @@ -55,17 +55,30 @@ before_install: script: - | # Install tools + npm install cd Tools npm install + cd .. # Run test units - cd ../CliClient + cd CliClient npm install ./run_test.sh testResult=$? if [ $testResult -ne 0 ]; then exit $testResult fi + cd .. + + # Run linter for pull requests only - this is so that + # bypassing eslint is allowed for urgent fixes. + if [ "$TRAVIS_PULL_REQUEST" != "false" ]; then + npm run linter-ci ./ + testResult=$? + if [ $testResult -ne 0 ]; then + exit $testResult + fi + fi # Find out if we should run the build or not. Electron-builder gets stuck when # builing PRs so we disable it in this case. The Linux build should provide @@ -78,6 +91,6 @@ script: fi # Prepare the Electron app and build it - cd ../ElectronClient/app + cd ElectronClient/app rsync -aP --delete ../../ReactNativeClient/lib/ lib/ npm install && USE_HARD_LINKS=false yarn dist diff --git a/package.json b/package.json index f5bc12d88..b32c04fa8 100644 --- a/package.json +++ b/package.json @@ -3,7 +3,8 @@ "version": "1.0.0", "description": "Joplin root package for linting", "scripts": { - "linter": "./node_modules/.bin/eslint --fix --ext .js --ext .jsx" + "linter": "./node_modules/.bin/eslint --fix --ext .js --ext .jsx", + "linter-ci": "./node_modules/.bin/eslint --ext .js --ext .jsx" }, "husky": { "hooks": {