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
Streams APIとTCPフロー制御 / Web Streams API and TCP flow control
tasshi
2
350
Contemporary Test Cases
maaretp
0
140
Micro Frontends Unmasked Opportunities, Challenges, Alternatives
manfredsteyer
PRO
0
110
Creating a Free Video Ad Network on the Edge
mizoguchicoji
0
120
Why Jakarta EE Matters to Spring - and Vice Versa
ivargrimstad
0
1.1k
AWS Lambdaから始まった Serverlessの「熱」とキャリアパス / It started with AWS Lambda Serverless “fever” and career path
seike460
PRO
1
260
RubyLSPのマルチバイト文字対応
notfounds
0
120
Generative AI Use Cases JP (略称:GenU)奮闘記
hideg
1
300
Hotwire or React? ~アフタートーク・本編に含めなかった話~ / Hotwire or React? after talk
harunatsujita
1
120
色々なIaCツールを実際に触って比較してみる
iriikeita
0
330
flutterkaigi_2024.pdf
kyoheig3
0
150
CSC509 Lecture 09
javiergs
PRO
0
140
Featured
See All Featured
A better future with KSS
kneath
238
17k
RailsConf 2023
tenderlove
29
900
10 Git Anti Patterns You Should be Aware of
lemiorhan
655
59k
Docker and Python
trallard
40
3.1k
Faster Mobile Websites
deanohume
305
30k
JavaScript: Past, Present, and Future - NDC Porto 2020
reverentgeek
47
5k
Navigating Team Friction
lara
183
14k
Bash Introduction
62gerente
608
210k
ReactJS: Keep Simple. Everything can be a component!
pedronauck
665
120k
Performance Is Good for Brains [We Love Speed 2024]
tammyeverts
6
430
The Cult of Friendly URLs
andyhume
78
6k
Music & Morning Musume
bryan
46
6.2k
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 ͷϧʔϧઃఆ͕γϯϓϧʹͳΔ • ͪΐͬͱίʔυॻ͖ʹ͍͘ • গͳ͍ϧʔϧͰ৭ʑͳॻ͖ํ੍͕ݶ͞ΕΔ͜ͱࣗମ
͍͍͔ͳͱࢥ͍ͬͯΔ
Έ͍ͨͳ