Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New: ESLint Class Replacing CLIEngine #40

Merged
merged 47 commits into from Jan 6, 2020
Merged
Changes from 3 commits
Commits
Show all changes
47 commits
Select commit Hold shift + click to select a range
b1840be
New: Moving to Asynchronous API
mysticatea Sep 28, 2019
6135383
add PR link
mysticatea Sep 28, 2019
0af99b0
fix to not change existing methods
mysticatea Sep 28, 2019
d9444ef
change getFormatter
mysticatea Oct 1, 2019
e5cc07c
fix getFormatter
mysticatea Oct 2, 2019
be5878c
update
mysticatea Oct 3, 2019
628e262
update Backwards Compatibility Analysis section
mysticatea Oct 3, 2019
cade0bd
add an example
mysticatea Oct 3, 2019
c99ae56
trivial fix
mysticatea Oct 3, 2019
730cb58
Add a note about streams
mysticatea Oct 3, 2019
2ab427f
trivial fix
mysticatea Oct 3, 2019
ed35022
update getErrorResults since it's sandwiched
mysticatea Oct 3, 2019
13354ce
add fail-fast note
mysticatea Oct 4, 2019
2aa4a5e
update
mysticatea Oct 8, 2019
8892dc7
refactor and add about usedDeprecatedRules
mysticatea Oct 13, 2019
7a94b03
fix typo
mysticatea Oct 13, 2019
7b5e401
fix typo
mysticatea Oct 14, 2019
2981228
add about aborting
mysticatea Oct 14, 2019
72e69af
add constructor and remove addPlugin
mysticatea Oct 14, 2019
86689ec
Update motivation section
mysticatea Oct 15, 2019
a76d6c0
Update motivation section
mysticatea Oct 15, 2019
face206
Update design overview
mysticatea Oct 15, 2019
65b67f5
Update constructor description
mysticatea Oct 15, 2019
cedb6e6
Update fail-fast on parallel calling section
mysticatea Oct 15, 2019
8f58df9
Update designs/2019-move-to-async-api/README.md
mysticatea Oct 15, 2019
227fe54
Update designs/2019-move-to-async-api/README.md
mysticatea Oct 15, 2019
4c5cdff
update RFC for more clarification and...
mysticatea Oct 17, 2019
00be95b
add a related discussion
mysticatea Oct 17, 2019
756e929
add about cache when abort
mysticatea Oct 21, 2019
975fa02
add TOC of methods
mysticatea Oct 21, 2019
f22894b
update about disallow execution in parallel
mysticatea Oct 21, 2019
d45e86e
rewrite "Alternatives" section
mysticatea Oct 21, 2019
c5bdf22
revert about errorsOnly and...
mysticatea Oct 21, 2019
6ecf034
small fix
mysticatea Oct 21, 2019
98243b8
remove collectResults method
mysticatea Nov 14, 2019
13650ff
remove getRules()
mysticatea Nov 14, 2019
a860d00
update the sentence about ES modules
mysticatea Nov 14, 2019
eeac990
rename for lintFiles() and lintText()
mysticatea Nov 14, 2019
6a36a14
replace pluginImplementations option
mysticatea Nov 14, 2019
ab978fa
update about cache handling
mysticatea Nov 14, 2019
920c881
rename the new class
mysticatea Nov 22, 2019
8547265
remove about to print progress
mysticatea Nov 30, 2019
c24f337
Update designs/2019-move-to-async-api/README.md
mysticatea Dec 5, 2019
9d4affc
Update designs/2019-move-to-async-api/README.md
mysticatea Dec 8, 2019
5032c3c
Update designs/2019-move-to-async-api/README.md
mysticatea Dec 8, 2019
671cf6a
remove about printing progress
mysticatea Dec 8, 2019
ef4d198
ESLint class again
mysticatea Dec 8, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
75 changes: 75 additions & 0 deletions designs/2019-move-to-async-api/README.md
@@ -0,0 +1,75 @@
- Start Date: 2019-09-28
- RFC PR: https://github.com/eslint/rfcs/pull/40
- Authors: Toru Nagashima ([@mysticatea](https://github.com/mysticatea))

# Moving to Asynchronous API
mysticatea marked this conversation as resolved.
Show resolved Hide resolved

## Summary

This RFC adds a new class `ESLint` that has asynchronous API and deprecates `CLIEngine`.

## Motivation

- Dynamic `import()` has arrived at Stage 4. The dynamic loading of ES modules requires asynchronous API. Migrating to asynchronous API opens up doors to write plugins/configs with ES modules.
mysticatea marked this conversation as resolved.
Show resolved Hide resolved
- Linting in parallel requires asynchronous API. We can improve linting logic to run it in parallel. And we can improve config loading logic and file enumeration logic to run it in parallel. (E.g., load `extends` list, traverse child directories.)

Because the migration of public API needs long time, we should start to migrate our APIs earlier.

And the name of `CLIEngine`, our primary API, causes confusion to the community. People try `Linter` class at first, then they notice it doesn't work as expected. We have a lot of issues that say "please use `CLIEngine` instead."
The name of new class, `ESLint`, is our primary API clearly.

## Detailed Design

### Add new `ESLint` class

This RFC adds a new class `ESLint`. It has almost the same methods as `CLIEngine`, but the following methods return `Promise`.

- `executeOnFiles()`
- `executeOnText()`
- `getConfigForFile()`
mysticatea marked this conversation as resolved.
Show resolved Hide resolved
- `getFormatter()`
- `isPathIgnored()`
- `outputFixes()`

The following methods are as-is because those don't touch both file system and module system.

- `addPlugin()`
- `getErrorResults()`
mysticatea marked this conversation as resolved.
Show resolved Hide resolved
- `getRules()`
- `resolveFileGlobPatterns()`

### Deprecate `CLIEngine` class

This RFC soft-deprecates `CLIEngine` class.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

May I suggest adding something similar to:

- Adds `disallowWorkerThreads` option to plugins. Defaults to `false`.

Like:

- Adds `requiresAsyncUse` option to plugins. Defaults to `false`.

That way any plugin which wants to move to fully use the new async features can do so without risking incompatibilities with the sync flow.

If that property is set on a plugin, then the sync flow of CLIEngine should error when encountering it and tell the user about the incompatibility.

This would help the ecosystem in regards to the deprecation and the move towards an async flow.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure if there are incompatibility things about this. We don't provide any asynchronous API to plugins. On the other hand, running in parallel can break plugins that use OS resources exclusively (e.g., cache file).

In the future, if we support asynchronous stuff for plugins (e.g., ES modules. It requires import() to load the plugins), CLIEngine fails to load those. I don't think that we need additional flags.


Because it's tough to maintain two versions (sync and async) of implementation. The two are almost copy-pasted stuff, but hard to share the code. Therefore, this RFC deprecates the sync version to improve our code with the way which needs asynchronous behavior in the future. For example, `CLIEngine` cannot support parallel linting, plugins/configs as ES modules, etc...

### Out of scope

- Not change API for rules. This RFC doesn't change APIs that rule implementation uses. We may be able to support asynchronous stuff in rules in the future, but it's out of this RFC's scope.
- Not change internal logics. This RFC just adds the public interface that is asynchronous. It would be a wrapper of `CLIEngine` for now.

## Documentation

- The "[Node.js API](https://eslint.org/docs/developer-guide/nodejs-api)" page should describe the new public API and deprecation of `CLIEngine` class.

## Drawbacks

People that use `CLIEngine` have to update their application with the new API. It will need hard work.

## Backwards Compatibility Analysis

Deprecating `CLIEngine` is a drastic change. But people can continue to use `CLIEngine` as-is until we decide to remove it. The decision would not be near future.

We can do both adding a new class and the deprecation in a minor release.

## Alternatives

- Adding `engine.executeAsyncOnFiles()`-like methods and we maintain it along with the existing synchronous API. But as what I wrote in the "[Deprecate `CLIEngine` class](#deprecate-cliengine-class)" section, it would be tough.
mysticatea marked this conversation as resolved.
Show resolved Hide resolved

## Related Discussions

- https://github.com/eslint/eslint/issues/3565 - Lint multiple files in parallel
- https://github.com/eslint/eslint/issues/12319 - `ERR_REQUIRE_ESM` when requiring `.eslintrc.js`
- https://github.com/eslint/rfcs/pull/4 - New: added draft for async/parallel proposal
- https://github.com/eslint/rfcs/pull/11 - New: Lint files in parallel