-
Notifications
You must be signed in to change notification settings - Fork 45
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
88 changed files
with
414 additions
and
391 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
18 changes: 8 additions & 10 deletions
18
rules/sort-array-includes-utils.ts → ...array-includes/does-custom-group-match.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
import type { | ||
SingleCustomGroup, | ||
AnyOfCustomGroup, | ||
Modifier, | ||
Selector, | ||
} from './types' | ||
|
||
import { matches } from '../../utils/matches' | ||
|
||
interface DoesCustomGroupMatchProps { | ||
customGroup: SingleCustomGroup | AnyOfCustomGroup | ||
elementValue: undefined | string | ||
selectors: Selector[] | ||
modifiers: Modifier[] | ||
decorators: string[] | ||
elementName: string | ||
} | ||
|
||
/** | ||
* Determines whether a custom group matches the given properties. | ||
* @param {DoesCustomGroupMatchProps} props - The properties to match against | ||
* the custom group, including selectors, modifiers, decorators, and element | ||
* names. | ||
* @returns {boolean} `true` if the custom group matches the properties; | ||
* otherwise, `false`. | ||
*/ | ||
export let doesCustomGroupMatch = ( | ||
props: DoesCustomGroupMatchProps, | ||
): boolean => { | ||
if ('anyOf' in props.customGroup) { | ||
// At least one subgroup must match | ||
return props.customGroup.anyOf.some(subgroup => | ||
doesCustomGroupMatch({ ...props, customGroup: subgroup }), | ||
) | ||
} | ||
if ( | ||
props.customGroup.selector && | ||
!props.selectors.includes(props.customGroup.selector) | ||
) { | ||
return false | ||
} | ||
|
||
if (props.customGroup.modifiers) { | ||
for (let modifier of props.customGroup.modifiers) { | ||
if (!props.modifiers.includes(modifier)) { | ||
return false | ||
} | ||
} | ||
} | ||
|
||
if ( | ||
'elementNamePattern' in props.customGroup && | ||
props.customGroup.elementNamePattern | ||
) { | ||
let matchesElementNamePattern: boolean = matches( | ||
props.elementName, | ||
props.customGroup.elementNamePattern, | ||
) | ||
if (!matchesElementNamePattern) { | ||
return false | ||
} | ||
} | ||
|
||
if ( | ||
'elementValuePattern' in props.customGroup && | ||
props.customGroup.elementValuePattern | ||
) { | ||
let matchesElementValuePattern: boolean = matches( | ||
props.elementValue ?? '', | ||
props.customGroup.elementValuePattern, | ||
) | ||
if (!matchesElementValuePattern) { | ||
return false | ||
} | ||
} | ||
|
||
if ( | ||
'decoratorNamePattern' in props.customGroup && | ||
props.customGroup.decoratorNamePattern | ||
) { | ||
let decoratorPattern = props.customGroup.decoratorNamePattern | ||
let matchesDecoratorNamePattern: boolean = props.decorators.some( | ||
decorator => matches(decorator, decoratorPattern), | ||
) | ||
if (!matchesDecoratorNamePattern) { | ||
return false | ||
} | ||
} | ||
|
||
return true | ||
} |
Oops, something went wrong.