-
28 Jan 2013 2:08 AM #1
Avoid trailing comma in array and object literals code review.
Avoid trailing comma in array and object literals code review.
Hi All,
I am analyzing JavaScript code quality in Sonar.
Its reporting "Avoid trailing comma in array and object literals." in the below code, which is highlighted in red color .
Ext.apply(Ext.form.VTypes, { usPhone: function(v) { return /^\d{3}-\d{3}-\d{4}$/.test(v); }, usPhoneText: 'Please enter a US Phone number in the format 999-999-9999', usPhoneMask: /[\d\s\(\)\-]/i });
Ext.define('AddressState', { extend: 'Ext.data.Model', fields: [ {type: 'string', name: 'abbr'}, {type: 'string', name: 'name'}, {type: 'string', name: 'slogan'} ] });
If I remove highleted in Red comma Ext js will not accept.
How to fix this issue. Please help me on this... we have 40 blockers all issues are same.
Thanks in Advance...
-
28 Jan 2013 2:48 AM #2
It's not wrong because the alternative is not valid syntax. Define is a method, the class name is the first parameter, the class definition is the second:
You can't pass arguments like this because it's a syntax error:Code:myFoo('name', { foo: 'bar' });
The tool you're using is bogus.Code:myFoo('name' { foo: 'bar' });Evan Trimboli
Sencha Developer
Twitter - @evantrimboli
Don't be afraid of the source code!
-
28 Jan 2013 3:00 AM #3
Hi Evant,
Thanks for your response..
I am using JavaScript plugin in Sonar.
Is there any best plugin to check javascript code as per the coding standard.
Thanks
-
28 Jan 2013 3:42 AM #4
Try a linter like javascriptlint or Douglas Crockford's original JSLint.
Product Architect
Altus Ltd.
-
31 Jan 2013 2:15 AM #5
Hi Westy,
I am using sonar server for code review. Sonar has java script plugin in built.
I am not aware how to use javascriptlint or Douglas Crockford's original JSLint in saonr.
If any body know how to use please let me know.
Thanks,
Sud
-
31 Jan 2013 10:27 PM #6
Hi All,
Please help me how to use javascriptlint or Douglas Crockford's original JSLint in sonar.
Thanks in Advance...!


Reply With Quote