Skip to content

Commit

Permalink
feat: support --config (#38)
Browse files Browse the repository at this point in the history
* feat: support `--config`

* docs: add `--config` flag

* fix: multiple use of `--config` flag error
  • Loading branch information
kecrily committed Oct 17, 2022
1 parent 368a1a3 commit a0fa620
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 1 deletion.
20 changes: 19 additions & 1 deletion README.md
@@ -1,4 +1,5 @@
# @eslint/create-config

Utility to create ESLint config files

## <a name="usage"></a>Usage
Expand All @@ -15,4 +16,21 @@ npm init @eslint/config
```bash
# use npx
npx @eslint/create-config
```
```

If you want to use the specified shared configs:

```bash
# use `eslint-config-semistandard` shared config
npm init @eslint/config --config semistandard
# or (`eslint-config` prefix is optional)
npm init @eslint/config --config eslint-config-semistandard
```

The `--config` flag also supports passing in arrays:

```bash
npm init @eslint/config --config semistandard,standard
# or
npm init @eslint/config --config semistandard --config standard
```
12 changes: 12 additions & 0 deletions lib/init/config-initializer.js
Expand Up @@ -16,6 +16,7 @@ import { Legacy } from "@eslint/eslintrc";
import { info } from "../shared/logging.js";
import * as ConfigFile from "./config-file.js";
import * as npmUtils from "./npm-utils.js";
import mri from "mri";

const { ConfigOps, naming, ModuleResolver } = Legacy;

Expand Down Expand Up @@ -571,6 +572,17 @@ function promptUser() {
* @returns {void}
*/
function initializeConfig() {
const argv = mri(process.argv.slice(2));

if (argv.config) {
const config = {
extends: typeof argv.config === "string" ? argv.config.split(",") : argv.config
};
const modules = getModulesList(config);

return askInstallModules(modules).then(() => writeFile(config, "JavaScript"));
}

return promptUser();
}

Expand Down
1 change: 1 addition & 0 deletions package.json
Expand Up @@ -50,6 +50,7 @@
"enquirer": "^2.3.5",
"js-yaml": "^4.1.0",
"json-stable-stringify-without-jsonify": "^1.0.1",
"mri": "^1.2.0",
"semver": "^7.2.1"
},
"devDependencies": {
Expand Down

0 comments on commit a0fa620

Please sign in to comment.