Currently it is possible to write fixers for a rule, for instance the gitignore fixer which is quite easy.
A downside however is that the fixer directly interacts with the file on the filesystem. This means that they are quite hard to test.
This is what I suggest as an improvement. When a rule reports an error or a warning, it also specifies the file in which the error occurred. This means that our core knows which file the fixer will operate on. So instead of reading and writing those files inside the rule, it could easily happen in the core of clinton.
The content of the file will be passed to the fixer as an argument. The fixer can easily return the new content of the file, or a promise that resolves the new content of the file. In case of json, yml/yaml files, the object is parsed beforehand to make it easier to work with. The core will use detect-indent to write the file back in the correct format. If it's not one of those files, it will just pass the raw contents to the fixer and writes the content back to disk as returned by the fixer. No parsing will be done whatsoever.
Currently it is possible to write fixers for a rule, for instance the gitignore fixer which is quite easy.
A downside however is that the fixer directly interacts with the file on the filesystem. This means that they are quite hard to test.
This is what I suggest as an improvement. When a rule reports an error or a warning, it also specifies the file in which the error occurred. This means that our core knows which file the fixer will operate on. So instead of reading and writing those files inside the rule, it could easily happen in the core of
clinton
.The content of the file will be passed to the fixer as an argument. The fixer can easily return the new content of the file, or a promise that resolves the new content of the file. In case of
json
,yml/yaml
files, the object is parsed beforehand to make it easier to work with. The core will usedetect-indent
to write the file back in the correct format. If it's not one of those files, it will just pass the raw contents to the fixer and writes the content back to disk as returned by the fixer. No parsing will be done whatsoever.