jshint: enforcing "globalstrict" : false when "node" : true - jshint

In my .jshintrc file I have globalstrict set to false and node set to true. A side affect of this is that is appears to suppress the warnings I would expect if a global use strict was in place.
Is there any way of overriding this behaviour so that the warning is not suppressed?
Edit
Having re-read the docs on jshint.com and some of the issues on GitHub (notably #1922 and #2551) I have modified my .jshintrc as follows:
{
"bitwise": true,
"curly": true,
"debug": false,
"eqeqeq": true,
"forin": true,
"freeze": true,
"futurehostile": true,
"globalstrict": false,
"latedef": true,
"noarg": true,
"nonbsp": true,
"nonew": true,
"singleGroups": true,
"strict": true,
"undef": true,
"unused": "strict",
"browser": false,
"devel": false,
"node": true,
"predef": [
"-console"
],
"+W097": true
}
However this doesn't work for this particular message (it does though if, for example, I change it to -W034, which is the functional equivalent).
Thanks

This currently isn't possible however issue #2575 and associated pull request #2576 will provide the functionality if they are accepted.

Related

NextJS: Build components to export and pull into a different project

Current Setup: I have two NextJS apps: one we'll call Project A and a library repo that we'll call Project LIB. Project A is a fairly simple app that has a couple independent components whereas Project LIB is a library-like app that many other apps leverage.
What I am trying to do: Package up Project A in a way where the build distribution contains all of its components that I can then leverage in Project LIB. I am currently building/deploying Project A as a private repo and pulling it into Project LIB using npm install git#github.com:<organization>/<Project A>.git and that is working fine. My current issue is that only the pages are being build when I build Project A using npm run build and it doesn't also generate each component's corresponding .d.ts file under /components.
I figured setting "declaration": true /* Generates corresponding '.d.ts' file. */ would generate the components for me but that didn't seem to do the trick. I'm also not finding much online regarding how to do this. Maybe i'm just a bad googler, who knows.
Anyways, here's what my tsconfig and package.json files looks like:
package.json:
{
...,
"files": [
"lib/**/*"
]
}
tsconfig.json:
{
"compilerOptions": {
"target": "es5",
"module": "ESNext",
"lib": [
"dom",
"dom.iterable",
"esnext"
],
"allowJs": true,
"jsx": "preserve",
"declaration": true,
"declarationMap": true,
"sourceMap": true,
"outDir": "./lib",
"rootDir": "./",
"removeComments": true,
"noEmit": true,
"isolatedModules": true,
"strict": true,
"moduleResolution": "node",
"esModuleInterop": true,
"skipLibCheck": true,
"forceConsistentCasingInFileNames": true,
"resolveJsonModule": true
},
"include": [
"next-env.d.ts",
"**/*.ts",
"**/*.tsx",
"components/**/*"
],
"exclude": [
"node_modules/*",
"./node_modules",
"./node_modules/*",
"./lib"
]
}

grunt jshint config not working

Having trouble setting up jshint options for grunt
Here is my gruntfile.js
grunt.initConfig( {
jshint : {
options: {
curly: false,
asi: true,
eqeqeq: false,
maxparams: 5,
undef: false,
unused: false,
eqnull: true,
browser: true,
devel: true,
expr: true,
jquery: true ,
evil : true
},
files : {
src : [
'dev/*.js', 'dev/**/*.js' ,
'files-lib/*.js', 'files-lib/**/*.js' ]
},
},
still getting the errors
71 | return (this.optional(element) && value=="") ||
re.test(value);
^ Use '===' to compare with ''.
Thanks for helping
short answer: There's nothing else you can do in your options configuration to avoid this.
longer answer: Although you have the eqeqeq property set to false in your options configuration, (which assumes instances of the double equals == should not throw an error), jshint in this instance I believe is correctly reporting this as an error.
The value=="" part in the code being validated is what is throwing the error (i.e. it's ignoring the eqeqeq: false option). This is for good reason!
The == operator will compare for equality after doing any necessary type conversions, which can lead to really quirky results in Javascript. For example:
0 == "" // true
false == "" // true
Whilst I appreciate double equals yields the correct result for many comparison scenarios, this value=="" example is certainly a scenario whereby triple equals should be used, or if you're a double equals only person, then you could replace value=="" with value.length == 0
Additional info regarding triple equals and double equals operators, and it's various quirks, can be found in the answer to this post

__awaiter is not defined when using async/await in Typescript

I have the following code snippet in Typescript:
nsp.on('connection', async function (socket) {
await this.emitInitialPackage(nsp, currentLine, currentCell);
}
emitInitialPackage(nsp: any, name: string, cell: any) {
return db.Line.find({
where: {
name: name,
CellId: cell
}
}).then(results => {
nsp.emit('value', results);
}).catch(err => console.log(err));
}
However, when this is compiled (v2.2.1) and run, I get the following error:
Uncaught ReferenceError: __awaiter is not defined
What does this mean and how do I get the expected functionality?
Update:
{
"compilerOptions": {
"target": "es5",
"module": "commonjs",
"moduleResolution": "node",
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"allowSyntheticDefaultImports": true,
"sourceMap": true,
"noEmitHelpers": true,
"strictNullChecks": false,
"lib": [
"dom",
"es2015.promise",
"es5"
],
"types": [
"node",
"express"
]
},
"exclude": [
"node_modules",
"dist"
]
}
When you use some functionalities from future version of JavaScript (ES6 and beyond) like in your case async/await, TypeScript generates helper functions. These helper functions are used to provide the new functionalities as ES5 code, thus it can be run in a web browser.
Your problem:
In your tsconfig.json you set the noEmitHelpers value to true. By doing that you tell the TypeScript compiler that you will provide these helper functions yourself.
How to fix it:
You can set the noEmitHelpers value to false in your tsconfig.json, thus the TypeScript compiler will emit the helper functions when needed. One drawback of this method is that if you use for example async/await in 2 different files, the helper functions will be emitted 2 times (one per file).
The other solution is to set the --importHelpers flag when you use tsc. It will tell the TypeScript compiler to include the helper functions only once. Please note that if you use this solution you have to install the tslib package.
In your case: tsc --importHelpers -w
The accepted answer didn't work in my case, but I found that my tsconfig.json was targeting es6 ("target":"es6").
What this means is that TypeScript transpiles to code that uses the __awaiter util because async await was not included in the spec until ES2017.
I fixed this by changing my target to ESNext (or anything ES2017 and above)

how to get all bucket types in riak using http get

I know how to list all bucket types using command line .reference http://stackoverflow.com/questions/30785431/how-to-list-all-the-bucket-types-in-riak
But I need it using HTTP call
There is currently no way to list bucket types via HTTP. I can suggest two options:
Wrap the riak-admin bucket-types list command in a simple Web service and expose it via HTTP.
Install the experimental Riak Explorer, point it to your cluster, and use the bucket_types endpoint to list bucket types. For example, curl -X GET http://127.0.0.1:9000/explore/clusters/default/bucket_types should give you something like
{
"bucket_types": [{
"id": "default",
"props": {
"active": true,
"allow_mult": true,
"basic_quorum": false,
"big_vclock": 50,
"chash_keyfun": "{riak_core_util,chash_std_keyfun}",
"dvv_enabled": false,
"dw": "quorum",
"last_write_wins": false,
"linkfun": "{modfun,riak_kv_wm_link_walker,mapreduce_linkfun}",
"n_val": 3,
"notfound_ok": true,
"old_vclock": 86400,
"postcommit": [],
"pr": 0,
"precommit": [],
"pw": 0,
"r": "quorum",
"rw": "quorum",
"small_vclock": 50,
"w": "quorum",
"write_once": false,
"young_vclock": 20
}
}],
"links": {
"self": "/explore/clusters/default/bucket_types"
}
}

Jshint jasmine functions undefined in mean.js

I have a mean.js application running, and every jasmine function name returns undefined even when i did what the following told me to do:
JSHint thinks Jasmine functions are undefined
This is the relevant code from my project:
.jshintrc
{
"node": true, // Enable globals available when code is running inside of the NodeJS runtime environment.
"jasmine": true,
"browser": true, // Standard browser globals e.g. `window`, `document`.
"esnext": true, // Allow ES.next specific features such as `const` and `let`.
"bitwise": false, // Prohibit bitwise operators (&, |, ^, etc.).
"camelcase": false, // Permit only camelcase for `var` and `object indexes`.
"curly": false, // Require {} for every new block or scope.
"eqeqeq": true, // Require triple equals i.e. `===`.
"immed": true, // Require immediate invocations to be wrapped in parens e.g. `( function(){}() );`
"latedef": true, // Prohibit variable use before definition.
"newcap": true, // Require capitalization of all constructor functions e.g. `new F()`.
"noarg": true, // Prohibit use of `arguments.caller` and `arguments.callee`.
"quotmark": "single", // Define quotes to string values.
"regexp": true, // Prohibit `.` and `[^...]` in regular expressions.
"undef": true, // Require all non-global variables be declared before they are used.
"unused": false, // Warn unused variables.
"strict": true, // Require `use strict` pragma in every file.
"trailing": true, // Prohibit trailing whitespaces.
"smarttabs": false, // Suppresses warnings about mixed tabs and spaces
"predef": [ // Extra globals.
"jasmine",
"angular",
"ApplicationConfiguration",
"define",
"require",
"exports",
"module",
"describe",
"before",
"beforeEach",
"after",
"afterEach",
"it",
"inject",
"expect"
],
"indent": 4, // Specify indentation spacing
"devel": true, // Allow development statements e.g. `console.log();`.
"noempty": true // Prohibit use of empty blocks.
}
gruntfile.js
jshint: {
all: {
src: watchFiles.clientJS.concat(watchFiles.serverJS),
options: {
jshintrc: true,
node: true,
jasmine: true
}
}
},
Still, 'it is not defined' ....
wat's wrong?
That Answer/jshint API is out of date. Try "predef" as the key in your .jshintrc instead of "globals". It's also an array. Final file should look like:
{
"node": true,
"jasmine": true,
....
"predef": [
"jasmine",
"angular",
"ApplicationConfiguration"
],
}
Also, make sure it's preceded with a . (should be .jshintrc)
Refs: http://jshint.com/docs/

Resources