saadeghi / daisyui

🌼 🌼 🌼 🌼 🌼  The most popular, free and open-source Tailwind CSS component library
https://daisyui.com
MIT License
33.75k stars 1.29k forks source link

Prettier and daisyui #1413

Closed nvsd closed 1 year ago

nvsd commented 1 year ago

For some reason daisyui's logs are getting prepended to files by prettier on save.

I use nvim as my editor, I tried vscode and can't reproduce there.


🌼 daisyUI components 2.42.1  https://github.com/saadeghi/daisyui
  ✔︎ Including:  base, components, themes[2], utilities

/** @type {import('tailwindcss').Config} */
module.exports = {
            content: ["./src/**/*.{js,ts,jsx,tsx}"],
            theme: {
                extend: {},
            },
            plugins: [
                require("@headlessui/tailwindcss"),
                require("@tailwindcss/forms"),
                require("daisyui"),
            ],
        };
saadeghi commented 1 year ago

The logs should be printed on terminal, not the file.
I don't know how, but something seems wrong about your environment, or tools or editor config.

Maybe if you provide a sample repo and steps to reproduction, I can help...

Any way, you can safely disable daisyUI logs from the config: https://daisyui.com/docs/config/#logs

Let me know if you have any questions.

saadeghi commented 1 year ago

I wish I could help but I really can't do anything about it because the issue is not from daisyUI.
Basically daisyUI just has 2 lines of console.log to inform the user about the daisyUI version and everything that is included.
It's console.log and it should be in the terminal output. I really don't understand why prettier plugin or the build tool (?) is appending them to the file content. It doesn't make sense 🤷‍♂️

And I'm not even sure if the issue is from the prettier plugin because prettier's job is to format file content not to append anything.

rathod-sahaab commented 1 year ago

I use neovim with null-ls

This occurs because neovim uses lua; hence, we cannot use prettier JS API, so formatted code is read from stdout, and daisy logs are also picked up.

Turning logs to false help, @saadeghi only thing you can do is turn logging off by default. I went to null-ls, prettier, tailwind then finally daisy UI page figuring this out took 2 hrs FML😂


/** @type {import('tailwindcss').Config} */
module.exports = {
    content: ['./src/**/*.tsx'],
    theme: {
        extend: {},
    },
    plugins: [require('@tailwindcss/typography'), require('daisyui')],
    daisyui: {
        logs: false,
        themes: ['dark', 'light', 'black', 'corporate', 'garden', 'night'],
    },
}
``
saadeghi commented 1 year ago

@rathod-sahaab the logs are important because daisyUI applies some default style to the project even if you don't use any component class names (for example themes and foreground+background colors for the whole page). So if someone just adds the plugin it should be obvious for them that daisyUI styles are applied for them. And since daisyUI works on build time, that console log is the only way of communicating with the developer.

So, I don't think disabling it by default would be a good idea. Especially when the majority of developers have no issue about it.

I think if the formatted code is read from stdout (as you mentioned) that's just a super lazy solution from the developers of that tool. And it will create further problems as well. For example, Tailwind CSS itself shows warnings on the console log if there's a change on their API and you're still using a deprecated one. That warning and any other console log belongs to terminal. not the file output.

szachy113 commented 1 year ago

I'm facing the same problem. I resolved it by disabling the logs. I don't see any other feasible solution. Thanks for bringing this up, @nvsd!

joekrall commented 3 months ago

I've had success using prettierd with conform.nvim, installed with Mason. The logs are not prepended as prettierd runs a server. ~As a project, it looks unmaintained right now.~ Apologies, wrong project. prettier_d is not maintained. prettierd looks alive and well and is used in the Mason registry.