gitea push

This commit is contained in:
2026-05-09 12:19:29 -06:00
parent 06113c95b8
commit 429461e985
1481 changed files with 74306 additions and 52475 deletions
+21
View File
@@ -185,6 +185,27 @@ const config = await composer([
> [!NOTE]
> This function **mutate** the plugin object which will affect all the references to the plugin object globally. The changes are not reversible in the current runtime.
##### `composer.setDefaultIgnores`
Sets default `ignores` globs for configs that have rules but no explicit scoping (`files`, `ignores`, or `language`). Useful when mixing fundamentally different languages (e.g. JS + Markdown) and you want global rule configs to not "leak" into a foreign language whose `SourceCode` lacks JS-only methods.
The callback receives the composer's previously-accumulated globs and returns the new list, so calls compose:
```ts
const config = await composer([
// gains `ignores: ['**/*.md']`
{ rules: { 'no-irregular-whitespace': 'error' } },
// explicit `files`, untouched
{ files: ['**/*.md'], rules: { 'markdown/heading-increment': 'error' } },
])
.setDefaultIgnores(() => ['**/*.md'])
.setDefaultIgnores(prev => [...prev, '**/*.json']) // additive
```
Configs without rules (`plugins`-only, `languageOptions`-only, setup blocks) are left as-is. Configs already scoped (with `files`, `ignores`, or `language` set) are also left as-is.
When a sub-composer is appended into another via `append`/`prepend`/`insertBefore`/`insertAfter`/`replace`, the parent absorbs the child's accumulated globs at append time — so a default-ignores declared on the inner composer also protects the parent's other unscoped configs.
### `extend`
Extend another flat config from a different root, and rewrite the glob paths accordingly:
+25
View File
@@ -160,6 +160,7 @@ declare class FlatConfigComposer<T extends object = ConfigWithExtends, ConfigNam
private _operationsResolved;
private _renames;
private _renamesOptions;
private _defaultIgnores;
private _pluginsConflictsError;
constructor(...configs: ResolvableFlatConfig<T>[]);
/**
@@ -168,6 +169,30 @@ declare class FlatConfigComposer<T extends object = ConfigWithExtends, ConfigNam
* This will runs after all config items are resolved. Applies to `plugins` and `rules`.
*/
renamePlugins(renames: Record<string, string>, options?: RenamePluginsInConfigsOptions): this;
/**
* Set default `ignores` globs for configs that have rules but no explicit
* scoping (`files` / `ignores` / `language`).
*
* The callback receives the composer's previously-accumulated globs and
* returns the new list, so calls compose:
*
* ```ts
* composer
* .setDefaultIgnores(() => ['**\/*.md'])
* .setDefaultIgnores(prev => [...prev, '**\/*.json'])
* ```
*
* Useful when mixing fundamentally different languages (e.g. JS + Markdown)
* and you want global rule configs to not "leak" into a foreign language
* whose `SourceCode` lacks JS-only methods.
*/
setDefaultIgnores(fn: (globs: string[]) => string[]): this;
/**
* Absorb another composer's accumulated state when it is appended/prepended/etc.
* into this one, so renames and default-ignores globs declared on the inner
* composer apply to the parent's other configs as well.
*/
private _absorbComposer;
/**
* Append configs to the end of the current configs array.
*/
+25
View File
@@ -160,6 +160,7 @@ declare class FlatConfigComposer<T extends object = ConfigWithExtends, ConfigNam
private _operationsResolved;
private _renames;
private _renamesOptions;
private _defaultIgnores;
private _pluginsConflictsError;
constructor(...configs: ResolvableFlatConfig<T>[]);
/**
@@ -168,6 +169,30 @@ declare class FlatConfigComposer<T extends object = ConfigWithExtends, ConfigNam
* This will runs after all config items are resolved. Applies to `plugins` and `rules`.
*/
renamePlugins(renames: Record<string, string>, options?: RenamePluginsInConfigsOptions): this;
/**
* Set default `ignores` globs for configs that have rules but no explicit
* scoping (`files` / `ignores` / `language`).
*
* The callback receives the composer's previously-accumulated globs and
* returns the new list, so calls compose:
*
* ```ts
* composer
* .setDefaultIgnores(() => ['**\/*.md'])
* .setDefaultIgnores(prev => [...prev, '**\/*.json'])
* ```
*
* Useful when mixing fundamentally different languages (e.g. JS + Markdown)
* and you want global rule configs to not "leak" into a foreign language
* whose `SourceCode` lacks JS-only methods.
*/
setDefaultIgnores(fn: (globs: string[]) => string[]): this;
/**
* Absorb another composer's accumulated state when it is appended/prepended/etc.
* into this one, so renames and default-ignores globs declared on the inner
* composer apply to the parent's other configs as well.
*/
private _absorbComposer;
/**
* Append configs to the end of the current configs array.
*/
+67
View File
@@ -186,6 +186,7 @@ class FlatConfigComposer extends Promise {
_operationsResolved = [];
_renames = {};
_renamesOptions;
_defaultIgnores = [];
_pluginsConflictsError = /* @__PURE__ */ new Map();
constructor(...configs) {
super(() => {
@@ -203,10 +204,46 @@ class FlatConfigComposer extends Promise {
this._renamesOptions = options;
return this;
}
/**
* Set default `ignores` globs for configs that have rules but no explicit
* scoping (`files` / `ignores` / `language`).
*
* The callback receives the composer's previously-accumulated globs and
* returns the new list, so calls compose:
*
* ```ts
* composer
* .setDefaultIgnores(() => ['**\/*.md'])
* .setDefaultIgnores(prev => [...prev, '**\/*.json'])
* ```
*
* Useful when mixing fundamentally different languages (e.g. JS + Markdown)
* and you want global rule configs to not "leak" into a foreign language
* whose `SourceCode` lacks JS-only methods.
*/
setDefaultIgnores(fn) {
this._defaultIgnores = fn(this._defaultIgnores);
return this;
}
/**
* Absorb another composer's accumulated state when it is appended/prepended/etc.
* into this one, so renames and default-ignores globs declared on the inner
* composer apply to the parent's other configs as well.
*/
_absorbComposer(other) {
this._renames = { ...other._renames, ...this._renames };
if (!this._renamesOptions && other._renamesOptions)
this._renamesOptions = other._renamesOptions;
this._defaultIgnores = [.../* @__PURE__ */ new Set([...this._defaultIgnores, ...other._defaultIgnores])];
}
/**
* Append configs to the end of the current configs array.
*/
append(...items) {
for (const item of items) {
if (item instanceof FlatConfigComposer)
this._absorbComposer(item);
}
const promise = Promise.all(items);
this._operations.push(async (configs) => {
const resolved = (await promise).flat().filter(Boolean);
@@ -218,6 +255,10 @@ class FlatConfigComposer extends Promise {
* Prepend configs to the beginning of the current configs array.
*/
prepend(...items) {
for (const item of items) {
if (item instanceof FlatConfigComposer)
this._absorbComposer(item);
}
const promise = Promise.all(items);
this._operations.push(async (configs) => {
const resolved = (await promise).flat().filter(Boolean);
@@ -229,6 +270,10 @@ class FlatConfigComposer extends Promise {
* Insert configs before a specific config.
*/
insertBefore(nameOrIndex, ...items) {
for (const item of items) {
if (item instanceof FlatConfigComposer)
this._absorbComposer(item);
}
const promise = Promise.all(items);
this._operations.push(async (configs) => {
const resolved = (await promise).flat().filter(Boolean);
@@ -242,6 +287,10 @@ class FlatConfigComposer extends Promise {
* Insert configs after a specific config.
*/
insertAfter(nameOrIndex, ...items) {
for (const item of items) {
if (item instanceof FlatConfigComposer)
this._absorbComposer(item);
}
const promise = Promise.all(items);
this._operations.push(async (configs) => {
const resolved = (await promise).flat().filter(Boolean);
@@ -410,6 +459,10 @@ class FlatConfigComposer extends Promise {
* The original config will be removed and replaced with the new one.
*/
replace(nameOrIndex, ...items) {
for (const item of items) {
if (item instanceof FlatConfigComposer)
this._absorbComposer(item);
}
const promise = Promise.all(items);
this._operations.push(async (configs) => {
const resolved = (await promise).flat().filter(Boolean);
@@ -523,6 +576,7 @@ ${errors.map((e, i) => ` ${i + 1}: ${e}`).join("\n")}`);
composer2._operationsResolved = this._operationsResolved.slice();
composer2._renames = { ...this._renames };
composer2._renamesOptions = this._renamesOptions;
composer2._defaultIgnores = this._defaultIgnores.slice();
composer2._pluginsConflictsError = new Map(this._pluginsConflictsError);
return composer2;
}
@@ -538,6 +592,19 @@ ${errors.map((e, i) => ` ${i + 1}: ${e}`).join("\n")}`);
for (const promise of this._operationsOverrides)
configs = await promise(configs);
configs = renamePluginsInConfigs(configs, this._renames, this._renamesOptions);
if (this._defaultIgnores.length) {
for (const config of configs) {
if (!config.rules || Object.keys(config.rules).length === 0)
continue;
if (config.files)
continue;
if (config.ignores)
continue;
if (config.language)
continue;
config.ignores = [...this._defaultIgnores];
}
}
for (const promise of this._operationsResolved)
configs = await promise(configs) || configs;
const resolved = defineConfig(configs);
+10 -10
View File
@@ -1,7 +1,7 @@
{
"name": "eslint-flat-config-utils",
"type": "module",
"version": "3.1.0",
"version": "3.2.0",
"description": "Utils for managing and manipulating ESLint flat config arrays",
"author": "Anthony Fu <anthonyfu117@hotmail.com>",
"license": "MIT",
@@ -38,27 +38,27 @@
"dist"
],
"dependencies": {
"@eslint/config-helpers": "^0.5.3",
"@eslint/config-helpers": "^0.5.5",
"pathe": "^2.0.3"
},
"devDependencies": {
"@antfu/eslint-config": "^7.7.3",
"@antfu/ni": "^30.0.0",
"@antfu/eslint-config": "^8.2.0",
"@antfu/ni": "^30.1.0",
"@antfu/utils": "^9.3.0",
"@types/node": "^25.5.0",
"@types/node": "^25.6.0",
"bumpp": "^11.0.1",
"eslint": "^10.1.0",
"eslint": "^10.2.1",
"eslint-plugin-unused-imports": "^4.4.1",
"jsr": "^0.14.3",
"lint-staged": "^16.4.0",
"pnpm": "^10.32.1",
"pnpm": "^10.33.2",
"rimraf": "^6.1.3",
"simple-git-hooks": "^2.13.1",
"tsx": "^4.21.0",
"typescript": "^5.9.3",
"typescript": "^6.0.3",
"unbuild": "^3.6.1",
"vite": "^8.0.2",
"vitest": "^4.1.1"
"vite": "^8.0.10",
"vitest": "^4.1.5"
},
"simple-git-hooks": {
"pre-commit": "pnpm lint-staged"