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
680
Serverless for Front-end Server-Side Rendering
boiyama
1
92
Learning Elm in JS
boiyama
1
530
JSでElmを学ぶ
boiyama
0
86
フロントエンドのサーバーレス SPA編
boiyama
1
1.1k
Other Decks in Programming
See All in Programming
開発者とQAの越境で自動テストが増える開発プロセスを実現する
92thunder
1
190
快速入門可觀測性
blueswen
0
380
range over funcの使い道と非同期N+1リゾルバーの夢 / about a range over func
mackee
0
110
ChatGPT とつくる PHP で OS 実装
memory1994
PRO
2
110
create_tableをしただけなのに〜囚われのuuid編〜
daisukeshinoku
0
270
今年のアップデートで振り返るCDKセキュリティのシフトレフト/2024-cdk-security-shift-left
tomoki10
0
210
Recoilを剥がしている話
kirik
5
6.8k
htmxって知っていますか?次世代のHTML
hiro_ghap1
0
340
数十万行のプロジェクトを Scala 2から3に完全移行した
xuwei_k
0
280
情報漏洩させないための設計
kubotak
3
340
Exploring: Partial and Independent Composables
blackbracken
0
100
선언형 UI에서의 상태관리
l2hyunwoo
0
180
Featured
See All Featured
Fashionably flexible responsive web design (full day workshop)
malarkey
405
66k
The Cult of Friendly URLs
andyhume
78
6.1k
Fantastic passwords and where to find them - at NoRuKo
philnash
50
2.9k
Fight the Zombie Pattern Library - RWD Summit 2016
marcelosomers
232
17k
Site-Speed That Sticks
csswizardry
2
190
Product Roadmaps are Hard
iamctodd
PRO
49
11k
Making the Leap to Tech Lead
cromwellryan
133
9k
Testing 201, or: Great Expectations
jmmastey
40
7.1k
The Invisible Side of Design
smashingmag
298
50k
XXLCSS - How to scale CSS and keep your sanity
sugarenia
247
1.3M
The Illustrated Children's Guide to Kubernetes
chrisshort
48
48k
Bootstrapping a Software Product
garrettdimon
PRO
305
110k
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 ͷϧʔϧઃఆ͕γϯϓϧʹͳΔ • ͪΐͬͱίʔυॻ͖ʹ͍͘ • গͳ͍ϧʔϧͰ৭ʑͳॻ͖ํ੍͕ݶ͞ΕΔ͜ͱࣗମ
͍͍͔ͳͱࢥ͍ͬͯΔ
Έ͍ͨͳ