【问题标题】:Replace `'react'` with `"react"` eslint(prettier/prettier)将 `'react'` 替换为 `"react"` eslint(prettier/prettier)
【发布时间】:2020-03-15 21:31:18
【问题描述】:

本地环境:

  • IDE:vscode
  • 语言模式:JavasSript React
import React from 'react';

出现语法错误信息:

Replace `'react'` with `"react"`eslint(prettier/prettier)

如何配置?


.eslintrc.js

module.exports = {
  root: true,
  extends: '@react-native-community',
  rules: {
    quotes: [1, 'single'],
  }
};

感谢您的回答。 Rules可以解决

但我想知道@react-native-community 来自哪里。我没有看到这个文件。

【问题讨论】:

    标签: javascript reactjs react-native eslint tslint


    【解决方案1】:

    你可以试试这样的东西,它对我有用。

    package.json

      "devDependencies": {
        "eslint-plugin-prettier": "^3.1.1",
        "prettier": "^1.18.2"
      },
    

    .eslintrc

    {
      "extends": "react-app",
      "plugins": ["prettier"],
      "rules": {
        "prettier/prettier": "error"
      }
    }
    

    .prettierrc

    {
      "semi": false,
      "trailingComma": "all",
      "singleQuote": true,
      "printWidth": 80,
      "tabWidth": 3
    }
    

    【讨论】:

      【解决方案2】:

      查看文档here。它指定了 singleQuote 选项,可以在 prettier 的配置文件或 package.json 中配置,即:

      "prettier": {
          "singleQuote": true
      }
      

      其他配置选项,请看here

      【讨论】:

        【解决方案3】:

        在 eslint/prettier 配置中,你启用了double quotes

        检查以下内容:

        • 转到 vscode 设置 (ctrl + ,) (cmd + ,) 并搜索 single quote 并禁用它。

        【讨论】:

          猜你喜欢
          • 2020-11-01
          • 2021-09-14
          • 2021-05-06
          • 2017-11-25
          • 2021-10-22
          • 2020-12-25
          • 2018-08-22
          • 2022-01-09
          • 2020-08-02
          相关资源
          最近更新 更多