-
-
Notifications
You must be signed in to change notification settings - Fork 33
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
feat: add organizeImportsMode
option
#140
base: master
Are you sure you want to change the base?
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||
---|---|---|---|---|
|
@@ -10,7 +10,14 @@ const { getLanguageService } = require('./get-language-service'); | |||
*/ | ||||
module.exports.organize = ( | ||||
code, | ||||
{ filepath = 'file.ts', organizeImportsSkipDestructiveCodeActions, parentParser, parser }, | ||||
{ | ||||
filepath = 'file.ts', | ||||
organizeImportsSkipDestructiveCodeActions, | ||||
// @ts-ignore | ||||
organizeImportsMode = 'All', | ||||
parentParser, | ||||
parser, | ||||
}, | ||||
) => { | ||||
if (parentParser === 'vue') { | ||||
// we already did the preprocessing in the parent parser, so we skip the child parsers | ||||
|
@@ -24,7 +31,13 @@ module.exports.organize = ( | |||
const languageService = getLanguageService(parser, filepath, code); | ||||
|
||||
const fileChanges = languageService.organizeImports( | ||||
{ type: 'file', fileName: filepath, skipDestructiveCodeActions: organizeImportsSkipDestructiveCodeActions }, | ||||
{ | ||||
type: 'file', | ||||
fileName: filepath, | ||||
skipDestructiveCodeActions: organizeImportsSkipDestructiveCodeActions, | ||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
I assume we can skip this now that we set |
||||
// @ts-ignore | ||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same here, why a ts-ignore? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's the problem of use enum type in javascript code, since the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ok we can just type case it instead. i'll try to finish this PR soon, sorry somehow was too busy lately 🫣 |
||||
mode: organizeImportsSkipDestructiveCodeActions ? 'SortAndCombine' : organizeImportsMode, | ||||
}, | ||||
{}, | ||||
{}, | ||||
)[0]; | ||||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,11 @@ | ||
declare module 'prettier' { | ||
interface Options { | ||
organizeImportsSkipDestructiveCodeActions?: boolean; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sry i didn't mean dropping the deprecated option entirely. just when calling languageService.organizeImports(
// ...
mode: organizeImportsMode ?? (organizeImportsSkipDestructiveCodeActions ? 'SortAndCombine' : undefined),
// ...
) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Got it, restored and updated. |
||
organizeImportsMode?: 'All' | 'SortAndCombine' | 'RemoveUnused'; | ||
} | ||
interface ParserOptions { | ||
organizeImportsSkipDestructiveCodeActions?: boolean; | ||
organizeImportsMode?: 'All' | 'SortAndCombine' | 'RemoveUnused'; | ||
} | ||
} | ||
|
||
|
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.
Do you really need to set a default value here, since we're already setting the default in the plugin options?
Also what is the
@ts-ignore
ignoring? 🙃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.
Since the default value is unnecessary here, this one could be delete.