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
92
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
初めてDefinitelyTypedにPRを出した話
syumai
0
420
Ethereum_.pdf
nekomatu
0
460
Amazon Bedrock Agentsを用いてアプリ開発してみた!
har1101
0
340
TypeScript Graph でコードレビューの心理的障壁を乗り越える
ysk8hori
2
1.1k
Webの技術スタックで マルチプラットフォームアプリ開発を可能にするElixirDesktopの紹介
thehaigo
2
1k
cmp.Or に感動した
otakakot
3
200
Hotwire or React? ~アフタートーク・本編に含めなかった話~ / Hotwire or React? after talk
harunatsujita
1
120
.NET のための通信フレームワーク MagicOnion 入門 / Introduction to MagicOnion
mayuki
1
1.7k
『ドメイン駆動設計をはじめよう』のモデリングアプローチ
masuda220
PRO
8
540
GitHub Actionsのキャッシュと手を挙げることの大切さとそれに必要なこと
satoshi256kbyte
5
430
What’s New in Compose Multiplatform - A Live Tour (droidcon London 2024)
zsmb
1
480
ヤプリ新卒SREの オンボーディング
masaki12
0
130
Featured
See All Featured
Optimizing for Happiness
mojombo
376
70k
[Rails World 2023 - Day 1 Closing Keynote] - The Magic of Rails
eileencodes
33
1.9k
Done Done
chrislema
181
16k
The Pragmatic Product Professional
lauravandoore
31
6.3k
What’s in a name? Adding method to the madness
productmarketing
PRO
22
3.1k
Building an army of robots
kneath
302
43k
Cheating the UX When There Is Nothing More to Optimize - PixelPioneers
stephaniewalter
280
13k
How To Stay Up To Date on Web Technology
chriscoyier
788
250k
The Art of Programming - Codeland 2020
erikaheidi
52
13k
Refactoring Trust on Your Teams (GOTO; Chicago 2020)
rmw
31
2.7k
A designer walks into a library…
pauljervisheath
204
24k
It's Worth the Effort
3n
183
27k
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 ͷϧʔϧઃఆ͕γϯϓϧʹͳΔ • ͪΐͬͱίʔυॻ͖ʹ͍͘ • গͳ͍ϧʔϧͰ৭ʑͳॻ͖ํ੍͕ݶ͞ΕΔ͜ͱࣗମ
͍͍͔ͳͱࢥ͍ͬͯΔ
Έ͍ͨͳ