Skip to content

Commit

Permalink
feat(lint-staged): add oxlint support, remove zhlint support
Browse files Browse the repository at this point in the history
  • Loading branch information
ModyQyW committed Jan 4, 2024
1 parent 7f3b79d commit b5ba1c6
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 17 deletions.
2 changes: 1 addition & 1 deletion src/env.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 =
Expand Down
13 changes: 12 additions & 1 deletion src/lint-staged/factory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,27 @@ export function lintStaged(
eslint: enableESLint,
jsonc: lintJsonc,
markdownlint: enableMarkdownlint,
oxlint: enableOxlint,
prettier: enablePrettier,
stylelint: enableStylelint,
yml: lintYml,
} = parseOptions(options);

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';
Expand Down
19 changes: 7 additions & 12 deletions src/lint-staged/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
5 changes: 2 additions & 3 deletions src/lint-staged/utils.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import {
hasESLint,
hasMarkdownlintCli,
hasOxlint,
hasPrettier,
hasStylelint,
hasTsconfigAppJson,
hasTsconfigTestJson,
hasTsconfigVitestJson,
hasTypeScript,
hasVueTsc,
hasZhlint,
} from '../env';
import type { Options } from './types';

Expand All @@ -17,6 +17,7 @@ export function parseOptions(options: Options = {}): Required<Options> {
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,
Expand All @@ -30,7 +31,5 @@ export function parseOptions(options: Options = {}): Required<Options> {
: 'tsconfig.json',
vueTsc: options.vueTsc ?? hasVueTsc,
yml: options.yml ?? true,
zhPatterns: options.zhPatterns ?? ['*.{zh-CN,zh-Hans}.{md,markdown}'],
zhlint: options.zhlint ?? hasZhlint,
};
}

0 comments on commit b5ba1c6

Please sign in to comment.