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
アクターシステムに頼らずEvent Sourcingする方法について
j5ik2o
4
290
CSC305 Lecture 26
javiergs
PRO
0
140
モバイルアプリにおける自動テストの導入戦略
ostk0069
0
110
KMP와 kotlinx.rpc로 서버와 클라이언트 동기화
kwakeuijin
0
160
コンテナをたくさん詰め込んだシステムとランタイムの変化
makihiro
1
140
tidymodelsによるtidyな生存時間解析 / Japan.R2024
dropout009
1
790
これが俺の”自分戦略” プロセスを楽しんでいこう! - Developers CAREER Boost 2024
niftycorp
PRO
0
190
テストコード文化を0から作り、変化し続けた組織
kazatohiei
2
1.5k
なまけものオバケたち -PHP 8.4 に入った新機能の紹介-
tanakahisateru
1
120
KubeCon + CloudNativeCon NA 2024 Overviewat Kubernetes Meetup Tokyo #68 / amsy810_k8sjp68
masayaaoyama
0
260
rails stats で紐解く ANDPAD のイマを支える技術たち
andpad
1
290
各クラウドサービスにおける.NETの対応と見解
ymd65536
0
110
Featured
See All Featured
RailsConf 2023
tenderlove
29
940
Refactoring Trust on Your Teams (GOTO; Chicago 2020)
rmw
32
2.7k
Principles of Awesome APIs and How to Build Them.
keavy
126
17k
A Philosophy of Restraint
colly
203
16k
Helping Users Find Their Own Way: Creating Modern Search Experiences
danielanewman
29
2.3k
Testing 201, or: Great Expectations
jmmastey
40
7.1k
The Web Performance Landscape in 2024 [PerfNow 2024]
tammyeverts
2
290
Optimising Largest Contentful Paint
csswizardry
33
3k
A Modern Web Designer's Workflow
chriscoyier
693
190k
Art, The Web, and Tiny UX
lynnandtonic
298
20k
Building Applications with DynamoDB
mza
91
6.1k
Building Flexible Design Systems
yeseniaperezcruz
327
38k
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 ͷϧʔϧઃఆ͕γϯϓϧʹͳΔ • ͪΐͬͱίʔυॻ͖ʹ͍͘ • গͳ͍ϧʔϧͰ৭ʑͳॻ͖ํ੍͕ݶ͞ΕΔ͜ͱࣗମ
͍͍͔ͳͱࢥ͍ͬͯΔ
Έ͍ͨͳ