flow-immutable-models
flow-immutable-models copied to clipboard
Add comment once per generated code block, automatically add (some) necessary imports
Should address #4
@p-bomb suggested,
I think we should add the missing imports as the first non-commented line instead of after the cutline so we don't break common eslint rules like this one.
I'm not keen on breaking eslint rules, but it seems rude to modify the original code. Perhaps if we annotated the import with a comment indicating that it was generated?
I don't think it's rude to modify the original code, because these model files exist in order to support the code generation. They go hand-in-hand. I don't think we should add commented-out import statements and I think if we add import statements later in the file, we might break eslint rules, which I think we need to avoid. import statements should go at the top of the file. If we're going to add support for that to this library, they should be added to the top of the file.
Sorry, I think I wasn't clear. I mean, do something like this...
Original:
export type QuuxModelType = {
id: number,
name: string,
};
Post code generation:
import * as Immutable from 'immutable'; // Added
import ImmutableModel from 'flow-immutable-models'; // Added
export type QuuxModelType = {
id: number,
name: string,
};
// //////////////////////////////////////////////////////////////////////////////
//
// NOTE: EVERYTHING BELOW THIS COMMENT IS GENERATED. DO NOT MAKE CHANGES HERE.
//
// If you need to update this class, update the corresponding flow type above
// and re-run the flow-immutable-models codemod
//
// //////////////////////////////////////////////////////////////////////////////
[blahblahblah]
~~(Also, I lied, this PR is very incomplete.)~~ OK, more complete now.
I'm fine with that, although I think the import comments are unnecessary.
OK; they may be tricky to pull off anyway. So I will concentrate on just getting the imports into the top of the file. I appreciate the feedback!