Add support for config files
See original GitHub issueProposal
Teach the binary to accept a --config
option
This option would allow you to specify a config file on disk from which additional options would be read. The file would contain additional options to be included with the invocation; for example:
--cpus 2 -v
Options explicitly provided on the command-line would override options read from the config file. For example, given the config above, --cpus
would be set to 4
for an invocation like this:
jscodeshift --config my-config --cpus 4 target.js
In the absence of a --config
option, look for config in default locations
Default locations could be:
.jscodeshiftrc
in current directory$HOME/.jscodeshiftrc
/etc/jscodeshiftrc
(or something like that)
This would, for example, enable you to provide a consistent set of Recast printOptions
that you would use, by convention, in all of your transform scripts (ie. in the call to toSource()
).
Considerations
Do we want the config file to be just a dumb string that we split and pass into nomnom as though the args were passed on the commandline? Or do we prefer a more structured format (like JSON) which would allow us to pass richer configuration objects rather than just scalar values (strings, numbers, bools)? I’m inclined to think the latter, so that we could configure things like printOptions
for Recast with:
{
'cpus': 2,
'v': true,
'printOptions': {'quote': 'single'}
}
Issue Analytics
- State:
- Created 8 years ago
- Reactions:2
- Comments:8 (7 by maintainers)
Top GitHub Comments
I think this suggestion should be revisited (there are nice solutions today like cosmiconfig for dealing with format). I currently have to use a custom npm script which passes options to jscodeshift the way I want, I think a config file would be a cleaner solution. Also, libraries like react-codemod could read your configuration instead of asking you (and I still couldn’t configure it to work, but that’s another story).
that’s I’m doing inside my transformer file
how to use it
jscodeshift -t transform.ts --config path/to/config.js
config.js