Skip to content

Commit

Permalink
fix(standard): standard --fix
Browse files Browse the repository at this point in the history
  • Loading branch information
zkat committed Oct 26, 2018
1 parent 55a2007 commit 2dedbb8
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 28 deletions.
26 changes: 13 additions & 13 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,8 @@ class Duck extends Function {
gf = arg[fns[i]]
if (!gf ||
(gf.hasMethod
? !gf.hasMethod.apply(gf, args)
: typeof gf === 'function')) {
? !gf.hasMethod.apply(gf, args)
: typeof gf === 'function')) {
return false
}
}
Expand Down Expand Up @@ -81,7 +81,7 @@ Duck.prototype.isProtocol = true
const Protoduck = module.exports = define(['duck'], {
createGenfun: ['duck', _metaCreateGenfun],
addMethod: ['duck', _metaAddMethod]
}, {name: 'Protoduck'})
}, { name: 'Protoduck' })

const noImplFound = module.exports.noImplFound = genfun.noApplicableMethod

Expand Down Expand Up @@ -168,22 +168,22 @@ function defineMethod (duck, name, target, types, impls) {
if (!Object.prototype.hasOwnProperty.call(target, name)) {
// Make a genfun if there's nothing there
const gf = useMetaobject
? duck._metaobject.createGenfun(duck, target, name, null)
: _metaCreateGenfun(duck, target, name, null)
? duck._metaobject.createGenfun(duck, target, name, null)
: _metaCreateGenfun(duck, target, name, null)
target[name] = gf
} else if (typeof target[name] === 'function' && !target[name].isGenfun) {
// Turn non-gf functions into genfuns
const gf = useMetaobject
? duck._metaobject.createGenfun(duck, target, name, target[name])
: _metaCreateGenfun(duck, target, name, target[name])
? duck._metaobject.createGenfun(duck, target, name, target[name])
: _metaCreateGenfun(duck, target, name, target[name])
target[name] = gf
}

const fn = impls[name] || duck._defaultImpls[name]
if (fn) { // checkImpls made sure this is safe
useMetaobject
? duck._metaobject.addMethod(duck, target, name, methodTypes, fn)
: _metaAddMethod(duck, target, name, methodTypes, fn)
? duck._metaobject.addMethod(duck, target, name, methodTypes, fn)
: _metaAddMethod(duck, target, name, methodTypes, fn)
}
}

Expand Down Expand Up @@ -256,8 +256,8 @@ function installMethodErrorMessage (proto, gf, target, name) {
proto.name ? `${proto.name}#` : ''
}${name}(${[].map.call(args, typeName).join(', ')}). You must implement ${
proto.name
? formatMethod(proto, name, true)
: `the protocol ${formatMethod(proto, name)} belongs to`
? formatMethod(proto, name, true)
: `the protocol ${formatMethod(proto, name)} belongs to`
} in order to call ${typeName(thisArg)}#${name}(${
[].map.call(args, typeName).join(', ')
}).`
Expand Down Expand Up @@ -330,8 +330,8 @@ class Constraint {
const thisType = (
this.thisIdx === 'this' || this.thisIdx == null
)
? target
: types[this.thisIdx]
? target
: types[this.thisIdx]
const parentTypes = this.indices.map(idx => {
if (idx === 'this') {
return target
Expand Down
6 changes: 3 additions & 3 deletions test/constraints.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ const duck = require('..')
test('basic constraint definitions', t => {
const Functor = duck.define(['f'], {
map: ['f']
}, {name: 'Functor'})
}, { name: 'Functor' })

const Apply = duck.define(['b'], {
ap: ['b']
Expand Down Expand Up @@ -55,7 +55,7 @@ test('basic constraint definitions', t => {
test('`this` as type identifier', t => {
const Foo = duck.define(['a'], {
frob: ['a']
}, {name: 'Foo'})
}, { name: 'Foo' })
const Bar = duck.define(['b'], {
frab: ['b']
}, {
Expand Down Expand Up @@ -94,7 +94,7 @@ test('`this` as type identifier', t => {
test('shorthand constraints', t => {
const Functor = duck.define(['f'], {
map: ['f']
}, {name: 'Functor'})
}, { name: 'Functor' })
const Apply = duck.define(['f'], {
ap: ['f']
}, {
Expand Down
12 changes: 6 additions & 6 deletions test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,13 @@ test('derivation', t => {
const Show = duck.define(['exemplar'], {
show: ['exemplar'],
meh: [function () {}]
}, {name: 'Show'})
}, { name: 'Show' })
t.notOk(Show.isDerivable, 'disallows derivation if any fns have no defaults')
t.throws(() => {
Show.impl(obj, [obj])
}, /Missing implementation for Show#show\(exemplar\)/)

const withShow = {show () { return 'success' }}
const withShow = { show () { return 'success' } }
Show.impl(withShow)
t.equal(withShow.show(), 'success', 'default method used')
t.ok(withShow.show.isGenfun, 'method converted to genfun')
Expand All @@ -55,7 +55,7 @@ test('derivation', t => {
test('defines implementations for protocol functions', t => {
const Eq = duck.define(['a'], {
eq: ['a']
}, {name: 'Eq'})
}, { name: 'Eq' })
class Obj {}
Eq.impl(Obj, [Obj], {
eq (a) { return this === a }
Expand Down Expand Up @@ -83,7 +83,7 @@ test('errors if too many types specified', t => {
test('treats missing types in impls as Object', t => {
const Foo = duck.define(['a', 'b'], {
frob: ['a', 'b']
}, {name: 'Foo'})
}, { name: 'Foo' })
Foo.impl(Number, [Number], {
frob (n, anything) {
return this + n + anything
Expand All @@ -98,15 +98,15 @@ test('treats missing types in impls as Object', t => {
})

test('errors if an extra function is implemented', t => {
const Eq = duck.define(['a'], { eq: ['a'] }, {name: 'Eq'})
const Eq = duck.define(['a'], { eq: ['a'] }, { name: 'Eq' })
t.throws(() => {
Eq.impl(Number, [Number], { eq () {}, extra () {} })
}, /extra\(\) was included in the impl, but is not part of Eq/i)
t.done()
})

test('errors if a function without a default is not implemented', t => {
const Eq = duck.define(['a'], { eq: ['a'] }, {name: 'Eq'})
const Eq = duck.define(['a'], { eq: ['a'] }, { name: 'Eq' })
const obj = {}
t.throws(function () {
Eq.impl(obj, [obj], { })
Expand Down
12 changes: 6 additions & 6 deletions test/mop.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ test('MOP: createGenfun', t => {
})
const Show = duck.define({
show: []
}, {metaobject})
}, { metaobject })
const obj = {}
Show.impl(obj, {show () { return 'ok' }})
Show.impl(obj, { show () { return 'ok' } })
t.equal(obj.show(), 'ok', 'method defined correctly')
t.deepEqual(obj.show.duck, null, 'no duck property')
t.equal(obj.show.metaProp, 'hello', 'extra prop added to gf')
Expand All @@ -36,9 +36,9 @@ test('MOP: addMethod', t => {
})
const Show = duck.define({
show: []
}, {metaobject})
}, { metaobject })
const obj = {}
Show.impl(obj, {show () { return 'ok' }})
Show.impl(obj, { show () { return 'ok' } })
t.equal(obj.show(), 'ok', 'method defined correctly')
})

Expand All @@ -54,9 +54,9 @@ test('MOP: Protoduck as metaobject', t => {
})
const Show = duck.define({
show: []
}, {metaobject})
}, { metaobject })
const obj = {}
Show.impl(obj, {show () { return 'ok' }})
Show.impl(obj, { show () { return 'ok' } })
t.equal(obj.show(), 'ok', 'method defined correctly')
t.equal(obj.show.duck, Show, 'duck property is there')
t.ok(true, 'none of the declared methods executed when meta === Protoduck')
Expand Down

0 comments on commit 2dedbb8

Please sign in to comment.