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プラグインでAST入門
Search
Sponsored
·
Your Podcast. Everywhere. Effortlessly.
Share. Educate. Inspire. Entertain. You do you. We'll handle the rest.
→
oodemi
May 28, 2016
1.1k
0
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
ESLintプラグインでAST入門
oodemi
May 28, 2016
More Decks by oodemi
See All by oodemi
開発プロセスの改革を促進し変化を楽しむチームを作る「振り返り」
oodemi
1
180
Building Design Systems with Atomic Design
oodemi
4
5.6k
マイクロインタラクション
oodemi
0
380
Featured
See All Featured
A Tale of Four Properties
chriscoyier
163
24k
Leveraging LLMs for student feedback in introductory data science courses - posit::conf(2025)
minecr
1
370
Chasing Engaging Ingredients in Design
codingconduct
0
290
Un-Boring Meetings
codingconduct
0
400
Put a Button on it: Removing Barriers to Going Fast.
kastner
60
4.6k
Designing Dashboards & Data Visualisations in Web Apps
destraynor
232
55k
Side Projects
sachag
455
43k
The Power of CSS Pseudo Elements
geoffreycrofte
82
6.5k
Agile that works and the tools we love
rasmusluckow
331
22k
Bootstrapping a Software Product
garrettdimon
PRO
306
120k
Future Trends and Review - Lecture 12 - Web Technologies (1019888BNR)
signer
PRO
0
3.7k
Bash Introduction
62gerente
615
220k
Transcript
ESLintϓϥάΠϯͰASTೖ ৽ ग़ւ / @ooDEMi
- Profile - Atarashi Hidemi Frontend Engineer @oodemi
JavaScript AST
Babel Webpack ESLint
AST ?
Abstract Syntax Tree நߏจ
! ?
None
! ??
ASTͱԿ͔
AST 4 ίʔυΛจ๏తʹղऍ͠ߏͰදݱͨ͠ͷ 4 JavaScript ASTJSONͰදݱ͞ΕΔ 4 ESTree ͕ίϛϡχςΟඪ४
JavaScript → AST AST Explorer
JavaScript var message = "Hello AST";
AST { "range": [ 0, 25 ], "type": "Program", "body":
[ { "range": [ 0, 25 ], "type": "VariableDeclaration", "declarations": [ { "range": [ 4, 25 ], "type": "VariableDeclarator", "id": { "range": [ 4, 11 ], "type": "Identifier", "name": "message" }, "init": { "range": [ 14, 25 ], "type": "Literal", "value": "Hello AST", "raw": "\"Hello AST\"" } } ], "kind": "var" } ], "sourceType": "module" }
1 lines → 44 lines
!
Ͱେৎɺා͘ͳ͍
Կͱͳ͔͘Δ 4 Ұ෦ൈਮ "type": "VariableDeclarator" // มએݴ "kind": "var" //
"var"Ͱએݴ͞ΕͯΔ "name": "message" // ม໊"message" "range": [4, 11] // 4จࣈ~11จࣈ "value": "Hello AST" // த"Hello AST"
AST͕Ͳ͏͍͏ͷ͔Կͱͳ ͘ཧղͰ͖ͨ !
Ͱ͜ΕΛԿʹ͏ͷʁ
ESLint
ESLint 4 ASTΛݕূ͠ϧʔϧʹͯ·Δͷ͕͋Ε ܯࠂΛग़͢ 4 ESLintͷϧʔϧશͯϓϥάΠϯ 4 eslint/lib/rules 4 ࣗ࡞ϧʔϧϓϥάΠϯΛ࡞Εಈ͘
4 Working with Plugins
no-var.js "use strict"; module.exports = { create: function(context) { return
{ // 1. VariableDeclarationͷnodeʹ౸ୡͨ͠Β࣮ߦ͞ΕΔ VariableDeclaration: function(node) { // 2. var͕ΘΕ͍ͯͨΒΤϥʔϝοηʔδΛදࣔ͢Δ if (node.kind === "var") { context.report(node, "Unexpected var, use let or const instead."); } } }; } };
ਅࣅͯ͠࡞ͬͯΈΔ
no-nemui-comment.js 1. ίʔυʹίϝϯτͰ[͍]͕ଘࡏͨ͠Β 2. [✘ ;͚ͨ͟ίϝϯτॻ͔ͳ͍ͰԼ͍͞.] ͱ͍͏ΤϥʔΛग़͢ 4 NGίʔυ: //͍
let status = "Nemui";
JavaScript → AST //͍ var status = "Nemui";
{ "range": [ 6, 27 ], "type": "Program", "body": [
{ "range": [ 6, 27 ], "type": "VariableDeclaration", "declarations": [ { "range": [ 10, 26 ], "type": "VariableDeclarator", "id": { "range": [ 10, 16 ], "type": "Identifier", "name": "status" }, "init": { "range": [ 19, 26 ], "type": "Literal", "value": "Nemui", "raw": "\"Nemui\"" } } ], "kind": "var" } ], "sourceType": "module", "comments": [ { "type": "Line", "value": " ͍", "range": [ 0, 5 ] } ] }
"comments": [ ίϝϯτͰ... { "type": "Line", छྨLineComment "value": "͍", த͕ʮ͍ʯ
"range": [ 0, 5 ] } ]
no-nemui-comment.js 'use strict'; module.exports = { create: (context) => {
return { // 1. LineCommentͷ࣌ʹ "LineComment": (node) => { // 2. த͕ʮ͍ʯͩͬͨΒ if (node.value === "͍") { context.report(node, "✘ ;͚ͨ͟ίϝϯτॻ͔ͳ͍ͰԼ͍͞."); } } }; } };
.eslintrc { "extends": "eslint:recommended", "rules": { "no-nemui-comment": 2 } }
࣮ߦ 4 ESLint CLI $ eslint -c .eslintrc ./nemui.js --rulesdir
./rules
None
!
৽͍͠ϧʔϧͷ࣮ 4 ৽͍͠ϧʔϧΛద༻͍ͨ͠ίʔυΛAST ExplorerͰݟͳ͕Β࣮͢Δͱ؆୯ʹϧʔϧ Λ࡞Δ͜ͱ͕ग़དྷΔ 4 ͍ͭͰʹASTͷษڧग़དྷΔ
ศརͳϧʔϧΛࢁ ࡞ͬͯΈ·͠ΐ͏ʂ
͋Γ͕ͱ͏͍͟͝·ͨ͠ :) @ooDEMi