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 max-empty-lines before comments #5507

Merged
merged 5 commits into from Sep 2, 2021
Merged
Show file tree
Hide file tree
Changes from 3 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
1 change: 1 addition & 0 deletions .github/dependabot.yml
Expand Up @@ -8,3 +8,4 @@ updates:
labels:
- 'pr: dependencies'
versioning-strategy: increase
target-branch: 'v14' # TODO: Remove when releasing v14.
7 changes: 7 additions & 0 deletions lib/rules/max-empty-lines/__tests__/index.js
Expand Up @@ -117,6 +117,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 {}',
Expand Down
15 changes: 3 additions & 12 deletions lib/rules/max-empty-lines/index.js
Expand Up @@ -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);
}
});

Expand Down