diff --git a/src/env.ts b/src/env.ts index c835acd9..6d3f4bca 100644 --- a/src/env.ts +++ b/src/env.ts @@ -83,12 +83,12 @@ export const hasTsconfigAppJson = existsSync( ); export const hasESLint = isPackageExists('eslint'); +export const hasOxlint = isPackageExists('oxlint'); export const hasStylelint = isPackageExists('stylelint'); export const hasPrettier = isPackageExists('prettier'); export const hasTsc = isPackageExists('typescript'); export const hasVueTsc = isPackageExists('vue-tsc'); export const hasMarkdownlintCli = isPackageExists('markdownlint-cli'); -export const hasZhlint = isPackageExists('zhlint'); export const hasLintStaged = isPackageExists('lint-staged'); export const hasCommitlint = diff --git a/src/lint-staged/factory.ts b/src/lint-staged/factory.ts index 64f4c6ce..82a1612f 100644 --- a/src/lint-staged/factory.ts +++ b/src/lint-staged/factory.ts @@ -9,6 +9,7 @@ export function lintStaged( eslint: enableESLint, jsonc: lintJsonc, markdownlint: enableMarkdownlint, + oxlint: enableOxlint, prettier: enablePrettier, stylelint: enableStylelint, yml: lintYml, @@ -16,9 +17,19 @@ export function lintStaged( const config: Config = {}; - if (enableESLint) { + if (enableOxlint && enableESLint) { + config['*.{js,cjs,mjs,jsx,ts,cts,mts,tsx,vue}'] = [ + 'oxlint --deny=correctness --deny=perf --fix', + 'eslint --fix --cache --no-error-on-unmatched-pattern', + ]; + } else if (enableOxlint) { + config['*.{js,cjs,mjs,jsx,ts,cts,mts,tsx,vue}'] = 'oxlint --fix'; + } else if (enableESLint) { config['*.{js,cjs,mjs,jsx,ts,cts,mts,tsx,vue}'] = 'eslint --fix --cache --no-error-on-unmatched-pattern'; + } + + if (enableESLint) { if (lintJsonc) { config['*.{json,jsonc,json5}'] = 'eslint --fix --cache --no-error-on-unmatched-pattern'; diff --git a/src/lint-staged/types.ts b/src/lint-staged/types.ts index 6b6cd316..49a03a78 100644 --- a/src/lint-staged/types.ts +++ b/src/lint-staged/types.ts @@ -25,23 +25,18 @@ export interface Options { yml?: boolean; /** - * Use markdownlint. - * - * Enabled by default if you have markdownlint-cli2 installed. - */ - markdownlint?: boolean; - /** - * Markdown files patterns for zhlint. + * Use oxlint. * - * @default *.{zh-CN,zh-Hans}.{md,markdown} + * Enabled by default if you have oxlint installed. */ - zhPatterns?: string[]; + oxlint?: boolean; + /** - * Use zhlint. + * Use markdownlint. * - * Enabled by default if you have zhlint installed. + * Enabled by default if you have markdownlint-cli2 installed. */ - zhlint?: boolean; + markdownlint?: boolean; /** * Use Prettier. diff --git a/src/lint-staged/utils.ts b/src/lint-staged/utils.ts index 6236ff33..854e39cf 100644 --- a/src/lint-staged/utils.ts +++ b/src/lint-staged/utils.ts @@ -1,6 +1,7 @@ import { hasESLint, hasMarkdownlintCli, + hasOxlint, hasPrettier, hasStylelint, hasTsconfigAppJson, @@ -8,7 +9,6 @@ import { hasTsconfigVitestJson, hasTypeScript, hasVueTsc, - hasZhlint, } from '../env'; import type { Options } from './types'; @@ -17,6 +17,7 @@ export function parseOptions(options: Options = {}): Required { eslint: options.eslint ?? hasESLint, jsonc: options.jsonc ?? true, markdownlint: options.markdownlint ?? hasMarkdownlintCli, + oxlint: options.oxlint ?? hasOxlint, prettier: options.prettier ?? hasPrettier, stylelint: options.stylelint ?? hasStylelint, tsc: options.tsc ?? hasTypeScript, @@ -30,7 +31,5 @@ export function parseOptions(options: Options = {}): Required { : 'tsconfig.json', vueTsc: options.vueTsc ?? hasVueTsc, yml: options.yml ?? true, - zhPatterns: options.zhPatterns ?? ['*.{zh-CN,zh-Hans}.{md,markdown}'], - zhlint: options.zhlint ?? hasZhlint, }; }