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

dollar-variable-colon-newline-after: allow !default for multiline vars #311

Merged
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
50 changes: 49 additions & 1 deletion src/rules/dollar-variable-colon-newline-after/__tests__/index.js
@@ -1,4 +1,4 @@
import rule, { ruleName, messages } from "..";
import rule, { messages, ruleName } from "..";

testRule(rule, {
ruleName,
Expand Down Expand Up @@ -51,6 +51,24 @@ testRule(rule, {
`,
description: "always: should ignore Sass maps"
},
{
code: `
$map: (
foo: 1,
bar: 2,
) !default;
`,
description: "always: should ignore Sass maps that use !default"
},
{
code: `
$map: (
foo: 1,
bar: 2,
)!default;
`,
description: "always: should ignore Sass maps that use !default"
},
{
code: `
$var: (
Expand All @@ -60,6 +78,16 @@ testRule(rule, {
);
`,
description: "always: should ignore multiline variables"
},
{
code: `
$var: (
1 +
2 +
3
) !default;
`,
description: "always: should ignore multiline variables that use !default"
}
],

Expand Down Expand Up @@ -279,6 +307,16 @@ testRule(rule, {
description:
"always-multi-line: should allow Sass map using newline after colon"
},
{
code: `
$map:\n(
foo: 1,
bar: 2,
) !default;
`,
description:
"always-multi-line: should allow Sass map that use !default using newline after colon"
},
{
code: `
$var:\r\n(
Expand All @@ -300,6 +338,16 @@ testRule(rule, {
description:
"always-multi-line: should allow using Sass map without a newline"
},
{
code: `
$map: (
foo: 1,
bar: 2,
) !default;
`,
description:
"always-multi-line: should allow using Sass map that use !default without a newline"
},
{
code: `
$var: (
Expand Down
11 changes: 7 additions & 4 deletions src/rules/dollar-variable-colon-newline-after/index.js
@@ -1,11 +1,11 @@
import { isBoolean } from "lodash";
import { utils } from "stylelint";
import {
declarationValueIndex,
isSingleLineString,
namespace,
whitespaceChecker
} from "../../utils";
import { utils } from "stylelint";
import { isBoolean } from "lodash";

export const ruleName = namespace("dollar-variable-colon-newline-after");

Expand Down Expand Up @@ -47,9 +47,12 @@ export default function(expectation, options, context) {
}

const value = decl.value.trim();
const startsWithParen = value[0] === "(";
const endsWithParen = value[value.length - 1] === ")";
const endsWithDefault = /\)\s*!default$/.test(value);
const isMultilineVarWithParens =
value[0] === "(" &&
value[value.length - 1] === ")" &&
startsWithParen &&
(endsWithParen || endsWithDefault) &&
!isSingleLineString(value);

if (isMultilineVarWithParens) {
Expand Down