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
Fix turning off autofix for sources containing scoped disable comments #4705
Conversation
This version of stylelint works correctly with my toolchain ( |
lib/lintSource.js
Outdated
* | ||
* @param {PostcssResult} postcssResult | ||
* @returns {boolean} | ||
*/ | ||
function isFixCompatible({ stylelint }) { | ||
// Check for issue #2643 | ||
if (stylelint.disabledRanges.all.length) return false; | ||
const hasUnscopedDisabledRanges = stylelint.disabledRanges.all.length > 0; | ||
const hasScopedDisabledRanges = Object.keys(stylelint.disabledRanges).length > 1; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think you can turn off autofix for each scoped rule.
Change the scope data to be passed to the third argument of ruleFunction
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think you can turn off autofix for each scoped rule.
Am I right in thinking that would give us a more granular workaround where autofix is turned off (for the entire source):
- for all rules, if the source contains unscoped disable comments
- for only the applicable rules, if the source only contains scoped disable comments
Would you mind pulling down the pull request and showing me what you mean? And is it something we should add to this pull request or a follow-up?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @jeddy3.
I want to fix it like this:
https://github.com/stylelint/stylelint/compare/issue-4704..issue-4704-2
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The color-hex-length rule does not autofix. However, the indent rule does autofix.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's a much better approach, thanks!
If possible, can you:
- use
require('common-tags').stripIndent
to indent theindentation
rule code snippets, like so:
.lint({
code: stripIndent`
/* stylelint-disable color-hex-length */
a {
color: #ffffff;
}
`,
- add a comment above the following:
// Next two conditionals are temporary measures until #2643 is resolved
isFileFixCompatible &&
!postcssResult.stylelint.disabledRanges[ruleName],
As their intent isn't immediately clear.
We should then merge your changes into this branch.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I fixed it and merged it into this branch.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Excellent. LGTM, thanks.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice solution!
I've added a commit to this pull request to update the docs to reflect the new behaviour introduced by this fix. I believe that autofix is now useful and stable for the majority of users. Those using scoped disable comments are only slightly inconvenienced when using the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I haven't realize how cool this PR until the last comment and document update. Amazing!
|
Closes #4704
We were only disabling autofix on files containing unscoped disable comments. This pull request disables it for both scoped and unscoped.