Add RulePatcher with module that fix incorrect interfaces #142
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Closes #141
Yo
Here is my attempt at what we were discussing in this issue
So we have the
RulePatcher
class, which is just a kind of container on which we will register modules. These said modules will be applied at the end of the rule file generation. Each of these modules will have access to the AST of the generated file, and can modify it. Once all the modules have been applied, the source code is generated from this modified ast.I have implemented a first module that simply converts the mapped types and interface into a union with the different members.
And it works great for the
node/file-extension-in-import
ruleThe only thing that is problematic is the following:
I use @babel/generator to regenerate the source code, and :
I used the
retainLines
options which allows having something formatted more or less like before.But we still end up with ~50 diff files compared to the original rules which have extra spaces in some places.
Example :
But it's not a big deal in my opinion.
The other thing I miss is to display the number of patches applied in the terminal report. Everything is ready thanks to the
hasPatched
property, it's just missing basically the console.log. But now I'm going to bed 😋Let me know if anything is wrong