Skip to content

Commit

Permalink
feat: add graphql to formatters, provide shorthand for enable all for…
Browse files Browse the repository at this point in the history
…matters
  • Loading branch information
antfu committed Dec 4, 2023
1 parent 5984f73 commit e192d3e
Show file tree
Hide file tree
Showing 7 changed files with 43 additions and 15 deletions.
1 change: 1 addition & 0 deletions README.md
Expand Up @@ -120,6 +120,7 @@ Add the following settings to your `.vscode/settings.json`:
// Silent the stylistic rules in you IDE, but still auto fix them
"eslint.rules.customizations": [
{ "rule": "style/*", "severity": "off" },
{ "rule": "format/*", "severity": "off" },
{ "rule": "*-indent", "severity": "off" },
{ "rule": "*-spacing", "severity": "off" },
{ "rule": "*-spaces", "severity": "off" },
Expand Down
6 changes: 1 addition & 5 deletions eslint.config.js
Expand Up @@ -11,11 +11,7 @@ export default antfu(
'fixtures',
'_fixtures',
],
formatters: {
css: true,
html: true,
markdown: true,
},
formatters: true,
},
{
files: ['src/**/*.ts'],
Expand Down
2 changes: 1 addition & 1 deletion src/cli/constants.ts
Expand Up @@ -26,7 +26,7 @@ export const vscodeSettingsString = `
// Silent the stylistic rules in you IDE, but still auto fix them
"eslint.rules.customizations": [
{ "rule": "style/*", "severity": "off" },
{ "rule": "prettier/*", "severity": "off" },
{ "rule": "format/*", "severity": "off" },
{ "rule": "*-indent", "severity": "off" },
{ "rule": "*-spacing", "severity": "off" },
{ "rule": "*-spaces", "severity": "off" },
Expand Down
31 changes: 30 additions & 1 deletion src/configs/formatters.ts
Expand Up @@ -5,13 +5,23 @@ import type { FlatConfigItem, OptionsFormatters, StylisticConfig } from '../type
import { StylisticConfigDefaults } from './stylistic'

export async function formatters(
options: OptionsFormatters = {},
options: OptionsFormatters | true = {},
stylistic: StylisticConfig = {},
): Promise<FlatConfigItem[]> {
await ensurePackages([
'eslint-plugin-format',
])

if (options === true) {
options = {
css: true,
graphql: true,
html: true,
markdown: true,
toml: true,
}
}

const {
indent,
quotes,
Expand Down Expand Up @@ -170,5 +180,24 @@ export async function formatters(
})
}

if (options.graphql) {
configs.push({
files: ['**/*.graphql'],

This comment has been minimized.

Copy link
@Henvy-Mango

Henvy-Mango Feb 4, 2024

we also need to support *.gql

languageOptions: {
parser: pluginFormat.parserPlain,
},
name: 'antfu:formatter:graphql',
rules: {
'format/prettier': [
'error',
{
...prettierOptions,
parser: 'graphql',
},
],
},
})
}

return configs
}
2 changes: 1 addition & 1 deletion src/factory.ts
Expand Up @@ -172,7 +172,7 @@ export async function antfu(
componentExts,
overrides: overrides.markdown,
},
!!options.formatters?.markdown,
options.formatters === true || !!(options.formatters || {})?.markdown,
),
)
}
Expand Down
9 changes: 8 additions & 1 deletion src/types.ts
Expand Up @@ -109,6 +109,11 @@ export interface OptionsFormatters {
*/
markdown?: 'prettier' | 'dprint' | boolean

/**
* Enable formatting support for GraphQL.
*/
graphql?: 'prettier' | boolean

/**
* Custom options for Prettier.
*
Expand Down Expand Up @@ -280,9 +285,11 @@ export interface OptionsConfig extends OptionsComponentExts {
* Requires installing:
* - `eslint-plugin-format`
*
* When set to `true`, it will enable all formatters.
*
* @default false
*/
formatters?: OptionsFormatters
formatters?: boolean | OptionsFormatters

/**
* Control to disable some rules in editors.
Expand Down
7 changes: 1 addition & 6 deletions test/fixtures.test.ts
Expand Up @@ -60,12 +60,7 @@ runWithConfig(
{
typescript: true,
vue: true,
formatters: {
css: true,
html: true,
markdown: true,
toml: 'dprint',
},
formatters: true,
},
)

Expand Down

0 comments on commit e192d3e

Please sign in to comment.