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

Add autofix to declaration-block-no-duplicate-properties #6296

Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions lib/rules/declaration-block-no-duplicate-properties/README.md
Expand Up @@ -11,6 +11,8 @@ a { color: pink; color: orange; }

This rule ignores variables (`$sass`, `@less`, `--custom-property`).

The [`fix` option](../../../docs/user-guide/usage/options.md#fix) can automatically fix all of the problems reported by this rule.

## Options

### `true`
Expand Down
Expand Up @@ -5,6 +5,7 @@ const { messages, ruleName } = require('..');
testRule({
ruleName,
config: [true],
fix: true,

accept: [
{
Expand Down Expand Up @@ -48,6 +49,7 @@ testRule({
reject: [
{
code: 'a { color: pink; color: orange }',
fixed: 'a { color: orange }',
message: messages.rejected('color'),
line: 1,
column: 18,
Expand All @@ -56,6 +58,7 @@ testRule({
},
{
code: 'a { cOlOr: pink; color: orange }',
fixed: 'a { color: orange }',
message: messages.rejected('color'),
line: 1,
column: 18,
Expand All @@ -64,6 +67,7 @@ testRule({
},
{
code: 'a { color: pink; cOlOr: orange }',
fixed: 'a { cOlOr: orange }',
message: messages.rejected('cOlOr'),
line: 1,
column: 18,
Expand All @@ -72,6 +76,7 @@ testRule({
},
{
code: 'a { cOlOr: pink; cOlOr: orange }',
fixed: 'a { cOlOr: orange }',
message: messages.rejected('cOlOr'),
line: 1,
column: 18,
Expand All @@ -80,6 +85,7 @@ testRule({
},
{
code: 'a { COLOR: pink; color: orange }',
fixed: 'a { color: orange }',
message: messages.rejected('color'),
line: 1,
column: 18,
Expand All @@ -88,6 +94,7 @@ testRule({
},
{
code: 'a { color: pink; COLOR: orange }',
fixed: 'a { COLOR: orange }',
message: messages.rejected('COLOR'),
line: 1,
column: 18,
Expand All @@ -96,6 +103,7 @@ testRule({
},
{
code: 'a { color: pink; background: orange; color: orange }',
fixed: 'a { background: orange; color: orange }',
message: messages.rejected('color'),
line: 1,
column: 38,
Expand All @@ -104,6 +112,7 @@ testRule({
},
{
code: 'a { color: pink; background: orange; background: pink; }',
fixed: 'a { color: pink; background: pink; }',
message: messages.rejected('background'),
line: 1,
column: 38,
Expand All @@ -112,6 +121,7 @@ testRule({
},
{
code: 'a { color: pink; { &:hover { color: orange; color: black; } } }',
fixed: 'a { color: pink; { &:hover { color: black; } } }',
description: 'spec nested',
message: messages.rejected('color'),
line: 1,
Expand All @@ -121,6 +131,7 @@ testRule({
},
{
code: 'a { color: pink; @media { color: orange; color: black; } }',
fixed: 'a { color: pink; @media { color: black; } }',
description: 'nested',
message: messages.rejected('color'),
line: 1,
Expand All @@ -130,6 +141,7 @@ testRule({
},
{
code: '@media { color: orange; .foo { color: black; color: white; } }',
fixed: '@media { color: orange; .foo { color: white; } }',
description: 'nested',
message: messages.rejected('color'),
line: 1,
Expand All @@ -139,6 +151,7 @@ testRule({
},
{
code: 'a { color: pink; @media { color: orange; &::before { color: black; color: white; } } }',
fixed: 'a { color: pink; @media { color: orange; &::before { color: white; } } }',
description: 'double nested',
message: messages.rejected('color'),
line: 1,
Expand All @@ -148,6 +161,7 @@ testRule({
},
{
code: 'a { color: pink; @media { color: orange; .foo { color: black; color: white; } } }',
fixed: 'a { color: pink; @media { color: orange; .foo { color: white; } } }',
description: 'double nested again',
message: messages.rejected('color'),
line: 1,
Expand All @@ -157,6 +171,7 @@ testRule({
},
{
code: 'a { -webkit-border-radius: 12px; -webkit-border-radius: 10px; }',
fixed: 'a { -webkit-border-radius: 10px; }',
message: messages.rejected('-webkit-border-radius'),
line: 1,
column: 34,
Expand All @@ -165,6 +180,7 @@ testRule({
},
{
code: 'a { -WEBKIT-border-radius: 12px; -webkit-BORDER-radius: 10px; }',
fixed: 'a { -webkit-BORDER-radius: 10px; }',
message: messages.rejected('-webkit-BORDER-radius'),
line: 1,
column: 34,
Expand All @@ -177,6 +193,7 @@ testRule({
testRule({
ruleName,
config: [true, { ignore: ['consecutive-duplicates'] }],
fix: true,

accept: [
{
Expand All @@ -196,18 +213,22 @@ testRule({
reject: [
{
code: 'p { font-size: 16px; font-weight: 400; font-size: 1rem; }',
fixed: 'p { font-weight: 400; font-size: 1rem; }',
message: messages.rejected('font-size'),
},
{
code: 'p { display: inline-block; font-size: 16px; font-weight: 400; font-size: 1rem; }',
fixed: 'p { display: inline-block; font-weight: 400; font-size: 1rem; }',
message: messages.rejected('font-size'),
},
{
code: 'p { font-size: 16px; font-weight: 400; font-size: 1rem; color: red; }',
fixed: 'p { font-weight: 400; font-size: 1rem; color: red; }',
message: messages.rejected('font-size'),
},
{
code: 'p { display: inline-block; font-size: 16px; font-weight: 400; font-size: 1rem; color: red; }',
fixed: 'p { display: inline-block; font-weight: 400; font-size: 1rem; color: red; }',
message: messages.rejected('font-size'),
},
],
Expand All @@ -216,16 +237,19 @@ testRule({
testRule({
ruleName,
config: [true, { ignore: ['consecutive-duplicates-with-different-values'] }],
fix: true,

accept: [{ code: 'p { font-size: 16px; font-size: 1rem; font-weight: 400; }' }],

reject: [
{
code: 'p { font-size: 16px; font-weight: 400; font-size: 1rem; }',
fixed: 'p { font-weight: 400; font-size: 1rem; }',
message: messages.rejected('font-size'),
},
{
code: 'p { font-size: 16px; font-size: 16px; font-weight: 400; }',
fixed: 'p { font-size: 16px; font-weight: 400; }',
message: messages.rejected('font-size'),
},
],
Expand All @@ -234,6 +258,7 @@ testRule({
testRule({
ruleName,
config: [true, { ignore: ['consecutive-duplicates-with-same-prefixless-values'] }],
fix: true,

accept: [
{
Expand All @@ -253,14 +278,17 @@ testRule({
reject: [
{
code: 'p { width: fit-content; height: 32px; width: -moz-fit-content; }',
fixed: 'p { height: 32px; width: -moz-fit-content; }',
message: messages.rejected('width'),
},
{
code: 'p { width: 100%; width: -moz-fit-content; height: 32px; }',
fixed: 'p { width: -moz-fit-content; height: 32px; }',
message: messages.rejected('width'),
},
{
code: 'p { width: -moz-fit-content; width: -moz-fit-content; }',
fixed: 'p { width: -moz-fit-content; }',
message: messages.rejected('width'),
},
],
Expand All @@ -269,6 +297,7 @@ testRule({
testRule({
ruleName,
config: [true, { ignoreProperties: ['color'] }],
fix: true,

accept: [
{
Expand All @@ -285,10 +314,12 @@ testRule({
reject: [
{
code: 'p { color: pink; background: orange; background: white; }',
fixed: 'p { color: pink; background: white; }',
message: messages.rejected('background'),
},
{
code: 'p { background: orange; color: pink; background: white; }',
fixed: 'p { color: pink; background: white; }',
message: messages.rejected('background'),
},
],
Expand All @@ -297,6 +328,7 @@ testRule({
testRule({
ruleName,
config: [true, { ignoreProperties: ['/background-/'] }],
fix: true,

accept: [
{
Expand All @@ -310,10 +342,12 @@ testRule({
reject: [
{
code: 'p { color: pink; background: orange; background: white; }',
fixed: 'p { color: pink; background: white; }',
message: messages.rejected('background'),
},
{
code: 'p { background: orange; color: pink; background: white; }',
fixed: 'p { color: pink; background: white; }',
message: messages.rejected('background'),
},
],
Expand All @@ -323,6 +357,7 @@ testRule({
ruleName,
config: [true],
customSyntax: 'postcss-html',
fix: true,

accept: [
{
Expand All @@ -342,14 +377,17 @@ testRule({
reject: [
{
code: '<a style="color: pink; color: orange"></a>',
fixed: '<a style="color: orange"></a>',
message: messages.rejected('color'),
},
{
code: '<style>p { color: pink; background: orange; background: white; }</style>',
fixed: '<style>p { color: pink; background: white; }</style>',
message: messages.rejected('background'),
},
{
code: '<a style="background: orange; color: pink; background: white;"></a>',
fixed: '<a style="color: pink; background: white;"></a>',
message: messages.rejected('background'),
},
],
Expand All @@ -360,6 +398,7 @@ testRule({
ruleName,
config: [true],
customSyntax: 'postcss-css-in-js',
fix: true,
ybiquitous marked this conversation as resolved.
Show resolved Hide resolved

accept: [
{
Expand All @@ -369,10 +408,13 @@ testRule({
reject: [
{
code: "import styled from 'styled-components';\nexport default styled.div` color: pink; color: orange; `;",
fixed:
"import styled from 'styled-components';\nexport default styled.div` color: orange; `;",
message: messages.rejected('color'),
},
{
code: "import styled from 'react-emotion'\nexport default styled.div` color: pink; color: orange; `;",
fixed: "import styled from 'react-emotion'\nexport default styled.div` color: orange; `;",
message: messages.rejected('color'),
},
],
Expand Down