|
| 1 | +# Eslint |
| 2 | + |
| 3 | +현재 Vue.js 사용 |
| 4 | + |
| 5 | +## 패키지 설치 |
| 6 | +Vue 팀에서 공식적으로 제공하는 esling-plugin-vue package 다운로드 |
| 7 | + |
| 8 | +```shell |
| 9 | +$ npm install --save-dev eslint @typescript-eslint/parser @typescript-eslint/eslint-plugin |
| 10 | +$ npm install --save-dev eslint-config-prettier eslint-plugin-vue |
| 11 | +``` |
| 12 | + |
| 13 | +## .eslintrc.js |
| 14 | + |
| 15 | +root 하위에 `.eslintrc.js` 파일 생성 |
| 16 | + |
| 17 | +```javascript |
| 18 | +module.exports = { |
| 19 | + root: true, |
| 20 | + env: { |
| 21 | + node: true, |
| 22 | + }, |
| 23 | + extends: [ |
| 24 | + 'plugin:vue/essential', // eslint-plugin-vue 패키지에서 제공 |
| 25 | + 'eslint:recommended', // eslint 에서 권장하는 javascript 코드 규칙 |
| 26 | + '@vue/typescript/recommended', |
| 27 | + '@vue/prettier', |
| 28 | + '@vue/prettier/@typescript-eslint', |
| 29 | + ], |
| 30 | + parserOptions: { |
| 31 | + ecmaVersion: 2020, // ECMAScript Version |
| 32 | + }, |
| 33 | + rules: { |
| 34 | + // add your custom rules here |
| 35 | + } |
| 36 | +}; |
| 37 | +``` |
| 38 | + |
| 39 | +## eslint-plugin-vue 제공 rules |
| 40 | + |
| 41 | +[eslint-plugin-yue](https://eslint.vuejs.org/rules/) 에서 필요한 rules 검색 가능 |
| 42 | + |
| 43 | +### vue/multiline-html-element-content-newline |
| 44 | + |
| 45 | +`plugin:vue/vue3-strongly-recommended`, `plugin:vue/strongly-recommended`, `plugin:vue/recommended` 에 포함된 rule |
| 46 | + |
| 47 | +현재 `plugin:vue/essential` 사용중이어서 적용되지 않고 있었음 |
| 48 | + |
| 49 | +#### default options |
| 50 | + |
| 51 | +```javascript |
| 52 | +{ |
| 53 | + "vue/multiline-html-element-content-newline": ["error", { |
| 54 | + "ignoreWhenEmpty": true, |
| 55 | + "ignores": ["pre", "textarea", ...INLINE_ELEMENTS], |
| 56 | + "allowEmptyLines": false |
| 57 | + }] |
| 58 | +} |
| 59 | +``` |
| 60 | + |
| 61 | +#### rules 적용 |
| 62 | + |
| 63 | +```javascript |
| 64 | +rules: { |
| 65 | + "vue/multiline-html-element-content-newline": 'warn', |
| 66 | +} |
| 67 | +``` |
| 68 | + |
0 commit comments