Permalink
Jump to Line
Branch:
master
Switch branches/tags
dollar-ignores
feature/new-rule-require-new-lines-in-array
gh-pages
issues/1242
issues/1271-related
master
mdevils/cst
Nothing to show
Nothing to show
Fetching contributors…
![]()
Cannot retrieve contributors at this time
| var Checker = require('../../../lib/checker'); | |
| var reportAndFix = require('../../lib/assertHelpers').reportAndFix; | |
| var expect = require('chai').expect; | |
| describe('rules/disallow-trailing-comma', function() { | |
| var checker; | |
| var rules = { disallowTrailingComma: true }; | |
| beforeEach(function() { | |
| checker = new Checker(); | |
| checker.registerDefaultRules(); | |
| checker.configure(rules); | |
| }); | |
| reportAndFix({ | |
| name: 'comma in object literal', | |
| rules: rules, | |
| errors: 1, | |
| input: '({b: 2,})', | |
| output: '({b: 2})' | |
| }); | |
| reportAndFix({ | |
| name: 'comma in object literal with couple properties', | |
| rules: rules, | |
| errors: 1, | |
| input: '({a: 1, b: 2,})', | |
| output: '({a: 1, b: 2})' | |
| }); | |
| it('should report trailing comma in object literal', function() { | |
| expect(checker.checkString('var x = {a: "a", b: "b"}')).to.have.no.errors(); | |
| expect(checker.checkString('var x = {a: "a", b: "b"\n}')).to.have.no.errors(); | |
| expect(checker.checkString('var x = {a: "a", b: "b",}')) | |
| .to.have.one.validation.error.from('disallowTrailingComma'); | |
| expect(checker.checkString('var x = {a: "a", b: "b",\n}')) | |
| .to.have.one.validation.error.from('disallowTrailingComma'); | |
| }); | |
| it('should report trailing comma in array', function() { | |
| expect(checker.checkString('var x = [1, 2]')).to.have.no.errors(); | |
| expect(checker.checkString('var x = [1, 2\n]')).to.have.no.errors(); | |
| expect(checker.checkString('var x = [1, 2,]')).to.have.one.validation.error.from('disallowTrailingComma'); | |
| expect(checker.checkString('var x = [1, 2,\n]')).to.have.one.validation.error.from('disallowTrailingComma'); | |
| }); | |
| it('should report right location for trailing comma in object (#1018)', function() { | |
| var errs = checker.checkString('var obj = {\n foo: "foo",\n};').getErrorList(); | |
| expect(errs[0].line + ':' + errs[0].column).to.equal('2:15'); | |
| }); | |
| it('should report right location for trailing comma in array (#1018)', function() { | |
| var errs = checker.checkString('var arr = [\n \'foo\',\n];').getErrorList(); | |
| expect(errs[0].line + ':' + errs[0].column).to.equal('2:10'); | |
| }); | |
| }); |