Skip to content

Commit

Permalink
feat: move eslint --init to @eslint/create-config (#15150)
Browse files Browse the repository at this point in the history
* feat: move eslint --init to @eslint/create-config

fixes #14768, fixes #15159

Update: rm eslint auto config

refs: https://github.com/aladdin-add/rfcs/blob/bdc12aa062750d837e5a3bbbf2f6e5e3a98da388/designs/2021-init-command-eslint-cli/README.md#1-remove-eslint-auto-config

Update: mv eslint --init to another package

moved `lib/init/config-rule` to tools, as it is also used by some others

refs: https://github.com/aladdin-add/rfcs/blob/bdc12aa062750d837e5a3bbbf2f6e5e3a98da388/designs/2021-init-command-eslint-cli/README.md#2-move-eslint---init-related-files-to-a-separate-repo

chore: fix imports to make test passing

todo: use the new eslint api

fix: use the new eslint api (async)

fix: remove espree from deps

chore: fix a failing test

fix: a failing test

chore: cleanup TODOs

fix: allow to use local-installed eslint

wip: fix one-var

chore: lib => esm

chore: tests => esm

todo: proxyquire => td

chore: update deps to latest

fix: should write a file through fs when a ${fileType} path is passed

replaced proxyquire & sinon => td

fix: should include a newline character at EOF

chore: add testdouble

--wip-- [skip ci]

chore: remove package @eslint/create-eslint

feat: update npm --init to run `npm init @eslint/config`

docs: update getting-started

Update README.md

Update getting-started.md

chore: rm init fixtures

fix: `npm init @eslint/config` output

chore: rm unused files

chore: rm unused deps

Update bin/eslint.js

Co-authored-by: Brandon Mills <btmills@users.noreply.github.com>

chore: fix typo

* docs: rm mentioned `--init`

* chore: fixtures/autoconfig/*

* chore: add config-rule unit tests

* docs: update some `eslint --init` usage
  • Loading branch information
aladdin-add committed Jan 9, 2022
1 parent 79b6340 commit 0d2b9a6
Show file tree
Hide file tree
Showing 32 changed files with 26 additions and 3,132 deletions.
4 changes: 2 additions & 2 deletions README.md
Expand Up @@ -54,7 +54,7 @@ $ npm install eslint --save-dev
You should then set up a configuration file:

```sh
$ ./node_modules/.bin/eslint --init
$ npm init @eslint/config
```

After that, you can run ESLint on any file or directory like this:
Expand All @@ -65,7 +65,7 @@ $ ./node_modules/.bin/eslint yourfile.js

## <a name="configuration"></a>Configuration

After running `eslint --init`, you'll have a `.eslintrc` file in your directory. In it, you'll see some rules configured like this:
After running `npm init @eslint/config`, you'll have a `.eslintrc` file in your directory. In it, you'll see some rules configured like this:

```json
{
Expand Down
8 changes: 7 additions & 1 deletion bin/eslint.js
Expand Up @@ -124,7 +124,13 @@ ${message}`);

// Call the config initializer if `--init` is present.
if (process.argv.includes("--init")) {
await require("../lib/init/config-initializer").initializeConfig();

// `eslint --init` has been moved to `@eslint/create-config`
console.warn("You can also run this command directly using 'npm init @eslint/config'.");

const spawn = require("cross-spawn");

spawn.sync("npm", ["init", "@eslint/config"], { encoding: "utf8", stdio: "inherit" });
return;
}

Expand Down
1 change: 0 additions & 1 deletion docs/developer-guide/architecture.md
Expand Up @@ -7,7 +7,6 @@ At a high level, there are a few key parts to ESLint:
* `bin/eslint.js` - this is the file that actually gets executed with the command line utility. It's a dumb wrapper that does nothing more than bootstrap ESLint, passing the command line arguments to `cli`. This is intentionally small so as not to require heavy testing.
* `lib/api.js` - this is the entry point of `require("eslint")`. This file exposes an object that contains public classes `Linter`, `ESLint`, `RuleTester`, and `SourceCode`.
* `lib/cli.js` - this is the heart of the ESLint CLI. It takes an array of arguments and then uses `eslint` to execute the commands. By keeping this as a separate utility, it allows others to effectively call ESLint from within another Node.js program as if it were done on the command line. The main call is `cli.execute()`. This is also the part that does all the file reading, directory traversing, input, and output.
* `lib/init/` - this module contains `--init` functionality that set up a configuration file for end users.
* `lib/cli-engine/` - this module is `CLIEngine` class that finds source code files and configuration files then does code verifying with the `Linter` class. This includes the loading logic of configuration files, parsers, plugins, and formatters.
* `lib/linter/` - this module is the core `Linter` class that does code verifying based on configuration options. This file does no file I/O and does not interact with the `console` at all. For other Node.js programs that have JavaScript text to verify, they would be able to use this interface directly.
* `lib/rule-tester/` - this module is `RuleTester` class that is a wrapper around Mocha so that rules can be unit tested. This class lets us write consistently formatted tests for each rule that is implemented and be confident that each of the rules work. The RuleTester interface was modeled after Mocha and works with Mocha's global testing methods. RuleTester can also be modified to work with other testing frameworks.
Expand Down
2 changes: 1 addition & 1 deletion docs/user-guide/command-line-interface.md
Expand Up @@ -457,7 +457,7 @@ Example:

#### `--init`

This option will start config initialization wizard. It's designed to help new users quickly create .eslintrc file by answering a few questions, choosing a popular style guide, or inspecting your source files and attempting to automatically generate a suitable configuration.
This option will run `npm init @eslint/config` to start config initialization wizard. It's designed to help new users quickly create .eslintrc file by answering a few questions, choosing a popular style guide.

The resulting configuration file will be created in the current directory.

Expand Down
2 changes: 1 addition & 1 deletion docs/user-guide/configuring/configuration-files.md
Expand Up @@ -232,7 +232,7 @@ A [sharable configuration](https://eslint.org/docs/developer-guide/shareable-con

The `extends` property value can omit the `eslint-config-` prefix of the package name.

The `eslint --init` command can create a configuration so you can extend a popular style guide (for example, `eslint-config-standard`).
The `npm init @eslint/config` command can create a configuration so you can extend a popular style guide (for example, `eslint-config-standard`).

Example of a configuration file in YAML format:

Expand Down
10 changes: 5 additions & 5 deletions docs/user-guide/getting-started.md
Expand Up @@ -20,17 +20,17 @@ npm install eslint --save-dev
yarn add eslint --dev
```

You should then set up a configuration file, and the easiest way to do that is to use the `--init` flag:
You should then set up a configuration file, and the easiest way to do that is:

```sh
$ npx eslint --init
$ npm init @eslint/config

# or

$ yarn run eslint --init
$ yarn create @eslint/config
```

**Note:** `--init` assumes you have a `package.json` file already. If you don't, make sure to run `npm init` or `yarn init` beforehand.
**Note:** `npm init @eslint/config` assumes you have a `package.json` file already. If you don't, make sure to run `npm init` or `yarn init` beforehand.

After that, you can run ESLint on any file or directory like this:

Expand All @@ -48,7 +48,7 @@ It is also possible to install ESLint globally rather than locally (using `npm i

**Note:** If you are coming from a version before 1.0.0 please see the [migration guide](migrating-to-1.0.0.md).

After running `eslint --init`, you'll have a `.eslintrc.{js,yml,json}` file in your directory. In it, you'll see some rules configured like this:
After running `npm init @eslint/config`, you'll have a `.eslintrc.{js,yml,json}` file in your directory. In it, you'll see some rules configured like this:

```json
{
Expand Down
2 changes: 1 addition & 1 deletion docs/user-guide/migrating-from-jscs.md
Expand Up @@ -42,7 +42,7 @@ $ polyjuice --jscs .jscsrc.json ./foo/.jscsrc.json > .eslintrc.json
If you don't want to convert your JSCS configuration directly into an ESLint configuration, then you can use ESLint's built-in wizard to get you started. Just run:

```sh
$ eslint --init
$ npm init @eslint/config
```

You'll be guided through a series of questions that will help you setup a basic configuration file to get you started.
Expand Down

0 comments on commit 0d2b9a6

Please sign in to comment.