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

fix: plugin warnings not showing warning.loc #3824

Merged
merged 4 commits into from Oct 21, 2020
Merged

fix: plugin warnings not showing warning.loc #3824

merged 4 commits into from Oct 21, 2020

Conversation

luciotato
Copy link
Contributor

Plugin warnings without warning.id but with warning.loc were not emitting loc information
loc information emitting is fundamental for user experience (to locate the source of the error/warning)

This PR contains:

  • bugfix
  • feature
  • refactor
  • documentation
  • other

Are tests included?

  • yes (bugfixes and features will not be merged without tests)
  • no

Breaking Changes?

  • yes (breaking changes will not be merged unless absolutely necessary)
  • no

List any relevant issue numbers:

Description

Plugin warnings without warning.id but with warning.loc were not emitting warning.loc information
warning.loc information emitting is fundamental for user experience (to locate the source of the error/warning)
added 3 lines, to emit the warning.loc info if present in a format amicable to IDEs problem matchers: file:line:col

Plugin warnings without warning.id but with warning.loc were not emitting loc information
loc information emitting is fundamental for user experience (to locate the source of the error/warning)
Copy link
Member

@lukastaegert lukastaegert left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks like a useful improvement to me. However, some work would be needed to get this ready for release, see my comment.

We would also need tests in order for this to be merged. And there are two different cases to be considered, one including loc.file and one where it is missing. These could be combined into a single test that emits two warnings, though. You could take for instance test/cli/samples/custom-frame as an inspiration.
Please let me know if you would be willing to go through with this.

@@ -196,6 +196,9 @@ const deferredHandlers: {
}
stderr(bold(loc));
}
else if (warning.loc) {
info(yellow(`${rollup.relativeId(warning.loc.file)}:${warning.loc.line}:${warning.loc.column}`)+' error '+message);
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm. not happy about this being the only non-title being formatted in yellow, couldn't we stick with the formatting used in the previous case? Also why do you want to repeat the error message that has just been written in the title? Moreover, file is optional in .loc, and this only makes sense if file is actually present otherwise you would not know what the location means.

Also this repeats the way that locations are formatted from the previous section, but in a slightly inconsistent way with regard to spacing. Here would be one suggestion to replace everything starting from line 192 with less duplication:

const id = warning.id || warning.loc?.file;
if (id) {
  let loc = relativeId(id);
  if (warning.loc) {
    loc += `: (${warning.loc.line}:${warning.loc.column})`;
  }
  stderr(bold(loc));
}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lukas, I changed the code as you suggested.
I won't be able to add tests.

@codecov
Copy link

codecov bot commented Oct 21, 2020

Codecov Report

Merging #3824 into master will increase coverage by 0.00%.
The diff coverage is 100.00%.

Impacted file tree graph

@@           Coverage Diff           @@
##           master    #3824   +/-   ##
=======================================
  Coverage   97.06%   97.06%           
=======================================
  Files         184      184           
  Lines        6502     6503    +1     
  Branches     1883     1884    +1     
=======================================
+ Hits         6311     6312    +1     
  Misses        101      101           
  Partials       90       90           
Impacted Files Coverage Δ
cli/run/batchWarnings.ts 98.44% <100.00%> (+0.01%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update b794a13...a71fa81. Read the comment docs.

@lukastaegert
Copy link
Member

I can push a test to your branch, but you would need to "allow edits by maintainer", which should be a checkbox somewhere to the bottom right of your PR:
Bildschirmfoto 2020-10-21 um 06 38 14

@luciotato
Copy link
Contributor Author

done.

@lukastaegert lukastaegert merged commit 53e30e2 into rollup:master Oct 21, 2020
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

Successfully merging this pull request may close these issues.

None yet

2 participants