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

Add allowEmptyInput, cache, fix options to configuration object #6778

Merged
merged 6 commits into from Apr 20, 2023

Conversation

mattxwang
Copy link
Member

@mattxwang mattxwang commented Apr 12, 2023

Which issue, if any, is this issue related to?

Part of (but does not close) #5142. This PR handles all the boolean flags (which should be relatively simple).

Is there anything in the PR that needs further explanation?

Sorry about the CodeQL alerts - it was an approach that I tried (and chose to abandon) that I forgot to remove 😅

As well as my note below on cache, two quick questions:

  1. For the configuration docs, what orders should the options go in? I may have missed a pattern - I was confused since it's not in the same order as the flags.
  2. Any tests I should add?

Note that I didn't augmentConfig for allowEmptyInput and cache, since we never access them through the config object outside of standalone.js; including them drops code coverage. That being said, maybe there's a cleaner way to use these options "downstream", and be consistent in augmenting the config?

@changeset-bot
Copy link

changeset-bot bot commented Apr 12, 2023

🦋 Changeset detected

Latest commit: 52b2ad5

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
stylelint Minor

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@mattxwang mattxwang force-pushed the add-remaining-boolean-config-objects branch from d1397b6 to cea2d4b Compare April 12, 2023 07:59
@mattxwang mattxwang marked this pull request as ready for review April 12, 2023 08:09
@mattxwang
Copy link
Member Author

mattxwang commented Apr 12, 2023

In #6402, it sounds like cache may be more complicated than it first seems. I feel like in this case, I must be missing a test case that addresses the complication in the issue (about per-file config resolution). My understanding is that the test cases are when the "global" cache disagrees with a per-file cache; in that case, the per-file cache should win. Is that correct?

(that's not what is implemented in the code right now)

@mattxwang mattxwang marked this pull request as draft April 12, 2023 08:18
@mattxwang mattxwang force-pushed the add-remaining-boolean-config-objects branch from b4313a7 to 014d5a9 Compare April 12, 2023 08:23
@mattxwang mattxwang marked this pull request as ready for review April 12, 2023 08:30
@ybiquitous ybiquitous mentioned this pull request Apr 13, 2023
6 tasks
@ybiquitous
Copy link
Member

  1. For the configuration docs, what orders should the options go in? I may have missed a pattern - I was confused since it's not in the same order as the flags.

I believe there is no clear order. We can improve the doc later, so this PR's change looks good.

@ybiquitous
Copy link
Member

@mattxwang Thanks for the pull request. In this good opportunity, I'm reconsidering this feature:

Should CLI flags win config files?

For example, assume we have the following config file named .stylelintrc.json:

{ "cache": true }

Then, should we expect the following? Note that --no- prefix is supported by meow.

# Cache is enabled via config file
stylelint *.css

# Cache is enabled via CLI flag
stylelint *.css --cache

# Cache is disabled via CLI flag
stylelint *.css --no-cache

My answer to the question above is yes. Because people would like to turn on/off caching without editing the config file.

Should we support per-file configs for properties like cache?

For example, assume we have the following config files:

.stylelintrc.json:

{ "cache": true }

special/folder/.stylelintrc.json:

{ "cache": false }

I don't believe such a per-file overriding for global settings makes sense. Lint performance and code maintainability would degrade. Even usability might decrease due to config files everywhere.

So, I recommend supporting only properties in the root config file. We can just ignore properties in sub-folder configs. Of course, we should clearly state the restriction in the document.

What do you think?

Similar discussions around config file

@mattxwang
Copy link
Member Author

Thanks for the quick response @ybiquitous, I think you bring up some really great points!

Should CLI flags win config files?

For example, assume we have the following config file named .stylelintrc.json:

{ "cache": true }

Then, should we expect the following? Note that --no- prefix is supported by meow.

# Cache is enabled via config file
stylelint *.css

# Cache is enabled via CLI flag
stylelint *.css --cache

# Cache is disabled via CLI flag
stylelint *.css --no-cache

My answer to the question above is yes. Because people would like to turn on/off caching without editing the config file.

I agree with you here (in other words, the CLI flag takes precedence over the config file)! Just implemented the change + have added tests for each of those three cases.

Should we support per-file configs for properties like cache?

I don't believe such a per-file overriding for global settings makes sense. Lint performance and code maintainability would degrade. Even usability might decrease due to config files everywhere.

So, I recommend supporting only properties in the root config file. We can just ignore properties in sub-folder configs. Of course, we should clearly state the restriction in the document.

This makes sense to me as well. Do you think there are other config options that fall into this category? The rest of them feel like they could be enabled/disabled per-file.

If the user has set cache in a subdirectory - should we error, print a message saying that we're ignoring, proceed quietly, or do something else? If this is an exception rather than a rule, I think informing users may be a good idea.

@ybiquitous
Copy link
Member

Do you think there are other config options that fall into this category? The rest of them feel like they could be enabled/disabled per-file.

Basically, we should prevent per-file config props from increasing in the future (we have now overrides). I'm not sure which config props support per-file configs, though. Anyway, not touching the existing props might be safe not to break users' linting.

If the user has set cache in a subdirectory - should we error, print a message saying that we're ignoring, proceed quietly, or do something else? If this is an exception rather than a rule, I think informing users may be a good idea.

I believe erroring is best, but if hard to implement it, just documenting the limitation might be enough.

lib/__tests__/standalone-cache.test.js Outdated Show resolved Hide resolved
lib/standalone.js Outdated Show resolved Hide resolved
lib/standalone.js Outdated Show resolved Hide resolved
lib/standalone.js Outdated Show resolved Hide resolved
Co-authored-by: Masafumi Koba <473530+ybiquitous@users.noreply.github.com>
lib/standalone.js Outdated Show resolved Hide resolved
mattxwang and others added 2 commits April 19, 2023 21:58
Co-authored-by: Masafumi Koba <473530+ybiquitous@users.noreply.github.com>
@mattxwang
Copy link
Member Author

Apologies for the delay, got held up with some other work. I think I've addressed most of the code review comments!

To clarify, when you say

Anyway, not touching the existing props might be safe not to break users' linting.

Do you mean the minimal-invasive change (ex, right now - we follow the "default" behaviour", and I've added a little note in the docs)? Or, do you mean that I should explicitly add a subdirectory check?

@ybiquitous
Copy link
Member

I think we should add some actions for the new config props in this PR, but I don't think they are needed for the existing props.

Copy link
Member

@ybiquitous ybiquitous left a comment

Choose a reason for hiding this comment

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

Thanks, LGTM 👍🏼

@mattxwang
Copy link
Member Author

mattxwang commented Apr 20, 2023

Shall I hold off on merging this since #6795 is a patch?

(also, if you think it's appropriate, I could submit a follow-up issue to explore better ways to deal with the subdirectory issue you mentioned)

@mattxwang mattxwang linked an issue Apr 20, 2023 that may be closed by this pull request
@ybiquitous ybiquitous mentioned this pull request Apr 20, 2023
6 tasks
@ybiquitous
Copy link
Member

Let's merge this and include it in the next release. 👍🏼

I've commented on the reason: #6795 (comment)

@mattxwang mattxwang merged commit b089a42 into main Apr 20, 2023
14 checks passed
@mattxwang mattxwang deleted the add-remaining-boolean-config-objects branch April 20, 2023 22:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
2 participants