diff --git a/docs/content/rules/sort-array-includes.mdx b/docs/content/rules/sort-array-includes.mdx index b17774f8..bc6c4533 100644 --- a/docs/content/rules/sort-array-includes.mdx +++ b/docs/content/rules/sort-array-includes.mdx @@ -197,6 +197,15 @@ if ([ } ``` +### matcher + +default: `'minimatch'` + +Determines the matcher used for patterns in the `partitionByComment` option. + +- `'minimatch'` — Use the [minimatch](https://github.com/isaacs/minimatch) library for pattern matching. +- `'regex'` — Use regular expressions for pattern matching. + ## Usage default: `'minimatch'` + +Determines the matcher used for patterns in the `customGroups` option. + +- `'minimatch'` — Use the [minimatch](https://github.com/isaacs/minimatch) library for pattern matching. +- `'regex'` — Use regular expressions for pattern matching. + ## Usage In order to start using this rule, you need to install additional dependency: diff --git a/docs/content/rules/sort-classes.mdx b/docs/content/rules/sort-classes.mdx index 19d2e29a..cfc78a75 100644 --- a/docs/content/rules/sort-classes.mdx +++ b/docs/content/rules/sort-classes.mdx @@ -557,6 +557,15 @@ Example: } ``` +### matcher + +default: `'minimatch'` + +Determines the matcher used for patterns in the `internalPattern` and `customGroups` options. + +- `'minimatch'` — Use the [minimatch](https://github.com/isaacs/minimatch) library for pattern matching. +- `'regex'` — Use regular expressions for pattern matching. + ## Usage default: `'minimatch'` + +Determines the matcher used for patterns in the `partitionByComment` option. + +- `'minimatch'` — Use the [minimatch](https://github.com/isaacs/minimatch) library for pattern matching. +- `'regex'` — Use regular expressions for pattern matching. + ## Usage default: `'minimatch'` + +Determines the matcher used for patterns in the `partitionByComment` option. + +- `'minimatch'` — Use the [minimatch](https://github.com/isaacs/minimatch) library for pattern matching. +- `'regex'` — Use regular expressions for pattern matching. ## Usage diff --git a/docs/content/rules/sort-imports.mdx b/docs/content/rules/sort-imports.mdx index e452fb36..f6284fb7 100644 --- a/docs/content/rules/sort-imports.mdx +++ b/docs/content/rules/sort-imports.mdx @@ -147,7 +147,7 @@ Controls whether sorting should be case-sensitive or not. ### internalPattern -default: `['~/**']` +default: `['~/**']` for `minimatch` matcher, `['^~/.*']` for `regex` matcher Allows you to specify a pattern for identifying internal imports. This is useful for distinguishing your own modules from external dependencies. @@ -292,6 +292,15 @@ Example: } ``` +### matcher + +default: `'minimatch'` + +Determines the matcher used for patterns in the `internalPattern` and `customGroups` options. + +- `'minimatch'` — Use the [minimatch](https://github.com/isaacs/minimatch) library for pattern matching. +- `'regex'` — Use regular expressions for pattern matching. + ### environment default: `'node'` @@ -319,6 +328,7 @@ Specifies which environment’s built-in modules should be recognized. If you ar type: 'alphabetical', order: 'asc', ignoreCase: true, + matcher: 'minimatch', internalPattern: ['~/**'], newlinesBetween: 'always', maxLineLength: undefined, @@ -357,6 +367,7 @@ Specifies which environment’s built-in modules should be recognized. If you ar type: 'alphabetical', order: 'asc', ignoreCase: true, + matcher: 'minimatch', internalPattern: ['~/**'], newlinesBetween: 'always', maxLineLength: undefined, diff --git a/docs/content/rules/sort-interfaces.mdx b/docs/content/rules/sort-interfaces.mdx index a3ac27fc..bee3642d 100644 --- a/docs/content/rules/sort-interfaces.mdx +++ b/docs/content/rules/sort-interfaces.mdx @@ -249,6 +249,14 @@ Example: } ``` +### matcher + +default: `'minimatch'` + +Determines the matcher used for patterns in the `partitionByComment` and `customGroups` option. + +- `'minimatch'` — Use the [minimatch](https://github.com/isaacs/minimatch) library for pattern matching. +- `'regex'` — Use regular expressions for pattern matching. ## Usage diff --git a/docs/content/rules/sort-intersection-types.mdx b/docs/content/rules/sort-intersection-types.mdx index d8cda690..e42df636 100644 --- a/docs/content/rules/sort-intersection-types.mdx +++ b/docs/content/rules/sort-intersection-types.mdx @@ -190,6 +190,15 @@ type Example = & undefined; ``` +### matcher + +default: `'minimatch'` + +Determines the matcher used for patterns in the `partitionByComment` option. + +- `'minimatch'` — Use the [minimatch](https://github.com/isaacs/minimatch) library for pattern matching. +- `'regex'` — Use regular expressions for pattern matching. + ## Usage default: `'minimatch'` + +Determines the matcher used for patterns in the `customGroups` option. + +- `'minimatch'` — Use the [minimatch](https://github.com/isaacs/minimatch) library for pattern matching. +- `'regex'` — Use regular expressions for pattern matching. + ## Usage default: `'minimatch'` + +Determines the matcher used for patterns in the `partitionByComment` option. + +- `'minimatch'` — Use the [minimatch](https://github.com/isaacs/minimatch) library for pattern matching. +- `'regex'` — Use regular expressions for pattern matching. + ## Usage default: `'minimatch'` + +Determines the matcher used for patterns in the `partitionByComment` option. + +- `'minimatch'` — Use the [minimatch](https://github.com/isaacs/minimatch) library for pattern matching. +- `'regex'` — Use regular expressions for pattern matching. + ## Usage default: `'minimatch'` + +Determines the matcher used for patterns in the `internalPattern` and `customGroups` options. + +- `'minimatch'` — Use the [minimatch](https://github.com/isaacs/minimatch) library for pattern matching. +- `'regex'` — Use regular expressions for pattern matching. + ## Usage default: `'minimatch'` + +Determines the matcher used for patterns in the `internalPattern` and `customGroups` options. + +- `'minimatch'` — Use the [minimatch](https://github.com/isaacs/minimatch) library for pattern matching. +- `'regex'` — Use regular expressions for pattern matching. + ## Usage default: `'minimatch'` + +Determines the matcher used for patterns in the `partitionByComment` option. + +- `'minimatch'` — Use the [minimatch](https://github.com/isaacs/minimatch) library for pattern matching. +- `'regex'` — Use regular expressions for pattern matching. + ## Usage default: `'minimatch'` + +Determines the matcher used for patterns in the `customGroups` option. + +- `'minimatch'` — Use the [minimatch](https://github.com/isaacs/minimatch) library for pattern matching. +- `'regex'` — Use regular expressions for pattern matching. + ## Usage In order to start using this rule, you need to install additional dependency: diff --git a/docs/content/rules/sort-union-types.mdx b/docs/content/rules/sort-union-types.mdx index 11ca5df6..c4be4393 100644 --- a/docs/content/rules/sort-union-types.mdx +++ b/docs/content/rules/sort-union-types.mdx @@ -253,6 +253,15 @@ groups: [ ], ``` +### matcher + +default: `'minimatch'` + +Determines the matcher used for patterns in the `partitionByComment` option. + +- `'minimatch'` — Use the [minimatch](https://github.com/isaacs/minimatch) library for pattern matching. +- `'regex'` — Use regular expressions for pattern matching. + ## Usage default: `'minimatch'` + +Determines the matcher used for patterns in the `partitionByComment` option. + +- `'minimatch'` — Use the [minimatch](https://github.com/isaacs/minimatch) library for pattern matching. +- `'regex'` — Use regular expressions for pattern matching. + ## Usage default: `'minimatch'` + +Determines the matcher used for patterns in the `customGroups` option. + +- `'minimatch'` — Use the [minimatch](https://github.com/isaacs/minimatch) library for pattern matching. +- `'regex'` — Use regular expressions for pattern matching. + ## Usage In order to start using this rule, you need to install additional dependency: diff --git a/rules/sort-array-includes.ts b/rules/sort-array-includes.ts index edde6217..0e6d8f80 100644 --- a/rules/sort-array-includes.ts +++ b/rules/sort-array-includes.ts @@ -27,6 +27,7 @@ export type Options = [ groupKind: 'literals-first' | 'spreads-first' | 'mixed' type: 'alphabetical' | 'line-length' | 'natural' partitionByComment: string[] | boolean | string + matcher: 'minimatch' | 'regex' partitionByNewLine: boolean order: 'desc' | 'asc' ignoreCase: boolean @@ -47,6 +48,11 @@ export let jsonSchema: JSONSchema4 = { type: 'string', enum: ['asc', 'desc'], }, + matcher: { + description: 'Specifies the string matcher.', + type: 'string', + enum: ['minimatch', 'regex'], + }, ignoreCase: { description: 'Controls whether sorting should be case-sensitive or not.', type: 'boolean', @@ -102,6 +108,7 @@ export default createEslintRule({ type: 'alphabetical', order: 'asc', ignoreCase: true, + matcher: 'minimatch', groupKind: 'literals-first', partitionByComment: false, partitionByNewLine: false, @@ -137,6 +144,7 @@ export let sortArray = ( groupKind: 'literals-first', type: 'alphabetical', ignoreCase: true, + matcher: 'minimatch', order: 'asc', partitionByComment: false, partitionByNewLine: false, @@ -171,6 +179,7 @@ export let sortArray = ( hasPartitionComment( partitionComment, getCommentsBefore(element, sourceCode), + options.matcher, )) || (options.partitionByNewLine && lastSortingNode && @@ -221,9 +230,7 @@ export let sortArray = ( .flat() : sortNodes(nodes, options) - return makeFixes(fixer, nodes, sortedNodes, sourceCode, { - partitionComment, - }) + return makeFixes(fixer, nodes, sortedNodes, sourceCode, options) }, }) } diff --git a/rules/sort-astro-attributes.ts b/rules/sort-astro-attributes.ts index 52a2169a..2cbb0dda 100644 --- a/rules/sort-astro-attributes.ts +++ b/rules/sort-astro-attributes.ts @@ -33,6 +33,7 @@ type Options = [ customGroups: { [key in T[number]]: string[] | string } type: 'alphabetical' | 'line-length' | 'natural' groups: (Group[] | Group)[] + matcher: 'minimatch' | 'regex' order: 'desc' | 'asc' ignoreCase: boolean }>, @@ -61,6 +62,11 @@ export default createEslintRule, MESSAGE_ID>({ type: 'string', enum: ['asc', 'desc'], }, + matcher: { + description: 'Specifies the string matcher.', + type: 'string', + enum: ['minimatch', 'regex'], + }, ignoreCase: { description: 'Controls whether sorting should be case-sensitive or not.', @@ -116,6 +122,7 @@ export default createEslintRule, MESSAGE_ID>({ type: 'alphabetical', order: 'asc', ignoreCase: true, + matcher: 'minimatch', groups: [], customGroups: {}, }, @@ -136,6 +143,7 @@ export default createEslintRule, MESSAGE_ID>({ let options = complete(context.options.at(0), settings, { type: 'alphabetical', ignoreCase: true, + matcher: 'minimatch', customGroups: {}, order: 'asc', groups: [], @@ -161,9 +169,8 @@ export default createEslintRule, MESSAGE_ID>({ ? attribute.name.name : sourceCode.text.slice(...attribute.name.range) - let { getGroup, defineGroup, setCustomGroups } = useGroups( - options.groups, - ) + let { getGroup, defineGroup, setCustomGroups } = + useGroups(options) setCustomGroups(options.customGroups, name) diff --git a/rules/sort-classes-utils.ts b/rules/sort-classes-utils.ts index 9fe69170..1623efb6 100644 --- a/rules/sort-classes-utils.ts +++ b/rules/sort-classes-utils.ts @@ -1,7 +1,5 @@ import type { TSESTree } from '@typescript-eslint/utils' -import { minimatch } from 'minimatch' - import type { SortClassesOptions, SingleCustomGroup, @@ -11,8 +9,11 @@ import type { } from './sort-classes.types' import type { CompareOptions } from '../utils/compare' +import { matches } from '../utils/matches' + interface CustomGroupMatchesProps { customGroup: SingleCustomGroup | CustomGroupBlock + matcher: 'minimatch' | 'regex' selectors: Selector[] modifiers: Modifier[] decorators: string[] @@ -184,12 +185,10 @@ export const customGroupMatches = (props: CustomGroupMatchesProps): boolean => { 'elementNamePattern' in props.customGroup && props.customGroup.elementNamePattern ) { - let matchesElementNamePattern: boolean = minimatch( + let matchesElementNamePattern: boolean = matches( props.elementName, props.customGroup.elementNamePattern, - { - nocomment: true, - }, + props.matcher, ) if (!matchesElementNamePattern) { return false @@ -202,10 +201,7 @@ export const customGroupMatches = (props: CustomGroupMatchesProps): boolean => { ) { let decoratorPattern = props.customGroup.decoratorNamePattern let matchesDecoratorNamePattern: boolean = props.decorators.some( - decorator => - minimatch(decorator, decoratorPattern, { - nocomment: true, - }), + decorator => matches(decorator, decoratorPattern, props.matcher), ) if (!matchesDecoratorNamePattern) { return false diff --git a/rules/sort-classes.ts b/rules/sort-classes.ts index 3be6d45b..9da4a0c6 100644 --- a/rules/sort-classes.ts +++ b/rules/sort-classes.ts @@ -65,6 +65,11 @@ export default createEslintRule({ type: 'string', enum: ['asc', 'desc'], }, + matcher: { + description: 'Specifies the string matcher.', + type: 'string', + enum: ['minimatch', 'regex'], + }, ignoreCase: { description: 'Controls whether sorting should be case-sensitive or not.', @@ -181,6 +186,7 @@ export default createEslintRule({ type: 'alphabetical', order: 'asc', ignoreCase: true, + matcher: 'minimatch', partitionByComment: false, groups: [ 'index-signature', @@ -221,6 +227,7 @@ export default createEslintRule({ ['get-method', 'set-method'], 'unknown', ], + matcher: 'minimatch', partitionByComment: false, type: 'alphabetical', ignoreCase: true, @@ -377,16 +384,18 @@ export default createEslintRule({ if ( options.partitionByComment && - hasPartitionComment(options.partitionByComment, comments) + hasPartitionComment( + options.partitionByComment, + comments, + options.matcher, + ) ) { accumulator.push([]) } let name: string let dependencies: string[] = [] - let { getGroup, defineGroup, setCustomGroups } = useGroups( - options.groups, - ) + let { getGroup, defineGroup, setCustomGroups } = useGroups(options) if (member.type === 'StaticBlock') { name = 'static' @@ -589,6 +598,7 @@ export default createEslintRule({ modifiers, selectors, decorators, + matcher: options.matcher, }) ) { defineGroup(customGroup.groupName, true) @@ -709,9 +719,7 @@ export default createEslintRule({ }, node: right.node, fix: (fixer: TSESLint.RuleFixer) => - makeFixes(fixer, nodes, sortedNodes, sourceCode, { - partitionComment: options.partitionByComment, - }), + makeFixes(fixer, nodes, sortedNodes, sourceCode, options), }) } }) diff --git a/rules/sort-classes.types.ts b/rules/sort-classes.types.ts index 04336de9..0f3dea0d 100644 --- a/rules/sort-classes.types.ts +++ b/rules/sort-classes.types.ts @@ -188,6 +188,7 @@ export type SortClassesOptions = [ customGroups: { [key: string]: string[] | string } | CustomGroup[] type: 'alphabetical' | 'line-length' | 'natural' partitionByComment: string[] | boolean | string + matcher: 'minimatch' | 'regex' groups: (Group[] | Group)[] order: 'desc' | 'asc' ignoreCase: boolean diff --git a/rules/sort-enums.ts b/rules/sort-enums.ts index 4519ad6e..3d5a1f43 100644 --- a/rules/sort-enums.ts +++ b/rules/sort-enums.ts @@ -26,6 +26,7 @@ export type Options = [ Partial<{ type: 'alphabetical' | 'line-length' | 'natural' partitionByComment: string[] | boolean | string + matcher: 'minimatch' | 'regex' partitionByNewLine: boolean forceNumericSort: boolean order: 'desc' | 'asc' @@ -57,6 +58,11 @@ export default createEslintRule({ type: 'string', enum: ['asc', 'desc'], }, + matcher: { + description: 'Specifies the string matcher.', + type: 'string', + enum: ['minimatch', 'regex'], + }, ignoreCase: { description: 'Controls whether sorting should be case-sensitive or not.', @@ -109,6 +115,7 @@ export default createEslintRule({ type: 'alphabetical', order: 'asc', ignoreCase: true, + matcher: 'minimatch', sortByValue: false, partitionByComment: false, partitionByNewLine: false, @@ -132,6 +139,7 @@ export default createEslintRule({ partitionByComment: false, partitionByNewLine: false, type: 'alphabetical', + matcher: 'minimatch', ignoreCase: true, order: 'asc', sortByValue: false, @@ -213,6 +221,7 @@ export default createEslintRule({ hasPartitionComment( partitionComment, getCommentsBefore(member, sourceCode), + options.matcher, )) || (options.partitionByNewLine && lastSortingNode && @@ -277,9 +286,7 @@ export default createEslintRule({ }, node: right.node, fix: fixer => - makeFixes(fixer, nodes, sortedNodes, sourceCode, { - partitionComment, - }), + makeFixes(fixer, nodes, sortedNodes, sourceCode, options), }) } }) diff --git a/rules/sort-exports.ts b/rules/sort-exports.ts index 15dbc12e..28cd316d 100644 --- a/rules/sort-exports.ts +++ b/rules/sort-exports.ts @@ -21,6 +21,7 @@ type Options = [ groupKind: 'values-first' | 'types-first' | 'mixed' type: 'alphabetical' | 'line-length' | 'natural' partitionByComment: string[] | boolean | string + matcher: 'minimatch' | 'regex' partitionByNewLine: boolean order: 'desc' | 'asc' ignoreCase: boolean @@ -54,6 +55,11 @@ export default createEslintRule({ type: 'string', enum: ['asc', 'desc'], }, + matcher: { + description: 'Specifies the string matcher.', + type: 'string', + enum: ['minimatch', 'regex'], + }, ignoreCase: { description: 'Controls whether sorting should be case-sensitive or not.', @@ -100,6 +106,7 @@ export default createEslintRule({ type: 'alphabetical', order: 'asc', ignoreCase: true, + matcher: 'minimatch', partitionByComment: false, partitionByNewLine: false, groupKind: 'mixed', @@ -112,6 +119,7 @@ export default createEslintRule({ type: 'alphabetical', ignoreCase: true, order: 'asc', + matcher: 'minimatch', partitionByComment: false, partitionByNewLine: false, groupKind: 'mixed', @@ -138,6 +146,7 @@ export default createEslintRule({ hasPartitionComment( partitionComment, getCommentsBefore(node, sourceCode), + options.matcher, )) || (options.partitionByNewLine && lastNode && @@ -194,9 +203,7 @@ export default createEslintRule({ }, node: right.node, fix: fixer => - makeFixes(fixer, nodes, sortedNodes, sourceCode, { - partitionComment, - }), + makeFixes(fixer, nodes, sortedNodes, sourceCode, options), }) } }) diff --git a/rules/sort-imports.ts b/rules/sort-imports.ts index 04718eb5..446cc83a 100644 --- a/rules/sort-imports.ts +++ b/rules/sort-imports.ts @@ -2,7 +2,6 @@ import type { TSESTree } from '@typescript-eslint/types' import type { TSESLint } from '@typescript-eslint/utils' import { builtinModules } from 'node:module' -import { minimatch } from 'minimatch' import type { SortingNode } from '../typings' @@ -21,6 +20,7 @@ import { sortNodes } from '../utils/sort-nodes' import { complete } from '../utils/complete' import { pairwise } from '../utils/pairwise' import { compare } from '../utils/compare' +import { matches } from '../utils/matches' type MESSAGE_ID = | 'missedSpacingBetweenImports' @@ -58,6 +58,7 @@ type Options = [ type: 'alphabetical' | 'line-length' | 'natural' newlinesBetween: 'ignore' | 'always' | 'never' groups: (Group[] | Group)[] + matcher: 'minimatch' | 'regex' environment: 'node' | 'bun' internalPattern: string[] sortSideEffects: boolean @@ -91,6 +92,11 @@ export default createEslintRule, MESSAGE_ID>({ type: 'string', enum: ['asc', 'desc'], }, + matcher: { + description: 'Specifies the string matcher.', + type: 'string', + enum: ['minimatch', 'regex'], + }, ignoreCase: { description: 'Controls whether sorting should be case-sensitive or not.', @@ -209,6 +215,7 @@ export default createEslintRule, MESSAGE_ID>({ sortSideEffects: false, newlinesBetween: 'always', maxLineLength: undefined, + matcher: 'minimatch', groups: [ 'type', ['builtin', 'external'], @@ -226,7 +233,8 @@ export default createEslintRule, MESSAGE_ID>({ create: context => { let settings = getSettings(context.settings) - let options = complete(context.options.at(0), settings, { + let defaultOptions = context.options.at(0) + let options = complete(defaultOptions, settings, { groups: [ 'type', ['builtin', 'external'], @@ -237,8 +245,10 @@ export default createEslintRule, MESSAGE_ID>({ 'object', 'unknown', ], + matcher: 'minimatch', customGroups: { type: {}, value: {} }, - internalPattern: ['~/**'], + internalPattern: + defaultOptions?.matcher === 'regex' ? ['^~/.*'] : ['~/**'], newlinesBetween: 'always', sortSideEffects: false, type: 'alphabetical', @@ -328,14 +338,12 @@ export default createEslintRule, MESSAGE_ID>({ let isSibling = (value: string) => value.startsWith('./') - let { getGroup, defineGroup, setCustomGroups } = useGroups(options.groups) + let { getGroup, defineGroup, setCustomGroups } = useGroups(options) let isInternal = (value: string) => options.internalPattern.length && options.internalPattern.some(pattern => - minimatch(value, pattern, { - nocomment: true, - }), + matches(value, pattern, options.matcher), ) let isCoreModule = (value: string) => { @@ -557,8 +565,10 @@ export default createEslintRule, MESSAGE_ID>({ fixes.push( fixer.replaceTextRange( - getNodeRange(nodesToFix.at(i)!.node, sourceCode), - sourceCode.text.slice(...getNodeRange(node.node, sourceCode)), + getNodeRange(nodesToFix.at(i)!.node, sourceCode, options), + sourceCode.text.slice( + ...getNodeRange(node.node, sourceCode, options), + ), ), ) @@ -582,10 +592,16 @@ export default createEslintRule, MESSAGE_ID>({ ) { fixes.push( fixer.removeRange([ - getNodeRange(nodesToFix.at(i)!.node, sourceCode).at(1)!, - getNodeRange(nodesToFix.at(i + 1)!.node, sourceCode).at( - 0, - )! - 1, + getNodeRange( + nodesToFix.at(i)!.node, + sourceCode, + options, + ).at(1)!, + getNodeRange( + nodesToFix.at(i + 1)!.node, + sourceCode, + options, + ).at(0)! - 1, ]), ) } @@ -599,10 +615,16 @@ export default createEslintRule, MESSAGE_ID>({ fixes.push( fixer.replaceTextRange( [ - getNodeRange(nodesToFix.at(i)!.node, sourceCode).at(1)!, - getNodeRange(nodesToFix.at(i + 1)!.node, sourceCode).at( - 0, - )! - 1, + getNodeRange( + nodesToFix.at(i)!.node, + sourceCode, + options, + ).at(1)!, + getNodeRange( + nodesToFix.at(i + 1)!.node, + sourceCode, + options, + ).at(0)! - 1, ], '\n', ), @@ -617,7 +639,7 @@ export default createEslintRule, MESSAGE_ID>({ ) { fixes.push( fixer.insertTextAfterRange( - getNodeRange(nodesToFix.at(i)!.node, sourceCode), + getNodeRange(nodesToFix.at(i)!.node, sourceCode, options), '\n', ), ) diff --git a/rules/sort-interfaces.ts b/rules/sort-interfaces.ts index 02ea0dad..66837e2f 100644 --- a/rules/sort-interfaces.ts +++ b/rules/sort-interfaces.ts @@ -1,5 +1,3 @@ -import { minimatch } from 'minimatch' - import type { SortingNode } from '../typings' import { validateGroupsConfiguration } from '../utils/validate-groups-configuration' @@ -18,6 +16,7 @@ import { useGroups } from '../utils/use-groups' import { makeFixes } from '../utils/make-fixes' import { complete } from '../utils/complete' import { pairwise } from '../utils/pairwise' +import { matches } from '../utils/matches' type MESSAGE_ID = | 'unexpectedInterfacePropertiesGroupOrder' @@ -32,6 +31,7 @@ type Options = [ type: 'alphabetical' | 'line-length' | 'natural' partitionByComment: string[] | boolean | string groups: (Group[] | Group)[] + matcher: 'minimatch' | 'regex' partitionByNewLine: boolean ignorePattern: string[] order: 'desc' | 'asc' @@ -62,6 +62,11 @@ export default createEslintRule, MESSAGE_ID>({ type: 'string', enum: ['asc', 'desc'], }, + matcher: { + description: 'Specifies the string matcher.', + type: 'string', + enum: ['minimatch', 'regex'], + }, ignoreCase: { description: 'Controls whether sorting should be case-sensitive or not.', @@ -153,6 +158,7 @@ export default createEslintRule, MESSAGE_ID>({ type: 'alphabetical', order: 'asc', ignoreCase: true, + matcher: 'minimatch', ignorePattern: [], partitionByComment: false, partitionByNewLine: false, @@ -170,6 +176,7 @@ export default createEslintRule, MESSAGE_ID>({ partitionByNewLine: false, type: 'alphabetical', groupKind: 'mixed', + matcher: 'minimatch', ignorePattern: [], ignoreCase: true, customGroups: {}, @@ -188,9 +195,7 @@ export default createEslintRule, MESSAGE_ID>({ if ( !options.ignorePattern.some(pattern => - minimatch(node.id.name, pattern, { - nocomment: true, - }), + matches(node.id.name, pattern, options.matcher), ) ) { let formattedMembers: SortingNode[][] = node.body.body.reduce( @@ -203,9 +208,8 @@ export default createEslintRule, MESSAGE_ID>({ let lastElement = accumulator.at(-1)?.at(-1) let name: string - let { getGroup, defineGroup, setCustomGroups } = useGroups( - options.groups, - ) + let { getGroup, defineGroup, setCustomGroups } = + useGroups(options) if (element.type === 'TSPropertySignature') { if (element.key.type === 'Identifier') { @@ -249,6 +253,7 @@ export default createEslintRule, MESSAGE_ID>({ hasPartitionComment( partitionComment, getCommentsBefore(element, sourceCode), + options.matcher, )) || (options.partitionByNewLine && lastElement && @@ -310,9 +315,7 @@ export default createEslintRule, MESSAGE_ID>({ }, node: right.node, fix: fixer => - makeFixes(fixer, nodes, sortedNodes, sourceCode, { - partitionComment, - }), + makeFixes(fixer, nodes, sortedNodes, sourceCode, options), }) } }) diff --git a/rules/sort-intersection-types.ts b/rules/sort-intersection-types.ts index 086832ff..cef6e811 100644 --- a/rules/sort-intersection-types.ts +++ b/rules/sort-intersection-types.ts @@ -39,6 +39,7 @@ type Options = [ Partial<{ type: 'alphabetical' | 'line-length' | 'natural' partitionByComment: string[] | boolean | string + matcher: 'minimatch' | 'regex' groups: (Group[] | Group)[] partitionByNewLine: boolean order: 'desc' | 'asc' @@ -69,6 +70,11 @@ export default createEslintRule({ type: 'string', enum: ['asc', 'desc'], }, + matcher: { + description: 'Specifies the string matcher.', + type: 'string', + enum: ['minimatch', 'regex'], + }, ignoreCase: { description: 'Controls whether sorting should be case-sensitive or not.', @@ -130,6 +136,7 @@ export default createEslintRule({ type: 'alphabetical', order: 'asc', ignoreCase: true, + matcher: 'minimatch', partitionByNewLine: false, partitionByComment: false, groups: [], @@ -143,6 +150,7 @@ export default createEslintRule({ type: 'alphabetical', ignoreCase: true, order: 'asc', + matcher: 'minimatch', partitionByComment: false, partitionByNewLine: false, groups: [], @@ -173,7 +181,7 @@ export default createEslintRule({ let formattedMembers: SortingNode[][] = node.types.reduce( (accumulator: SortingNode[][], type) => { - let { getGroup, defineGroup } = useGroups(options.groups) + let { getGroup, defineGroup } = useGroups(options) switch (type.type) { case 'TSConditionalType': @@ -246,6 +254,7 @@ export default createEslintRule({ hasPartitionComment( partitionComment, getCommentsBefore(type, sourceCode), + options.matcher, )) || (options.partitionByNewLine && lastSortingNode && @@ -282,9 +291,7 @@ export default createEslintRule({ }, node: right.node, fix: fixer => - makeFixes(fixer, nodes, sortedNodes, sourceCode, { - partitionComment, - }), + makeFixes(fixer, nodes, sortedNodes, sourceCode, options), }) } }) diff --git a/rules/sort-jsx-props.ts b/rules/sort-jsx-props.ts index 542037ab..a7cc68d9 100644 --- a/rules/sort-jsx-props.ts +++ b/rules/sort-jsx-props.ts @@ -1,7 +1,5 @@ import type { TSESTree } from '@typescript-eslint/types' -import { minimatch } from 'minimatch' - import type { SortingNode } from '../typings' import { validateGroupsConfiguration } from '../utils/validate-groups-configuration' @@ -15,6 +13,7 @@ import { useGroups } from '../utils/use-groups' import { makeFixes } from '../utils/make-fixes' import { pairwise } from '../utils/pairwise' import { complete } from '../utils/complete' +import { matches } from '../utils/matches' type MESSAGE_ID = 'unexpectedJSXPropsGroupOrder' | 'unexpectedJSXPropsOrder' @@ -29,6 +28,7 @@ type Options = [ customGroups: { [key in T[number]]: string[] | string } type: 'alphabetical' | 'line-length' | 'natural' groups: (Group[] | Group)[] + matcher: 'minimatch' | 'regex' ignorePattern: string[] order: 'desc' | 'asc' ignoreCase: boolean @@ -58,6 +58,11 @@ export default createEslintRule, MESSAGE_ID>({ type: 'string', enum: ['asc', 'desc'], }, + matcher: { + description: 'Specifies the string matcher.', + type: 'string', + enum: ['minimatch', 'regex'], + }, ignoreCase: { description: 'Controls whether sorting should be case-sensitive or not.', @@ -121,6 +126,7 @@ export default createEslintRule, MESSAGE_ID>({ type: 'alphabetical', order: 'asc', ignoreCase: true, + matcher: 'minimatch', ignorePattern: [], groups: [], customGroups: {}, @@ -135,6 +141,7 @@ export default createEslintRule, MESSAGE_ID>({ type: 'alphabetical', ignorePattern: [], ignoreCase: true, + matcher: 'minimatch', customGroups: {}, order: 'asc', groups: [], @@ -152,7 +159,7 @@ export default createEslintRule, MESSAGE_ID>({ if (options.ignorePattern.length) { let tagName = sourceCode.text.slice(...node.openingElement.name.range) shouldIgnore = options.ignorePattern.some(pattern => - minimatch(tagName, pattern), + matches(tagName, pattern, options.matcher), ) } @@ -172,9 +179,8 @@ export default createEslintRule, MESSAGE_ID>({ ? `${attribute.name.namespace.name}:${attribute.name.name.name}` : attribute.name.name - let { getGroup, defineGroup, setCustomGroups } = useGroups( - options.groups, - ) + let { getGroup, defineGroup, setCustomGroups } = + useGroups(options) setCustomGroups(options.customGroups, name) diff --git a/rules/sort-maps.ts b/rules/sort-maps.ts index 25a9feb0..c5d08690 100644 --- a/rules/sort-maps.ts +++ b/rules/sort-maps.ts @@ -23,6 +23,7 @@ type Options = [ Partial<{ type: 'alphabetical' | 'line-length' | 'natural' partitionByComment: string[] | boolean | string + matcher: 'minimatch' | 'regex' partitionByNewLine: boolean order: 'desc' | 'asc' ignoreCase: boolean @@ -52,6 +53,11 @@ export default createEslintRule({ type: 'string', enum: ['asc', 'desc'], }, + matcher: { + description: 'Specifies the string matcher.', + type: 'string', + enum: ['minimatch', 'regex'], + }, ignoreCase: { description: 'Controls whether sorting should be case-sensitive or not.', @@ -94,6 +100,7 @@ export default createEslintRule({ type: 'alphabetical', order: 'asc', ignoreCase: true, + matcher: 'minimatch', partitionByComment: false, partitionByNewLine: false, }, @@ -115,6 +122,7 @@ export default createEslintRule({ type: 'alphabetical', ignoreCase: true, order: 'asc', + matcher: 'minimatch', partitionByComment: false, partitionByNewLine: false, } as const) @@ -168,6 +176,7 @@ export default createEslintRule({ hasPartitionComment( partitionComment, getCommentsBefore(element, sourceCode), + options.matcher, )) || (options.partitionByNewLine && lastSortingNode && @@ -195,9 +204,7 @@ export default createEslintRule({ nodes, sortNodes(nodes, options), sourceCode, - { - partitionComment, - }, + options, ), }) } diff --git a/rules/sort-named-exports.ts b/rules/sort-named-exports.ts index a12667c5..62f33634 100644 --- a/rules/sort-named-exports.ts +++ b/rules/sort-named-exports.ts @@ -22,6 +22,7 @@ type Options = [ groupKind: 'values-first' | 'types-first' | 'mixed' type: 'alphabetical' | 'line-length' | 'natural' partitionByComment: string[] | boolean | string + matcher: 'minimatch' | 'regex' partitionByNewLine: boolean order: 'desc' | 'asc' ignoreCase: boolean @@ -51,6 +52,11 @@ export default createEslintRule({ type: 'string', enum: ['asc', 'desc'], }, + matcher: { + description: 'Specifies the string matcher.', + type: 'string', + enum: ['minimatch', 'regex'], + }, ignoreCase: { description: 'Controls whether sorting should be case-sensitive or not.', @@ -98,6 +104,7 @@ export default createEslintRule({ type: 'alphabetical', order: 'asc', ignoreCase: true, + matcher: 'minimatch', partitionByNewLine: false, partitionByComment: false, groupKind: 'mixed', @@ -112,6 +119,7 @@ export default createEslintRule({ type: 'alphabetical', groupKind: 'mixed', ignoreCase: true, + matcher: 'minimatch', partitionByNewLine: false, partitionByComment: false, order: 'asc', @@ -141,6 +149,7 @@ export default createEslintRule({ hasPartitionComment( partitionComment, getCommentsBefore(specifier, sourceCode), + options.matcher, )) || (options.partitionByNewLine && lastSortingNode && @@ -183,9 +192,7 @@ export default createEslintRule({ }, node: right.node, fix: fixer => - makeFixes(fixer, nodes, sortedNodes, sourceCode, { - partitionComment, - }), + makeFixes(fixer, nodes, sortedNodes, sourceCode, options), }) } }) diff --git a/rules/sort-named-imports.ts b/rules/sort-named-imports.ts index 9d1e13bc..721f0bb9 100644 --- a/rules/sort-named-imports.ts +++ b/rules/sort-named-imports.ts @@ -22,6 +22,7 @@ type Options = [ groupKind: 'values-first' | 'types-first' | 'mixed' type: 'alphabetical' | 'line-length' | 'natural' partitionByComment: string[] | boolean | string + matcher: 'minimatch' | 'regex' partitionByNewLine: boolean order: 'desc' | 'asc' ignoreAlias: boolean @@ -52,6 +53,11 @@ export default createEslintRule({ type: 'string', enum: ['asc', 'desc'], }, + matcher: { + description: 'Specifies the string matcher.', + type: 'string', + enum: ['minimatch', 'regex'], + }, ignoreCase: { description: 'Controls whether sorting should be case-sensitive or not.', @@ -123,6 +129,7 @@ export default createEslintRule({ ignoreAlias: false, groupKind: 'mixed', ignoreCase: true, + matcher: 'minimatch', partitionByNewLine: false, partitionByComment: false, order: 'asc', @@ -162,6 +169,7 @@ export default createEslintRule({ hasPartitionComment( partitionComment, getCommentsBefore(specifier, sourceCode), + options.matcher, )) || (options.partitionByNewLine && lastSortingNode && @@ -203,9 +211,7 @@ export default createEslintRule({ }, node: right.node, fix: fixer => - makeFixes(fixer, nodes, sortedNodes, sourceCode, { - partitionComment, - }), + makeFixes(fixer, nodes, sortedNodes, sourceCode, options), }) } }) diff --git a/rules/sort-object-types.ts b/rules/sort-object-types.ts index fd363029..f8cd3e3a 100644 --- a/rules/sort-object-types.ts +++ b/rules/sort-object-types.ts @@ -31,6 +31,7 @@ type Options = [ type: 'alphabetical' | 'line-length' | 'natural' partitionByComment: string[] | boolean | string groups: (Group[] | Group)[] + matcher: 'minimatch' | 'regex' partitionByNewLine: boolean order: 'desc' | 'asc' ignoreCase: boolean @@ -62,6 +63,11 @@ export default createEslintRule, MESSAGE_ID>({ type: 'string', enum: ['asc', 'desc'], }, + matcher: { + description: 'Specifies the string matcher.', + type: 'string', + enum: ['minimatch', 'regex'], + }, ignoreCase: { description: 'Controls whether sorting should be case-sensitive or not.', @@ -145,6 +151,7 @@ export default createEslintRule, MESSAGE_ID>({ type: 'alphabetical', order: 'asc', ignoreCase: true, + matcher: 'minimatch', partitionByComment: false, partitionByNewLine: false, groupKind: 'mixed', @@ -162,6 +169,7 @@ export default createEslintRule, MESSAGE_ID>({ partitionByNewLine: false, type: 'alphabetical', groupKind: 'mixed', + matcher: 'minimatch', ignoreCase: true, customGroups: {}, order: 'asc', @@ -187,9 +195,8 @@ export default createEslintRule, MESSAGE_ID>({ ) let lastSortingNode = accumulator.at(-1)?.at(-1) - let { getGroup, defineGroup, setCustomGroups } = useGroups( - options.groups, - ) + let { getGroup, defineGroup, setCustomGroups } = + useGroups(options) let formatName = (value: string): string => value.replace(/([,;])$/, '') @@ -239,6 +246,7 @@ export default createEslintRule, MESSAGE_ID>({ hasPartitionComment( partitionComment, getCommentsBefore(member, sourceCode), + options.matcher, )) || (options.partitionByNewLine && lastSortingNode && @@ -305,9 +313,7 @@ export default createEslintRule, MESSAGE_ID>({ }, node: right.node, fix: fixer => - makeFixes(fixer, nodes, sortedNodes, sourceCode, { - partitionComment, - }), + makeFixes(fixer, nodes, sortedNodes, sourceCode, options), }) } }) diff --git a/rules/sort-objects.ts b/rules/sort-objects.ts index 46d10c0b..eebdc252 100644 --- a/rules/sort-objects.ts +++ b/rules/sort-objects.ts @@ -1,8 +1,6 @@ import type { TSESTree } from '@typescript-eslint/types' import type { TSESLint } from '@typescript-eslint/utils' -import { minimatch } from 'minimatch' - import type { SortingNodeWithDependencies } from '../utils/sort-nodes-by-dependencies' import { @@ -25,6 +23,7 @@ import { useGroups } from '../utils/use-groups' import { makeFixes } from '../utils/make-fixes' import { complete } from '../utils/complete' import { pairwise } from '../utils/pairwise' +import { matches } from '../utils/matches' type MESSAGE_ID = | 'unexpectedObjectsDependencyOrder' @@ -46,6 +45,7 @@ type Options = [ customGroups: { [key: string]: string[] | string } type: 'alphabetical' | 'line-length' | 'natural' partitionByComment: string[] | boolean | string + matcher: 'minimatch' | 'regex' groups: (Group[] | Group)[] partitionByNewLine: boolean styledComponents: boolean @@ -79,6 +79,11 @@ export default createEslintRule({ type: 'string', enum: ['asc', 'desc'], }, + matcher: { + description: 'Specifies the string matcher.', + type: 'string', + enum: ['minimatch', 'regex'], + }, ignoreCase: { description: 'Controls whether sorting should be case-sensitive or not.', @@ -174,6 +179,7 @@ export default createEslintRule({ type: 'alphabetical', order: 'asc', ignoreCase: true, + matcher: 'minimatch', partitionByComment: false, partitionByNewLine: false, styledComponents: true, @@ -196,6 +202,7 @@ export default createEslintRule({ destructureOnly: false, type: 'alphabetical', ignorePattern: [], + matcher: 'minimatch', ignoreCase: true, customGroups: {}, order: 'asc', @@ -226,9 +233,7 @@ export default createEslintRule({ let checkMatch = (identifier: string) => options.ignorePattern.some(pattern => - minimatch(identifier, pattern, { - nocomment: true, - }), + matches(identifier, pattern, options.matcher), ) if (typeof varIdentifier === 'string' && checkMatch(varIdentifier)) { @@ -382,7 +387,11 @@ export default createEslintRule({ if ( options.partitionByComment && - hasPartitionComment(options.partitionByComment, comments) + hasPartitionComment( + options.partitionByComment, + comments, + options.matcher, + ) ) { accumulator.push([]) } @@ -391,7 +400,7 @@ export default createEslintRule({ let position: Position = Position.ignore let dependencies: string[] = [] - let { getGroup, setCustomGroups } = useGroups(options.groups) + let { getGroup, setCustomGroups } = useGroups(options) if (prop.key.type === 'Identifier') { ;({ name } = prop.key) @@ -471,9 +480,7 @@ export default createEslintRule({ }, node: right.node, fix: (fixer: TSESLint.RuleFixer) => - makeFixes(fixer, nodes, sortedNodes, sourceCode, { - partitionComment: options.partitionByComment, - }), + makeFixes(fixer, nodes, sortedNodes, sourceCode, options), }) } }) diff --git a/rules/sort-sets.ts b/rules/sort-sets.ts index d1f52d37..7390a2d7 100644 --- a/rules/sort-sets.ts +++ b/rules/sort-sets.ts @@ -23,6 +23,7 @@ export default createEslintRule({ type: 'alphabetical', order: 'asc', ignoreCase: true, + matcher: 'minimatch', groupKind: 'literals-first', }, ], diff --git a/rules/sort-svelte-attributes.ts b/rules/sort-svelte-attributes.ts index 6017d4fe..85abb2bb 100644 --- a/rules/sort-svelte-attributes.ts +++ b/rules/sort-svelte-attributes.ts @@ -33,6 +33,7 @@ type Options = [ customGroups: { [key in T[number]]: string[] | string } type: 'alphabetical' | 'line-length' | 'natural' groups: (Group[] | Group)[] + matcher: 'minimatch' | 'regex' order: 'desc' | 'asc' ignoreCase: boolean }>, @@ -61,6 +62,11 @@ export default createEslintRule, MESSAGE_ID>({ type: 'string', enum: ['asc', 'desc'], }, + matcher: { + description: 'Specifies the string matcher.', + type: 'string', + enum: ['minimatch', 'regex'], + }, ignoreCase: { description: 'Controls whether sorting should be case-sensitive or not.', @@ -116,6 +122,7 @@ export default createEslintRule, MESSAGE_ID>({ type: 'alphabetical', order: 'asc', ignoreCase: true, + matcher: 'minimatch', groups: [], customGroups: {}, }, @@ -134,6 +141,7 @@ export default createEslintRule, MESSAGE_ID>({ type: 'alphabetical', ignoreCase: true, customGroups: {}, + matcher: 'minimatch', order: 'asc', groups: [], } as const) @@ -155,9 +163,8 @@ export default createEslintRule, MESSAGE_ID>({ let name: string - let { getGroup, defineGroup, setCustomGroups } = useGroups( - options.groups, - ) + let { getGroup, defineGroup, setCustomGroups } = + useGroups(options) if (attribute.key.type === 'SvelteSpecialDirectiveKey') { name = sourceCode.text.slice(...attribute.key.range) diff --git a/rules/sort-union-types.ts b/rules/sort-union-types.ts index e35be9cf..ea8eaf9d 100644 --- a/rules/sort-union-types.ts +++ b/rules/sort-union-types.ts @@ -37,6 +37,7 @@ type Options = [ Partial<{ type: 'alphabetical' | 'line-length' | 'natural' partitionByComment: string[] | boolean | string + matcher: 'minimatch' | 'regex' groups: (Group[] | Group)[] partitionByNewLine: boolean order: 'desc' | 'asc' @@ -67,6 +68,11 @@ export default createEslintRule({ type: 'string', enum: ['asc', 'desc'], }, + matcher: { + description: 'Specifies the string matcher.', + type: 'string', + enum: ['minimatch', 'regex'], + }, ignoreCase: { description: 'Controls whether sorting should be case-sensitive or not.', @@ -128,6 +134,7 @@ export default createEslintRule({ type: 'alphabetical', order: 'asc', ignoreCase: true, + matcher: 'minimatch', partitionByNewLine: false, partitionByComment: false, groups: [], @@ -142,6 +149,7 @@ export default createEslintRule({ ignoreCase: true, order: 'asc', groups: [], + matcher: 'minimatch', partitionByNewLine: false, partitionByComment: false, } as const) @@ -171,7 +179,7 @@ export default createEslintRule({ let formattedMembers: SortingNode[][] = node.types.reduce( (accumulator: SortingNode[][], type) => { - let { getGroup, defineGroup } = useGroups(options.groups) + let { getGroup, defineGroup } = useGroups(options) switch (type.type) { case 'TSConditionalType': @@ -244,6 +252,7 @@ export default createEslintRule({ hasPartitionComment( partitionComment, getCommentsBefore(type, sourceCode), + options.matcher, )) || (options.partitionByNewLine && lastSortingNode && @@ -279,9 +288,7 @@ export default createEslintRule({ }, node: right.node, fix: fixer => - makeFixes(fixer, nodes, sortedNodes, sourceCode, { - partitionComment, - }), + makeFixes(fixer, nodes, sortedNodes, sourceCode, options), }) } }) diff --git a/rules/sort-variable-declarations.ts b/rules/sort-variable-declarations.ts index 1887585a..fdb303a2 100644 --- a/rules/sort-variable-declarations.ts +++ b/rules/sort-variable-declarations.ts @@ -27,6 +27,7 @@ type Options = [ Partial<{ type: 'alphabetical' | 'line-length' | 'natural' partitionByComment: string[] | boolean | string + matcher: 'minimatch' | 'regex' partitionByNewLine: boolean order: 'desc' | 'asc' ignoreCase: boolean @@ -56,6 +57,11 @@ export default createEslintRule({ type: 'string', enum: ['asc', 'desc'], }, + matcher: { + description: 'Specifies the string matcher.', + type: 'string', + enum: ['minimatch', 'regex'], + }, ignoreCase: { description: 'Controls whether sorting should be case-sensitive or not.', @@ -100,6 +106,7 @@ export default createEslintRule({ type: 'alphabetical', order: 'asc', ignoreCase: true, + matcher: 'minimatch', partitionByComment: false, partitionByNewLine: false, }, @@ -113,6 +120,7 @@ export default createEslintRule({ type: 'alphabetical', ignoreCase: true, partitionByNewLine: false, + matcher: 'minimatch', partitionByComment: false, order: 'asc', } as const) @@ -233,6 +241,7 @@ export default createEslintRule({ hasPartitionComment( partitionComment, getCommentsBefore(declaration, sourceCode), + options.matcher, )) || (options.partitionByNewLine && lastSortingNode && @@ -269,9 +278,7 @@ export default createEslintRule({ }, node: right.node, fix: fixer => - makeFixes(fixer, nodes, sortedNodes, sourceCode, { - partitionComment, - }), + makeFixes(fixer, nodes, sortedNodes, sourceCode, options), }) } }) diff --git a/rules/sort-vue-attributes.ts b/rules/sort-vue-attributes.ts index a0fdb88b..6be7f158 100644 --- a/rules/sort-vue-attributes.ts +++ b/rules/sort-vue-attributes.ts @@ -31,6 +31,7 @@ type Options = [ customGroups: { [key in T[number]]: string[] | string } type: 'alphabetical' | 'line-length' | 'natural' groups: (Group[] | Group)[] + matcher: 'minimatch' | 'regex' order: 'desc' | 'asc' ignoreCase: boolean }>, @@ -59,6 +60,11 @@ export default createEslintRule, MESSAGE_ID>({ type: 'string', enum: ['asc', 'desc'], }, + matcher: { + description: 'Specifies the string matcher.', + type: 'string', + enum: ['minimatch', 'regex'], + }, ignoreCase: { description: 'Controls whether sorting should be case-sensitive or not.', @@ -114,6 +120,7 @@ export default createEslintRule, MESSAGE_ID>({ type: 'alphabetical', order: 'asc', ignoreCase: true, + matcher: 'minimatch', groups: [], customGroups: {}, }, @@ -146,6 +153,7 @@ export default createEslintRule, MESSAGE_ID>({ type: 'alphabetical', ignoreCase: true, customGroups: {}, + matcher: 'minimatch', order: 'asc', groups: [], } as const) @@ -168,9 +176,8 @@ export default createEslintRule, MESSAGE_ID>({ let name: string - let { getGroup, defineGroup, setCustomGroups } = useGroups( - options.groups, - ) + let { getGroup, defineGroup, setCustomGroups } = + useGroups(options) if ( typeof attribute.key.name === 'string' && diff --git a/test/sort-array-includes.test.ts b/test/sort-array-includes.test.ts index 40fb92d8..888973f1 100644 --- a/test/sort-array-includes.test.ts +++ b/test/sort-array-includes.test.ts @@ -616,6 +616,30 @@ describe(ruleName, () => { }, ) }) + + ruleTester.run(`${ruleName}(${type}): allows to use regex matcher`, rule, { + valid: [ + { + code: dedent` + [ + 'e', + 'f', + // I am a partition comment because I don't have f o o + 'a', + 'b', + ].includes(value) + `, + options: [ + { + ...options, + matcher: 'regex', + partitionByComment: ['^(?!.*foo).*$'], + }, + ], + }, + ], + invalid: [], + }) }) describe(`${ruleName}: sorting by natural order`, () => { diff --git a/test/sort-astro-attributes.test.ts b/test/sort-astro-attributes.test.ts index 161e4017..eb49052b 100644 --- a/test/sort-astro-attributes.test.ts +++ b/test/sort-astro-attributes.test.ts @@ -465,6 +465,40 @@ describe(ruleName, () => { }, ], }) + + ruleTester.run( + `${ruleName}(${type}): allows to use regex matcher for custom groups`, + rule, + { + valid: [ + { + filename: 'file.astro', + code: dedent` + --- + import Component from '~/file.astro' + --- + + `, + options: [ + { + ...options, + matcher: 'regex', + groups: ['unknown', 'elementsWithoutFoo'], + customGroups: { + elementsWithoutFoo: '^(?!.*Foo).*$', + }, + }, + ], + }, + ], + invalid: [], + }, + ) }) describe(`${ruleName}: sorting by natural order`, () => { diff --git a/test/sort-classes.test.ts b/test/sort-classes.test.ts index cf60f5c0..dc6aa52e 100644 --- a/test/sort-classes.test.ts +++ b/test/sort-classes.test.ts @@ -6646,6 +6646,104 @@ describe(ruleName, () => { }, ], }) + + ruleTester.run( + `${ruleName}: allows to use regex matcher for element names in custom groups with old API`, + rule, + { + valid: [ + { + code: dedent` + class Class { + iHaveFooInMyName: string + meTooIHaveFoo: string + a: string + b: string + } + `, + options: [ + { + type: 'alphabetical', + matcher: 'regex', + groups: ['unknown', 'elementsWithoutFoo'], + customGroups: { + elementsWithoutFoo: '^(?!.*Foo).*$', + }, + }, + ], + }, + ], + invalid: [], + }, + ) + + ruleTester.run( + `${ruleName}: allows to use regex matcher for element names in custom groups with new API`, + rule, + { + valid: [ + { + code: dedent` + class Class { + iHaveFooInMyName: string + meTooIHaveFoo: string + a: string + b: string + } + `, + options: [ + { + type: 'alphabetical', + matcher: 'regex', + groups: ['unknown', 'elementsWithoutFoo'], + customGroups: [ + { + groupName: 'elementsWithoutFoo', + elementNamePattern: '^(?!.*Foo).*$', + }, + ], + }, + ], + }, + ], + invalid: [], + }, + ) + + ruleTester.run( + `${ruleName}: allows to use regex matcher for decorator names in custom groups with new API`, + rule, + { + valid: [ + { + code: dedent` + class Class { + @IHaveFooInMyName + x: string + @MeTooIHaveFoo + y: string + a: string + b: string + } + `, + options: [ + { + type: 'alphabetical', + matcher: 'regex', + groups: ['decoratorsWithFoo', 'unknown'], + customGroups: [ + { + groupName: 'decoratorsWithFoo', + decoratorNamePattern: '^.*Foo.*$', + }, + ], + }, + ], + }, + ], + invalid: [], + }, + ) }) describe(`${ruleName}: misc`, () => { @@ -6980,11 +7078,12 @@ describe(ruleName, () => { ], }) - ruleTester.run(`handles partition comments`, rule, { - valid: [], - invalid: [ - { - code: dedent` + describe('partition comments', () => { + ruleTester.run(`handles partition comments`, rule, { + valid: [], + invalid: [ + { + code: dedent` class Class { // Ignore this comment @@ -7009,7 +7108,7 @@ describe(ruleName, () => { a } `, - output: dedent` + output: dedent` class Class { // Ignore this comment @@ -7034,30 +7133,59 @@ describe(ruleName, () => { d } `, - options: [ - { - type: 'alphabetical', - partitionByComment: 'PartitionComment:*', - }, - ], - errors: [ - { - messageId: 'unexpectedClassesOrder', - data: { - left: 'c', - right: 'b', + options: [ + { + type: 'alphabetical', + partitionByComment: 'PartitionComment:*', }, - }, - { - messageId: 'unexpectedClassesOrder', - data: { - left: 'd', - right: 'a', + ], + errors: [ + { + messageId: 'unexpectedClassesOrder', + data: { + left: 'c', + right: 'b', + }, + }, + { + messageId: 'unexpectedClassesOrder', + data: { + left: 'd', + right: 'a', + }, }, + ], + }, + ], + }) + + ruleTester.run( + `${ruleName}: allows to use regex matcher for partition comments`, + rule, + { + valid: [ + { + code: dedent` + class Class { + e + f + // I am a partition comment because I don't have f o o + a + b + } + `, + options: [ + { + type: 'alphabetical', + matcher: 'regex', + partitionByComment: ['^(?!.*foo).*$'], + }, + ], }, ], + invalid: [], }, - ], + ) }) }) }) diff --git a/test/sort-enums.test.ts b/test/sort-enums.test.ts index be982ed2..7b725641 100644 --- a/test/sort-enums.test.ts +++ b/test/sort-enums.test.ts @@ -399,6 +399,34 @@ describe(ruleName, () => { }, ) + ruleTester.run( + `${ruleName}(${type}): allows to use regex matcher for partition comments`, + rule, + { + valid: [ + { + code: dedent` + enum Enum { + E = 'E', + F = 'F', + // I am a partition comment because I don't have f o o + A = 'A', + B = 'B', + } + `, + options: [ + { + ...options, + matcher: 'regex', + partitionByComment: ['^(?!.*foo).*$'], + }, + ], + }, + ], + invalid: [], + }, + ) + ruleTester.run(`${ruleName}: sort enum values correctly`, rule, { valid: [], invalid: [ diff --git a/test/sort-exports.test.ts b/test/sort-exports.test.ts index aacf25ed..1b3b4a57 100644 --- a/test/sort-exports.test.ts +++ b/test/sort-exports.test.ts @@ -346,6 +346,32 @@ describe(ruleName, () => { ) }) + ruleTester.run( + `${ruleName}(${type}): allows to use regex matcher for partition comments`, + rule, + { + valid: [ + { + code: dedent` + export * from './e' + export * from './f' + // I am a partition comment because I don't have f o o + export * from './a' + export * from './b' + `, + options: [ + { + ...options, + matcher: 'regex', + partitionByComment: ['^(?!.*foo).*$'], + }, + ], + }, + ], + invalid: [], + }, + ) + ruleTester.run(`${ruleName}(${type}): sorts by group kind`, rule, { valid: [], invalid: [ diff --git a/test/sort-imports.test.ts b/test/sort-imports.test.ts index fa460f2b..ed8fe2d9 100644 --- a/test/sort-imports.test.ts +++ b/test/sort-imports.test.ts @@ -5172,5 +5172,114 @@ describe(ruleName, () => { ], invalid: [], }) + + describe(`${ruleName}: allows to use regex matcher`, () => { + let options = { + type: 'alphabetical', + ignoreCase: true, + order: 'asc', + matcher: 'regex', + } as const + + ruleTester.run( + `${ruleName}: uses default internalPattern for regex`, + rule, + { + valid: [ + { + code: dedent` + import type { T } from 't' + + import { a1, a2, a3 } from 'a' + + import { b1, b2 } from '~/b' + import { c1, c2, c3 } from '~/c' + + import { e1, e2, e3 } from '../../e' + `, + options: [ + { + ...options, + groups: ['type', 'external', 'internal', 'parent'], + }, + ], + }, + ], + invalid: [], + }, + ) + + ruleTester.run( + `${ruleName}: allows to use regex matcher for custom groups`, + rule, + { + valid: [ + { + code: dedent` + import type { T } from 't' + + import { i18n } from "../../../../../Basics/Language"; + import { i18n } from "../../../Basics/Language"; + + import { b1, b2 } from '~/b' + import { c1, c2, c3 } from '~/c' + `, + options: [ + { + ...options, + customGroups: { + value: { + primary: '^(?:\\.\\.\\/)+Basics\\/Language$', + }, + }, + groups: ['type', 'primary', 'unknown'], + }, + ], + }, + ], + invalid: [], + }, + ) + + ruleTester.run( + `${ruleName}: allows hash symbol in internal pattern`, + rule, + { + valid: [ + { + code: dedent` + import type { T } from 'a' + + import { a } from 'a' + + import type { S } from '#b' + + import { b1, b2 } from '#b' + import c from '#c' + + import { d } from '../d' + `, + options: [ + { + ...options, + internalPattern: ['^#.*$'], + groups: [ + 'type', + ['builtin', 'external'], + 'internal-type', + 'internal', + ['parent-type', 'sibling-type', 'index-type'], + ['parent', 'sibling', 'index'], + 'object', + 'unknown', + ], + }, + ], + }, + ], + invalid: [], + }, + ) + }) }) }) diff --git a/test/sort-interfaces.test.ts b/test/sort-interfaces.test.ts index 7bd3908d..ec28a032 100644 --- a/test/sort-interfaces.test.ts +++ b/test/sort-interfaces.test.ts @@ -578,6 +578,36 @@ describe(ruleName, () => { }, ) + ruleTester.run( + `${ruleName}(${type}): allows to use regex matcher for custom groups`, + rule, + { + valid: [ + { + code: dedent` + interface Interface { + iHaveFooInMyName: string + meTooIHaveFoo: string + a: string + b: string + } + `, + options: [ + { + ...options, + matcher: 'regex', + groups: ['unknown', 'elementsWithoutFoo'], + customGroups: { + elementsWithoutFoo: '^(?!.*Foo).*$', + }, + }, + ], + }, + ], + invalid: [], + }, + ) + ruleTester.run( `${ruleName}(${type}): allows to use new line as partition`, rule, @@ -918,6 +948,34 @@ describe(ruleName, () => { ], }, ) + + ruleTester.run( + `${ruleName}(${type}): allows to use regex matcher for partition comments`, + rule, + { + valid: [ + { + code: dedent` + interface MyInterface { + e: string, + f: string, + // I am a partition comment because I don't have f o o + a: string, + b: string, + } + `, + options: [ + { + ...options, + matcher: 'regex', + partitionByComment: ['^(?!.*foo).*$'], + }, + ], + }, + ], + invalid: [], + }, + ) }) describe(`${ruleName}: sorting by natural order`, () => { diff --git a/test/sort-intersection-types.test.ts b/test/sort-intersection-types.test.ts index 85d26632..05bc654f 100644 --- a/test/sort-intersection-types.test.ts +++ b/test/sort-intersection-types.test.ts @@ -610,6 +610,33 @@ describe(ruleName, () => { ], }, ) + + ruleTester.run( + `${ruleName}(${type}): allows to use regex matcher for partition comments`, + rule, + { + valid: [ + { + code: dedent` + type T = + E & + F & + // I am a partition comment because I don't have f o o + A & + B + `, + options: [ + { + ...options, + matcher: 'regex', + partitionByComment: ['^(?!.*foo).*$'], + }, + ], + }, + ], + invalid: [], + }, + ) }) }) diff --git a/test/sort-jsx-props.test.ts b/test/sort-jsx-props.test.ts index e5b301eb..7a92059b 100644 --- a/test/sort-jsx-props.test.ts +++ b/test/sort-jsx-props.test.ts @@ -493,6 +493,36 @@ describe(ruleName, () => { }, ], }) + + ruleTester.run( + `${ruleName}(${type}): allows to use regex matcher for custom groups`, + rule, + { + valid: [ + { + code: dedent` + + `, + options: [ + { + ...options, + matcher: 'regex', + groups: ['unknown', 'elementsWithoutFoo'], + customGroups: { + elementsWithoutFoo: '^(?!.*Foo).*$', + }, + }, + ], + }, + ], + invalid: [], + }, + ) }) describe(`${ruleName}: sorting by natural order`, () => { diff --git a/test/sort-maps.test.ts b/test/sort-maps.test.ts index d67a19b3..5908359c 100644 --- a/test/sort-maps.test.ts +++ b/test/sort-maps.test.ts @@ -439,6 +439,34 @@ describe(ruleName, () => { ], }, ) + + ruleTester.run( + `${ruleName}(${type}): allows to use regex matcher`, + rule, + { + valid: [ + { + code: dedent` + new Map([ + ['e', 'e'], + ['f', 'f'], + // I am a partition comment because I don't have f o o + ['a', 'a'], + ['b', 'b'], + ]) + `, + options: [ + { + ...options, + matcher: 'regex', + partitionByComment: ['^(?!.*foo).*$'], + }, + ], + }, + ], + invalid: [], + }, + ) }) }) diff --git a/test/sort-named-exports.test.ts b/test/sort-named-exports.test.ts index 29fd4abb..bc4eb591 100644 --- a/test/sort-named-exports.test.ts +++ b/test/sort-named-exports.test.ts @@ -354,6 +354,34 @@ describe(ruleName, () => { ], }, ) + + ruleTester.run( + `${ruleName}(${type}): allows to use regex matcher for partition comments`, + rule, + { + valid: [ + { + code: dedent` + export { + E, + F, + // I am a partition comment because I don't have f o o + A, + B, + } + `, + options: [ + { + ...options, + matcher: 'regex', + partitionByComment: ['^(?!.*foo).*$'], + }, + ], + }, + ], + invalid: [], + }, + ) }) }) diff --git a/test/sort-object-types.test.ts b/test/sort-object-types.test.ts index 61978542..0f90c36e 100644 --- a/test/sort-object-types.test.ts +++ b/test/sort-object-types.test.ts @@ -365,6 +365,36 @@ describe(ruleName, () => { }, ) + ruleTester.run( + `${ruleName}(${type}): allows to use regex matcher for custom groups`, + rule, + { + valid: [ + { + code: dedent` + type T = { + iHaveFooInMyName: string + meTooIHaveFoo: string + a: string + b: string + } + `, + options: [ + { + ...options, + matcher: 'regex', + groups: ['unknown', 'elementsWithoutFoo'], + customGroups: { + elementsWithoutFoo: '^(?!.*Foo).*$', + }, + }, + ], + }, + ], + invalid: [], + }, + ) + ruleTester.run( `${ruleName}(${type}): allows to use in class methods`, rule, @@ -626,6 +656,34 @@ describe(ruleName, () => { ], }, ) + + ruleTester.run( + `${ruleName}(${type}): allows to use regex matcher for partition comments`, + rule, + { + valid: [ + { + code: dedent` + type Type = { + e: string + f: string + // I am a partition comment because I don't have f o o + a: string + b: string + } + `, + options: [ + { + ...options, + matcher: 'regex', + partitionByComment: ['^(?!.*foo).*$'], + }, + ], + }, + ], + invalid: [], + }, + ) }) ruleTester.run( diff --git a/test/sort-objects.test.ts b/test/sort-objects.test.ts index c2b1d737..0888a69d 100644 --- a/test/sort-objects.test.ts +++ b/test/sort-objects.test.ts @@ -321,6 +321,36 @@ describe(ruleName, () => { ], }) + ruleTester.run( + `${ruleName}(${type}): allows to use regex matcher for custom groups`, + rule, + { + valid: [ + { + code: dedent` + let Obj = { + iHaveFooInMyName: string, + meTooIHaveFoo: string, + a: string, + b: string, + } + `, + options: [ + { + ...options, + matcher: 'regex', + groups: ['unknown', 'elementsWithoutFoo'], + customGroups: { + elementsWithoutFoo: '^(?!.*Foo).*$', + }, + }, + ], + }, + ], + invalid: [], + }, + ) + ruleTester.run( `${ruleName}(${type}): sorts with comments on the same line`, rule, @@ -1435,6 +1465,34 @@ describe(ruleName, () => { }, ) + ruleTester.run( + `${ruleName}(${type}): allows to use regex matcher for partition comments`, + rule, + { + valid: [ + { + code: dedent` + let obj = { + e = 'e', + f = 'f', + // I am a partition comment because I don't have f o o + a = 'a', + b = 'b', + } + `, + options: [ + { + ...options, + matcher: 'regex', + partitionByComment: ['^(?!.*foo).*$'], + }, + ], + }, + ], + invalid: [], + }, + ) + ruleTester.run( `${ruleName}(${type}): allows to use new line as partition`, rule, diff --git a/test/sort-sets.test.ts b/test/sort-sets.test.ts index 5e55ed55..0bf0dd74 100644 --- a/test/sort-sets.test.ts +++ b/test/sort-sets.test.ts @@ -562,6 +562,34 @@ describe(ruleName, () => { ], }, ) + + ruleTester.run( + `${ruleName}(${type}): allows to use regex matcher`, + rule, + { + valid: [ + { + code: dedent` + new Set([ + 'e', + 'f', + // I am a partition comment because I don't have f o o + 'a', + 'b', + ]) + `, + options: [ + { + ...options, + matcher: 'regex', + partitionByComment: ['^(?!.*foo).*$'], + }, + ], + }, + ], + invalid: [], + }, + ) }) }) diff --git a/test/sort-svelte-attributes.test.ts b/test/sort-svelte-attributes.test.ts index 8da84137..f1a3286f 100644 --- a/test/sort-svelte-attributes.test.ts +++ b/test/sort-svelte-attributes.test.ts @@ -471,6 +471,41 @@ describe(ruleName, () => { }, ], }) + + ruleTester.run( + `${ruleName}(${type}): allows to use regex matcher for custom groups`, + rule, + { + valid: [ + { + filename: 'file.svelte', + code: dedent` + + + + `, + options: [ + { + ...options, + matcher: 'regex', + groups: ['unknown', 'elementsWithoutFoo'], + customGroups: { + elementsWithoutFoo: '^(?!.*Foo).*$', + }, + }, + ], + }, + ], + invalid: [], + }, + ) }) describe(`${ruleName}: sorting by natural order`, () => { diff --git a/test/sort-union-types.test.ts b/test/sort-union-types.test.ts index 7bb4541a..df7e55df 100644 --- a/test/sort-union-types.test.ts +++ b/test/sort-union-types.test.ts @@ -613,6 +613,33 @@ describe(ruleName, () => { ], }, ) + + ruleTester.run( + `${ruleName}(${type}): allows to use regex matcher for partition comments`, + rule, + { + valid: [ + { + code: dedent` + type T = + E | + F | + // I am a partition comment because I don't have f o o + A | + B + `, + options: [ + { + ...options, + matcher: 'regex', + partitionByComment: ['^(?!.*foo).*$'], + }, + ], + }, + ], + invalid: [], + }, + ) }) }) diff --git a/test/sort-variable-declarations.test.ts b/test/sort-variable-declarations.test.ts index 378d70fa..c6e9148a 100644 --- a/test/sort-variable-declarations.test.ts +++ b/test/sort-variable-declarations.test.ts @@ -844,6 +844,33 @@ describe(ruleName, () => { ], }, ) + + ruleTester.run( + `${ruleName}(${type}): allows to use regex matcher`, + rule, + { + valid: [ + { + code: dedent` + const + e = 'e', + f = 'f', + // I am a partition comment because I don't have f o o + a = 'a', + b = 'b' + `, + options: [ + { + ...options, + matcher: 'regex', + partitionByComment: ['^(?!.*foo).*$'], + }, + ], + }, + ], + invalid: [], + }, + ) }) }) diff --git a/test/sort-vue-attributes.test.ts b/test/sort-vue-attributes.test.ts index 9d99bea0..738967c3 100644 --- a/test/sort-vue-attributes.test.ts +++ b/test/sort-vue-attributes.test.ts @@ -308,6 +308,39 @@ describe(ruleName, () => { ], }, ) + + ruleTester.run( + `${ruleName}(${type}): allows to use regex matcher for custom groups`, + rule, + { + valid: [ + { + filename: 'file.vue', + code: dedent` + + `, + options: [ + { + ...options, + matcher: 'regex', + groups: ['unknown', 'elementsWithoutFoo'], + customGroups: { + elementsWithoutFoo: '^(?!.*Foo).*$', + }, + }, + ], + }, + ], + invalid: [], + }, + ) }) describe(`${ruleName}: sorting by natural order`, () => { diff --git a/utils/get-node-range.ts b/utils/get-node-range.ts index 9e429eb2..f892e757 100644 --- a/utils/get-node-range.ts +++ b/utils/get-node-range.ts @@ -10,7 +10,8 @@ export let getNodeRange = ( node: TSESTree.Node, sourceCode: TSESLint.SourceCode, additionalOptions?: { - partitionComment?: string[] | boolean | string + partitionByComment?: string[] | boolean | string + matcher?: 'minimatch' | 'regex' }, ): TSESTree.Range => { let start = node.range.at(0)! @@ -44,14 +45,21 @@ export let getNodeRange = ( } } let comments = getCommentsBefore(node, sourceCode) - let partitionComment = additionalOptions?.partitionComment ?? false + let partitionComment = additionalOptions?.partitionByComment ?? false + let partitionCommentMatcher = additionalOptions?.matcher ?? 'minimatch' // Iterate on all comments starting from the bottom until we reach the last // of the comments, a newline between comments, or a partition comment let relevantTopComment: TSESTree.Comment | undefined for (let i = comments.length - 1; i >= 0; i--) { let comment = comments[i] - if (isPartitionComment(partitionComment, comment.value)) { + if ( + isPartitionComment( + partitionComment, + comment.value, + partitionCommentMatcher, + ) + ) { break } // Check for newlines between comments or between the first comment and diff --git a/utils/is-partition-comment.ts b/utils/is-partition-comment.ts index 3c774cc3..50993c4d 100644 --- a/utils/is-partition-comment.ts +++ b/utils/is-partition-comment.ts @@ -1,25 +1,25 @@ import type { TSESTree } from '@typescript-eslint/types' -import { minimatch } from 'minimatch' +import { matches } from './matches' export let isPartitionComment = ( partitionComment: string[] | boolean | string, comment: string, + matcher: 'minimatch' | 'regex', ) => (Array.isArray(partitionComment) && partitionComment.some(pattern => - minimatch(comment.trim(), pattern, { - nocomment: true, - }), + matches(comment.trim(), pattern, matcher), )) || (typeof partitionComment === 'string' && - minimatch(comment.trim(), partitionComment, { - nocomment: true, - })) || + matches(comment.trim(), partitionComment, matcher)) || partitionComment === true export let hasPartitionComment = ( partitionComment: string[] | boolean | string, comments: TSESTree.Comment[], + matcher: 'minimatch' | 'regex', ): boolean => - comments.some(comment => isPartitionComment(partitionComment, comment.value)) + comments.some(comment => + isPartitionComment(partitionComment, comment.value, matcher), + ) diff --git a/utils/make-fixes.ts b/utils/make-fixes.ts index 4e508619..5940a355 100644 --- a/utils/make-fixes.ts +++ b/utils/make-fixes.ts @@ -12,7 +12,8 @@ export let makeFixes = ( sortedNodes: SortingNode[], source: TSESLint.SourceCode, additionalOptions?: { - partitionComment?: string[] | boolean | string + partitionByComment: string[] | boolean | string + matcher: 'minimatch' | 'regex' }, ) => { let fixes: TSESLint.RuleFix[] = [] diff --git a/utils/matches.ts b/utils/matches.ts new file mode 100644 index 00000000..4fab9537 --- /dev/null +++ b/utils/matches.ts @@ -0,0 +1,17 @@ +import { minimatch } from 'minimatch' + +export let matches = ( + value: string, + pattern: string, + type: 'minimatch' | 'regex', +) => { + switch (type) { + case 'regex': + return new RegExp(pattern).test(value) + case 'minimatch': + default: + return minimatch(value, pattern, { + nocomment: true, + }) + } +} diff --git a/utils/use-groups.ts b/utils/use-groups.ts index 040eb3b2..62f574bc 100644 --- a/utils/use-groups.ts +++ b/utils/use-groups.ts @@ -1,6 +1,11 @@ -import { minimatch } from 'minimatch' +import { matches } from './matches' -export let useGroups = (groups: (string[] | string)[]) => { +interface UseGroupProps { + matcher: 'minimatch' | 'regex' + groups: (string[] | string)[] +} + +export let useGroups = ({ matcher, groups }: UseGroupProps) => { let group: undefined | string // For lookup performance let groupsSet = new Set(groups.flat()) @@ -24,21 +29,12 @@ export let useGroups = (groups: (string[] | string)[]) => { for (let [key, pattern] of Object.entries(customGroups)) { if ( Array.isArray(pattern) && - pattern.some(patternValue => - minimatch(name, patternValue, { - nocomment: true, - }), - ) + pattern.some(patternValue => matches(name, patternValue, matcher)) ) { defineGroup(key, params.override) } - if ( - typeof pattern === 'string' && - minimatch(name, pattern, { - nocomment: true, - }) - ) { + if (typeof pattern === 'string' && matches(name, pattern, matcher)) { defineGroup(key, params.override) } }