-
-
Notifications
You must be signed in to change notification settings - Fork 44
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
Disable PugPrinter:formatText vue's specific warnings #172
Comments
There is one problem with that: It's more "you may ignore this message" instead of "can" We already thought about flags for vue and angular, but until now we tried to avoid these flags You should add a comment on #109 (it's now in GitHub's new little sidenote: I'm currently making a bit like holiday from working on GitHub, just responding here and there. Will effectively work again starting January 2021 |
Yeah, my point is to have a flag for Vue to disable these warning who aren't an actual problem, because vue. It wouldn't be a problem if they were printed only one time but because of Nuxt hot reload they are literally spamming and polluting our terminal. It may be a specific problem thought. I'll check the Discussion and add a little comment linking to this issue. Aren't we all ? Thanks for the quick response and enjoy your holidays |
Thinking about this futher, should I just implement a The default would still be 'info', but this way you could set it to e.g. 'error'. What do you think? What would be the at least okay-ish version for you to be satisfied? |
Hello, Sorry for the delay. I don't think it is a good solution to off all warnings. Some might be very useful. |
@bsiguret Thank you. |
[Leaving a breadcrumb here for anyone else that stumbles across this.] I've worked around this issue by monkey-patching the Logger class thusly: const { default: PugLogger } = await import('@prettier/plugin-pug/dist/logger');
const {message: originalMessage} = PugLogger.Logger.prototype
PugLogger.Logger.prototype.message = function(level, message, ...optionalParams) {
// Ignore "debug" log messages
if (level <= 0) return;
// Default logging behavior
originalMessage.call(this, level, message, ...optionalParams);
} While this is a terrible solution for all sorts of reasons, it does solve the two problems I have, which are:
'Would love to see a more official API for injecting a custom logger here, but I'm not actually sure what the cleanest way to do that is. |
@broofa Oh wow! You gave me a wonderful idea! // @ts-check
/// <reference path="node_modules/@prettier/plugin-pug/src/prettier.d.ts" />
const pluginPug = require('@prettier/plugin-pug');
pluginPug.logger.setLogLevel(1); // Should be possible to e.g. pass `'ERROR'` or so
/**
* @type {import('prettier').Options}
*/
module.exports = {
plugins: [
require.resolve('@prettier/plugin-pug'),
],
singleQuote: true,
trailingComma: 'all',
pugSingleQuote: false,
// ...
}; I tried it out locally by manually writing into |
Any way this could be made configurable via one of the JSON config file options? JS-based config files suffer from a number of issues:
Edit to add: It would also be nice to be have a way of injecting a custom logger. And have a well-defined structure for log messages. E.g. {
message : string,
level : number,
filepath ?: string,
line ?: number,
column ?: number,
excerpt ?: string
} ... something like that. (The end goal here being that callers would have a way to understand and route log messages to other services rather than them always going to stdout.) |
I highly assume that is not well possible, because the logger may run in a context where you have no access to the options. The logger is currently build in a way that it is for the whole plugin. With your request to have the possibility to pass a custom logger we would be totally out of config-via-json at all. You have full TS / autocomplete support for cjs files when using That all said... I like your idea of having it possible to configure your own logger, your own level and set that via One problem I have is: make a total solution and solve it finally (prettier/prettier#11078) or it is over engineered for a single plugin like mine. /cc @thorn0 A "programmatic" logger api for prettier plugins may also solve #172 (comment), because we could implement it so that you can consume the warning and filter on it or something like that. I have so many ideas but I don't want to start it if it is not worth it at the end because this could be very time consuming, theoretically a whole new project to manage and at the end I'm afraid that it could be over engineered. |
For context, I'm coming at this problem from the perspective of the work we're doing here at CodePen, where we do file processing on behalf of the user. I.e. We run user-supplied content through prettier(+pug) programatically. And, because we want to provide structured feedback to the user about any issues we might find anything a plugin output to the console is either a) log noise that we probably don't care about, or b) issues that we need to capture and surface to the user (e.g. as "squiggly-red-lines" under the offending content).
💯 agree here. Definitely seems like the sort of thing that should be common across all plugins. |
So do you just want to disable Lines 111 to 112 in d07b9f5
But actually this was already helpful for me in the past as I could identify some issue problems with that debugging more easily, that is why I debug it The initial issue description also mentioned warnings like |
In looking further at this... in our case... yeah, that would probably make sense. See below.
There are two categories of errors/warnings we care about:
That latter category are what I would call "fatal errors" - they're errors that prevent the the user content from being linted or formatted - and, as expected, take the form of thrown exceptions. Which is great. That's exactly as expected. The former category - "lint" errors - are also being thrown as exceptions, but they're... weird. For example, if there's a missing quote (") in the input,
The most obvious issue here is that Error: Pug:1:52
> 1| div.text( color = primary", disabled ="true" )
----------------------------------------------------------^
The end of the string reached with no closing bracket ) found.
at ... <long stacktrace deleted>... {
code: 'PUG:NO_END_BRACKET',
msg: 'The end of the string reached with no closing bracket ) found.',
line: 1,
column: 52,
filename: test.pug,
src: 'div.text( color = primary", disabled ="true" )',
toJSON: [Function (anonymous)]
} Anyhow... to answer your original question about disabling logging: Yes, given that the errors we care about are actually being thrown as exception, rather than being logged, we could probably just disable logging altogether in our case. (That said, it's odd that lint errors get thrown as exceptions. Generally speaking, "linting" can involve more than one error, so you typically want to handle things in a way that allows for that, which throwing doesn't. Other tools I've worked with will return a data structure that looks something like |
I will test out to implement a solution to set logging via env variable, need to test if it's possible to set from outside somehow. You mentioned lint errors... that confuses me a bit. |
@broofa I created a { "@prettier/plugin-pug": "2.1.0-rework-logging-feature.1" } For details, see the PR // .prettierrc.cjs
import { logger, LogLevel } from '@prettier/plugin-pug'
logger.setLogLevel(LogLevel.OFF)
// ... |
I only mean "lint" in the sense that
If this is the case, then |
@broofa So 2 working days are passed, did you tried it yet? Does it work as expected? |
@Shinigami92 Apologies for the delay. 'Trying to use your new version but it's complaining about
[Edit to add: I think this is due to TS enum's not being defined by default... unless you make them |
I'm able to set the log level using a string, though - e.g. |
@broofa I (hopefully) fixed the LogLevel by removing the const and released v2.1.0 |
Looks good now. Thanks! |
Request / Idea
Make a way to be able to disable these kind of warning:
If you are using Vue, you can ignore this message
Additional Context
Hello,
First of all sorry if it's existing already but I couldn't find a way to do this. We are working on Vue with pug template and Nuxt. Our problem is that Pug warning are spamming our terminal every time our site hot reload with this type of messages:
[PugPrinter:formatText]: Missing expected ). If you are using Vue, you can ignore this message. code:
I thought there would be an option to disable these vue's specifics warning but I couldn't find it
The text was updated successfully, but these errors were encountered: