-
Notifications
You must be signed in to change notification settings - Fork 285
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
refactor: error management #1185
Conversation
ok someone can explain to me why and when implementing dedicated field in struct:
is better then implementing dedicated
iam just curious thats all :P |
sure, the problem is the fact that Apply is called on multiple files On first run, it's the same thing. This time the Now with the |
From this article https://victoriametrics.com/blog/go-sync-once/index.html#what-is-synconce: Also, if you need to handle errors that might come out of f, it can get a little awkward to write: var once sync.Once
var config Config
func GetConfig() (Config, error) {
var err error
once.Do(func() {
config, err = fetchConfig()
})
return config, err
} This works well, but only the first time. The thing is, if var once sync.Once
var config Config
var err error
func GetConfig() (Config, error) {
once.Do(func() {
config, err = fetchConfig()
})
return config, err
} |
lint/linter.go
Outdated
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.
Could we add a test to demonstrate that the fix actually works?
I previously requested tests in this comment: #1126 (comment), but it seems to have been overlooked. It's likely that this test would catch the situation addressed by this PR.
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.
Of course.
I plan to add them, but I was waiting a nonnegative reaction, telling me I was breaking everything.
e04c9cd
to
4f484d1
Compare
I implemented the Configurable interface. I had to export a few things, please let me know what you guys think about it. Let me know what you think about it. I didn't add the tests yet. |
Please note that except one rule (that could be refactored) the arguments of Apply no longer need the Arguments
|
4f484d1
to
dfa9f2b
Compare
@ccoVeille what about with |
I'm sorry, but I don't understand your question, especially if you are replying to my previous comment, or the whole changes I made |
@ccoVeille I understand concept of Configurable interface and when it is executed (at config level when iteration over list of rules, and if rule have |
No problem, I just needed to know what you were asking for. So this refactoring is about moving the calls to Configure in the code that computes all the available rules. Lines 152 to 156 in dfa9f2b
So it's done only once when the app starts, GetLintingRules is called only once Line 54 in 45731a3
|
ok my question is because not all rules have configure methods only basic code in apply, for example rules: use_any, duplicated_imports, call_to_gc, and many others :P |
We can add empty configure methods to all rules, regardless of whether they have parameters or not. These methods will simply do nothing. |
It would change the signature, and so we will need to update all rules. This option was not considered as it would bring a lot of changes. But, as I spotted the arguments in Apply is no longer needed (once we will do a small refactoring for one rule) So now, I would say it's a good move. What do you guys think? |
@ccoVeille thanks for the work on this PR. |
It's up to you @chavacava I was expecting to get a feedback from you about this
So it would be to move from This (currently in this PR) // Rule defines an abstract rule interface
type Rule interface {
Name() string
Apply(*File, Arguments) []Failure
}
// ConfigurableRule defines an abstract configurable rule interface.
type ConfigurableRule interface {
Configure(Arguments) error
} To this // Rule defines an abstract rule interface
type Rule interface {
Name() string
Apply(*File) []Failure
Configure(Arguments) error
} So this change // Rule defines an abstract rule interface
type Rule interface {
Name() string
- Apply(*File, Arguments) []Failure
-}
-// ConfigurableRule defines an abstract configurable rule interface.
-type ConfigurableRule interface {
+ Apply(*File) []Failure
Configure(Arguments) error
} |
We can of course merge as is, an iterate in another PR |
I suggest to merge as is, without changing the Rule interface. |
Also, I'm curious. Do you see any improvement in term of speed? We are removing a lot of mutex. |
Go for it, then. |
Indeed, I'm setting up some benchmarks, I'll share the results when done |
Oh I forgot to add tests ... 😭 |
Comparing performance of new and previous version: Benchmark on revive code base
Benchmark on gitea
Benchmark on forgejo
|
Closes #1182