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 inlines styles in declaration-empty-line-before #4726

Merged
merged 5 commits into from May 12, 2020
Merged
Show file tree
Hide file tree
Changes from 4 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
105 changes: 105 additions & 0 deletions lib/rules/declaration-empty-line-before/__tests__/index.js
Expand Up @@ -2,6 +2,7 @@

const rule = require('..');
const { messages, ruleName } = rule;
const stripIndent = require('common-tags').stripIndent;

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

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 @@ -7,6 +7,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 @@ -54,6 +55,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