Skip to content

Commit

Permalink
Fix TypeError for inline comments and autofix for sugarss in max-empt…
Browse files Browse the repository at this point in the history
…y-lines (#4821)
  • Loading branch information
ecuplxd committed Jun 9, 2020
1 parent 8e07ca0 commit 120df50
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 1 deletion.
44 changes: 44 additions & 0 deletions lib/rules/max-empty-lines/__tests__/index.js
Expand Up @@ -478,6 +478,50 @@ testRule({
],
});

testRule({
ruleName,
config: [2],
skipBasicChecks: true,
syntax: 'sugarss',
fix: true,

accept: [
{
code: '\n\n// one',
},
{
code: '// one\n\n',
},
{
code: '// one\n\n\n// two\n',
},
],

reject: [
{
code: '\n\n\n// one',
fixed: '\n\n// one',
message: messages.expected(2),
line: 3,
column: 1,
},
{
code: '// one\n\n\n',
fixed: '// one\n\n',
message: messages.expected(2),
line: 4,
column: 1,
},
{
code: '// one\n\n\n\n// two\n',
fixed: '// one\n\n\n// two\n',
message: messages.expected(2),
line: 4,
column: 1,
},
],
});

testRule({
ruleName,
config: [2, { ignore: 'comments' }],
Expand Down
2 changes: 1 addition & 1 deletion lib/rules/max-empty-lines/index.js
Expand Up @@ -154,7 +154,7 @@ function rule(max, options, context) {
function replaceEmptyLines(max, str, isSpecialCase = false) {
const repeatTimes = isSpecialCase ? max : max + 1;

if (repeatTimes === 0) {
if (repeatTimes === 0 || typeof str !== 'string') {
return '';
}

Expand Down

0 comments on commit 120df50

Please sign in to comment.