Skip to content

Commit

Permalink
style: Set up eslint and fix (#16)
Browse files Browse the repository at this point in the history
All autofixes except for strict mode, added manually.
  • Loading branch information
paulmelnikow authored and RichardLitt committed Apr 12, 2019
1 parent 8639a87 commit d4f4768
Show file tree
Hide file tree
Showing 6 changed files with 836 additions and 28 deletions.
2 changes: 2 additions & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
/coverage
/node_modules
35 changes: 35 additions & 0 deletions .eslintrc.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
env:
node: true

parserOptions:
ecmaVersion: 9
# Override eslint-config-standard, which incorrectly sets this to "module",
# though that setting is only for ES6 modules, not CommonJS modules.
sourceType: 'script'

extends:
- 'eslint:recommended'
- standard
- prettier

rules:
# Override some recommended rules.
no-unused-vars: ['error', { 'args': 'none' }]
no-empty: ['error', { 'allowEmptyCatch': true }]

# Nock additions.
strict: ['error', 'safe']
no-loop-func: 'error'
no-var: 'error'
prefer-const: 'error'
object-shorthand: ['error', 'properties']
prefer-template: 'error'
arrow-body-style: ['error', 'as-needed']
prefer-destructuring:
[
'error',
{
'VariableDeclarator': { 'array': false, 'object': true },
'AssignmentExpression': { 'array': false, 'object': false },
},
]
18 changes: 10 additions & 8 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
'use strict'

function propagate(events, source, dest) {
if (arguments.length < 3) {
dest = source
Expand All @@ -6,14 +8,14 @@ function propagate(events, source, dest) {
}

// events should be an array or object
var eventsIsObject = typeof events === 'object'
const eventsIsObject = typeof events === 'object'
if (events && !eventsIsObject) events = [events]

if (eventsIsObject) {
return explicitPropagate(events, source, dest)
}

var oldEmit = source.emit
const oldEmit = source.emit

source.emit = function(eventType) {
oldEmit.apply(source, arguments)
Expand All @@ -28,15 +30,15 @@ function propagate(events, source, dest) {
}

return {
end: end,
end,
}
}

module.exports = propagate

function explicitPropagate(events, source, dest) {
var eventsIn
var eventsOut
let eventsIn
let eventsOut
if (Array.isArray(events)) {
eventsIn = events
eventsOut = events
Expand All @@ -47,9 +49,9 @@ function explicitPropagate(events, source, dest) {
})
}

var listeners = eventsOut.map(function(event) {
const listeners = eventsOut.map(function(event) {
return function() {
var args = Array.prototype.slice.call(arguments)
const args = Array.prototype.slice.call(arguments)
args.unshift(event)
dest.emit.apply(dest, args)
}
Expand All @@ -58,7 +60,7 @@ function explicitPropagate(events, source, dest) {
listeners.forEach(register)

return {
end: end,
end,
}

function register(listener, i) {
Expand Down
Loading

0 comments on commit d4f4768

Please sign in to comment.