jslint

Ember-CLI: Fix for “'Ember' is not defined”?

若如初见. 提交于 2019-12-05 06:45:27
问题 When using Ember-CLI and running ember server, I get the following error from JSLint: [app_path]/filename.js: line 1, col 16, 'Ember' is not defined. Adding import Ember from 'ember'; fixes this. Is this the official way to go now on all my files? The documentation does not mention this change yet. 回答1: EDIT From Stephan Penner: We explicitly left it [Ember] out [of the .jshintrc file], please import ember instead. We plan on exposing more and more of ember as es6, someday this will allow the

JSLint complaining about my try/catch

纵然是瞬间 提交于 2019-12-05 03:01:01
The javascript, when run through JSLint yells at me and I am not sure why. /*jslint browser: true, devel: true, evil: true, undef: true, nomen: true, eqeqeq: true, plusplus: true, bitwise: true, newcap: true, immed: true */ var foo = function() { try { console.log('foo'); } catch(e) { alert(e); } try { console.log('bar'); } catch(e) { alert(e); } }; foo(); It tells me: Problem at line 12 character 11: 'e' is already defined. } catch(e) { It appears to be upset that I have a second catch(e) . Why would this be an issue? Does it not simply set e to local variable inside the catch block? Do I

JavaScript code checking beyond JSLint [closed]

删除回忆录丶 提交于 2019-12-05 01:53:22
I'm looking for something that works like Checkstyle for JavaScript. I know about JSLint and I'm already using Google's Closure compiler, but these mostly check for syntactic issues. Checkstyle can check for braces on the wrong line, but it also makes it possible to write custom checks like don't use HashMap. I'm looking for something like that for an upcoming JavaScript project. Any ideas? Google Closure Linter: http://code.google.com/closure/utilities/ "The Closure Linter is a utility that checks JavaScript files for style issues such as operator placement, missing semicolons, spacing, the

How to concisely assign and immediately invoke a function variable?

旧街凉风 提交于 2019-12-05 01:28:55
问题 The following is a method for defining an anonymous function within a closure, invoke the function, and forget it: (function () { "do stuff"; })(); This is used to maintain a limited scope without adding bulk to the script (IIFE: Immediately-Invoked Function Expression). What if you're hoping to immediately execute a function, while still retaining the function for future use, like the following: var doThing; (doThing = function () { "do stuff"; })(); This works in the browsers I've tested

JSLint doesn’t expect my tildes

佐手、 提交于 2019-12-05 01:26:16
JSLint insists that my use of the somewhat exotic tilde operator in the below example is unexpected. What I’m wondering is whether this is a limitation of JSLint? or strict mode? or what else am I missing? (function () { 'use strict'; if (~'foo'.indexOf('bar')) { return 'wild accusations'; } }()); Also, why shouldn’t I use the simple-looking tilde operator instead of the more complex example below? Surely there must be a good reason not to? if ('foo'.indexOf('bar') >= 0) { … } From the JSLint Docs : Bitwise Operators JavaScript does not have an integer type, but it does have bitwise operators.

JSLint - problems declaring variables

北慕城南 提交于 2019-12-05 01:16:32
The following code passes JSLint: var sGreeting = 'hello world'; switch (sGreeting) { case 'Hello world!': var a = 'some a value'; break; case 'Kamusta mundo!': var b = 'some b value'; break; case 'Salut le Monde!': var c = 'some c value'; break; default: break; } However, once I put that code in a function, JSLint complains that I should Combine ... with the previous 'var' statement. If I follow JSLint, I would be defining variables that may never need to be used. How should I deal with this problem? Here's the code followed by JSLint's errors: function foo() { 'use strict'; var sGreeting =

Is there a way to catch typos when writing CoffeeScript

久未见 提交于 2019-12-05 01:15:54
问题 This small CoffeeScript contains a typo drinks = "Coffee" drinks = drinks + ", " + "Tea" drinsk = drinks + ", " + "Lemonade" alert drinks The intention was to alert "Coffee, Tea, Lemonade" but the result is instead "Coffee, Tea". The generated JavaScript is still valid and passes JSLint; it declares the variables before usage which is good, but its the wrong variables. var drinks, drinsk; drinks = "Coffee"; drinks = drinks + ", " + "Tea"; drinsk = drinks + ", " + "Lemonade"; alert(drinks); If

Putting ; at the end of a function definition

情到浓时终转凉″ 提交于 2019-12-04 23:50:25
Why is it considered best practise to put a ; at the end of a function definition. e.g. var tony = function () { console.log("hello there"); }; is better than: var tony = function () { console.log("hello there"); } TL;DR: Without a semicolon, your function expression can turn into an Immediately Invoked Functional Expression depending on the code that follows it. Automatic semicolon insertion is a pain. You shouldn't rely on it: var tony = function () { console.log("hello there"); // Hint: this doesn't get executed; }; (function() { /* do nothing */ }()); Versus: var tony = function () {

JSLint “eval is evil.” alternatives

与世无争的帅哥 提交于 2019-12-04 19:16:44
问题 I am have some JavaScript functions that run on both the client (browser) and the server (within a Java Rhino context). These are small functions - basically little validators that are well defined and don't rely upon globals or closures - self-contained and portable. Here's an example: function validPhoneFormat(fullObject, value, params, property) { var phonePattern = /^\+?([0-9\- \(\)])*$/; if (value && value.length && !phonePattern.test(value)) return [ {"policyRequirement": "VALID_PHONE

Should I worry about “window is not defined” JSLint strict mode error?

我只是一个虾纸丫 提交于 2019-12-04 16:28:09
问题 This won't pass JSLint in strict mode: "use strict"; (function (w) { w.alert(w); }(window)); The error--from jslint.com--looks like this: Problem at line 4 character 3: 'window' is not defined. }(window)); Implied global: window 4 Do I need to tell JSLint to ignore the error, or am I seriously doing something wrong? 回答1: Try adding the following: /*jslint browser: true */ /*global window */ (or check Assume a browser checkbox). The first line adds general browser support. The second line