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

[Feature request] cjs config extension support #190

Closed
taep96 opened this issue Dec 19, 2022 · 4 comments
Closed

[Feature request] cjs config extension support #190

taep96 opened this issue Dec 19, 2022 · 4 comments
Labels
enhancement New feature or request feedback needed

Comments

@taep96
Copy link

taep96 commented Dec 19, 2022

In projects that have "type": "module" set in package.json, you have to use tailwind.config.cjs instead of tailwind.config.js, since TainwindCSS config doesn't support ES modules. Can you also check for .cjs config files by default, so there is no need to set the option?

@taep96 taep96 added the enhancement New feature or request label Dec 19, 2022
@taep96 taep96 changed the title cjs config extension support [Feature request] cjs config extension support Dec 19, 2022
@ChristianIvicevic
Copy link

This would be marvelous. It took me some time to understand why the plugin would report false positives after migrating to .cjs. Right now I have to repeat myself in my custom config as follows:

// This mixin applies some additional checks for projects using Tailwind.
module.exports = {
  plugins: [
    // Plugin documentation: https://www.npmjs.com/package/eslint-plugin-tailwindcss
    'eslint-plugin-tailwindcss'
  ],
  overrides: [
    {
      // Declare an override that applies to TypeScript files only
      files: ['*.ts', '*.tsx'],
      rules: {
        'tailwindcss/classnames-order': ['warn', { config: 'tailwind.config.cjs' }],
        'tailwindcss/enforces-negative-arbitrary-values': 'warn',
        'tailwindcss/enforces-shorthand': 'warn',
        'tailwindcss/migration-from-tailwind-2': 'warn',
        'tailwindcss/no-arbitrary-value': 'off',
        'tailwindcss/no-custom-classname': ['warn', { config: 'tailwind.config.cjs' }],
        'tailwindcss/no-contradicting-classname': 'error'
      }
    }
  ]
};

@taep96
Copy link
Author

taep96 commented Jan 17, 2023

You can actually specify your config file in the top level settings option. Also consider extending from the recommended config which has the exact same rules set as your's.

Example .eslintrc:

{
    "extends": ["plugin:tailwindcss/recommended"],
    "settings": {
        "tailwindcss": {
            "config": "./tailwind.config.cjs"
        }
    },
    "rules": {
        // Other options here
    }
}

@francoismassart
Copy link
Owner

@taep96 & @ChristianIvicevic
Did you try this issue against the 3.12.0 or 3.12.1 ?
It might be fixed.
please let me know.

@taep96
Copy link
Author

taep96 commented May 31, 2023

Afaik .cjs is only used when ESM/TS can't be so this issue isn't valid anymore unless I'm missing something.

@taep96 taep96 closed this as completed May 31, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request feedback needed
Projects
None yet
Development

No branches or pull requests

3 participants