Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 8522f69

Browse files
committed
feat(composer): add .removePlugins()
1 parent 6210b48 commit 8522f69

File tree

4 files changed

+97
-0
lines changed

4 files changed

+97
-0
lines changed

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@
5959
"@types/node": "^22.15.21",
6060
"bumpp": "^10.1.1",
6161
"eslint": "^9.27.0",
62+
"eslint-plugin-unused-imports": "^4.1.4",
6263
"esno": "^4.8.0",
6364
"jsr": "^0.13.4",
6465
"lint-staged": "^16.0.0",

pnpm-lock.yaml

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/composer.ts

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -266,6 +266,42 @@ export class FlatConfigComposer<
266266
) as any)
267267
}
268268

269+
/**
270+
* Remove plugins by name and all the rules referenced by them.
271+
*
272+
* @example
273+
* ```ts
274+
* composer
275+
* .removePlugins(
276+
* 'node'
277+
* )
278+
* ```
279+
*
280+
* The `plugins: { node }` and `rules: { 'node/xxx': 'error' }` will be removed from all configs.
281+
*/
282+
public removePlugins(
283+
...names: string[]
284+
): this {
285+
this._operationsOverrides.push(async (configs) => {
286+
for (const config of configs) {
287+
if ('plugins' in config && typeof config.plugins === 'object' && config.plugins) {
288+
for (const name of names) {
289+
if (name in config.plugins)
290+
delete (config.plugins as any)[name]
291+
}
292+
}
293+
if ('rules' in config && typeof config.rules === 'object' && config.rules) {
294+
for (const key of Object.keys(config.rules)) {
295+
if (names.some(n => key.startsWith(`${n}/`)))
296+
delete (config.rules as any)[key]
297+
}
298+
}
299+
}
300+
return configs
301+
})
302+
return this
303+
}
304+
269305
/**
270306
* Remove a specific config by name or index.
271307
*/

test/composer.test.ts

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,63 @@ it('override rules', async () => {
177177
`)
178178
})
179179

180+
it('remove plugins', async () => {
181+
const p = composer([
182+
{
183+
name: 'init',
184+
plugins: {
185+
node: {},
186+
},
187+
rules: {
188+
'no-console': 'error',
189+
'no-unused-vars': 'error',
190+
},
191+
},
192+
{
193+
rules: {
194+
'node/no-console': 'error',
195+
'node/no-unused-vars': 'error',
196+
},
197+
},
198+
{
199+
plugins: {
200+
node: {},
201+
node2: {},
202+
},
203+
rules: {
204+
'node/no-console': 'off',
205+
'node/no-unused-vars': 'error',
206+
'node2/no-unused-vars': 'error',
207+
},
208+
},
209+
])
210+
.removePlugins('node')
211+
212+
expect(await p).toMatchInlineSnapshot(`
213+
[
214+
{
215+
"name": "init",
216+
"plugins": {},
217+
"rules": {
218+
"no-console": "error",
219+
"no-unused-vars": "error",
220+
},
221+
},
222+
{
223+
"rules": {},
224+
},
225+
{
226+
"plugins": {
227+
"node2": {},
228+
},
229+
"rules": {
230+
"node2/no-unused-vars": "error",
231+
},
232+
},
233+
]
234+
`)
235+
})
236+
180237
describe('error', () => {
181238
it('error in config', async () => {
182239
const p = composer([{ name: 'init' }])

0 commit comments

Comments
 (0)