Skip to content

Commit

Permalink
Add failing test case for trailing comma bug in at-function-named-arg…
Browse files Browse the repository at this point in the history
…uments
  • Loading branch information
thibaudcolas committed Sep 23, 2018
1 parent 993f32e commit 6d53579
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/rules/at-function-named-arguments/__tests__/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,16 @@ testRule(rule, {
description:
"Always. Example: single argument is named in multiline function call."
},
{
code: `
.b {
border: reset(
$value: 40px,
);
}
`,
description: "Always. Example: trailing comma after last argument."
},
{
code: `
.b {
Expand Down
58 changes: 58 additions & 0 deletions src/utils/__tests__/parseFunctionArguments.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,53 @@ describe("groupByKeyValue", () => {
{ quote: "'", sourceIndex: 49, type: "string", value: "black" }
]
]);
expect(
groupByKeyValue([
{ type: "word", sourceIndex: 6, value: "$value" },
{
type: "div",
sourceIndex: 12,
value: ":",
before: "",
after: " "
},
{ type: "word", sourceIndex: 14, value: "40px" },
{
type: "div",
sourceIndex: 18,
value: ",",
before: "",
after: " "
},
{ type: "word", sourceIndex: 20, value: "$second-value" },
{
type: "div",
sourceIndex: 33,
value: ":",
before: "",
after: " "
},
{ type: "word", sourceIndex: 35, value: "10px" },
{
type: "div",
sourceIndex: 39,
value: ",",
before: "",
after: " "
}
])
).toEqual([
[
{ sourceIndex: 6, type: "word", value: "$value" },
{ after: " ", before: "", sourceIndex: 12, type: "div", value: ":" },
{ sourceIndex: 14, type: "word", value: "40px" }
],
[
{ sourceIndex: 20, type: "word", value: "$second-value" },
{ after: " ", before: "", sourceIndex: 33, type: "div", value: ":" },
{ sourceIndex: 35, type: "word", value: "10px" }
]
]);
});
});

Expand Down Expand Up @@ -151,6 +198,17 @@ describe("parseFunctionArguments", () => {
]);
});

it("parses trailing commas", () => {
expect(parseFunctionArguments("func(1, 2,)")).toEqual([
{
value: "1"
},
{
value: "2"
}
]);
});

it("parses variable as the key and a number as the value", () => {
expect(parseFunctionArguments("func($var: 1)")).toEqual([
{
Expand Down

0 comments on commit 6d53579

Please sign in to comment.