Skip to content

Commit 4fc9b8d

Browse files
filmajLars Schneider
authored and
Lars Schneider
committed
Add JS linting config and lint JS files
Add basic eslint config, including project-wide lint settings in the root of the docs/ dir, as well as browser-and-js-vendor-specific lint config under assets/js, and finally testing-specific lint config under spec/. Set to ignore the generated _site dir and the assets/js/vendor dir
1 parent 3ba3720 commit 4fc9b8d

File tree

9 files changed

+967
-748
lines changed

9 files changed

+967
-748
lines changed

docs/.eslintignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
_site/**
2+
assets/js/vendor/*.js

docs/.eslintrc.json

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
{
2+
"parserOptions": {
3+
"ecmaVersion": 6
4+
},
5+
"extends": "eslint:recommended",
6+
"rules": {
7+
"brace-style": ["error", "allman", {"allowSingleLine": true}],
8+
"camelcase": ["error"],
9+
"comma-spacing": ["error", {"before": false, "after": true}],
10+
"indent": ["error", 4, {"SwitchCase": 1}],
11+
"key-spacing": ["error", {"beforeColon": false, "afterColon": true}],
12+
"keyword-spacing": ["error", {"before": true, "after": true}],
13+
"max-len": ["error", {"code": 116}],
14+
"object-curly-spacing": ["error", "never"],
15+
"no-case-declarations": ["off"],
16+
"no-tabs": ["error"],
17+
"no-trailing-spaces": ["error"],
18+
"no-var": ["error"],
19+
"quotes": ["error", "single"],
20+
"semi": ["error", "always"],
21+
"space-before-function-paren": ["error", "never"],
22+
"space-in-parens": ["error", "never"]
23+
}
24+
}

docs/README.md

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,29 @@ as the testing / assertion library. The tests are implemented as `.js` files und
3232

3333
### Running the Tests
3434

35-
To run the tests once:
35+
To run the tests and linter:
3636

3737
$ npm test
3838

39+
To run just the unit tests once:
40+
41+
$ npm run unit-test
42+
3943
During local development, it may be nice to keep the test runner running in the background as one makes changes to the JavaScript source files (under `assets/js/`), or the test files (under `spec/`) so as to
4044
get immediate feedback. This mode will re-run the tests every time a source or test file changes. To run in this mode:
4145

42-
$ npm test -- --no-single-run --auto-watch
46+
$ npm run unit-test -- --no-single-run --auto-watch
47+
48+
#### Linting JavaScript
49+
50+
This project has formalized a JS style using the [ESLint tool](https://eslint.org). To run the linter, ensure you have dependencies installed via `npm install`, then run:
51+
52+
$ npm run lint
53+
54+
ESLint allows for [cascading rules](https://eslint.org/docs/user-guide/configuring#configuration-cascading-and-hierarchy) to be in place, which this project leverages:
55+
56+
- There is one "global" ESLint config defined in [`.eslintrc.json`](.eslintrc.json), where we house the main stylistic rules.
57+
- We also have a browser-context-specific config defined in [`assets/js/.eslintrc.json`](assets/js/.eslintrc.json).
58+
- Finally, we have a test-context-specific config defined in [`spec/.eslintrc.json`](spec/.eslintrc.json).
59+
60+
The [`.eslintignore` file](.eslintignore) defines what directories and files we should not lint.

docs/assets/js/.eslintrc.json

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
{
2+
"parserOptions": {
3+
"ecmaVersion": 6
4+
},
5+
"env": {
6+
"browser": true,
7+
"jquery": true
8+
},
9+
"globals": {
10+
"Chart": false,
11+
"d3": false,
12+
"Spinner": false
13+
}
14+
}

0 commit comments

Comments
 (0)