Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add comment once per generated code block, automatically add (some) necessary imports #17

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

object88
Copy link
Collaborator

@object88 object88 commented Dec 28, 2016

Should address #4

@object88
Copy link
Collaborator Author

@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?

@pbomb
Copy link
Owner

pbomb commented Dec 28, 2016

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.

@object88
Copy link
Collaborator Author

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]

@object88 object88 changed the title Add comment once per generated code block, automatically add (some) necessary imports WIP: Add comment once per generated code block, automatically add (some) necessary imports Dec 28, 2016
@object88
Copy link
Collaborator Author

object88 commented Dec 28, 2016

(Also, I lied, this PR is very incomplete.) OK, more complete now.

@pbomb
Copy link
Owner

pbomb commented Dec 28, 2016

I'm fine with that, although I think the import comments are unnecessary.

@object88
Copy link
Collaborator Author

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!

@object88 object88 changed the title WIP: Add comment once per generated code block, automatically add (some) necessary imports Add comment once per generated code block, automatically add (some) necessary imports Jan 18, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants