francoismassart / eslint-plugin-tailwindcss

ESLint plugin for Tailwind CSS usage
https://www.npmjs.com/package/eslint-plugin-tailwindcss
MIT License
1.44k stars 66 forks source link

[BUG] Error while loading rule 'tailwindcss/no-custom-classname' #234

Open mafikes opened 1 year ago

mafikes commented 1 year ago

Describe the bug I updated eslint-plugin-tailwindcss to the latest version and getting error below:

Internal server error: Error while loading rule 'tailwindcss/no-custom-classname': <css input>:43:22: Unknown word

To disable no-custom-classname without change or help. I need to disable all plugin to finish my build process.

To Reproduce npm run lint

Environment:

eslint config file I use default eslint setup from tailwindcss as "warn"

// .eslintrc.js
module.exports = {
  extends: [
    "eslint:recommended",
    "plugin:@typescript-eslint/eslint-recommended",
    "plugin:vue/vue3-recommended",
    "plugin:tailwindcss/recommended",
    "prettier",
  ],
  parser: "vue-eslint-parser",
  parserOptions: {
    ecmaVersion: "latest",
    sourceType: "module",
    parser: "@typescript-eslint/parser",
  },
  plugins: ["unused-imports", "vue", "@typescript-eslint"],
  rules: {
    "vue/component-tags-order": [
      "error",
      {
        order: ["script", "template", "style"],
      },
    ],
    "vue/multi-word-component-names": "off",
    "vue/component-api-style": ["error", ["script-setup", "composition"]],
    "vue/component-name-in-template-casing": "error",
    "vue/block-lang": [
      "error",
      {
        script: { lang: "ts" },
      },
    ],
    "vue/define-macros-order": [
      "warn",
      {
        order: ["defineProps", "defineEmits"],
      },
    ],
    "vue/define-emits-declaration": ["error", "type-based"],
    "vue/define-props-declaration": ["error", "type-based"],
    "vue/match-component-import-name": "error",
    "vue/no-ref-object-destructure": "error",
    "vue/no-unused-refs": "error",
    "vue/no-useless-v-bind": "error",
    "vue/padding-line-between-tags": "warn",
    "vue/prefer-separate-static-class": "error",
    "vue/prefer-true-attribute-shorthand": "error",
    "vue/no-v-html": "off",
    "vue/no-v-text-v-html-on-component": "off",

    "no-undef": "off",
    "no-unused-vars": "off",
    "no-console": ["warn"],
  },
  ignorePatterns: ["*.d.ts"],
}
mafikes commented 1 year ago

I fix this issue with adding cssFiles strictly to the no-custom-classname rule.

It was working fine before update.

// .eslintrc.js
"tailwindcss/no-custom-classname": ["warn", {
  cssFiles: [
    "resources/css/app.css",
    "resources/css/editor.css",
    "resources/css/font-delivery.css"
  ]
}],
francoismassart commented 1 year ago

Hi @mafikes Can you share a demo repo so that I can take a look at it ?

Bosphoramus commented 1 year ago

Happening to me too

akegvd commented 1 year ago

It happened to me too. But I can fix that.

In my case I use .scss and it has the code comment start with // some comment (double slash), when I remove It or replace it with /* some comment */ and rerun eslint, it's back to work.

in my main.scss file

❌Bad
// components
@import "./components/button";

✅ Good
/** components */
@import "./components/button";
paix26875 commented 1 year ago

It happened to me too.

Livijn commented 4 months ago

Got the same error but I want to enable custom classes so I just disabled the error: "tailwindcss/no-custom-classname": "off"

mirite commented 4 months ago

No clue why, but simply having the cssFiles parameter present fixed it for me. The problem seemed to start after switching to the flat config. This works and is still checking the tsx files.

    ...compat.config({
        plugins: ["eslint-plugin-tailwindcss"],
        extends: ["plugin:tailwindcss/recommended"],
        rules: {
            "tailwindcss/classnames-order": "off",
            "tailwindcss/no-custom-classname": [
                "warn",
                {
                    callees: ["twMerge"],
                    cssFiles: [],
                },
            ],
        },
    }),