From b883515a5feddb9ced0e3a6cbb9aea86606fc8de Mon Sep 17 00:00:00 2001 From: Freywar Ulvnaudgari Date: Fri, 9 Aug 2024 23:05:07 +0300 Subject: [PATCH] Fix linter errors --- eslint.config.mjs | 1 + src/bf.ts | 24 ++++++++++++------------ src/core.ts | 6 +++--- src/list.ts | 14 +++++++------- src/num.ts | 4 ++-- src/ord.ts | 6 +++--- src/string.ts | 4 ++-- test/bf.spec.ts | 4 ++-- test/list.spec.ts | 12 ++++++------ test/num.spec.ts | 2 +- test/string.spec.ts | 5 ++--- 11 files changed, 41 insertions(+), 41 deletions(-) diff --git a/eslint.config.mjs b/eslint.config.mjs index 95e0c11..e104470 100644 --- a/eslint.config.mjs +++ b/eslint.config.mjs @@ -28,6 +28,7 @@ export default [ rules: { 'arrow-body-style': 'error', 'no-extra-parens': ['error', 'all'], + 'no-unexpected-multiline': 'off', 'sort-imports': ['error', { ignoreDeclarationSort: true }], '@stylistic/quotes': ['error', 'single'], '@stylistic/semi': ['error', 'always'], diff --git a/src/bf.ts b/src/bf.ts index ef44be5..f19d4e7 100644 --- a/src/bf.ts +++ b/src/bf.ts @@ -4,7 +4,7 @@ import { Num, Zero, ge, ifz, pred, succ } from './num'; import { x00 } from './byte'; import { Char, fromChar as _c, dec as cdec, inc as cinc, eq, ifn } from './char'; import { Pair, first, fst, second, snd, uncurry } from './pair'; -import { List, Nil, cons, head, repeat, set, singleton, tail, update } from './list'; +import { List, cons, head, repeat, set, singleton, tail, update } from './list'; import { Empty, String, get, len, snoc } from './string'; type Program = Pair, String>; @@ -57,8 +57,8 @@ const prev: L<(t: State) => State> const jump: L<(d: Num) => L<(s: State) => State>> = _(d => _(s => iif(command(_c('['))(s))(jump(succ(d))) - (iif(command(_c(']'))(s))(ifz(pred(d))(cnst(s))(jump(pred(d)))) - (jump(d)))(advance(s)))); + (iif(command(_c(']'))(s))(ifz(pred(d))(cnst(s))(jump(pred(d)))) + (jump(d)))(advance(s)))); const whlnz: L<(t: State) => State> = _(s => ifn(read(s))(jump(Zero))(save)(s)); @@ -68,15 +68,15 @@ const endwhl: L<(t: State) => State> const exec: L<(s: State) => State> = _(s => iif(done(s))(s)(exec(advance - (iif(command(_c('>'))(s))(next) - (iif(command(_c('<'))(s))(prev) - (iif(command(_c('+'))(s))(inc) - (iif(command(_c('-'))(s))(dec) - (iif(command(_c('.'))(s))(output) - (iif(command(_c(','))(s))(input) - (iif(command(_c('['))(s))(whlnz) - (iif(command(_c(']'))(s))(endwhl) - (id))))))))(s))))); + (iif(command(_c('>'))(s))(next) + (iif(command(_c('<'))(s))(prev) + (iif(command(_c('+'))(s))(inc) + (iif(command(_c('-'))(s))(dec) + (iif(command(_c('.'))(s))(output) + (iif(command(_c(','))(s))(input) + (iif(command(_c('['))(s))(whlnz) + (iif(command(_c(']'))(s))(endwhl) + (id))))))))(s))))); export const run: L<(p: String) => L<(i: String) => String>> = _(p => _(i => snd(snd(snd(exec(Pair(Pair(singleton(Zero))(p))(Pair(Pair(Zero)(repeat(x00)))(Pair(i)(Empty))))))))); diff --git a/src/core.ts b/src/core.ts index 848d371..0c40cb0 100644 --- a/src/core.ts +++ b/src/core.ts @@ -1,10 +1,10 @@ -export type L L> = T & { run: () => T; } +export type L L> = T & { run: () => T }; -export function ___ L>(run: () => T): L{ +export function ___ L>(run: () => T): L { const r: T = ((p: Parameters[0]) => { let v: any; return ___(() => run()( - ___(() => v ??= p.run()) + ___(() => v ??= p.run()), ).run()); }) as T; diff --git a/src/list.ts b/src/list.ts index 4f32af1..68b1b7e 100644 --- a/src/list.ts +++ b/src/list.ts @@ -66,11 +66,11 @@ export const cmp: L<(ecmp: L<(l: T) => L <(r: T) => Ord>>) => L<(l: = _((ecmp: L<(l: T) => L<(r: T) => Ord>>) => _((l: List) => _((r: List) => l - (r(EQ)(cnst(cnst(LT)))) - (_(lx => _(lxs => r(GT)(_(rx => _(rxs => iif - (eqc(EQ)(ecmp(lx)(rx))) - (cmp(ecmp)(lxs)(rxs)) - (ecmp(lx)(rx))))))))))); + (r(EQ)(cnst(cnst(LT)))) + (_(lx => _(lxs => r(GT)(_(rx => _(rxs => iif + (eqc(EQ)(ecmp(lx)(rx))) + (cmp(ecmp)(lxs)(rxs)) + (ecmp(lx)(rx))))))))))); export const lt: L<(ecmp: L<(l: T) => L <(r: T) => Ord>>) => L<(l: List) => L<(r: List) => Bool>>> = _((ecmp: L<(l: T) => L<(r: T) => Ord>>) => @@ -88,8 +88,8 @@ export const eq: L<(eeq: L<(l: T) => L <(r: T) => Bool>>) => L<(l: = _((eeq: L<(l: T) => L<(r: T) => Bool>>) => _((l: List) => _((r: List) => l - (r(True)(cnst(cnst(False)))) - (_(lx => _(lxs => r(False)(_(rx => _(rxs => and(eeq(lx)(rx))(eq(eeq)(lxs)(rxs))))))))))); + (r(True)(cnst(cnst(False)))) + (_(lx => _(lxs => r(False)(_(rx => _(rxs => and(eeq(lx)(rx))(eq(eeq)(lxs)(rxs))))))))))); export const ge: L<(ecmp: L<(l: T) => L <(r: T) => Ord>>) => L<(l: List) => L<(r: List) => Bool>>> = _((ecmp: L<(l: T) => L<(r: T) => Ord>>) => diff --git a/src/num.ts b/src/num.ts index 5201402..70c9dab 100644 --- a/src/num.ts +++ b/src/num.ts @@ -61,8 +61,8 @@ export const mod: L<(l: Num) => L<(r: Num) => Num>> export const show: L<(n: Num) => String> = _(n => iif(lt(n)(fromNumber(10))) - (cons(sum(n)(fromNumber(48)))(Empty)) - (append(show(div(n)(fromNumber(10))))(show(mod(n)(fromNumber(10)))))); + (cons(sum(n)(fromNumber(48)))(Empty)) + (append(show(div(n)(fromNumber(10))))(show(mod(n)(fromNumber(10)))))); export const fromNumber: (n: number) => Num = n => !n ? Zero : Succ(___(() => fromNumber(n - 1).run())); diff --git a/src/ord.ts b/src/ord.ts index 509586c..f629360 100644 --- a/src/ord.ts +++ b/src/ord.ts @@ -21,9 +21,9 @@ export const GT: Ord export const eq: L<(l: Ord) => L<(r: Ord) => Bool>> = _(l => _(r => l - (r(True)(False)(False)) - (r(False)(True)(False)) - (r(False)(False)(True)))); + (r(True)(False)(False)) + (r(False)(True)(False)) + (r(False)(False)(True)))); export const show: L<(o: Ord) => String> = _(o => o(_s('LT'))(_s('EQ'))(_s('GT'))); diff --git a/src/string.ts b/src/string.ts index 80d30ef..3cd1e0a 100644 --- a/src/string.ts +++ b/src/string.ts @@ -3,7 +3,7 @@ import { Ord } from './ord'; import { Bool } from './bool'; import { fromNumber as _nn } from './num'; import { toChar as $c, Char, fromChar as _c, cmp as cmpc, eq as eqc } from './char'; -import { Cons, List, Nil, append, cmp as cmpl, concat, cons, eq as eql, ge as gel, gt as gtl, le as lel, lt as ltl } from './list'; +import { Cons, List, Nil, append, cmp as cmpl, eq as eql, ge as gel, gt as gtl, le as lel, lt as ltl } from './list'; export type String = List; @@ -27,7 +27,7 @@ export const ge: L<(l: String) => L<(r: String) => Bool>> export const gt: L<(l: String) => L<(r: String) => Bool>> = gtl(cmpc); -export const wrap: L<(w: String) => L<(c: String) => String>> +export const wrap: L<(w: String) => L<(c: String) => String>> = _(w => _(c => append(w)(append(c)(w)))); export const fromString: (xs: string) => String diff --git a/test/bf.spec.ts b/test/bf.spec.ts index 4f12ef1..227a38e 100644 --- a/test/bf.spec.ts +++ b/test/bf.spec.ts @@ -40,8 +40,8 @@ describe('BF', () => { it('prints "Hello World!"', () => { expect($s(run - (_s('++++++++[>++++[>++>+++>+++>+<<<<-]>+>+>->>+[<]<-]>>.>---.+++++++..+++.>>.<-.<.+++.------.--------.>>+.>++.')) - (_s('')))) + (_s('++++++++[>++++[>++>+++>+++>+<<<<-]>+>+>->>+[<]<-]>>.>---.+++++++..+++.>>.<-.<.+++.------.--------.>>+.>++.')) + (_s('')))) .toBe('Hello World!\n'); }); }); diff --git a/test/list.spec.ts b/test/list.spec.ts index 632dacd..e5c6bc9 100644 --- a/test/list.spec.ts +++ b/test/list.spec.ts @@ -1,5 +1,5 @@ import { describe, expect, it } from '@jest/globals'; -import { toNative as $$, L, _, fromNative as __, ___, undef } from '../src/core'; +import { toNative as $$, _, fromNative as __, ___, undef } from '../src/core'; import { toNOrd as $o, NOrd } from '../src/ord'; import { toBoolean as $b, iif } from '../src/bool'; import { toNumber as $n, toNumber as $nn, Num, Succ, Zero, fromNumber as _n, fromNumber as _nn, cmp as cmpn, eq as eqn, even, gt as ngt, show as nshow, odd, succ, sum } from '../src/num'; @@ -261,9 +261,9 @@ describe('List', () => { it('handles infinite lists', () => { expect($n( foldr - (_(x => _(a => sum(x)(iif(eqn(_n(5))(x))(Zero)(a))))) - (Zero) - (infinite))) + (_(x => _(a => sum(x)(iif(eqn(_n(5))(x))(Zero)(a))))) + (Zero) + (infinite))) .toBe(15); }); }); @@ -284,8 +284,8 @@ describe('List', () => { it.failing('handles infinite lists', () => { expect($n( foldrz - (_(x => _(a => sum(x)(iif(eqn(_n(5))(x))(Zero)(a))))) - (infinite))) + (_(x => _(a => sum(x)(iif(eqn(_n(5))(x))(Zero)(a))))) + (infinite))) .toBe(15); }); }); diff --git a/test/num.spec.ts b/test/num.spec.ts index e7d7320..6760a79 100644 --- a/test/num.spec.ts +++ b/test/num.spec.ts @@ -1,5 +1,5 @@ import { describe, expect, it } from '@jest/globals'; -import { ___, L, undef } from '../src/core'; +import { ___, undef } from '../src/core'; import { toNOrd as $o, NOrd } from '../src/ord'; import { toBoolean as $b, fromBoolean as _b } from '../src/bool'; import { toNumber as $n, Num, Succ, Zero, fromNumber as _n, cmp, div, eq, ge, gt, ifz, le, lt, mod, mul, pred, show, sub, succ, sum } from '../src/num'; diff --git a/test/string.spec.ts b/test/string.spec.ts index 8448d78..761f8a6 100644 --- a/test/string.spec.ts +++ b/test/string.spec.ts @@ -1,5 +1,5 @@ import { describe, expect, it } from '@jest/globals'; -import { L, _, ___, undef } from '../src/core'; +import { _, ___, undef } from '../src/core'; import { NOrd, toNOrd } from '../src/ord'; import { toBoolean as $b } from '../src/bool'; import { toNumber as $n, Zero, gt as ngt } from '../src/num'; @@ -37,7 +37,7 @@ describe('String', () => { }); }); - // describe('repeat', () => { + // describe('repeat', () => { // it('repeat "a" is "aaa..."', () => { // expect($na( // repeat(_s('a'))(_((x0: Char) => _((x1s: String) => @@ -55,7 +55,6 @@ describe('String', () => { // }); // }); - describe('empty', () => { it('empty "" is True', () => { expect($b(empty(_s('')))).toEqual(true);