bhirsz / robotframework-cop-academy

Tool for static code analysis and formatting of Robot Framework language
Apache License 2.0
2 stars 0 forks source link

[Design] Fixable rules #5

Open bhirsz opened 4 hours ago

bhirsz commented 4 hours ago

Robocop rules should have option to fix them.

To enable automatic fixing we can use fix option:

robocop check --fix

By default error message should mention if rule is fixable (if fix option is not provided).

Some rules should be safe to fix and some may cause issues in the code (for example renaming arguments or ordering import). Such rules can be fixed only if additional --unsafe-fixes id provided.

From implementation point of view, fixable rules should have fix argument provided with either robotidy formatter (essentialy running part of the formatter to fix particular rule) or class that only fix particular issue.

Rules summary should contain count of the potentially fixable rules.

bhirsz commented 4 hours ago

Calling the formatter should be done in isolation, without caling whole robotidy. Even if user have custom configuration for given formatter, we want to call it with out settings in accordance with the rule we want to fix.

For example rule that reports problems with continuation line indentation should configure given formatted to fix only this issue if possible.

bhirsz commented 3 hours ago

Example how fixer could be defined for the rule:

Rule(
... 
fix=NormalizeTags
) 

Rule(
unsafe_fix=MyRuleFixer

) 

If fixer needs configuration it could be provided using 'fix_args'. For performance reason we should prefer lazy instantation - thats why we cant create fixer instance in the Rule but only after reading config and assuring there is fix flag. That's why we can only pass arguments indirectly:

Rule(
... 
fix=FixerWithArgs, 
fix_args={'param': 2}
) 

Fixer class should use ModelTransformator class as its type.