Skip to content

Commit 3c9deda

Browse files
committed
add better linting options and cleanup the code a bit
1 parent 545a009 commit 3c9deda

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+58
-87
lines changed

.jshintrc

+11-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,15 @@
11
{
22
"asi": true,
3+
"curly": true,
4+
"eqeqeq": true,
35
"esversion": 6,
4-
"laxbreak": true
6+
"freeze": true,
7+
"funcscope": true,
8+
"globals": {
9+
"require": true,
10+
"module": true
11+
},
12+
"laxbreak": true,
13+
"undef": true,
14+
"unused": true
515
}

combinators/constant.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,6 @@ const curry = require('../helpers/curry')
55

66
// Constant (Kestrel)
77
// constant :: a -> b -> a
8-
const constant = x => _ => x
8+
const constant = x => () => x
99

1010
module.exports = curry(constant)

combinators/substitution.spec.js

-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
const test = require('tape')
2-
const sinon = require('sinon')
32
const helpers = require('../test/helpers')
43

54
const bindFunc = helpers.bindFunc

crocks/Async.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ const _of =
2929
x => Async((_, resolve) => resolve(x))
3030

3131
const Rejected =
32-
x => Async((reject, _) => reject(x))
32+
x => Async((reject) => reject(x))
3333

3434
function all(asyncs) {
3535
if(!(isFoldable(asyncs) && allAsyncs(asyncs))) {
@@ -163,7 +163,7 @@ function Async(fn) {
163163

164164
return Async((rej, res) => {
165165
fork(
166-
_ => m.fork(rej, res),
166+
() => m.fork(rej, res),
167167
res
168168
)
169169
})

crocks/Async.spec.js

+17-15
Original file line numberDiff line numberDiff line change
@@ -76,13 +76,13 @@ test('Async Resolved', t => {
7676
})
7777

7878
test('Async fromPromise', t => {
79-
const resProm = x => new Promise((res, _) => res(x))
79+
const resProm = x => new Promise((res) => res(x))
8080

8181
t.ok(isFunction(Async.fromPromise), 'is a function')
8282
t.ok(isFunction(Async.fromPromise(resProm)), 'returns a function')
8383

8484
const fn = bindFunc(Async.fromPromise)
85-
const fork = bindFunc(x => Async.fromPromise(_ => x)().fork(noop, noop))
85+
const fork = bindFunc(x => Async.fromPromise(() => x)().fork(noop, noop))
8686

8787
t.throws(fn(undefined), TypeError, 'throws with undefined')
8888
t.throws(fn(null), TypeError, 'throws with null')
@@ -116,7 +116,7 @@ test('Async fromPromise resolution', t => {
116116
const val = 'super fun'
117117

118118
const rejProm = x => new Promise((_, rej) => rej(x))
119-
const resProm = x => new Promise((res, _) => res(x))
119+
const resProm = x => new Promise((res) => res(x))
120120

121121
const rej = y => x => t.equal(x, y, 'rejects a rejected Promise')
122122
const res = y => x => t.equal(x, y, 'resolves a resolved Promise')
@@ -228,7 +228,7 @@ test('Async type', t => {
228228

229229
test('Async fork', t => {
230230
const resolved = Async((_, res) => res('resolved'))
231-
const rejected = Async((rej, _) => rej('rejected'))
231+
const rejected = Async((rej) => rej('rejected'))
232232

233233
const res = sinon.spy(identity)
234234
const rej = sinon.spy(identity)
@@ -305,7 +305,7 @@ test('Async swap', t => {
305305
t.throws(fn(noop, {}), TypeError, 'throws with object in right')
306306
t.throws(fn(noop, []), TypeError, 'throws with array in right')
307307

308-
const rejected = Async((rej, _) => rej('silly')).swap(constant('was rejected'), identity)
308+
const rejected = Async((rej) => rej('silly')).swap(constant('was rejected'), identity)
309309
const resolved = Async((_, res) => res('silly')).swap(identity, constant('was resolved'))
310310

311311
const rej = sinon.spy()
@@ -346,7 +346,7 @@ test('Async coalesce', t => {
346346
t.throws(fn(noop, {}), TypeError, 'throws with object in right')
347347
t.throws(fn(noop, []), TypeError, 'throws with array in right')
348348

349-
const rejected = Async((rej, _) => rej()).coalesce(constant('was rejected'), identity)
349+
const rejected = Async((rej) => rej()).coalesce(constant('was rejected'), identity)
350350
const resolved = Async((_, res) => res()).coalesce(identity, constant('was resolved'))
351351

352352
const rej = sinon.spy()
@@ -384,8 +384,8 @@ test('Async map errors', t => {
384384
test('Async map functionality', t => {
385385
const mapFn = sinon.spy()
386386

387-
const rejected = Async((rej, _) => rej('rejected')).map(mapFn).fork(noop, noop)
388-
const resolved = Async((_, res) => res('resolved')).map(mapFn).fork(noop, noop)
387+
Async((rej) => rej('rejected')).map(mapFn).fork(noop, noop)
388+
Async((_, res) => res('resolved')).map(mapFn).fork(noop, noop)
389389

390390
t.equal(Async(noop).map(noop).type(), 'Async', 'returns an Async')
391391
t.ok(mapFn.calledWith('resolved'), 'calls map function on resolved')
@@ -455,7 +455,7 @@ test('Async bimap functionality', t => {
455455
const rej = sinon.spy()
456456
const res = sinon.spy()
457457

458-
Async((rej, _) => rej('rejected')).bimap(left, right).fork(rej, res)
458+
Async((rej) => rej('rejected')).bimap(left, right).fork(rej, res)
459459
Async((_, res) => res('resolved')).bimap(left, right).fork(rej, res)
460460

461461
t.equal(Async(noop).bimap(noop, noop).type(), 'Async', 'returns an Async')
@@ -714,8 +714,10 @@ test('Async chain properties (Chain)', t => {
714714
const f = x => Async((_, res) => res(x + 2))
715715
const g = x => Async((_, res) => res(x + 10))
716716

717-
const a = x => Async((_, res) => res(x)).chain(f).chain(g).fork(noop, aRes)
718-
const b = x => Async((_, res) => res(x)).chain(y => f(y).chain(g)).fork(noop, bRes)
717+
const x = 12
718+
719+
Async((_, res) => res(x)).chain(f).chain(g).fork(noop, aRes)
720+
Async((_, res) => res(x)).chain(y => f(y).chain(g)).fork(noop, bRes)
719721

720722
t.same(aRes.args[0], bRes.args[0], 'assosiativity')
721723

@@ -728,16 +730,16 @@ test('Async chain properties (Monad)', t => {
728730

729731
const f = x => Async((_, res) => res(x))
730732

731-
aLeft = sinon.spy()
732-
bLeft = sinon.spy()
733+
const aLeft = sinon.spy()
734+
const bLeft = sinon.spy()
733735

734736
Async.of(3).chain(f).fork(noop, aLeft)
735737
f(3).fork(noop, bLeft)
736738

737739
t.same(aLeft.args[0], bLeft.args[0], 'left identity')
738740

739-
aRight = sinon.spy()
740-
bRight = sinon.spy()
741+
const aRight = sinon.spy()
742+
const bRight = sinon.spy()
741743

742744
f(3).chain(Async.of).fork(noop, aRight)
743745
f(3).fork(noop, bRight)

crocks/Either.spec.js

-1
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,6 @@ test('Either concat errors', t => {
179179
const m = { type: () => 'Either...Not' }
180180

181181
const good = Either.Right([])
182-
const bad = Either.Left([])
183182

184183
const f = bindFunc(Either.Right([]).concat)
185184
const nonEitherErr = /Either.concat: Either of Semigroup required/

crocks/IO.spec.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -212,8 +212,8 @@ test('IO chain properties (Chain)', t => {
212212
t.ok(isFunction(IO(noop).chain), 'provides a chain function')
213213
t.ok(isFunction(IO(noop).ap), 'implements the Apply spec')
214214

215-
const f = x => IO(_ => x + 2)
216-
const g = x => IO(_ => x + 10)
215+
const f = x => IO(() => x + 2)
216+
const g = x => IO(() => x + 10)
217217

218218
const a = x => IO(constant(x)).chain(f).chain(g)
219219
const b = x => IO(constant(x)).chain(y => f(y).chain(g))

crocks/Identity.js

-2
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,7 @@ const isSameType = require('../predicates/isSameType')
88
const _inspect = require('../internal/inspect')
99
const innerConcat = require('../internal/innerConcat')
1010

11-
const composeB = require('../combinators/composeB')
1211
const constant = require('../combinators/constant')
13-
const identity = require('../combinators/identity')
1412

1513
const _type =
1614
constant('Identity')

crocks/List.spec.js

-3
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ const Pred = require('./Pred')
2020
const List = require('./List')
2121

2222
test('List', t => {
23-
const m = bindFunc(List)
2423
const f = x => List(x).toArray()
2524

2625
t.ok(isFunction(List), 'is a function')
@@ -505,8 +504,6 @@ test('List chain errors', t => {
505504
const chain = bindFunc(List([ 0 ]).chain)
506505
const bad = bindFunc(x => List.of(x).chain(identity))
507506

508-
const f = x => List.of(x)
509-
510507
const noFunc = /List.chain: Function required/
511508
t.throws(chain(undefined), noFunc, 'throws with undefined')
512509
t.throws(chain(null), noFunc, 'throws with null')

crocks/Maybe.spec.js

-3
Original file line numberDiff line numberDiff line change
@@ -463,9 +463,7 @@ test('Maybe of', t => {
463463

464464
test('Maybe of properties (Applicative)', t => {
465465
const m = Maybe.Just(identity)
466-
467466
const j = Maybe.Just(3)
468-
const n = Maybe.Nothing()
469467

470468
t.ok(isFunction(j.of), 'Just provides an of function')
471469
t.ok(isFunction(j.ap), 'Just implements the Apply spec')
@@ -487,7 +485,6 @@ test('Maybe of properties (Applicative)', t => {
487485

488486
test('Maybe chain errors', t => {
489487
const chain = bindFunc(Maybe(0).chain)
490-
const nChain = bindFunc(Maybe(undefined).chain)
491488

492489
t.throws(chain(undefined), TypeError, 'throws with undefined')
493490
t.throws(chain(null), TypeError, 'throws with null')

crocks/Pair.spec.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -389,8 +389,8 @@ test('Pair chain errors', t => {
389389
const badChain = bindFunc(Pair(0, 0).chain)
390390
const chain = bindFunc(Pair([], 0).chain)
391391

392-
const badFn = x => Pair(0, 0)
393-
const fn = x => Pair([], 0)
392+
const badFn = () => Pair(0, 0)
393+
const fn = () => Pair([], 0)
394394

395395
t.throws(badChain(noop), TypeError, 'throws if wrapped first value is not a Semigroup')
396396
t.throws(chain(badFn), TypeError, 'throws if monadic function returns a Pair with a non-Semigroup as first value')

crocks/Result.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ const _type =
3434
const concatErr =
3535
m => x => m.either(
3636
y => and(isSemigroup, isSameType(y), x) ? x.concat(y) : x,
37-
_ => x
37+
() => x
3838
)
3939

4040
function runSequence(x) {
@@ -158,7 +158,7 @@ function Result(u) {
158158
throw new TypeError('Result.ap: Wrapped value must be a function')
159159
}
160160

161-
return m.either(Result.Err, _ => m.map(fn))
161+
return m.either(Result.Err, () => m.map(fn))
162162
}
163163
)
164164
}

crocks/Result.spec.js

+1-2
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,6 @@ test('Result concat errors', t => {
114114
const m = { type: () => 'Result...Not' }
115115

116116
const good = Result.Ok([])
117-
const bad = Result.Err([])
118117

119118
const f = bindFunc(Result.Ok([]).concat)
120119

@@ -575,7 +574,7 @@ test('Result ap errors', t => {
575574

576575
test('Result Err ap functionality', t => {
577576
const Err = Result.Err
578-
const m = Result.Ok(x => y => z => x)
577+
const m = Result.Ok(x => () => () => x)
579578

580579
const extract = either(identity, constant('Ok'))
581580

crocks/Star.js

-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ const _inspect = require('../internal/inspect')
1010

1111
const compose = require('../helpers/compose')
1212
const constant = require('../combinators/constant')
13-
const identity = require('../combinators/identity')
1413

1514
const merge = require('../pointfree/merge')
1615
const sequence = require('../pointfree/sequence')

crocks/Star.spec.js

+5-5
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,7 @@ test('Star contramap functionality', t => {
242242
t.equal(m.type(), 'Star', 'returns a Star')
243243
t.notOk(spy.called, 'does not call mapping function initially')
244244

245-
const result = m.runWith(x)
245+
m.runWith(x)
246246

247247
t.ok(spy.called, 'calls mapping function when ran')
248248
t.equal(m.runWith(x).value(), x, 'returns the result of the resulting composition')
@@ -320,7 +320,7 @@ test('Star promap functionality', t => {
320320
t.notOk(spyLeft.called, 'does not call left mapping function initially')
321321
t.notOk(spyRight.called, 'does not call right mapping function initially')
322322

323-
const result = m.runWith(x)
323+
m.runWith(x)
324324

325325
t.ok(spyLeft.called, 'calls left mapping function when ran')
326326
t.ok(spyRight.called, 'calls right mapping function when ran')
@@ -375,7 +375,7 @@ test('Star first', t => {
375375

376376
t.doesNotThrow(runWith(Pair(1, 2)), 'does not throw when inner value is a Pair')
377377

378-
const notValid = bindFunc(x => Star(_ => x).first().runWith(Pair(2, 3)))
378+
const notValid = bindFunc(x => Star(() => x).first().runWith(Pair(2, 3)))
379379

380380
t.throws(notValid(undefined), TypeError, 'throws with undefined input')
381381
t.throws(notValid(null), TypeError, 'throws with null as input')
@@ -416,7 +416,7 @@ test('Star second', t => {
416416

417417
t.doesNotThrow(runWith(Pair(1, 2)), 'does not throw when inner value is a Pair')
418418

419-
const notValid = bindFunc(x => Star(_ => x).second().runWith(Pair(2, 3)))
419+
const notValid = bindFunc(x => Star(() => x).second().runWith(Pair(2, 3)))
420420

421421
t.throws(notValid(undefined), TypeError, 'throws when computation returns undefined')
422422
t.throws(notValid(null), TypeError, 'throws when computation returns null')
@@ -459,7 +459,7 @@ test('Star both', t => {
459459

460460
t.doesNotThrow(runWith(Pair(1, 2)), 'does not throw when inner value is a Pair')
461461

462-
const notValid = bindFunc(x => Star(_ => x).both().runWith(Pair(2, 3)))
462+
const notValid = bindFunc(x => Star(() => x).both().runWith(Pair(2, 3)))
463463

464464
t.throws(notValid(undefined), TypeError, 'throws when computation returns undefined')
465465
t.throws(notValid(null), TypeError, 'throws when computation returns null')

crocks/State.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ State.type =
141141
_type
142142

143143
State.get =
144-
_ => State(s => Pair(s, s))
144+
() => State(s => Pair(s, s))
145145

146146
State.gets =
147147
gets

crocks/State.spec.js

+1-2
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ const isObject = require('../predicates/isObject')
99
const isFunction = require('../predicates/isFunction')
1010

1111
const composeB = require('../combinators/composeB')
12-
const constant = require('../combinators/constant')
1312
const identity = require('../combinators/identity')
1413

1514
const Pair = require('./Pair')
@@ -400,7 +399,7 @@ test('State chain errors', t => {
400399
t.throws(noPair({}), TypeError, 'throws when inner function returns an object')
401400
t.throws(noPair(noop), TypeError, 'throws when inner function returns a function')
402401

403-
const noState = bindFunc(State(x => Pair(0, 0)).chain(identity).runWith)
402+
const noState = bindFunc(State(() => Pair(0, 0)).chain(identity).runWith)
404403

405404
t.throws(noState(undefined), TypeError, 'throws when chain function returns undefined')
406405
t.throws(noState(null), TypeError, 'throws when chain function returns null')

crocks/Unit.js

+1-4
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,10 @@
11
/** @license ISC License (c) copyright 2016 original and current authors */
22
/** @author Ian Hofmann-Hicks (evil) */
33

4+
const constant = require('../combinators/constant')
45
const isFunction = require('../predicates/isFunction')
5-
6-
const _inspect = require('../internal/inspect')
76
const isSameType = require('../predicates/isSameType')
87

9-
const constant = require('../combinators/constant')
10-
118
const _type =
129
constant('Unit')
1310

helpers/composeP.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ const isPromise = require('../predicates/isPromise')
99

1010
function applyCompose(f, g) {
1111
return function() {
12-
p = f.apply(null, arguments)
12+
const p = f.apply(null, arguments)
1313

1414
if(!isPromise(p)) {
1515
throw new TypeError('composeP: Only accepts Promise returning functions')

helpers/composeP.spec.js

+1-4
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,11 @@
11
const test = require('tape')
2-
const sinon = require('sinon')
32
const helpers = require('../test/helpers')
43

54
const bindFunc = helpers.bindFunc
65
const noop = helpers.noop
76

8-
const isFunction = require('../predicates/isFunction')
9-
10-
const compose = require('./compose')
117
const identity = require('../combinators/identity')
8+
const isFunction = require('../predicates/isFunction')
129

1310
const composeP = require('./composeP')
1411

helpers/pipeP.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ const isPromise = require('../predicates/isPromise')
99

1010
function applyPipe(f, g) {
1111
return function() {
12-
p = f.apply(null, arguments)
12+
const p = f.apply(null, arguments)
1313

1414
if(!isPromise(p)) {
1515
throw new TypeError('pipeP: Only accepts Promise returning functions')

0 commit comments

Comments
 (0)