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

[Bug]: Support custom reserved words in jsx-sort-props #3639

Open
2 tasks done
hisuwh opened this issue Oct 5, 2023 · 3 comments
Open
2 tasks done

[Bug]: Support custom reserved words in jsx-sort-props #3639

hisuwh opened this issue Oct 5, 2023 · 3 comments
Labels

Comments

@hisuwh
Copy link

hisuwh commented Oct 5, 2023

Is there an existing issue for this?

  • I have searched the existing issues and my issue is unique
  • My issue appears in the command-line and not only in the text editor

Description Overview

eslint-plugin-react seems to be the go to linting plugin for any jsx/tsx, and indeed supports other frameworks than react by specifying the pragma setting.

However, the jsx-sort-props rule does not allow you to specify non react keywords in the reservedFirst option:

A customized reserved first list must only contain a subset of React reserved props

I'm using Vue which has a convention where their pseudo two-way binding prop v-model is always the first prop passed to a component - I wish to be able to enforce that for my tsx files.

        "react/jsx-sort-props": [
            "error",
            {
                "reservedFirst": ["v-model", "key", "ref"],
                "multiline": "last",
                "shorthandLast": true,
                "callbacksLast": true
            }
        ],

Expected Behavior

jsx-sort-props rule reservedFirst prop should allow non-react keywords

eslint-plugin-react version

v7.33.2

eslint version

v8.50.0

node version

v18.12.1

@hisuwh hisuwh added the bug label Oct 5, 2023
@ljharb
Copy link
Member

ljharb commented Oct 5, 2023

The only acceptable way to manage this would likely be to add a new settings.react config that lets you define, for the whole plugin, what the reserved prop names are, that would default to:

const RESERVED_PROPS_LIST = [
  'children',
  'dangerouslySetInnerHTML',
  'key',
  'ref',
];

However, for anyone who's not using vue, this seems like it has the potential to cause a lot of bugs and confusion, since some may change it for aesthetic reasons, not realizing it must only match the renderer's reserved props.

@hisuwh
Copy link
Author

hisuwh commented Oct 6, 2023

it must only match the renderer's reserved props

@ljharb what's the reason for this?

@ljharb
Copy link
Member

ljharb commented Oct 8, 2023

Because miscategorizing reserved props can lead to user confusion and bugs.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Development

No branches or pull requests

2 participants