Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature: Add checking ignore patterns for JSX properties name in sort-object #96

Open
2 tasks done
hstemplewski opened this issue Dec 7, 2023 · 1 comment
Open
2 tasks done
Labels
enhancement New feature or request

Comments

@hstemplewski
Copy link

hstemplewski commented Dec 7, 2023

What rule do you want to change?

JSX properties are missed when checking ignore rule pattern

Describe the problem

When we are using React as a framework and added perfectionist which sorts object keys, the pattern for ignore sorting does not check the JSX prop names when the object is passed directly to the component.

Code example

<Table
  //This one shouldn't be sorted
  columns={{
    firstCol: "COL 1",
    secondCol: "COL 2",
    thirdCol: "COL 3",
    fourhtCol: "COL 4"
  }}
/>

the rule is applied like:

"perfectionist/sort-objects": [
      "error",
      {
        type: "natural",
        order: "asc",
        "ignore-pattern": ["[Cc]olumn*"],
        groups: ["id", "unknown"],
        "custom-groups": {
          id: "id",
        },
      },
    ],

Additional comments

I think this one needs to be changes from

 let variableIdentifier =
        node.parent.type === 'VariableDeclarator' &&
        node.parent.id.type === 'Identifier'
          ? node.parent.id.name
          : null

to (or sth simmillar)

 let variableIdentifier =
        (node.parent.type === 'VariableDeclarator' || node.parent.type === 'JSXAttribute') &&
        node.parent.id.type === 'Identifier'
          ? node.parent.id.name
          : null

Validations

  • Read the docs.
  • Check that there isn't already an issue that reports the same bug to avoid creating a duplicate.
@hstemplewski hstemplewski added the enhancement New feature or request label Dec 7, 2023
@hstemplewski hstemplewski changed the title Feature: Add checking JSX properties in sort-object Feature: Add checking ignore patterns for JSX properties name in sort-object Dec 7, 2023
@azat-io
Copy link
Owner

azat-io commented Dec 7, 2023

Thanks, that's a really good point, I'll think about how this can be fixed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants