jslint

Expected an assignment or function call and instead saw an expression

断了今生、忘了曾经 提交于 2019-11-29 23:42:44
I'm totally cool with this JSLint error. How can I tolerate it? Is there a flag or checkbox for it? You get it when you do stuff like: v && arr.push(v); as opposed to: if (v) { arr.push(v); } Both do the same exact thing. If you put: window.test = function(v) { 'use strict'; var arr = []; if (v) { arr.push(v); } return arr; }; into the minifier it minifies down to this anyway: window.test=function(a){var b=[];a&&b.push(a);return b}; I don't think JSLint has an option to turn that off. JSHint (a fork with more options) has an option for it, though: The expr option, documented as "if

Maven plugins to analyze javascript code quality

大兔子大兔子 提交于 2019-11-29 23:07:59
Javascript code can be tough to maintain. I am looking for tools that will help me ensure a reasonable quality level. So far I have found JsUNit , a very nice unit test framework for javascript. Tests can be run automatically from ant on any browser available. I have not found yet some javascript equivalent of PMD, checkstyle, Findbug... Do you know any static code analysis tool for javascript ? This is an old thread, but if you're interested in running Jasmine for BDD testing in your maven project, I wrote this jasmine-maven-plugin for exactly this purpose (that is, improving JS quality by

Any tool to automatically fix simple JSLint issues? [closed]

被刻印的时光 ゝ 提交于 2019-11-29 22:55:59
I've run JSLint for the first time on a rather lengthy file, and I have a lot of errors like expected exactly 1 space between "function" and "(" or unexpected ' ' . I didn't realize this was important at all anywhere I learned about javascript and now fixing each one of these rather simple things by hand seems frustrating. Some I can figure out with simple find and replaces, but I wondered if there's any tools online that will automatically make these changes for me since they seem to be pretty straightforward? (I have /*jslint white: false */ in my file, I develop in Netbeans and auto-format

What is the correct way to check if a global variable exists?

折月煮酒 提交于 2019-11-29 21:13:52
JSLint is not passing this as a valid code: /* global someVar: false */ if (typeof someVar === "undefined") { var someVar = "hi!"; } What is the correct way? bigoldbrute /*global window */ if (window.someVar === undefined) { window.someVar = 123456; } if (!window.hasOwnProperty('someVar')) { window.someVar = 123456; } /** * @param {string} nameOfVariable */ function globalExists(nameOfVariable) { return nameOfVariable in window } It doesn't matter whether you created a global variable with var foo or window.foo — variables created with var in global context are written into window. If you are

Why does JSHint throw a warning if I am using const?

筅森魡賤 提交于 2019-11-29 19:03:18
This is the error I get when using const: <error line="2" column="1" severity="warning" message="&apos;const&apos; is available in ES6 (use esnext option) or Mozilla JS extensions (use moz)." source="jshint.W104" /> My code looks like this: const Suites = { Spade: 1, Heart: 2, Diamond: 3, Club: 4 }; The code works fine only JSHint is warning me every time. When relying upon ECMAScript 6 features such as const , you should set this option so JSHint doesn't raise unnecessary warnings. /*jshint esnext: true */ ( Edit 2015.12.29 : updated syntax to reflect @Olga's comments ) /*jshint esversion: 6

“Use the array literal notation []” for var os_map = {}

ぐ巨炮叔叔 提交于 2019-11-29 17:54:31
问题 I don't understand why I get the error message when I run JSLint with a JavaScript file. I get the message var os_map = {}; Problem at line 28 character 36: Use the array literal notation []. if I run this code in JSLint. The options for the JSLint as the following. /*jslint onevar: true, browser: true, undef: true, nomen: true, eqeqeq: true, plusplus: true, bitwise: true, regexp: true, strict: true, newcap: true, immed: true */ Claiming object (, which is {} ) should be okay, but JSLint

Is a reversed switch statement acceptable JavaScript?

倖福魔咒の 提交于 2019-11-29 13:53:38
JSLint is complaining that (true) is a weird condition . Which is understandable if I wasn't using it on a reversed switch statement. So is JSLint wrong or should I not be using reversed switch statements? Thanks for any help/enlightenment. switch (true) { case (menuLinksLength < 4): numberOfColumns = 1; break; case (menuLinksLength > 3 && menuLinksLength < 7): numberOfColumns = 2; break; case (menuLinksLength > 6 && menuLinksLength < 10): numberOfColumns = 3; break; case (menuLinksLength > 9): numberOfColumns = 4; break; default: numberOfColumns = 0; } The third edition of the ECMA-262

JSLint “document.write can be a form of eval” - How is this so?

笑着哭i 提交于 2019-11-29 12:21:08
问题 I've come across this message in JSLint... document.write can be a form of eval. and was wondering exactly how so? The JSLint instructions page states: The eval function...provide access to the JavaScript compiler. This is sometimes necessary, but in most cases it indicates the presence of extremely bad coding.... So, how does document.write "provide access to the JavaScript compiler" then? Thanks 回答1: What does your browser do with this? document.write('<script type="text/javascript">window

Is there a difference between ++i and i++ in this loop?

倖福魔咒の 提交于 2019-11-29 11:37:50
The array.prototype.reduce function at: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/Reduce It has the following loop: for (index = 0; length > index; ++index) { if (this.hasOwnProperty(index)) { if (isValueSet) { value = callback(value, this[index], index, this); } else { value = this[index]; isValueSet = true; } } } I don't think there is a difference whether the index is pre or post incremented here since it's done after the loop iterates each time, but want to be certain. Can this be changed to index += 1 so it passes jslint? Please don't debate

JsLint 'out of scope' error

Deadly 提交于 2019-11-29 10:51:14
问题 function test(){ if(true){ var a = 5; } alert(a); } test(); I keep getting 'out of scope' errors in my JS code when I check with JsLint which make no sense to me.So I quickly created an example. Is there something actually wrong with this code piece, as the variable is eventually hoisted to the top of the function anyways. 回答1: While var localizes a variable to the function and is subject to hoisting, most languages have block scope and not function scope. By using the var keyword inside an