eslint-plugin-tailwindcss: [BUG] The plugin does not pick up tailwind configs in projects nested within monorepos
Describe the bug When a frontend project is nested within a monorepo, any linting process run not from the frontend folder does not see the tailwind config. This is especially apparent with VSCode intellisense - the eslint process is run at the project root level, while the tailwind config resides somewhere nested. Since the config is not found the plugin des not pick up any custom colours and other stuff.
To Reproduce Assumed folder structure:
/rootProject
├ package.json
├ /frontend
│ ├ .eslintrc.js
│ ├ package.json
│ ├ tailwind.config.js
- When eslint is run from
rootProjectfolder thetailwind.config.jsis not found. - When eslint is run from
frontendfolder thetailwind.config.jsis found. - eslint process in VSCode is run from
rootProjectand thus does not find thetailwind.config.js.
BTW, the eslint config is picked up and the rules from eslint-plugin-tailwindcss apply - they just don’t use the custom theme and other settings.
Expected behavior Tailwind config is discoverable as long as it is in the same folder with the eslint config.
Environment (please complete the following information):
- VSCode@1.77.3
- eslint@8.37.0
- tailwindcss@3.3.2
- eslint-plugin-tailwindcss@3.11.0
Additional context Seems like this code is the reason for the behaviour: https://github.com/francoismassart/eslint-plugin-tailwindcss/blob/master/lib/util/customConfig.js#L26
The path.resolve() resolves to the rootProject folder, while the config is at rootProject/frontend.
PS. I can make it work if I open the frontend folder in a separate editor window. However it is very inconvenient in a large project.
About this issue
- Original URL
- State: open
- Created 4 years ago
- Reactions: 7
- Comments: 16 (3 by maintainers)
Commits related to this issue
- Fix TailwindCSS setup for monorepo support in IDE https://github.com/francoismassart/eslint-plugin-tailwindcss/issues/241 — committed to bestofjs/bestofjs by michaelrambeau 3 years ago
- Testing updated eslint config for TailwindCSS Problem: classname ordering is getting messed up in monorepos using eslint-plugin-tailwindcss. This is especially a problem when you want to update class... — committed to TryGhost/Ghost by peterzimon a year ago
- Testing updated eslint config for TailwindCSS Problem: classname ordering is getting messed up in monorepos using eslint-plugin-tailwindcss. This is especially a problem when you want to update class... — committed to TryGhost/Ghost by peterzimon a year ago
- Testing updated eslint config for TailwindCSS Problem: classname ordering is getting messed up in monorepos using eslint-plugin-tailwindcss. This is especially a problem when you want to update class... — committed to TryGhost/Ghost by peterzimon a year ago
- Testing updated eslint config for TailwindCSS Problem: classname ordering is getting messed up in monorepos using eslint-plugin-tailwindcss. This is especially a problem when you want to update class... — committed to TryGhost/Ghost by peterzimon a year ago
Do you mind sharing your current
.eslintrc.jsfile?I just fixed a similar issue and this worked for me:
After doing some digging, it looks like the vscode-eslint extension is not passing the context object to the rules when running from a higher level folder. You can confirm this yourself by being in your root project folder and running
npx eslint ./your-packagewhereyour-packageis where the eslint and tailwind config files are and it will lint the whole project without issue.Apparently the solution is the
eslint.workingDirectoriessetting in the workspace.vscode/settings.json. The following config should fix the problem.It’s fairly simple:
In fact I can’t use the workaround, since I use a JSON config.
it works in monorepo thank you soo much!!
This works but I’m not using a monorepo. I’m using the base Vite template from
pnpm create vite.This worked for me when my
pnpm lintscript was complaining that__dirname is not defined in ES module scope@maslennikov I didn’t actually say that this file should be committed. I just provided a solution for correctly configuring the eslint extension.
Whether it is practical or not is subjective and committing this file is a team decision. If your team has decided that shared workspace settings should actually not be shared, then perhaps you can find and suggest a different solution instead of just spreading your (unsolicited) opinion.
For example, a common pattern is to add the
.vscode/settings.jsonfile in.gitignorebut include shared settings in a.vscode/settings.default.jsonso that developers can copy required settings and customize the settings themselves.@lachieh Your suggested workaround with custom
.vscode/settings.jsonwouldn’t be practical for teams working on same monorepo, since custom vscode settings do not normally belong to codebase committed to git.Just for people landing here who have a *.json eslint configuration and are working with a monorepo tool like Nx and wonder how to get this working.
In my case I resolved it by referencing the tailwind-preset library in the monorepo top-level file .eslintrc.json. I still have an issue with the configuration of the IntelliJ EsLint plugin but for the command execution it looks fine. This section in my top-level file looks like this:
@francoismassart Actually no, the commit does not solve the current issue completely. It helps in my case, where I can get rid of the custom config. But if anybody needs to use a json eslint config, refer to a custom tailwind config, and all this done not in the root folder of a project, then it still won’t load the tailwind config properly.
However I’m not sure if it has a solution within the plugin repo - maybe it’s a problem with eslint itself.