# ESLint와 Prettier μ„€μ • ν•˜κΈ°

νŒ€ ν”„λ‘œμ νŠΈμ—μ„œ λ·°λ₯Ό κ°œλ°œν•  λ•Œ μ½”λ“œλ₯Ό μΌκ΄€μ μœΌλ‘œ μž‘μ„±ν•˜κ³  μ—λŸ¬λ₯Ό 덜 λ‚˜κ²Œ ν•˜λŠ” 방법이 μžˆμŠ΅λ‹ˆλ‹€. λ°”λ‘œ ESLint + Prettier ν”ŒλŸ¬κ·ΈμΈμ„ μ‚¬μš©ν•˜λŠ” λ°©λ²•μΈλ°μš”. 이 2개 도ꡬ에 λŒ€ν•œ μžμ„Έν•œ μ„€λͺ…κ³Ό μ„€μ • 방법은 λ‹€μŒ 글을 μ°Έκ³ ν•©λ‹ˆλ‹€.

# ESLint에 Vue.js 곡식 μŠ€νƒ€μΌ κ°€μ΄λ“œλ₯Ό μ μš©ν•˜λŠ” 방법

μœ„ λΈ”λ‘œκ·Έ κΈ€μ—μ„œ μ•ˆλ‚΄λœ 것 이외에도 Vue.js 곡식 μŠ€νƒ€μΌ κ°€μ΄λ“œ (opens new window)λ₯Ό ESLint 룰에 μ μš©ν•˜μ—¬ μ‚¬μš©ν•˜λŠ” 방법이 μžˆμŠ΅λ‹ˆλ‹€.

λ¨Όμ € λ·° ν”„λ‘œμ νŠΈμ˜ 루트 디렉토리에 μžˆλŠ” .eslintrc 파일의 extendsλ₯Ό μ•„λž˜μ™€ 같이 μˆ˜μ •ν•©λ‹ˆλ‹€.




Β 


Β 
Β 
Β 



module.exports = {
  // ...
  extends: [
		// 'plugin:vue/essential',
		'@vue/prettier',
		'@vue/typescript',
		'plugin:import/errors',
		'plugin:import/warnings',
		'plugin:vue/recommended',
	],
}

그리고 λ‚˜μ„œ 같은 파일의 rules 속성에 μ•„λž˜μ˜ λ‚΄μš©μ„ μΆ”κ°€ν•΄μ€λ‹ˆλ‹€.

module.exports = {
  rules: {
    /**********************/
    /* General Code Rules */
    /**********************/

    // Enforce import order
    'import/order': 'error',

    // Imports should come first
    'import/first': 'error',

    // Other import rules
    'import/no-mutable-exports': 'error',

    // Allow unresolved imports
    'import/no-unresolved': 'off',

    // Allow async-await
    'generator-star-spacing': 'off',

    // Prefer const over let
    'prefer-const': [
      'error',
      {
        destructuring: 'any',
        ignoreReadBeforeAssign: false,
      },
    ],

    // No single if in an "else" block
    'no-lonely-if': 'error',

    // Force curly braces for control flow,
    // including if blocks with a single statement
    curly: ['error', 'all'],

    // No async function without await
    'require-await': 'error',

    // Force dot notation when possible
    'dot-notation': 'error',

    'no-var': 'error',

    // Force object shorthand where possible
    'object-shorthand': 'error',

    // No useless destructuring/importing/exporting renames
    'no-useless-rename': 'error',

    /**********************/
    /*     Vue Rules      */
    /**********************/

    // Disable template errors regarding invalid end tags
    'vue/no-parsing-error': [
      'error',
      {
        'x-invalid-end-tag': false,
      },
    ],

    // Maximum 5 attributes per line instead of one
    'vue/max-attributes-per-line': [
      'error',
      {
        singleline: 5,
      },
    ],

    /***************************/
    /* ESLint Vue Plugin Rules */
    /***************************/
    'vue/html-indent': [
      'error',
      'tab',
      {
        attribute: 1,
        baseIndent: 1,
        closeBracket: 0,
        alignAttributesVertically: true,
        ignores: [],
      },
    ],

    'vue/order-in-components': [
      'error',
      {
        order: [
          'el',
          'name',
          'parent',
          'functional',
          ['delimiters', 'comments'],
          ['components', 'directives', 'filters'],
          'extends',
          'mixins',
          'inheritAttrs',
          'model',
          ['props', 'propsData'],
          'fetch',
          'asyncData',
          'data',
          'computed',
          'watch',
          'LIFECYCLE_HOOKS',
          'methods',
          'head',
          ['template', 'render'],
          'renderError',
        ],
      },
    ],

    'vue/html-self-closing': ['off'],

    // https://eslint.vuejs.org/rules/attributes-order.html
    // TODO: νŒ€ λ‚΄ κΈ°μ€€μœΌλ‘œ μž¬μ‘°μ • ν•„μš”
    'vue/attributes-order': [
      'error',
      {
        order: [
          'DEFINITION',
          'LIST_RENDERING',
          'CONDITIONALS',
          'RENDER_MODIFIERS',
          'GLOBAL',
          'UNIQUE',
          'TWO_WAY_BINDING',
          'OTHER_DIRECTIVES',
          'OTHER_ATTR',
          'EVENTS',
          'CONTENT',
        ],
      },
    ],
  },
}

μ΄λ ‡κ²Œ μž‘μ„±ν•œ ESLint의 κ·œμΉ™μ΄ ν”„λ‘œμ νŠΈμ— 적용되렀면 λ·° ν”„λ‘œμ νŠΈμ— μ•„λž˜μ™€ 같이 κ΄€λ ¨ λΌμ΄λΈŒλŸ¬λ¦¬κ°€ μ„€μΉ˜λ˜μ–΄μ•Ό ν•©λ‹ˆλ‹€.

{
  "eslint-config-standard": "^14.1.0",
  "eslint-plugin-import": "^2.18.2",
  "eslint-plugin-promise": "^4.2.1",
  "eslint-plugin-standard": "^4.0.1",
}

# 참고 자료