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 with basic keywords #6748

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/lovely-ligers-sip.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"stylelint": patch
---

Fixed: `declaration-block-no-redundant-longhand-properties` with basic keywords
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ a {
}
```

This rule will only complain if you've used the longhand equivalent of _all_ the properties that the shorthand will set and if their values are not `inherit`.
This rule will only complain if you've used the longhand equivalent of _all_ the properties that the shorthand will set and if their values are not [CSS-wide keywords](https://www.w3.org/TR/css-values/#common-keywords) like `initial`, `inherit` etc.

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,14 @@ testRule({
{
code: 'a { top: 0; right: 0; bottom: 0; }',
},
{
code: 'a { top: 0; right: 0; bottom: initial; left: 0; }',
description: 'contains basic keyword (initial)',
},
{
code: 'a { margin-top: 0; margin-right: 0; margin-bottom: unset; margin-left: 0; }',
description: 'contains basic keyword (unset)',
},
],

reject: [
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
'use strict';

const arrayEqual = require('../../utils/arrayEqual');
const { basicKeywords } = require('../../reference/keywords');
const eachDeclarationBlock = require('../../utils/eachDeclarationBlock');
const optionsMatches = require('../../utils/optionsMatches');
const report = require('../../utils/report');
Expand All @@ -21,8 +22,6 @@ const meta = {
fixable: true,
};

const IGNORED_VALUES = new Set(['inherit']);

/** @typedef {import('postcss').Declaration} Declaration */

/** @type {import('stylelint').Rule} */
Expand Down Expand Up @@ -68,7 +67,8 @@ const rule = (primary, secondaryOptions, context) => {
const longhandDeclarationNodes = new Map();

eachDecl((decl) => {
if (IGNORED_VALUES.has(decl.value)) {
// basic keywords are not allowed in shorthand properties
if (basicKeywords.has(decl.value)) {
return;
}

Expand Down