From 4a03e36aabc27ebb33c2e85d1c3a64cd6d2f11e4 Mon Sep 17 00:00:00 2001 From: Kasper Nilsson Date: Thu, 27 Apr 2017 10:01:37 +0200 Subject: [PATCH] Add ESLint config & update documentation Change-Id: I10ecba3272265aa1d6cae29c17f60b2f741f15f4 --- polygerrit-ui/.eslintrc.json | 70 ++++++++++++++++++++++++++++++++++++ polygerrit-ui/README.md | 19 ++++++++++ 2 files changed, 89 insertions(+) create mode 100644 polygerrit-ui/.eslintrc.json diff --git a/polygerrit-ui/.eslintrc.json b/polygerrit-ui/.eslintrc.json new file mode 100644 index 0000000000..8c4ee998a9 --- /dev/null +++ b/polygerrit-ui/.eslintrc.json @@ -0,0 +1,70 @@ +{ + "extends": ["eslint:recommended", "google"], + "installedESLint": true, + "env": { + "browser": true, + "es6": true + }, + "globals": { + "__dirname": false, + "app": false, + "page": false, + "Polymer": false, + "process": false, + "require": false, + "Gerrit": false, + "Promise": false, + "assert": false, + "test": false, + "flushAsynchronousOperations": false + }, + "rules": { + "arrow-parens": ["error", "as-needed"], + "brace-style": ["error", "1tbs", { "allowSingleLine": true }], + "camelcase": "off", + "comma-dangle": ["error", "always-multiline"], + "eol-last": "off", + "indent": ["error", 2, { + "MemberExpression": 2, + "FunctionDeclaration": {"body": 1, "parameters": 2}, + "FunctionExpression": {"body": 1, "parameters": 2}, + "CallExpression": {"arguments": 2}, + "ArrayExpression": 1, + "ObjectExpression": 1, + "SwitchCase": 1 + }], + "max-len": [ + "error", + 80, + 2, + {"ignoreComments": true} + ], + "new-cap": ["error", { "capIsNewExceptions": ["Polymer"] }], + "no-console": "off", + "no-restricted-syntax": [ + "error", + { + "selector": "BinaryExpression > CallExpression > MemberExpression > Identifier[name = 'indexOf']", + "message": "Prefer includes/startsWith to indexOf." + }, + { + "selector": "ExpressionStatement > CallExpression > MemberExpression > Identifier[name = 'forEach']", + "message": "Prefer for-of to Array.forEach." + } + ], + "no-undef": "off", + "no-var": "error", + "object-shorthand": ["error", "always"], + "prefer-arrow-callback": "error", + "prefer-const": "error", + "prefer-spread": "error", + "quote-props": ["error", "consistent-as-needed"], + "require-jsdoc": "off", + "semi": [2, "always"], + "template-curly-spacing": "error", + "valid-jsdoc": "off" + }, + "plugins": [ + "html" + ] +} diff --git a/polygerrit-ui/README.md b/polygerrit-ui/README.md index 77d5781e18..0fdbd446f6 100644 --- a/polygerrit-ui/README.md +++ b/polygerrit-ui/README.md @@ -116,3 +116,22 @@ Then visit http://localhost:8081/elements/foo/bar_test.html We follow the [Google JavaScript Style Guide](https://google.github.io/styleguide/javascriptguide.xml) with a few exceptions. When in doubt, remain consistent with the code around you. + +In addition, we encourage the use of [ESLint](http://eslint.org/). +It is available as a command line utility, as well as a plugin for most editors +and IDEs. It, along with a few dependencies, can also be installed through NPM: + +```sh +sudo npm install -g eslint eslint-config-google eslint-plugin-html +``` + +`eslint-config-google` is a port of the Google JS Style Guide to an ESLint +config module, and `eslint-plugin-html` allows ESLint to lint scripts inside +HTML. +We have an .eslintrc.json config file in the polygerrit-ui/ directory configured +to enforce the preferred style of the PolyGerrit project. +After installing, you can use `eslint` on any new file you create. +In addition, you can supply the `--fix` flag to apply some suggested fixes for +simple style issues. +If you modify JS inside of `