This repository has been archived by the owner on Mar 23, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 513
/
disallow-implicit-type-conversion.js
76 lines (61 loc) · 2.71 KB
/
disallow-implicit-type-conversion.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
var Checker = require('../../../lib/checker');
var expect = require('chai').expect;
describe('rules/disallow-implicit-type-conversion', function() {
var checker;
beforeEach(function() {
checker = new Checker();
checker.registerDefaultRules();
});
describe('option ["numeric"]', function() {
beforeEach(function() {
checker.configure({ disallowImplicitTypeConversion: ['numeric'] });
});
it('should report implicit numeric conversion', function() {
expect(checker.checkString('var x = +y;'))
.to.have.one.validation.error.from('disallowImplicitTypeConversion');
});
it('should not report negative numbers', function() {
expect(checker.checkString('var x = -y;')).to.have.no.errors();
});
});
describe('option ["binary"]', function() {
beforeEach(function() {
checker.configure({ disallowImplicitTypeConversion: ['binary'] });
});
it('should report implicit binary conversion', function() {
expect(checker.checkString('var x = ~y;'))
.to.have.one.validation.error.from('disallowImplicitTypeConversion');
});
});
describe('option ["boolean"]', function() {
beforeEach(function() {
checker.configure({ disallowImplicitTypeConversion: ['boolean'] });
});
it('should report implicit boolean conversion', function() {
expect(checker.checkString('var x = !!y;'))
.to.have.one.validation.error.from('disallowImplicitTypeConversion');
});
});
describe('option ["string"]', function() {
beforeEach(function() {
checker.configure({ disallowImplicitTypeConversion: ['string'] });
});
it('should report implicit string conversion on rhs', function() {
expect(checker.checkString('var x = y + \'\';'))
.to.have.one.validation.error.from('disallowImplicitTypeConversion');
});
it('should report implicit string conversion on lhs', function() {
expect(checker.checkString('var x = \'\' + y;'))
.to.have.one.validation.error.from('disallowImplicitTypeConversion');
});
it('should not report string literal', function() {
expect(checker.checkString('var x = \'hi\' + y;')).to.have.no.errors();
});
it('should not report operations other than +', function() {
expect(checker.checkString('var x = \'\' * y;')).to.have.no.errors();
});
it('should not report concatination with two literals (#1538)', function() {
expect(checker.checkString('"" + "string";')).to.have.no.errors();
});
});
});