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 support to use --fix with checkAgainstRule #6465

Closed
aaronccasanova opened this issue Nov 10, 2022 · 3 comments · Fixed by #6466
Closed

Add support to use --fix with checkAgainstRule #6465

aaronccasanova opened this issue Nov 10, 2022 · 3 comments · Fixed by #6466
Labels
status: ready to implement is ready to be worked on by someone type: enhancement a new feature that isn't related to rules

Comments

@aaronccasanova
Copy link
Member

What is the problem you're trying to solve?

The --fix option does not work with the checkAgainstRule utility:

stylelint.utils.checkAgainstRule(
  {
    ruleName: 'length-zero-no-unit'
    ruleSettings: true,
    root,
  },
  (warning) => { /* Don't report if the problem can be automatically fixed */ },
)

What solution would you like to see?

I would like to be able to pass through the context.fix option to checkAgainstRule:

module.exports = createPlugin(
  'custom/length-zero-no-unit',
  (primary, secondary, context) => (root) => {
    stylelint.utils.checkAgainstRule(
      {
        ruleName: 'length-zero-no-unit'
        ruleSettings: true,
        fix: context.fix,
        root,
      },
      (warning) => { /* Don't report if the problem can be automatically fixed */ },
    )
  },
})

My team currently has this behavior patched with the following updates to checkAgainstRule:

rule(settings[0], /** @type {O} */ (settings[1]), {})(options.root, tmpPostcssResult);

- rule(settings[0], /** @type {O} */ (settings[1]), {})(options.root, tmpPostcssResult);
+ rule(settings[0], /** @type {O} */ (settings[1]), {fix: options.fix})(options.root, tmpPostcssResult);
@ybiquitous ybiquitous added the status: needs discussion triage needs further discussion label Nov 11, 2022
@ybiquitous
Copy link
Member

@aaronccasanova Thanks for the proposal. I agree with passing the fix option to checkAgainstRule(). Furthermore, giving a context object seems to make sense instead of fix. What do you think?

@aaronccasanova
Copy link
Member Author

aaronccasanova commented Nov 11, 2022

Great idea, passing through the entire PluginContext is definitely more future facing 👍

@ybiquitous ybiquitous added status: ready to implement is ready to be worked on by someone type: enhancement a new feature that isn't related to rules and removed status: needs discussion triage needs further discussion labels Nov 11, 2022
@ybiquitous
Copy link
Member

@aaronccasanova Thanks for the feedback. Let's add the context parameter to checkAgainstRule.

I've labeled the issue as ready to implement. Please consider contributing if you have time.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: ready to implement is ready to be worked on by someone type: enhancement a new feature that isn't related to rules
Development

Successfully merging a pull request may close this issue.

2 participants