Closed9

export default を eslint で落としたい

tkttkt
module.exports = {
  extends: [
    "eslint:recommended",
    "plugin:react/recommended",
    "plugin:@typescript-eslint/recommended",
    "prettier",
  ],
  plugins: ["react", "@typescript-eslint"],
  rules: {
    "import/no-default-export": "error",
    
  },
  env: {
    browser: true,
    commonjs: true,
    es6: true,
    node: true,
  },
  settings: {
    react: {
      version: "detect",
    },
  },
};

こんな感じで書いたけど効かない

tkttkt

import の plugin が必要とかな気がする?

tkttkt
  "devDependencies": {
    "@types/jest": "^26.0.24",
    "@types/react": "17.0.9",
    "@types/react-headroom": "^2.2.1",
    "@types/react-helmet": "^6.1.0",
    "@types/rebass": "^4.0.9",
    "@typescript-eslint/eslint-plugin": "^4.26.0",
    "@typescript-eslint/parser": "^4.26.0",
    "eslint": "^7.28.0",
    "eslint-config-prettier": "^8.3.0",
    "eslint-plugin-import": "^2.23.4",
    "eslint-plugin-react": "^7.24.0",
    "eslint-plugin-simple-import-sort": "^7.0.0",
    "jest": "^27.0.6",
    "prettier": "^2.3.1",
    "ts-jest": "^27.0.4",
    "typescript": "4.3.2"
  }

package には入ってた

tkttkt
module.exports = {
  extends: [
    "eslint:recommended",
    "plugin:react/recommended",
    "plugin:@typescript-eslint/recommended",
    "prettier",
  ],
  plugins: ["react", "@typescript-eslint", "import"],
  rules: {
    "import/no-default-export": "error",
  },
  env: {
    browser: true,
    commonjs: true,
    es6: true,
    node: true,
  },
  settings: {
    react: {
      version: "detect",
    },
  },
};

plugin にも入れた

tkttkt

extends の方に上書きされてるとかかな

tkttkt

extends を comment out しても同じだった

tkttkt

.eslintrc.js ではなく eslint.js に書き込んでた。
まぬけ

tkttkt
module.exports = {
  extends: [
    "eslint:recommended",
    "plugin:react/recommended",
    "plugin:@typescript-eslint/recommended",
    "prettier",
  ],
  plugins: ["@typescript-eslint", "import", "react", "simple-import-sort"],
  rules: {
    // 1: Turn off rules that are no longer necessary in React 17 and in Next.js
    "react/jsx-uses-react": "off",
    "react/react-in-jsx-scope": "off",
    "react/prop-types": "off",
    "import/no-default-export": "error",
  },
  overrides: [
    // Next.js needs default exports for pages and API points
    {
      files: ["*/pages/*", "*/pages/api/*"],
      rules: {
        "import/no-default-export": "off",
        "import/prefer-default-export": "error",
      },
    },
  ],
  env: {
    browser: true,
    commonjs: true,
    es6: true,
    node: true,
  },
  settings: {
    react: {
      version: "detect",
    },
  },
};

nextjs の場合、pages は default export する必要があるので、そこだけ override してる

このスクラップは2021/11/04にクローズされました