jshint

Expected an assignment or function call and instead saw an expression

孤人 提交于 2019-12-18 10:48:38
问题 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}; 回答1: I don't think JSLint has an option to turn that off.

Does jshint understand Angular?

给你一囗甜甜゛ 提交于 2019-12-18 01:55:27
问题 jshint is throwing an error when defining an angular module (or directive, or factory) as recommended by the Angular style guides (by John Papa or Todd Motto). For example, for a controller like this: (function () { 'use strict'; angular .module('myApp') .controller('myAppCtrl', theController); function theController() {...} })(); ... jshint throws this error: 'theController' was used before it was defined. The angular app works perfectly despite these errors. However I don't know why jshint

Does JSHint support async/await?

旧街凉风 提交于 2019-12-17 22:55:40
问题 I'm using JSHint for the JavaScript project (with the Visual Studio Code). And in this project I use async / await, which JSHint highlights as errors. I tried to set up jshint, but the it seems like the maxim version of "esversion" is 6. Does jshint support async/await yet? If it does, how to turn it on? And if not, are there any workarounds? 回答1: Update (February 2019) : Async/await are now supported as of version 2.10.1. Simply update your .jshintrc to use "esversion": 9 . (+Info : Version

JSHint “Possible strict violation.” when using `bind`

試著忘記壹切 提交于 2019-12-17 21:57:26
问题 Consider this simple code: "use strict"; var obj = { f: function() { this.prop = 'value'; g.bind( this )(); } }; function g() { console.log( this.prop ); } If I try to validate this code, jshint gives me the error Possible strict violation. where I call console.log( this.prop ); . This is because this is undefined in strict mode in a function. But I'm binding this function before calling it, so this is the correct object. I'm using this "design pattern" to avoid cluttering the main object.

How to tell JSLint / JSHint what global variables are already defined

女生的网名这么多〃 提交于 2019-12-17 17:42:30
问题 In my project we have some global variables that work as containers: MyProject.MyFreature.someFunction = function() { ... } So then I use that script across the site and JSLint / JSHint complains about that: 'MyProject' is not defined I know that I can go to every JavaScript file and add the comment /*global MyProject*/ on top of it. But I'm looking a way to define that comment in some sort of config file so I don't have to go file by file adding this comment. Some kind on option in the

Detecting typos in JavaScript code

£可爱£侵袭症+ 提交于 2019-12-14 03:43:38
问题 In Python world, one of the most widely-used static code analysis tools, pylint has a special check, that detects typos in comments and docstrings. Is there a way to detect typos in JavaScript code using static code analysis? To make the question more specific, here is an example code I want to cause a warning: // enter credntials and log in scope.loginPage.logIn(browser.params.regularUser.login, browser.params.regularUser.password); Here credntials is misspelled. 回答1: There is a eslint

How to disable “use strict” in JSHint

梦想的初衷 提交于 2019-12-13 02:16:36
问题 I'd like to eliminate the 'Missing "use strict" statement.' warning that JSHint shows in my .js files. Now, I want to keep the rest of the functionality intact, and I want a global way to disable the "use strict;" thing, because inserting the "use strict" command into every file is not an option for me. I haven't been able to find any solutions that don't involve adding "use strict;" to each file, so I'm hoping this question will point me in the right direction. Thanks. 回答1: Just set strict

jshint grunt exported options

♀尐吖头ヾ 提交于 2019-12-13 01:19:40
问题 Hi I'm trying to achieve the following. I'm using grunt for jshint validating. Somewhere in a file I have used: var logger = function () { // some ode } Because logger is never actually used jshint correctly shows me the following error. W098: 'logger' is defined but never used. I could set unused to false and it would work perfectly. But I actually want the option to take place in other files and warn me about unused variables. So the unused option is not gonna work for me. I also saw that I

How can I make a Grunt task fail if one of its sub tasks fail?

久未见 提交于 2019-12-12 19:42:29
问题 I have a build task in grunt, which looks like this: grunt.registerTask("build", ["jshint", "uglify"]); The problem is that the uglify task runs even if the jshint task fails, how can I make the 'build' task terminate if one of it's sub tasks fails? 回答1: The default behavior in Grunt is to not run subsequent tasks if one fails. So you must be using the force option somewhere. You are either: 1 - passing --force on the command line 2 - calling grunt.option( 'force', true ); somewhere 3 - have

Custom settings with jshint-rhino.js

心不动则不痛 提交于 2019-12-12 19:02:08
问题 I've been using jshint with node but just recently had to switch over to using it with Rhino. I used to be able to do: jshint --config=jsHintConfig.json fileToLint.js Now, I've tried replacing that call with: rhino jshint-rhino.js --config=jsHintConfig.json fileToLint.js But it doesn't seem to work. I only get the following printed to the console: Usage: jshint.js file.js Does jshint-rhino not accept a json configuration file? Update: http://anton.kovalyov.net/2011/03/01/jshint-edition-update