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

[BUG] no-custom-classname rule will not honor the project setting for config #212

Closed
davazp opened this issue Feb 17, 2023 · 12 comments
Closed
Assignees
Labels
bug Something isn't working

Comments

@davazp
Copy link

davazp commented Feb 17, 2023

Describe the bug
When I add a project setting like described in the README:

"settings": {
  "tailwindcss": {
    "config": "custom-file"
  }
}

to specify the tailwind config file (in .eslintrc), the no-custom-classname will ignore it.

I can workaround the issue by specifying the rule specific config:

    "tailwindcss/no-custom-classname": [
      "warn",
      {
        // NOTE: There is a bug in the eslint-plugin-tailwindcss
        // library that prevents this rule from seeing the project
        // settings. So until that is fixed, we are forced to specify
        // the config file here.
        //
        // We need to specify the file as an absolute path because
        // eslint runs from the root yarn workspace.
        config: path.join(__dirname, 'tailwind.config.js')
      },

I debugged a little bit and it seems the options of the rule have a default defined.

I think that default shadows the project setting:

const options = context.options[0] || {};
if (options[name] != undefined) {
return options[name];
}
// Settings (defined at plugin level, shared accross rules)
if (context.settings && context.settings.tailwindcss && context.settings.tailwindcss[name] != undefined) {
return context.settings.tailwindcss[name];
}

eslint config file or live demo
Let me know if you need further information, I can work to provide one.

@davazp davazp added the bug Something isn't working label Feb 17, 2023
@isaaccuraErnesto
Copy link

I believe this may be happening with all rules as I'm experiencing the same with both classnames-order and no-custom-classname.

@francoismassart
Copy link
Owner

@davazp & @isaaccuraErnesto ,

Can you try to provide the path to the config in the shared settings via an absolute path ?

// .eslintrc.js
const path = require("path");

...

"settings": {
  "tailwindcss": {
    "config": path.join(__dirname, "custom-file"),
  }
}

@davazp
Copy link
Author

davazp commented Feb 20, 2023

I did try but it doesn't work. Regardless of what I pass in the project setting, the rule config's default shadows the project config.

@francoismassart
Copy link
Owner

Please provide a demo repository and I'll investigate more 😉

@davazp
Copy link
Author

davazp commented Feb 20, 2023

Thanks @francoismassart . I created a sample repository here: https://github.com/davazp/eslint-plugin-tailwindcss-issue-212

You can reproduce it by npm installing it and running npm run lint.

I made a custom file for tailwind config at tailwindcss.custom.js. Then, if you look at the .eslintrc.js:

const path = require('path');

module.exports = {
  plugins: ["tailwindcss"],
  parser: '@typescript-eslint/parser',
  rules: {
    // If we remove the {} options here, it will work. With it, the
    // default for the rule takes over project setting.
    "tailwindcss/no-custom-classname": ["error", {}]
  },
  settings: {
    tailwindcss: {
      config: path.join(__dirname, 'tailwindcss.custom.js')
    }
  }
};

I specify the config. However, the plugin will still think myviolet color is unknown. If you remove the {} from the rule options, then it works.

I hope this helps! Let me know if I can do anything else.

@isaaccuraErnesto
Copy link

@francoismassart I too have tried providing the path to the config file via an absolute path without any luck.

@francoismassart
Copy link
Owner

That is caused by the default value set in the meta block of each rule...

@francoismassart
Copy link
Owner

@davazp & @isaaccuraErnesto
=> npm i eslint-plugin-tailwindcss@3.10.1-beta.4 -D

Waiting for your feedback(s) 😉

@davazp
Copy link
Author

davazp commented Mar 1, 2023

@davazp & @isaaccuraErnesto => npm i eslint-plugin-tailwindcss@3.10.1-beta.4 -D

Waiting for your feedback(s) 😉

The upgrade fixes it for me! Thanks for the work.

@francoismassart
Copy link
Owner

👉 eslint-plugin-tailwindcss@3.10.1

@damianobarbati
Copy link

@francoismassart I'm working in a mono-repository having a top .eslintrc and a nested .eslintrc for the react application, but I see no luck in having the tailwindcss/no-custom-classname rule working.

To test I added the following:

    "tailwindcss/no-custom-classname": ["off", {
      "config": "ciao",
      "cssFiles": ["src/*.css", "src/**/*.css"]
    }]

ciao file does not exist but the plugin does not throw so I'm assuming that it's not picking the configuration.

Any advice? I tried to move every dependency in both folder's package.json with no luck.

@felicio
Copy link

felicio commented Jun 15, 2023

@damianobarbati please, have you ever resolved it or maybe opened a new issue?

felicio added a commit to prichodko/status-web that referenced this issue Jun 16, 2023
felicio added a commit to prichodko/status-web that referenced this issue Jun 20, 2023
felicio added a commit to status-im/status-web that referenced this issue Jun 21, 2023
* add ghost api

* connect blog overview page

* connect and render post detail

* add processing to server

* update blog detail page

* add eslint-plugin-tailwindcss

* add @tanstack/react-query

* truncate text by numberOfLines

* use ComponentPropsWithRef to infer style prop type

* update ghost fns

* update index

* add tag page

* add author page

* update /

* update /tag

* update /author

* update detail page

* fix posts type

* disable redirect

* remove global background

- not found pages
- pages without common layout (preview)

* tmp: hide nav on smaller screens

* update app layout spacing

* remove text truncating

* update / spacing and sizing

* update .vscode/settings.json

* update .eslintrc

* update prettier-plugin-tailwindcss

* sort tailwind classes

* add packages/eslint-config-custom

* use turbo lint

* use tailwind.config.cjs

see francoismassart/eslint-plugin-tailwindcss#212

* reset global line-height

* fix lint-staged

* update color tokens

* update spacing and sizes

* Update apps/website/src/lib/ghost.ts

Co-authored-by: Pavel <14926950+prichodko@users.noreply.github.com>

* update layout max width

* update card min width

* set line-height

* set overflow on pre

* use flex for markdown content to prevent overflow

* collect follow-ups

* add visibility filter

* update page count

* rename var

* remove filter

* use prod ghost api key

* update ghost api

* revert line-height

* add limit to getPosts params

* update visible posts

* add related articles

* add env vars to gh

* rename eslint config package

* update gh vars

* rename envs

* set emtpy array to related posts

* fix lint-staged

* prevent importing server envs on client

* set limit

---------

Co-authored-by: Felicio Mununga <felicio@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

5 participants