Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
ヤバいESLint/TSLintルール作っちゃったかもしれない
Search
boiyama
April 24, 2018
Programming
0
1.5k
ヤバいESLint/TSLintルール作っちゃったかもしれない
Roppongi.js #2 での発表資料です。
https://roppongi-js.connpass.com/event/82998/
boiyama
April 24, 2018
Tweet
Share
More Decks by boiyama
See All by boiyama
Reproのビジネスサイドを支えるJS
boiyama
0
170
バックオフィスに行ったソフトウェアエンジニアの業務効率化事例
boiyama
1
240
2018年、IE6対応サイトを作る
boiyama
4
970
チームをCQRS
boiyama
1
1.4k
フロントエンドのサーバーレス SSR編
boiyama
0
670
Serverless for Front-end Server-Side Rendering
boiyama
1
89
Learning Elm in JS
boiyama
1
530
JSでElmを学ぶ
boiyama
0
85
フロントエンドのサーバーレス SPA編
boiyama
1
1.1k
Other Decks in Programming
See All in Programming
推し活の ハイトラフィックに立ち向かう Railsとアーキテクチャ - Kaigi on Rails 2024
falcon8823
6
2.4k
Snowflake x dbtで作るセキュアでアジャイルなデータ基盤
tsoshiro
2
460
WEBエンジニア向けAI活用入門
sutetotanuki
0
310
ECS Service Connectのこれまでのアップデートと今後のRoadmapを見てみる
tkikuc
2
230
讓數據說話:用 Python、Prometheus 和 Grafana 講故事
eddie
0
370
JaSST 24 九州:ワークショップ(は除く)実践!マインドマップを活用したソフトウェアテスト+活用事例
satohiroyuki
0
290
Importmapを使ったJavaScriptの 読み込みとブラウザアドオンの影響
swamp09
4
1.3k
役立つログに取り組もう
irof
27
8.9k
プロジェクト新規参入者のリードタイム短縮の観点から見る、品質の高いコードとアーキテクチャを保つメリット
d_endo
1
1k
Why Jakarta EE Matters to Spring - and Vice Versa
ivargrimstad
0
160
C#/.NETのこれまでのふりかえり
tomokusaba
1
170
Tuning GraphQL on Rails
pyama86
2
1.2k
Featured
See All Featured
Let's Do A Bunch of Simple Stuff to Make Websites Faster
chriscoyier
505
140k
Raft: Consensus for Rubyists
vanstee
136
6.6k
The Illustrated Children's Guide to Kubernetes
chrisshort
48
48k
[RailsConf 2023] Rails as a piece of cake
palkan
51
4.9k
Fantastic passwords and where to find them - at NoRuKo
philnash
50
2.8k
CSS Pre-Processors: Stylus, Less & Sass
bermonpainter
355
29k
Done Done
chrislema
181
16k
The MySQL Ecosystem @ GitHub 2015
samlambert
250
12k
Statistics for Hackers
jakevdp
796
220k
Designing on Purpose - Digital PM Summit 2013
jponch
115
6.9k
Easily Structure & Communicate Ideas using Wireframe
afnizarnur
191
16k
Side Projects
sachag
452
42k
Transcript
Ϡό ͍ 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
P ro f i l e • ϑϩϯτΤϯυΤϯδχΞ at PERSOL
• GitHub: boiyaa Twitter: boiyaaaaaa
Ͳ Μ ͳ ϧ ʔϧ ͔ return จΛېࢭͯ͠Έͨ eslint-plugin-no-return tslint-no-return
ݩʑଞͷؔܕݴޠνοΫͳจ๏Λਅࣅ͔ͨͬͨ ˍؔͷॻ͖ํΛἧ͔͑ͨͬͨతͳಈػɻ
// 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;
Λฦؔ͢Λॻ࣌͘ʹɺΞϩʔؔͷ؆ܿจମ͔͠ ͑ͳ͘ͳΔ͚͔ͩͱࢥ͚ͬͨͲ จ͕ॻ͚ͳ͍؆ܿจମʹΑͬͯɺ৭ʑͳॻ͖ํΛ౷ҰͰ ͖ͨΓɺ Lint ϧʔϧΛγϯϓϧʹͰ͖ͨΓ͢Δ͜ͱʹؾ ͍ͮͨɻ
݅ͷॻ͖ํΛ౷ҰͰ͖ͯɺ ϧʔϧΛݮΒͤͨɻ
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");
if switch ESLint ϧʔϧଟ͍ͷͰ͑ͳ͍ͳΒ͖ͬ͢ Γ͍͍ͯ͠ͱࢥ͏ɻ Ͱࡾ߲ԋࢉࢠ൱ఆ͕݁ߏ͍Δ͠ೖΕࢠϠό͍ɻ Ramda ΛͬͯΈΔͱ͔
const foo = bar => (bar == "baz" ? "qux"
: "quux"); // ! const foo = ifElse(equals("baz"), always("qux"), always("quux"));
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")] ]);
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")] ]);
ϧʔϓͷॻ͖ํΛ౷ҰͰ͖ͨɻ
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 = 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;
for ͱ͔ while ͱ͔ॻ͚ͳ͍ͱɺྻ͍͍ͱͯ͠ɺ ؆ܿจମʴࡾ߲ԋࢉࢠͷ࠶ؼؔಡΈʹ͍͘ɻ ͜Ε Ramda Ͱॻ͍ͯΈΔɻ
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);
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);
มɾఆΛఆٛͰ͖ͳ͘ͳͬͨ
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);
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);
// ͜ΜͳؔΛ࡞Δ const letin = (initialValue, funcs) => funcs .reduce(
(previousValue, func) => [ ...previousValue, func.apply(null, previousValue) ], initialValue ) .pop();
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 ] );
return Ҏ֎ͷจ͔͚ΔͷͰɺ Λฦ͞ͳ͍ؔͳΒͳΜͰ͋Γ
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"; }
· ͱ Ί • ESLint/TSLint ͷϧʔϧઃఆ͕γϯϓϧʹͳΔ • ͪΐͬͱίʔυॻ͖ʹ͍͘ • গͳ͍ϧʔϧͰ৭ʑͳॻ͖ํ੍͕ݶ͞ΕΔ͜ͱࣗମ
͍͍͔ͳͱࢥ͍ͬͯΔ
Έ͍ͨͳ