You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I played around a bit, and came up with a possible solution. Maybe this is too complicated, so feel free to build something simpler ;).
For every Rule, we can make a separate struct which holds the configurable values. For example, for the TodoRule, we might want to configure the words:
Now, if we want to capture the fact that words is an option, we can create a struct ConfigurationOption which allows us to describe the options name (e.g. this is what people specify in the YAML) and a way to apply it to a configuration of type A. Because we don't really know what type will come in, we will try to do a cast within the apply function, and return an updated A if this succeeeds. Otherwise we return nil (which means: couldn't parse option). This should probably return a Result rather than an optional.
And finally, now that we have all of that in place, we can write a simple applyConfiguration function, which takes a rule, a list of (untyped) option values (this can be a YAML dict, or JSON dict, or whatever) and returns a new rule with all the options applied. Again, this might also produce errors, not sure how we should handle them (hence the TODO).
funcapplyConfiguration<A:Configurable>(varrule:A,optionValues:[String:Any])->A{foroptioninrule.options{ifletvalue=optionValues[option.name]{ifletnewRule=option.apply(rule,value){rule=newRule}else{
// TODO: option could not be parsed
}}}returnrule}
I realize this might look complicated, but I think it should be easy to work with. The nice thing about making it all explicit is that we can also generate documentation for the options, and we can easily add some more fields to the ConfigurationOption struct, (e.g. a short description of the option).
It does seem a bit complicated, and maybe even overlapping with the concepts of RuleParameter/ParameterizedRule, but I think that once a draft implementation is done, some of these concerns will naturally go away just by getting to a working state.
No, it hasn't been considered. Really the mechanics for enabling command line arguments as rule parameters are very similar to doing so via a configuration file. Feel free to take a stab at implementing that if you'd like.
Activity
aarondaub commentedon May 18, 2015
What is the support for YAML like? Should we limit it to the JSON subset, or is YAML well enough supported?
skywinder commentedon May 28, 2015
+1 👍
it will awesome to have
.swiftlint.ymlwith custom rules.as a good example of this approach is
.rubocop.ymlfor ruby linter https://github.com/bbatsov/rubocopchriseidhof commentedon May 30, 2015
I played around a bit, and came up with a possible solution. Maybe this is too complicated, so feel free to build something simpler ;).
For every
Rule, we can make a separate struct which holds the configurable values. For example, for the TodoRule, we might want to configure the words:Now, if we want to capture the fact that
wordsis an option, we can create a structConfigurationOptionwhich allows us to describe the options name (e.g. this is what people specify in the YAML) and a way to apply it to a configuration of typeA. Because we don't really know what type will come in, we will try to do a cast within the apply function, and return an updatedAif this succeeeds. Otherwise we return nil (which means: couldn't parse option). This should probably return aResultrather than an optional.For example, one option would be the
keywordsoption:Now, to say that a configuration (e.g.
TodoRuleConfiguration) has options, we can create a protocol:And finally, now that we have all of that in place, we can write a simple
applyConfigurationfunction, which takes a rule, a list of (untyped) option values (this can be a YAML dict, or JSON dict, or whatever) and returns a new rule with all the options applied. Again, this might also produce errors, not sure how we should handle them (hence the TODO).I realize this might look complicated, but I think it should be easy to work with. The nice thing about making it all explicit is that we can also generate documentation for the options, and we can easily add some more fields to the
ConfigurationOptionstruct, (e.g. a short description of the option).jpsim commentedon Jun 2, 2015
It does seem a bit complicated, and maybe even overlapping with the concepts of
RuleParameter/ParameterizedRule, but I think that once a draft implementation is done, some of these concerns will naturally go away just by getting to a working state.So in other words, go for it! 😄
bsrz commentedon Jun 24, 2015
@jpsim I'm coming in late in this conversation but has the option of passing parameters at the command line been looked into?
jpsim commentedon Jun 24, 2015
not as command line arguments, no.
bsrz commentedon Jun 24, 2015
Has it been rejected?
jpsim commentedon Jun 24, 2015
No, it hasn't been considered. Really the mechanics for enabling command line arguments as rule parameters are very similar to doing so via a configuration file. Feel free to take a stab at implementing that if you'd like.
bsrz commentedon Jun 24, 2015
Ok, sounds good!
Thanks for the information, I'll try to find some time to try this out.
Configure SwiftLint via a YAML file. Fixes #1 and #3.
Configure SwiftLint via a YAML file. Fixes #1 and #3.
Configure SwiftLint via a YAML file. Fixes #1 and #3.
Configure SwiftLint via a YAML file. Fixes #1 and #3.
jpsim commentedon Aug 28, 2015
Done in #99.
Added [Int] support for VariableNameMinLengthRule configuration.
[CI] Remove 'TSan Runs' job
[CI] Remove 'TSan Runs' job (#4701)
Merge pull request realm#3 in IOSUTILS/swiftlint from feature/implici…