-
Notifications
You must be signed in to change notification settings - Fork 509
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
Extending visit
function's argument list from Rule.kt
with parameters
#806
Conversation
…ation parameters. ### What's done: 1. Extended visit function with new arguments. It becomes very useful in case you will need to match or check any parameter in any rule. For example - in case you will need to check a filename in a rule - you don't need to pass it through your code and change every visitor. Everything will be already passed through and you will need simply to add needed parameter to `KtLint.Params` data class. 2. Changed all rules and tests where visit is overridden
This is very useful for cases when you need to check file naming or any other stuff that can be added to Ktlint params. |
### What's done: 1) Making RuleSet class open - it should be useful for developers who would like to add their own rule sets with their own internal class properties. For example you can add flags here to control if this part of rule should be run or not
This will not break anything in ktlint, but will give a chance for developers of rules to use your code instead of customized forks. |
This will break downstream dependencies though (like detekt) in that the public API has changed. But I guess it's fine. cc @arturbosch |
@romtsn @arturbosch yeah, I understand this, but the main problem is now for usage of the framework is that we are not able to extend your library to write some rules. For example - to check everything related to file naming. Or do other checks where parameters being passed to a visitor are needed. I am pretty sure that one day some one will need parameters being passed inside the visitors and at that time everything will be so mature that you won't be able to change it, unfortunately. So better to do that now or never :) |
@romtsn @arturbosch so what do you think about breaking your API a little bit? :) |
Your idea is interesting. While ktlint is not yet reached 1.x version, we try to introduce api changes with some deprecation strategy and keep it for few versions. If you really want this, please consider forking and building your version of ktlint until this will be merged or introduced in some similar way. |
@Tapchicoma - we have already done it and are using fork inside of our ruleset: https://github.com/cqfn/diKTat |
@akuleshov7 what info from BTW file name is already available to the rules:
|
@Tapchicoma I am pretty sure that you will agree with me that passing normal object of a normal class (or data class) with strong typing is much better than:
Creating objects with strong typing is much better than mapping values and keys on some magic constants. Also - if you will need to pass, for example, Today we need I guess it will be a good approach to pass Params to all rules (visitors) through the code. |
@Tapchicoma @romtsn guys. if we are not able to merge this one PR - can we at least open API for RuleSet class? |
tbh I'm fine with both of these changes, so I wouldn't mind merging this in, but I'd like @Tapchicoma and @shashachu opinions |
Personally I don't want to break Generally I would agree that user data usage is not the best approach and we should drop it when we will introduce next iteration of |
Yes, that is fine. We are absolutely fine with merging at least #894 |
What's done:
For example - in case you will need to check a filename in a rule - you don't need to pass it through your code and change every visitor. Everything will be already passed through and you will need simply to add needed parameter to
KtLint.Params
data class.