简体   繁体   中英

Replace `'react'` with `“react”` eslint(prettier/prettier)

Local environment:

  • IDE: vscode
  • Language mode: JavasSript React
import React from 'react';

A syntax error message appears:

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

How can I configure it?


in .eslintrc.js

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

Thank you for your answer. Rules can be solved

But I want to know where @react-native-community comes from. I didn't see this file.

You can try something like this, it works for me.

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
}

Have a look at the documentation here . It specifies the singleQuote option, which could be configured in a configuration file for prettier or in the package.json, ie:

"prettier": {
    "singleQuote": true
}

For other options of configuration, have a look here .

You can do the configuration by adapting .eslintrc within your project. The error above is related to the quotes rule .

In eslint/ prettier configuration, you have enabled double quotes .

check the following:

  • goto vscode settings (ctrl +,) (cmd +,) and search for single quote and disable it.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM