hudochenkov / stylelint-order

A plugin pack of order related linting rules for Stylelint.
MIT License
916 stars 61 forks source link

fix: fix the option validate logic of `rules/properties-alphabetical-… #158

Closed Arichy closed 2 years ago

Arichy commented 2 years ago

This PR is a bug fix. Here is my .stylelintrc.json

{
  "extends": ["stylelint-config-standard-scss"],
  "plugins": ["stylelint-order"],
  "rules": {
    "order/properties-alphabetical-order": false
  }
}

After I run stylelint, it threw the error Invalid Option: Invalid option "false" for rule "order/properties-alphabetical-order". I checked your code, found that stylelint.utils.validateOptions threw this (at rules/properties-alphabetical-order/index.js line14) It seems that you set the possible as Boolean, and if the option is a falsy value like false, stylelint will throw the error because the check result is false. So nobody can turn off the rule.

I think the following code may meet your expectation.

let validOptions = stylelint.utils.validateOptions(result, ruleName, {
    actual,
    possible: possible: (option) => typeof option === 'boolean',
});

if (!validOptoins) {
    return;
}

if (!actual) {
    return;
}
hudochenkov commented 2 years ago

It is not a bug. To turn off rule in Stylelint you need to set it's value to null:

{
  "extends": ["stylelint-config-standard-scss"],
  "plugins": ["stylelint-order"],
  "rules": {
    "order/properties-alphabetical-order": null
  }
}
Arichy commented 2 years ago

It is not a bug. To turn off rule in Stylelint you need to set it's value to null:

{
  "extends": ["stylelint-config-standard-scss"],
  "plugins": ["stylelint-order"],
  "rules": {
    "order/properties-alphabetical-order": null
  }
}

Ok, it works. But the doc of order/order/properties-alphabetical-order says the option is boolean. Maybe it's better to update the doc.

hudochenkov commented 2 years ago

@Arichy good idea.