10.24便42日間TIL


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
  • きれいな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',
      },
    };
    ここまですれば、正常に適用されます.