-
Notifications
You must be signed in to change notification settings - Fork 42
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
Add fixer #72
Conversation
this would be a great feature |
I'm not looking forward to support removal of lines and not mess up comments in the current state. I'm not sure if whitespace will resolve errors 1:1 with how this linter want's it but at least it will fix obvious empty lines. I think > 99% are using this linter with golangci-lint and if so using |
Just found out about https://github.com/mvdan/gofumpt which overlaps a lot of features here, many removing newlines. Might be some help figuring out a way forward for this. Although this has been stale manly because I haven't had the time to work on it. |
What's the current state of this? |
Sadly unchanged from last time and the note in #90 and I consider the project mostly in a maintenance state. I haven't really gotten much feedback or request so motivation has been low. I actually started some rework in a v4.0.0 branch this year but I've been too focused on other things to give this the attention needed. The idea with the v4 branch was to rebuild a lot of things from scratch to be more confident around the fixer but I never kept working on it. Any help or PR in the right direction would be appreciated but I think my biggest problem is that I don't want to release a fixer that doesn't fix 100% of the cases and until I have that in place there will be no fixer in wsl. I do however think about it every now and then so I can't say it will never happen, although the fact that I haven't gotten to it in 2,5 yeas says otherwise... |
@bombsimon we love this linter at work but are getting tired of fixing the issues manually specifically (cuddling) which seems you have working based off the list above. Wondering if any progress has been made since you last wrote? If not we would love to help if possible. |
This feature would be great. How can we help this progress? |
Hey, glad to hear you're finding this linter useful and want to contribute! And sorry for not pushing this issue more forward. So first off, not much has changed and the reasons are the same; a combination of time and motivation. The motivation is mostly based on the assumption not many people use this linter and that I also no longer use this at my current workplace so there's no natural maintenance happening. Also since 2018 there's only 18 👍 on #4. A second reason for little progress is probably Second-system effect. I created the v4.0.0 branch back in 2020 and have been tinkering on and off trying to address all open issues but every time I instead get exhausted by starting over. There's also the discussion (oh well, an issue with just a single reaction) in #110 about dropping support to make it easier to land this. After some thinking this would mostly be things that's not really related to whitespaces and mentioned under Hearing you offering to help is very appreciated and makes me think about what would need to happen to land this. I think for now the roadmap should start with:
These three (or at least first two) things is probably something I can try to address fairly soon so we have a better starting point. Let me give this a go and feel free to ping me next week if no progress is made in this PR. If we end up there there's a few things to figure out: Whitespace parsing in beginning and end of blockThis has become more complex than intended given all the hard requirements of Advanced formattingThis is things like grouping multiple
We would just add whitespaces:
TestingLastly as mentioned in #90 (comment) I think it's scary to modify other's source code and I can't guarantee everyone has backups or use revision control. I think just help with testing this and finding edge cases would help a lot. |
With `RunWithSuggestedFixes` we can assert that the output of the diagnostics created are corect. It's a bit weird because the golden file will contain all the expected assertions even though the would no longer be triggered. For now they're kept to make the test pass. Ref: https://godocs.io/golang.org/x/tools/go/analysis/analysistest#RunWithSuggestedFixes
We can now fix a line that's not the one we reported. This is used when we have multiple cuddled vars but want to keep the last one since it's allowed (and required if error cuddling is forced). Also adds all the config flags
We currently only support adding a newline if we don't think vars should be cuddled. For `var` blocks we would ideally group them instead of separating by newline but this is currently not supported. This test only serves as an expectation of the fixer.
* Remove newline in end of block * Remove newline in start of block (and comments...) This is WIP because we need to preserve the comments so they don't get deleted when we remove beginning of blocks.
* Work around case blocks * All tests now uses fixer * Different tests can set config per test
Regarding the trailing comments, I have found myself commenting out the last line of a function/ block sometimes and as a result wsl complained. Moving the comments wouldn't make sense in this case as it's just normal code and I might uncomment it later on. So vouching for relaxing around trailing comments |
Soo, I think this might be getting closer. This is from the › time wsl --fix ./...
[...snip]
wsl --fix ./... 50.21s user 5.55s system 434% cpu 12.840 total
› git status | wc -l
2840
› git diff | wc -l
329355 I'm running }
- return nil
+ return nil
} Running the linter again after the first fix only shows the unfixable › time wsl --fix ./... 2>&1 | grep -v "block should not end with a whitespace"
wsl --fix ./... 2>&1 47.04s user 5.23s system 585% cpu 8.928 total I think this is fine since we already support › time wsl --allow-trailing-comment --fix ./... && echo "Zero violations"
wsl --allow-trailing-comment --fix ./... 45.87s user 5.14s system 582% cpu 8.757 total
Zero violations I've also tested this on the |
I've discovered an intermittent bug where if I run it on wsl: analysis "wsl" suggests invalid fix: pos (204243988) > end (204243907) I think it's related to not allowing trailing comments and case blocks. Last example I reproduced was What's weird is that it's not consistent. Running I need to troubleshoot this further but I'm travelling tomorrow and won't be back until Sunday evening so I might not pick this up until next week. |
Found this which I somehow didn't know so probably worth looking into before merging this PR, maybe I can convert it somehow... golangci/golangci-lint#1779 |
Found a way to reproduce the intermittent bug, fixed it and ran the test a couple of 100 times to ensure it's fixed. |
According to primary maintainer of |
I found a way to work with |
I've made some iterations on converting multiple I think I'm going to revert the last changes for this and put that in a separate PR/issue. Either I go with #110 and just remove the rule or I spend some more time with an improved fixer. |
I feel I'm losing pace on this PR so I'm going to leave the fixer as is and create a followup ticket to improve the fixer. A summary of what this means:
|
This is a tracking pull request for the implementation of a fixer. This PR aims to solve #4
Advanced formatting, e.g. groupvar
1Since only one assignment/statement is allowed before if checks the linter will warn if blocks are cuddled. The fixer will resolve the block cuddling and thus the fixer should not add proposals to fix the check after. Example:
This
Should be resolved to this
But is currently resolved to this