[javascriptlint-commit] SF.net SVN: javascriptlint:[262] trunk
Status: Beta
Brought to you by:
matthiasmiller
From: <mat...@us...> - 2009-10-06 16:06:08
|
Revision: 262 http://javascriptlint.svn.sourceforge.net/javascriptlint/?rev=262&view=rev Author: matthiasmiller Date: 2009-10-06 16:05:47 +0000 (Tue, 06 Oct 2009) Log Message: ----------- www: first cut on a markdown-based website Added Paths: ----------- trunk/www/ trunk/www/__template__ trunk/www/docs/ trunk/www/docs/index.htm trunk/www/docs/running_from_the_command_line.htm trunk/www/docs/running_from_windows_explorer.htm trunk/www/docs/running_from_your_ide.htm trunk/www/docs/running_from_your_php_website.htm trunk/www/docs/running_from_your_windows_program.htm trunk/www/download.htm trunk/www/index.htm trunk/www/online_lint.php trunk/www/static/ trunk/www/static/feed-icon-32x32.png trunk/www/static/global.css trunk/www.py Added: trunk/www/__template__ =================================================================== --- trunk/www/__template__ (rev 0) +++ trunk/www/__template__ 2009-10-06 16:05:47 UTC (rev 262) @@ -0,0 +1,22 @@ +<html> +<head> + <title>%(title)s</title> + <link rel="stylesheet" type="text/css" href="/static/global.css" /> +</head> +<body> + <div id="title"> + JavaScript Lint + </div> + <div id="nav"> + %(nav)s + <p align="center"><a href="rss.php"> + <img border="0" src="/static/feed-icon-32x32.png" width="32" height="32"></a></p> + </div> + <div id="body"> + %(body)s + </div> + <div id="footer"> + JavaScript Lint is sponsored by <a href="http://blog.outofhanwell.com/">Matthias Miller</a>. + </div> +</body> +</html> Property changes on: trunk/www/__template__ ___________________________________________________________________ Added: svn:eol-style + native Added: trunk/www/docs/index.htm =================================================================== --- trunk/www/docs/index.htm (rev 0) +++ trunk/www/docs/index.htm 2009-10-06 16:05:47 UTC (rev 262) @@ -0,0 +1,84 @@ +<!-- +@title=Documentation +--> + +Setting Up JavaScript Lint +========================== + +You can run JavaScript Lint several ways: + +* You can [integrate it into your IDE](running_from_your_ide.htm), such as Visual Studio, SciTE, or any other IDE supporting external tools. When JavaScript Lint finds an error, your IDE takes you directly to the line containing the error. + +* You can [run it through Windows Explorer](running_from_windows_explorer.htm), which Windows programmers may prefer. + +* You can [use the command line](running_from_the_command_line.htm) to integrate into your build system, or maybe you're a Linux programmer and simply prefer the command line! + +Additionally, if you are a software developer, you may want to [integrate into your Windows program](running_from_your_windows_program.htm) or [run it from your PHP website](running_from_your_php_website.htm) to take advantage of the full power of JavaScript Lint. + +Disable Warnings with Control Comment +===================================== + +JavaScript Lint has limited support for control comments. To disable warnings in part of your JavaScript file, you can add the following comments: + +> /*jsl:ignore*/ +> (code that fires warnings) +> /*jsl:end*/ + +To ignore all warnings in a file, simply place `/*jsl:ignoreall*/` at the top of the file. + +Note that this should only be used as a short-term solution for code that you maintain. If this is caused by a bug or missing feature in JavaScript Lint, please report the problem to Info\<at\>JavaScriptLint.com. + +Option Explicit +=============== + +JavaScript Lint can optionally check for variables, functions, and objects that don't exist, much like Visual Basic's "option explicit." In the interest of making JavaScript Lint accessible to the average programmer, this powerful feature is disabled by default. Although this feature requires more work to understand and implement, it provides a higher level of protection against coding errors. + +A variable that is not explicitly declared has a global scope. For example, if a function uses a counter variable and calls another function that uses a counter variable by the same name, unless these functions use the var keyword to declare the variable, the two functions will be accessing and modifying the same variable. This almost never produces the expected behavior. + +Here's what it takes to set up this feature: + +* The check for undeclared identifiers is enabled on a per-file basis with a `/*jsl:option explicit*/` comment within a script. To enforce the use of option explicit, you can modify your configuration file to warn against scripts that do not use this feature. + +* If a script references a variable, function, or object from another script, you will need to add a `/*jsl:import PathToOtherScript*/` comment in your script. This tells JavaScript Lint to check for items declared in the other script. Relative paths are resolved based on the path of the current script. + +* Your script may also reference global objects that are provided by the runtime (e.g. Firefox or Windows Scripting Host). For example, the script in a web page may reference the global window object. Add the line "+define window" to your configuration file to tell JavaScript Lint about this global. + +JavaScript Lint does not validate object properties. They do not use the var keyword and cannot be validated without executing the script. + +The warnings for undeclared identifiers will appear after other warnings that may occur in the script. This is by design, since the entire script must be examined before identifiers can be called undefined. + +Switches and Breaks +=================== + +By default, JavaScript Lint warns against missing _break_'s in switch statements. Sometimes, however, break statements are intentionally excluded. To indicate this, use the `/*jsl:fallthru*/` control comment: + +> switch (i) { +> case 1: +> break; +> case 2: +> /*jsl:fallthru*/ +> case 3: +> break; +> } + +Empty Statements +================ + +By default, JavaScript Lint warns against empty statements. However, empty statements are sometimes intention. To indicate this, use the /*jsl:pass*/ control comment: + +> while (!hasResponse()) { +> /*jsl:pass*/ +> } + +Advanced Output Format +====================== + +The following output formats may also be used: + +* `__ERROR_PREFIX__` indicates the type of message +* `__ERROR_MSG__` indicates the message contents +* `__ERROR__` indicates the full error including the error type and the message. + +If the output format is prefixed with "encode:", all backslashes, single and double quotes, tabs, carriage returns, and line breaks will be escaped as `\\`, `\'` and `\"`, `\t`, `\r`, and `\n` (respectively). + +> __Syntax Note__: In addition to the /*jsl:keyword*/ syntax, control comments can also use the traditional `/*@keyword@*/` syntax. However, the jsl syntax is recommended for interoperability with JScript conditional compilation. Property changes on: trunk/www/docs/index.htm ___________________________________________________________________ Added: svn:eol-style + native Property changes on: trunk/www/docs/running_from_the_command_line.htm ___________________________________________________________________ Added: svn:eol-style + native Property changes on: trunk/www/docs/running_from_windows_explorer.htm ___________________________________________________________________ Added: svn:eol-style + native Property changes on: trunk/www/docs/running_from_your_ide.htm ___________________________________________________________________ Added: svn:eol-style + native Property changes on: trunk/www/docs/running_from_your_php_website.htm ___________________________________________________________________ Added: svn:eol-style + native Property changes on: trunk/www/docs/running_from_your_windows_program.htm ___________________________________________________________________ Added: svn:eol-style + native Added: trunk/www/download.htm =================================================================== --- trunk/www/download.htm (rev 0) +++ trunk/www/download.htm 2009-10-06 16:05:47 UTC (rev 262) @@ -0,0 +1,28 @@ +<!-- +@title=Download +--> + +Getting Started +=============== + +To get started with JavaScript Lint, download the appropriate package and extract its contents. + +* JavaScript Lint 0.3.0 for Windows ([jsl-0.3.0-win32.zip](http://www.javascriptlint.com/download/jsl-0.3.0-win32.zip)) +* JavaScript Lint 0.3.0 for Mac OS X Intel ([jsl-0.3.0-mac.tar.gz](http://www.javascriptlint.com/download/jsl-0.3.0-mac.tar.gz)) +* JavaScript Lint 0.3.0 Source ([jsl-0.3.0-src.tar.gz](http://www.javascriptlint.com/download/jsl-0.3.0-src.tar.gz)) + +Developers can also check out from the Subversion trunk: + +> svn co https://javascriptlint.svn.sourceforge.net/svnroot/javascriptlint/trunk jsl + +The [documentation](/docs/) explains the different ways that you can run JavaScript Lint. + +JavaScript Lint continues to be improved. If you encounter problems or have suggestions or revisions, please visit the project [forum](http://sourceforge.net/forum/?group_id=168518) and [tracker](http://sourceforge.net/tracker/?group_id=168518). + +Acknowledgements +================ + +We all stand on the shoulders of giants. I would like to especially acknowledge [Douglas Crockford's](http://www.crockford.com/) work on [JSLint](http://www.jslint.com/). This lint is itself written in JavaScript and is an interesting and rather sophisticated script. Crockford's ideas about good coding practices served as a springboard for many of these lint rules. + +We are all indebted to the many people who have worked hard to develop Firefox. + Property changes on: trunk/www/download.htm ___________________________________________________________________ Added: svn:eol-style + native Added: trunk/www/index.htm =================================================================== --- trunk/www/index.htm (rev 0) +++ trunk/www/index.htm 2009-10-06 16:05:47 UTC (rev 262) @@ -0,0 +1,40 @@ +<!-- +@title=JavaScript Lint +--> + +What It Is +========== + +Many JavaScript implementations do not warn against questionable coding practices. Yes, that's nice for the site that "works best with Internet Explorer" (designed with templates, scripted with snippets copied from forums). But it's a nightmare when you actually want to write quality, maintainable code. + +That's where JavaScript Lint comes in. With JavaScript Lint, you can check all your JavaScript source code for common mistakes without actually running the script or opening the web page. + +JavaScript Lint holds an advantage over competing lints because it is based on the JavaScript engine for the [Firefox browser](http://www.spreadfirefox.com/?q=affiliates&id=123423&t=70). This provides a robust framework that can not only check JavaScript syntax but also examine the coding techniques used in the script and warn against questionable practices. + +What It Does +============ + +Here are some common mistakes that JavaScript Lint looks for: + +* Missing semicolons at the end of a line. +* Curly braces without an _if_, _for_, _while_, etc. +* Code that is never run because of a _return_, _throw_, _continue_, or _break_. +* Case statements in a switch that do not have a _break_ statement. +* Leading and trailing decimal points on a number. +* A leading zero that turns a number into octal (base 8). +* Comments within comments. +* Ambiguity whether two adjacent lines are part of the same statement. +* Statements that don't do anything. + +JavaScript Lint also looks for the following less common mistakes: + +* Regular expressions that are not preceded by a left parenthesis, assignment, colon, or comma. +* Statements that are separated by commas instead of semicolons. +* Use of increment (++) and decrement (--) except for simple statements such as "i++;" or "--i;". +* Use of the _void_ type. +* Successive plus (e.g. x+++y) or minus (e.g. x---y) signs. +* Use of labeled _for_ and _while_ loops. +* _if_, _for_, _while_, etc. without curly braces. (This check is disabled by default.) + +Advanced users can also configure JavaScript Lint to check for [undeclared identifiers](docs/). + Property changes on: trunk/www/index.htm ___________________________________________________________________ Added: svn:eol-style + native Added: trunk/www/online_lint.php =================================================================== --- trunk/www/online_lint.php (rev 0) +++ trunk/www/online_lint.php 2009-10-06 16:05:47 UTC (rev 262) @@ -0,0 +1,22 @@ +<!-- +@title=The Online Lint +--> + +Online Lint +=========== + +All warnings except "option explicit" are enabled in this online edition, although certain warnings are displayed only once. For full control over which warnings are displayed, [download the JavaScript Lint software](/download.htm). + +If you encounter any problems, please report them to Matthias Miller at Info<at>JavaScriptLint.com. + + +<form method="POST" action=""> +<p>Paste your JavaScript, HTML, or URL into the box below:</p> +<p> + <textarea name="script" rows="15" cols="75" style="width: 100%"></textarea> +</p> +<p> + <input type="submit" value="Lint"/> + +</p> +</form> Added: trunk/www/static/feed-icon-32x32.png =================================================================== (Binary files differ) Property changes on: trunk/www/static/feed-icon-32x32.png ___________________________________________________________________ Added: svn:mime-type + application/octet-stream Added: trunk/www/static/global.css =================================================================== --- trunk/www/static/global.css (rev 0) +++ trunk/www/static/global.css 2009-10-06 16:05:47 UTC (rev 262) @@ -0,0 +1,71 @@ +body +{ + font-family: Verdana,Arial,Helvetica,sans-serif; + color: #222; + background: #FFF; +} + +#title +{ + border-bottom: 2px solid #669; + color: #669; + font-size: 4em; + margin-bottom: 0.25em; +} + +#nav +{ + float: left; +} + +#nav ul +{ + margin: 0; + padding: 0; +} + +#nav li a +{ + background: #EEF; + color: #000; + border: 1px solid #AAC; + display: block; + text-decoration: none; + margin: 0.25em; + padding: 0.25em; + text-align: center; + -moz-border-radius: 5px; + -webkit-border-radius: 5px; +} + +#nav li a.active +{ + cursor: default; +} + +#nav li a.active, +#nav li a:hover +{ + background: #335; + border-color: #334; + color: #FFF; +} + +h1 +{ + color: #003; +} + +#body +{ + margin-left: 9em; +} + +#footer +{ + color: #666; + font-size: 0.8em; + font-style: italic; + text-align: right; +} + Property changes on: trunk/www/static/global.css ___________________________________________________________________ Added: svn:eol-style + native Added: trunk/www.py =================================================================== --- trunk/www.py (rev 0) +++ trunk/www.py 2009-10-06 16:05:47 UTC (rev 262) @@ -0,0 +1,98 @@ +#!/usr/bin/python +# vim: ts=4 sw=4 expandtab +import BaseHTTPServer +import re +import os +import sys + +import markdown + +DOC_ROOT = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'www') +TEMPLATE_PATH = os.path.join(DOC_ROOT, '__template__') + +NAV = [ + ('/', 'Home'), + ('/download.htm', 'Download'), + ('/online_lint.php', 'The Online Lint'), + ('/docs/', 'Documentation'), + ('/news.php', 'News'), + ('/contact_support.htm', 'Contact'), +] + +def _resolve_url(url): + urls = [ + url.rstrip('/') + '/index.htm', + url + ] + for url in urls: + path = os.path.join(DOC_ROOT, url.lstrip('/')) + if path.startswith(DOC_ROOT + os.sep) and os.path.isfile(path): + return path + +def _get_nav(path): + nav = [] + for url, name in NAV: + navpath = _resolve_url(url) + if navpath and navpath == path: + nav.append('* <a class="active">%s</a>' % name) + else: + nav.append('* [%s](%s)' % (name, url)) + return markdown.markdown('\n'.join(nav)) + +def _transform_file(path): + source = open(path).read() + if path.endswith('.css'): + return 'text/css', source + elif path.endswith('.gif'): + return 'image/gif', source + elif path.endswith('.png'): + return 'image/png', source + elif path.endswith('.htm') or path.endswith('.php'): + body = markdown.markdown(source) + keywords = re.findall(r'^@(\w+)=(.*)$', source, re.MULTILINE) + # TODO: encode + keywords = dict(keywords) + keywords['body'] = body + keywords['nav'] = _get_nav(path) + page = open(TEMPLATE_PATH).read() % keywords + return 'text/html', page + else: + raise ValueError, 'Invalid file type: %s' % path + +class _Handler(BaseHTTPServer.BaseHTTPRequestHandler): + def do_GET(self): + path = _resolve_url(self.path) + if path: + self._send_response(*_transform_file(path)) + else: + self.send_error(404, "File not found") + + def _send_response(self, contenttype, content): + self.send_response(200) + self.send_header("Content-type", contenttype) + self.send_header("Content-length", str(len(content))) + self.end_headers() + self.wfile.write(content) + + +def runserver(): + server_address = ('', 8000) + httpd = BaseHTTPServer.HTTPServer(server_address, _Handler) + httpd.serve_forever() + +def main(action=''): + if action == 'server': + runserver() + return + # TODO: Implement 'build'. + print >>sys.stderr, """\ +Usage: www.py [server|build] + +server runs a test server on localhost +build generates static HTML files from the markup +""" + sys.exit(1) + +if __name__ == '__main__': + main(*sys.argv[1:]) + Property changes on: trunk/www.py ___________________________________________________________________ Added: svn:executable + * Added: svn:eol-style + native This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |