Skip to content

Commit

Permalink
Fix false positives for inlines styles in declaration-empty-line-befo…
Browse files Browse the repository at this point in the history
…re (#4726)
  • Loading branch information
mattxwang committed May 12, 2020
1 parent 900649d commit 269e3bf
Show file tree
Hide file tree
Showing 2 changed files with 112 additions and 0 deletions.
106 changes: 106 additions & 0 deletions lib/rules/declaration-empty-line-before/__tests__/index.js
@@ -1,5 +1,7 @@
'use strict';

const stripIndent = require('common-tags').stripIndent;

const { messages, ruleName } = require('..');

testRule({
Expand Down Expand Up @@ -897,3 +899,107 @@ testRule({
},
],
});

testRule(rule, {
ruleName,
config: ['always'],
syntax: 'html',
fix: true,
accept: [
{
code: `<span style="color: red;"></span>`,
description: 'Single-line HTML style tag',
},
{
code: stripIndent`
<span
style="
color: red;
font-size: 1rem;
">
Text
</span>`,
description: 'Multi-line HTML style attribute with two declarations',
},
],
reject: [
{
code: stripIndent`
<span style="color: red;font-size: 16px;"></span>
<style>
color: red;
font-size: 16px;
</style>`,
fixed: stripIndent`
<span style="color: red;
font-size: 16px;"></span>
<style>
color: red;
font-size: 16px;
</style>`,
description: 'flush declaration in style tag',
warnings: [
{
message: messages.expected,
line: 1,
column: 25,
},
{
message: messages.expected,
line: 4,
column: 2,
},
],
},
],
});

testRule(rule, {
ruleName,
config: ['always', { ignore: ['inside-single-line-block'] }],
syntax: 'html',
fix: true,

accept: [
{
code: `<span style="color: red; font-size: 1rem;"></span>`,
description: 'Single-line HTML style attribute with two declarations',
},
{
code: stripIndent`
<span
style="
color: red;
font-size: 1rem;
">
Text
</span>`,
description: 'Multi-line HTML style attribute with two declarations',
},
],
reject: [
{
code: stripIndent`
<span style="color: red; font-size: 1rem;"></span>
<style>
color: red;
font-size: 16px;
</style>`,
fixed: stripIndent`
<span style="color: red; font-size: 1rem;"></span>
<style>
color: red;
font-size: 16px;
</style>`,
description: 'flush declaration in style tag',
message: messages.expected,
line: 4,
column: 2,
},
],
});
6 changes: 6 additions & 0 deletions lib/rules/declaration-empty-line-before/index.js
Expand Up @@ -9,6 +9,7 @@ const isAfterComment = require('../../utils/isAfterComment');
const isAfterStandardPropertyDeclaration = require('../../utils/isAfterStandardPropertyDeclaration');
const isCustomProperty = require('../../utils/isCustomProperty');
const isFirstNested = require('../../utils/isFirstNested');
const isFirstNodeOfRoot = require('../../utils/isFirstNodeOfRoot');
const isSingleLineString = require('../../utils/isSingleLineString');
const isStandardSyntaxDeclaration = require('../../utils/isStandardSyntaxDeclaration');
const optionsMatches = require('../../utils/optionsMatches');
Expand Down Expand Up @@ -56,6 +57,11 @@ function rule(expectation, options, context) {
const prop = decl.prop;
const parent = decl.parent;

// Ignore the first node
if (isFirstNodeOfRoot(decl)) {
return;
}

if (!isStandardSyntaxDeclaration(decl)) {
return;
}
Expand Down

0 comments on commit 269e3bf

Please sign in to comment.