import e from"../../utils/fixEmptyLinesBefore.mjs";import t from"../../utils/getPreviousNonSharedLineCommentNode.mjs";import r from"../../utils/hasEmptyLine.mjs";import i from"../../utils/isAfterSingleLineComment.mjs";import s from"../../utils/isFirstNested.mjs";import n from"../../utils/isFirstNodeOfRoot.mjs";import o from"../../utils/isSingleLineString.mjs";import l from"../../utils/isStandardSyntaxRule.mjs";import m from"../../utils/optionsMatches.mjs";import u from"../../utils/report.mjs";import a from"../../utils/ruleMessages.mjs";import f from"../../utils/validateOptions.mjs";const p="rule-empty-line-before",c=a(p,{expected:"Expected empty line before rule",rejected:"Unexpected empty line before rule"}),d=(t,a,d)=>(x,y)=>{if(!f(y,p,{actual:t,possible:["always","never","always-multi-line","never-multi-line"]},{actual:a,possible:{ignore:["after-comment","first-nested","inside-block"],except:["after-rule","after-single-line-comment","first-nested","inside-block-and-after-rule","inside-block"]},optional:!0}))return;const b=t;x.walkRules(t=>{if(!l(t))return;if(n(t))return;if(m(a,"ignore","after-comment")){const e=t.prev();if(e&&"comment"===e.type)return}if(m(a,"ignore","first-nested")&&s(t))return;const f=t.parent&&"root"!==t.parent.type;if(m(a,"ignore","inside-block")&&f)return;if(b.includes("multi-line")&&o(t.toString()))return;let x=b.includes("always");(m(a,"except","first-nested")&&s(t)||m(a,"except","after-rule")&&g(t)||m(a,"except","inside-block-and-after-rule")&&f&&g(t)||m(a,"except","after-single-line-comment")&&i(t)||m(a,"except","inside-block")&&f)&&(x=!x);if(x===r(t.raws.before))return;const j=x?c.expected:c.rejected,k=x?"add":"remove";u({message:j,messageArgs:[],node:t,result:y,ruleName:p,fix:{apply:()=>e({node:t,newline:d.newline,action:k}),node:t.parent}})})};function g(e){const r=t(e);return null!=r&&"rule"===r.type}d.ruleName=p,d.messages=c,d.meta={url:"https://stylelint.io/user-guide/rules/rule-empty-line-before",fixable:!0};export{d as default};