Skip to content

Commit

Permalink
feat(sort-objects): add custom-ignore to enable customizable ignore rule
Browse files Browse the repository at this point in the history
  • Loading branch information
KID-joker committed Apr 22, 2024
1 parent c2eac1c commit 81b978e
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 9 deletions.
6 changes: 3 additions & 3 deletions docs/rules/sort-objects.md
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ interface Options {
'custom-groups'?: { [key: string]: string[] | string }
'styled-components'?: boolean
'ignore-pattern'?: string[]
'ignore-function'?: { [key: string]: Function }
'custom-ignore'?: { [key: string]: Function }
'partition-by-comment'?: string[] | string | boolean
'partition-by-new-line'?: boolean
}
Expand Down Expand Up @@ -150,7 +150,7 @@ If you need to ignore a rule for some interfaces, you can specify their names or

The [minimatch](https://github.com/isaacs/minimatch) library is used for pattern matching.

### ignore-function
### custom-ignore

<sub>(default: `{}`)</sub>

Expand All @@ -160,7 +160,7 @@ Example:

```
{
"ignore-function": {
"custom-ignore": {
ignoreButtonStyles: (node: TSESTree.ObjectExpression | TSESTree.ObjectPattern, filename: string) => {
if (
node.parent.type === 'VariableDeclarator' &&
Expand Down
8 changes: 4 additions & 4 deletions rules/sort-objects.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ type SortingNodeWithPosition = SortingNode & {
type Options = [
Partial<{
'custom-groups': { [key: string]: string[] | string }
'ignore-function': { [key: string]: Function }
'custom-ignore': { [key: string]: Function }
'partition-by-comment': PartitionComment
'partition-by-new-line': boolean
groups: (string[] | string)[]
Expand Down Expand Up @@ -101,7 +101,7 @@ export default createEslintRule<Options, MESSAGE_ID>({
},
type: 'array',
},
'ignore-function': {
'custom-ignore': {
type: 'object',
},
groups: {
Expand Down Expand Up @@ -132,14 +132,14 @@ export default createEslintRule<Options, MESSAGE_ID>({
'styled-components': true,
'ignore-case': false,
'ignore-pattern': [],
'ignore-function': {},
'custom-ignore': {},
order: SortOrder.asc,
'custom-groups': {},
groups: [],
})

let shouldIgnore = false
let ignoreFunctions = Object.values(options['ignore-function'])
let ignoreFunctions = Object.values(options['custom-ignore'])
if (
ignoreFunctions.length &&
ignoreFunctions.some(fn => fn(node, context.filename))
Expand Down
4 changes: 2 additions & 2 deletions test/sort-objects.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2684,7 +2684,7 @@ describe(RULE_NAME, () => {
`,
options: [
{
'ignore-function': {
'custom-ignore': {
ignoreButtonStyles: (node: TSESTree.ObjectExpression) => {
if (
node.parent.type === 'VariableDeclarator' &&
Expand Down Expand Up @@ -2773,7 +2773,7 @@ describe(RULE_NAME, () => {
`,
options: [
{
'ignore-function': {
'custom-ignore': {
ignoreButtonStyles: () => false,
},
},
Expand Down

0 comments on commit 81b978e

Please sign in to comment.