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 selector-list-comma-space-before #3447

Merged
merged 3 commits into from
Jul 15, 2018
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
2 changes: 1 addition & 1 deletion docs/user-guide/rules.md
Original file line number Diff line number Diff line change
Expand Up @@ -311,7 +311,7 @@ Here are all the rules within stylelint, grouped first [by category](../../VISIO
- [`selector-list-comma-newline-after`](../../lib/rules/selector-list-comma-newline-after/README.md): Require a newline or disallow whitespace after the commas of selector lists.
- [`selector-list-comma-newline-before`](../../lib/rules/selector-list-comma-newline-before/README.md): Require a newline or disallow whitespace before the commas of selector lists.
- [`selector-list-comma-space-after`](../../lib/rules/selector-list-comma-space-after/README.md): Require a single space or disallow whitespace after the commas of selector lists.
- [`selector-list-comma-space-before`](../../lib/rules/selector-list-comma-space-before/README.md): Require a single space or disallow whitespace before the commas of selector lists.
- [`selector-list-comma-space-before`](../../lib/rules/selector-list-comma-space-before/README.md): Require a single space or disallow whitespace before the commas of selector lists (Autofixable).

#### Rule

Expand Down
22 changes: 22 additions & 0 deletions lib/rules/selector-list-comma-newline-before/__tests__/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,10 @@ testRule(rule, {
{
code: "html { --custom-property-set: {} }",
description: "custom property set in selector"
},
{
code: "a/*comment,comment*/\n,/*comment*/b {}",
description: "comment"
}
],

Expand Down Expand Up @@ -117,6 +121,13 @@ testRule(rule, {
message: messages.expectedBefore(),
line: 2,
column: 3
},
{
code: "a/*comment*/,/*comment*/b {}",
description: "comment",
message: messages.expectedBefore(),
line: 1,
column: 13
}
]
});
Expand Down Expand Up @@ -198,6 +209,10 @@ testRule(rule, {
{
code: ":not(:hover, :focus) {}",
description: "comma inside :not()"
},
{
code: "a/*comment\n,comment*/,/*comment*/b {\n}",
description: "comment"
}
],

Expand All @@ -220,6 +235,13 @@ testRule(rule, {
message: messages.rejectedBeforeMultiLine(),
line: 2,
column: 3
},
{
code: "a/*comment*/\n,/*comment*/b {\n}",
description: "comment",
message: messages.rejectedBeforeMultiLine(),
line: 2,
column: 1
}
]
});
20 changes: 20 additions & 0 deletions lib/rules/selector-list-comma-space-after/__tests__/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,10 @@ testRule(rule, {
{
code: "html { --custom-property-set: {} }",
description: "custom property set in selector"
},
{
code: "a/*comment,comment*/, /*comment*/b {}",
description: "comment"
}
],

Expand Down Expand Up @@ -97,6 +101,12 @@ testRule(rule, {
message: messages.expectedAfter(),
line: 1,
column: 5
},
{
code: "a/*comment*/,/*comment*/b {}",
message: messages.expectedAfter(),
line: 1,
column: 13
}
]
});
Expand Down Expand Up @@ -133,6 +143,10 @@ testRule(rule, {
{
code: ":not(:hover, :focus) {}",
description: "comma inside :not()"
},
{
code: "a/*comment, comment*/,/*comment*/b {}",
description: "comment"
}
],

Expand Down Expand Up @@ -179,6 +193,12 @@ testRule(rule, {
message: messages.rejectedAfter(),
line: 1,
column: 4
},
{
code: "a/*comment*/, /*comment*/b {}",
message: messages.rejectedAfter(),
line: 1,
column: 13
}
]
});
Expand Down
2 changes: 2 additions & 0 deletions lib/rules/selector-list-comma-space-before/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ Require a single space or disallow whitespace before the commas of selector list
* The space before this comma */
```

The `--fix` option on the [command line](../../../docs/user-guide/cli.md#autofixing-errors) can automatically fix all of the problems reported by this rule.

## Options

`string`: `"always"|"never"|"always-single-line"|"never-single-line"`
Expand Down
67 changes: 67 additions & 0 deletions lib/rules/selector-list-comma-space-before/__tests__/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ const { messages, ruleName } = rule;
testRule(rule, {
ruleName,
config: ["always"],
fix: true,

accept: [
{
Expand Down Expand Up @@ -51,59 +52,85 @@ testRule(rule, {
{
code: "html { --custom-property-set: {} }",
description: "custom property set in selector"
},
{
code: "a/*comment,comment*/ ,/*comment*/b {}",
description: "comment"
}
],

reject: [
{
code: "a,b {}",
fixed: "a ,b {}",
message: messages.expectedBefore(),
line: 1,
column: 2
},
{
code: "a ,b {}",
fixed: "a ,b {}",
message: messages.expectedBefore(),
line: 1,
column: 4
},
{
code: "a\n,b {}",
fixed: "a ,b {}",
message: messages.expectedBefore(),
line: 2,
column: 1
},
{
code: "a\r\n,b {}",
fixed: "a ,b {}",
description: "CRLF",
message: messages.expectedBefore(),
line: 2,
column: 1
},
{
code: "a\t,b {}",
fixed: "a ,b {}",
message: messages.expectedBefore(),
line: 1,
column: 3
},
{
code: "a ,b,c {}",
fixed: "a ,b ,c {}",
message: messages.expectedBefore(),
line: 1,
column: 5
},
{
code: "a ,b ,c {}",
fixed: "a ,b ,c {}",
message: messages.expectedBefore(),
line: 1,
column: 7
},
{
code: "a,b,c {}",
fixed: "a ,b ,c {}",
message: messages.expectedBefore(),
line: 1,
column: 2
},
{
code: "a/*comment*/,/*comment*/b {}",
fixed: "a/*comment*/ ,/*comment*/b {}",
message: messages.expectedBefore(),
line: 1,
column: 13
}
]
});

testRule(rule, {
ruleName,
config: ["never"],
fix: true,

accept: [
{
Expand Down Expand Up @@ -133,59 +160,78 @@ testRule(rule, {
{
code: ":not(:hover , :focus) {}",
description: "comma inside :not()"
},
{
code: "a/*comment ,comment*/,/*comment*/b {}",
description: "comment"
}
],

reject: [
{
code: "a ,b {}",
fixed: "a,b {}",
message: messages.rejectedBefore(),
line: 1,
column: 3
},
{
code: "a ,b {}",
fixed: "a,b {}",
message: messages.rejectedBefore(),
line: 1,
column: 4
},
{
code: "a\n,b {}",
fixed: "a,b {}",
message: messages.rejectedBefore(),
line: 2,
column: 1
},
{
code: "a\r\n,b {}",
fixed: "a,b {}",
description: "CRLF",
message: messages.rejectedBefore(),
line: 2,
column: 1
},
{
code: "a\t,b {}",
fixed: "a,b {}",
message: messages.rejectedBefore(),
line: 1,
column: 3
},
{
code: "a,b ,c {}",
fixed: "a,b,c {}",
message: messages.rejectedBefore(),
line: 1,
column: 5
},
{
code: "a,b ,c {}",
fixed: "a,b,c {}",
message: messages.rejectedBefore(),
line: 1,
column: 6
},
{
code: "a/*comment*/ ,/*comment*/b {}",
fixed: "a/*comment*/,/*comment*/b {}",
message: messages.rejectedBefore(),
line: 1,
column: 14
}
]
});

testRule(rule, {
ruleName,
config: ["always-single-line"],
fix: true,

accept: [
{
Expand All @@ -204,29 +250,40 @@ testRule(rule, {
reject: [
{
code: "a,b {}",
fixed: "a ,b {}",
message: messages.expectedBeforeSingleLine(),
line: 1,
column: 2
},
{
code: "a,b {\n}",
fixed: "a ,b {\n}",
message: messages.expectedBeforeSingleLine(),
line: 1,
column: 2
},
{
code: "a,b {\r\n}",
fixed: "a ,b {\r\n}",
description: "CRLF",
message: messages.expectedBeforeSingleLine(),
line: 1,
column: 2
},
{
code: "a/*comment*/,/*comment*/b {\n}",
fixed: "a/*comment*/ ,/*comment*/b {\n}",
message: messages.expectedBeforeSingleLine(),
line: 1,
column: 13
}
]
});

testRule(rule, {
ruleName,
config: ["never-single-line"],
fix: true,

accept: [
{
Expand All @@ -245,22 +302,32 @@ testRule(rule, {
reject: [
{
code: "a ,b {}",
fixed: "a,b {}",
message: messages.rejectedBeforeSingleLine(),
line: 1,
column: 3
},
{
code: "a ,b {\n}",
fixed: "a,b {\n}",
message: messages.rejectedBeforeSingleLine(),
line: 1,
column: 3
},
{
code: "a ,b {\r\n}",
fixed: "a,b {\r\n}",
description: "CRLF",
message: messages.rejectedBeforeSingleLine(),
line: 1,
column: 3
},
{
code: "a/*comment*/ ,/*comment*/b {\n}",
fixed: "a/*comment*/,/*comment*/b {\n}",
message: messages.rejectedBeforeSingleLine(),
line: 1,
column: 14
}
]
});
Loading