Skip to content

ESLint ๊ด€๋ จ

Jin Young Park edited this page Nov 30, 2020 · 1 revision

vue js eslint-loader autofix ์„ค์ • (vue-cli๋กœ ๋งŒ๋“  ํ”„๋กœ์ ํŠธ์—์„œ webpack ์„ค์ •ํ•˜๋Š”๋ฒ•)

vscode์—์„œ saveํ• ๋•Œ๋งˆ๋‹ค eslint, prettier autofix๊ฐ€ ๋˜๋Š”๋ฐ vue js์—์„œ๋Š” waring error๊ฐ€ ๋‚ฌ๋‹ค. image

vscode setting์—์„œ editor.formatOnSave: true ์„ค์ •์„ ํ•ด์ค˜๋„ error๊ฐ€ ๊ณ„์† ๋‚ฌ๋‹ค.

eslint-loader์—์„œ ์—๋Ÿฌ๊ฐ€ ๋‚˜๋Š” ๊ฒƒ์„ ๋ณด๊ณ  ๋‚ด์žฅ๋œ webpack loader์— eslint-loader๊ฐ€ ์žˆ๋Š” ๊ฒƒ์œผ๋กœ ์ƒ๊ฐ๋˜์–ด์„œ ๊ฒ€์ƒ‰์„ ํ•ด๋ณด๋‹ˆ, vue.config.js์—์„œ loader ์„ค์ •์„ ๋ฐ”๊ฟ”์ค„์ˆ˜ ์žˆ์—ˆ๋‹ค.

// vue.config.js
module.exports = {
    chainWebpack: config => {
        config.module
          .rule('eslint')
          .use('eslint-loader')
          .loader('eslint-loader')
          .tap(options => {
              options.fix = true
              return options
          })
      }
}

๋‹ค์Œ๊ณผ ๊ฐ™์ด autofix๋ฅผ ํ•ด์ฃผ๋Š” ์˜ต์…˜์„ ์ ์šฉํ•˜๋‹ˆ error๊ฐ€ ๋”์ด์ƒ ์•ˆ๋œจ๊ฒŒ ๋˜์—ˆ๋‹ค.

reference

cannot find module 'eslint-plugin-vue' ์—๋Ÿฌ ํ•ด๊ฒฐ

.vscode/setting.json์—

"eslint.workingDirectories": [
    ['./client','./server']
  ]

๋ฅผ ์ถ”๊ฐ€ํ•ด์ฃผ๋ฉด ํ•ด๊ฒฐ๋œ๋‹ค.

root/
  client/
    .eslintrc.js
  server/
    .eslintrc.js

ํ˜„์žฌ ํด๋”๊ตฌ์กฐ๊ฐ€ ์œ„์™€๊ฐ™๊ณ  working directory๊ฐ€ root๋ผ์„œ ๋ฐœ์ƒํ•œ ์—๋Ÿฌ ๊ฐ™๋‹ค.

['./client','./server'] ์˜ต์…˜์„ ์ฃผ๋ฉด working directory๊ฐ€ client๋‚ด์—์„œ๋Š” client๋กœ server ๋‚ด์—์„œ๋Š” server๋กœ ๋ฐ”๋€Œ์–ด์„œ ๊ฐ๊ฐ์— ๋งž๋Š” lint๊ฐ€ ์ ์šฉ๋œ๋‹ค.

Delete โ eslint (prettier/prettier) ํ•ด๊ฒฐ๋ฐฉ๋ฒ•

CRLF ๊ด€๋ จ ๋ฌธ์ œ.

eslint rules์— ๋‹ค์Œ ๋ฌธ๊ตฌ๋ฅผ ์ถ”๊ฐ€ํ•ด์ฃผ๋ฉด ๋œ๋‹ค.

    rules: {
        'prettier/prettier': [
            'error',
            {
                endOfLine: 'auto',
            },
        ],
    },
Clone this wiki locally