-
Notifications
You must be signed in to change notification settings - Fork 59
feat: consolidate adjacent error messages #360
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
Conversation
This looks like a great PR already. CI is failing because of your commit message, we require semantic commits i.e. |
that's a really easy fix at least - I fixed the commit messages, treating the change to the human output as a breaking change, since somebody out there is probably going to rely on it. Sadly I didn't see a CONTRIBUTING.md or similar section in the README and didn't notice in the existing commits. Since it didn't seem much work anymore, I also implemented the output format that github actions uses. |
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #360 +/- ##
==========================================
+ Coverage 84.89% 87.04% +2.15%
==========================================
Files 8 8
Lines 695 610 -85
==========================================
- Hits 590 531 -59
+ Misses 81 55 -26
Partials 24 24 ☔ View full report in Codecov by Sentry. |
I now managed to build a test case for the newly introduced |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Typo spotted
of cause now testing the tester was needed as well - that finally should bring testing coverage up to where it was before I started this branch |
okay, now the ci should pass - turns out I had a unicode nonbreaking space in the second to last commit, and the wording in the last commit tripped the "subject must not be sentence-case" rule. Now I verified locally to ensure the commit messages pass. |
pkg/error/error_test.go
Outdated
|
||
expected := []ValidationError{ | ||
{LineNumber: -1, Message: errors.New("file-level error")}, | ||
{LineNumber: 1, ConsecutiveCount: 1, Message: errors.New("message kind one")}, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I know lists start at 0
But I would have expected to find a Consecutive count of 2.
With the current example and code, line 1 will report a consecutive count of 1.
A human would expect to know that the error reported line 1 was reported twice, so 2
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hm.. ConsecutiveCount is the count of additional error messages that followed the first one - so it excludes the first one (meaning ConsecutiveCount == 0
is "one singular message").
But switching to storing according to your model would mean the last-line-of-block calculation becomes a tad simpler. I'll think about that one - maybe renaming the property to a better name is better to make it clearer (I'm thinking about AdditionalIdenticalErrorCount
for example)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It would make sense.
I'm not good with wording, but yes I think it would make it easier to understand.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I renamed it, sadly I had no better idea than AdditionalIdenticalErrorCount
, so that one it is for now ;)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Someone may come and suggest a new name
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm open for suggestions - a rename is cheap!
For anyone interested by the feature this PR would bring, please take a look at |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you @klaernie for opening the PR, and thank you @ccoVeille for helping to review the PR. 😄
I've left some comments.
0f79805
to
6198132
Compare
Having seen the latest CI run result, I'm not sure what the best way to proceed with snapshot testing is. The test cases in error_test.go line 229 and error_test.go line 238 refer to files by an absolute patch, and the conversion to a relative path then means the test case becomes sensitive to the current working directory. If a user tries to run the test in The only workaround I can imagine is changing the working directory for the duration of the test - which I implemented in 0d679db. If anyone has a better solution feel free to tell me. |
One thing I just remembered, that I need to do: Edit: done |
Dotting
Thinking about it we have three options:
I would categorically exclude option 1, since we do not give up that easily. Option 2 is a per-OS version of options 1, preventing future develops who work on Windows from benefiting from the snapshot tests, but would at least codify that the current tests are only expected to work on systems with unix-style path separators. Option 3 would be probably the best, but introduce a new long-term problem: running the testsuite fully would require being done twice - once on Windows and once on Linux. Running in CI or Linux one can at least install wine and a windows version of golang, then run Does anyone of you have a suggestion what route to take? |
Ah, Windows and path issues. 🙃 Hmm, we should probably run CI in Windows and macOS as well. For the moment, only Given, that we run CI only on Linux, we should probably do:
Unless we already have a solution, we might create an issue to fix that separately to this PR. Run CI in all supported OS. |
I would say as long as ubuntu test are launched via the CI, and as long as it's a know and documented things, I'm fine with tests that use t.Skip when and if a better solution is found later, then it will be fixed But yes, windows, and macOS should be added to the matrix |
This needs to be done since the paths between systems using / and \ lead to different interpretations of what the absolute paths in the test data mean.
This also makes sure, that make run does not verify the entire node_modules folder with the editorconfig for this repo
3f14908
to
bb077d7
Compare
I've now completed enabling the tests to work with both path separators golang supports, and ensured that a possible future discovery of new path separator fails the test. I would now call this finally complete enough to merge. |
I tried to build this package with this PKGBUILD and this pr (since this pr to be precise) pkgname=editorconfig-checker-git
_pkgname=editorconfig-checker
_commit=cf4ae1ccede331b2aa1b115f1de5257737de7eef
pkgver=next
pkgrel=1
pkgdesc='A tool to verify that your files are in harmony with your .editorconfig'
arch=(x86_64)
url="https://github.com/editorconfig-checker/$_pkgname"
license=(MIT)
depends=(glibc)
makedepends=(go)
provides=(ec)
conflicts=("$_pkgname")
source=(
"git+${url}.git#commit=$_commit"
)
sha256sums=('SKIP')
build() {
cd "$srcdir/$_pkgname"
export CGO_CPPFLAGS="$CPPFLAGS"
export CGO_CFLAGS="$CFLAGS"
export CGO_CXXFLAGS="$CXXFLAGS"
export CGO_LDFLAGS="$LDFLAGS"
export GOFLAGS="-buildmode=pie -trimpath -ldflags=-linkmode=external -mod=readonly -modcacherw" # won't pass check
# export GOFLAGS="-buildmode=pie -ldflags=-linkmode=external -mod=readonly -modcacherw" # will pass check
go build -o "$_pkgname" ./cmd/...
}
check() {
cd "$srcdir/$_pkgname"
go test ./...
}
package() {
cd "$srcdir/$_pkgname"
install -Dm755 -t "$pkgdir/usr/bin/" "$_pkgname"
ln -sf "$_pkgname" "$pkgdir/usr/bin/ec"
install -Dm644 -t "$pkgdir/usr/share/licenses/$_pkgname" LICENSE
}
I got this error
If I remove |
@orhun you are maintaining the package, could you have a look? |
That flag is necessary for the reproducibility. I just checked and the package builds fine in a clean chroot - you can remove the flag if it causes problems in your local machine :) |
@orhun Really? I also tried in gitlab cicd. |
You need to build in a clean chroot with |
…/cmd/editorconfig-checker to v3.1.1 (forgejo) (#6520) This PR contains the following updates: | Package | Update | Change | |---|---|---| | [github.com/editorconfig-checker/editorconfig-checker/v3/cmd/editorconfig-checker](https://github.com/editorconfig-checker/editorconfig-checker) | minor | `v3.0.3` -> `v3.1.1` | --- ### Release Notes <details> <summary>editorconfig-checker/editorconfig-checker (github.com/editorconfig-checker/editorconfig-checker/v3/cmd/editorconfig-checker)</summary> ### [`v3.1.1`](https://github.com/editorconfig-checker/editorconfig-checker/releases/tag/v3.1.1) [Compare Source](editorconfig-checker/editorconfig-checker@v3.1.0...v3.1.1) ##### Bug Fixes - dockerfile expected binary at /, not /usr/bin/ [#​410](editorconfig-checker/editorconfig-checker#410) ([#​411](editorconfig-checker/editorconfig-checker#411)) ([2c82197](editorconfig-checker/editorconfig-checker@2c82197)) ### [`v3.1.0`](https://github.com/editorconfig-checker/editorconfig-checker/releases/tag/v3.1.0) [Compare Source](editorconfig-checker/editorconfig-checker@v3.0.3...v3.1.0) ##### Features - add zip version when compressing all binaries ([#​321](editorconfig-checker/editorconfig-checker#321)) ([#​362](editorconfig-checker/editorconfig-checker#362)) ([f1bb625](editorconfig-checker/editorconfig-checker@f1bb625)) - consolidate adjacent error messages ([#​360](editorconfig-checker/editorconfig-checker#360)) ([cf4ae1c](editorconfig-checker/editorconfig-checker@cf4ae1c)) - editorconfig-checker-disable-next-line ([#​363](editorconfig-checker/editorconfig-checker#363)) ([6116ec6](editorconfig-checker/editorcon C890 fig-checker@6116ec6)) - provide Codeclimate compatible report fromat ([#​367](editorconfig-checker/editorconfig-checker#367)) ([282c315](editorconfig-checker/editorconfig-checker@282c315)) - support `.editorconfig-checker.json` config ([#​375](editorconfig-checker/editorconfig-checker#375)) ([cb0039c](editorconfig-checker/editorconfig-checker@cb0039c)) ##### Bug Fixes - actually use the correct end marker ([#​405](editorconfig-checker/editorconfig-checker#405)) ([3c03499](editorconfig-checker/editorconfig-checker@3c03499)) - add `.ecrc` deprecation warning ([#​389](editorconfig-checker/editorconfig-checker#389)) ([d33b81c](editorconfig-checker/editorconfig-checker@d33b81c)) - this release-please marker ([#​403](editorconfig-checker/editorconfig-checker#403)) ([617c6d4](editorconfig-checker/editorconfig-checker@617c6d4)) - typo in config, `SpacesAftertabs` => `SpacesAfterTabs` ([#​386](editorconfig-checker/editorconfig-checker#386)) ([25e3542](editorconfig-checker/editorconfig-checker@25e3542)) </details> --- ### Configuration 📅 **Schedule**: Branch creation - "* 0-3 * * *" (UTC), Automerge - "* 0-3 * * *" (UTC). 🚦 **Automerge**: Disabled by config. Please merge this manually once you are satisfied. ♻ **Rebasing**: Whenever PR becomes conflicted, or you tick the rebase/retry checkbox. 🔕 **Ignore**: Close this PR and you won't be reminded about this update again. --- - [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check this box --- This PR has been generated by [Renovate Bot](https://github.com/renovatebot/renovate). <!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiIzOS45My4wIiwidXBkYXRlZEluVmVyIjoiMzkuOTMuMCIsInRhcmdldEJyYW5jaCI6ImZvcmdlam8iLCJsYWJlbHMiOlsiZGVwZW5kZW5jeS11cGdyYWRlIiwidGVzdC9ub3QtbmVlZGVkIl19--> Reviewed-on: https://codeberg.org/forgejo/forgejo/pulls/6520 Reviewed-by: Earl Warren <earl-warren@noreply.codeberg.org> Co-authored-by: Renovate Bot <forgejo-renovate-action@forgejo.org> Co-committed-by: Renovate Bot <forgejo-renovate-action@forgejo.org>
Wow. What an effort @klaernie 🙌 Thank you! I came to GitHub to mention a petty thing and after seeing this PR, I'm having second thoughts :) Still - what I wanted to mention is that it would be neat to be silent if no errors are found. Right now you get a red "0 errors found" after this PR - it's information one cannot act on, and thus could be skipped. |
This changes the human output format to collect multiple identical error
messages on consecutive lines into one error message that list both the
starting and ending line.
This is still missing a properly written testcase, I so far only tested
with
So far the output for the newly included testfile is this:
However there are still a few things that annoy me:
The summary of how many errors are present is now incorrect, since the
error.GetErrorCount()
is called bymain()
, before any consolidation happened.However one should not hoist the consolidation up into
main()
, since it must only happen for the human output (or the eventual github action format mentioned in More Output Formats #245).My first instinct would be to let
error.PrintErrors()
handle writing that summary as well, but technically that would add a side effect forerror.TestPrintErrors()
.I have no idea how to work with golang's testing infrastructure. I'd roughly guess that one would have to make PrintErrors() side effect free by collecting the lines to be printed and returning them, letting the caller handle the actual printing, but being then able to validate the output lines in a testcase.
I'd be really happy for any feedback, while programming for years, this is maybe my third time touching golang - which is quite a different beast compared to Perl. So especially if any I did is not idiomatic or hard to understand, please tell me! (aka:
perlcritic --brutal
)