[Original] Enterprise Web2.0 project development essential-http://code.google.com/p/jslint-toolkit/

Source: Internet
Author: User
Introduction
Many enterprises have now launched the Web2.0 project, and an important feature of Web2.0 is Ajax interaction. Therefore, it is a headache for many people to control the quality of a large number of JavaScript scripts in Enterprise Web projects.
Douglas crockford, the inventor of the famous JSON Data Interaction format, began to pay attention to this issue a long time ago and provided the corresponding solution-jslint, through the Javascript Code To reduce the number of bugs.

However, jslint can only verify one Javascript file at a time. Although Visual Studio, Aptana, eclipse and other famous development tools all have corresponding jslint plug-ins, these plug-ins are only for personal use.
If you can verify all the JavaScript files in a project and provide an intuitive verification report, it will play an intuitive and important role in the JavaScript code quality in the project.

Jslint-Toolkit debut
I recently open-source a project jslint-Toolkit, which can easily solve this problem.

To give you an intuitive experience, let's first introduce how to use jslint-Toolkit:

    • Modify config. JSON
      {// JavaScript files to check "events des": ["scripts \ source", "scripts \ jquery-1.3.2.js"], // exclude Files "excludes": [], // exclude file names "excludenames": ["CVS"], // output directory "outpath": "Out "}

      To verify all the files under the scripts \ source directory and scripts \ jquery-1.3.2.js, ignore the folder or file named CVs, output the end to the out sub-directory in the current directory.

    • Double-click Run. BAT to run:
    • Open the index.htm file of the outchild directory:

It's easy.

Classify verification results
There are sometimes many errors (Note: The error here refers to the verification result of jslint, which is not a standard. You can find the specifications used by jslint here ),
We classify errors to help us find the most serious error information.

Jslint errors are classified into two types: critical errors and optional errors.
Currently, critical errors is divided into the following parts. I have added a simple example:

  • Missing semicolon.
    // Bad var appdiscuss = {cred: "", baseurl: "/mashup/WebClient/community/discussion/"} // good var appdiscuss = {cred: "", baseurl: "/mashup/WebClient/community/discussion /"};
  • '{A}' is already defined.
    // 'Title' is already defined. // bad $. Extend ({confirm: function (Info, call, title) {var Title = (title )? Title: 'system ';//...}}; // good $. extend ({confirm: function (Info, call, title) {Title = title | 'system ';//...}};
  • Expected '{A}' and instead saw '{B }'.
    // Expected '{' and instead saw 'Return '. // bad if ($ (this ). ATTR ('class') return; // good if ($ (this ). ATTR ('class') {return ;}
  • Extra comma.
    // Bad var DATA = {name: "zhangsan", sex: "Man" ,}; // good var DATA = {name: "zhangsan", sex: "Man "};
  • Bad for in variable '{}'.
    // Bad for in variable 'prop'. // bad for (prop in headers) {}// good for (VAR prop in headers ){}
  • Unnecessary semicolon.
    // Bad function validate () {}; // good function validate (){}
  • Bad line breaking before '{}'.
    // Bad line breaking before '+ '. // bad var frame = '<Div class = "contentpane">' + '<Div class = "comments_show_hide panel_action">' + '</div> '; // good var frame = '<Div class = "contentpane">' + '<Div class = "comments_show_hide panel_action">' + '</div> ';
  • Missing Radix parameter.
    // Bad var val = parseint ("10,000 ". replace (/,/g, ""); // good var val = parseint ("10,000 ". replace (/,/g, ""), 10 );
  • '{A}' was used before it was defined.
    // 'Plus 'was used before it was defined. // bad function add (a, B) {return plus (A) + B; Function Plus (a) {return a + 1 ;}// good function add (, b) {Function Plus (a) {return a + 1;} return plus (A) + B ;}

For more details, download jslint-toolkit from the http://code.google.com/p/jslint-toolkit/ and find it in jslint-toolkit-Rhino \ doc \ lint_msg.htm.

Technologies used in jslint-Toolkit
Jslint-Toolkit uses two key open-source technologies: jslint and rhino.
The following is a detailed list:

  • Rhino
    Rhino (Javascript in Java) is open source and licensed by Mozilla under the MPL 1.1 or later/GPL 2.0 or later licenses, the text of which is available at http://www.mozilla.org/MPL/
    You can obtain the source code for Rhino from the Mozilla web site at http://www.mozilla.org/rhino/download.html
  • Jslint
    Jslint is a javascript program that looks for problems in javascript programs. It is a code quality tool. http://www.jslint.com/
    We use the rhino version of jslint, you can obtain the source code here: http://www.jslint.com/rhino/index.html
  • Qooxdoo
    Qooxdoo is a comprehensive and innovative Ajax application framework. No HTML, CSS nor Dom knowledge is needed. It is open source under an lgpl/EPL dual license.
    Http://qooxdoo.org/
  • Syntaxhighlighter
    Syntaxhighlighter is a fully functional self-contained code syntax highlighter developed in JavaScript.
    Http://alexgorbatchev.com/wiki/SyntaxHighlighter
  • Jquery
    Jquery is a fast and concise JavaScript library that simplifies HTML document traversing, event handling, animating, and Ajax interactions for rapid web development.
    Http://jquery.com/

What are you waiting for? Try again ......

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.