Skip to content

Commit

Permalink
Merge pull request #311 from kristerkari/bugfix/dollar-variable-colon…
Browse files Browse the repository at this point in the history
…-newline-after-default

dollar-variable-colon-newline-after: allow !default for multiline vars
  • Loading branch information
kristerkari committed Feb 22, 2019
2 parents 0a081a2 + 04d6b47 commit a1d6c3e
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 5 deletions.
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

0 comments on commit a1d6c3e

Please sign in to comment.