New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

eslint-flat-config-utils

Package Overview
Dependencies
Maintainers
1
Versions
19
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

eslint-flat-config-utils - npm Package Compare versions

Comparing version 0.0.1 to 0.0.2

100

dist/index.d.ts

@@ -78,43 +78,97 @@ import { Linter } from 'eslint';

/**
* Create a pipeline to build a flat config.
* Create a chainable pipeline object that makes manipulating ESLint flat config easier.
*
* @example
* It extends Promise, so that you can directly await or export it to `eslint.config.mjs`
*
* ```ts
* // eslint.config.mjs
* import { pipe } from 'eslint-flat-config-utils'
*
* export pipe(
* // ...flat configs
* export default pipe(
* {
* plugins: {},
* rules: {},
* }
* // ...some configs, accepts same arguments as `concat`
* )
* .append(
* // appends more configs at the end, accepts same arguments as `concat`
* )
* .prepend(
* // ...flat configs
* // prepends more configs at the beginning, accepts same arguments as `concat`
* )
* .insetAfter('some-config',
* // ...flat configs
* .insertAfter(
* 'config-name', // specify the name of the target config, or index
* // insert more configs after the target, accepts same arguments as `concat`
* )
* .override('some-config', {
* rules: {
* 'no-console': 'off',
* .renamePlugins({
* // rename plugins
* 'old-name': 'new-name',
* // for example, rename `n` from `eslint-plugin-n` to more a explicit prefix `node`
* 'n': 'node'
* // applies to all plugins and rules in the configs
* })
* .override(
* 'config-name', // specify the name of the target config, or index
* {
* // merge with the target config
* rules: {
* 'no-console': 'off'
* },
* }
* })
* .setRenames({
* 'n': 'node',
* 'import-x': 'import',
* '@typescript-eslint': 'ts'
* })
* )
*
* // And you an directly return the pipeline object to `eslint.config.mjs`
* ```
*/
declare function pipe(...configs: Awaitable<FlatConfigItem | FlatConfigItem[]>[]): FlatConfigPipeline<FlatConfigItem>;
/**
* The underlying impolementation of `pipe()`.
*
* You don't need to use this class directly.
*/
declare class FlatConfigPipeline<T extends FlatConfigItem = FlatConfigItem> extends Promise<T[]> {
private _promises;
private _operations;
private _operationsPost;
private _renames;
constructor();
setRenames(renames: Record<string, string>): this;
getRenames(): Record<string, string>;
/**
* Set plugin renames, like `n` -> `node`, `import-x` -> `import`, etc.
*
* This will runs after all config items are resolved. Applies to `plugins` and `rules`.
*/
renamePlugins(renames: Record<string, string>): this;
/**
* Append configs to the end of the current configs array.
*/
append(...items: Awaitable<T | T[]>[]): this;
/**
* Prepend configs to the beginning of the current configs array.
*/
prepend(...items: Awaitable<T | T[]>[]): this;
insertBefore(name: string, ...items: Awaitable<T | T[]>[]): this;
insertAfter(name: string, ...items: Awaitable<T | T[]>[]): this;
override(name: string, config: T | ((config: T) => Awaitable<T>)): this;
overrides(overrides: Record<string, T | ((config: T) => Awaitable<T>)>): this;
/**
* Insert configs before a specific config.
*/
insertBefore(nameOrIndex: string | number, ...items: Awaitable<T | T[]>[]): this;
/**
* Insert configs after a specific config.
*/
insertAfter(nameOrIndex: string | number, ...items: Awaitable<T | T[]>[]): this;
/**
* Provide overrides to a specific config.
*
* It will be merged with the original config, or provide a custom function to replace the config entirely.
*/
override(nameOrIndex: string | number, config: T | ((config: T) => Awaitable<T>)): this;
/**
* Provide overrides to multiple configs as an object map.
*
* Same as calling `override` multiple times.
*/
overrides(overrides: Record<string | number, T | ((config: T) => Awaitable<T>)>): this;
/**
* Resolve the pipeline and return the final configs.
*
* This returns a promise. Calling `.then()` has the same effect.
*/
toConfigs(): Promise<T[]>;

@@ -121,0 +175,0 @@ then(onFulfilled: (value: T[]) => any, onRejected?: (reason: any) => any): Promise<any>;

{
"name": "eslint-flat-config-utils",
"type": "module",
"version": "0.0.1",
"version": "0.0.2",
"packageManager": "pnpm@8.15.5",

@@ -6,0 +6,0 @@ "description": "Utils for managing and manipulating ESLint flat config arrays",

@@ -19,11 +19,85 @@ # eslint-flat-config-utils

## Utils
Most of the descriptions are written in JSDoc, you can find more details in the [documentation](https://jsr.io/@antfu/eslint-flat-config-utils/doc) via JSR.
Here listing a few highlighted ones:
### `concat`
Concatenate multiple ESLint flat configs into one, resolve the promises, and flatten the array.
```ts
// eslint.config.mjs
import { conact, defineFlatConfig, renamePluginsInConfigs } from 'eslint-flat-config-utils'
import { conact } from 'eslint-flat-config-utils'
export default conact(
// configs...
{
plugins: {},
rules: {},
},
// It can also takes a array of configs:
[
{
plugins: {},
rules: {},
}
// ...
],
// Or promises:
Promise.resolve({
files: ['*.ts'],
rules: {},
})
// ...
)
```
### `pipe`
Create a chainable pipeline object that makes manipulating ESLint flat config easier.
It extends Promise, so that you can directly await or export it to `eslint.config.mjs`
```ts
// eslint.config.mjs
import { pipe } from 'eslint-flat-config-utils'
export default pipe(
{
plugins: {},
rules: {},
}
// ...some configs, accepts same arguments as `concat`
)
.append(
// appends more configs at the end, accepts same arguments as `concat`
)
.prepend(
// prepends more configs at the beginning, accepts same arguments as `concat`
)
.insertAfter(
'config-name', // specify the name of the target config, or index
// insert more configs after the target, accepts same arguments as `concat`
)
.renamePlugins({
// rename plugins
'old-name': 'new-name',
// for example, rename `n` from `eslint-plugin-n` to more a explicit prefix `node`
'n': 'node'
// applies to all plugins and rules in the configs
})
.override(
'config-name', // specify the name of the target config, or index
{
// merge with the target config
rules: {
'no-console': 'off'
},
}
)
// And you an directly return the pipeline object to `eslint.config.mjs`
```
## Sponsors

@@ -30,0 +104,0 @@

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc