Permalink
Browse files

add jshint

  • Loading branch information...
1 parent 00f3167 commit 6a62f56b2ca9480078b982ca8f5fdfcf843a7255 Russell Haering committed Dec 20, 2011
Showing with 25,608 additions and 0 deletions.
  1. +15 −0 jshint.json
  2. +3 −0 lint.sh
  3. +1 −0 node_modules/.bin/jshint
  4. +3 −0 node_modules/jshint/.gitignore
  5. +3 −0 node_modules/jshint/.gitmodules
  6. +3 −0 node_modules/jshint/.jshintignore
  7. +40 −0 node_modules/jshint/.jshintrc
  8. +9 −0 node_modules/jshint/HELP
  9. +4 −0 node_modules/jshint/LICENSE
  10. +70 −0 node_modules/jshint/README.md
  11. +2 −0 node_modules/jshint/bin/hint
  12. +73 −0 node_modules/jshint/example/config.json
  13. +18 −0 node_modules/jshint/example/reporter.js
  14. +135 −0 node_modules/jshint/lib/cli.js
  15. +108 −0 node_modules/jshint/lib/hint.js
  16. +18 −0 node_modules/jshint/lib/reporters/default.js
  17. +54 −0 node_modules/jshint/lib/reporters/jslint_xml.js
  18. +45 −0 node_modules/jshint/lib/reporters/non_error.js
  19. +34 −0 node_modules/jshint/package.json
  20. +1 −0 node_modules/jshint/packages/jshint/.gitignore
  21. +63 −0 node_modules/jshint/packages/jshint/CHANGELOG
  22. +16 −0 node_modules/jshint/packages/jshint/Makefile
  23. +71 −0 node_modules/jshint/packages/jshint/README.markdown
  24. +57 −0 node_modules/jshint/packages/jshint/env/jsc.js
  25. +29 −0 node_modules/jshint/packages/jshint/env/jsc.sh
  26. +75 −0 node_modules/jshint/packages/jshint/env/rhino.js
  27. +168 −0 node_modules/jshint/packages/jshint/env/wsh.js
  28. +4,311 −0 node_modules/jshint/packages/jshint/jshint.js
  29. +401 −0 node_modules/jshint/packages/jshint/tests/core.js
  30. +514 −0 node_modules/jshint/packages/jshint/tests/envs.js
  31. +28 −0 node_modules/jshint/packages/jshint/tests/fixtures/asi.js
  32. +1,158 −0 node_modules/jshint/packages/jshint/tests/fixtures/backbone.js
  33. +12 −0 node_modules/jshint/packages/jshint/tests/fixtures/boss.js
  34. +11 −0 node_modules/jshint/packages/jshint/tests/fixtures/caseExpressions.js
  35. +72 −0 node_modules/jshint/packages/jshint/tests/fixtures/const.js
  36. +8 −0 node_modules/jshint/packages/jshint/tests/fixtures/curly.js
  37. +11 −0 node_modules/jshint/packages/jshint/tests/fixtures/curly2.js
  38. +23 −0 node_modules/jshint/packages/jshint/tests/fixtures/emptystmt.js
  39. +10 −0 node_modules/jshint/packages/jshint/tests/fixtures/eqeqeq.js
  40. +15 −0 node_modules/jshint/packages/jshint/tests/fixtures/es5.funcexpr.js
  41. +38 −0 node_modules/jshint/packages/jshint/tests/fixtures/es5.js
  42. +15 −0 node_modules/jshint/packages/jshint/tests/fixtures/forin.js
  43. +8 −0 node_modules/jshint/packages/jshint/tests/fixtures/functionScopedOptions.js
  44. +15 −0 node_modules/jshint/packages/jshint/tests/fixtures/immed.js
  45. +8 −0 node_modules/jshint/packages/jshint/tests/fixtures/indent.js
  46. +9,304 −0 node_modules/jshint/packages/jshint/tests/fixtures/jquery-1.7.js
  47. +9 −0 node_modules/jshint/packages/jshint/tests/fixtures/jslintOptions.js
  48. +6 −0 node_modules/jshint/packages/jshint/tests/fixtures/lastsemic.js
  49. +11 −0 node_modules/jshint/packages/jshint/tests/fixtures/latedef.js
  50. +46 −0 node_modules/jshint/packages/jshint/tests/fixtures/latedefundef.js
  51. +19 −0 node_modules/jshint/packages/jshint/tests/fixtures/laxbreak.js
  52. +11 −0 node_modules/jshint/packages/jshint/tests/fixtures/loopfunc.js
  53. +3 −0 node_modules/jshint/packages/jshint/tests/fixtures/maxlen.js
  54. +8 −0 node_modules/jshint/packages/jshint/tests/fixtures/missingspaces.js
  55. +5 −0 node_modules/jshint/packages/jshint/tests/fixtures/newcap.js
  56. +7 −0 node_modules/jshint/packages/jshint/tests/fixtures/noarg.js
  57. +11 −0 node_modules/jshint/packages/jshint/tests/fixtures/onevar.js
  58. +37 −0 node_modules/jshint/packages/jshint/tests/fixtures/protoiterator.js
  59. +6,082 −0 node_modules/jshint/packages/jshint/tests/fixtures/prototype-17.js
  60. +11 −0 node_modules/jshint/packages/jshint/tests/fixtures/redef.js
  61. +40 −0 node_modules/jshint/packages/jshint/tests/fixtures/return.js
  62. +43 −0 node_modules/jshint/packages/jshint/tests/fixtures/scope.js
  63. +11 −0 node_modules/jshint/packages/jshint/tests/fixtures/scripturl.js
  64. +7 −0 node_modules/jshint/packages/jshint/tests/fixtures/smarttabs.js
  65. +59 −0 node_modules/jshint/packages/jshint/tests/fixtures/strict_incorrect.js
  66. +17 −0 node_modules/jshint/packages/jshint/tests/fixtures/strict_this.js
  67. +18 −0 node_modules/jshint/packages/jshint/tests/fixtures/strict_this2.js
  68. +9 −0 node_modules/jshint/packages/jshint/tests/fixtures/strict_violations.js
  69. +16 −0 node_modules/jshint/packages/jshint/tests/fixtures/strings.js
  70. +11 −0 node_modules/jshint/packages/jshint/tests/fixtures/supernew.js
  71. +40 −0 node_modules/jshint/packages/jshint/tests/fixtures/switchFallThrough.js
  72. +24 −0 node_modules/jshint/packages/jshint/tests/fixtures/trycatch.js
  73. +10 −0 node_modules/jshint/packages/jshint/tests/fixtures/undef.js
  74. +6 −0 node_modules/jshint/packages/jshint/tests/fixtures/undefstrict.js
  75. +66 −0 node_modules/jshint/packages/jshint/tests/fixtures/white.js
  76. +1,007 −0 node_modules/jshint/packages/jshint/tests/options.js
  77. +318 −0 node_modules/jshint/packages/jshint/tests/parser.js
  78. +147 −0 node_modules/jshint/packages/jshint/tests/testhelper
  79. +20 −0 node_modules/jshint/test/system/genfiles
  80. +34 −0 node_modules/jshint/test/system/perf.js
  81. +185 −0 node_modules/jshint/test/unit/cli.js
  82. +174 −0 node_modules/jshint/test/unit/hint.js
View
@@ -0,0 +1,15 @@
+{
+ "maxerr" : 100,
+ "node" : true,
+ "curly" : true,
+ "eqeqeq" : true,
+ "latedef" : false,
+ "undef" : true,
+ "newcap" : true,
+ "nonew" : true,
+ "onevar" : false,
+ "trailing" : true,
+ "white" : false,
+ "sub" : true
+}
+
View
@@ -0,0 +1,3 @@
+#!/bin/bash
+
+./node_modules/.bin/jshint $(find ./lib -type f -name "*.js") --config jshint.json
@@ -0,0 +1,3 @@
+tags
+node_modules
+test/system/.files
@@ -0,0 +1,3 @@
+[submodule "packages/jshint"]
+ path = packages/jshint
+ url = git://github.com/jshint/jshint.git
@@ -0,0 +1,3 @@
+node_modules
+packages
+.git
@@ -0,0 +1,40 @@
+{
+ "predef": [
+ "jasmine",
+ "spyOn",
+ "it",
+ "console",
+ "describe",
+ "expect",
+ "beforeEach",
+ "waits",
+ "waitsFor",
+ "runs"
+ ],
+
+ "node" : true,
+ "es5" : true,
+ "browser" : true,
+
+ "boss" : false,
+ "curly": false,
+ "debug": false,
+ "devel": false,
+ "eqeqeq": true,
+ "evil": true,
+ "forin": false,
+ "immed": true,
+ "laxbreak": false,
+ "newcap": true,
+ "noarg": true,
+ "noempty": false,
+ "nonew": false,
+ "nomen": false,
+ "onevar": true,
+ "plusplus": false,
+ "regexp": false,
+ "undef": true,
+ "sub": true,
+ "strict": false,
+ "white": true
+}
@@ -0,0 +1,9 @@
+Usage: jshint path path2 [options]
+
+Options:
+
+ --version display package version
+ --config custom config file
+ --reporter custom reporter
+ --jslint-reporter use a jslint compatible xml reporter
+ --show-non-errors show additional data generated by jshint
@@ -0,0 +1,4 @@
+** Licensed Under **
+
+ The MIT License
+ http://www.opensource.org/licenses/mit-license.php
@@ -0,0 +1,70 @@
+# node-jshint
+
+A command line interface and npm package for jshint.
+
+## Install
+
+To use jshint from any location (for npm v1.x) you need to install using the global (-g) flag.
+
+ npm install -g jshint
+
+## Usage
+
+The command line interface looks like this.
+
+ jshint path path2 [options]
+
+You can also require JSHint itself as a module.
+
+ var jshint = require('jshint');
+
+Note: If you are using npm v1.x be sure to install jshint locally (without the -g flag) or link it globally.
+
+## Text Editor Plugins
+
+* [gedit-node-jshint](https://github.com/niftylettuce/gedit-node-jshint) - Simply use CTRL+J in gedit to run JSHint using `node-jshint`.
+* [vim syntastic](https://github.com/scrooloose/syntastic) - Run node-jshint at each file save.
+
+## Custom Reporters
+
+Specify a custom reporter module (see example/reporter.js).
+
+ --reporter path/to/reporter.js
+
+Use a jslint compatible xml reporter.
+
+ --jslint-reporter
+
+Show additional non-error data generated by jshint (unused globals etc).
+
+ --show-non-errors
+
+## Custom Options
+
+Specify custom lint options (see [example/config.json](https://github.com/jshint/node-jshint/blob/master/example/config.json)).
+
+ --config path/to/config.json
+
+Note: This bypasses any .jshintrc files.
+
+## Default Options
+
+The CLI uses the default options that come with JSHint. However, if it locates a .jshintrc file in your home directory (~/) it will use those options first.
+
+## Per Directory Options
+
+If there is a .jshintrc file in the current working directory, any of those options will take precedence over (or be merged with) any options found in the ~/.jshintrc file (if it exists).
+
+## Ignoring Files and Directories
+
+If there is a .jshintignore file in the current working directory, then any directories or files will be skipped over.
+
+Note: Pattern matching uses minimatch, with the nocase [option](https://github.com/isaacs/minimatch). When there is no match, it performs a left side match (when no forward slashes present and path is a directory).
+
+## Installing dependencies for development
+
+ ./configure
+
+## Build Commands
+
+ jake -T
@@ -0,0 +1,2 @@
+#!/usr/bin/env node
+require('./../lib/cli').interpret(process.argv);
@@ -0,0 +1,73 @@
+{
+ // Settings
+ "passfail" : false, // Stop on first error.
+ "maxerr" : 100, // Maximum error before stopping.
+
+
+ // Predefined globals whom JSHint will ignore.
+ "browser" : true, // Standard browser globals e.g. `window`, `document`.
+
+ "node" : false,
+ "rhino" : false,
+ "couch" : false,
+ "wsh" : true, // Windows Scripting Host.
+
+ "jquery" : true,
+ "prototypejs" : false,
+ "mootools" : false,
+ "dojo" : false,
+
+ "predef" : [ // Custom globals.
+ //"exampleVar",
+ //"anotherCoolGlobal",
+ //"iLoveDouglas"
+ ],
+
+
+ // Development.
+ "debug" : false, // Allow debugger statements e.g. browser breakpoints.
+ "devel" : true, // Allow developments statements e.g. `console.log();`.
+
+
+ // ECMAScript 5.
+ "es5" : true, // Allow ECMAScript 5 syntax.
+ "strict" : false, // Require `use strict` pragma in every file.
+ "globalstrict" : false, // Allow global "use strict" (also enables 'strict').
+
+
+ // The Good Parts.
+ "asi" : false, // Tolerate Automatic Semicolon Insertion (no semicolons).
+ "laxbreak" : true, // Tolerate unsafe line breaks e.g. `return [\n] x` without semicolons.
+ "bitwise" : true, // Prohibit bitwise operators (&, |, ^, etc.).
+ "boss" : false, // Tolerate assignments inside if, for & while. Usually conditions & loops are for comparison, not assignments.
+ "curly" : true, // Require {} for every new block or scope.
+ "eqeqeq" : true, // Require triple equals i.e. `===`.
+ "eqnull" : false, // Tolerate use of `== null`.
+ "evil" : false, // Tolerate use of `eval`.
+ "expr" : false, // Tolerate `ExpressionStatement` as Programs.
+ "forin" : false, // Tolerate `for in` loops without `hasOwnPrototype`.
+ "immed" : true, // Require immediate invocations to be wrapped in parens e.g. `( function(){}() );`
+ "latedef" : true, // Prohipit variable use before definition.
+ "loopfunc" : false, // Allow functions to be defined within loops.
+ "noarg" : true, // Prohibit use of `arguments.caller` and `arguments.callee`.
+ "regexp" : true, // Prohibit `.` and `[^...]` in regular expressions.
+ "regexdash" : false, // Tolerate unescaped last dash i.e. `[-...]`.
+ "scripturl" : true, // Tolerate script-targeted URLs.
+ "shadow" : false, // Allows re-define variables later in code e.g. `var x=1; x=2;`.
+ "supernew" : false, // Tolerate `new function () { ... };` and `new Object;`.
+ "undef" : true, // Require all non-global variables be declared before they are used.
+
+
+ // Personal styling preferences.
+ "newcap" : true, // Require capitalization of all constructor functions e.g. `new F()`.
+ "noempty" : true, // Prohibit use of empty blocks.
+ "nonew" : true, // Prohibit use of constructors for side-effects.
+ "nomen" : true, // Prohibit use of initial or trailing underbars in names.
+ "onevar" : false, // Allow only one `var` statement per function.
+ "plusplus" : false, // Prohibit use of `++` & `--`.
+ "sub" : false, // Tolerate all forms of subscript notation besides dot notation e.g. `dict['key']` instead of `dict.key`.
+ "trailing" : true, // Prohibit trailing whitespaces.
+ "white" : true, // Check against strict whitespace and indentation rules.
+ "indent" : 4 // Specify indentation spacing
+}
+
@@ -0,0 +1,18 @@
+module.exports = {
+ reporter: function reporter(results) {
+ var len = results.length,
+ str = '',
+ file, error;
+
+ results.forEach(function (result) {
+ file = result.file;
+ error = result.error;
+ str += file + ': line ' + error.line + ', col ' +
+ error.character + ', ' + error.reason + '\n';
+ });
+
+ if (str) {
+ process.stdout.write(str + "\n" + len + ' error' + ((len === 1) ? '' : 's') + "\n");
+ }
+ }
+};
@@ -0,0 +1,135 @@
+var fs = require('fs'),
+ path = require('path'),
+ argsparser = require('argsparser'),
+ hint = require('./hint');
+
+function _help() {
+ process.stdout.write(fs.readFileSync(__dirname + "/../HELP", "utf-8"));
+}
+
+function _version() {
+ process.stdout.write(JSON.parse(fs.readFileSync(__dirname + "/../package.json", "utf-8")).version + "\n");
+}
+
+function _removeJsComments(str) {
+ str = str || '';
+ str = str.replace(/\/\*[\s\S]*(?:\*\/)/g, ''); //everything between "/* */"
+ str = str.replace(/\/\/[^\n\r]*/g, ''); //everything after "//"
+ return str;
+}
+
+function _loadAndParseConfig(filePath) {
+ return path.existsSync(filePath) ?
+ JSON.parse(_removeJsComments(fs.readFileSync(filePath, "utf-8"))) : {};
+}
+
+function _mergeConfigs(homerc, cwdrc) {
+ var homeConfig = _loadAndParseConfig(homerc),
+ cwdConfig = _loadAndParseConfig(cwdrc),
+ prop;
+
+ for (prop in cwdConfig) {
+ if (typeof prop === 'string') {
+ if (prop === 'predef') {
+ homeConfig.predef = (homeConfig.predef || []).concat(cwdConfig.predef);
+ } else {
+ homeConfig[prop] = cwdConfig[prop];
+ }
+ }
+ }
+
+ return homeConfig;
+}
+
+function _print(results) {
+ function exit() {
+ process.exit(results.length > 0 ? 1 : 0);
+ }
+
+ // avoid stdout cutoff in node 0.4.x, also supports 0.5.x
+ // see https://github.com/joyent/node/issues/1669
+ try {
+ if (!process.stdout.flush()) {
+ process.stdout.once("drain", exit);
+ } else {
+ exit();
+ }
+ } catch (e) {
+ exit();
+ }
+}
+
+module.exports = {
+ interpret: function (args) {
+ var config, reporter, ignore,
+ options = argsparser.parse(args),
+ pathsToIgnore = path.join(process.cwd(), '.jshintignore'),
+ defaultConfig = path.join(process.env.HOME, '.jshintrc'),
+ projectConfig = path.join(process.cwd(), '.jshintrc'),
+ customConfig = options["--config"],
+ customReporter = options["--reporter"] ? path.resolve(process.cwd(), options["--reporter"]) : null,
+ targets = options.node;
+
+ //could be on Windows which we are looking for an attribute ending in 'node.exe'
+ if (targets === undefined) {
+ (function () {
+ var arg;
+
+ for (arg in options) {
+ if (path.basename(arg) === 'node.exe') {
+ targets = options[arg];
+ break;
+ }
+ }
+ }());
+ }
+
+ targets = typeof targets === "string" ? null : targets.slice(1);
+
+
+ if (options["--version"]) {
+ _version();
+ return;
+ }
+
+ if (!targets || options["--help"]) {
+ _help();
+ return;
+ }
+
+ if (options["--jslint-reporter"]) {
+ customReporter = "./reporters/jslint_xml.js";
+ }
+
+ if (options["--show-non-errors"]) {
+ customReporter = "./reporters/non_error.js";
+ }
+
+ if (customConfig) {
+ config = _loadAndParseConfig(customConfig);
+ } else {
+ config = _mergeConfigs(defaultConfig, projectConfig);
+ }
+
+ if (customReporter) {
+ try {
+ reporter = require(customReporter).reporter;
+ } catch (r) {
+ process.stdout.write("Error opening reporter file: " + customReporter);
+ process.stdout.write(r + "\n");
+ process.exit(1);
+ }
+ }
+
+ if (path.existsSync(pathsToIgnore)) {
+ ignore = fs.readFileSync(pathsToIgnore, "utf-8").split("\n").map(function (line) {
+ return line.trim();
+ }).filter(function (line) {
+ return !!line;
+ });
+ }
+
+ _print(hint.hint(targets, config, reporter, ignore));
+ }
+};
+
Oops, something went wrong.

0 comments on commit 6a62f56

Please sign in to comment.