Skip to content

Commit efd5e7d

Browse files
authored
feat: ESLint class migration (#11)
* refactor: make linter asynchronous Refactor the linter method to run asynchronously because many methods have been changed to run asynchronously in the new ESLint class. Preperation for migration to the ESLint class, see #10. * refactor: make formatter loading asynchronous Refactor to asynchronous formatter loading because the new ESLint class loads formatters asynchronously. Move formatter loading to the linter file for access to the ESLint instance because the new ESLint loadFormatter method is not static. Refactor formatter loading to use a CLIEngine instance. Refactor the linting function to load the formatters. Preperation for migration to the ESLint class, see #10. * refactor: add loader option filtering Refactor to filter out loader options before passing the options to ESLint because the new ESLint class throws when unknown options are passed to it. Add method for filtering out loader options and unit tests for it. Rename the getOptions file options because it now contains option utilities. It was possible to have getESLintOptions as a private function in getCLIEngine, but having it exported helps testing. There is no way to query the ESLint class for the options it received so there is no way to test it through the getCLIEngine/ESLint method. Part of the migration to the new ESLint class, see #10. * refactor: simplify getCLIEngine Refactor to simplify and remove unnecessary operations. After the formatter loading refactor the getCLIEngine is no longer used without starting a CLIEngine. Remove no longer used options parameter reassignments. Remove unused eslintPath property from the return object. Preperation for migration to the ESLint class, see #10. * refactor: add custom formatter mock Refactor the custom formatter tests to use a mock. Refactor to test the error output to make sure the selected formatter is being used. The test used to always pass because formatter loading fails silently and returns the default formatter. Add a mock formatter. Remove eslint-friendly-formatter that was only used for the test. This refactor helps decouple the tests from the results format. Making the migration to the new ESLint class easier. Preperation for migration to the ESLint class, see #10. * chore: update ESLint development dependency Update ESLint development dependency to version 7 to prepare for migration to the new ESLint class that was introduced with it. Part of the migration to the new ESLint class, see #10. * refactor: migrate tests to the ESLint class Refactor the ESLint mock to imitate the new ESLint class. Refactor to simplify mock formatter loading. Refactor ESLint options because the new API introduces a new options format. The tests do not pass yet as the plugin has not been refactored. Part of the migration to the new ESLint class, see #10. * refactor: migrate to the new ESLint class Refactor linter to the new ESLint class. Refactor the getCLIEngine method to getESLint. Refactor LintDirtyModulesPlugin to remove use of resolveFileGlobPatterns which is not available in the new API. File paths should work fine as globs and do not need to be converted. Completing the migration to the new ESLint class, see #10. * chore: update package and documentation Update plugin ESLint peer dependency to remove version 6 support. Update the readme to reflect the changes to the plugin. Add warning that the plugin used to use CLIEngine in version 1. Finishing details of the ESLint class migration. Closes #10. * refactor: remove callback from linter function Refactor to remove an unnecessary callback from the linter function. It is unnecessary because linter is an async function returning a promise so it can be used directly with a promise tap. Preparation for requested change in #11. * refactor: simplify dirty file linting Refactor LintDirtyModulesPlugin to only handle dirty file filtering. The refactor allows for easier testing without the need for mocks. Rename LintDirtyModulesPlugin to DirtyFileWatcher to make the name more descriptive of the new functionality. Refactor the tests for the simplified DirtyFileWatcher. Refactor the tests to use absolute paths because Webpack passes absolute paths in the compiler.fileTimestamps map. Refactor to only test system specific paths. The functionality of the requested change requires using real paths for some tests which causes issues with testing both Windows and Unix paths on the same machine. As the CI runs on Windows, Mac and Linux paths will be tested on all platforms. Preparation for requested change in #11. * test: add tests for dirty watch file patterns Add failing tests that ensure dirty file watching is matching patterns from the files options exactly like ESLint. Add folder fixture because handling folder paths requires checking existence of folders. Preparation for requested change in #11. * fix: folder pattern watch issue Fix issue with folder patterns not working with the lintDirtyModulesOnly option. The issue was caused by the removal of resolveFileGlobPatterns which resolved folder patterns into globs matching the correct file extensions. Resolve requested change in #11. * refactor: replace remaining callbacks with async functions Refactor remaining callbacks to async functions to make them consistent with the rest of the taps that have been refactored. * fix: use plugin object for linter hook identity Refactor the linter function to register hooks with the same plugin object that is used to register the run and watchRun hooks. * perf: parse patterns to globs only on startup Refactor to parse patterns only on startup instead of parsing them to globs on each run. In watch mode Webpack does not watch it's own configuration so the plugin configuration does not change when Webpack is running. Because the file patterns and extensions do not change there is no need to process them into globs separately for each run. * docs: add information about the files option Add more information about the files option to the readme.
1 parent e01341c commit efd5e7d

25 files changed

+767
-455
lines changed

README.md

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -54,11 +54,13 @@ module.exports = {
5454

5555
## Options
5656

57-
You can pass [eslint options](http://eslint.org/docs/developer-guide/nodejs-api#cliengine).
57+
You can pass [eslint options](https://eslint.org/docs/developer-guide/nodejs-api#%E2%97%86-new-eslint-options).
5858

59-
Note that the config option you provide will be passed to the `CLIEngine`.
59+
Note that the config option you provide will be passed to the `ESLint` class.
6060
This is a different set of options than what you'd specify in `package.json` or `.eslintrc`.
61-
See the [eslint docs](http://eslint.org/docs/developer-guide/nodejs-api#cliengine) for more detail.
61+
See the [eslint docs](https://eslint.org/docs/developer-guide/nodejs-api#%E2%97%86-new-eslint-options) for more details.
62+
63+
**Warning**: In eslint-webpack-plugin version 1 the options were passed to the now deprecated [CLIEngine](https://eslint.org/docs/developer-guide/nodejs-api#cliengine).
6264

6365
### `context`
6466

@@ -79,7 +81,9 @@ Path to `eslint` instance that will be used for linting. If the `eslintPath` is
7981
- Type: `String|Array[String]`
8082
- Default: `'.'`
8183

82-
Specify the files and/or directories to traverse. Must be relative to `options.context`.
84+
Specify directories, files, or globs. Must be relative to `options.context`.
85+
Directories are traveresed recursively looking for files matching `options.extensions`.
86+
File and glob patterns ignore `options.extensions`.
8387

8488
### `fix`
8589

0 commit comments

Comments
 (0)