├── .editorconfig ├── .gitignore ├── README.md ├── package.json ├── LICENSE ├── index.js ├── test └── index.js ├── lib └── jshint │ ├── index.js │ ├── jshintRulesMap.js │ └── options.js └── .eslintrc /.editorconfig: -------------------------------------------------------------------------------- 1 | # http://editorconfig.org 2 | 3 | root = true 4 | 5 | [*] 6 | charset = utf-8 7 | indent_style = space 8 | indent_size = 2 9 | end_of_line = lf 10 | insert_final_newline = true 11 | trim_trailing_whitespace = true -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .idea/ 2 | .DS_Store 3 | .sass-cache/ 4 | node_modules/ 5 | logs 6 | newrelic_agent.log 7 | pre-commit 8 | npm-debug.log 9 | 10 | coverage 11 | config.codekit 12 | 13 | dump* 14 | migrations/.migrate 15 | mj.web/public/index.html -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # UNMAINTAINED eslint-rules-mapper 2 | [![Dependency Status](https://david-dm.org/valorkin/eslint-rules-mapper.svg)](https://david-dm.org/valorkin/eslint-rules-mapper) 3 | [![Dev dependency Status](https://david-dm.org/valorkin/eslint-rules-mapper/dev-status.svg)](https://david-dm.org/valorkin/eslint-rules-mapper#info=devDependencies) 4 | 5 | Converts .jshintrc files to eslint configuration 6 | 7 | ```sh 8 | npm install -g eslint-rules-mapper 9 | 10 | eslint-rules-mapper ./path/to/.jshintrc > ./.eslintrc 11 | ``` 12 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "eslint-rules-mapper", 3 | "version": "0.1.0", 4 | "description": "map jshint or jscs rules configs to eslint", 5 | "main": "index.js", 6 | "scripts": { 7 | "test": "node test" 8 | }, 9 | "bin": { 10 | "eslint-rules-mapper": "index.js" 11 | }, 12 | "repository": { 13 | "type": "git", 14 | "url": "git@github.com:valorkin/eslint-rules-mapper.git" 15 | }, 16 | "keywords": [ 17 | "eslint", 18 | "jshint", 19 | "jscs" 20 | ], 21 | "author": "valorkin ", 22 | "license": "MIT", 23 | "bugs": { 24 | "url": "https://github.com/valorkin/eslint-rules-mapper/issues" 25 | }, 26 | "homepage": "https://github.com/valorkin/eslint-rules-mapper", 27 | "dependencies": { 28 | "eslint": "^0.22.0", 29 | "lodash": "^3.9.0", 30 | "strip-json-comments": "^1.0.2" 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2015 Dmitriy Schekhovtsov 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | 23 | -------------------------------------------------------------------------------- /index.js: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env node 2 | var fs = require('fs'); 3 | var _ = require('lodash'); 4 | var stripJsonComments = require('strip-json-comments'); 5 | var map = require('./lib/jshint').map; 6 | 7 | // Parse file path to jshintrc file 8 | var args = process.argv.slice(2); 9 | var jshintFilePath = args[0]; 10 | 11 | // Check if argument exists 12 | if (!jshintFilePath) { 13 | console.log('Please specify the path to your .jshintrc file'); 14 | process.exit(1); 15 | } 16 | 17 | // Chefk if .jshintrc file exists 18 | if (!fs.existsSync(jshintFilePath)) { 19 | console.log('The .jshintrc file specified does not exist'); 20 | process.exit(1); 21 | } 22 | 23 | // Read jshintrc file 24 | var jshintContents = fs.readFileSync(jshintFilePath); 25 | var jshintRules = JSON.parse(stripJsonComments(jshintContents)); 26 | 27 | // Disable console.log statements before running this, to ensure we can pipe results only 28 | console.log = function noop() {}; 29 | 30 | // Convert to eslint json 31 | var eslintResult = map(jshintRules); 32 | var eslintEnv = eslintResult.env; 33 | var eslintGlobals = eslintResult.globals || {}; 34 | var eslintRules = sortObject(_.omit(eslintResult, 'env', 'globals')); 35 | var eslintJson = { 36 | env: eslintEnv, 37 | globals: eslintGlobals, 38 | rules: eslintRules 39 | }; 40 | 41 | // Write output to stdout 42 | var output = JSON.stringify(eslintJson, null, 2); 43 | process.stdout.write(output); 44 | 45 | /** 46 | * Sorts the keys in an object. 47 | */ 48 | function sortObject(obj) { 49 | var keys = Object.keys(obj); 50 | var sortedKeys = keys.sort(); 51 | var sortedObj = {}; 52 | 53 | sortedKeys.forEach(function x(key) { 54 | sortedObj[key] = obj[key]; 55 | }); 56 | 57 | return sortedObj; 58 | } 59 | -------------------------------------------------------------------------------- /test/index.js: -------------------------------------------------------------------------------- 1 | /*eslint no-console:0, no-inline-comments:0, max-statements:0*/ 2 | var map = require('../lib/jshint').map; 3 | 4 | var jshintRules = { 5 | bitwise: true, // Prohibits the use of bitwise operators such as ^ (XOR), | (OR) 6 | camelcase: true, // Force all variable names to use either camelCase style or UPPER_CASE with underscores 7 | curly: true, // Require {} for every new block or scope 8 | eqeqeq: true, // Require triple equals (===) for comparison 9 | forin: true, // Requires all for in loops to filter object's items 10 | freeze: true, 11 | immed: true, // Require immediate invocations to be wrapped in parens e.g. `(function () { } ());` 12 | indent: 2, // Enforces specific tab width for your code 13 | latedef: 'nofunc', // Require variables/functions to be defined before being used 14 | maxcomplexity: 5, 15 | maxdepth: 3, 16 | maxlen: 120, 17 | // maxparams: 3, 18 | maxstatements: 15, 19 | newcap: true, // Require capitalization of all constructor functions e.g. `new F()` 20 | noarg: true, // Prohibit use of `arguments.caller` and `arguments.callee` 21 | //nocomma: true, // works incorectly 22 | noempty: true, // Warns when you have an empty block in your code 23 | nonbsp: true, 24 | nonew: true, 25 | strict: false, // Requires all functions to run in ECMAScript 5's strict mode 26 | trailing: true, // Makes it an error to leave a trailing whitespace in your code 27 | quotmark: 'single', // Enforces the consistency of quotation marks 28 | undef: true, // Require all non-global variables to be declared (prevents global leaks) 29 | unused: true, // Warns when you define and never use your variables 30 | 31 | eqnull: false, 32 | expr: true, 33 | funcscope: true, 34 | 35 | browser: true, // browser 36 | jquery: true, // jQuery, $ 37 | mocha: true, // bdd globals: describe, it, before, after ... 38 | node: true, // node.js 39 | 40 | globals: { 41 | _: true, // lodash 42 | d3: true, // d3 43 | angular: false, // angular.js 44 | io: true, // socket.io 45 | moment: true // moment.js 46 | } 47 | }; 48 | 49 | var util = require('util'); 50 | console.log(util.inspect(map(jshintRules))); 51 | -------------------------------------------------------------------------------- /lib/jshint/index.js: -------------------------------------------------------------------------------- 1 | /*eslint no-console:0, no-inline-comments:0, max-statements:0*/ 2 | var _ = require('lodash'); 3 | 4 | var rulesMap = require('./jshintRulesMap'); 5 | 6 | module.exports.map = map; 7 | 8 | function map(jshintConf) { 9 | if (!jshintConf) { 10 | throw new Error('JSHint config is required!'); 11 | } 12 | 13 | var enforceAll = jshintConf.enforceall; 14 | 15 | var result = {globals: jshintConf.globals}; 16 | 17 | _.reduce(rulesMap, mapJsHintRulesToEsLintRules, result); 18 | 19 | return result; 20 | 21 | function mapJsHintRulesToEsLintRules(res, eslintRule, key) { 22 | var val = jshintConf[key]; 23 | 24 | if (enforceAll && _.isBoolean(val)) { 25 | val = true; 26 | } 27 | 28 | // skip relaxing options in enforce mode 29 | if (enforceAll && eslintRule.isRelaxing) { 30 | return res; 31 | } 32 | 33 | // report not supported properties 34 | if (eslintRule.notSupported) { 35 | if (typeof val !== 'undefined') { 36 | console.log('Unsupported jshint rule: ' + key); 37 | } 38 | 39 | return res; 40 | } 41 | 42 | // value options 43 | if (eslintRule.opts === 'inherit') { 44 | if (!val) { 45 | return res; 46 | } 47 | 48 | if (!_.isNumber(val)) { 49 | throw new Error('Incorrect value for ' + key + 50 | ', expected Number, got: ' + val); 51 | } 52 | 53 | if (key === 'maxlen') { 54 | res[eslintRule.name] = [2, val, jshintConf.indent || 2]; 55 | return res; 56 | } 57 | 58 | res[eslintRule.name] = [2, val]; 59 | return res; 60 | } 61 | 62 | if (eslintRule.map) { 63 | res[eslintRule.name] = eslintRule.map(val); 64 | return res; 65 | } 66 | 67 | // is rule enabled 68 | var isRuleEnabled = isEnabled(val); 69 | 70 | // skip disabled relaxing rules 71 | if (eslintRule.isRelaxing && isRuleEnabled !== 2) { 72 | return res; 73 | } 74 | 75 | if (_.isFunction(eslintRule)) { 76 | var rule = eslintRule(val); 77 | res[rule.name] = isRuleEnabled; 78 | return res; 79 | } 80 | 81 | if (_.isNumber(eslintRule.opts)) { 82 | res[eslintRule.name] = isRuleEnabled; 83 | return res; 84 | } 85 | 86 | if (_.isArray(eslintRule.opts)) { 87 | var opts = eslintRule.opts.slice(); 88 | if (!eslintRule.isRelaxing) { 89 | opts[0] = isRuleEnabled; 90 | } 91 | 92 | res[eslintRule.name] = opts; 93 | return res; 94 | } 95 | 96 | // environment variables 97 | if (eslintRule.isEnv) { 98 | res.env = res.env || {}; 99 | res.env[eslintRule.name] = val !== false; 100 | return res; 101 | } 102 | 103 | console.log(key, val, eslintRule); 104 | console.log('Unhandled jshint rule: ' + key); 105 | 106 | function isEnabled(v) { return v === false ? 0 : 2; } 107 | } 108 | } 109 | -------------------------------------------------------------------------------- /.eslintrc: -------------------------------------------------------------------------------- 1 | { 2 | "env": { 3 | "browser": 2, 4 | "node": true, 5 | "mocha": 2 6 | }, 7 | "globals": { 8 | "_": 2, 9 | "$": 2, 10 | "angular": 2, 11 | "jQuery": 2 12 | }, 13 | "rules": { 14 | // Possible Errors 15 | "no-comma-dangle": 2, 16 | // except-parens, always 17 | "no-cond-assign": [2, "always"], 18 | "no-console": 0, 19 | "no-constant-condition": 2, 20 | "no-control-regex": 2, 21 | "no-debugger": 2, 22 | "no-dupe-keys": 2, 23 | "no-empty": 2, 24 | "no-empty-class": 2, 25 | "no-ex-assign": 2, 26 | "no-extra-boolean-cast": 2, 27 | "no-extra-parens": 2, 28 | "no-extra-semi": 2, 29 | "no-func-assign": 2, 30 | "no-inner-declarations": 2, 31 | "no-invalid-regexp": 2, 32 | "no-irregular-whitespace": 2, 33 | "no-negated-in-lhs": 2, 34 | "no-obj-calls": 2, 35 | "no-regex-spaces": 2, 36 | "no-sparse-arrays": 2, 37 | "no-unreachable": 2, 38 | "use-isnan": 2, 39 | "valid-jsdoc": 0, 40 | "valid-typeof": 2, 41 | 42 | // Best Practices 43 | "block-scoped-var": 2, 44 | "complexity": 5, 45 | "consistent-return": 2, 46 | "curly": 2, 47 | "default-case": 2, 48 | // [2, {"allowKeywords": true}] 49 | "dot-notation": 2, 50 | "eqeqeq": 2, 51 | "guard-for-in": 2, 52 | "no-alert": 2, 53 | "no-caller": 2, 54 | "no-div-regex": 2, 55 | "no-else-return": 2, 56 | "no-empty-label": 2, 57 | "no-eq-null": 2, 58 | "no-eval": 2, 59 | "no-extend-native": 2, 60 | "no-extra-bind": 2, 61 | "no-fallthrough": 2, 62 | "no-floating-decimal": 2, 63 | "no-implied-eval": 2, 64 | "no-iterator": 2, 65 | "no-labels": 2, 66 | "no-lone-blocks": 2, 67 | "no-loop-func": 2, 68 | "no-multi-spaces": 2, 69 | "no-multi-str": 2, 70 | "no-native-reassign": 2, 71 | "no-new": 2, 72 | "no-new-func": 2, 73 | "no-new-wrappers": 2, 74 | "no-octal": 2, 75 | "no-octal-escape": 2, 76 | "no-process-env": 2, 77 | "no-proto": 2, 78 | "no-redeclare": 2, 79 | "no-return-assign": 2, 80 | "no-script-url": 2, 81 | "no-self-compare": 2, 82 | "no-sequences": 2, 83 | "no-unused-expressions": 2, 84 | "no-void": 2, 85 | "no-warning-comments": [1, { "terms": ["todo", "fixme", "any other term"], "location": "anywhere" }], 86 | "no-with": 2, 87 | "radix": 2, 88 | "wrap-iife": [2, "inside"], 89 | "yoda": "never", 90 | 91 | "strict": false, 92 | "no-extra-strict": 2, 93 | 94 | // Variables 95 | "no-catch-shadow": 2, 96 | "no-delete-var": 2, 97 | "no-label-var": 2, 98 | "no-shadow": 2, 99 | "no-shadow-restricted-names": 2, 100 | "no-undef": 2, 101 | "no-undef-init": 2, 102 | "no-undefined": 2, 103 | "no-unused-vars": 2, 104 | "no-use-before-define": "nofunc", 105 | 106 | // Node.js 107 | "handle-callback-err": [2, "^.*(e|E)rr" ], 108 | "no-mixed-requires": [1, 2], 109 | "no-new-require": 2, 110 | "no-path-concat": 2, 111 | "no-process-exit": 0, 112 | "no-sync": 0, 113 | 114 | // Stylistic Issues 115 | "brace-style": [2, "1tbs", { "allowSingleLine": true }], 116 | "camelcase": 2, 117 | "comma-spacing": [2, {"before": false, "after": true}], 118 | "comma-style": [2, "last"], 119 | "consistent-this": [1, "self"], 120 | // not sure 121 | "eol-last": 0, 122 | "func-names": 2, 123 | "func-style": [2, "declaration"], 124 | "key-spacing": [2, { "beforeColon": false, "afterColon": true}], 125 | "max-nested-callbacks": [2, 3], 126 | "new-cap": [2, {"newIsCap": true, "capIsNew": true, "capIsNewExceptions":[ 127 | "Object", 128 | "Function", 129 | "Number", 130 | "String", 131 | "Boolean", 132 | "Date", 133 | "Array", 134 | "Symbol", 135 | "RegExp" 136 | ]}], 137 | "new-parens": 2, 138 | "no-array-constructor": 2, 139 | "no-inline-comments": 2, 140 | "no-mixed-spaces-and-tabs": 2, 141 | "no-multiple-empty-lines": [2, {"max": 1}], 142 | "no-nested-ternary": 2, 143 | "no-new-object": 2, 144 | "no-space-before-semi": 2, 145 | "no-spaced-func": 2, 146 | "no-underscore-dangle": false, 147 | "no-trailing-spaces": 2, 148 | "no-wrap-func": 2, 149 | "operator-assignment": [2, "always"], 150 | "padded-blocks": [2, "never"], 151 | // not sure 152 | "quote-props": [2, "as-needed"], 153 | // not sure 154 | "quotes": [2, "single", "avoid-escape"], 155 | "semi": [2, "always"], 156 | // "sort-vars": [1, { "ignoreCase": true }], 157 | "space-after-function-name": [2, "never"], 158 | "space-after-keywords": [2, "always", { "checkFunctionKeyword": true } ], 159 | "space-before-blocks": [2, "always"], 160 | "space-in-brackets": [2, "never"], 161 | "space-in-parens": [2, "never"], 162 | "space-return-throw-case": 2, 163 | "space-unary-ops": [2, { "words": true, "nonwords": false }], 164 | 165 | // Legacy 166 | "max-len": [1, 120, 4], 167 | "max-params": [2, 3], 168 | "max-statements": [2, 20], 169 | "no-bitwise": 2 170 | } 171 | } 172 | -------------------------------------------------------------------------------- /lib/jshint/jshintRulesMap.js: -------------------------------------------------------------------------------- 1 | /** 2 | * This option tells JSHint that your code needs to adhere to ECMAScript 3 3 | * specification. Use this option if you need your program to be executable 4 | * in older browsers—such as Internet Explorer 6/7/8/9—and other legacy 5 | * JavaScript environments. 6 | */ 7 | //es3 : true, 8 | 9 | /** 10 | * This option enables syntax first defined in [the ECMAScript 5.1 11 | * specification](http://es5.github.io/). This includes allowing reserved 12 | * keywords as object properties. 13 | */ 14 | //es5 : true, 15 | 16 | module.exports = { 17 | /** 18 | * This option prohibits the use of bitwise operators such as `^` (XOR), 19 | * `|` (OR) and others. Bitwise operators are very rare in JavaScript 20 | * programs and quite often `&` is simply a mistyped `&&`. 21 | */ 22 | bitwise: {name: 'no-bitwise', opts: 2}, 23 | 24 | /** 25 | * This option allows you to force all variable names to use either 26 | * camelCase style or UPPER_CASE with underscores. 27 | */ 28 | camelcase: {name: 'camelcase', opts: 2}, 29 | 30 | /** 31 | * This option requires you to always put curly braces around blocks in 32 | * loops and conditionals. JavaScript allows you to omit curly braces when 33 | * the block consists of only one statement, for example: 34 | * 35 | * while (day) 36 | * shuffle(); 37 | * 38 | * However, in some circumstances, it can lead to bugs (you'd think that 39 | * `sleep()` is a part of the loop while in reality it is not): 40 | * 41 | * while (day) 42 | * shuffle(); 43 | * sleep(); 44 | */ 45 | curly: {name: 'curly', opts: [2, 'all']}, 46 | 47 | // should I apply def rules here? 48 | /** 49 | * This option is a short hand for the most strict JSHint configuration. It 50 | * enables all enforcing options and disables all relaxing options. 51 | */ 52 | //enforceall: false, 53 | 54 | /** 55 | * This options prohibits the use of `==` and `!=` in favor of `===` and 56 | * `!==`. The former try to coerce values before comparing them which can 57 | * lead to some unexpected results. The latter don't do any coercion so 58 | * they are generally safer. If you would like to learn more about type 59 | * coercion in JavaScript, we recommend [Truth, Equality and 60 | * JavaScript](http://javascriptweblog.wordpress.com/2011/02/07/truth-equality-and-javascript/) 61 | * by Angus Croll. 62 | */ 63 | eqeqeq: {name: 'eqeqeq', opts: [2]}, 64 | 65 | /** 66 | * This option requires all `for in` loops to filter object's items. The 67 | * for in statement allows for looping through the names of all of the 68 | * properties of an object including those inherited through the prototype 69 | * chain. This behavior can lead to unexpected items in your object so it 70 | * is generally safer to always filter inherited properties out as shown in 71 | * the example: 72 | * 73 | * for (key in obj) { 74 | * if (obj.hasOwnProperty(key)) { 75 | * // We are sure that obj[key] belongs to the object and was not inherited. 76 | * } 77 | * } 78 | * 79 | * For more in-depth understanding of `for in` loops in JavaScript, read 80 | * [Exploring JavaScript for-in 81 | * loops](http://javascriptweblog.wordpress.com/2011/01/04/exploring-javascript-for-in-loops/) 82 | * by Angus Croll. 83 | */ 84 | forin: {name: 'guard-for-in', opts: 2}, 85 | 86 | /** This options prohibits overwriting prototypes of native objects such as 87 | * `Array`, `Date` and so on. 88 | * 89 | * // jshint freeze:true 90 | * Array.prototype.count = function (value) { return 4; }; 91 | * // -> Warning: Extending prototype of native object: 'Array'. 92 | */ 93 | freeze: {name: 'no-extend-native', opts: 2}, 94 | 95 | /** 96 | * This option prohibits the use of immediate function invocations without 97 | * wrapping them in parentheses. Wrapping parentheses assists readers of 98 | * your code in understanding that the expression is the result of a 99 | * function, and not the function itself. 100 | */ 101 | immed: {name: 'wrap-iife', opts: [2, 'inside']}, 102 | 103 | /** 104 | * This option prohibits the use of a variable before it was defined. 105 | * JavaScript has function scope only and, in addition to that, all variables 106 | * are always moved—or hoisted— to the top of the function. This behavior can 107 | * lead to some very nasty bugs and that's why it is safer to always use 108 | * variable only after they have been explicitly defined. 109 | * 110 | * Setting this option to "nofunc" will allow function declarations to be 111 | * ignored. 112 | * 113 | * For more in-depth understanding of scoping and hoisting in JavaScript, 114 | * read [JavaScript Scoping and 115 | * Hoisting](http://www.adequatelygood.com/2010/2/JavaScript-Scoping-and-Hoisting) 116 | * by Ben Cherry. 117 | */ 118 | latedef: { 119 | name: 'no-use-before-define', 120 | opts: [0], 121 | map: function map(v) { 122 | return v === 'nofunc' ? [2, 'nofunc'] : v; 123 | } 124 | }, 125 | 126 | /** 127 | * This option lets you control cyclomatic complexity throughout your code. 128 | * Cyclomatic complexity measures the number of linearly independent paths 129 | * through a program's source code. Read more about [cyclomatic complexity on 130 | * Wikipedia](http://en.wikipedia.org/wiki/Cyclomatic_complexity). 131 | */ 132 | maxcomplexity: {name: 'complexity', opts: 'inherit'}, 133 | 134 | /** 135 | * This option lets you control how nested do you want your blocks to be: 136 | * 137 | * // jshint maxdepth:2 138 | * 139 | * function main(meaning) { 140 | * var day = true; 141 | * 142 | * if (meaning === 42) { 143 | * while (day) { 144 | * shuffle(); 145 | * 146 | * if (tired) { // JSHint: Blocks are nested too deeply (3). 147 | * sleep(); 148 | * } 149 | * } 150 | * } 151 | * } 152 | */ 153 | maxdepth: {name: 'max-depth', opts: 'inherit'}, 154 | 155 | /** 156 | * This option lets you set the maximum length of a line. 157 | */ 158 | maxlen: {name: 'max-len', opts: 'inherit', default: [2, 'inherit', 'indent']}, 159 | 160 | /** 161 | * This option lets you set the max number of formal parameters allowed per 162 | * function: 163 | * 164 | * // jshint maxparams:3 165 | * 166 | * function login(request, onSuccess) { 167 | * // ... 168 | * } 169 | * 170 | * // JSHint: Too many parameters per function (4). 171 | * function logout(request, isManual, whereAmI, onSuccess) { 172 | * // ... 173 | * } 174 | */ 175 | maxparams: {name: 'max-params', opts: 'inherit'}, 176 | 177 | /** 178 | * This option lets you set the max number of statements allowed per function: 179 | * 180 | * // jshint maxstatements:4 181 | * 182 | * function main() { 183 | * var i = 0; 184 | * var j = 0; 185 | * 186 | * // Function declarations count as one statement. Their bodies 187 | * // don't get taken into account for the outer function. 188 | * function inner() { 189 | * var i2 = 1; 190 | * var j2 = 1; 191 | * 192 | * return i2 + j2; 193 | * } 194 | * 195 | * j = i + j; 196 | * return j; // JSHint: Too many statements per function. (5) 197 | * } 198 | */ 199 | maxstatements: {name: 'max-statements', opts: 'inherit'}, 200 | 201 | /** 202 | * This option requires you to capitalize names of constructor functions. 203 | * Capitalizing functions that are intended to be used with `new` operator 204 | * is just a convention that helps programmers to visually distinguish 205 | * constructor functions from other types of functions to help spot 206 | * mistakes when using `this`. 207 | * 208 | * Not doing so won't break your code in any browsers or environments but 209 | * it will be a bit harder to figure out—by reading the code—if the 210 | * function was supposed to be used with or without new. And this is 211 | * important because when the function that was intended to be used with 212 | * `new` is used without it, `this` will point to the global object instead 213 | * of a new object. 214 | */ 215 | newcap: {name: 'new-cap', opts: 2}, 216 | 217 | /** 218 | * This option prohibits the use of `arguments.caller` and 219 | * `arguments.callee`. Both `.caller` and `.callee` make quite a few 220 | * optimizations impossible so they were deprecated in future versions of 221 | * JavaScript. In fact, ECMAScript 5 forbids the use of `arguments.callee` 222 | * in strict mode. 223 | */ 224 | noarg: {name: 'no-caller', opts: 2}, 225 | 226 | /** 227 | * This option prohibits the use of the comma operator. When misused, the 228 | * comma operator can obscure the value of a statement and promote 229 | * incorrect code. 230 | */ 231 | nocomma: {name: 'no-sequences', opts: 2}, 232 | 233 | /** 234 | * This option warns when you have an empty block in your code. JSLint was 235 | * originally warning for all empty blocks and we simply made it optional. 236 | * There were no studies reporting that empty blocks in JavaScript break 237 | * your code in any way. 238 | */ 239 | noempty: {name: 'no-empty', opts: 2}, 240 | 241 | /** 242 | * This option warns about "non-breaking whitespace" characters. These 243 | * characters can be entered with option-space on Mac computers and have a 244 | * potential of breaking non-UTF8 web pages. 245 | */ 246 | nonbsp: {name: 'no-irregular-whitespace', opts: 2}, 247 | 248 | /** 249 | * This option prohibits the use of constructor functions for side-effects. 250 | * Some people like to call constructor functions without assigning its 251 | * result to any variable: 252 | * 253 | * new MyConstructor(); 254 | * 255 | * There is no advantage in this approach over simply calling 256 | * `MyConstructor` since the object that the operator `new` creates isn't 257 | * used anywhere so you should generally avoid constructors like this one. 258 | */ 259 | nonew: {name: 'no-new', opts: 2}, 260 | 261 | /** 262 | * This option suppresses warnings about invalid `typeof` operator values. 263 | * This operator has only [a limited set of possible return 264 | * values](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/typeof). 265 | * By default, JSHint warns when you compare its result with an invalid 266 | * value which often can be a typo. 267 | * 268 | * // 'fuction' instead of 'function' 269 | * if (typeof a == "fuction") { // Invalid typeof value 'fuction' 270 | * // ... 271 | * } 272 | * 273 | * Do not use this option unless you're absolutely sure you don't want 274 | * these checks. 275 | */ 276 | notypeof: {name: 'valid-typeof', opts: 2}, 277 | 278 | /** 279 | * This option enforces the consistency of quotation marks used throughout 280 | * your code. It accepts three values: `true` if you don't want to enforce 281 | * one particular style but want some consistency, `"single"` if you want to 282 | * allow only single quotes and `"double"` if you want to allow only double 283 | * quotes. 284 | */ 285 | quotmark: {name: 'quotes', opts: [2, 'single']}, 286 | 287 | /** 288 | * This option suppresses warnings about variable shadowing i.e. declaring a 289 | * variable that had been already declared somewhere in the outer scope. 290 | * 291 | * - "inner" - check for variables defined in the same scope only 292 | * - "outer" - check for variables defined in outer scopes as well 293 | * - false - same as inner 294 | * - true - allow variable shadowing 295 | */ 296 | shadow: function map(v) { 297 | var outer = {name: 'no-shadow', opts: 2}; 298 | switch (v) { 299 | case true: 300 | return outer; 301 | // same as `inner` 302 | case false: 303 | case 'inner': 304 | return {name: 'no-redeclare', opts: 2}; 305 | case 'outer': 306 | return outer; 307 | default: 308 | return outer; 309 | } 310 | }, 311 | 312 | /** 313 | * This option prohibits the use of the grouping operator for 314 | * single-expression statements. This unecessary usage commonly reflects 315 | * a misunderstanding of unary operators, for example: 316 | * 317 | * // jshint singleGroups: true 318 | * 319 | * delete(obj.attr); // Warning: Grouping operator is unnecessary for lone expressions. 320 | */ 321 | singleGroups: {name: 'no-extra-parens', opts: 0}, 322 | 323 | /** 324 | * This option prohibits the use of explicitly undeclared variables. This 325 | * option is very useful for spotting leaking and mistyped variables. 326 | * 327 | * // jshint undef:true 328 | * 329 | * function test() { 330 | * var myVar = 'Hello, World'; 331 | * console.log(myvar); // Oops, typoed here. JSHint with undef will complain 332 | * } 333 | * 334 | * If your variable is defined in another file, you can use the `global` 335 | * directive to tell JSHint about it. 336 | */ 337 | undef: {name: 'no-undef', opts: 2}, 338 | 339 | /** 340 | * This option warns when you define and never use your variables. It is very 341 | * useful for general code cleanup, especially when used in addition to 342 | * `undef`. 343 | * 344 | * // jshint unused:true 345 | * 346 | * function test(a, b) { 347 | * var c, d = 2; 348 | * 349 | * return a + d; 350 | * } 351 | * 352 | * test(1, 2); 353 | * 354 | * // Line 3: 'b' was defined but never used. 355 | * // Line 4: 'c' was defined but never used. 356 | * 357 | * In addition to that, this option will warn you about unused global 358 | * variables declared via the `global` directive. 359 | * 360 | * This can be set to `vars` to only check for variables, not function 361 | * parameters, or `strict` to check all variables and parameters. The 362 | * default (true) behavior is to allow unused parameters that are followed by 363 | * a used parameter. 364 | */ 365 | unused: {name: 'no-unused-vars', opts: 2}, 366 | 367 | /** 368 | * This option suppresses warnings about declaring variables inside of 369 | * control 370 | * structures while accessing them later from the outside. Even though 371 | * JavaScript has only two real scopes—global and function—such practice 372 | * leads to confusion among people new to the language and hard-to-debug 373 | * bugs. This is why, by default, JSHint warns about variables that are 374 | * used outside of their intended scope. 375 | * 376 | * function test() { 377 | * if (true) { 378 | * var x = 0; 379 | * } 380 | * 381 | * x += 1; // Default: 'x' used out of scope. 382 | * // No warning when funcscope:true 383 | * } 384 | */ 385 | funcscope: {name: 'block-scoped-var', opts: 1}, 386 | 387 | /** 388 | * This option suppresses warnings about the use of global strict mode. 389 | * Global strict mode can break third-party widgets so it is not 390 | * recommended. 391 | * 392 | * For more info about strict mode see the `strict` option. 393 | */ 394 | globalstrict: {name: 'global-strict', opts: [2, 'never']}, 395 | 396 | /** 397 | * This option suppresses warnings about the `__iterator__` property. This 398 | * property is not supported by all browsers so use it carefully. 399 | */ 400 | iterator: {name: 'no-iterator', opts: 1}, 401 | 402 | asi: {name: 'semi', opts: [0, 'never'], isRelaxing: true}, 403 | 404 | /** 405 | * This option suppresses warnings about multi-line strings. Multi-line 406 | * strings can be dangerous in JavaScript because all hell breaks loose if 407 | * you accidentally put a whitespace in between the escape character (`\`) 408 | * and a new line. 409 | * 410 | * Note that even though this option allows correct multi-line strings, it 411 | * still warns about multi-line strings without escape characters or with 412 | * anything in between the escape character and a whitespace. 413 | * 414 | * // jshint multistr:true 415 | * 416 | * var text = "Hello\ 417 | * World"; // All good. 418 | * 419 | * text = "Hello 420 | * World"; // Warning, no escape character. 421 | * 422 | * text = "Hello\ 423 | * World"; // Warning, there is a space after \ 424 | */ 425 | multistr: {name: 'no-multi-str', opts: 0, isRelaxing: true}, 426 | 427 | /** 428 | * This option suppresses warnings about the `debugger` statements in your 429 | * code. 430 | */ 431 | debug: {name: 'no-debugger', opts: 0, isRelaxing: true}, 432 | 433 | /** 434 | * This option suppresses warnings about the use of assignments in cases 435 | * where comparisons are expected. More often than not, code like `if (a = 436 | * 10) {}` is a typo. However, it can be useful in cases like this one: 437 | * 438 | * for (var i = 0, person; person = people[i]; i++) {} 439 | * 440 | * You can silence this error on a per-use basis by surrounding the assignment 441 | * with parenthesis, such as: 442 | * 443 | * for (var i = 0, person; (person = people[i]); i++) {} 444 | */ 445 | boss: {name: 'no-cond-assign', opts: [2, 'except-parens'], isRelaxing: true}, 446 | 447 | /** 448 | * This option suppresses warnings about the use of `eval`. The use of 449 | * `eval` is discouraged because it can make your code vulnerable to 450 | * various injection attacks and it makes it hard for JavaScript 451 | * interpreter to do certain optimizations. 452 | */ 453 | evil: {name: 'no-eval', opts: 0, isRelaxing: true}, 454 | 455 | /** 456 | * This option prohibits the use of unary increment and decrement 457 | * operators. Some people think that `++` and `--` reduces the quality of 458 | * their coding styles and there are programming languages—such as 459 | * Python—that go completely without these operators. 460 | */ 461 | plusplus: {name: 'no-plusplus', opts: 0, isRelaxing: true}, 462 | 463 | /** 464 | * This option suppresses warnings about the `__proto__` property. 465 | */ 466 | proto: {name: 'no-proto', opts: 0, isRelaxing: true}, 467 | 468 | /** 469 | * This option suppresses warnings about the use of script-targeted 470 | * URLs—such as `javascript:...`. 471 | */ 472 | scripturl: {name: 'no-script-url', opts: 0, isRelaxing: true}, 473 | 474 | /** 475 | * This option requires all functions to run in ECMAScript 5's strict mode. 476 | * [Strict mode](https://developer.mozilla.org/en/JavaScript/Strict_mode) 477 | * is a way to opt in to a restricted variant of JavaScript. Strict mode 478 | * eliminates some JavaScript pitfalls that didn't cause errors by changing 479 | * them to produce errors. It also fixes mistakes that made it difficult 480 | * for the JavaScript engines to perform certain optimizations. 481 | * 482 | * *Note:* This option enables strict mode for function scope only. It 483 | * *prohibits* the global scoped strict mode because it might break 484 | * third-party widgets on your page. If you really want to use global 485 | * strict mode, see the *globalstrict* option. 486 | */ 487 | strict: {name: 'strict', opts: 0, isRelaxing: true}, 488 | 489 | /** 490 | * This option suppresses warnings about using `[]` notation when it can be 491 | * expressed in dot notation: `person['name']` vs. `person.name`. 492 | */ 493 | sub: {name: 'dot-notation', opts: [2, {allowKeywords: true}], isRelaxing: true}, 494 | 495 | /** 496 | * This option suppresses warnings about "weird" constructions like 497 | * `new function () { ... }` and `new Object;`. Such constructions are 498 | * sometimes used to produce singletons in JavaScript: 499 | * 500 | * var singleton = new function() { 501 | * var privateVar; 502 | * 503 | * this.publicMethod = function () {} 504 | * this.publicMethod2 = function () {} 505 | * }; 506 | */ 507 | supernew: {notSupported: '0.12.0'}, 508 | 509 | /** 510 | * This option suppresses most of the warnings about possibly unsafe line 511 | * breakings in your code. It doesn't suppress warnings about comma-first 512 | * coding style. To suppress those you have to use `laxcomma` (see below). 513 | */ 514 | laxbreak: {notSupported: '0.12.0'}, 515 | 516 | indent: {notSupported: '0.12.0'}, 517 | 518 | /** 519 | * This option suppresses warnings about comma-first coding style: 520 | * 521 | * var obj = { 522 | * name: 'Anton' 523 | * , handle: 'valueof' 524 | * , role: 'SW Engineer' 525 | * }; 526 | */ 527 | laxcomma: {name: 'comma-style', opts: [2, 'first'], isRelaxing: true}, 528 | 529 | /** 530 | * This option suppresses warnings about possible strict violations when 531 | * the code is running in strict mode and you use `this` in a 532 | * non-constructor function. You should use this option—in a function scope 533 | * only—when you are positive that your use of `this` is valid in the 534 | * strict mode (for example, if you call your function using 535 | * `Function.call`). 536 | * 537 | * **Note:** This option can be used only inside of a function scope. 538 | * JSHint will fail with an error if you will try to set this option 539 | * globally. 540 | */ 541 | validthis: {notSupported: '0.12.0'}, 542 | 543 | /** 544 | * This option suppresses warnings about the use of the `with` statement. 545 | * The semantics of the `with` statement can cause confusion among 546 | * developers and accidental definition of global variables. 547 | * 548 | * More info: 549 | * 550 | * * [with Statement Considered 551 | * Harmful](http://yuiblog.com/blog/2006/04/11/with-statement-considered-harmful/) 552 | */ 553 | withstmt: {name: 'no-with', opts: 0, isRelaxing: true}, 554 | 555 | /** 556 | * This options tells JSHint that your code uses Mozilla JavaScript 557 | * extensions. Unless you develop specifically for the Firefox web browser 558 | * you don't need this option. 559 | * 560 | * More info: 561 | * 562 | * * [New in JavaScript 563 | * 1.7](https://developer.mozilla.org/en-US/docs/JavaScript/New_in_JavaScript/1.7) 564 | */ 565 | moz: {isEnv: true, notSupported: '0.12.0'}, 566 | 567 | /** 568 | * This option suppresses warnings about generator functions with no 569 | * `yield` statement in them. 570 | */ 571 | noyield: {notSupported: '0.12.0'}, 572 | 573 | /** 574 | * This option suppresses warnings about `== null` comparisons. Such 575 | * comparisons are often useful when you want to check if a variable is 576 | * `null` or `undefined`. 577 | */ 578 | eqnull: {name: 'eqeqeq', opts: [2, 'allow-null'], isRelaxing: true}, 579 | 580 | /** 581 | * This option suppresses warnings about missing semicolons, but only when 582 | * the semicolon is omitted for the last statement in a one-line block: 583 | * 584 | * var name = (function() { return 'Anton' }()); 585 | * 586 | * This is a very niche use case that is useful only when you use automatic 587 | * JavaScript code generators. 588 | */ 589 | lastsemic: {notSupported: '0.12.0'}, 590 | 591 | /** 592 | * This option suppresses warnings about functions inside of loops. 593 | * Defining functions inside of loops can lead to bugs such as this one: 594 | * 595 | * var nums = []; 596 | * 597 | * for (var i = 0; i < 10; i++) { 598 | * nums[i] = function (j) { 599 | * return i + j; 600 | * }; 601 | * } 602 | * 603 | * nums[0](2); // Prints 12 instead of 2 604 | * 605 | * To fix the code above you need to copy the value of `i`: 606 | * 607 | * var nums = []; 608 | * 609 | * for (var i = 0; i < 10; i++) { 610 | * (function (i) { 611 | * nums[i] = function (j) { 612 | * return i + j; 613 | * }; 614 | * }(i)); 615 | * } 616 | */ 617 | loopfunc: {name: 'no-loop-func', opts: 0, isRelaxing: true}, 618 | 619 | /** 620 | * This option suppresses warnings about the use of expressions where 621 | * normally you would expect to see assignments or function calls. Most of 622 | * the time, such code is a typo. However, it is not forbidden by the spec 623 | * and that's why this warning is optional. 624 | */ 625 | expr: {notSupported: '0.12.0'}, 626 | 627 | /** 628 | * This option tells JSHint that your code uses ECMAScript 6 specific 629 | * syntax. Note that these features are not finalized yet and not all 630 | * browsers implement them. 631 | * 632 | * More info: 633 | * 634 | * * [Draft Specification for ES.next (ECMA-262 Ed. 635 | * 6)](http://wiki.ecmascript.org/doku.php?id=harmony:specification_drafts) 636 | */ 637 | esnext: {notSupported: '0.12.0'}, 638 | 639 | /** 640 | * This option tells JSHint that your code uses ES3 array elision elements, 641 | * or empty elements (for example, `[1, , , 4, , , 7]`). 642 | */ 643 | elision: {notSupported: '0.12.0'}, 644 | 645 | /** 646 | * This option defines globals available when your core is running inside 647 | * of the PhantomJS runtime environment. [PhantomJS](http://phantomjs.org/) 648 | * is a headless WebKit scriptable with a JavaScript API. It has fast and 649 | * native support for various web standards: DOM handling, CSS selector, 650 | * JSON, Canvas, and SVG. 651 | */ 652 | phantom: {notSupported: '0.12.0'}, 653 | 654 | /** 655 | * This option defines globals exposed by the 656 | * [MooTools](http://mootools.net/) JavaScript framework. 657 | */ 658 | mootools: {notSupported: '0.12.0'}, 659 | 660 | /** 661 | * This option defines globals exposed by 662 | * [CouchDB](http://couchdb.apache.org/). CouchDB is a document-oriented 663 | * database that can be queried and indexed in a MapReduce fashion using 664 | * JavaScript. 665 | */ 666 | couch: {notSupported: '0.12.0'}, 667 | 668 | /** 669 | * This option defines globals exposed by [the Jasmine unit testing 670 | * framework](https://jasmine.github.io/). 671 | */ 672 | jasmine: {name: 'jasmine', isEnv: true}, 673 | 674 | /** 675 | * This option defines globals exposed by the [jQuery](http://jquery.com/) 676 | * JavaScript library. 677 | */ 678 | jquery: {notSupported: '0.12.0'}, 679 | 680 | /** 681 | * This option defines globals available when your code is running inside 682 | * of the Node runtime environment. [Node.js](http://nodejs.org/) is a 683 | * server-side JavaScript environment that uses an asynchronous 684 | * event-driven model. This option also skips some warnings that make sense 685 | * in the browser environments but don't make sense in Node such as 686 | * file-level `use strict` pragmas and `console.log` statements. 687 | */ 688 | node: {name: 'node', isEnv: true}, 689 | 690 | /** 691 | * This option defines globals exposed by [the QUnit unit testing 692 | * framework](http://qunitjs.com/). 693 | */ 694 | qunit: {notSupported: '0.12.0'}, 695 | 696 | /** 697 | * This option defines globals available when your code is running inside 698 | * of the Rhino runtime environment. [Rhino](http://www.mozilla.org/rhino/) 699 | * is an open-source implementation of JavaScript written entirely in Java. 700 | */ 701 | rhino: {notSupported: '0.12.0'}, 702 | 703 | /** 704 | * This option defines globals exposed by [the ShellJS 705 | * library](http://documentup.com/arturadib/shelljs). 706 | */ 707 | shelljs: {notSupported: '0.12.0'}, 708 | 709 | /** 710 | * This option defines globals exposed by the 711 | * [Prototype](http://www.prototypejs.org/) JavaScript framework. 712 | */ 713 | prototypejs: {notSupported: '0.12.0'}, 714 | 715 | /** 716 | * This option defines globals exposed by the [YUI](http://yuilibrary.com/) 717 | * JavaScript framework. 718 | */ 719 | yui: {notSupported: '0.12.0'}, 720 | 721 | /** 722 | * This option defines globals exposed by the "BDD" and "TDD" UIs of the 723 | * [Mocha unit testing framework](http://mochajs.org/). 724 | */ 725 | mocha: {name: 'mocha', isEnv: true}, 726 | 727 | /** 728 | * This option defines globals available when your code is running as a 729 | * script for the [Windows Script 730 | * Host](http://en.wikipedia.org/wiki/Windows_Script_Host). 731 | */ 732 | wsh: {notSupported: '0.12.0'}, 733 | 734 | /** 735 | * This option defines globals available when your code is running inside 736 | * of a Web Worker. [Web 737 | * Workers](https://developer.mozilla.org/en/Using_web_workers) provide a 738 | * simple means for web content to run scripts in background threads. 739 | */ 740 | worker: {notSupported: '0.12.0'}, 741 | 742 | /** 743 | * This option defines non-standard but widely adopted globals such as 744 | * `escape` and `unescape`. 745 | */ 746 | nonstandard: {notSupported: '0.12.0'}, 747 | 748 | /** 749 | * This option defines globals exposed by modern browsers: all the way from 750 | * good old `document` and `navigator` to the HTML5 `FileReader` and other 751 | * new developments in the browser world. 752 | * 753 | * **Note:** This option doesn't expose variables like `alert` or 754 | * `console`. See option `devel` for more information. 755 | */ 756 | browser: {name: 'browser', isEnv: true}, 757 | 758 | /** 759 | * This option defines globals available when using [the Browserify 760 | * tool](http://browserify.org/) to build a project. 761 | */ 762 | browserify: {name: 'node', isEnv: true}, 763 | 764 | /** 765 | * This option defines globals that are usually used for logging poor-man's 766 | * debugging: `console`, `alert`, etc. It is usually a good idea to not 767 | * ship them in production because, for example, `console.log` breaks in 768 | * legacy versions of Internet Explorer. 769 | */ 770 | devel: {name: 'browser', isEnv: true}, 771 | 772 | /** 773 | * This option defines globals exposed by the [Dojo 774 | * Toolkit](http://dojotoolkit.org/). 775 | */ 776 | dojo: {notSupported: '0.12.0'}, 777 | 778 | /** 779 | * This option defines globals for typed array constructors. 780 | * 781 | * More info: 782 | * 783 | * * [JavaScript typed 784 | * arrays](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Typed_arrays) 785 | */ 786 | typed: {name: 'builtin', isEnv: true} 787 | }; 788 | -------------------------------------------------------------------------------- /lib/jshint/options.js: -------------------------------------------------------------------------------- 1 | /*eslint-disable*/ 2 | "use strict"; 3 | // JSHint v 2.5.11 4 | // These are the JSHint boolean options. 5 | exports.bool = { 6 | enforcing: { 7 | 8 | /** 9 | * This option prohibits the use of bitwise operators such as `^` (XOR), 10 | * `|` (OR) and others. Bitwise operators are very rare in JavaScript 11 | * programs and quite often `&` is simply a mistyped `&&`. 12 | */ 13 | bitwise : true, 14 | 15 | /** 16 | * 17 | * This options prohibits overwriting prototypes of native objects such as 18 | * `Array`, `Date` and so on. 19 | * 20 | * // jshint freeze:true 21 | * Array.prototype.count = function (value) { return 4; }; 22 | * // -> Warning: Extending prototype of native object: 'Array'. 23 | */ 24 | freeze : true, 25 | 26 | /** 27 | * This option allows you to force all variable names to use either 28 | * camelCase style or UPPER_CASE with underscores. 29 | */ 30 | camelcase : true, 31 | 32 | /** 33 | * This option requires you to always put curly braces around blocks in 34 | * loops and conditionals. JavaScript allows you to omit curly braces when 35 | * the block consists of only one statement, for example: 36 | * 37 | * while (day) 38 | * shuffle(); 39 | * 40 | * However, in some circumstances, it can lead to bugs (you'd think that 41 | * `sleep()` is a part of the loop while in reality it is not): 42 | * 43 | * while (day) 44 | * shuffle(); 45 | * sleep(); 46 | */ 47 | curly : true, 48 | 49 | /** 50 | * This options prohibits the use of `==` and `!=` in favor of `===` and 51 | * `!==`. The former try to coerce values before comparing them which can 52 | * lead to some unexpected results. The latter don't do any coercion so 53 | * they are generally safer. If you would like to learn more about type 54 | * coercion in JavaScript, we recommend [Truth, Equality and 55 | * JavaScript](http://javascriptweblog.wordpress.com/2011/02/07/truth-equality-and-javascript/) 56 | * by Angus Croll. 57 | */ 58 | eqeqeq : true, 59 | 60 | /** 61 | * This option suppresses warnings about invalid `typeof` operator values. 62 | * This operator has only [a limited set of possible return 63 | * values](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/typeof). 64 | * By default, JSHint warns when you compare its result with an invalid 65 | * value which often can be a typo. 66 | * 67 | * // 'fuction' instead of 'function' 68 | * if (typeof a == "fuction") { // Invalid typeof value 'fuction' 69 | * // ... 70 | * } 71 | * 72 | * Do not use this option unless you're absolutely sure you don't want 73 | * these checks. 74 | */ 75 | notypeof : true, 76 | 77 | /** 78 | * This option tells JSHint that your code needs to adhere to ECMAScript 3 79 | * specification. Use this option if you need your program to be executable 80 | * in older browsers—such as Internet Explorer 6/7/8/9—and other legacy 81 | * JavaScript environments. 82 | */ 83 | es3 : true, 84 | 85 | /** 86 | * This option enables syntax first defined in [the ECMAScript 5.1 87 | * specification](http://es5.github.io/). This includes allowing reserved 88 | * keywords as object properties. 89 | */ 90 | es5 : true, 91 | 92 | /** 93 | * This option requires all `for in` loops to filter object's items. The 94 | * for in statement allows for looping through the names of all of the 95 | * properties of an object including those inherited through the prototype 96 | * chain. This behavior can lead to unexpected items in your object so it 97 | * is generally safer to always filter inherited properties out as shown in 98 | * the example: 99 | * 100 | * for (key in obj) { 101 | * if (obj.hasOwnProperty(key)) { 102 | * // We are sure that obj[key] belongs to the object and was not inherited. 103 | * } 104 | * } 105 | * 106 | * For more in-depth understanding of `for in` loops in JavaScript, read 107 | * [Exploring JavaScript for-in 108 | * loops](http://javascriptweblog.wordpress.com/2011/01/04/exploring-javascript-for-in-loops/) 109 | * by Angus Croll. 110 | */ 111 | forin : true, 112 | 113 | /** 114 | * This option suppresses warnings about declaring variables inside of 115 | * control 116 | * structures while accessing them later from the outside. Even though 117 | * JavaScript has only two real scopes—global and function—such practice 118 | * leads to confusion among people new to the language and hard-to-debug 119 | * bugs. This is why, by default, JSHint warns about variables that are 120 | * used outside of their intended scope. 121 | * 122 | * function test() { 123 | * if (true) { 124 | * var x = 0; 125 | * } 126 | * 127 | * x += 1; // Default: 'x' used out of scope. 128 | * // No warning when funcscope:true 129 | * } 130 | */ 131 | funcscope : true, 132 | 133 | /** 134 | * This option suppresses warnings about the use of global strict mode. 135 | * Global strict mode can break third-party widgets so it is not 136 | * recommended. 137 | * 138 | * For more info about strict mode see the `strict` option. 139 | */ 140 | globalstrict: true, 141 | 142 | /** 143 | * This option prohibits the use of immediate function invocations without 144 | * wrapping them in parentheses. Wrapping parentheses assists readers of 145 | * your code in understanding that the expression is the result of a 146 | * function, and not the function itself. 147 | */ 148 | immed : true, 149 | 150 | /** 151 | * This option suppresses warnings about the `__iterator__` property. This 152 | * property is not supported by all browsers so use it carefully. 153 | */ 154 | iterator : true, 155 | 156 | /** 157 | * This option requires you to capitalize names of constructor functions. 158 | * Capitalizing functions that are intended to be used with `new` operator 159 | * is just a convention that helps programmers to visually distinguish 160 | * constructor functions from other types of functions to help spot 161 | * mistakes when using `this`. 162 | * 163 | * Not doing so won't break your code in any browsers or environments but 164 | * it will be a bit harder to figure out—by reading the code—if the 165 | * function was supposed to be used with or without new. And this is 166 | * important because when the function that was intended to be used with 167 | * `new` is used without it, `this` will point to the global object instead 168 | * of a new object. 169 | */ 170 | newcap : true, 171 | 172 | /** 173 | * This option prohibits the use of `arguments.caller` and 174 | * `arguments.callee`. Both `.caller` and `.callee` make quite a few 175 | * optimizations impossible so they were deprecated in future versions of 176 | * JavaScript. In fact, ECMAScript 5 forbids the use of `arguments.callee` 177 | * in strict mode. 178 | */ 179 | noarg : true, 180 | 181 | /** 182 | * This option prohibits the use of the comma operator. When misused, the 183 | * comma operator can obscure the value of a statement and promote 184 | * incorrect code. 185 | */ 186 | nocomma : true, 187 | 188 | /** 189 | * This option warns when you have an empty block in your code. JSLint was 190 | * originally warning for all empty blocks and we simply made it optional. 191 | * There were no studies reporting that empty blocks in JavaScript break 192 | * your code in any way. 193 | */ 194 | noempty : true, 195 | 196 | /** 197 | * This option warns about "non-breaking whitespace" characters. These 198 | * characters can be entered with option-space on Mac computers and have a 199 | * potential of breaking non-UTF8 web pages. 200 | */ 201 | nonbsp : true, 202 | 203 | /** 204 | * This option prohibits the use of constructor functions for side-effects. 205 | * Some people like to call constructor functions without assigning its 206 | * result to any variable: 207 | * 208 | * new MyConstructor(); 209 | * 210 | * There is no advantage in this approach over simply calling 211 | * `MyConstructor` since the object that the operator `new` creates isn't 212 | * used anywhere so you should generally avoid constructors like this one. 213 | */ 214 | nonew : true, 215 | 216 | /** 217 | * This option prohibits the use of explicitly undeclared variables. This 218 | * option is very useful for spotting leaking and mistyped variables. 219 | * 220 | * // jshint undef:true 221 | * 222 | * function test() { 223 | * var myVar = 'Hello, World'; 224 | * console.log(myvar); // Oops, typoed here. JSHint with undef will complain 225 | * } 226 | * 227 | * If your variable is defined in another file, you can use the `global` 228 | * directive to tell JSHint about it. 229 | */ 230 | undef : true, 231 | 232 | /** 233 | * This option prohibits the use of the grouping operator for 234 | * single-expression statements. This unecessary usage commonly reflects 235 | * a misunderstanding of unary operators, for example: 236 | * 237 | * // jshint singleGroups: true 238 | * 239 | * delete(obj.attr); // Warning: Grouping operator is unnecessary for lone expressions. 240 | */ 241 | singleGroups: false, 242 | 243 | /** 244 | * This option is a short hand for the most strict JSHint configuration. It 245 | * enables all enforcing options and disables all relaxing options. 246 | */ 247 | enforceall : false 248 | }, 249 | relaxing: { 250 | 251 | /** 252 | * This option suppresses warnings about missing semicolons. There is a lot 253 | * of FUD about semicolon spread by quite a few people in the community. 254 | * The common myths are that semicolons are required all the time (they are 255 | * not) and that they are unreliable. JavaScript has rules about semicolons 256 | * which are followed by *all* browsers so it is up to you to decide 257 | * whether you should or should not use semicolons in your code. 258 | * 259 | * For more information about semicolons in JavaScript read [An Open Letter 260 | * to JavaScript Leaders Regarding 261 | * Semicolons](http://blog.izs.me/post/2353458699/an-open-letter-to-javascript-leaders-regarding) 262 | * by Isaac Schlueter and [JavaScript Semicolon 263 | * Insertion](http://inimino.org/~inimino/blog/javascript_semicolons). 264 | */ 265 | asi : true, 266 | 267 | /** 268 | * This option suppresses warnings about multi-line strings. Multi-line 269 | * strings can be dangerous in JavaScript because all hell breaks loose if 270 | * you accidentally put a whitespace in between the escape character (`\`) 271 | * and a new line. 272 | * 273 | * Note that even though this option allows correct multi-line strings, it 274 | * still warns about multi-line strings without escape characters or with 275 | * anything in between the escape character and a whitespace. 276 | * 277 | * // jshint multistr:true 278 | * 279 | * var text = "Hello\ 280 | * World"; // All good. 281 | * 282 | * text = "Hello 283 | * World"; // Warning, no escape character. 284 | * 285 | * text = "Hello\ 286 | * World"; // Warning, there is a space after \ 287 | */ 288 | multistr : true, 289 | 290 | /** 291 | * This option suppresses warnings about the `debugger` statements in your 292 | * code. 293 | */ 294 | debug : true, 295 | 296 | /** 297 | * This option suppresses warnings about the use of assignments in cases 298 | * where comparisons are expected. More often than not, code like `if (a = 299 | * 10) {}` is a typo. However, it can be useful in cases like this one: 300 | * 301 | * for (var i = 0, person; person = people[i]; i++) {} 302 | * 303 | * You can silence this error on a per-use basis by surrounding the assignment 304 | * with parenthesis, such as: 305 | * 306 | * for (var i = 0, person; (person = people[i]); i++) {} 307 | */ 308 | boss : true, 309 | 310 | /** 311 | * This option defines globals available when your core is running inside 312 | * of the PhantomJS runtime environment. [PhantomJS](http://phantomjs.org/) 313 | * is a headless WebKit scriptable with a JavaScript API. It has fast and 314 | * native support for various web standards: DOM handling, CSS selector, 315 | * JSON, Canvas, and SVG. 316 | */ 317 | phantom : true, 318 | 319 | /** 320 | * This option suppresses warnings about the use of `eval`. The use of 321 | * `eval` is discouraged because it can make your code vulnerable to 322 | * various injection attacks and it makes it hard for JavaScript 323 | * interpreter to do certain optimizations. 324 | */ 325 | evil : true, 326 | 327 | /** 328 | * This option prohibits the use of unary increment and decrement 329 | * operators. Some people think that `++` and `--` reduces the quality of 330 | * their coding styles and there are programming languages—such as 331 | * Python—that go completely without these operators. 332 | */ 333 | plusplus : true, 334 | 335 | /** 336 | * This option suppresses warnings about the `__proto__` property. 337 | */ 338 | proto : true, 339 | 340 | /** 341 | * This option suppresses warnings about the use of script-targeted 342 | * URLs—such as `javascript:...`. 343 | */ 344 | scripturl : true, 345 | 346 | /** 347 | * This option requires all functions to run in ECMAScript 5's strict mode. 348 | * [Strict mode](https://developer.mozilla.org/en/JavaScript/Strict_mode) 349 | * is a way to opt in to a restricted variant of JavaScript. Strict mode 350 | * eliminates some JavaScript pitfalls that didn't cause errors by changing 351 | * them to produce errors. It also fixes mistakes that made it difficult 352 | * for the JavaScript engines to perform certain optimizations. 353 | * 354 | * *Note:* This option enables strict mode for function scope only. It 355 | * *prohibits* the global scoped strict mode because it might break 356 | * third-party widgets on your page. If you really want to use global 357 | * strict mode, see the *globalstrict* option. 358 | */ 359 | strict : true, 360 | 361 | /** 362 | * This option suppresses warnings about using `[]` notation when it can be 363 | * expressed in dot notation: `person['name']` vs. `person.name`. 364 | */ 365 | sub : true, 366 | 367 | /** 368 | * This option suppresses warnings about "weird" constructions like 369 | * `new function () { ... }` and `new Object;`. Such constructions are 370 | * sometimes used to produce singletons in JavaScript: 371 | * 372 | * var singleton = new function() { 373 | * var privateVar; 374 | * 375 | * this.publicMethod = function () {} 376 | * this.publicMethod2 = function () {} 377 | * }; 378 | */ 379 | supernew : true, 380 | 381 | /** 382 | * This option suppresses most of the warnings about possibly unsafe line 383 | * breakings in your code. It doesn't suppress warnings about comma-first 384 | * coding style. To suppress those you have to use `laxcomma` (see below). 385 | */ 386 | laxbreak : true, 387 | 388 | /** 389 | * This option suppresses warnings about comma-first coding style: 390 | * 391 | * var obj = { 392 | * name: 'Anton' 393 | * , handle: 'valueof' 394 | * , role: 'SW Engineer' 395 | * }; 396 | */ 397 | laxcomma : true, 398 | 399 | /** 400 | * This option suppresses warnings about possible strict violations when 401 | * the code is running in strict mode and you use `this` in a 402 | * non-constructor function. You should use this option—in a function scope 403 | * only—when you are positive that your use of `this` is valid in the 404 | * strict mode (for example, if you call your function using 405 | * `Function.call`). 406 | * 407 | * **Note:** This option can be used only inside of a function scope. 408 | * JSHint will fail with an error if you will try to set this option 409 | * globally. 410 | */ 411 | validthis : true, 412 | 413 | /** 414 | * This option suppresses warnings about the use of the `with` statement. 415 | * The semantics of the `with` statement can cause confusion among 416 | * developers and accidental definition of global variables. 417 | * 418 | * More info: 419 | * 420 | * * [with Statement Considered 421 | * Harmful](http://yuiblog.com/blog/2006/04/11/with-statement-considered-harmful/) 422 | */ 423 | withstmt : true, 424 | 425 | /** 426 | * This options tells JSHint that your code uses Mozilla JavaScript 427 | * extensions. Unless you develop specifically for the Firefox web browser 428 | * you don't need this option. 429 | * 430 | * More info: 431 | * 432 | * * [New in JavaScript 433 | * 1.7](https://developer.mozilla.org/en-US/docs/JavaScript/New_in_JavaScript/1.7) 434 | */ 435 | moz : true, 436 | 437 | /** 438 | * This option suppresses warnings about generator functions with no 439 | * `yield` statement in them. 440 | */ 441 | noyield : true, 442 | 443 | /** 444 | * This option suppresses warnings about `== null` comparisons. Such 445 | * comparisons are often useful when you want to check if a variable is 446 | * `null` or `undefined`. 447 | */ 448 | eqnull : true, 449 | 450 | /** 451 | * This option suppresses warnings about missing semicolons, but only when 452 | * the semicolon is omitted for the last statement in a one-line block: 453 | * 454 | * var name = (function() { return 'Anton' }()); 455 | * 456 | * This is a very niche use case that is useful only when you use automatic 457 | * JavaScript code generators. 458 | */ 459 | lastsemic : true, 460 | 461 | /** 462 | * This option suppresses warnings about functions inside of loops. 463 | * Defining functions inside of loops can lead to bugs such as this one: 464 | * 465 | * var nums = []; 466 | * 467 | * for (var i = 0; i < 10; i++) { 468 | * nums[i] = function (j) { 469 | * return i + j; 470 | * }; 471 | * } 472 | * 473 | * nums[0](2); // Prints 12 instead of 2 474 | * 475 | * To fix the code above you need to copy the value of `i`: 476 | * 477 | * var nums = []; 478 | * 479 | * for (var i = 0; i < 10; i++) { 480 | * (function (i) { 481 | * nums[i] = function (j) { 482 | * return i + j; 483 | * }; 484 | * }(i)); 485 | * } 486 | */ 487 | loopfunc : true, 488 | 489 | /** 490 | * This option suppresses warnings about the use of expressions where 491 | * normally you would expect to see assignments or function calls. Most of 492 | * the time, such code is a typo. However, it is not forbidden by the spec 493 | * and that's why this warning is optional. 494 | */ 495 | expr : true, 496 | 497 | /** 498 | * This option tells JSHint that your code uses ECMAScript 6 specific 499 | * syntax. Note that these features are not finalized yet and not all 500 | * browsers implement them. 501 | * 502 | * More info: 503 | * 504 | * * [Draft Specification for ES.next (ECMA-262 Ed. 505 | * 6)](http://wiki.ecmascript.org/doku.php?id=harmony:specification_drafts) 506 | */ 507 | esnext : true, 508 | 509 | /** 510 | * This option tells JSHint that your code uses ES3 array elision elements, 511 | * or empty elements (for example, `[1, , , 4, , , 7]`). 512 | */ 513 | elision : true 514 | }, 515 | 516 | // Third party globals 517 | environments: { 518 | 519 | /** 520 | * This option defines globals exposed by the 521 | * [MooTools](http://mootools.net/) JavaScript framework. 522 | */ 523 | mootools : true, 524 | 525 | /** 526 | * This option defines globals exposed by 527 | * [CouchDB](http://couchdb.apache.org/). CouchDB is a document-oriented 528 | * database that can be queried and indexed in a MapReduce fashion using 529 | * JavaScript. 530 | */ 531 | couch : true, 532 | 533 | /** 534 | * This option defines globals exposed by [the Jasmine unit testing 535 | * framework](https://jasmine.github.io/). 536 | */ 537 | jasmine : true, 538 | 539 | /** 540 | * This option defines globals exposed by the [jQuery](http://jquery.com/) 541 | * JavaScript library. 542 | */ 543 | jquery : true, 544 | 545 | /** 546 | * This option defines globals available when your code is running inside 547 | * of the Node runtime environment. [Node.js](http://nodejs.org/) is a 548 | * server-side JavaScript environment that uses an asynchronous 549 | * event-driven model. This option also skips some warnings that make sense 550 | * in the browser environments but don't make sense in Node such as 551 | * file-level `use strict` pragmas and `console.log` statements. 552 | */ 553 | node : true, 554 | 555 | /** 556 | * This option defines globals exposed by [the QUnit unit testing 557 | * framework](http://qunitjs.com/). 558 | */ 559 | qunit : true, 560 | 561 | /** 562 | * This option defines globals available when your code is running inside 563 | * of the Rhino runtime environment. [Rhino](http://www.mozilla.org/rhino/) 564 | * is an open-source implementation of JavaScript written entirely in Java. 565 | */ 566 | rhino : true, 567 | 568 | /** 569 | * This option defines globals exposed by [the ShellJS 570 | * library](http://documentup.com/arturadib/shelljs). 571 | */ 572 | shelljs : true, 573 | 574 | /** 575 | * This option defines globals exposed by the 576 | * [Prototype](http://www.prototypejs.org/) JavaScript framework. 577 | */ 578 | prototypejs : true, 579 | 580 | /** 581 | * This option defines globals exposed by the [YUI](http://yuilibrary.com/) 582 | * JavaScript framework. 583 | */ 584 | yui : true, 585 | 586 | /** 587 | * This option defines globals exposed by the "BDD" and "TDD" UIs of the 588 | * [Mocha unit testing framework](http://mochajs.org/). 589 | */ 590 | mocha : true, 591 | 592 | /** 593 | * This option defines globals available when your code is running as a 594 | * script for the [Windows Script 595 | * Host](http://en.wikipedia.org/wiki/Windows_Script_Host). 596 | */ 597 | wsh : true, 598 | 599 | /** 600 | * This option defines globals available when your code is running inside 601 | * of a Web Worker. [Web 602 | * Workers](https://developer.mozilla.org/en/Using_web_workers) provide a 603 | * simple means for web content to run scripts in background threads. 604 | */ 605 | worker : true, 606 | 607 | /** 608 | * This option defines non-standard but widely adopted globals such as 609 | * `escape` and `unescape`. 610 | */ 611 | nonstandard : true, 612 | 613 | /** 614 | * This option defines globals exposed by modern browsers: all the way from 615 | * good old `document` and `navigator` to the HTML5 `FileReader` and other 616 | * new developments in the browser world. 617 | * 618 | * **Note:** This option doesn't expose variables like `alert` or 619 | * `console`. See option `devel` for more information. 620 | */ 621 | browser : true, 622 | 623 | /** 624 | * This option defines globals available when using [the Browserify 625 | * tool](http://browserify.org/) to build a project. 626 | */ 627 | browserify : {name: 'node'}, 628 | 629 | /** 630 | * This option defines globals that are usually used for logging poor-man's 631 | * debugging: `console`, `alert`, etc. It is usually a good idea to not 632 | * ship them in production because, for example, `console.log` breaks in 633 | * legacy versions of Internet Explorer. 634 | */ 635 | devel : {name: 'browser'}, 636 | 637 | /** 638 | * This option defines globals exposed by the [Dojo 639 | * Toolkit](http://dojotoolkit.org/). 640 | */ 641 | dojo : true, 642 | 643 | /** 644 | * This option defines globals for typed array constructors. 645 | * 646 | * More info: 647 | * 648 | * * [JavaScript typed 649 | * arrays](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Typed_arrays) 650 | */ 651 | typed : {name: 'builtin'} 652 | }, 653 | 654 | // Obsolete options 655 | obsolete: { 656 | onecase : true, // if one case switch statements should be allowed 657 | regexp : true, // if the . should not be allowed in regexp literals 658 | regexdash : true // if unescaped first/last dash (-) inside brackets 659 | // should be tolerated 660 | } 661 | }; 662 | 663 | // These are the JSHint options that can take any value 664 | // (we use this object to detect invalid options) 665 | exports.val = { 666 | 667 | /** 668 | * This option lets you set the maximum length of a line. 669 | */ 670 | maxlen : false, 671 | 672 | /** 673 | * This option sets a specific tab width for your code. 674 | */ 675 | indent : false, 676 | 677 | /** 678 | * This options allows you to set the maximum amount of warnings JSHint will 679 | * produce before giving up. Default is 50. 680 | */ 681 | maxerr : false, 682 | 683 | predef : false, // predef is deprecated and being replaced by globals 684 | 685 | /** 686 | * This option can be used to specify a white list of global variables that 687 | * are not formally defined in the source code. This is most useful when 688 | * combined with the `undef` option in order to suppress warnings for 689 | * project-specific global variables. 690 | * 691 | * Setting an entry to `true` enables reading and writing to that variable. 692 | * Setting it to `false` will trigger JSHint to consider that variable 693 | * read-only. 694 | * 695 | * See also the "environment" options: a set of options to be used as short 696 | * hand for enabling global variables defined in common JavaScript 697 | * environments. 698 | */ 699 | globals : false, 700 | 701 | /** 702 | * This option enforces the consistency of quotation marks used throughout 703 | * your code. It accepts three values: `true` if you don't want to enforce 704 | * one particular style but want some consistency, `"single"` if you want to 705 | * allow only single quotes and `"double"` if you want to allow only double 706 | * quotes. 707 | */ 708 | quotmark : false, 709 | 710 | scope : false, 711 | 712 | /** 713 | * This option lets you set the max number of statements allowed per function: 714 | * 715 | * // jshint maxstatements:4 716 | * 717 | * function main() { 718 | * var i = 0; 719 | * var j = 0; 720 | * 721 | * // Function declarations count as one statement. Their bodies 722 | * // don't get taken into account for the outer function. 723 | * function inner() { 724 | * var i2 = 1; 725 | * var j2 = 1; 726 | * 727 | * return i2 + j2; 728 | * } 729 | * 730 | * j = i + j; 731 | * return j; // JSHint: Too many statements per function. (5) 732 | * } 733 | */ 734 | maxstatements: false, 735 | 736 | /** 737 | * This option lets you control how nested do you want your blocks to be: 738 | * 739 | * // jshint maxdepth:2 740 | * 741 | * function main(meaning) { 742 | * var day = true; 743 | * 744 | * if (meaning === 42) { 745 | * while (day) { 746 | * shuffle(); 747 | * 748 | * if (tired) { // JSHint: Blocks are nested too deeply (3). 749 | * sleep(); 750 | * } 751 | * } 752 | * } 753 | * } 754 | */ 755 | maxdepth : false, 756 | 757 | /** 758 | * This option lets you set the max number of formal parameters allowed per 759 | * function: 760 | * 761 | * // jshint maxparams:3 762 | * 763 | * function login(request, onSuccess) { 764 | * // ... 765 | * } 766 | * 767 | * // JSHint: Too many parameters per function (4). 768 | * function logout(request, isManual, whereAmI, onSuccess) { 769 | * // ... 770 | * } 771 | */ 772 | maxparams : false, 773 | 774 | /** 775 | * This option lets you control cyclomatic complexity throughout your code. 776 | * Cyclomatic complexity measures the number of linearly independent paths 777 | * through a program's source code. Read more about [cyclomatic complexity on 778 | * Wikipedia](http://en.wikipedia.org/wiki/Cyclomatic_complexity). 779 | */ 780 | maxcomplexity: false, 781 | 782 | /** 783 | * This option suppresses warnings about variable shadowing i.e. declaring a 784 | * variable that had been already declared somewhere in the outer scope. 785 | * 786 | * - "inner" - check for variables defined in the same scope only 787 | * - "outer" - check for variables defined in outer scopes as well 788 | * - false - same as inner 789 | * - true - allow variable shadowing 790 | */ 791 | shadow : false, 792 | 793 | /** 794 | * This option warns when you define and never use your variables. It is very 795 | * useful for general code cleanup, especially when used in addition to 796 | * `undef`. 797 | * 798 | * // jshint unused:true 799 | * 800 | * function test(a, b) { 801 | * var c, d = 2; 802 | * 803 | * return a + d; 804 | * } 805 | * 806 | * test(1, 2); 807 | * 808 | * // Line 3: 'b' was defined but never used. 809 | * // Line 4: 'c' was defined but never used. 810 | * 811 | * In addition to that, this option will warn you about unused global 812 | * variables declared via the `global` directive. 813 | * 814 | * This can be set to `vars` to only check for variables, not function 815 | * parameters, or `strict` to check all variables and parameters. The 816 | * default (true) behavior is to allow unused parameters that are followed by 817 | * a used parameter. 818 | */ 819 | unused : true, 820 | 821 | /** 822 | * This option prohibits the use of a variable before it was defined. 823 | * JavaScript has function scope only and, in addition to that, all variables 824 | * are always moved—or hoisted— to the top of the function. This behavior can 825 | * lead to some very nasty bugs and that's why it is safer to always use 826 | * variable only after they have been explicitly defined. 827 | * 828 | * Setting this option to "nofunc" will allow function declarations to be 829 | * ignored. 830 | * 831 | * For more in-depth understanding of scoping and hoisting in JavaScript, 832 | * read [JavaScript Scoping and 833 | * Hoisting](http://www.adequatelygood.com/2010/2/JavaScript-Scoping-and-Hoisting) 834 | * by Ben Cherry. 835 | */ 836 | latedef : false, 837 | 838 | ignore : false, // start/end ignoring lines of code, bypassing the lexer 839 | // start - start ignoring lines, including the current line 840 | // end - stop ignoring lines, starting on the next line 841 | // line - ignore warnings / errors for just a single line 842 | // (this option does not bypass the lexer) 843 | ignoreDelimiters: false // array of start/end delimiters used to ignore 844 | // certain chunks from code 845 | }; 846 | 847 | // These are JSHint boolean options which are shared with JSLint 848 | // where the definition in JSHint is opposite JSLint 849 | exports.inverted = { 850 | bitwise : true, 851 | forin : true, 852 | newcap : true, 853 | plusplus: true, 854 | regexp : true, 855 | undef : true, 856 | 857 | // Inverted and renamed, use JSHint name here 858 | eqeqeq : true, 859 | strict : true 860 | }; 861 | 862 | exports.validNames = Object.keys(exports.val) 863 | .concat(Object.keys(exports.bool.relaxing)) 864 | .concat(Object.keys(exports.bool.enforcing)) 865 | .concat(Object.keys(exports.bool.obsolete)) 866 | .concat(Object.keys(exports.bool.environments)); 867 | 868 | // These are JSHint boolean options which are shared with JSLint 869 | // where the name has been changed but the effect is unchanged 870 | exports.renamed = { 871 | eqeq : "eqeqeq", 872 | windows: "wsh", 873 | sloppy : "strict" 874 | }; 875 | 876 | exports.removed = { 877 | nomen: true, 878 | onevar: true, 879 | passfail: true, 880 | white: true, 881 | gcl: true, 882 | smarttabs: true, 883 | trailing: true 884 | }; 885 | --------------------------------------------------------------------------------