jshint

Does JSHint support async/await?

一笑奈何 提交于 2019-11-28 21:03:09
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? Update (February 2019) : Async/await are now supported as of version 2.10.1. Simply update your .jshintrc to use "esversion": 9 . (+Info : Version changelog ) Update (july 2018) : Async/await will arrive with the release of JsHint 2.10.0. +info : https:/

jshint expects the new 'prefix' for functions

我们两清 提交于 2019-11-28 20:08:34
CSiginIn , CSignUp , CTryIt , CBlocks are all functions declared as such function CSignIn(){//stuff here} yet JSHint says that I am missing the 'new' 'prefix'. What can I do to fix this? They are just functions inside the module pattern. Also, it is asking me to remove semicolons I had placed at the end of the function which I have done. var Control = ( function () { /** *Publik */ var publik = function ( page ) { // page 1 initialization if( page == 1 ) { CSignIn(); CSignUp(); CTryIt(); CBlocks(); } Function Example... function CTryIt() { // pull elements var tryit_button = document

JS Hint - don't make functions within a loop

风格不统一 提交于 2019-11-28 18:17:50
问题 I can not get around JSHint's error message. Here is the loop I am using: for (i = 0; i < Collection.length; i += 4) { data.push({ items : Collection.slice(i, i + 4).map(function(item) { return { id: item[0], title: item[1], }; }) }); } 回答1: You can just move the function outside the loop and pass a reference to it to map : function mapCallback(item) { return { id : item[0], title : item[1], }; } for (i = 0; i < Collection.length; i += 4) { data.push({ items: Collection.slice(i, i + 4).map

JSHint (r10): 'angular' is not defined

孤人 提交于 2019-11-28 18:11:00
I have the following: angular.module('test') .controller('TestMenuController', [ '$http', '$scope', '$resource', '$state', 'os', 'us', function ( $http, $scope, $resource, $state, os, us) { When I build this in VS2014 it gives me an error message saying: JSHint (r10): 'angular' is not defined. Can someone tell me how I can avoid this message coming up? One way to tackle this is to modify your .jshintrc and set angular as one of the predefined variables, as Jayantha said. .jshintrc would look like this: { "predef": ["angular"] } One approach would be adding 'angular' as a global variable in the

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

家住魔仙堡 提交于 2019-11-28 17:21:46
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. Passing the properties in the parameters will also clutter the function, so I refuse to do this. Besides,

setup pre-commit hook jshint

99封情书 提交于 2019-11-28 16:12:53
I recently started a project on github . I've managed to setup automatic testing after each commit using Travis. But now I would like to setup a pre-commit hook with jshint too. So if jshint reports errors, the commit should fail. But is this possible, and if so, how to do this ? James Allardice But is this possible... Yes! This is possible. I recently wrote about it . Note that it's not specific to GitHub, just Git in general - as it's a pre-commit hook, it runs before any data is sent to GitHub. Any appropriately-named executable files in the /.git/hooks directory of your repository will be

Function declarations should not be placed in blocks. Use a function expression or move the statement to the top of the outer function

懵懂的女人 提交于 2019-11-28 10:52:11
I have the following code: if (typeof console === "object" && typeof console.error === "function") { function e(msg) {"use strict"; console.info(msg);} } For which jsLint gives the following error: Function statements should not be placed in blocks. Use a function expression or move the statement to the top of the outer function. Why is it giving this error and what does it mean? You should not be creating function inside if block. You are much better off doing: var e = function(){}; if(typeof console === "object" && typeof console.error === "function"){ e = function (msg){ ... }; } KyleMit

JS Hint - don't make functions within a loop

两盒软妹~` 提交于 2019-11-28 04:49:53
I can not get around JSHint's error message. Here is the loop I am using: for (i = 0; i < Collection.length; i += 4) { data.push({ items : Collection.slice(i, i + 4).map(function(item) { return { id: item[0], title: item[1], }; }) }); } You can just move the function outside the loop and pass a reference to it to map : function mapCallback(item) { return { id : item[0], title : item[1], }; } for (i = 0; i < Collection.length; i += 4) { data.push({ items: Collection.slice(i, i + 4).map(mapCallback) }); } Alternatively, you can use a JSHint directive to ignore function expressions inside loops.

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

匆匆过客 提交于 2019-11-28 04:48:43
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 config/jshint.yml would be nice. For JSHint you can create .jshintrc to your project directory with {

JSHint and jQuery: '$' is not defined

五迷三道 提交于 2019-11-28 02:40:19
The following JS: (function() { "use strict"; $("#target").click(function(){ console.log("clicked"); }); }()); Yields: test.js: line 5, col 3, '$' is not defined. When linted using JSHint 0.5.5. Any ideas? Stephen Booher If you are using a relatively recent version of JSHint, the generally preferred approach is to create a .jshintrc file in the root of your project, and put this config in it: { "globals": { "$": false } } This declares to JSHint that $ is a global variable, and the false indicates that it should not be overridden. The .jshintrc file was not supported in really old versions of