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

Conversation

mysticatea
Copy link
Member

@mysticatea 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 mysticatea added core Relates to ESLint's core APIs and features accepted There is consensus among the team that this change meets the criteria for inclusion feature This change adds a new feature to ESLint labels Sep 17, 2019
@mysticatea
Copy link
Member Author

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

@mysticatea
Copy link
Member Author

This PR is ready for review.

Copy link
Member

@platinumazure platinumazure left a comment

Choose a reason for hiding this comment

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

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 September 29, 2019 13:09
Co-Authored-By: Kevin Partington <platinum.azure@kernelpanicstudios.com>
Co-Authored-By: Kevin Partington <platinum.azure@kernelpanicstudios.com>
# Conflicts:
#	lib/cli-engine/ignored-paths.js
#	tests/lib/cli-engine/ignored-paths.js
@mysticatea
Copy link
Member Author

I have resolved conflicts.

Copy link
Member

@kaicataldo kaicataldo left a comment

Choose a reason for hiding this comment

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

LGTM, thanks!

lib/cli-engine/config-array/ignore-pattern.js Show resolved Hide resolved
@platinumazure platinumazure self-requested a review October 13, 2019 04:10
Copy link
Member

@kaicataldo kaicataldo left a comment

Choose a reason for hiding this comment

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

Still LGTM!

Copy link
Member

@platinumazure platinumazure left a comment

Choose a reason for hiding this comment

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

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
@kaicataldo kaicataldo deleted the ignore-patterns branch November 20, 2019 06:52
@kaicataldo
Copy link
Member

Thanks! Sorry for the delay in getting this merged.

@mysticatea
Copy link
Member Author

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) {
Copy link
Contributor

Choose a reason for hiding this comment

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

@mysticatea - getCommonAncestorPath introduces this issue - #12850

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
accepted There is consensus among the team that this change meets the criteria for inclusion archived due to age This issue has been archived; please open a new issue for any further discussion core Relates to ESLint's core APIs and features feature This change adds a new feature to ESLint
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants