import-sort
import-sort copied to clipboard
Unclear how to set style when using the CLI
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.
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
Oh, I didn't know about the config file. Thanks for the tip @danielpza!