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

How to use an external plugin with your flat config? #315

Closed
stefanobartoletti opened this issue Nov 7, 2023 · 8 comments
Closed

How to use an external plugin with your flat config? #315

stefanobartoletti opened this issue Nov 7, 2023 · 8 comments

Comments

@stefanobartoletti
Copy link

First of all thanks for this configuration, I'm considering migrating to it since a lot of my custom rules are already covered in the same way here.

I have a single point where I am a bit confused, about correctly using a third-party plugin.

I use eslint-plugin-tailwindcss to keep my class names ordered in my templates, and I'm not exactly sure how should I correctly include it in the configuration.

Accordig to eslint docs, a plugin has to be included like this, i.e.

import jsdoc from "eslint-plugin-tailwindcss";

export default [
    {
        plugins: {
            tailwindcss: tailwindcss
        }
    }
];

But I'm not exactly sure about what is the proper way to use it with your

import antfu from '@antfu/eslint-config'

export default antfu()

Can you provide some insight? Sorry if this may seem trivial

@antfu
Copy link
Owner

antfu commented Nov 7, 2023

import antfu from '@antfu/eslint-config'

export default antfu(
  {},
  {
    plugins: { a },
    rules: { a }
  },
  {
    plugins: { b },
    rules: { b }
  },
  // ...as many as you want, rest args as forwarded as-is.
)

@antfu antfu closed this as completed Nov 7, 2023
@Mat4m0
Copy link

Mat4m0 commented Nov 7, 2023

@stefanobartoletti

I am also struggling with this one ^^'.. Maybe you can post your solution once it’s working for you.

Thanks!

@stefanobartoletti
Copy link
Author

stefanobartoletti commented Nov 7, 2023

Thanks for sharing the answer @antfu 🙏🏻

Even with the correct syntax, it seems that the tailwind plugin itself is not already updated to use the flat config: francoismassart/eslint-plugin-tailwindcss#280

So @Mat4m0 we have to wait I guess.

@Mat4m0
Copy link

Mat4m0 commented Nov 7, 2023

@stefanobartoletti actually in the issue you linked there is a working solution:

import antfu from '@antfu/eslint-config'
import { FlatCompat } from '@eslint/eslintrc'

const compat = new FlatCompat()

export default antfu({}, ...compat.config({
  extends: ['plugin:tailwindcss/recommended'],
  rules: {
    'tailwindcss/no-custom-classname': 'off',
    'tailwindcss/migration-from-tailwind-2': 'off',
  },
}))

@stefanobartoletti
Copy link
Author

I see but it involves another package, I'm not in a hurry and I think I can wait to see if they will update the plugin

@gerbenvandijk
Copy link

For the ones who can't use ESM modules:

const antfu = require('@antfu/eslint-config').default
const { FlatCompat } = require('@eslint/eslintrc')
const compat = new FlatCompat()
module.exports = antfu({}, ...compat.config({
    extends: [ 'plugin:tailwindcss/recommended' ],
    rules: {}
}))

@antfu
Copy link
Owner

antfu commented Nov 9, 2023

Oh thanks for the tip, I didn't know it exists. Added to the readme.

@codeflorist
Copy link

@stefanobartoletti actually in the issue you linked there is a working solution:

import antfu from '@antfu/eslint-config'
import { FlatCompat } from '@eslint/eslintrc'

const compat = new FlatCompat()

export default antfu({}, ...compat.config({
  extends: ['plugin:tailwindcss/recommended'],
  rules: {
    'tailwindcss/no-custom-classname': 'off',
    'tailwindcss/migration-from-tailwind-2': 'off',
  },
}))

Unfortunately this doesn't seem to work anymore with eslint v9.

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

5 participants