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.
Related
I'm trying to create wfs-t service I have used the ol.format.WFS#writeTransaction method and serialize the WFS-t XML but my jslint always preview error at the GML format options. Is it possible that I am initializing the ol.format.WFS object incorrectly?
Or maybe I am passing the wrong options to the writeTransaction method? Or maybe it's a bug in OpenLayers4? this detail of my wfs-t service using angular http service:
private _transactWFS(feature: any, operation: any): any {
let payload;
try {
const formatWFS = new ol.format.WFS({});
const formatGML = new ol.format.GML({
featureNS: operation.featureNS,
featureType: operation.featureType,
srsName: operation.srsName
});
const xs = new XMLSerializer();
let node: any = null;
switch (operation.mode) {
case 'insert':
node = formatWFS.writeTransaction([feature], null, null, formatGML);
break;
case 'update':
node = formatWFS.writeTransaction(null, [feature], null, formatGML);
break;
case 'delete':
node = formatWFS.writeTransaction(null, null, [feature], formatGML);
break;
}
payload = xs.serializeToString(node);
} catch (error) {}
return payload;
}
lint message:
[ts]
Argument of type 'GML' is not assignable to parameter of type 'WFSWriteTransactionOptions'.
Property 'featureNS' is missing in type 'GML'.
From the OpenLayers WFS-T example:
// Word to the Wise from an anonymous OpenLayers hacker:
//
// The typename in the options list when adding/loading a wfs
// layer not should contain the namespace before, (as in the
// first typename parameter to the wfs consctructor).
//
// Specifically, in the first parameter you write typename:
// 'topp:myLayerName', and in the following option list
// typeName: 'myLayerName'.
//
// If you have topp included in the second one you will get
// namespace 14 errors when trying to insert features.
//
wfs = new OpenLayers.Layer.WFS(
"Cities",
"http://sigma.openplans.org/geoserver/wfs",
{typename: 'topp:tasmania_cities'},
{
typename: "tasmania_cities",
featureNS: "http://www.openplans.org/topp",
extractAttributes: false,
commitReport: function(str) {
OpenLayers.Console.log(str);
}
}
);
Seems to indicate you are building your WFS object wrong.
I'm give up using WFS Format for build WFS Transaction request so my problem was solved by myself, I found this lib geojson-to-wfs-t-2. This library is very legit for solving my problem.
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);
}
I'm trying to load a custom module in a restartless add-on, using the following:
chrome/content/modules/Test.jsm:
var EXPORTED_SYMBOLS = [ 'Test' ];
let Test = {};
chrome.manifest:
content test chrome/content/
bootstrap.js:
const Cu = Components.utils;
// Tried this first, but figured perhaps chrome directives aren't loaded here yet
// let test = Cu.import( 'chrome://test/modules/Test.jsm', {} ).Test;
function install() {
let test = Cu.import( 'chrome://test/modules/Test.jsm', {} ).Test;
}
function uninstall() {
let test = Cu.import( 'chrome://test/modules/Test.jsm', {} ).Test;
}
function startup() {
let test = Cu.import( 'chrome://test/modules/Test.jsm', {} ).Test;
}
function shutdown() {
let test = Cu.import( 'chrome://test/modules/Test.jsm', {} ).Test;
}
However, I get the following types of WARN messages (this one was for shutdown(), but basically identical for all functions and in the earlier attempt in the global scope):
1409229174591 addons.xpi WARN Exception running bootstrap method
shutdown on test#extensions.codifier.nl: [Exception... "Component
returned failure code: 0x80070057 (NS_ERROR_ILLEGAL_VALUE)
[nsIXPCComponents_Utils.import]" nsresult: "0x80070057
(NS_ERROR_ILLEGAL_VALUE)" location: "JS frame ::
resource://gre/modules/addons/XPIProvider.jsm ->
file:///test/bootstrap.js :: shutdown :: line 21" data: no] Stack
trace: shutdown()#resource://gre/modules/addons/XPIProvider.jsm ->
file:///test/bootstrap.js:21 <
XPI_callBootstrapMethod()#resource://gre/modules/addons/XPIProvider.jsm:4232
<
XPI_updateAddonDisabledState()#resource://gre/modules/addons/XPIProvider.jsm:4347
<
AddonWrapper_userDisabledSetter()#resource://gre/modules/addons/XPIProvider.jsm:6647
< uninstall()#extensions.xml:1541 < oncommand()#about:addons:1 <
Are chrome.manifest directives not yet available in bootstrap.js? Or is what I am attempting some kind of security violation, perhaps? Or am I simply doing something trivially wrong?
What I was hoping to achieve, is that I could do something like the following:
chrome/content/modules/Test.jsm:
var EXPORTED_SYMBOLS = [ 'Test' ];
let Test = {
install: function( data, reason ) {
},
/* etc */
bootstrap: function( context ) {
context.install = this.install;
context.uninstall = this.uninstall;
context.startup = this.startup;
context.shutdown = this.shutdown;
}
}
bootstrap.js:
const Cu = Components.utils;
Cu.import( 'chrome://test/modules/Test.jsm' );
Test.bootstrap( this );
Perhaps it's a bit over the top to begin with, but I just kind of like the idea of hiding implementations in modules and/or objects and keeping bootstrap.js super clean.
If you happen to have suggestions on how to achieve this by other means: I'm all ears.
Yes you can your path is wrong though.
Just do this:
let test = Cu.import( 'chrome://test/content/modules/Test.jsm', {} ).Test;
notice the /content/
You don't have to do the .Test unless you want the lower case test to hold it. You can just do:
Cu.import( 'chrome://test/content/modules/Test.jsm');
and use as Test.blah where blah is whatever is in the JSM module.
This code can go anywhere, it does not have to be in the install function.
Make sure to unload the custom JSM modules or else it can lead to zombie compartments which is bad for memory. Read here:
last paragraph here: https://developer.mozilla.org/en-US/docs/Extensions/Common_causes_of_memory_leaks_in_extensions
more reading but optional: https://developer.mozilla.org/en-US/docs/Zombie_compartments
Beyond #Noitidart's answer, you don't have to use chrome.manifest' and register a content package if your only concern is how to import your module.
function install(data, reason) {
Components.utils.import(data.resourceURI.spec + "relative/path/to/your/module.jsm");
}
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.
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.