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

Fix declaration-block-no-redundant-longhand-properties false negatives for *-block and *-inline logical properties #7208

Merged
merged 6 commits into from
Oct 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/moody-pugs-clean.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"stylelint": patch
---

Fixed: `declaration-block-no-redundant-longhand-properties` false negatives for `*-block` and `*-inline` logical properties
98 changes: 98 additions & 0 deletions lib/reference/properties.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,15 @@ const longhandSubPropertiesOfShorthandProperties = new Map([
'border-left-color',
]),
],
[
'border-block',
new Set([
// prettier-ignore
'border-block-width',
'border-block-style',
'border-block-color',
]),
],
[
'border-block-end',
new Set([
Expand Down Expand Up @@ -110,6 +119,15 @@ const longhandSubPropertiesOfShorthandProperties = new Map([
'border-image-repeat',
]),
],
[
'border-inline',
new Set([
// prettier-ignore
'border-inline-width',
'border-inline-style',
'border-inline-color',
]),
],
[
'border-inline-end',
new Set([
Expand Down Expand Up @@ -299,6 +317,22 @@ const longhandSubPropertiesOfShorthandProperties = new Map([
'left',
]),
],
[
'inset-block',
new Set([
// prettier-ignore
'inset-block-start',
'inset-block-end',
]),
],
[
'inset-inline',
new Set([
// prettier-ignore
'inset-inline-start',
'inset-inline-end',
]),
],
[
'list-style',
new Set([
Expand All @@ -318,6 +352,22 @@ const longhandSubPropertiesOfShorthandProperties = new Map([
'margin-left',
]),
],
[
'margin-block',
new Set([
// prettier-ignore
'margin-block-start',
'margin-block-end',
]),
],
[
'margin-inline',
new Set([
// prettier-ignore
'margin-inline-start',
'margin-inline-end',
]),
],
[
'mask',
new Set([
Expand Down Expand Up @@ -351,6 +401,54 @@ const longhandSubPropertiesOfShorthandProperties = new Map([
'padding-left',
]),
],
[
'padding-block',
new Set([
// prettier-ignore
'padding-block-start',
'padding-block-end',
]),
],
[
'padding-inline',
new Set([
// prettier-ignore
'padding-inline-start',
'padding-inline-end',
]),
],
[
'scroll-margin-block',
new Set([
// prettier-ignore
'scroll-margin-block-start',
'scroll-margin-block-end',
]),
],
[
'scroll-margin-inline',
new Set([
// prettier-ignore
'scroll-margin-inline-start',
'scroll-margin-inline-end',
]),
],
[
'scroll-padding-block',
new Set([
// prettier-ignore
'scroll-padding-block-start',
'scroll-padding-block-end',
]),
],
[
'scroll-padding-inline',
new Set([
// prettier-ignore
'scroll-padding-inline-start',
'scroll-padding-inline-end',
]),
],
[
'text-decoration',
new Set([
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,42 +26,54 @@ This rule will only complain if you've used the longhand equivalent of _all_ the

This rule complains when the following shorthand properties can be used:

- `margin`
- `padding`
- `inset`
- `animation`
- `background`
- `font`
- `border`
- `border-top`
- `border-bottom`
- `border-left`
- `border-right`
- `border-width`
- `border-style`
- `border-color`
- `list-style`
- `border-radius`
- `transition`
- `animation`
- `border-block`
- `border-block-end`
- `border-block-start`
- `border-bottom`
- `border-color`
- `border-image`
- `border-inline`
- `border-inline-end`
- `border-inline-start`
- `border-left`
- `border-radius`
- `border-right`
- `border-style`
- `border-top`
- `border-width`
- `column-rule`
- `columns`
- `flex`
- `flex-flow`
- `font`
- `grid`
- `grid-area`
- `grid-column`
- `grid-gap`
- `grid-row`
- `grid-template`
- `inset`
- `inset-block`
- `inset-inline`
- `list-style`
- `margin`
- `margin-block`
- `margin-inline`
- `mask`
- `outline`
- `padding`
- `padding-block`
- `padding-inline`
- `scroll-margin-block`
- `scroll-margin-inline`
- `scroll-padding-block`
- `scroll-padding-inline`
- `text-decoration`
- `text-emphasis`
- `mask`
- `transition`

**Please note** that properties are considered to be redundant if they may be written shorthand according to the specification, **regardless of the behavior of any individual browser**. For example, due to Internet Explorer's implementation of Flexbox, [it may not be possible to use the shorthand property `flex`](https://github.com/philipwalton/flexbugs#flexbug-8), but the longhand form is still considered a problem.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,78 @@ testRule({
description: 'explicit border-width test',
message: messages.expected('border-width'),
},
{
code: 'a { inset-block-start: 1px; inset-block-end: 2px; }',
fixed: 'a { inset-block: 1px 2px; }',
description: 'explicit inset-block test',
message: messages.expected('inset-block'),
},
{
code: 'a { inset-inline-start: 1px; inset-inline-end: 2px; }',
fixed: 'a { inset-inline: 1px 2px; }',
description: 'explicit inset-inline test',
message: messages.expected('inset-inline'),
},
{
code: 'a { margin-block-start: 1px; margin-block-end: 2px; }',
fixed: 'a { margin-block: 1px 2px; }',
description: 'explicit margin-block test',
message: messages.expected('margin-block'),
},
{
code: 'a { margin-inline-start: 1px; margin-inline-end: 2px; }',
fixed: 'a { margin-inline: 1px 2px; }',
description: 'explicit margin-inline test',
message: messages.expected('margin-inline'),
},
{
code: 'a { padding-block-start: 1px; padding-block-end: 2px; }',
fixed: 'a { padding-block: 1px 2px; }',
description: 'explicit padding-block test',
message: messages.expected('padding-block'),
},
{
code: 'a { padding-inline-start: 1px; padding-inline-end: 2px; }',
fixed: 'a { padding-inline: 1px 2px; }',
description: 'explicit padding-inline test',
message: messages.expected('padding-inline'),
},
{
code: 'a { scroll-margin-block-start: 1px; scroll-margin-block-end: 2px; }',
fixed: 'a { scroll-margin-block: 1px 2px; }',
description: 'explicit scroll-margin-block test',
message: messages.expected('scroll-margin-block'),
},
{
code: 'a { scroll-margin-inline-start: 1px; scroll-margin-inline-end: 2px; }',
fixed: 'a { scroll-margin-inline: 1px 2px; }',
description: 'explicit scroll-margin-inline test',
message: messages.expected('scroll-margin-inline'),
},
{
code: 'a { scroll-padding-block-start: 1px; scroll-padding-block-end: 2px; }',
fixed: 'a { scroll-padding-block: 1px 2px; }',
description: 'explicit scroll-padding-block test',
message: messages.expected('scroll-padding-block'),
},
{
code: 'a { scroll-padding-inline-start: 1px; scroll-padding-inline-end: 2px; }',
fixed: 'a { scroll-padding-inline: 1px 2px; }',
description: 'explicit scroll-padding-inline test',
message: messages.expected('scroll-padding-inline'),
},
{
code: 'a { border-block-color: blue; border-block-style: dashed; border-block-width: medium; }',
fixed: 'a { border-block: medium dashed blue; }',
description: 'explicit border-block test',
message: messages.expected('border-block'),
},
{
code: 'a { border-inline-color: blue; border-inline-style: dashed; border-inline-width: medium; }',
fixed: 'a { border-inline: medium dashed blue; }',
description: 'explicit border-inline test',
message: messages.expected('border-inline'),
},
],
});

Expand Down
14 changes: 14 additions & 0 deletions types/stylelint/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -440,8 +440,12 @@ declare namespace stylelint {
| 'animation'
| 'background'
| 'border'
| 'border-block'
| 'border-block-end'
| 'border-block-start'
| 'border-inline'
| 'border-inline-end'
| 'border-inline-start'
| 'border-bottom'
| 'border-color'
| 'border-image'
Expand All @@ -465,11 +469,21 @@ declare namespace stylelint {
| 'grid-row'
| 'grid-template'
| 'inset'
| 'inset-block'
| 'inset-inline'
| 'list-style'
| 'margin'
| 'margin-block'
| 'margin-inline'
| 'mask'
| 'outline'
| 'padding'
| 'padding-block'
| 'padding-inline'
| 'scroll-margin-block'
| 'scroll-margin-inline'
| 'scroll-padding-block'
| 'scroll-padding-inline'
| 'text-decoration'
| 'text-emphasis'
| 'transition';
Expand Down