有没有办法在JSX类名字符串中去掉多余的空格?

huangapple go评论84阅读模式
英文:

Is there any way to remove extra white space in JSX classname strings?

问题

我在WebStorm中使用React和Tailwind。如何配置ESLint或Prettier以自动删除JSX类名字符串中“text-3xl”和“font-bold”之间的额外空格?

我尝试了我能想到的所有ESLint和Prettier插件,包括' eslint-plugin-tailwindcss '和' prettier-plugin-tailwindcss '。

以下是我目前拥有的 .eslintrc.cjs 文件。

我发现这个Github问题,似乎说prettier-plugin-tailwindcss不再支持删除空格。但我感到困惑,因为在我的Vue项目中,这些空格会以某种方式被删除。我不知道为什么它不适用于React,但我怀疑这是因为Prettier会删除Vue模板中的额外空格,其中可以使用'class'属性,而不是React中的'classname'属性。

英文:

I'm using React and Tailwind in WebStorm. How can I configure ESLint or Prettier to automatically remove the extra whitespace between 'text-3xl' and 'font-bold' in the JSX classname string below?

<h1 className="text-3xl     font-bold underline"> Intake Page</h1>

I've tried all the ESLint and Prettier plugins I can think of including 'eslint-plugin-tailwindcss' and 'prettier-plugin-tailwindcss'.

Below is the.eslintrc.cjs file I have at this moment.

module.exports = {
  env: {
    browser: true,
    es2021: true,
  },
  extends: [
    "eslint:recommended",
    "plugin:react/recommended",
    "standard-with-typescript",
    "plugin:prettier/recommended",
    "plugin:tailwindcss/recommended",
  ],
  overrides: [],
  parserOptions: {
    ecmaVersion: "latest",
    sourceType: "module",
    project: "./tsconfig.json",
    ecmaFeatures: {
      jsx: true,
    },
  },
  plugins: ["react"],
  rules: {
    "react/react-in-jsx-scope": "off",
  },
};

I found this Github issue which seems to say that the whitespace removal is no longer supported by prettier-plugin-tailwindcss. But I'm confused because that space somehow gets removed in my Vue projects. I don't know why it doesn't work with React, but I suspect it's because Prettier removes the extra spaces in Vue templates where the 'class' prop can be used, as opposed to the 'classname' prop in React.

答案1

得分: 3

prettier-plugin-tailwindcss 曾经可以修整类名以去除空格,但现在不能了。请查看这个Github问题

英文:

prettier-plugin-tailwindcss has been able to trim the classname to remove whitespace but now it no longer can. Check this Github issue

huangapple
  • 本文由 发表于 2023年2月14日 22:24:52
  • 转载请务必保留本文链接:https://go.coder-hub.com/75449218.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定