Add ESLint config & update documentation

Change-Id: I10ecba3272265aa1d6cae29c17f60b2f741f15f4
This commit is contained in:
Kasper Nilsson
2017-04-27 10:01:37 +02:00
parent c0ba40f6c9
commit 4a03e36aab
2 changed files with 89 additions and 0 deletions

View File

@@ -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"
]
}

View File

@@ -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 `<script>` tags, like for test suites, you may have
to supply the `--ext .html` flag.