Upgrade to Pro — share decks privately, control downloads, hide ads and more …

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

boiyama
April 24, 2018

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

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

boiyama

April 24, 2018
Tweet

More Decks by boiyama

Other Decks in Programming

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
  2. P ro f i l e • ϑϩϯτΤϯυΤϯδχΞ at PERSOL

    • GitHub: boiyaa
 Twitter: boiyaaaaaa
  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;
  5. 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");
  6. const foo = bar => (bar == "baz" ? "qux"

    : "quux"); // ! const foo = ifElse(equals("baz"), always("qux"), always("quux"));
  7. 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")] ]);
  8. 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")] ]);
  9. 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);
  10. 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;
  11. 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);
  12. 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);
  13. 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);
  14. 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);
  15. // ͜Μͳؔ਺Λ࡞Δ const letin = (initialValue, funcs) => funcs .reduce(

    (previousValue, func) => [ ...previousValue, func.apply(null, previousValue) ], initialValue ) .pop();
  16. 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 ] );
  17. 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"; }