Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
103 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
/** | ||
* Internal dependencies. | ||
*/ | ||
|
||
var Rule = require('../rule'); | ||
|
||
var Comma = Rule.create({ | ||
error: 'Bad comma spacing', | ||
|
||
option: { | ||
key: 'commaspace', | ||
type: 'enum', | ||
values: ['after', 'before', 'surround'], | ||
defaults: 'off' | ||
}, | ||
|
||
on: { | ||
Punctuator: 'check', | ||
}, | ||
}); | ||
|
||
/** | ||
* Perform the check. | ||
* | ||
* @param {Object} token | ||
* @api public | ||
*/ | ||
|
||
Comma.prototype.check = function(token) { | ||
if (token.value !== ',') return; | ||
|
||
var range = [token.range[0] - 1, token.range[1] + 1]; | ||
var str = this.source.range(range); | ||
var error = false; | ||
var test = function(char) { | ||
return /\s/.test(char); | ||
}; | ||
|
||
switch (this.option()) { | ||
case 'after': | ||
if (!test(str[2]) || test(str[0])) error = true; | ||
break; | ||
case 'before': | ||
if (!test(str[0]) || test(str[2])) error = true; | ||
break; | ||
case 'surround': | ||
if (!test(str[0]) || !test(str[2])) error = true; | ||
break; | ||
} | ||
|
||
if (error) { | ||
this.badToken(token); | ||
} | ||
}; | ||
|
||
/** | ||
* Primary export. | ||
*/ | ||
|
||
module.exports = Comma; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
/* stylec arrcomma: prohibited */ | ||
/* stylec arrcomma: prohibited, commaspace: off */ | ||
|
||
var good = [ | ||
1, | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
/* stylec commaspace: after */ | ||
|
||
var good = (1, 2, 3); | ||
var good = [1, 2, 3]; | ||
var good, verygood, awesome; | ||
|
||
var bad = [1 ,2 ,3]; | ||
var bad ,boo ,bar = null; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
module.exports = [ | ||
{ line: 7, column: 13 }, | ||
{ line: 7, column: 16 }, | ||
{ line: 8, column: 8 }, | ||
{ line: 8, column: 13 }, | ||
]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
/* stylec commaspace: before */ | ||
|
||
var good = (1 ,2 ,3); | ||
var good = [1 ,2 ,3]; | ||
var good ,verygood ,awesome; | ||
|
||
var bad = [1, 2, 3]; | ||
var bad, boo, bar = null; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
module.exports = [ | ||
{ line: 7, column: 12 }, | ||
{ line: 7, column: 15 }, | ||
{ line: 8, column: 7 }, | ||
{ line: 8, column: 12 }, | ||
]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
/* stylec commaspace: surround */ | ||
|
||
var good = (1 , 2 , 3); | ||
var good = [1 , 2 , 3]; | ||
var good , verygood , awesome; | ||
|
||
var bad = [1, 2, 3]; | ||
var bad, boo, bar = null; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
module.exports = [ | ||
{ line: 7, column: 12 }, | ||
{ line: 7, column: 15 }, | ||
{ line: 8, column: 7 }, | ||
{ line: 8, column: 12 }, | ||
]; |