diff --git a/src/rules/dollar-variable-colon-newline-after/__tests__/index.js b/src/rules/dollar-variable-colon-newline-after/__tests__/index.js index 42d54911..f6ee2fd7 100644 --- a/src/rules/dollar-variable-colon-newline-after/__tests__/index.js +++ b/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, @@ -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: ( @@ -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" } ], @@ -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( @@ -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: ( diff --git a/src/rules/dollar-variable-colon-newline-after/index.js b/src/rules/dollar-variable-colon-newline-after/index.js index 85d1806e..b73cbb2f 100644 --- a/src/rules/dollar-variable-colon-newline-after/index.js +++ b/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"); @@ -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) {