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

feat: support prettierConfigs with internal default options #592

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion src/configs/formatters.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ export async function formatters(
options.prettierOptions || {},
)

const prettierXmlOptions = {
const prettierXmlOptions: VendoredPrettierOptions = {
xmlQuoteAttributes: 'double',
xmlSelfClosingSpace: true,
xmlSortAttributesByKey: false,
Expand Down Expand Up @@ -289,5 +289,15 @@ export async function formatters(
})
}

if (options.prettierConfigs) {
const prettierConfigs = options.prettierConfigs({
defaultOptions: prettierOptions,
defaultXmlOptions: prettierXmlOptions,
})
prettierConfigs.forEach((item) => {
configs.push(item)
})
}

return configs
}
10 changes: 10 additions & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,11 @@ export type OptionsTypescript =
(OptionsTypeScriptWithTypes & OptionsOverrides)
| (OptionsTypeScriptParserOptions & OptionsOverrides)

export interface PrettierConfigsOptions {
defaultOptions: VendoredPrettierOptions
defaultXmlOptions: VendoredPrettierOptions
}

export interface OptionsFormatters {
/**
* Enable formatting support for CSS, Less, Sass, and SCSS.
Expand Down Expand Up @@ -93,6 +98,11 @@ export interface OptionsFormatters {
*/
prettierOptions?: VendoredPrettierOptions

/**
* Custom configs let you have different configuration for certain file extensions and specific files.
*/
prettierConfigs?: (options: PrettierConfigsOptions) => TypedFlatConfigItem[]
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not sure about the return of TypedFlatConfigItem[] convention, which supposedly to be the append or prepend operation of the main config. Also it feels a bit too specific here.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any suggestions to optimize it?

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't understand what you want - for appending the config you and use .append etc, I guess you'd more like to read the resolved options?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I hope to allow users to use prettier intead of stylistic to format GLOB_SRC, but I can not get the internal runtime prettier options easily to keey the consistent format style.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also it will be easily to format others files by prettier if necessary.


/**
* Custom options for dprint.
*
Expand Down