From 399d524ea7f6869892e83731b333ef1120ffdfda Mon Sep 17 00:00:00 2001 From: Yevgeny Petukhov Date: Thu, 2 Sep 2021 18:14:33 +0300 Subject: [PATCH] Fix max-empty-lines before comments (#5507) * Disable Dependabot on default branch (#5452) Currently, we have mainly developed on the `v14` branch. See #5439. See also: https://docs.github.com/en/code-security/supply-chain-security/keeping-your-dependencies-updated-automatically/configuration-options-for-dependency-updates#open-pull-requests-limit * Set `target-branch: v14` for Dependabot again (#5453) This change is a retry of PR #5439 and also a revert of PR #5452. Maybe, `target-branch: v14` should be set on the `master` branch, not `v14`. * Fix max-empty-lines before comments * Update snapshot Co-authored-by: Masafumi Koba <473530+ybiquitous@users.noreply.github.com> --- lib/rules/max-empty-lines/__tests__/index.js | 7 +++++++ lib/rules/max-empty-lines/index.js | 15 +++------------ system-tests/003/__snapshots__/no-fs.test.js.snap | 2 -- 3 files changed, 10 insertions(+), 14 deletions(-) diff --git a/lib/rules/max-empty-lines/__tests__/index.js b/lib/rules/max-empty-lines/__tests__/index.js index 5bd10f321f..ba6ad6fbad 100644 --- a/lib/rules/max-empty-lines/__tests__/index.js +++ b/lib/rules/max-empty-lines/__tests__/index.js @@ -120,6 +120,13 @@ testRule({ line: 5, column: 1, }, + { + code: 'a {}\n\n\n/** horse */\n\nb {}', + fixed: 'a {}\n\n/** horse */\n\nb {}', + message: messages.expected(1), + line: 3, + column: 1, + }, { code: 'a {}\r\n\r\n/** horse */\r\n\r\n\r\nb {}', fixed: 'a {}\r\n\r\n/** horse */\r\n\r\nb {}', diff --git a/lib/rules/max-empty-lines/index.js b/lib/rules/max-empty-lines/index.js index b545457c82..3e8aa9cb4f 100644 --- a/lib/rules/max-empty-lines/index.js +++ b/lib/rules/max-empty-lines/index.js @@ -50,23 +50,14 @@ function rule(max, options, context) { if (context.fix) { root.walk((node) => { if (node.type === 'comment') { - // for inline comments - if (node.raws.inline) { - node.raws.before = getChars(node.raws.before); - } - if (!ignoreComments) { node.raws.left = getChars(node.raws.left); node.raws.right = getChars(node.raws.right); } - } else { - if (node.raws.before) { - node.raws.before = getChars(node.raws.before); - } + } - if (node.raws.after) { - node.raws.after = getChars(node.raws.after); - } + if (node.raws.before) { + node.raws.before = getChars(node.raws.before); } }); diff --git a/system-tests/003/__snapshots__/no-fs.test.js.snap b/system-tests/003/__snapshots__/no-fs.test.js.snap index 33b27ad578..9aa6062945 100644 --- a/system-tests/003/__snapshots__/no-fs.test.js.snap +++ b/system-tests/003/__snapshots__/no-fs.test.js.snap @@ -15,7 +15,6 @@ Object { /* Your images should be linked as if the CSS file sits in the same folder as the images. ie. no paths. */ - /* basic elements */ html { margin: 0; @@ -66,7 +65,6 @@ abbr { border-bottom: none; } - /* specific divs */ .page-wrapper { background: url(http://csszengarden.com/001/zen-bg.jpg) no-repeat top left;