jshint

JSLint error: Move the invocation into the parens that contain the function

别来无恙 提交于 2019-12-21 21:23:04
问题 How can i make this code jsLint Happy ? ;(function ( $, window, document, undefined ) { //some code })( jQuery, window, document ); It advises me to write it this way ? Will there be any difference ? What do i do ? (function ( $, window, document, undefined ) { //some code }( jQuery, window, document )); 回答1: I'm copying my answer from the next question in the JSLint stack. Here's why Crockford says that the second way is better. From http://javascript.crockford.com/code.html When a function

Suppress `Expected an identifier and instead saw 'default' (a reserved word)` in JSLint with Mongoose

心不动则不痛 提交于 2019-12-21 12:44:37
问题 I'm using jshint to validate my JavaScript files. On the server-side I'm using node.js with Mongoose. In Mongoose I'm encouraged to write schemata in a fashion like: var UserSchema = new mongoose.Schema({ firstname : { type: String, default: '' } }); When running linting, I get error: Expected an identifier and instead saw 'default' (a reserved word). Is there a way to suppress this error? I really would prefer that behaviour instead of writing: var UserSchema = new mongoose.Schema({

switch fall through being ignored by JSHint

我怕爱的太早我们不能终老 提交于 2019-12-21 12:27:52
问题 I'm running my code through JSHint, and I'm hitting this error: Expected a break statement before case On this block of code: switch(true) { // Renames skill1=abc to section_8_1_body=abc case Major === 0 && Minor === 0 && Patch < 433: upgraded = upgraded.replace(/(\s+)skill(\d)=/gm, '$1section_8_$2_body='); /*falls through*/ // Example case Major === 0 && Minor === 0 && Patch < 442: console.log('test'); /*falls through*/ } The code checks version information for a file, and upgrades it to be

jshint complains: 'Ember' is not defined

房东的猫 提交于 2019-12-21 07:29:12
问题 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

In Javascript, is it OK to put the ternary operator's `?` on then next line?

落爺英雄遲暮 提交于 2019-12-20 11:49:40
问题 I really like aligning the ? and the : of my ternary operator when they don't fit on a line, like this: var myVar = (condition ? ifTrue : ifFalse ); However, JSHint complains with: Bad line breaking before '?' Why would JSHint have this warning? Is there any nastyness (like semicolon insertion, etc) it is protecting me against or can I safely change my JSHINT configuration to ignore it? 回答1: This works and is certainly valid. It's especially useful in more complicated use cases, like nested

How to tell JSHint to ignore all undefined variables in one file?

做~自己de王妃 提交于 2019-12-20 11:48:34
问题 In Karma tests, there are a lot of global variables and functions, which JSHint complains about (it is integrated into my editor). How can I tell JSHint to ignore all undefined variables in this one specific file? I would expect /* jshint undef: false */ to turn off these warning, but it doesn't. 回答1: The correct way to tell JSHint about globals is to use the globals directive. For example: /*globals globalFunction, anotherGlobal, oneMore */ This will prevent "{a} is not defined" warnings

Why does JSHint dislike ternaries for method calls on objects?

最后都变了- 提交于 2019-12-19 17:43:26
问题 JSHint give the following error: Expected an assignment or function call and instead saw an expression. For the following line of code: (aFunctionOrNull) ? aFunctionOrNull() : someObject.someMethod(); It highlights the final ) on someMethod so I assume the error is there. The code works and JSHint doesn't have a problem when I change it to if () {} else {} syntax. I don't mind the longer syntax but I'd like to learn why JSHint says this and if this is a bad practice. The biggest piece of

Don't make functions within a loop. - jslint error

。_饼干妹妹 提交于 2019-12-19 08:57:06
问题 I am getting this jslint error Don't make functions within a loop. I can't change the javascript that is causing this issue - however I cant, due to restrictions from modifying it. So, I want to turn this validation to check for this error off in a particular javascript file. Is this possible to do for this js error? 回答1: No, that valildation check is not optional. A possible workaround: // simple closure scoping i to the function. for(var i = 0; i < 10; i++) { (function (index) { console.log

What is the matter with script-targeted URLs?

余生长醉 提交于 2019-12-19 05:12:43
问题 I'm using JSHint, and it got the following error: Script URL. Which I noticed that happened because on this particular line there is a string containing a javascript:... URL. I know that JSHint complained that because the scripturl option is set, and since my codebase is quite large, I'll have to unset it for now. Still, I don't understood what is the issue of using script URLs? 回答1: javascript: URLs are part of 'eval is evil'. In order to execute the javascript: URL, the browser must fire up

What is the matter with script-targeted URLs?

不想你离开。 提交于 2019-12-19 05:12:08
问题 I'm using JSHint, and it got the following error: Script URL. Which I noticed that happened because on this particular line there is a string containing a javascript:... URL. I know that JSHint complained that because the scripturl option is set, and since my codebase is quite large, I'll have to unset it for now. Still, I don't understood what is the issue of using script URLs? 回答1: javascript: URLs are part of 'eval is evil'. In order to execute the javascript: URL, the browser must fire up