Skip to content

Commit bd983c7

Browse files
authored
Merge pull request #13 from share/linter
👷 Add linting
2 parents dfd17e6 + ad89e89 commit bd983c7

File tree

4 files changed

+57
-2
lines changed

4 files changed

+57
-2
lines changed

.eslintrc.js

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
// The ESLint ecmaVersion argument is inconsistently used. Some rules will ignore it entirely, so if the rule has
2+
// been set, it will still error even if it's not applicable to that version number. Since Google sets these
3+
// rules, we have to turn them off ourselves.
4+
var DISABLED_ES6_OPTIONS = {
5+
'no-var': 'off',
6+
'prefer-rest-params': 'off'
7+
};
8+
9+
var SHAREDB_RULES = {
10+
// Comma dangle is not supported in ES3
11+
'comma-dangle': ['error', 'never'],
12+
// We control our own objects and prototypes, so no need for this check
13+
'guard-for-in': 'off',
14+
// Google prescribes different indents for different cases. Let's just use 2 spaces everywhere. Note that we have
15+
// to override ESLint's default of 0 indents for this.
16+
indent: ['error', 2, {
17+
SwitchCase: 1
18+
}],
19+
// Less aggressive line length than Google, which is especially useful when we have a lot of callbacks in our code
20+
'max-len': ['error',
21+
{
22+
code: 120,
23+
tabWidth: 2,
24+
ignoreUrls: true
25+
}
26+
],
27+
// Google overrides the default ESLint behaviour here, which is slightly better for catching erroneously unused
28+
// variables
29+
'no-unused-vars': ['error', {vars: 'all', args: 'after-used'}],
30+
// It's more readable to ensure we only have one statement per line
31+
'max-statements-per-line': ['error', {max: 1}],
32+
// ES3 doesn't support spread
33+
'prefer-spread': 'off',
34+
// as-needed quote props are easier to write
35+
'quote-props': ['error', 'as-needed'],
36+
'require-jsdoc': 'off',
37+
'valid-jsdoc': 'off'
38+
};
39+
40+
module.exports = {
41+
extends: 'google',
42+
parserOptions: {
43+
ecmaVersion: 3
44+
},
45+
rules: Object.assign(
46+
{},
47+
DISABLED_ES6_OPTIONS,
48+
SHAREDB_RULES
49+
)
50+
};

.github/workflows/test.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ jobs:
3131
node-version: ${{ matrix.node }}
3232
- name: Install
3333
run: npm install
34+
- name: Lint
35+
run: npm run lint
3436
- name: Test
3537
run: npm run test-cover
3638
- name: Coveralls

package.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,13 @@
1111
"devDependencies": {
1212
"chai": "^4.2.0",
1313
"coveralls": "^3.0.7",
14+
"eslint": "^7.23.0",
15+
"eslint-config-google": "^0.14.0",
1416
"mocha": "^6.2.2",
1517
"nyc": "^14.1.1"
1618
},
1719
"scripts": {
20+
"lint": "./node_modules/.bin/eslint --ignore-path .gitignore '**/*.js'",
1821
"test": "mocha",
1922
"test-cover": "nyc --temp-dir=coverage -r text -r lcov npm test"
2023
},

test/test.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
var RedisPubSub = require('../index');
1+
var redisPubSub = require('../index');
22

33
require('sharedb/test/pubsub')(function(callback) {
4-
callback(null, RedisPubSub());
4+
callback(null, redisPubSub());
55
});

0 commit comments

Comments
 (0)