jshint

jshint complains: 'Ember' is not defined

一个人想着一个人 提交于 2019-12-03 23:29:45
I have a standard Ember main.js file, which starts like this: this.App = Ember.Application.create({ LOG_TRANSITIONS: true, VERSION: '1.0.0', ready: function () { console.log('App version: ' + App.VERSION + ' is ready.'); } }); Running this through jshint complains about Ember not being defined, which is true for this particular file in the server, during the deployment phase. Because of this, lots of error messages are shown. Ember is made available in the browser by the script tag in index.html : <script src="scripts/vendor/ember-1.0.0-rc.2.js"></script> How can I tell jshint about Ember ?

difference between globals and predef in .jshintrc?

强颜欢笑 提交于 2019-12-03 23:19:25
问题 What the difference and purpose of having both of them in the .jshintrc? When I want to add a variable to be ignored, which one is the best one I should use? Also I can't find 'predef' in http://www.jshint.com/docs/options/ 回答1: It seems like predef is deprecated and you should use globals instead. More information here 回答2: At JSHint Doc page http://www.jshint.com/docs/ "predef" is mention for use inside .jshintrc file, wile word "globals" is used only once for inline directive (those that

webpack3 jshint-loader does not work

戏子无情 提交于 2019-12-03 17:26:35
问题 I'm trying to follow this instruction https://webpack.js.org/loaders/jshint-loader/ and get an error: My config file: const path = require('path'); module.exports = { entry: { app: './index.js' }, output: { filename: 'bundle.js', path: path.resolve(__dirname, 'dist') }, module: { rules: [ { test: /\.js$/, // include .js files enforce: "pre", // preload the jshint loader exclude: /node_modules/, // exclude any and all files in the node_modules folder use: [ { loader: "jshint-loader" } ] } ] },

jshint ignore Use '!==' to compare with ''

♀尐吖头ヾ 提交于 2019-12-03 16:45:59
问题 How can I configure JSHint to ignore this error: Use '!==' to compare with ''. ? I want that this code pass: /*jshint undef: false */ if (a == true) { } 回答1: The solution is to install the new version of jshint: npm install -g https://github.com/jshint/jshint/archive/1.0.0-rc4.tar.gz Then to use this config: { "-W041": false } Finally this command jshint --config jshint.json file.js 回答2: Just use: if (a) { } You don't ever need to use == true in a if statement. 来源: https://stackoverflow.com

How do I configure jshint to not give me the error “Bad line breaking before”?

隐身守侯 提交于 2019-12-03 14:31:30
问题 It's giving me the error "Bad line breaking before ','" because I have code like the following var one = 1 , two = 2 , three = 3 ; If I put the , at the end of the line instead of the beginning of the next, it doesn't complain. But I want to code this way. Is there a way I can make it not show this warning? I looked though JSHint's options but there isn't anything pertaining to this error. 回答1: As mentioned in the comments of the laxbreak answer, laxcomma option should actually be used for

npm run cmd fails while cmd on command line works

泄露秘密 提交于 2019-12-03 11:50:43
In my HTTP Status Check project : If I run node_modules/.bin/jshint . I get: $ node_modules/.bin/jshint . test/inAdapters_fileAdapter.js: line 73, col 31, Missing semicolon. 1 error It executes correctly and produces the expected output: 1 error. But if I add that command to package.json and try and run it through npm run then it works and produces the expected output but also follows that with a bunch of errors: $ npm run jshint > http-status-check@0.0.5 jshint /home/guy/source/http-status-check > jshint . test/inAdapters_fileAdapter.js: line 73, col 31, Missing semicolon. 1 error npm ERR!

Expressions in JavaScript Ternary Operator and JSLint

风格不统一 提交于 2019-12-03 10:52:07
问题 I recently received a comment on one of my blog posts about JSLint asking why JSLint threw an error with the following: s === "test" ? MyFunc() : MyFunc2(); The error generated was: "Expected an assignment or function call and instead saw an expression." Clearly JSLint is expecting an assignment here, somthing more like: var y = (s === "test") ? MyFunc() : MyFunc2(); But, I don't really see the problem with the first example. Is it really the case that ternary operators should only be used

Why is Jshint saying “variable already defined” in this if statement?

醉酒当歌 提交于 2019-12-03 06:28:20
问题 I have this code: if ( something is true ) { var someVar = true; } else { var someVar = false; } JsHint is saying that "someVar was already defined" on the else statement part. Why is this and how do I fix it? Thanks 回答1: JS variables do not have block scope, they have "function" scope (or sometimes global). The declaration (but not the assignment) is "hoisted" to the top of the function. jshint is warning you that you have two such declarations - your code is equivalent to: var someVar; var

Is it bad practice to use the same variable name in multiple for-loops?

我与影子孤独终老i 提交于 2019-12-03 06:27:46
问题 I was just linting some JavaScript code using JSHint. In the code I have two for-loops both used like this: for (var i = 0; i < somevalue; i++) { ... } So both for-loops use the var i for iteration. Now JSHint shows me an error for the second for-loop: "'i' is already defined". I can't say that this isn't true (because it obviously is) but I always thought this wouldn't matter as the var i is only used in that specific place. Is it bad practice to use for-loops this way? Should I use a

How to suppress “{variable} is better written in dot notation.”

牧云@^-^@ 提交于 2019-12-03 06:11:15
问题 Is there an option to and/or how do I suppress errors like the following? 175,14:['tracker'] is better written in dot notation. 回答1: If it's a feature and not a bug, place this at the top of your file. /*jshint sub:true*/ If it's a bug, you should refactor your code foo['tracker'] = bar // from this... foo.tracker = bar; // to this! Good post on the reasons here: https://stackoverflow.com/a/2001410/94668 回答2: In JSHint 1.0.0 and above you have the ability to ignore any warning with a special