JSHint W117 inline ignore - jslint

JSHint override not being respected.
[Output]: [L59:C38] W117: 'alert' is not defined.
[Output]: /*jshint -W117 */alert("failed to load review data..");/*jshint +W117 */
-- Actual line of code:
$scope.example.$get(
function(data){
$scope.data = //do something;
}, function(message){
/*jshint -W117 */alert("failed..");/*jshint +W117 */
});
I use these for other warnings, but W117 seems to be ignored.

Try have them on a seperate line
/* jshint -W117 */
alert("failed..");
/* jshint +W117 */
Another option to disable the warning is to add this at the top of the file
/* global alert */

alert("failed.."); //jshint ignore:line

You can also create a .jshintrc file with this content:
{
"globals": {
"alert": false
}
}
The globals configuration option says that this variable is a global defined elsewhere, and the false value says that it shouldn't be redefined.

Related

How to disable flag in "ngx-intl-tel-input" lib?

how to disable flag in "ngx-intl-tel-input" lib, I disable input field in form has ngx-intl-tel-input but not disable flag.
Please see issue fixed "https://github.com/webcat12345/ngx-intl-tel-input/issues/205"
This issue has been fixed in the latest releases. To disable your control, including the country dropdown:
phoneForm = new FormGroup({
phone: new FormControl({
value: undefined,
disabled: true
}, [Validators.required])
});
or
this.phoneForm.controls['phone'].disable();
I found a hack. Take a ref of <ngx-mat-intl-tel-input> and disable the button inside it. Check the code below.
HTML:
<ngx-mat-intl-tel-input
[preferredCountries]="['us']"
[enablePlaceholder]="true"
[enableSearch]="true"
format="national"
name="phone"
placeholder="Phone Number"
formControlName="phone"
#phoneField
></ngx-mat-intl-tel-input>
Component TS:
#ViewChild('phoneField')
public phoneField;
public ngAfterViewChecked() {
// disabling country selection button
try {
this.phoneField.elRef.nativeElement.firstChild.children[0].disabled = 'true';
} catch (e) {
// ignore this
}
}
Enjoy :)

How to ignore lines for code coverage in Jest

In Jest, is there any way to ignore code for test coverage?
I tried using
/* istanbul ignore next */
But it doesn't seem to work.
It works.
(function(global) {
var defineAsGlobal = true;
/* istanbul ignore next */
if(typeof exports === 'object') {
module.exports = lib;
defineAsGlobal = false;
}
/* istanbul ignore next */
if(typeof modules === 'object' && typeof modules.define === 'function') {
modules.define('lib', function(provide) {
provide(lib);
});
defineAsGlobal = false;
}
/* istanbul ignore next */
if(typeof define === 'function') {
define(function(require, exports, module) {
module.exports = lib;
});
defineAsGlobal = false;
}
/* istanbul ignore next */
defineAsGlobal && (global.lib = lib);
})(this);
Sample project https://github.com/ilyar/sandbox/tree/master/jest
Update for anyone that finds this at a later date.
/* istanbul ignore next */
Will work but as read from The Jest Official Documentation:
coveragePathIgnorePatterns seems to not have any effect.
Make sure you are not using the babel-plugin-istanbul plugin. Jest
wraps Istanbul, and therefore also tells Istanbul what files to
instrument with coverage collection. When using babel-plugin-istanbul,
every file that is processed by Babel will have coverage collection
code, hence it is not being ignored by coveragePathIgnorePatterns.
The documentation can be found here: Documentation
So in order to fix this issue uninstall babel-plugin-istanbul:
If it is a library based only on javascript, than you can just run npm uninstall --save babel-plugin-istanbul or npm uninstall --save-dev babel-plugin-istanbul
If you've installed a library with native content that requires linking, and you've linked it with rnpm then you can do: rnpm unlink package_name then follow step 1 - Aakash Sigdel
This quote was from Aakash Sigdel found here: quote
Found a workaround (spaces before and after the comment seem to be necessary):
class Foo {
bar /* istanbul ignore next */ () {
return 'biu~';
}
}
Just for anyone finding this who uses the v8 provider:
the docs now state how to ignore lines with different providers, and link to more details. But basically either /* c8 ignore next */ or /* c8 ignore start */ + /*c8 ignore end */ should work well with the v8 provider.
Example:
/* c8 ignore next */
if (process.env.DEBUG) console.log('debug');
/* c8 ignore start */
switch (process.env.DEBUG) {
case '1':
console.log('some verbosity');
break;
case '2':
console.log('a lot of verbosity');
break;
}
/* c8 ignore end */
In my case, I had coverageProvider: 'v8', and it was causing this to break. doing: coverageProvider: 'babel', fixed it and the pragma works great.
According to a babel issue thread Istambul appears to have a bug where it assumes the preceding line of code is terminated with a semi-colon...
constructor(message: string) {
// TODO: how do I get Jest code coverage for "super(message)?
// /* istanbul ignore next */ assumes the preceding line of code is terminated with a ;
DEBUG: console.log();
/* istanbul ignore next */
super(message);
}

jslint Missing property name

I am using jslint. I have this tolerance setting in my comments.
/*jslint todo: true*/
The online tester passes it. I have it passing in a piece of code tested earlier. However, later on I get this failure message:
Missing property name.
Does anyone know why the property name is regarded as missing in the second place and not the first?
Update 17/072014 15:03 - included code
I was able to isolate the issue with the following code. Below you can see the parts of the code if run in lint.com and what errors they output:
/**
* #todo "Unexpected TODO comment".
*/
/*jslint todo: true*/
/**
* #todo Will be tolerated by jslint.
*/
/*jslint todo: false*/
var obj = {
/**
* #todo "Unexpected TODO comment".
*/
};
/*jslint todo: true*/
var obj = {
/**
* #todo jslint will tolerate this line.
*/
};
/*jslint todo: false*/
var obj = {
/*jslint todo: true*/
/**
* #todo jslint will never get to this line.
*/
/*jslint todo: false*/
};
What I found was that the tolerance properties could not be set inside an object literal. I can now work around the issue.
I had trouble finding documentation on the issue because my searches for 'literal' were being obscured by the literal notation errors. Does anyone know why this occurs or if there is documentation to explain it, or even just state that it happens?
JSLint does not like it when you introduce /* */ comments inside of objects.
For example, I had this error with this code:
config.output = {
/*jslint nomen:true*/
path: __dirname + '/public',
/*jslint nomen:false*/
publicPath: BUILD ? '/' : 'http://localhost:8080/',
filename: BUILD ? '[name].[hash].js' : '[name].bundle.js',
chunkFilename: BUILD ? '[name].[hash].js' : '[name].bundle.js'
};
And it was resolved by changing that to:
/*jslint nomen:true*/
config.output = {
path: __dirname + '/public',
publicPath: BUILD ? '/' : 'http://localhost:8080/',
filename: BUILD ? '[name].[hash].js' : '[name].bundle.js',
chunkFilename: BUILD ? '[name].[hash].js' : '[name].bundle.js'
};
/*jslint nomen:false*/
I know it's been a year or two since you asked but, hopefully this helps anyone else who is looking.

Using knockout-jqueryui with bundling

According to "Reference bundles on requirejs" the solution to the problem of getting requirejs to reference modules delivered in a bundle is to name them with a name exactly matching the filename so that with optimisations turned off they resolve from the filesystem and with optimisations turned on they resolve from the bundle.
This is the start of knockout-jqueryui
/*! knockout-jqueryui - v1.0.0 - 3/21/2014
* https://github.com/gvas/knockout-jqueryui
* Copyright (c) 2014 Vas Gabor <gvas.munka#gmail.com>; Licensed MIT */
/*global require, define, exports*/
/*jslint browser:true, maxlen:256*/
(function (root, factory) {
'use strict';
if (typeof exports === 'object') {
// CommonJS
factory(exports, require('jquery'), require('knockout'), require('jquery-ui'));
} else if (typeof define === 'function' && define.amd) {
// AMD. Register as an anonymous module.
define(['exports', 'jquery', 'knockout', 'jquery-ui'], factory);
} else {
// Browser globals
factory((root.kojqui = {}), root.jQuery, root.ko);
}
} (this, function (exports, $, ko) {
'use strict';
As you can see it's anonymous. I have two conspicuous options:
Edit the file and give it a name matching the file.
Somehow wrap it so as to name it.
Option one is straightforward:
if (typeof exports === 'object') {
// CommonJS
factory(exports, require('jquery'), require('knockout'), require('jquery-ui'));
} else if (typeof define === 'function' && define.amd) {
// AMD. Register as a module named 'knockout-jqueryui'.
define('knockout-jqueryui',
['exports', 'jquery', 'knockout', 'jquery-ui'], factory);
} else {
// Browser globals
factory((root.kojqui = {}), root.jQuery, root.ko);
}
But it doesn't seem like a great idea. I'm pretty new to AMD so if anyone can advise me on a good way to implement an option two wrapper, that would be excellent.
I am pleased to report that I have found a nice clean solution.
Bundling causes knockout-jqueryui.js to be loaded directly by a script tag. As a result it uses the third factory option in the code extract shown in the question, producing a global kojqui.
This global is in scope for main.js and can be captured:
requirejs.config({
paths: {
'text': '../Scripts/text',
'durandal': '../Scripts/durandal',
'plugins': '../Scripts/durandal/plugins',
'transitions': '../Scripts/durandal/transitions'
}
});
define('jquery', function () { return jQuery; });
define('knockout', ko);
define('moment', function () { return moment; });
define('knockout-jqueryui', kojqui);
No change is required in knockout-jqueryui.js and I have verified that this works both with optimisations enabled and with optimisations off for debugging.

Bindings on ObjectController - Ember.js

When you try adding a binding to an ObjectController it doesn't work.
App.FailController = Em.ObjectController.extend({
content: null,
myBinding: "App.router.myController" // <-- fails
});
Error:
Uncaught Error: assertion failed: Cannot delegate set('my', ) to the 'content' property of object proxy <.FailController:ember154>: its 'content' is undefined.
It tries adding it to the content property.
jsFiddle: demo
credits: to caligo-mentis who answered this over at github.
ObjectProxy delegates any call to set to the content property unless a property with the same name exists on the ObjectProxy instance. The simple solution is to define a property with the desired name prior to declaring the binding.
App.FailController = Em.ObjectController.extend({
my: null,
myBinding: "App.router.myController" // <-- works
});
jsFiddle: demo
Alternative solution:
App.FailController = Em.ObjectController.extend({
content: Ember.Object.create(),
my: function() {
return App.router.myController;
}.property('App.router.myController')
});
or better:
App.FailController = Em.ObjectController.extend({
content: Ember.Object.create(),
my: Ember.computed.alias('App.router.myController')
});

Resources