Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use eslint instead of jshint #604

Merged
merged 12 commits into from
Oct 6, 2022
44 changes: 44 additions & 0 deletions .eslintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
{
"env": {
"node": true
},
"parserOptions": {
"ecmaVersion": 8
},
"globals": {
"window": false,
"document": false
},
"rules": {
"comma-style": [
2,
"last"
],
"eqeqeq": ["error", "always", {"null": "ignore"}],
"indent": [
2,
2,
{
"SwitchCase": 1
}
],
"new-cap": 2,
"quotes": [
2,
"single"
],
"no-undef": 2,
"no-shadow": 0,
"no-unused-expressions": 2,
"no-cond-assign": [
2,
"except-parens"
]
},
"overrides": [
{
"files": ["test/**/*.mocha.js", "test/browser/*.js"],
"env": {"mocha": true, "node": true}
}
]
}
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,4 @@ jobs:
- name: Install
run: npm install
- name: Test
run: npm run test
run: npm run checks
18 changes: 0 additions & 18 deletions .jshintrc

This file was deleted.

22 changes: 13 additions & 9 deletions lib/AppForServer.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ if (module.require) {
var STYLE_EXTENSIONS = ['.css'];
var VIEW_EXTENSIONS = ['.html'];
var COMPILERS = {
'.css': cssCompiler
, '.html': htmlCompiler
'.css': cssCompiler,
'.html': htmlCompiler
};
function cssCompiler(file, filename, options) {
return {css: file, files: [filename]};
Expand Down Expand Up @@ -121,7 +121,9 @@ AppForServer.prototype.bundle = function(backend, options, cb) {
cb = options;
options = null;
}
options || (options = {});
if (options == null) {
options = {};
}
if (options.minify == null) options.minify = util.isProduction;
// Turn all of the app's currently registered views into a javascript
// function that can recreate them in the client
Expand All @@ -136,7 +138,7 @@ AppForServer.prototype.bundle = function(backend, options, cb) {
if (filename !== viewsFilename) return through();
return through(
function write() {}
, function end() {
, function end() {
this.queue(viewsSource);
this.queue(null);
}
Expand Down Expand Up @@ -204,7 +206,9 @@ AppForServer.prototype.writeScripts = function(backend, dir, options, cb) {
fs.unlinkSync(oldFilename);
}
}
cb && cb();
if (cb) {
cb();
}
});
};

Expand All @@ -229,10 +233,10 @@ AppForServer.prototype.serialize = function() {
this.scriptMapUrl.slice(this.scriptMapBaseUrl.length) :
this.scriptMapUrl;
var serialized = JSON.stringify({
scriptBaseUrl: this.scriptBaseUrl
, scriptMapBaseUrl: this.scriptMapBaseUrl
, scriptUrl: scriptUrl
, scriptMapUrl: scriptMapUrl
scriptBaseUrl: this.scriptBaseUrl,
scriptMapBaseUrl: this.scriptMapBaseUrl,
scriptUrl: scriptUrl,
scriptMapUrl: scriptMapUrl
});
fs.writeFileSync(this.serializedBase + '.json', serialized, 'utf8');
};
Expand Down
2 changes: 1 addition & 1 deletion lib/Dom.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ Dom.prototype.addListener = function(type, target, listener, useCapture) {
}
var domListener =
(type === 'destroy') ? new DestroyListener(target, listener) :
new DomListener(type, target, listener, useCapture);
new DomListener(type, target, listener, useCapture);
if (-1 === this._listenerIndex(domListener)) {
var listeners = this._listeners || this._initListeners();
listeners.push(domListener);
Expand Down
4 changes: 3 additions & 1 deletion lib/Page.js
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,9 @@ Page.prototype.destroy = function() {
silentModel.destroy('_page');
silentModel.destroy('$components');
// Unfetch and unsubscribe from all queries and documents
silentModel.unloadAll && silentModel.unloadAll();
if (silentModel.unloadAll) {
silentModel.unloadAll();
}
};

Page.prototype._addModelListeners = function(eventModel) {
Expand Down
6 changes: 3 additions & 3 deletions lib/PageForServer.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,9 +96,9 @@ function stringifyBundle(bundle) {
// TODO: Cleanup; copied from tracks
function pageParams(req) {
var params = {
url: req.url
, body: req.body
, query: req.query
url: req.url,
body: req.body,
query: req.query,
};
for (var key in req.params) {
params[key] = req.params[key];
Expand Down
4 changes: 3 additions & 1 deletion lib/eventmodel.js
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,9 @@ EventModel.prototype._removeItemContext = function(context) {

EventModel.prototype._addBinding = function(binding) {
var bindings = this.bindings || (this.bindings = new BindingsMap());
binding.eventModels || (binding.eventModels = new EventModelsMap());
if (bindings.eventModel == null) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should actually be:

if (binding.eventModels == null) {

Issue was caught by internal tests when testing derby-2 branch. I'll try and write a more minimal test in the Derby tests.

binding.eventModels = new EventModelsMap();
}
bindings[binding.id] = binding;
binding.eventModels[this.id] = this;
};
Expand Down
4 changes: 3 additions & 1 deletion lib/files.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,9 @@ function loadViewsSync(app, sourceFilename, namespace) {
}

function loadStylesSync(app, sourceFilename, options) {
options || (options = {compress: util.isProduction});
if (options == null) {
options = { compress: util.isProduction };
}
var resolved = resolve.sync(sourceFilename, {
extensions: app.styleExtensions,
packageFilter: deleteMain}
Expand Down
8 changes: 6 additions & 2 deletions lib/textDiff.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@ function onStringInsert(el, previous, index, text) {
function transformCursor(cursor) {
return (index < cursor) ? cursor + text.length : cursor;
}
previous || (previous = '');
if (!previous) {
previous = '';
}
var newText = previous.slice(0, index) + text + previous.slice(index);
replaceText(el, newText, transformCursor);
}
Expand All @@ -15,7 +17,9 @@ function onStringRemove(el, previous, index, howMany) {
function transformCursor(cursor) {
return (index < cursor) ? cursor - Math.min(howMany, cursor - index) : cursor;
}
previous || (previous = '');
if (!previous) {
previous = '';
}
var newText = previous.slice(0, index) + previous.slice(index + howMany);
replaceText(el, newText, transformCursor);
}
Expand Down
6 changes: 4 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@
},
"main": "index.js",
"scripts": {
"test": "./node_modules/.bin/mocha test/all/*.mocha.js test/dom/*.mocha.js test/server/*.mocha.js; ./node_modules/.bin/jshint lib/*.js test/*.js test-utils/*.js",
"checks": "npm run lint && npm test",
"lint": "npx eslint *.js lib/**/*.js test/**/*.js test-utils/**/*.js",
"test": "npx mocha test/all/*.mocha.js test/dom/*.mocha.js test/server/*.mocha.js",
"test-browser": "node test/server.js"
},
"dependencies": {
Expand All @@ -27,9 +29,9 @@
"async": "^1.5.2",
"browserify": "^16.2.2",
"chai": "^4.2.0",
"eslint": "^8.24.0",
"express": "^4.13.3",
"jsdom": "^15.2.0",
"jshint": "^2.9.5",
"mocha": "^6.2.0"
},
"optionalDependencies": {},
Expand Down
2 changes: 1 addition & 1 deletion test-utils/assertions.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ module.exports = function(dom, Assertion) {
// NodeFilter.SHOW_COMMENT === 128
var treeWalker = domDocument.createTreeWalker(clone, 128, null, false);
var toRemove = [];
for (var item; item = treeWalker.nextNode();) {
for (var item = treeWalker.nextNode(); item != null; item = treeWalker.nextNode()) {
toRemove.push(item);
}
for (var i = toRemove.length; i--;) {
Expand Down
2 changes: 1 addition & 1 deletion test/dom/bindings.mocha.js
Original file line number Diff line number Diff line change
Expand Up @@ -417,7 +417,7 @@ describe('bindings', function() {

var page = app.createPage();
page.model.on('insert', '_data.items', function(index, values) {
if (values[0] == 'B') {
if (values[0] === 'B') {
page.model.insert('_data.items', 0, 'C');
}
});
Expand Down