jslint

Why 'Unexpected “.”' when using || operator for a default value in parenthesis

ε祈祈猫儿з 提交于 2019-12-08 15:54:04
问题 Getting Unexpected "." from jslint ( http://jslint.com/ ) on this code: function test(foo) { "use strict"; return (foo || "").replace("bar", "baz"); } Why does jslint have a problem with the || operator to force an empty string so a replace can be performed without causing an error, in case foo is passed in as undefined? This passes: function test(foo) { "use strict"; var xFoo = (foo || ""); return xFoo.replace("bar", "baz"); } I know it's opinion based and I can ignore it, etc... but trying

JSlint on TypeScript code - can it still teach me to write better code?

不羁的心 提交于 2019-12-08 15:00:47
问题 Can using JSlint on TypeScript generated code still teach me to write better code? If yes en can you please provide one or two examples? Thanks 回答1: Nope. Since the generated javascript is consistent between bad typescript / good typescript (e.g. missing semicolons). For typescript there is a (recommended) ts-lint : https://www.npmjs.org/package/tslint Also has a grunt plugin : https://www.npmjs.org/package/grunt-tslint 来源: https://stackoverflow.com/questions/21827126/jslint-on-typescript

Method expression is not of Function type

痴心易碎 提交于 2019-12-08 14:46:10
问题 I have the following JavaScript file: /*global $ */ function foo() { 'use strict'; var $tr = $('table tr'), $td = $tr.children('td'); $td.html('Hello World'); } In PHPStorm, children gets underlined with a weak warning. Mousing over it reveals this message: Method expression is not of Function type This file is in the same directory as jquery.min.js (v. 1.11.0, if that matters). How can I fix this? Note that the above example is a minimalist example sufficient to reproduce the problem; it's

Javascript/jsLint: What to replace jQuery(this) with when using “use strict”;

强颜欢笑 提交于 2019-12-08 14:30:11
问题 When I validate the following code with jslint I get the following errors. function displayMegaDropDown() { "use strict"; var liMegaPosition, divMegaOffset; liMegaPosition = jQuery(this).position(); divMegaOffset = { top: liMegaPosition.top + jQuery(this).height(), left: liMegaPosition.left }; jQuery(this).find("div").offset(divMegaOffset); jQuery(this).addClass("hovering"); } Problem at line 4 character 29: Strict violation. liMegaPosition = jQuery(this).position(); Problem at line 5

JSLint unused variable error

不问归期 提交于 2019-12-08 12:18:28
问题 I created a javascript document and I want to make this JSlint valid. http://pastebin.com/GvZLyNbV /*jslint browser: true, indent: 2 */ /*global ActiveXObject: true, window: true*/ (function (window) { "use strict"; /** * ajax class * * ez az objektum fogja kezelni az ajax kérelmeket. lényege hogy nagyon * minimális legyen. nem akarom jobban magyarázni, eléggé bonyolult, mert a * különböző böngészők különbözően kezelik az ajax hívásokat. */ var ajax = window.ajax = {}; ajax.XHR = { getXHR:

Variable naming conventions other than trailing underscore [duplicate]

我们两清 提交于 2019-12-07 21:08:36
问题 This question already has answers here : JSLint reports “Unexpected dangling” character in an underscore prefixed variable name (4 answers) Closed 3 years ago . I'm reformatting a plug-in so that it passes JSLint. Plug-in uses trailing underscores to name local variables, like so: var __slice = [].slice, __indexOf = [].indexOf JSLint does not like this. What's another easily recognisable convention for naming these, that JSLint won't object to? 回答1: Quoting from Douglas Crockford, the guy who

JavaScript code checking beyond JSLint [closed]

牧云@^-^@ 提交于 2019-12-06 22:05:24
问题 As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance. Closed 7 years ago . I'm looking for something that works like Checkstyle for JavaScript. I know about JSLint and I'm already using Google's Closure

Putting ; at the end of a function definition

萝らか妹 提交于 2019-12-06 18:43:03
问题 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"); } 回答1: 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"); //

Why does JSLint prefer dot notation over Square Bracket?

人走茶凉 提交于 2019-12-06 17:44:00
问题 I've been linting some of my code and got some errors back saying it is better to use dot notation. I found out I was using square bracket notation (with clarity from this great post), however, I wanted to ask why exactly does Crockford prefer dot notation? The project I'm working on has used SBN for it's entirity, and I don't think it's confusing or un-readable, but if there are distinct reasons to user dot, I will correct it. Just want to understand it fully before proceeding! 回答1: As I

JSLint and the “Expected to see a statement and instead saw a block.” error

怎甘沉沦 提交于 2019-12-06 14:44:25
I have picked up the habit of wrapping all of my case statements in curly brackets from programming in C because of this but JSLint is throwing a fit. It stops validating at that point. My question is: Is this such a bad practice in JS? Do I not have to worry about the scope issue because JS has function scope (I understand how that would be the case, I just want a good reason not to be 'consistent' on this)? (I know that different languages call for different practices, but i am trying to be as consisten as possible across languages to help protect my sanity.) Good question. The reason that