This repository has been archived by the owner. It is now read-only.
Permalink
Browse files

Fix: account for generators in function spacing rules

Fixes #1175
  • Loading branch information...
hzoo committed Oct 17, 2015
1 parent 7952b17 commit a2c009f19aaf410a46abb3edfbc56d4aa9931f41
@@ -105,6 +105,10 @@ module.exports.prototype = {
if (node.async && functionToken.value === 'async') {
functionToken = file.getNextToken(functionToken);
}
// if generator, set token to be * instead
if (node.generator && functionToken.value === 'function') {
functionToken = file.getNextToken(functionToken);
}
errors.assert.noWhitespaceBetween({
token: functionToken,
nextToken: file.getNextToken(functionToken),
@@ -85,6 +85,10 @@ module.exports.prototype = {
if (node.async && functionToken.value === 'async') {
functionToken = file.getNextToken(functionToken);
}
// if generator, set token to be * instead
if (node.generator && functionToken.value === 'function') {
functionToken = file.getNextToken(functionToken);
}
errors.assert.noWhitespaceBetween({
token: functionToken,
nextToken: file.getNextToken(functionToken),
@@ -105,6 +105,10 @@ module.exports.prototype = {
if (node.async && functionToken.value === 'async') {
functionToken = file.getNextToken(functionToken);
}
// if generator, set token to be * instead
if (node.generator && functionToken.value === 'function') {
functionToken = file.getNextToken(functionToken);
}
errors.assert.noWhitespaceBetween({
token: functionToken,
nextToken: file.getNextToken(functionToken),
@@ -103,6 +103,10 @@ module.exports.prototype = {
if (node.async && functionToken.value === 'async') {
functionToken = file.getNextToken(functionToken);
}
// if generator, set token to be * instead
if (node.generator && functionToken.value === 'function') {
functionToken = file.getNextToken(functionToken);
}
errors.assert.noWhitespaceBetween({
token: functionToken,
nextToken: file.getNextToken(functionToken),
@@ -151,6 +151,10 @@ module.exports.prototype = {
if (node.async && functionToken.value === 'async') {
functionToken = file.getNextToken(functionToken);
}
// if generator, set token to be * instead
if (node.generator && functionToken.value === 'function') {
functionToken = file.getNextToken(functionToken);
}
errors.assert.whitespaceBetween({
token: functionToken,
nextToken: file.getNextToken(functionToken),
@@ -86,6 +86,10 @@ module.exports.prototype = {
if (node.async && functionToken.value === 'async') {
functionToken = file.getNextToken(functionToken);
}
// if generator, set token to be * instead
if (node.generator && functionToken.value === 'function') {
functionToken = file.getNextToken(functionToken);
}
errors.assert.whitespaceBetween({
token: functionToken,
nextToken: file.getNextToken(functionToken),
@@ -104,6 +104,10 @@ module.exports.prototype = {
if (node.async && functionToken.value === 'async') {
functionToken = file.getNextToken(functionToken);
}
// if generator, set token to be * instead
if (node.generator && functionToken.value === 'function') {
functionToken = file.getNextToken(functionToken);
}
errors.assert.whitespaceBetween({
token: functionToken,
nextToken: file.getNextToken(functionToken),
@@ -150,6 +150,10 @@ module.exports.prototype = {
if (node.async && functionToken.value === 'async') {
functionToken = file.getNextToken(functionToken);
}
// if generator, set token to be * instead
if (node.generator && functionToken.value === 'function') {
functionToken = file.getNextToken(functionToken);
}
errors.assert.whitespaceBetween({
token: functionToken,
nextToken: file.getNextToken(functionToken),
@@ -37,21 +37,21 @@ describe('rules/require-spaces-in-function-expression', function() {
expect(checker.checkString('var x = function a (){}')).to.have.no.errors();
});
it('should report missing space before round brace in FunctionExpression', function() {
it('should report missing space before round brace in async FunctionExpression', function() {
expect(checker.checkString('var x = async function(){}'))
.to.have.one.validation.error.from('requireSpacesInFunctionExpression');
});
it('should report missing space before round brace in named FunctionExpression', function() {
it('should report missing space before round brace in named async FunctionExpression', function() {
expect(checker.checkString('var x = async function a(){}'))
.to.have.one.validation.error.from('requireSpacesInFunctionExpression');
});
it('should not report space before round brace in FunctionExpression', function() {
it.only('should not report space before round brace in async FunctionExpression', function() {
expect(checker.checkString('var x = async function (){}')).to.have.no.errors();
});
it('should not report space before round brace in named FunctionExpression', function() {
it('should not report space before round brace in named async FunctionExpression', function() {
expect(checker.checkString('var x = async function a (){}')).to.have.no.errors();
});
@@ -101,6 +101,22 @@ describe('rules/require-spaces-in-function-expression', function() {
output: 'var x = function (){}'
});
reportAndFix({
name: 'missing space before round brace in generator FunctionExpression',
rules: rules,
errors: 1,
input: 'var x = function*(){}',
output: 'var x = function* (){}'
});
reportAndFix({
name: 'missing space before round brace in generator FunctionExpression',
rules: rules,
errors: 1,
input: 'var x = function *(){}',
output: 'var x = function * (){}'
});
reportAndFix({
name: 'missing space before round brace in method shorthand',
rules: rules,

0 comments on commit a2c009f

Please sign in to comment.