1- import type { CoreConfig } from '@code-pushup/models' ;
1+ import type {
2+ CategoryConfig ,
3+ CoreConfig ,
4+ PluginConfig ,
5+ } from '@code-pushup/models' ;
26import { filterItemRefsBy } from '@code-pushup/utils' ;
37import type { FilterOptions , Filterables } from './filter.model.js' ;
48import {
59 handleConflictingOptions ,
10+ isValidCategoryRef ,
611 validateFilterOption ,
12+ validateFilteredCategories ,
713 validateFinalState ,
814} from './validate-filter-options.utils.js' ;
915
16+ // eslint-disable-next-line max-lines-per-function
1017export function filterMiddleware < T extends FilterOptions > (
1118 originalProcessArgs : T ,
1219) : T {
1320 const {
14- plugins ,
15- categories ,
21+ categories : rcCategories ,
22+ plugins : rcPlugins ,
1623 skipCategories = [ ] ,
1724 onlyCategories = [ ] ,
1825 skipPlugins = [ ] ,
@@ -32,6 +39,13 @@ export function filterMiddleware<T extends FilterOptions>(
3239 handleConflictingOptions ( 'categories' , onlyCategories , skipCategories ) ;
3340 handleConflictingOptions ( 'plugins' , onlyPlugins , skipPlugins ) ;
3441
42+ const plugins = processPlugins ( rcPlugins ) ;
43+ const categories = filterSkippedCategories ( rcCategories , plugins ) ;
44+
45+ if ( rcCategories && categories && verbose ) {
46+ validateFilteredCategories ( rcCategories , categories ) ;
47+ }
48+
3549 const filteredCategories = applyCategoryFilters (
3650 { categories, plugins } ,
3751 skipCategories ,
@@ -52,7 +66,7 @@ export function filterMiddleware<T extends FilterOptions>(
5266
5367 validateFinalState (
5468 { categories : finalCategories , plugins : filteredPlugins } ,
55- { categories, plugins } ,
69+ { categories : rcCategories , plugins : rcPlugins } ,
5670 ) ;
5771
5872 return {
@@ -141,3 +155,51 @@ function filterPluginsFromCategories({
141155 ) ;
142156 return plugins . filter ( plugin => validPluginSlugs . has ( plugin . slug ) ) ;
143157}
158+
159+ function filterSkippedItems < T extends { isSkipped ?: boolean } > (
160+ items : T [ ] | undefined ,
161+ ) : T [ ] {
162+ return ( items ?? [ ] ) . filter ( ( { isSkipped } ) => isSkipped !== true ) ;
163+ }
164+
165+ export function filterSkippedGroups (
166+ groups : PluginConfig [ 'groups' ] ,
167+ audits : PluginConfig [ 'audits' ] ,
168+ ) : PluginConfig [ 'groups' ] {
169+ if ( ! groups ) {
170+ return groups ;
171+ }
172+ return filterItemRefsBy ( groups , ref =>
173+ audits . some ( audit => audit . slug === ref . slug && audit . isSkipped !== true ) ,
174+ ) ;
175+ }
176+
177+ export function processPlugins ( plugins : PluginConfig [ ] ) : PluginConfig [ ] {
178+ return plugins . map ( ( plugin : PluginConfig ) => ( {
179+ ...plugin ,
180+ ...( plugin . groups && {
181+ groups : filterSkippedGroups (
182+ filterSkippedItems ( plugin . groups ) ,
183+ filterSkippedItems ( plugin . audits ) ,
184+ ) ,
185+ } ) ,
186+ audits : filterSkippedItems ( plugin . audits ) ,
187+ } ) ) ;
188+ }
189+
190+ export function filterSkippedCategories (
191+ categories : CoreConfig [ 'categories' ] ,
192+ plugins : CoreConfig [ 'plugins' ] ,
193+ ) : CoreConfig [ 'categories' ] {
194+ if ( ! categories || categories . length === 0 ) {
195+ return categories ;
196+ }
197+ return categories
198+ . map ( category => {
199+ const validRefs = category . refs . filter ( ref =>
200+ isValidCategoryRef ( ref , plugins ) ,
201+ ) ;
202+ return validRefs . length > 0 ? { ...category , refs : validRefs } : null ;
203+ } )
204+ . filter ( ( category ) : category is CategoryConfig => category != null ) ;
205+ }
0 commit comments