-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
Better warnings #1194
Comments
Further thought: we could probably group certain warnings together. For example, all the implicit external dependency or ' |
I want to see warning, but recently you've added feature which prints to the console simple linting errors. I do not want to see those, they are huge and I already have elegant eslint messages. if i'll set the |
The new system is a lot more flexible in terms of how warnings are printed. By default it'll show a code frame etc, but because the warning is now an object rather than a string you can do this sort of thing: onwarn ( warning ) {
// simple handler
console.warn( warning.message );
}
onwarn ({ loc, message }) {
// print location if applicable
if ( loc ) {
console.warn( `${loc.file} (${loc.line}:${loc.column}) ${message}` );
} else {
console.warn( message );
}
}
onwarn ( warning ) {
// skip certain warnings
if ( warning.code === 'UNUSED_EXTERNAL_IMPORT' ) return;
// throw on others
if ( warning.code === 'NON_EXISTENT_EXPORT' ) throw new Error( warning.message );
// console.warn everything else
console.warn( warning.message );
} |
Thank you very much for the fine explanation! would be nice to copy it to the WIKI |
Good point! Done https://github.com/rollup/rollup/wiki/JavaScript-API#onwarn |
What about adding a helper function which renders a warning beautifully? I.e. incapsulate this code function printRollupWarning({loc, message, frame}, printer) {
if (loc) {
printer(`${loc.file} (${loc.line}:${loc.column}) ${message}`);
if (frame) {
printer(frame);
}
} else {
printer(message);
}
} |
Warnings are a bit hard to do things with at the moment, because they're just strings, meaning that if you want to (say) suppress all warnings about
this
being undefined, you have to do some regex hackery.It would be better if the warning was an object similar to an error object, with a warning code, a message, and other applicable information like file, line and column (which would allow the CLI to print a code frame – see also #296).
To minimise breakage, the warning object should have a
toString
method that returns the message.The text was updated successfully, but these errors were encountered: