Skip to content

Commit

Permalink
Merge branch 'main' into v15
Browse files Browse the repository at this point in the history
  • Loading branch information
ybiquitous committed Dec 23, 2022
2 parents ab146ee + cae5880 commit 68f9a64
Show file tree
Hide file tree
Showing 8 changed files with 100 additions and 8 deletions.
5 changes: 5 additions & 0 deletions .changeset/itchy-seas-care.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"stylelint": patch
---

Fixed: `function-no-unknown` false positives for `scroll`, `-webkit-gradient`, `color-stop`, `from`, and `to`
5 changes: 5 additions & 0 deletions .changeset/rude-hornets-begin.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"stylelint": patch
---

Fixed: `declaration-block-no-duplicate-properties` autofix for `!important`
3 changes: 2 additions & 1 deletion docs/developer-guide/syntaxes.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,9 @@ Existing syntaxes that you can use for reference include:
- [postcss-less](https://www.npmjs.com/package/postcss-less)
- [postcss-html](https://www.npmjs.com/package/postcss-html)
- [postcss-lit](https://www.npmjs.com/package/postcss-lit)
- [@linaria/postcss-linaria](https://www.npmjs.com/package/@linaria/postcss-linaria)

The latter two use `Document` nodes, [introduced in PostCSS 8.3](https://github.com/postcss/postcss/releases/tag/8.3.0) to support files with multiple roots.
The latter three use `Document` nodes, [introduced in PostCSS 8.3](https://github.com/postcss/postcss/releases/tag/8.3.0) to support files with multiple roots.

After publishing your custom syntax, we recommend creating a shared-config that:

Expand Down
1 change: 1 addition & 0 deletions docs/user-guide/get-started.md
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ Other PostCSS syntaxes known to be compatible with Stylelint include:
- [postcss-less](https://www.npmjs.com/package/postcss-less)
- [postcss-sass](https://www.npmjs.com/package/postcss-sass)
- [sugarss](https://www.npmjs.com/package/sugarss)
- [@linaria/postcss-linaria](https://www.npmjs.com/package/@linaria/postcss-linaria)

### Using more than one custom syntax

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,24 @@ testRule({
endLine: 1,
endColumn: 55,
},
{
code: 'a { color: red !important; color: blue; }',
fixed: 'a { color: red !important; }',
message: messages.rejected('color'),
line: 1,
column: 28,
endLine: 1,
endColumn: 33,
},
{
code: 'a { color: red !important; color: blue !important; }',
fixed: 'a { color: blue !important; }',
message: messages.rejected('color'),
line: 1,
column: 28,
endLine: 1,
endColumn: 33,
},
],
});

Expand Down Expand Up @@ -231,6 +249,11 @@ testRule({
fixed: 'p { display: inline-block; font-weight: 400; font-size: 1rem; color: red; }',
message: messages.rejected('font-size'),
},
{
code: 'p { font-size: 16px !important; font-weight: 400; font-size: 1rem; }',
fixed: 'p { font-size: 16px !important; font-weight: 400; }',
message: messages.rejected('font-size'),
},
],
});

Expand All @@ -252,6 +275,16 @@ testRule({
fixed: 'p { font-size: 16px; font-weight: 400; }',
message: messages.rejected('font-size'),
},
{
code: 'p { font-size: 16px !important; font-weight: 400; font-size: 1rem; }',
fixed: 'p { font-size: 16px !important; font-weight: 400; }',
message: messages.rejected('font-size'),
},
{
code: 'p { font-size: 16px; font-size: 16px !important; font-weight: 400; }',
fixed: 'p { font-size: 16px !important; font-weight: 400; }',
message: messages.rejected('font-size'),
},
],
});

Expand Down Expand Up @@ -291,6 +324,16 @@ testRule({
fixed: 'p { width: -moz-fit-content; }',
message: messages.rejected('width'),
},
{
code: 'p { width: -moz-fit-content; width: -moz-fit-content !important; }',
fixed: 'p { width: -moz-fit-content !important; }',
message: messages.rejected('width'),
},
{
code: 'p { width: 100% !important; width: -moz-fit-content; }',
fixed: 'p { width: 100% !important; }',
message: messages.rejected('width'),
},
],
});

Expand All @@ -309,6 +352,9 @@ testRule({
{
code: 'p { color: pink; background: orange; color: orange }',
},
{
code: 'p { color: pink; color: orange !important; }',
},
],

reject: [
Expand All @@ -322,6 +368,11 @@ testRule({
fixed: 'p { color: pink; background: white; }',
message: messages.rejected('background'),
},
{
code: 'p { background: orange; color: pink; background: white !important; }',
fixed: 'p { color: pink; background: white !important; }',
message: messages.rejected('background'),
},
],
});

Expand Down
26 changes: 20 additions & 6 deletions lib/rules/declaration-block-no-duplicate-properties/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ const rule = (primary, secondaryOptions, context) => {
const prop = decl.prop;
const lowerProp = decl.prop.toLowerCase();
const value = decl.value;
const important = decl.important;

if (!isStandardSyntaxProperty(prop)) {
return;
Expand All @@ -88,11 +89,19 @@ const rule = (primary, secondaryOptions, context) => {
const indexDuplicate = decls.findIndex((d) => d.prop.toLowerCase() === lowerProp);

if (indexDuplicate !== -1) {
const duplicateDecl = decls[indexDuplicate];
const duplicateValue = duplicateDecl ? duplicateDecl.value : '';
const duplicateImportant = duplicateDecl ? duplicateDecl.important : false;

if (ignoreDiffValues || ignorePrefixlessSameValues) {
// fails if duplicates are not consecutive
if (indexDuplicate !== decls.length - 1) {
if (context.fix) {
removePreviousDuplicate(decls, lowerProp);
if (!important && duplicateImportant) {
decl.remove();
} else {
removePreviousDuplicate(decls, lowerProp);
}

return;
}
Expand All @@ -108,14 +117,15 @@ const rule = (primary, secondaryOptions, context) => {
return;
}

const duplicateDecl = decls[indexDuplicate];
const duplicateValue = duplicateDecl ? duplicateDecl.value : '';

if (ignorePrefixlessSameValues) {
// fails if values of consecutive, unprefixed duplicates are equal
if (vendor.unprefixed(value) !== vendor.unprefixed(duplicateValue)) {
if (context.fix) {
removePreviousDuplicate(decls, lowerProp);
if (!important && duplicateImportant) {
decl.remove();
} else {
removePreviousDuplicate(decls, lowerProp);
}

return;
}
Expand Down Expand Up @@ -159,7 +169,11 @@ const rule = (primary, secondaryOptions, context) => {
}

if (context.fix) {
removePreviousDuplicate(decls, lowerProp);
if (!important && duplicateImportant) {
decl.remove();
} else {
removePreviousDuplicate(decls, lowerProp);
}

return;
}
Expand Down
6 changes: 6 additions & 0 deletions lib/rules/function-no-unknown/__tests__/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,12 @@ testRule({
{
code: 'a { transform: scale(0.5) translate(-100%, -100%); }',
},
{
code: 'a { animation-timeline: scroll(); }',
},
{
code: 'a { background: -webkit-gradient(linear, 0 50%, 0 100%, from(white), color-stop(0.5, yellow), to(red)); }',
},
],

reject: [
Expand Down
11 changes: 10 additions & 1 deletion lib/rules/function-no-unknown/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,16 @@ const rule = (primary, secondaryOptions) => {
return;
}

const functionsList = JSON.parse(fs.readFileSync(functionsListPath.toString(), 'utf8'));
const functionsList = [
...JSON.parse(fs.readFileSync(functionsListPath.toString(), 'utf8')),
// #5960
'-webkit-gradient',
'color-stop',
'from',
'to',
// #6537
'scroll',
];

root.walkDecls((decl) => {
const { value } = decl;
Expand Down

0 comments on commit 68f9a64

Please sign in to comment.