-
Notifications
You must be signed in to change notification settings - Fork 44
Optional configuration for multiple imports per line
and strictly one import per line
.
#50
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
Conversation
As per buehler/typescript-hero/issues/379, there should be an option `multiLineWrapMethod`, where a user can choose between: `ONE_IMPORT_PER_LINE` OR `MULTIPLE_IMPORTS_PER_LINE`
This change will provide code generation support from But I am not sure how to push it in since I have another pending change request. |
Once |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Cool idea! And many many thanks for your work. I reviewed it, and I'd suggest some small changes as documented. After that, we're good to go.
@@ -45,7 +46,8 @@ | |||
"typedoc": "^0.9.0" | |||
}, | |||
"dependencies": { | |||
"lodash": "^4.17.4", | |||
"lodash": "^4.17.5", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
so if you want to use lodash-es
instead of lodash
(which is fine by me, since I didn't knew it existed) you can remove the other one right? or are both needed?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Both are needed, I only had to add these because I was facing errors in running npm run develop
. Right now lodash imports are untouched. At some point I would change those imports to use lodash-es
. With that I tihnk we can eventually get treeshaking benefit.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Alright
* @type {'MULTIPLE_IMPORTS_PER_LINE' | 'ONE_IMPORT_PER_LINE'} | ||
* @memberof TypescriptGenerationOptions | ||
*/ | ||
multiLineWrapMethod: 'ONE_IMPORT_PER_LINE' | 'MULTIPLE_IMPORTS_PER_LINE'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd use a string enum
for this particular case:
This way, it should be exported and is easy extendable (and more convenient to use in an IDE)
export enum MultiLineImportRule {
onePerLine = 'onePerLine',
multiplePerLine = 'multiplePerLine',
}
With this method, we can implement this feature as a normal config in typescript hero and use the enum directly (as string value)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sounds good.
getImportSpecifiers(imp, spaceBraces), | ||
lib, | ||
); | ||
let retVal:string = ''; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
missing space in code formatting
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And please use the whole name returnValue
or generatedImport
or something like that. I'm not a big fan of abbreviations since we're not coding C or something ;-)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yup.
|
||
if (importString.length > multiLineWrapThreshold) { | ||
if (specifiers.length > multiLineWrapThreshold) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This actually changes the behaviour of the multi line wrap threshold. before, the generated string was checked for his length. Now only the specifiers.
Or did I misread something?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It should behave like before, or we need to introduce a BREAKING CHANGE
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I actually intended this change, because I thought that it is the right thing to do, didn't realize that it could be considered a Breaking change.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually, I will rever that part for now. Its small thing to change later if think that it should be done.
const sortedImportSpecifiers: SymbolSpecifier[] = imp.specifiers.sort(specifierSort); | ||
let importSpecifierStrings: string = ''; | ||
|
||
if (multiLineWrapMethod === 'MULTIPLE_IMPORTS_PER_LINE') { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please use the string enum, as mentioned above
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes.
config/tsconfig.base.json
Outdated
@@ -7,7 +7,7 @@ | |||
"outDir": "../build", | |||
"rootDir": "../src", | |||
"declaration": true, | |||
"sourceMap": false, | |||
"sourceMap": true, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please not in the base config. The tsconfig.json
configuration does specify sourceMap: true
. The base should not change that since the production config does not overwrite the setting again.
-> false
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok
To consume the change, we will release the parser and then we can update it in typescript hero. Afterwards the settings needs to be coded in TSH |
I think there are some inefficiencies in this file in general. There is some logic we are doing more an once. |
Thank you so much 🙇 |
I have made some changes as per what I think are the best set of options. But I am not very good with tests, I just updated them using the test script. @buehler Please review and let me know if anything needs improvement, and also see if you can help with tests. |
Just FIY, the option |
multiple imports per line
and strictly one import per line
.
Option |
@buehler Can you please review this? Once we are settled with this change, then I would need to make a parallel ts-hero change to make it work with this commit, and once that is reviewed, both can go in together. |
As per buehler/typescript-hero/issues/379, there should be an option
multiLineWrapMethod
, where a user can choose between:ONE_IMPORT_PER_LINE
OR
MULTIPLE_IMPORTS_PER_LINE