is a JavaScript code quality tool which you can use for free to validate your JavaScript.
JavaScript is not a very strict language but in some cases you might bump into situations when you need to find an error which is caused by another and so on and therefore hard to find. In these cases this tool will be of great use to you. As you can see on their homepage there are many extra options to choose from as well regarding the validation.
I pasted one of my script libraries in here and found several smaller errors. I think it's about time to get rid of them now.
I have pasted a small function below with some intentional errors in it just to demonstrate the feedback you might get back.
function validateFields(fldName,labelName,validation) { var str = ""; var iChar = ""; var orgStr = ""; if (validation == "isEmptyString") { if (document.getElementById(fldName).value == "") { str = str + "Field '" + labelName + "' must have a value!\n"; } } else if (validation == "isNumber") { if (!isNumber(document.getElementById(fldName).value)) { str = str + "Field '" + labelName + "' is not a number!\n"; } } else if (validation == "specialChars") { orgStr = document.getElementById(fldName).value;
var char1Pos = orgStr.indexOf('"'); var char2Pos = orgStr.indexOf('\\'); if (char1Pos >= 0) { str = str + "The character " + orgStr.charAt(char1Pos) + " is not allowed for field '" + labelName + "'\n"; } else if (char2Pos >= 0) { str = str + "The character " + orgStr.charAt(char2Pos) + " is not allowed for field '" + labelName + "'\n"; } } if (str == "") { return true; } else { alert(str); return false; } } |
Here is the feedback/response/validation:
Error: Implied global: alert 29, document 6 10 14, isNumber 10, orgStr 14 16 17 20 22
Problem at line 6 character 52: Use '===' to compare with ''.
if (document.getElementById(fldName).value == "") {
Problem at line 26 character 13: Use '===' to compare with ''.
if (str == "") {
Problem at line 1 character 55: Unmatched '{'.
function validateFields(fldName,labelName,validation) {
|
Global validateFields
1 validateFields(fldName, labelName, validation) Variable char1Pos, char2Pos, str Unused iChar |