1

I'm trying to lint certain rules via the eslint CLI in my create-react-app. The rule I'd like to fix is react/jsx-sort-props.

At first I tried the format for fixing single rules provided here: How to fix just one rule using eslint

"fix-style":"eslint --fix --rule 'react/jsx-sort-props"

But this gives error:

Invalid value for option 'rule' - expected type Object, received value: 'react/jsx-sort-props.

This error is discussed in ESLint CLI with --rule option but none of the solutions seem to work.

Running:

//package.json
"scripts": {
    "fix-style": "eslint --fix --rule 'react/jsx-sort-props: ['warn']'",
}

Gives:

$ eslint --fix --rule 'react/jsx-sort-props: ['warn']'

Oops! Something went wrong! :(

ESLint: 7.32.0

No files matching the pattern "['warn']'" were found.
Please check for typing mistakes in the pattern.

So what's the correct way to fix a single rule?

OS: Windows 10

ANimator120
  • 2,556
  • 1
  • 20
  • 52

2 Answers2

1

The inner single-quotes ended the rule string prematurely, so use double quotes to surround the entire string

try: eslint --fix --rule "react/jsx-sort-props: ['warn']"

0

It was necessary to escape the double quotes when using the command in my package.json:

  "scripts": {
    "start": "react-scripts start",
    "build": "react-scripts build",
    "fix-style": "eslint --fix --rule \"react/jsx-sort-props: ['warn']\"",
  },

ANimator120
  • 2,556
  • 1
  • 20
  • 52