å°ããªçŽ¹ä»ã ã»ãšãã©ã®å Žåããã®æçš¿ã¯ESLintãšã¯äœããç¥ã£ãŠãã人ã«ã ãèå³æ·±ããã®ã§ãããããã§ãç§ã¯å°ããªçŽ¹ä»ãããŸãããããªããã°ãåºçç©ãéããšéåžžã«æã£ãŠããããªãã話ããŠããxxxã10幎é䜿ã£ãŠããŸãããšããèšèã§å§ãŸããŸããåç¥ã§ãããxxx.yyyã«ã€ããŠæžãããšã«ããŸãããããã¯èª°ããã£ãããšããããŸãããããããããšãŠãã¯ãŒã«ã§ããã
ãã®ããã
ESLintã¯ãéžæããJavaScriptæšæºã§èšè¿°ãããã³ãŒãã®å質ãåæã§ããã¯ãŒã«ãªããŒã«ã§ãã ã³ãŒããã»ãŒåäžãªã¹ã¿ã€ã«ã«ããæããªééããåé¿ããèŠã€ãã£ãåé¡ã®å€ããèªåçã«ä¿®æ£ããå€ãã®éçºããŒã«ïŒhelloãJetbrainsãç§ãã¡ã¯ããªããæããŠããŸãïŒïŒãšå®å
šã«çµ±åã§ããŸãã ã¡ãªã¿ã«ã圌ã¯ãä»ã®ãªã³ã¿ãŒã®ããã«ãããªãã«ç¹å®ã®ã¹ã¿ã€ã«ã矩åä»ããŸããã ããã©ããã-ãã¹ããã©ã¯ãã£ã¹ããäœããéžæããå¿
èŠã«å¿ããŠå€æŽã§ããŸãã
ã¢ããªã±ãŒã·ã§ã³ã®äžã§ã¯ããŸã£ããäºæããªãã±ãŒã¹ãèŠã€ããããšãã§ããŸããããšãã°ããªã³ã¿ãŒãèªåçã«ä¿®æ£ããããšã§ã¬ã¬ã·ãŒã³ãŒããå®è¡ãããããªãããšã©ãŒããã®ãŸãŸä¿®æ£ãããããããèŠããææ°ã®æšæºã«ãªããŸãã ãã®çµæãç¡å¹ãªæ§æäœãå€æããå¯èœæ§ããããŸãããç§ãã¡ã®èŠ³å¯ã«ãããšãããã¯å€æåã«ããããããã³ãŒãããã£ãããšãæå³ããŸãã
äžè¬ã«ã2017幎ã«Node.JSã§ãªã³ã¿ãŒãªãã§ç掻ããããšã¯ãçæã«åº§ã£ãŠã¡ã¢åž³ã§ã³ãŒããæžããããªãã®ã§ãã
ãããŠä»æ¥ãç§ã¯åœŒãå人ãšããŠã§ã¯ãªããããŒã ãšããŠå¹æçã«åãããã«ã©ã®ããã«ãããå®è£
ããããšã«æ±ºããããã話ãããŸãã
倧äŒæ¥ã¯CIããã»ã¹ã®äžéšãšããŠãªã³ã¿ãŒãã¹ããè¡ã£ãŠããŸãããããã«ããã説æããŸãã ãããä»ã®ãšãããç§ãã¡ã¯äž»ãªå¿
èŠæ§ãèªèããå¿
èŠããããŸã-éçºè
ããã®ãªã³ã¿ãŒã®ç«ã¡äžãããã¹ãŠãããŸããããã»ãŒåãããã«åäœããããšãä¿èšŒããŸãã
ã©ããã-ããã¯äœã§ããããããžã§ã¯ãã«.eslintrc.jsonãè¿œå ããŠãå§ããŸãããïŒ ããããçåãçããŸããESLintãã©ã®ããã«ãã©ãã§ã誰ã«ãã£ãŠé
眮ããå¿
èŠããããã³ãŒãã¹ã¿ã€ã«ã«å¿
èŠãªãã©ã°ã€ã³ã®æã§ããïŒ éåžžãããã«ã¯3ã€ã®ã¢ãããŒãã䜿çšãããŸãã
- ããããdevDependencyã«å
¥ããŸãããã
- ããããã©ãã«ã眮ããªãããã«ããŸãããã 誰ããã¢ã«\ãšã¹ãªã³ã\ã¹ã¿ãããäžçäžã«æã¡ãŸãããã
- gulpãgruntãªã©ã®ã¿ã¹ã¯ãããŒãžã£ãŒã«ãããã§ãã¯ã§ãã¹ãŠãèšå®ããŠå®è¡ããŸãã
2çªç®ã®ãªãã·ã§ã³ã¯ããã«æé€ãããŸãããã®æ¹æ³ã§ã¯ããããžã§ã¯ãããšã«ããŒã«èªäœã®ããŒãžã§ã³ç®¡çã倱ãããããŒã«ãšãã©ã°ã€ã³ãã°ããŒãã«ã«ã€ã³ã¹ããŒã«ããã ãã§ã¯ãŸã£ããã¯ãŒã«ã§ã¯ãªãããšã¯æããã§ãã
3çªç®ã®ãªãã·ã§ã³ã¯æªããããŸãããããããŸã§ã®ãšããããªããšãããŠã¿ã¹ã¯ãããŒãžã£ãŒãªãã§ç®¡çããŠããŸãã ãã®ãããªã¿ã¹ã¯ã®ãããžã§ã¯ãã«ããããè¿œå ãããšãæããã«éå°ã«ãªããŸãã
éåžžãæåã®ãªãã·ã§ã³ã¯githubãããžã§ã¯ãã«æé©ã§ãããåæ¥éçºã«ã¯ããŸãé©ããŠããŸããã ç§ãã¡ã®CIã¯ããã¹ããµãŒããŒã§èªåãã¹ããå®è¡ããããã«çšæãããŠãããdevDependencies以å€ã«ãã¹ãã®äŸåé¢ä¿ãç»é²ããå Žæã¯ãããŸããã ããããåé¡ã¯ããã§ã¯ãããŸããããèªåãã¹ããšã¯ç°ãªãããªã³ã¿ãŒçšã®ããŒã«ã¯ãã¹ããµãŒããŒã«è¡ãã¹ãã§ã¯ãããŸããã å°ãªããšããããžã§ã¯ããå±éããããšã30ã®ä»£ããã«200ã¡ã¬ãã€ããè¶
ããééãçªç¶çºçãå§ããŸããããã¯éèŠã§ã¯ãªããšèãã人ãããŸãããPCI DSSæšæºã«æºæ ããããã«ãããããå Žæã§ããªãæ·±å»ãªæå·åã䜿çšããŠããããã 200ã¡ã¬ãã€ãã«ã¯è²ŽéãªæéãããããŸãã ãããã£ãŠãæåã®ãªãã·ã§ã³ãç§ãã¡ã«ã¯é©ããŠããŸããã èŠçŽãããšïŒ
- ãªã³ã¿ãŒãšãã®ãã©ã°ã€ã³ã¯ã°ããŒãã«ã«ç«ã€ã¹ãã§ã¯ãããŸããã
- ç¹å®ã®ãããžã§ã¯ãã¯ãããŒã«ã®ç¹å®ã®ããŒãžã§ã³ã«ãªã³ã¯ããå¿
èŠããããŸãã
- ãããã®ããŒã«ã¯ãäŸåé¢ä¿ãdevDependenciesã«çœ®ããªãã§ãã ããã
äžèŠãããšãç°¡åãªè§£æ±ºçãææ¡ãããŸããããšãã°ãnpmã¹ã¯ãªãããå®è¡ããããšãã°npm run lint-installãå®è¡ãããšãæå®ããããŒãžã§ã³ã®ãã¹ãŠã®ããã±ãŒãžãã³ãã³ãã©ã€ã³ããå
¥åããbashã¹ã¯ãªããããã«ãããŸãã ãããããã®ãããªãœãªã¥ãŒã·ã§ã³ã®äžåšçšãã«å ããŠãäŸåé¢ä¿ã®äžéšïŒéçºäžã®ãã®ã§ã¯ãããïŒãpackage.jsonãå¥ã®bashã¹ã¯ãªããã«æ®ãããšãå€æããŠããŸã...ãããŠãããã¯ãŸã£ããã¯ãŒã«ã§ã¯ãããŸããã ããã«èããŠãpackage.jsonã®ä»æ§ãæãåºããŠãã ããã äžè¬çã«ã誰ãããªããããã«å¥œããªã»ã¯ã·ã§ã³ãè¿œå ããããšãæ°ã«ããŸãã-ããããç§ã¯ç¹å®ã®åºæºã«åŸãããã§ãã
package.jsonä»æ§ãã
ã peerDependenciesã®ãããªããªãå¥åŠã§ãã£ãã«äœ¿çšãããªãã»ã¯ã·ã§ã³ãããããšãæãåºããŠ
ãã ãã ïŒ
å Žåã«ãã£ãŠã¯ããã¹ãããŒã«ãã©ã€ãã©ãªãšããã±ãŒãžã®äºææ§ãè¡šçŸãããããå¿
ããããã®ãã¹ãã®èŠä»¶ãå®è¡ããå¿
èŠã¯ãããŸããã ããã¯éåžžããã©ã°ã€ã³ãšåŒã°ããŸãã ç¹ã«ãããªãã®ã¢ãžã¥ãŒã«ã¯ããã¹ãã®ããã¥ã¡ã³ãã«ãã£ãŠæåŸ
ãããæå®ãããç¹å®ã®ã€ã³ã¿ãŒãã§ãŒã¹ãå
¬éããŠããå¯èœæ§ããããŸãã
èªåçã«èšå®ãããŸããããå°ããªèœãšãç©Žã¯ãããŸãïŒ
泚ïŒnpmããŒãžã§ã³1ããã³2ã¯ãäŸåé¢ä¿ããªãŒã®äžäœã«æ瀺çã«äŸåããŠããªãå ŽåãpeerDependenciesãèªåçã«ã€ã³ã¹ããŒã«ããŸãã npmã®æ¬¡ã®ã¡ãžã£ãŒããŒãžã§ã³ïŒnpm @ 3ïŒã§ã¯ãããã¯åœãŠã¯ãŸããŸããã 代ããã«ãpeerDependencyãã€ã³ã¹ããŒã«ãããŠããªããšããèŠåã衚瀺ãããŸãã npms 1ãš2ã®åäœã¯ãã°ãã°æ··ä¹±ãæããããªããäŸåé¢ä¿ã®å°çã«ç°¡åã«é¥ãããå¯èœæ§ããããŸããnpmsã¯å¯èœãªéãåé¿ããããã«èšèšãããŠããŸãã
幞ããnpmã¯2çªç®ã§ã¯ãªãã£ãã®ã§ãçªç¶ã®çµæãæããããšãªããã®ã»ã¯ã·ã§ã³ãå®å
šã«äœ¿çšã§ããŸããã ããããåé¡ã¯åœŒããåŸ
ããªãã£ããšããããæ¥ãŸãã... peerDependenciesã®ç¡äººã€ã³ã¹ããŒã«ãã¢ã³ã€ã³ã¹ããŒã«ãããšããnpmã®äœè
ã¯ããããæåã§çœ®ãæ¹æ³ãäœããªãããšãå€æããŸããã ãããã£ãŠãpeerDependenciesã»ã¯ã·ã§ã³ã§å©çšã§ããã®ã¯ãããããã€ã³ã¹ããŒã«ãããŠããªããšããèŠåã ãã§ãã ãããã®äŸåé¢ä¿ã¯ãªãã·ã§ã³ã§ãããããã¯éšåçã«èª¬æå¯èœã§ãã ãã®ãããªå€æŽã®åŸããã¹ãŠã®éçºè
ãåçŽã«ãã¹ãŠãdevDependenciesã«ç§»è¡ããã®ã§ã¯ãªãããšçã£ãŠããŸã...ãããŠãäŸåé¢ä¿ã®å°çã¯ãªããªããŸããã§ããã
ã¡ãªã¿ã«ããã®ãããªãªãã·ã§ã³ã®æ¬ åŠã¯ç§ã«ã¯å¥åŠã§ã¯ãªãããã§ããã ããã«ã€ããŠã
åé¡ããããŸã-éããããŠããŸããããããæè¿ãšããŠããŒã¯ãããŠããŸãã ã€ãŸããnpmã®äœæè
ã¯äžè¬ã«ãããããæ±ã§ããããšã«åæããŸã-ä¿®æ£ããã®ã«ååãªæéããããŸãã...
ãã®ãããã»ã¯ã·ã§ã³ããããŸãããã©ã®ããã«äœ¿çšãããã¯æ確ã§ã¯ãããŸããã åãåé¡ã®18ã®ãããã«ã¯ããã®ãããªè§£æ±ºçããããŸãã
npm info . peerDependencies | sed -n 's/^{\{0,1\}[[:space:]]*'\''\{0,1\}\([^:'\'']*\)'\''\{0,1\}:[[:space:]]'\''\([^'\'']*\).*$/\1@\2/p' | xargs npm i
å°çã ãšæãã ããŒã ãªãŒããŒãšããŠãç§ã¯ãããç§ãã¡ã®ãããžã§ã¯ãã«å
¥ãããšãèš±ããŸãã...
äžè¬ã«ããã®ã¢ã€ãã¢ã¯ãpackage.jsonã解æããŠnpm installãåŒã³åºãããšãã§ããããŒã«ãäœæãŸãã¯æ€çŽ¢ããããšãç®æããŠããŸãããäžèšã®ã¹ã¯ãªããã»ã©é£ããã¯ãããŸããã å€ããå°ãªããnpm-install-peersã¯ç§ãæºè¶³ãããã 圌ã«ã¯2ã€ã®ãã€ãã¹ç¹ããããŸãã
- ãªãããã®çç±ã§ã·ã¹ãã ã«npmãã€ã³ã¹ããŒã«ãããŠããªãå ŽåïŒå®éã«ã€ã³ã¹ããŒã«ãããïŒã圌ã¯...ããŒã«ã«ã«åã€ã³ã¹ããŒã«ãããããæéããã©ãã£ãã¯ããããŠããããçš®é¡ã®å°çã®ãããªãšã©ãŒãçºçããŸãã
- 圌ã¯åŒæ°ããµããŒãããŠããŸããã ãŠã£ã³ããŠäžã®ã·ã³ããªãã¯ãªã³ã¯ããã§ã«æå¹ã«ãªã£ãŠããŠã-no-bin-linksãããŸãé¢ä¿ãªãå Žåã¯ã-productionããŸã æãŸããã§ãã åããªã³ã¿ãŒã®äŸåé¢ä¿ã®å Žåãããã«ããã€ã³ã¹ããŒã«æéã倧å¹
ã«ç¯çŽãããŸãã
ããããè¿ãå°æ¥ãåãããšãããããã¢ãžã¥ãŒã«ãšããŠã§ã¯ãªãbashãä»ããŠnpmããã«ããåæ§ã®ã€ã³ã¹ããŒã©ãŒãå®è¡ããã§ãããã ããã¯ããã»ã©çŸãããªããããããŸããããåŒæ°ã§ãã¹ãŠãæ確ã§ããã2åç®ã¯npmãã€ã³ã¹ããŒã«ããå¿
èŠã¯ãããŸããã ãããŠãåŒæ°ãæž¡ããã-å°ãªããšãeslintãšãã®ãã©ã°ã€ã³ããdevDependenciesãã€ã³ã¹ããŒã«ããªãã
次ã«è³ªåãçºçããŸã-å®éã«npm-install-peersãã°ããŒãã«ã«ã€ã³ã¹ããŒã«ããæ¹æ³ã¯ïŒ ããã©ã«ãã§èæ
®ããŸããïŒ ã¹ã¯ãªãããå®è¡ãããšãã«éãã«èšå®ããŸããïŒ devDependenciesã§ããŒã«ã«ã«èšå®ããŸããïŒ ç§ã¯ã©ã®ãªãã·ã§ã³ã奜ãã§ã¯ãããŸããã§ããã ãã®çµæã次ã®ãããªç°¡åãªè§£æ±ºçã«æºè¶³ããŸããã
"lint-install": "npm-install-peers || echo 'Please run npm install -g npm-install-peers first'",
ãã®ãªãã·ã§ã³ã¯ãéçºè
ã«ãšã£ãŠæãééçã§ããããã«æããŸããã
ããšã¯ãå®éã«å¿
èŠãªãªã³ã¿ãŒãšpeerDependenciesãéå§ããã¹ã¯ãªãããè¿œå ããã ãã§ãã ã¹ã¯ãªããïŒ
"lint": "./node_modules/eslint/bin/eslint.js app.js routes modules test App.js"
äŸåé¢ä¿ïŒ
"peerDependencies": { "babel-cli": "^6.23.0", "babel-preset-es2015": "^6.22.0", "eslint": "^3.16.0", "eslint-config-airbnb": "^14.1.0", "eslint-plugin-import": "^2.2.0", "eslint-plugin-jsx-a11y": "^4.0.0", "eslint-plugin-promise": "^3.4.2", "eslint-plugin-react": "^6.10.0", "eslint-plugin-standard": "^2.0.1" }
ã¡ãªã¿ã«ãå¯æ¬¡çãªæ©èœãšããŠãpeerDependenciesã«ããã¹ãã«é¢ä¿ããªãä»ã®ããããçš®é¡ã®äŸåé¢ä¿ïŒããšãã°ãç¥èãª
jsdoc-to-markdownïŒãé
眮ã§ããããã«ãªããŸãã ã
åçŽãªã¿ã¹ã¯ã®ããã«æããŸãããããããçš®é¡ã®èå³æ·±ããã¥ã¢ã³ã¹ãéåžžã«å€ãããšãå€æããŸããã ãããŠãç§ã¯ãããããç°¡åã«ãããè¯ãã§ãããšå®å
šã«èªããŠããŸãã äŒæ¥ãããžã§ã¯ãã«ãªã³ã¿ãŒãã©ã®ããã«äœ¿çšããŸããïŒ