flow-immutable-models
flow-immutable-models copied to clipboard
Automatically include necessary imports if missing from a model file
The current code requires that ImmutableModel
must exist in a model file for it to be functional. It would be nice to include that import in the generated portion of the file if it is missing.
Agreed. The same is true for the immutable import. I feel like a pull request might be coming. Yeah? 😉
Feel free to assign it to me, and I'll poke at it.
Working through this. When I first looked at this, I had assumed that the comment block was free-floating, but I now see that comment blocks pretty much have to be associated with a code block (as per issues in the ast-types project). (Which also means that because it is possible to have more than one ModelType
in a file, there will be more than one comment block.)
I have a very rudimentary pass at this which pops an import at the end of a file.
Before proceeding further, I'd like to do another refactor which will prepend the comment block only to the first added code block. This will have the side benefit of making it easier to handle pre-existing added code blocks -- look through all top-level code blocks in sequential order and remove anything at or after the block which has out delimiting comment. This is Good(tm) because if we add the ImmutableModel
import, I'd rather not see that leak into the original code.
Thoughts or feedback?