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: ignorePatterns in config files (refs eslint/rfcs#22) #12274

Merged
merged 17 commits into from Nov 20, 2019
Merged

Conversation

@mysticatea
Copy link
Member

mysticatea commented Sep 17, 2019

What is the purpose of this pull request? (put an "X" next to item)

[X] Add something to the core.

What changes did you make? (Give an overview)

This PR implements ignorePatterns top-level property into config files. This feature has been approved in RFC 22. People can use ignorePatterns property instead of .eslintignore file. Also, people can provide the ignorePatterns setting with shareable configs. It will reduce the cost of setup of new repositories.

# .eslintrc.yml
ignorePatterns:
- /dist
- /temp
- /test.js
- "*.min.js"
extends:
- eslint:recommended
rules:
  semi: error

Detailed Design

I removed IgnoredPaths class that had been handling .eslintignore, --ignore-path, --ignore-pattern, and --no-ignore. Instead, now ConfigArray handles ignore patterns.

// Example of `ConfigArray`.
[
    { name: "DefaultIgnorePattern", ignorePattern: { /*...*/ } },
    { name: ".eslintrc.yml » eslint:recommended", /*...*/ },
    { name: ".eslintrc.yml", /*...*/ },
    { name: ".eslintignore", ignorePattern: { /*...*/ } },
    { name: "CLIOptions", ignorePattern: { /*...*/ } }, // --ignore-pattern
]

Like above, config array contains the ignore pattern data additionally if existed. It will merge ignore patterns of all config array element in the order as-is then create a node-ignore instance. This means, ignorePatterns properties will be merged in the same order as the other settings, and we can use the unignoring with !.

Classes:

  • IgnorePattern class (new!)
    It has basePath and patterns as similar to OverrideTester class that handles overrides[i].files. The IgnorePattern.createIgnore() static method creates the predicate function from multiple IgnorePattern instances.
  • ConfigArray class
    Now the array elements have ignorePattern property that is an IgnorePattern instance or undefined. The ConfigArray#extractConfig() method merges the IgnorePattern instances by IgnorePattern.createIgnore() static method.
  • ConfigArrayFactory class
    Now it recognizes ignorePatterns top-level property in config files then creates ignorePattern properties into config array elements.
    Also, now it has new two methods factory.loadESLintIgnore(filePath) and factory.loadDefaultESLintIgnore() to load .eslintignore and something like.
  • CascadingConfigArrayFactory class
    Now it recognizes --ignore-pattern, --ignore-path, and .eslintignore then creates the corresponding config array elements by a ConfigArrayFactory instance.
  • FileEnumerator class
    Now it has the updated ignoring logic.
  • CLIEngine class
    Now it has the updated ignoring logic in executeOnFiles(), executeOnText(), and isPathIgnored().

Tests:

  • First, I moved the tests in ignored-paths.js to cli-engine.js (a630d9e). Now it tests public APIs instead of internal classes. (I'd like to test the public APIs primarily. Many tests that depend on internal structures make tough to refactor code.)
  • Then, I added several tests to cli-engine.js to test isPathIgnored() and executeOnFiles() with the new feature. (executeOnText() uses isPathIgnored() internally)

Is there anything you'd like reviewers to focus on?

  • Are there more tests we should?
  • How do I improve the documentation?
mysticatea added 8 commits Sep 16, 2019
@mysticatea

This comment has been minimized.

Copy link
Member Author

mysticatea commented Sep 17, 2019

Hmm, the test results are different from my local... 🤔

@mysticatea mysticatea force-pushed the ignore-patterns branch from 9a60f5b to cf5befc Sep 17, 2019
@mysticatea mysticatea force-pushed the ignore-patterns branch from cf5befc to 869f96a Sep 17, 2019
@mysticatea

This comment has been minimized.

Copy link
Member Author

mysticatea commented Sep 18, 2019

This PR is ready for review.

Copy link
Member

platinumazure left a comment

Just two small changes needed from my perspective.

Not sure if another person should also review. This is a pretty large commit.

tests/lib/cli-engine/cli-engine.js Outdated Show resolved Hide resolved
lib/cli-engine/config-array/ignore-pattern.js Outdated Show resolved Hide resolved
mysticatea and others added 2 commits Sep 29, 2019
Co-Authored-By: Kevin Partington <platinum.azure@kernelpanicstudios.com>
Co-Authored-By: Kevin Partington <platinum.azure@kernelpanicstudios.com>
mysticatea added 2 commits Oct 8, 2019
# Conflicts:
#	lib/cli-engine/ignored-paths.js
#	tests/lib/cli-engine/ignored-paths.js
@mysticatea

This comment has been minimized.

Copy link
Member Author

mysticatea commented Oct 8, 2019

I have resolved conflicts.

Copy link
Member

kaicataldo left a comment

LGTM, thanks!

mysticatea added 2 commits Oct 10, 2019
# Conflicts:
#	lib/cli-engine/ignored-paths.js
@platinumazure platinumazure self-requested a review Oct 13, 2019
@fer22f fer22f mentioned this pull request Nov 17, 2019
10 of 10 tasks complete
Copy link
Member

kaicataldo left a comment

Still LGTM!

Copy link
Member

platinumazure left a comment

Just one small nit (left a suggestion), otherwise looks great. Thanks!

tests/lib/cli-engine/cli-engine.js Outdated Show resolved Hide resolved
Co-Authored-By: Kevin Partington <platinum.azure@kernelpanicstudios.com>
@kaicataldo kaicataldo merged commit ca3b2a6 into master Nov 20, 2019
18 checks passed
18 checks passed
Verify Files
Details
Test (ubuntu-latest, 13.x)
Details
Test (ubuntu-latest, 12.x)
Details
Test (ubuntu-latest, 10.x)
Details
Test (ubuntu-latest, 8.x)
Details
Test (ubuntu-latest, 8.10.0)
Details
Test (windows-latest, 12.x)
Details
Test (macOS-latest, 12.x)
Details
Browser Test
Details
commit-message PR title follows commit message guidelines
Details
continuous-integration Build #20191120.1 succeeded
Details
continuous-integration (Test on Node.js 10 (Linux)) Test on Node.js 10 (Linux) succeeded
Details
continuous-integration (Test on Node.js 12 (Linux)) Test on Node.js 12 (Linux) succeeded
Details
continuous-integration (Test on Node.js 12 (Windows)) Test on Node.js 12 (Windows) succeeded
Details
continuous-integration (Test on Node.js 12 (macOS)) Test on Node.js 12 (macOS) succeeded
Details
continuous-integration (Test on Node.js 8 (Linux)) Test on Node.js 8 (Linux) succeeded
Details
licence/cla Contributor License Agreement is signed.
Details
release-monitor No patch release is pending
Details
@kaicataldo kaicataldo deleted the ignore-patterns branch Nov 20, 2019
@kaicataldo

This comment has been minimized.

Copy link
Member

kaicataldo commented Nov 20, 2019

Thanks! Sorry for the delay in getting this merged.

@mysticatea

This comment has been minimized.

Copy link
Member Author

mysticatea commented Nov 20, 2019

Thank you for reviewing this big PR!

* @param {string[]} sourcePaths The paths to calculate the common ancestor.
* @returns {string} The path to the common ancestor directory.
*/
function getCommonAncestorPath(sourcePaths) {

This comment has been minimized.

Copy link
@nickharris

nickharris Feb 13, 2020

Contributor

@mysticatea - getCommonAncestorPath introduces this issue - #12850

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

None yet

4 participants
You can’t perform that action at this time.