10.24 항해 42일차 TIL

한우석·2021년 10월 24일
0

eslint를 적용하다가 계속 에러가 나서 결국 다시 처음부터 정리를 해보았다.


1. npx eslint —init

  • To check syntax, find problems, and enforce code style

    √ How would you like to use ESLint? · style
    √ What type of modules does your project use? · esm
    √ Which framework does your project use? · react
    √ Does your project use TypeScript? · No
    √ Where does your code run? · browser
    √ How would you like to define a style for your project? · guide
    √ Which style guide do you want to follow? · airbnb
    √ What format do you want your config file to be in? · JavaScript

    √ Would you like to install them now with npm? · Yes

2. npm install prettier --save-dev --save-exact

  • prettier npm 설치

3. prettierrc.json 만들기

// prettierrc.json
{ 
    "arrowParens": "always", 
    "bracketSpacing": true, 
    "htmlWhitespaceSensitivity": "css", 
    "insertPragma": false, 
    "bracketSameLine": false, 
    "jsxSingleQuote": false, 
    "printWidth": 80, 
    "proseWrap": "preserve", 
    "quoteProps": "as-needed", 
    "requirePragma": false, 
    "semi": true, 
    "singleQuote": true, 
    "tabWidth": 2, 
    "trailingComma": "all", 
    "useTabs": false, 
    "vueIndentScriptAndStyle": false 
}

4. npm install eslint-config-prettier eslint-plugin-prettier --save-dev

  • plugin 설치

5. eslintrc.js 설정

// eslintrc.js
module.exports = {
  env: {
    browser: true,
    node: true,
    es2021: true,
  },
  extends: [
    'plugin:react/recommended',
    'airbnb',
    'plugin:prettier/recommended',
  ],
  parserOptions: {
    ecmaFeatures: {
      jsx: true,
    },
    ecmaVersion: 12,
    sourceType: 'module',
  },
  plugins: ['react', 'prettier'],
  rules: {
    'react/jsx-filename-extension': [
      'error',
      {
        extensions: ['.js', '.jsx'],
      },
    ],
    'prettier/prettier': [
      'error',
      {
        endOfLine: 'auto',
      },
    ],
    'no-console': 'off',
  },
};

여기까지 하니 정상적으로 적용이 되었다.

profile
H/W 개발자에서 프론트 엔드 개발자로 전향 하고 있는 초보 개발자

0개의 댓글