-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
new API for plugin errors/warnings #177
Comments
Awesome idea! But what should be in Or what error handling process you suggest for PostCSS users like |
I see this as a non breaking enhancement to postcss. So
Using the errors and warnings stack should not break the process. We can see that as just a way to notify some messages with a given severity. A stack can be an array like this [{
filename: "/whatever.css"
line: 1,
column: 23,
source: [Object] // related source if message send from a node
severity: 0, // PostCSS.LOG,
origin: "plugin-name",
id: "sort of uniq & short id",
message: "This is a message dude!"
},
{ /*...*/ } //...
]
Plugins like postcss-loader or gulp-postcss might be able to do what they want with that. We can imagine a option (callback) to postcss that would handle the stack when process is done, that would allow tools to show/save or do whatever they whan with those messages. By default we can provide a simple GNU like output /filename:1:23: plugin-name ERROR: This is a message dude ("uniqid")
|
What is different between “unimportant error” and “warning”? :) As I understand there are 2 semantics: we do not compile CSS and show error (for example, in browser) and we compile CSS and show warning somewhere in console. |
But I understand that might me confusing. That's why I mention a simple message stack with severity in each message. We can also imagine a simple log helper (to debug?) |
But what behavior |
Hm. You suggest debug helper rather that |
By default, maybe we should not do anything & let tool handle the |
Nobody will see What is a benefits of silent errors for unknown variables or mixins? |
We ask gulp-postcss fail on |
What I want to offer here is a new feature that don't have any equivalent. For now, we don't have anything and some plugin are already doing console.log that nobody see. It's especially boring in a webpack workflow for example (because webpack dev server output a lot of thing, and "simple" console.log are mixed in a huge output - that said, it offers a nice way to emit messages that will be outputed at the end of build so user can see them). I think it's a must have to provide a way so plugins can communicate with users in a normalized way. Using a simple With this new API, cli & wrapper might want to do whatever they want with the messages array (cli: console.log in an appropriate moment, wrapper: use corresponding api to show the messages) |
I totally agree. Question is only about But maybe I miss some important user case. |
It's up to the plugin to decide if they want to throw or just notify. Plugins can already throw exceptions. We should not care plugin will use error, warnings, simple logs... We should just provide a generic way to returns message with a given type (severity can be PostCSSMessage.ERROR, PostCSSMessage.WARN, PostCSSMessage.LOG or other I don't see yet). |
OK. I will add |
I can do something to help.
We should also think about the message object. I check eslint and came with that {
filename: "/whatever.css"
line: 1,
column: 23,
source: [Object] // related source if message send from a node
severity: 0, // PostCSS.LOG,
origin: "plugin-name",
id: "sort of uniq & short id",
message: "This is a message dude!"
} What do you think about that? |
@MoOx yeeap, I think about |
What is |
A simple key to define a message. Message can be updated but the key might helps tools to adjust behavior according to those key (eg: ignore some messages). |
Maybe |
yep :) |
Very interesting things is where we will store the messages. We can use Maybe we should add second argument to plugin functions? Or forbid to change root? |
We should provide postcss instance as a second parameter to the plugin functions. That will be flexible enough to avoid changing plugin function signature later. |
What do you think about this API: node.message(text, id); Plugin name we will take from |
Maybe we should rename mmethod to |
Maybe we should have some |
Like I said many times, I think it's not just about warning. You should be able to define different type of severity. var severity = require("postcss/messages/severity")
processor.message("text message", {origin: "stylelint", severity: severity.INFO, source: node.source, customData: "...", })
// and with one arg only
processor.message({origin: "stylelint", message: "text message", customData: "...", severity: severity.WARNING})
processor.message("text message"}) // severity: severity.INFO by default
// at node level
node.message(...) // same thing without the need for node and/or source I think the origin from the plugin name is a good idea but it should be overwritable. A message should have at least: text + origin. Other thing should be optional (source, severity, related node...) |
What other types of severity we will use? Yeap, direct API is nececessary. Your And I am +1 for overwritable plugin name and flexible. |
INFO, WARNING, ERROR are enough for a start. People will still be able to provide custom severity value. |
I think errors should be raised by |
There is 2 kind of errors:
|
What is difference between “recoverable errors” and warnings? |
Maybe we can add low level But users will use |
A plugin that doesn't work vs. a plugin that warn you for a deprecation notice for example. |
Why plugin that doesn't work just can't send a warning? Why we need special type? |
I added I will close this issue, when add |
|
@ai and @MoOx: Did you have some specific model in mind for how something like a linter, whose whole purpose is to show errors, would use warnings? I'm thinking about postcss-bem-linter, specifically, and have at least these two questions:
(Ultimately I know these same questions will come up for other linters, including any written for stylelint as that gets started.) |
|
You should take a look to eslint. |
Ok, I get that. Unfortunately at this point it seems like adding another step in the chain (a tool that understands the metadata and responds accordingly) is an annoyance for a small independent focused linter like postcss-bem-linter. Maybe I should make the plugin itself work that way (outputting metadata) but then include a little CLI that interprets the metadata, prints things, throws errors, etc., enabling the plugin to be used on its own. |
Currently postcss can encounter unrecoverable error during parsing, that might throw exceptions.
Next level should be to add a new feature to allow plugins to report error/warnings in a stack.
A plugin might return an error during the
process()
if the current css is not fitting the requirements (like custom-prop need a --stuff defined before using var(--stuff).We can also imagine warnings if a plugin want to warn the user about something it's recommanded to do (see stylelint).
We can even imagine that plugins will be able to check postcss version & with the same api solve #163.
The format should contain at least source (filename, l, c) & message + plugin ref.
We might also reuse
node.error()
and a newnode.warning()
.That would helps a lot for stylelint and MoOx/postcss-cssnext#64 as it might help a lot to make webpack loader more awesome (with real reportings, not just stupid console.log)
The text was updated successfully, but these errors were encountered: