【发布时间】:2020-09-01 18:18:31
【问题描述】:
当我使用 jsx pragma 时,如何阻止 eslint 抛出错误。
我正在使用 airbnb 配置,我尝试将 "react/jsx-uses-react": 1, 添加为一条无效的规则。
使用airbnb时需要在extends中包含plugin:react/recommended吗?
.eslintrc.js
extends: [
"airbnb",
"airbnb/hooks",
"plugin:react-redux/recommended",
"plugin:prettier/recommended",
"prettier/react",
],
settings: {
react: {
version: "detect",
},
},
plugins: ["emotion", "graphql", "prettier", "react-redux"],
rules: {
"emotion/jsx-import": "error",
"emotion/no-vanilla": "error",
"emotion/import-from-emotion": "error",
"emotion/styled-import": "error",
"react/jsx-filename-extension": [1, { extensions: [".js", ".jsx"] }],
"graphql/template-strings": [
`error`,
{
env: `relay`,
tagName: `graphql`,
},
],
},
layout.js
/* ESLint: 'React' is defined but never used.(no-unused-vars) */
import React from "react"
import PropTypes from "prop-types"
import { useStaticQuery, graphql } from "gatsby"
/** @jsx jsx */
import { Global, css, jsx } from "@emotion/core"
import { ThemeProvider } from "emotion-theming"
【问题讨论】:
-
@Fryla-CristianMarucci 你是否建议我需要添加 babel-plugin-transform-react-jsx?
-
是的,我认为值得一试。
标签: reactjs jsx emotion eslint-config-airbnb airbnb-js-styleguide