eslint-plugin-vue icon indicating copy to clipboard operation
eslint-plugin-vue copied to clipboard

Prefer boolean prop usage at first

Open jd-solanki opened this issue 3 years ago • 3 comments

Please describe what the rule should do: This rule is related to this rule. In the existing rule we are enforcing defining the boolean rules first but in this rule, we can enforce using boolean props first.

What category should the rule belong to?

[x] Enforces code style (layout) [ ] Warns about a potential error (problem) [ ] Suggests an alternate way of doing something (suggestion) [ ] Other (please specify:)

Provide 2-3 code examples that this rule should warn about:

   <!-- GOOD -->
    <v-btn
      flat
      color="success"
    >
      Success
    </v-btn>

   <!-- BAD -->
    <v-btn
      color="info"
      flat
    >
      Info
    </v-btn>

   <!-- GOOD -->
    <v-btn
      flat
      variant="outilned"
      color="success"
      rounded="pill"
    >
      Success
    </v-btn>

Additional context Placing boolean prop usage on top makes it easy to read the component props. 👀

jd-solanki avatar Apr 26 '22 07:04 jd-solanki

That would collide with the Style Guide and the existing vue/attributes-order rule. (See also the vue/prefer-true-attribute-shorthand rule).

Maybe it would be possible to add a new option SHORTHAND_BOOL_ATTR to the vue/attributes-order rule. But the logic should not change for existing configurations:

  • If SHORTHAND_BOOL_ATTR is present in the config, OTHER_ATTR would only apply to non-shorthand attributes.
  • If SHORTHAND_BOOL_ATTR is not present in the config, OTHER_ATTR would apply to both shorthand and non-shorthand attributes (like it is now).

FloEdelmann avatar Apr 26 '22 11:04 FloEdelmann

SHORTHAND_BOOL_ATTR looks good. ❤️

jd-solanki avatar Apr 26 '22 11:04 jd-solanki

See also #1728. That issue should probably be implemented together with this one.

FloEdelmann avatar May 30 '22 07:05 FloEdelmann