Skip to content

Commit

Permalink
Update our eslint rules (#329)
Browse files Browse the repository at this point in the history
And fix a lot of spacing
  • Loading branch information
gcampax committed Sep 25, 2020
1 parent 1bd1489 commit c99e65b
Show file tree
Hide file tree
Showing 40 changed files with 184 additions and 137 deletions.
82 changes: 64 additions & 18 deletions .eslintrc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,28 +5,31 @@ parserOptions:
ecmaVersion: 2018
extends: 'eslint:recommended'
rules:
# disable some rules we don't want
indent: off
no-console: off
no-fallthrough: off
linebreak-style:
- error
- unix
semi:
- error
- always
consistent-return: warn
curly:
require-atomic-updates: off
no-lonely-if: off
arrow-body-style: off

# correctness checks
strict:
- error
- multi-or-nest
- consistent
- global
consistent-return: error
array-callback-return: error
eqeqeq:
- error
- always
no-var: error
no-unused-vars:
- error
-
varsIgnorePattern: _
args: none
no-shadow-restricted-names: error
no-promise-executor-return: error
no-case-declarations: warn
no-eval: error
no-proto: error
Expand All @@ -36,17 +39,60 @@ rules:
no-useless-call: warn
no-useless-return: warn
no-void: error
no-self-compare: error
prefer-promise-reject-errors: error
strict:
- error
- global
no-label-var: error
no-lonely-if: off
no-new-object: error
arrow-body-style: off
no-invalid-this: error
prefer-arrow-callback: warn
prefer-numeric-literals: error
no-constructor-return: error
no-new-wrappers: error
no-return-await: warn
no-unused-expressions: warn

# code style
linebreak-style:
- error
- unix
semi:
- error
- always
curly:
- error
- multi-or-nest
- consistent
dot-location:
- error
- property
arrow-parens:
- error
- always
prefer-arrow-callback: warn
prefer-numeric-literals: error
require-atomic-updates: off
block-spacing: error
computed-property-spacing: error
func-call-spacing: error
keyword-spacing:
- error
-
overrides:
catch:
before: true
after: false
space-before-function-paren:
- error
-
anonymous: never
named: never
asyncArrow: always
generator-star-spacing:
- error
-
anonymous:
before: false
after: false
named:
before: false
after: true
method:
before: false
after: false
8 changes: 4 additions & 4 deletions languages/thingtalk/ast_manip.js
Original file line number Diff line number Diff line change
Expand Up @@ -320,12 +320,12 @@ function addUnit(unit, num) {
}

function resolveProjection(args, schema) {
assert (args.length >= 1);
assert(args.length >= 1);
args = new Set(args);
for (let arg of schema.minimal_projection)
args.add(arg);
for (let arg of args)
assert (schema.hasArgument(arg));
assert(schema.hasArgument(arg));
// if default_projection is non-empty, it's overwritten after a projection
schema.default_projection = [];
if (schema.annotations)
Expand Down Expand Up @@ -734,7 +734,7 @@ function checkFilter(table, filter) {
throw new Error(`Unexpected filter type ${filter}`);
}

function *iterateFilters(table) {
function* iterateFilters(table) {
if (table.isInvocation || table.isVarRef || table.isResultRef)
return;

Expand All @@ -748,7 +748,7 @@ function *iterateFilters(table) {
}
}

function *iterateFields(filter) {
function* iterateFields(filter) {
assert(filter instanceof Ast.BooleanExpression);
if (filter.isAnd) {
for (let operand of filter.operands)
Expand Down
12 changes: 6 additions & 6 deletions languages/thingtalk/dialogue_acts/initial-request.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,8 @@ function adjustStatementsForInitialRequest(stmt) {

assert(stmt.actions.length === 1);
const action = stmt.actions[0];
assert (action.isInvocation);
assert (action.invocation.selector.isDevice);
assert(action.isInvocation);
assert(action.invocation.selector.isDevice);
const confirm = C.normalizeConfirmAnnotation(action.invocation.schema);

// if confirm === auto, we leave the compound command as is, but add the [1] clause
Expand Down Expand Up @@ -102,8 +102,8 @@ function adjustStatementsForInitialRequest(stmt) {

assert(stmt.actions.length === 1);
const action = stmt.actions[0];
assert (action.isInvocation);
assert (action.invocation.selector.isDevice);
assert(action.isInvocation);
assert(action.invocation.selector.isDevice);

// for "confirm=auto", the query is added to a compound command
// and for "confirm=display_result", the query is added as a separate statement
Expand Down Expand Up @@ -148,11 +148,11 @@ function adjustStatementsForInitialRequest(stmt) {
const type = clone.invocation.schema.getArgType(param.name);
if (!type.isEntity || !_loader.idQueries.has(type.type))
continue;
assert (param.value.isUndefined);
assert(param.value.isUndefined);

// this assertion will fire if there are two entity parameters of
// ID type in the same action
assert (newTable === undefined);
assert(newTable === undefined);

const query = _loader.idQueries.get(type.type);
newTable = new Ast.Table.Invocation(null,
Expand Down
2 changes: 1 addition & 1 deletion languages/thingtalk/dialogue_acts/recommendation.js
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ function combineDisplayResult(proposal, newInfo) {
const results = ctx.results;
assert(results.length > 0);
const topResult = results[0];
assert (isInfoPhraseCompatibleWithResult(topResult, newInfo));
assert(isInfoPhraseCompatibleWithResult(topResult, newInfo));

newInfo = SlotBag.merge(oldInfo, newInfo);
if (newInfo === null)
Expand Down
2 changes: 1 addition & 1 deletion languages/thingtalk/load-thingpedia.js
Original file line number Diff line number Diff line change
Expand Up @@ -1072,7 +1072,7 @@ class ThingpediaLoader {
}

async _getDataset(kind) {
return await this._tpClient.getExamplesByKinds([kind]);
return this._tpClient.getExamplesByKinds([kind]);
}

async _loadMetadata() {
Expand Down
2 changes: 1 addition & 1 deletion lib/dataset-tools/augmentation/replace_parameters.js
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ class ValueListLoader {
}
}

function *resampleIgnorableAndAbbreviations(langPack, ptype, sentence, rng) {
function* resampleIgnorableAndAbbreviations(langPack, ptype, sentence, rng) {
if (!ptype.isEntity) {
yield *sentence;
return;
Expand Down
2 changes: 1 addition & 1 deletion lib/dialogue-agent/dialogue_policy.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ const TARGET_PRUNING_SIZES = [25, 50, 100];
function arrayEqual(a, b) {
if (a.length !== b.length)
return false;
for (var i = 0; i < a.length; i++) {
for (let i = 0; i < a.length; i++) {
if (a[i] !== b[i])
return false;
}
Expand Down
14 changes: 7 additions & 7 deletions lib/dialogue-agent/entity-linking/contact_search.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ const SCORING_MODEL = {
};

function dotProduct(a, b) {
var score = 0;
for (var name in b)
let score = 0;
for (let name in b)
score += (a[name] || 0) * (b[name] || 0);
return score;
}
Expand Down Expand Up @@ -73,12 +73,12 @@ class SimpleClassifier {
}

scoreAll(examples) {
var scores = new Array(examples.length);
let scores = new Array(examples.length);
examples.forEach(function(ex, i) {
scores[i] = this.score(ex);
}, this);
var probs = expNormalize(scores);
var mapped = examples.map((ex, i) => {
let probs = expNormalize(scores);
let mapped = examples.map((ex, i) => {
return {
ex: ex,
score: scores[i],
Expand Down Expand Up @@ -149,7 +149,7 @@ function makeValue(dlg, category, choice) {
return new Ast.Value.Entity(choice.value, 'tt:contact', choice.displayName);
}

module.exports.contactSearch = async function (dlg, type, name) {
module.exports.contactSearch = async function(dlg, type, name) {
if (!type.isEntity)
throw new TypeError('Invalid contact type ' + type);
let category;
Expand Down Expand Up @@ -197,7 +197,7 @@ module.exports.contactSearch = async function (dlg, type, name) {
choice = top;
} else {
fallbacks = [];
for (var candidate of scored) {
for (let candidate of scored) {
if (candidate.prob < 0.15 || candidate.score < -10)
break;
fallbacks.push(candidate.ex);
Expand Down
2 changes: 1 addition & 1 deletion lib/dialogue-agent/entity-linking/entity-finder.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ const editDistance = require('../../utils/edit-distance');

// FIXME use the actual tokenizer
function tokenize(string) {
var tokens = string.split(/(\s+|[,."'!?])/g);
let tokens = string.split(/(\s+|[,."'!?])/g);
return tokens.filter((t) => !(/^\s*$/).test(t)).map((t) => t.toLowerCase());
}

Expand Down
2 changes: 1 addition & 1 deletion lib/dialogue-agent/value-category.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ ValueCategory.fromValue = function fromValue(value) {
if (value.isVarRef)
return ValueCategory.Unknown;

var type = value.getType();
let type = value.getType();
return ValueCategory.fromType(type);
};

Expand Down
10 changes: 5 additions & 5 deletions lib/engine/apps/database.js
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ class AppDatabase extends events.EventEmitter {

// run the rest of app loading asynchronously
this._doStartApp(app, isNewApp);
} catch (e) {
} catch(e) {
console.error('Failed to add app: ' + e);
app.reportError(e);
this._removeAppInternal(app.uniqueId);
Expand All @@ -129,14 +129,14 @@ class AppDatabase extends events.EventEmitter {
}

async _removeAppInternal(uniqueId) {
var app = this._apps[uniqueId];
let app = this._apps[uniqueId];
delete this._apps[uniqueId];

if (app !== undefined) {
this.emit('app-removed', app);
try {
await app.destroy();
} catch (e) {
} catch(e) {
console.error('Failed to destroy app ' + uniqueId + ': ' + e.message);
}
}
Expand Down Expand Up @@ -176,8 +176,8 @@ class AppDatabase extends events.EventEmitter {
}

getAllApps() {
var apps = [];
for (var id in this._apps)
let apps = [];
for (let id in this._apps)
apps.push(this._apps[id]);
return apps;
}
Expand Down
4 changes: 2 additions & 2 deletions lib/engine/apps/runner.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,12 @@ module.exports = class AppRunner {
}

_startAllApps() {
var apps = this._db.getAllApps();
let apps = this._db.getAllApps();
return Promise.all(apps.map(this._startOneApp, this));
}

_stopAllApps() {
var apps = this._db.getAllApps();
let apps = this._db.getAllApps();
return Promise.all(apps.map(this._stopOneApp, this));
}

Expand Down
4 changes: 2 additions & 2 deletions lib/engine/apps/timers.js
Original file line number Diff line number Diff line change
Expand Up @@ -252,15 +252,15 @@ class AtTimer extends BaseTimer {
}

_nextTimeout() {
var now = new Date;
let now = new Date;

if (this._expiration_date !== null && this._expiration_date < now) {
console.log('AtTimer to the times ' + this._times + ': has hit expiration date of ' + this._expiration_date);
this.end();
return 86400000;
}

var interval = 86400000; // Tomorrow
let interval = 86400000; // Tomorrow
for (let i = 0; i < this._times.length; i++) {
let target = new Date(now.getFullYear(), now.getMonth(), now.getDate(),
this._times[i].hour, this._times[i].minute, this._times[i].second, 0);
Expand Down
8 changes: 4 additions & 4 deletions lib/engine/apps/trigger_runner.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,17 +46,17 @@ module.exports = class MonitorRunner {
// rate limit to 1 per second, with a burst of 300
this._rateLimiter = new RateLimiter(300, 300 * 1000);

var self = this;
let self = this;
this._dataListener = function(data) {
var from = this;
let from = this;
self._onTriggerData(from, data);
};
this._endListener = function() {
var from = this;
let from = this;
self._onTriggerEnd(from);
};
this._errorListener = function(error) {
var from = this;
let from = this;
self._onTriggerError(from, error);
};

Expand Down
Loading

0 comments on commit c99e65b

Please sign in to comment.