Skip to content

Commit

Permalink
Merge a3858dd into 421aab4
Browse files Browse the repository at this point in the history
  • Loading branch information
not-an-aardvark committed Apr 2, 2017
2 parents 421aab4 + a3858dd commit 8f75093
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 3 deletions.
8 changes: 5 additions & 3 deletions lib/rules/space-unary-ops.js
Expand Up @@ -288,9 +288,11 @@ module.exports = {
* @returns {void}
*/
function checkForSpaces(node) {
const tokens = sourceCode.getFirstTokens(node, 2),
firstToken = tokens[0],
secondToken = tokens[1];
const tokens = node.type === "UpdateExpression" && !node.prefix
? sourceCode.getLastTokens(node, 2)
: sourceCode.getFirstTokens(node, 2);
const firstToken = tokens[0];
const secondToken = tokens[1];

if ((node.type === "NewExpression" || node.prefix) && firstToken.type === "Keyword") {
checkUnaryWordOperatorForSpaces(node, firstToken, secondToken);
Expand Down
22 changes: 22 additions & 0 deletions tests/lib/rules/space-unary-ops.js
Expand Up @@ -36,6 +36,13 @@ ruleTester.run("space-unary-ops", rule, {
code: "this.a--",
options: [{ words: true }]
},
{
code: "foo .bar++"
},
{
code: "foo.bar --",
options: [{ nonwords: true }]
},
{
code: "delete foo.bar",
options: [{ words: true }]
Expand Down Expand Up @@ -417,6 +424,21 @@ ruleTester.run("space-unary-ops", rule, {
message: "Unary operator '++' must be followed by whitespace."
}]
},
{
code: "foo .bar++",
output: "foo .bar ++",
options: [{ nonwords: true }],
errors: [{
message: "Space is required before unary expressions '++'."
}]
},
{
code: "foo.bar --",
output: "foo.bar--",
errors: [{
message: "Unexpected space before unary operator '--'."
}]
},
{
code: "+ +foo",
output: null,
Expand Down

0 comments on commit 8f75093

Please sign in to comment.