stylelint: declaration-block-no-redundant-longhand-properties

Ref: https://github.com/CSSLint/csslint/wiki/Require-shorthand-properties Ref: https://github.com/CSSLint/csslint/issues/668

I don’t know best name for rule 😄

Throw error if we use all 4 values, also throw errors if we use top and left, top and left and right. Example:

a {
  padding-top: 1px;
  padding-right: 2px;
  padding-bottom: 3px;
  padding-left: 4px; /* Throw error, need `padding: 1px 2px 3px 4px;` */
}
a {
  padding-top: 5px;
  padding-right: 5px;
  padding-bottom: 5px; /* Throw error, need `padding: 1px 2px 3px;` */
}
a {
  padding-top: 5px;
  padding-right: 5px; /* Throw error, need `padding: 1px 2px;` */
}

Also add option minProperties(maybe rename) to control how many properties throw errors.

About this issue

  • Original URL
  • State: closed
  • Created 8 years ago
  • Comments: 19 (19 by maintainers)

Most upvoted comments

@jeddy3 for compat with csslint we should add option ignoreProperties, because csslint support this only for padding and margin

i agree only throw errors on 4 properties,

Phew, I’m glad we got there in the end 😃 @davidtheclark Thanks for helping to clarify!

we need name for rule

declaration-block-no-redundant-longhand-properties?

  • declaration-block because, like declaration-block-no-duplicate-properties, declaration-block-no-ignored-properties and declaration-block-no-shorthand-property-override, it’s scoped to declaration blocks.
  • redundant because that’s aligned with shorthand-property-no-redundant-values.
  • longhand-properties, well, because that’s the thing that’s redundant.

I guess all the shorthand properties ought to be caught by this rule (e.g. font, border etc), rather than just margin and padding.

Thinking about this more, I even wonder if there should be a declaration-no-shorthand-property rule. I’d use it.

Ha, I know what you mean. The implicit setting of values by shorthand properties can be a killer. including for properties like font. Anyhow, lets create a separate issue for that discussion though 😃

sorry, tired 😭

Ha, no problem! I think that quality of shorthand properties stands out to me because it’s bitten me so many times.