Skip to content
This repository was archived by the owner on Mar 23, 2024. It is now read-only.

Commit 0df1c71

Browse files
hzoomikesherov
authored andcommitted
Assertions: always allow new lines in whitespaceBetween
Fixes gh-791 Closes gh-794
1 parent 6e1e3b9 commit 0df1c71

File tree

4 files changed

+26
-14
lines changed

4 files changed

+26
-14
lines changed

README.md

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3459,15 +3459,16 @@ function(d) {
34593459

34603460
### validateParameterSeparator
34613461

3462-
Enable validation of separators between function parameters.
3462+
Enable validation of separators between function parameters. Will ignore newlines.
34633463

34643464
Type: `String`
34653465

34663466
Values:
34673467

3468-
- `", "`: function parameters are immediately followed by a comma then a space
3469-
- `" ,"`: function parameters are immediately followed by a space then a comma
3470-
- `" , "`: function parameters are immediately followed by a space, a comma then a space
3468+
- `","`: function parameters are immediately followed by a comma
3469+
- `", "`: function parameters are immediately followed by a comma and then a space
3470+
- `" ,"`: function parameters are immediately followed by a space and then a comma
3471+
- `" , "`: function parameters are immediately followed by a space, a comma, and then a space
34713472

34723473
#### Example
34733474

lib/token-assert.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ function TokenAssert(file) {
1616
utils.inherits(TokenAssert, EventEmitter);
1717

1818
/**
19-
* Requires to have whitespace between specified tokens.
19+
* Requires to have whitespace between specified tokens. Ignores newlines.
2020
*
2121
* @param {Object} options.token
2222
* @param {Object} options.nextToken
@@ -28,7 +28,7 @@ TokenAssert.prototype.whitespaceBetween = function(options) {
2828
var nextToken = options.nextToken;
2929
if (options.hasOwnProperty('spaces')) {
3030
var spaces = options.spaces;
31-
if (nextToken.loc.start.line !== token.loc.end.line ||
31+
if (nextToken.loc.start.line === token.loc.end.line &&
3232
(nextToken.loc.start.column - token.loc.end.column) !== spaces
3333
) {
3434
this.emit('error', {

test/rules/validate-parameter-separator.js

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,10 @@ describe('rules/validate-parameter-separator', function() {
108108
assert.strictEqual(checker.checkString('function a(b\n, c) {}').getErrorCount(), 0);
109109
});
110110

111+
it('should not report any errors for function a(b,<line-break>c) {}', function() {
112+
assert.strictEqual(checker.checkString('function a(b,\nc) {}').getErrorCount(), 0);
113+
});
114+
111115
it('should report errors for function a(b,<space><space>c) {}', function() {
112116
assert.strictEqual(checker.checkString('function a(b, c) {}').getErrorCount(), 1);
113117
});
@@ -143,7 +147,11 @@ describe('rules/validate-parameter-separator', function() {
143147
assert.strictEqual(checker.checkString('function a(b ,c) {}').getErrorCount(), 0);
144148
});
145149

146-
it('should not report any errors for function a(b,<line-break>c) {}', function() {
150+
it('should not report any errors for function a(b<line-break>,c) {}', function() {
151+
assert.strictEqual(checker.checkString('function a(b\n,c) {}').getErrorCount(), 0);
152+
});
153+
154+
it('should not report any errors for function a(b ,<line-break>c) {}', function() {
147155
assert.strictEqual(checker.checkString('function a(b ,\nc) {}').getErrorCount(), 0);
148156
});
149157

@@ -182,6 +190,14 @@ describe('rules/validate-parameter-separator', function() {
182190
assert.strictEqual(checker.checkString('function a(b , c) {}').getErrorCount(), 0);
183191
});
184192

193+
it('should not report any errors for function a(b<line-break>, c) {}', function() {
194+
assert.strictEqual(checker.checkString('function a(b\n, c) {}').getErrorCount(), 0);
195+
});
196+
197+
it('should not report any errors for function a(b ,<line-break>c) {}', function() {
198+
assert.strictEqual(checker.checkString('function a(b ,\nc) {}').getErrorCount(), 0);
199+
});
200+
185201
it('should report errors for function a(b<space>,<space><space>c) {}', function() {
186202
assert.strictEqual(checker.checkString('function a(b , c) {}').getErrorCount(), 1);
187203
});

test/token-assert.js

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ describe('modules/token-assert', function() {
9191
assert.equal(error.column, 1);
9292
});
9393

94-
it('should trigger error on newline between tokens', function() {
94+
it('should not trigger error on newline between tokens', function() {
9595
var file = createJsFile('x\n=y;');
9696

9797
var tokenAssert = new TokenAssert(file);
@@ -105,12 +105,7 @@ describe('modules/token-assert', function() {
105105
spaces: 2
106106
});
107107

108-
assert(onError.calledOnce);
109-
110-
var error = onError.getCall(0).args[0];
111-
assert.equal(error.message, '2 spaces required between x and =');
112-
assert.equal(error.line, 1);
113-
assert.equal(error.column, 1);
108+
assert(!onError.calledOnce);
114109
});
115110

116111
it('should not trigger error on valid space count between tokens', function() {

0 commit comments

Comments
 (0)