Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

@html-eslint/parser doesn't support eslint-plugin-tailwindcss #211

Open
LatenPath opened this issue Aug 20, 2024 · 5 comments
Open

@html-eslint/parser doesn't support eslint-plugin-tailwindcss #211

LatenPath opened this issue Aug 20, 2024 · 5 comments

Comments

@LatenPath
Copy link

I'm using html-eslint and it works fine:
image

But, then I want to use eslint-plugin-tailwindcss to lint tailwind elements.
image
image
image

It works. But, as you can see, I need to use @angular-eslint/template-parser for HTML file to make Tailwind-eslint worked.
And as I know so far, I'm not able to use both @angular-eslint/template-parser and @html-eslint/parser at the same time.
image

I wonder if I can do something to solve this problem? I would love some advice, thank you all very much.

@yeonjuan
Copy link
Owner

Hi @LatenPath Can you share the configuration? eslint.config.js

@LatenPath
Copy link
Author

LatenPath commented Aug 22, 2024

package.json:

"devDependencies": {
    "@angular-eslint/template-parser": "^18.3.0",
    "@html-eslint/eslint-plugin": "^0.26.0",
    "@html-eslint/parser": "^0.26.0",
    "eslint": "^9.9.0",
    "eslint-plugin-tailwindcss": "^3.17.4",
    "tailwindcss": "^3.4.10",
    "typescript": "~5.5.4",
    "typescript-eslint": "^8.2.0"
}

eslint.config.mjs:

import eslintHTML from "@html-eslint/eslint-plugin";
import eslintTypescript from "typescript-eslint";
import eslintTailwindCSS from "eslint-plugin-tailwindcss";

import eslintHTMLParser from "@html-eslint/parser";
import eslintAngularParser from "@angular-eslint/template-parser";

export default eslintTypescript.config(
//
// HTML plugin configs
{
    "files": [ "**/*.html" ],
    "languageOptions": {
      parser: eslintHTMLParser,
    },
    "plugins": {
      "@html-eslint": eslintHTML,
    },
    "rules": {
     "@html-eslint/require-doctype": 1 // For testing
    }
}
// The above code will run fine alone, below is the code used to run TailwindCSS Eslint
//  (**will cause 'TypeError: Cannot read' error, but will run fine without the above code**)
  // {
  //   "files": [ "**/*.html" ],
  //   "languageOptions": {
  //     parser: eslintAngularParser,
  //   },
  //   "plugins": {
  //     "tailwindcss": eslintTailwindCSS,
  //   },
  //   "rules": {
  //     "tailwindcss/classnames-order": [ 1 ] // For testing
  //   },
  // },
  
// I tried to combine them, but this one will cause an error too:
  // {
  //   "files": [ "**/*.html" ],
  //   "languageOptions": {
  //     parser: eslintHTMLParser,
  //   },
  //   "plugins": {
  //     "@html-eslint": eslintHTML,
  //     "tailwindcss": eslintTailwindCSS,
  //   },
  //   "rules": {
  //     "@html-eslint/require-doctype": 1,
  //     "tailwindcss/classnames-order": [ 1 ],
  //   },
  // },
//
);

TailwindCSS Eslint Github link: https://github.com/francoismassart/eslint-plugin-tailwindcss
Thank you for your support.

@yeonjuan
Copy link
Owner

@LatenPath
I've tried to reproduce it, but I don't get an error, only the config after it seems to be applied and the config before it is ignored. I'm not sure if this is the intended behavior in eslint, I'll reach out to the ESLint team about this.

It would be great if you could also share the contents of the HTML file you ran the lint on to reproduce the error.

@LatenPath
Copy link
Author

Let me write the code for our reproduce steps.
This is a simple HTML file for testing:

<div id="dup"></div>
<div class="custom-class"></div>

Step 1: Let's test html-eslint plugin first.
eslint.config.mjs:

// HTML configs
  {
    "files": [ "**/*.html" ],
    "languageOptions": {
      parser: eslintHTMLParser,
    },
     "plugins": {
      "@html-eslint": eslintHTML,
    },
     "rules": {
     "@html-eslint/no-duplicate-id": 2
      }
   }

Ok, it worked!
image

Step 2: Now, comment the config above and test tailwindcss-eslint plugin alone.

// HTML configs
  {
    "files": [ "**/*.html" ],
    "languageOptions": {
      // parser: eslintHTMLParser,
      parser: eslintAngularParser, // import from "@angular-eslint/template-parser"
    },
     "plugins": {
      // "@html-eslint": eslintHTML,
      "tailwindcss": eslintTailwindCSS,
    },
     "rules": {
     // "@html-eslint/no-duplicate-id": 2
     "tailwindcss/no-custom-classname": [ 2 ],
      }
   }

Testing...
It worked!
image
image

Now, let's enable HTML-eslint again to try it out. Will it work with Angular-parser?

// HTML configs
  {
    "files": [ "**/*.html" ],
    "languageOptions": {
      // parser: eslintHTMLParser,
      parser: eslintAngularParser, // import from "@angular-eslint/template-parser"
    },
     "plugins": {
      "@html-eslint": eslintHTML,
      "tailwindcss": eslintTailwindCSS,
    },
     "rules": {
     "@html-eslint/no-duplicate-id": 2
     "tailwindcss/no-custom-classname": [ 2 ],
      }
   }

The result is... nothing changed. No Eslint output error code.
image
Only TailwindCSS plugin worked.

Let's try out with other rules:

"rules": {
     "@html-eslint/no-duplicate-id": 2
     "@html-eslint/element-newline": 2, // NEW
     "tailwindcss/no-custom-classname": [ 2 ],
      }

Now, we have some Eslint output error code.
image

Step 3: Let's change the parser to HTML-parser:

// HTML configs
  {
    "files": [ "**/*.html" ],
    "languageOptions": {
      parser: eslintHTMLParser,
      // parser: eslintAngularParser, 
    },
     "plugins": {
      "@html-eslint": eslintHTML,
      "tailwindcss": eslintTailwindCSS,
    },
     "rules": {
     "@html-eslint/no-duplicate-id": 2
     "tailwindcss/no-custom-classname": [ 2 ],
      }
   }

Unfortunately, only HTML plugin worked alone.
image

So, as the tittle saying, for now html parser doesn't support TailwindCSS.
TailwindCSS is a not bad tool for HTML, it's awesome if their eslint rules can be enabled together with html-eslint rules. Step 3 is the end result that I hope it would happen.

Thanks for your help. If anything is unclear, please let me know.

@yeonjuan
Copy link
Owner

eslint/eslint#18808

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants