Skip to content
This repository was archived by the owner on Nov 22, 2022. It is now read-only.

Commit a0fec35

Browse files
Revise linting and incorporate linter feedback
1 parent a5404fc commit a0fec35

File tree

12 files changed

+42
-36
lines changed

12 files changed

+42
-36
lines changed

packages/library/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838
"eslint": "^4.2.0",
3939
"eslint-config-airbnb": "^15.0.0",
4040
"eslint-plugin-import": "^2.6.0",
41-
"eslint-plugin-jsx-a11y": "^6.0.0",
41+
"eslint-plugin-jsx-a11y": "^5.1.1",
4242
"eslint-plugin-react": "^7.1.0",
4343
"karma": "^1.7.0",
4444
"karma-chai": "^0.1.0",
@@ -65,6 +65,7 @@
6565
"no-console": 0,
6666
"no-else-return": 1,
6767
"no-param-reassign": 1,
68+
"no-warning-comments": ["error", { "terms": [ "fixme", "xxx" ] }],
6869
"prefer-rest-params": 1,
6970
"radix": [2, "as-needed"],
7071
"react/no-multi-comp": 0,

packages/library/src/core.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
import { extend, cloneDeep } from 'lodash'
2+
import Proxy from 'es2015-proxy'
3+
24
import { EventHandler } from './util/eventAPI'
35
import { DomConnection } from './util/domEvents'
46
import { Random } from './util/random'
57
import { parseOption, parseAllOptions } from './util/options'
68
import { preloadImage, preloadAudio } from './util/preload'
7-
import Proxy from 'es2015-proxy'
89

910
// Define status codes
1011
export const status = Object.freeze({
@@ -166,7 +167,7 @@ export class Component extends EventHandler {
166167

167168
// Collect options 'handed down' from higher-level components
168169
if (this.parent) {
169-
const foo = this.parents.reduce(
170+
this.parents.reduce(
170171
// Accumulate handed down options from parents
171172
(acc, cur) => {
172173
cur.options.handMeDowns.forEach(o => acc.add(o))
@@ -175,7 +176,7 @@ export class Component extends EventHandler {
175176
new Set(),
176177
).forEach(
177178
// 'inherit' the option from the parent component
178-
o => (this.options[o] = this.options[o] || this.parent.options[o])
179+
o => (this.options[o] = this.options[o] || this.parent.options[o]),
179180
)
180181
}
181182

packages/library/src/data.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ const escapeCsvCell = (c) => {
3434
return c
3535
}
3636

37+
// eslint-disable-next-line import/prefer-default-export
3738
export class Store extends EventHandler {
3839
constructor(options={}) {
3940
// Construct the underlying EventHandler
@@ -288,7 +289,7 @@ export class Store extends EventHandler {
288289
return fetch(url, {
289290
method: 'post',
290291
headers: {
291-
'Accept': 'application/json',
292+
'Accept': 'application/json', // eslint-disable-line quote-props
292293
'Content-Type': 'application/json',
293294
},
294295
body: JSON.stringify({

packages/library/src/flow.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ export class Sequence extends Component {
5959

6060
async onRun() {
6161
// Make the first step
62-
return await this.step()
62+
return this.step()
6363
}
6464

6565
onEnd() {
@@ -81,12 +81,12 @@ export class Sequence extends Component {
8181
// Move through the content
8282
const next = this.internals.iterator.next()
8383
if (next.done) {
84-
return await this.end('completion')
84+
return this.end('completion')
8585
} else {
8686
[this.internals.currentPosition, this.internals.currentComponent] = next.value
8787
this.internals.currentComponent.on('after:end', this.internals.stepper)
8888
this.triggerMethod('step')
89-
return await this.internals.currentComponent.run()
89+
return this.internals.currentComponent.run()
9090
}
9191
}
9292

packages/library/src/html.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ export class Form extends Screen {
6868
if (e.target.getAttribute('form')) {
6969
// ... find it and ...
7070
const targetForm = this.options.el.querySelector(
71-
`form#${ e.target.getAttribute('form') }`
71+
`form#${ e.target.getAttribute('form') }`,
7272
)
7373

7474
// ... submit that form instead

packages/library/src/index.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// Components
22
import { Component, Dummy } from './core'
33
import { Screen as CanvasScreen, Sequence as CanvasSequence,
4-
Frame as CanvasFrame } from './canvas'
4+
Frame as CanvasFrame } from './canvas'
55
import { Screen, Form, Frame } from './html'
66
import { Sequence, Parallel, Loop } from './flow'
77

@@ -63,6 +63,6 @@ export const util = {
6363
launch, exit,
6464
},
6565
tree: {
66-
traverse, reduce
66+
traverse, reduce,
6767
},
6868
}

packages/library/src/plugins/metadata.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,10 @@ const getMetadata = () => {
1919
}
2020

2121
export default class Metadata {
22+
// TODO: The linter thinks it is not worth to use
23+
// a class here. Possibly the plugin could accept
24+
// additional data to include?
25+
// eslint-disable-next-line class-methods-use-this
2226
handle(context, event) {
2327
if (event === 'prepare') {
2428
// If a datastore is available, save the metadata

packages/library/src/util/domEvents.js

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,7 @@ const wrapHandler = function(handler, eventName, options=null, context=null) {
127127
}
128128
}
129129

130+
// eslint-disable-next-line import/prefer-default-export
130131
export class DomConnection {
131132
constructor(options) {
132133
// Limit search for elements to a
@@ -168,11 +169,8 @@ export class DomConnection {
168169
// If the event is constrainted to a certain element
169170
// or a set of elements, search for these within the
170171
// specified element, and add the handler to each
171-
for (const child of Array.from(this.el.querySelectorAll(selector))) {
172-
child.addEventListener(
173-
eventName, handler,
174-
)
175-
}
172+
Array.from(this.el.querySelectorAll(selector))
173+
.forEach(child => child.addEventListener(eventName, handler))
176174
} else {
177175
// If no selector is supplied, the listener is
178176
// added to the document itself
@@ -198,11 +196,8 @@ export class DomConnection {
198196

199197
if (selector !== '') {
200198
// Remove listener from specified elements
201-
for (const child of Array.from(this.el.querySelectorAll(selector))) {
202-
child.removeEventListener(
203-
eventName, handler,
204-
)
205-
}
199+
Array.from(this.el.querySelectorAll(selector))
200+
.forEach(child => child.removeEventListener(eventName, handler))
206201
} else {
207202
// Remove global listeners
208203
document.removeEventListener(

packages/library/src/util/fromObject.js

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,11 @@ import { isObject } from 'lodash'
22

33
// Retrieve an entry from a nested object
44
// hierarchy, given a path
5-
const retrieveNested = (path, object) => {
6-
let current = object
7-
for (const level of path) {
8-
current = current[level]
9-
}
10-
return current
11-
}
5+
const retrieveNested = (path, object) =>
6+
path.reduce(
7+
(subobject, subpath) => subobject[subpath],
8+
object,
9+
)
1210

1311
// Construct a component given only an
1412
// object that specifies the options

packages/library/src/util/options.js

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { entries, extend, template } from 'lodash'
1+
import { extend, template } from 'lodash'
22

33
// TODO: Does this work in shorthand notation? () => {}
44
const parsableOptions = function parsableOptions() {
@@ -77,13 +77,17 @@ export const parseAllOptions = function(options, context) {
7777
// Parse all of the options that are
7878
// marked as parsable, and save them to output
7979
// if the option has actually changed
80-
for (const [key, metadata] of entries(optionsMetadata)) {
81-
const candidate = parseOption.call(this, key, options[key], context, metadata)
80+
Object.entries(optionsMetadata).forEach(([key, metadata]) => {
81+
const candidate = parseOption.call(
82+
this,
83+
key, options[key],
84+
context, metadata,
85+
)
8286

8387
if (candidate) {
8488
output[key] = candidate
8589
}
86-
}
90+
})
8791

8892
return output
8993
}

0 commit comments

Comments
 (0)