boiyama
April 24, 2018
1.4k

# ヤバいESLint/TSLintルール作っちゃったかもしれない

Roppongi.js #2 での発表資料です。
https://roppongi-js.connpass.com/event/82998/

April 24, 2018

## Transcript

1. ### Ϡό ͍ E S L i n t / T

S L i n t ϧ ʔϧ ࡞ ͬ ͪ Ό ͬ ͨ ͔ ΋ ͠ Ε ͳ ͍ 2 0 1 8 . 4 . 2 4 R o p p o n g i . j s # 2

3. ### Ͳ Μ ͳ ϧ ʔϧ ͔ return จΛېࢭͯ͠Έͨ eslint-plugin-no-return tslint-no-return

ݩʑ͸ଞͷؔ਺ܕݴޠνοΫͳจ๏Λਅࣅ͔ͨͬͨ  ˍؔ਺ͷॻ͖ํΛἧ͔͑ͨͬͨతͳಈػɻ
4. ### // Error function foo(bar) { const baz = bar **

2; return baz; } // Error const foo = function (bar) { const baz = bar ** 2; return baz; }; // Error const foo = bar => { const baz = bar ** 2; return baz; }; // OK const foo = bar => bar ** 2;

7. ### const foo = bar => { if (bar == "baz")

{ return "qux"; } return "quux"; }; const foo = bar => { switch (bar) { case "baz": { return "qux"; } default: { return "quux"; } } }; // ! const foo = bar => (bar == "baz" ? "qux" : "quux");

9. ### const foo = bar => (bar == "baz" ? "qux"

: "quux"); // ! const foo = ifElse(equals("baz"), always("qux"), always("quux"));
10. ### const foo = (bar, baz) => { if (bar <

baz) { return "qux"; } else if (bar > baz) { return "quux"; } return "corge"; }; // ! const foo = cond([ [R.lt(R.__, R.__), R.always("qux")], [R.gt(R.__, R.__), R.always("quux")], [T, always("corge")] ]);
11. ### const foo = bar => { switch (bar) { case

"baz": { return "qux"; } case "quux": { return "corge"; } default: { return "grault"; } } }; // ! const foo = cond([ [equals("baz"), always("qux")], [equals("quux"), always("corge")], [T, always("grault")] ]);

13. ### const foo = bar => { const baz = [];

for (let i = 0; i < bar.length; i++) { baz.push(bar[i] ** 2); } return baz; }; // ! const foo = bar => bar.map(baz => baz ** 2);
14. ### const foo = count => { const baz = [];

for (let i = 0; i < count; i++) { baz.push(i ** 2); } return baz; }; // ! const foo = (count, baz, i) => i < count ? foo(count, [].concat(baz, [i ** 2]), i + 1) : baz;

16. ### const foo = bar => { const baz = [];

for (let i = 0; i < bar.length; i++) { baz.push(bar[i] ** 2); } return baz; }; // ! const foo = bar => bar.map(baz => baz ** 2); // ! const foo = bar => map(baz => baz ** 2, bar);
17. ### const foo = count => { const baz = [];

for (let i = 0; i < count; i++) { baz.push(i ** 2); } return baz; }; // ! const foo = (count, baz, i) => i < count ? foo(count, [].concat(baz, [i ** 2]), i + 1) : baz; // ! const foo = count => times(i => i ** 2, count);

19. ### const foo = bar => { const baz = bar

** 2; return baz + baz; }; // ! const foo = bar => bar ** 2 + bar ** 2; // ! let ࣜ෩Ξϓϩʔν const foo = bar => (baz => baz + baz)(bar ** 2);
20. ### const foo = bar => { const baz = bar

** 2; const qux = baz ** 2; const quux = qux ** 2; return baz + qux + quux; }; // ! let ࣜ෩Ξϓϩʔν͸Ϡό͍ const foo = bar => (baz => ((baz, qux) => ((baz, qux, quux) => baz + qux + quux)(baz, qux, qux ** 2))( baz, baz ** 2 ))(bar ** 2);
21. ### // ͜Μͳؔ਺Λ࡞Δ const letin = (initialValue, funcs) => funcs .reduce(

(previousValue, func) => [ ...previousValue, func.apply(null, previousValue) ], initialValue ) .pop();
22. ### const foo = bar => { const baz = bar

** 2; const qux = baz ** 2; const quux = qux ** 2; return baz + qux + quux; }; // ! const foo = bar => letin( [bar], [ bar => bar * bar, (bar, baz) => baz * baz, (bar, baz, qux) => qux * qux, (bar, baz, qux, quux) => baz + qux + quux ] );

24. ### function foo(bar) { bar.baz = "qux"; bar.quux.push("corge"); } const foo

= function (callback) { callback(); }; const foo = () => { throw new Error("bar"); }; function* foo() { yield "bar"; }

͍͍͔ͳͱࢥ͍ͬͯΔ