Skip to content

Commit

Permalink
Breaking: Switch class option for lines-around-comment (fixes #8564)
Browse files Browse the repository at this point in the history
  • Loading branch information
Mardak committed May 8, 2017
1 parent c70b0ed commit b260b10
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 6 deletions.
21 changes: 21 additions & 0 deletions docs/rules/lines-around-comment.md
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,11 @@ var foo = {
day: "great"
};

class foo {
// what a great and wonderful day
day() {"great"}
};

const {
// what a great and wonderful day
foo: someDay
Expand All @@ -205,6 +210,11 @@ var foo = {
day: "great"
};

class foo {
/* what a great and wonderful day */
day() {"great"}
};

const {
/* what a great and wonderful day */
foo: someDay
Expand All @@ -228,6 +238,11 @@ var foo = {
// what a great and wonderful day
};

class foo {
day() {"great"}
// what a great and wonderful day
};

const {
foo: someDay
// what a great and wonderful day
Expand All @@ -250,6 +265,12 @@ var foo = {
/* what a great and wonderful day */
};

class foo {
day() {"great"}

/* what a great and wonderful day */
};

const {
foo: someDay

Expand Down
8 changes: 4 additions & 4 deletions lib/rules/lines-around-comment.js
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ module.exports = {
* @returns {boolean} True if the comment is at block start.
*/
function isCommentAtBlockStart(token) {
return isCommentAtParentStart(token, "ClassBody") || isCommentAtParentStart(token, "BlockStatement") || isCommentAtParentStart(token, "SwitchCase");
return isCommentAtParentStart(token, "BlockStatement") || isCommentAtParentStart(token, "SwitchCase");
}

/**
Expand All @@ -221,7 +221,7 @@ module.exports = {
* @returns {boolean} True if the comment is at block end.
*/
function isCommentAtBlockEnd(token) {
return isCommentAtParentEnd(token, "ClassBody") || isCommentAtParentEnd(token, "BlockStatement") || isCommentAtParentEnd(token, "SwitchCase") || isCommentAtParentEnd(token, "SwitchStatement");
return isCommentAtParentEnd(token, "BlockStatement") || isCommentAtParentEnd(token, "SwitchCase") || isCommentAtParentEnd(token, "SwitchStatement");
}

/**
Expand All @@ -230,7 +230,7 @@ module.exports = {
* @returns {boolean} True if the comment is at object start.
*/
function isCommentAtObjectStart(token) {
return isCommentAtParentStart(token, "ObjectExpression") || isCommentAtParentStart(token, "ObjectPattern");
return isCommentAtParentStart(token, "ObjectExpression") || isCommentAtParentStart(token, "ObjectPattern") || isCommentAtParentStart(token, "ClassBody");
}

/**
Expand All @@ -239,7 +239,7 @@ module.exports = {
* @returns {boolean} True if the comment is at object end.
*/
function isCommentAtObjectEnd(token) {
return isCommentAtParentEnd(token, "ObjectExpression") || isCommentAtParentEnd(token, "ObjectPattern");
return isCommentAtParentEnd(token, "ObjectExpression") || isCommentAtParentEnd(token, "ObjectPattern") || isCommentAtParentEnd(token, "ClassBody");
}

/**
Expand Down
4 changes: 2 additions & 2 deletions tests/lib/rules/lines-around-comment.js
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ ruleTester.run("lines-around-comment", rule, {
},
{
code: "class A {\n/**\n* hi\n */\nconstructor() {}\n}",
options: [{ allowBlockStart: true }],
options: [{ allowObjectStart: true }],
parserOptions: { ecmaVersion: 6 }
},
{
Expand Down Expand Up @@ -414,7 +414,7 @@ ruleTester.run("lines-around-comment", rule, {
code: "class B {\nconstructor() {}\n\n/**\n* hi\n */\n}",
options: [{
afterBlockComment: true,
allowBlockEnd: true
allowObjectEnd: true
}],
parserOptions: { ecmaVersion: 6 }
},
Expand Down

0 comments on commit b260b10

Please sign in to comment.