diff --git a/lib/rules/declaration-empty-line-before/__tests__/index.js b/lib/rules/declaration-empty-line-before/__tests__/index.js
index 55e702f9ee..caabbf20de 100644
--- a/lib/rules/declaration-empty-line-before/__tests__/index.js
+++ b/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({
@@ -897,3 +899,107 @@ testRule({
},
],
});
+
+testRule(rule, {
+ ruleName,
+ config: ['always'],
+ syntax: 'html',
+ fix: true,
+ accept: [
+ {
+ code: ``,
+ description: 'Single-line HTML style tag',
+ },
+ {
+ code: stripIndent`
+
+ Text
+ `,
+ description: 'Multi-line HTML style attribute with two declarations',
+ },
+ ],
+ reject: [
+ {
+ code: stripIndent`
+
+ `,
+ fixed: stripIndent`
+
+ `,
+ 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: ``,
+ description: 'Single-line HTML style attribute with two declarations',
+ },
+ {
+ code: stripIndent`
+
+ Text
+ `,
+ description: 'Multi-line HTML style attribute with two declarations',
+ },
+ ],
+ reject: [
+ {
+ code: stripIndent`
+
+ `,
+ fixed: stripIndent`
+
+ `,
+ description: 'flush declaration in style tag',
+ message: messages.expected,
+ line: 4,
+ column: 2,
+ },
+ ],
+});
diff --git a/lib/rules/declaration-empty-line-before/index.js b/lib/rules/declaration-empty-line-before/index.js
index faa8511bb2..86a7a7cb83 100644
--- a/lib/rules/declaration-empty-line-before/index.js
+++ b/lib/rules/declaration-empty-line-before/index.js
@@ -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');
@@ -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;
}