facebook / facebook/jscodeshift

Add support for config files

Open
#4 8 comments 3 reactions 0 assignees View on GitHub
improvement
Dominant language
JavaScript
Stars
10k
Forks
498
PR merge metrics
No merged PRs in 30d

Description

## Proposal
### 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'}
}
```

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.