Skip to content

Commit

Permalink
feat(projects): add overrides for options
Browse files Browse the repository at this point in the history
  • Loading branch information
honghuangdc committed Apr 27, 2024
1 parent 60049af commit 4485bc3
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 26 deletions.
46 changes: 21 additions & 25 deletions eslint.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,30 +11,26 @@ const useBuild = false;
/** @type {import('./src/index.ts').defineConfig} */
const defineConfig = useBuild ? defineConfig2 : defineConfig1;

export default defineConfig(
{
vue: true,
react: { files: ['**/*react.tsx'] },
svelte: true,
astro: true,
unocss: false,
formatter: {
html: true,
css: true,
json: true,
markdown: true,
yaml: true,
toml: true
}
export default defineConfig({
vue: true,
react: { files: ['**/*react.tsx'] },
svelte: true,
astro: true,
unocss: false,
formatter: {
html: true,
css: true,
json: true,
markdown: true,
yaml: true,
toml: true
},
{
rules: {
'vue/multi-word-component-names': [
'warn',
{
ignores: ['index', 'App', '[id]']
}
]
}
overrides: {
'vue/multi-word-component-names': [
'warn',
{
ignores: ['index', 'App', '[id]']
}
]
}
);
});
5 changes: 5 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,10 @@ export async function defineConfig(options: Partial<Options> = {}, ...userConfig
const prettier = await createPrettierConfig(opts.prettierRules);
const formatter = await createFormatterConfig(opts.formatter, opts.prettierRules);

const overrides: FlatConfigItem = {
rules: opts.overrides
};

const userResolved = await Promise.all(userConfigs);

const configs: FlatConfigItem[] = [
Expand All @@ -55,6 +59,7 @@ export async function defineConfig(options: Partial<Options> = {}, ...userConfig
...astro,
...svelte,
...unocss,
overrides,
...userResolved,
...prettier,
...formatter
Expand Down
7 changes: 6 additions & 1 deletion src/options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ export async function createOptions(options: Partial<Options> = {}) {
const opts: ParsedOptions = {
cwd: process.cwd(),
ignores: GLOB_EXCLUDE,
overrides: {},
prettierRules: {
...DEFAULT_PRETTIER_RULES
},
Expand All @@ -19,7 +20,7 @@ export async function createOptions(options: Partial<Options> = {}) {
}
};

const { cwd, ignores, prettierRules, usePrettierrc, formatter, unocss, ...rest } = options;
const { cwd, ignores, overrides, prettierRules, usePrettierrc, formatter, unocss, ...rest } = options;

if (cwd) {
opts.cwd = cwd;
Expand All @@ -29,6 +30,10 @@ export async function createOptions(options: Partial<Options> = {}) {
opts.ignores = [...opts.ignores, ...ignores];
}

if (overrides) {
opts.overrides = overrides;
}

if (prettierRules) {
opts.prettierRules = { ...opts.prettierRules, ...prettierRules };
}
Expand Down
2 changes: 2 additions & 0 deletions src/types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ export interface BaseOptions {
cwd: string;
/** The globs to ignore lint */
ignores: string[];
/** The override rules */
overrides: FlatConfigItem['rules'];
/**
* Default prettier rules
*
Expand Down

0 comments on commit 4485bc3

Please sign in to comment.