Jshint jasmine functions undefined in mean.js - jshint

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/

Related

Did Firebase Cloud Functions ESLint change recently?

I created a cloud function project with firebase a few months ago, and used linting.
I recently created a new cloud function project with linting, and now the linter is complaining about random rules I never set. I don't remember it enforcing nearly the amount of style rules a few months ago.
Things like:
This line has a length of 95. Maximum allowed is 80
Missing JSDoc comment
Missing Trailing comma
expected indentation of 2 spaces but found 4
Strings must use singlequote
It's also not letting me use async/await.
I found out I can individually set these rules in my .eslintrc.js file, but that's annoying and I don't want to do that. By default, why aren't these rules disabled? I just want basic rules that make sure my code won't fail when run, not random style preferences like single/double quotes and max line length.
Is there any way to use just basic linting functionality with firebase functions?
I ran into the same issue as you. The new, more strict linting rules seem to come from the fact that Firebase functions use the "google" eslint base configuration plugin by default now. Read more about configuring ESLint plugins in the docs. My older Firebase functions were using tslint without issue.
Here's what my .eslintrc.js file looked like while I was getting style errors from eslint:
module.exports = {
env: {
es6: true,
node: true,
},
extends: [
'eslint:recommended',
'plugin:import/errors',
'plugin:import/warnings',
'plugin:import/typescript',
'google',
],
parser: '#typescript-eslint/parser',
parserOptions: {
project: ['tsconfig.json', 'tsconfig.dev.json'],
sourceType: 'module',
},
ignorePatterns: [
'/lib/**/*', // Ignore built files.
],
plugins: ['#typescript-eslint', 'import'],
rules: {
quotes: ['error', 'double'],
},
};
I deleted 'google' from the extends property, which seemed to resolve almost all of the style linting issues.
Now it looks like this:
module.exports = {
env: {
es6: true,
node: true,
},
extends: [
'eslint:recommended',
'plugin:import/errors',
'plugin:import/warnings',
'plugin:import/typescript',
],
parser: '#typescript-eslint/parser',
parserOptions: {
project: ['tsconfig.json', 'tsconfig.dev.json'],
sourceType: 'module',
},
ignorePatterns: [
'/lib/**/*', // Ignore built files.
],
plugins: ['#typescript-eslint', 'import'],
rules: {
quotes: ['error', 'double'],
},
};
You can get rid of the google extends value but I would suggest keeping it and just turning off the rules that bother you the most, which for me is indentation and max length (of lines):
module.exports = {
root: true,
env: {
es6: true,
node: true,
},
extends: [
"eslint:recommended",
"google",
],
rules: {
"quotes": ["error", "double"],
"indent": ["off"],
"max-len": ["off"],
},
};
For anyone who is confused by this, there is a lint config file in the Cloud Functions folder that you can edit. As of this answer, that file is named .eslintrc.js.

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)

google closureCompiler doesn't want to read my goog.getMsg()

I'm trying to compile my js files using closure compiler, but it's giving me this error:
ERROR - goog.getMsg() function could be used only with MSG_* property or variable
my closureCompiler options are:
closureCompiler: {
options: {
compilerFile: 'temp/compiler.jar',
compilerOpts: {
compilation_level: 'ADVANCED_OPTIMIZATIONS',
//compilation_level: 'WHITESPACE_ONLY',
language_in: 'ECMASCRIPT6',
language_out: 'ECMASCRIPT5_STRICT',
formatting: 'PRETTY_PRINT',
externs: ['src/js/compiled/react-extern.js'],
warning_level: 'verbose',
summary_detail_level: 3,
output_wrapper: '"(function(){%output%}).call(window);"',
create_source_map: 'src/js/compiled/output.js.map',
manage_closure_dependencies: true,
use_types_for_optimization: null,
debug: true
},
execOpts: {
maxBuffer: 999999 * 1024
}
},
compile: {
//src: 'src/js/debug/**/*.js',
src: [
'temp/closure-library/closure/goog/base.js',
'src/js/compiled/test.js'
],
dest: 'src/js/compiled/compiled.js'
},
},
I believe I'm missing a flag, but I don't which one to write ?
You can't include goog.getMsg() in your code.
It has to be:
var MSG_SOMETHING = goog.getMsg('something');
and use the MSG_SOMETHING instead.
Google Closure Compiler enforced that, so you could write all your variable in one file and send this one to get translated.

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

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.

Resources