Skip to content

Commit

Permalink
Merge pull request #13 from share/linter
Browse files Browse the repository at this point in the history
👷 Add linting
  • Loading branch information
alecgibson committed Mar 31, 2021
2 parents dfd17e6 + ad89e89 commit bd983c7
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 2 deletions.
50 changes: 50 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
// The ESLint ecmaVersion argument is inconsistently used. Some rules will ignore it entirely, so if the rule has
// been set, it will still error even if it's not applicable to that version number. Since Google sets these
// rules, we have to turn them off ourselves.
var DISABLED_ES6_OPTIONS = {
'no-var': 'off',
'prefer-rest-params': 'off'
};

var SHAREDB_RULES = {
// Comma dangle is not supported in ES3
'comma-dangle': ['error', 'never'],
// We control our own objects and prototypes, so no need for this check
'guard-for-in': 'off',
// Google prescribes different indents for different cases. Let's just use 2 spaces everywhere. Note that we have
// to override ESLint's default of 0 indents for this.
indent: ['error', 2, {
SwitchCase: 1
}],
// Less aggressive line length than Google, which is especially useful when we have a lot of callbacks in our code
'max-len': ['error',
{
code: 120,
tabWidth: 2,
ignoreUrls: true
}
],
// Google overrides the default ESLint behaviour here, which is slightly better for catching erroneously unused
// variables
'no-unused-vars': ['error', {vars: 'all', args: 'after-used'}],
// It's more readable to ensure we only have one statement per line
'max-statements-per-line': ['error', {max: 1}],
// ES3 doesn't support spread
'prefer-spread': 'off',
// as-needed quote props are easier to write
'quote-props': ['error', 'as-needed'],
'require-jsdoc': 'off',
'valid-jsdoc': 'off'
};

module.exports = {
extends: 'google',
parserOptions: {
ecmaVersion: 3
},
rules: Object.assign(
{},
DISABLED_ES6_OPTIONS,
SHAREDB_RULES
)
};
2 changes: 2 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ jobs:
node-version: ${{ matrix.node }}
- name: Install
run: npm install
- name: Lint
run: npm run lint
- name: Test
run: npm run test-cover
- name: Coveralls
Expand Down
3 changes: 3 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,13 @@
"devDependencies": {
"chai": "^4.2.0",
"coveralls": "^3.0.7",
"eslint": "^7.23.0",
"eslint-config-google": "^0.14.0",
"mocha": "^6.2.2",
"nyc": "^14.1.1"
},
"scripts": {
"lint": "./node_modules/.bin/eslint --ignore-path .gitignore '**/*.js'",
"test": "mocha",
"test-cover": "nyc --temp-dir=coverage -r text -r lcov npm test"
},
Expand Down
4 changes: 2 additions & 2 deletions test/test.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
var RedisPubSub = require('../index');
var redisPubSub = require('../index');

require('sharedb/test/pubsub')(function(callback) {
callback(null, RedisPubSub());
callback(null, redisPubSub());
});

0 comments on commit bd983c7

Please sign in to comment.