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

Fix false positives for values wrapped in parentheses in declaration-empty-line-before #5680

Merged
merged 2 commits into from Nov 2, 2021
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
13 changes: 13 additions & 0 deletions lib/utils/__tests__/isStandardSyntaxDeclaration.test.js
Expand Up @@ -138,17 +138,30 @@ describe('isStandardSyntaxDeclaration', () => {
it('less map', () => {
expect(isStandardSyntaxDeclaration(lessDecl('@map: { key: value; }'))).toBe(false);
});

it('scss map declaration', () => {
expect(isStandardSyntaxDeclaration(scssDecl('$foo: (key: value, key2: value2)'))).toBe(false);
});

it('scss map declaration with quotes', () => {
expect(isStandardSyntaxDeclaration(scssDecl('$foo: ("key": value, "key2": value2)'))).toBe(
false,
);
});

it('scss list declaration', () => {
expect(isStandardSyntaxDeclaration(scssDecl('$foo: (value, value2)'))).toBe(false);
});

it('scss pure value in parentheses', () => {
expect(isStandardSyntaxDeclaration(scssDecl('a { height: (0) }'))).toBe(true);
});

it('scss complex value in parentheses', () => {
expect(isStandardSyntaxDeclaration(scssDecl('a { height: (3px + 5px) * (2px + 4px) }'))).toBe(
true,
);
});
ek68794998 marked this conversation as resolved.
Show resolved Hide resolved
});

function decl(css, parser = postcss) {
Expand Down
8 changes: 1 addition & 7 deletions lib/utils/isStandardSyntaxDeclaration.js
Expand Up @@ -18,7 +18,6 @@ function isStandardSyntaxLang(lang) {
module.exports = function (decl) {
const prop = decl.prop;
const parent = decl.parent;
const value = decl.value;

// Declarations belong in a declaration block or standard CSS source
if (
Expand All @@ -32,16 +31,11 @@ module.exports = function (decl) {
return false;
}

// SCSS var
// SCSS var; covers map and list declarations
if (isScssVariable(prop)) {
return false;
}

// SCSS map and list declarations
if (value.startsWith('(') && value.endsWith(')')) {
return false;
}

// Less var (e.g. @var: x), but exclude variable interpolation (e.g. @{var})
if (prop[0] === '@' && prop[1] !== '{') {
return false;
Expand Down