import-sort icon indicating copy to clipboard operation
import-sort copied to clipboard

Unclear how to set style when using the CLI

Open PaulRBerg opened this issue 4 years ago • 2 comments

Use case

Run import-sort on an entire code base to programatically sort imports in all files according to a non-default import style.

Current Workaround

Temporarily modify the root package.json by adding the following field:

"importSort": {
  ".js, .jsx, .ts, .tsx": {
    "parser": "MY_PARSER",
    "style": "MY_STYLE"
  }
}

Optionally install the style if not already present in node_modules.

Then run the import sort CLI:

npx import-sort-cli ./path/to/my-files

Then delete the importSort field in package.json because it's no longer needed.

Question

Is this the recommended way to run the CLI? I couldn't find any documentation in the README for how to set the style when running the CLI. The command-line options listed in the README don't include a style option.

PaulRBerg avatar Mar 19 '21 13:03 PaulRBerg

I also have this question.

@paulrberg however note you can also use a .importsortrc file if you don't want to put it in your package.json see https://github.com/renke/import-sort#using-a-different-style-or-parser

danielpza avatar Oct 01 '21 04:10 danielpza

Oh, I didn't know about the config file. Thanks for the tip @danielpza!

PaulRBerg avatar Oct 01 '21 12:10 PaulRBerg