diff --git a/fixtures/output/with-formatters/astro.astro b/fixtures/output/with-formatters/astro.astro index b67c6784ea..47e8620b52 100644 --- a/fixtures/output/with-formatters/astro.astro +++ b/fixtures/output/with-formatters/astro.astro @@ -1,21 +1,18 @@ --- const isJsx = true -const content = 'hi!'; +const content = 'hi!' ---
{content}
- {isJsx && ( -

{content}

- )} + {isJsx &&

{content}

}
- diff --git a/src/configs/formatters.ts b/src/configs/formatters.ts index e0f3782934..87b7e6f459 100644 --- a/src/configs/formatters.ts +++ b/src/configs/formatters.ts @@ -1,5 +1,5 @@ import { isPackageExists } from 'local-pkg' -import { GLOB_ASTRO, GLOB_CSS, GLOB_GRAPHQL, GLOB_HTML, GLOB_LESS, GLOB_MARKDOWN, GLOB_POSTCSS, GLOB_SCSS, GLOB_XML } from '../globs' +import { GLOB_ASTRO, GLOB_ASTRO_TS, GLOB_CSS, GLOB_GRAPHQL, GLOB_HTML, GLOB_LESS, GLOB_MARKDOWN, GLOB_POSTCSS, GLOB_SCSS, GLOB_XML } from '../globs' import type { VendoredPrettierOptions } from '../vender/prettier-types' import { ensurePackages, interopDefault, parserPlain } from '../utils' import type { OptionsFormatters, StylisticConfig, TypedFlatConfigItem } from '../types' @@ -11,7 +11,7 @@ export async function formatters( ): Promise { if (options === true) { options = { - astro: isPackageExists('astro'), + astro: isPackageExists('prettier-plugin-astro'), css: true, graphql: true, html: true, @@ -255,6 +255,20 @@ export async function formatters( ], }, }) + + configs.push({ + files: [GLOB_ASTRO, GLOB_ASTRO_TS], + name: 'antfu/formatter/astro/disables', + rules: { + 'style/arrow-parens': 'off', + 'style/block-spacing': 'off', + 'style/comma-dangle': 'off', + 'style/indent': 'off', + 'style/no-multi-spaces': 'off', + 'style/quotes': 'off', + 'style/semi': 'off', + }, + }) } if (options.graphql) { diff --git a/src/configs/markdown.ts b/src/configs/markdown.ts index fc6b9ab4e0..90e8829f71 100644 --- a/src/configs/markdown.ts +++ b/src/configs/markdown.ts @@ -83,26 +83,6 @@ export async function markdown( 'unused-imports/no-unused-imports': 'off', 'unused-imports/no-unused-vars': 'off', - // Type aware rules - ...{ - 'ts/await-thenable': 'off', - 'ts/dot-notation': 'off', - 'ts/no-floating-promises': 'off', - 'ts/no-for-in-array': 'off', - 'ts/no-implied-eval': 'off', - 'ts/no-misused-promises': 'off', - 'ts/no-throw-literal': 'off', - 'ts/no-unnecessary-type-assertion': 'off', - 'ts/no-unsafe-argument': 'off', - 'ts/no-unsafe-assignment': 'off', - 'ts/no-unsafe-call': 'off', - 'ts/no-unsafe-member-access': 'off', - 'ts/no-unsafe-return': 'off', - 'ts/restrict-plus-operands': 'off', - 'ts/restrict-template-expressions': 'off', - 'ts/unbound-method': 'off', - }, - ...overrides, }, }, diff --git a/src/configs/typescript.ts b/src/configs/typescript.ts index 26dee32cab..de1cce8193 100644 --- a/src/configs/typescript.ts +++ b/src/configs/typescript.ts @@ -1,5 +1,5 @@ import process from 'node:process' -import { GLOB_TS, GLOB_TSX } from '../globs' +import { GLOB_ASTRO_TS, GLOB_MARKDOWN, GLOB_TS, GLOB_TSX } from '../globs' import type { OptionsComponentExts, OptionsFiles, OptionsOverrides, OptionsTypeScriptParserOptions, OptionsTypeScriptWithTypes, TypedFlatConfigItem } from '../types' import { pluginAntfu } from '../plugins' import { interopDefault, renameRules, toArray } from '../utils' @@ -20,6 +20,10 @@ export async function typescript( ] const filesTypeAware = options.filesTypeAware ?? [GLOB_TS, GLOB_TSX] + const ignoresTypeAware = options.ignoresTypeAware ?? [ + `${GLOB_MARKDOWN}/**`, + GLOB_ASTRO_TS, + ] const tsconfigPath = options?.tsconfigPath ? toArray(options.tsconfigPath) : undefined @@ -90,10 +94,12 @@ export async function typescript( // assign type-aware parser for type-aware files and type-unaware parser for the rest ...isTypeAware ? [ - makeParser(true, filesTypeAware), + makeParser(true, filesTypeAware, ignoresTypeAware), makeParser(false, files, filesTypeAware), ] - : [makeParser(false, files)], + : [ + makeParser(false, files), + ], { files, name: 'antfu/typescript/rules', @@ -138,6 +144,7 @@ export async function typescript( ...isTypeAware ? [{ files: filesTypeAware, + ignores: ignoresTypeAware, name: 'antfu/typescript/rules-type-aware', rules: { ...tsconfigPath ? typeAwareRules : {}, diff --git a/src/globs.ts b/src/globs.ts index a423c50640..247e93df48 100644 --- a/src/globs.ts +++ b/src/globs.ts @@ -26,6 +26,7 @@ export const GLOB_TOML = '**/*.toml' export const GLOB_XML = '**/*.xml' export const GLOB_HTML = '**/*.htm?(l)' export const GLOB_ASTRO = '**/*.astro' +export const GLOB_ASTRO_TS = '**/*.astro/*.ts' export const GLOB_GRAPHQL = '**/*.{g,graph}ql' export const GLOB_MARKDOWN_CODE = `${GLOB_MARKDOWN}/${GLOB_SRC}` diff --git a/src/types.ts b/src/types.ts index 7668a73e82..229562a5c5 100644 --- a/src/types.ts +++ b/src/types.ts @@ -138,6 +138,12 @@ export interface OptionsTypeScriptParserOptions { * @default ['**\/*.{ts,tsx}'] */ filesTypeAware?: string[] + + /** + * Glob patterns for files that should not be type aware. + * @default ['**\/*.md\/**', '**\/*.astro/*.ts'] + */ + ignoresTypeAware?: string[] } export interface OptionsTypeScriptWithTypes {