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
Related
I'm trying to use VSCode for R scripts, along with the Radian terminal. I'm on Mac OS 10.14.6 (Mojave). Installation went fine. But now when I try to execute a multi-line block of code, if a line of code ends with a comma then the code to that point gets sent to the console as a complete statement, which of course generates an error. I've read https://github.com/REditorSupport/vscode-R/issues/437, but it doesn't seem to be addressing the same thing.
Here's a quick example of something that causes the problem:
mydf <- data.frame("Cat" = c("A", "B", "C"),
Values = c(12, 10, 15))
Both lines get sent to the console for execution separately, and of course both throw errors.
At the suggestion of a commenter below, here's my settings.json file:
{
"window.zoomLevel": 1,
"workbench.colorTheme": "Abyss",
"editor.wordWrap": "bounded",
"editor.wordWrapColumn": 100,
"editor.tokenColorCustomizations": {
"comments": "#7c9478"
},
"workbench.colorCustomizations": {
"editor.selectionBackground": "#0000ff"
},
"diffEditor.wordWrap": "on",
"launch": {
"configurations": [],
"compounds": []
},
"liveServer.settings.AdvanceCustomBrowserCmdLine": "Chrome",
"editor.inlineSuggest.enabled": true,
"terminal.integrated.enableMultiLinePasteWarning": false,
"r.bracketedPaste": true,
"r.plot.useHttpgd": true,
"r.alwaysUseActiveTerminal": true,
"r.rpath.mac": "/Library/Frameworks/R.framework/Resources/bin/R",
"diffEditor.ignoreTrimWhitespace": false,
"r.rterm.mac": "/usr/local/bin/radian",
"r.rterm.option": [],
"terminal.integrated.env.osx":{
"R_HOME": "/Library/Frameworks/R.framework/Resources"
},
}
Any ideas, anyone? Big thanks.
Thanks for the comments, everyone. This turned out to be a problem with settings.json scope. I had somehow made the change to r.bracketedPaste (setting it to true) in the user and default settings, but not the workspace settings, where it was still set to false (as you can probably tell, I'm new to vscode). Changing the setting at the workspace level did the trick. Sorry for the false alarm, and thanks again for the suggestions.
is there any easy method to call APIs from Wordpress website and return true or false, depends if some data is there?
Here is the API:
https://api.covalenthq.com/v1/137/address/0x3FEb1D627c96cD918f2E554A803210DA09084462/balances_v2/?&format=JSON&nft=true&no-nft-fetch=true&key=ckey_docs
here is a JSON:
{
"data": {
"address": "0x3feb1d627c96cd918f2e554a803210da09084462",
"updated_at": "2021-11-13T23:25:27.639021367Z",
"next_update_at": "2021-11-13T23:30:27.639021727Z",
"quote_currency": "USD",
"chain_id": 137,
"items": [
{
"contract_decimals": 0,
"contract_name": "PublicServiceKoalas",
"contract_ticker_symbol": "PSK",
"contract_address": "0xc5df71db9055e6e1d9a37a86411fd6189ca2dbbb",
"supports_erc": [
"erc20"
],
"logo_url": "https://logos.covalenthq.com/tokens/137/0xc5df71db9055e6e1d9a37a86411fd6189ca2dbbb.png",
"last_transferred_at": "2021-11-13T09:45:36Z",
"type": "nft",
"balance": "0",
"balance_24h": null,
"quote_rate": 0.0,
"quote_rate_24h": null,
"quote": 0.0,
"quote_24h": null,
"nft_data": null
}
],
"pagination": null
},
"error": false,
"error_message": null,
"error_code": null
}
I want to check if there is "PSK" in contract_ticker_symbol, if it exist and "balance" is > 0 ... then return true.
Is there any painless method because I'm not a programmer...
The Python requests library can handle this. You'll have to install it with pip first (package installer for Python).
I also used a website called JSON Parser Online to see what was going on with all of the data first so that I would be able to make sense of it in my code:
import requests
def main():
url = "https://api.covalenthq.com/v1/137/address/0x3FEb1D627c96cD918f2E554A803210DA09084462/balances_v2/?&format" \
"=JSON&nft=true&no-nft-fetch=true&key=ckey_docs "
try:
response = requests.get(url).json()
for item in response['data']['items']:
# First, find 'PSK' in the list
if item['contract_ticker_symbol'] == "PSK":
# Now, check the balance
if item['balance'] == 0:
return True
else:
return False
except requests.ConnectionError:
print("Exception")
if __name__ == "__main__":
print(main())
This is what is going on:
I am pulling all of the data from the API.
I am using a try/except clause because I need the code to
handle if I can't make a connection to the site.
I am looping through all of the 'items' to find the correct 'item'
that includes the contract ticker symbol for 'PSK'.
I am checking the balance in that item and returning the logic that you wanted.
The script is running itself at the end, but you can always just rename this function and have some other code call it to check it.
For some reason the following security rule is resolving to false when I try to write an object without the property that should be verified in .hasChild(newData.child('ownerId').val()). The property isn't mandatory, so I'm up to accept a write without it.
"pizza": {
"$pizzaId": {
".write": "root.child('users').hasChild(newData.child('ownerId').val()) || true"
}
}
Thus, I'm getting a PERMISSION_DENIED when running something like the code bellow:
firebase.database().ref(`pizza/peperoneID`).set({
extraPepe: true
});
I know that I can fix it by just going with (newData.child('ownerId').exists() && .hasChild(...)) || true but I'm really trying to understand why the first option isn't enough.
If there is no ownerId, you'll be passing null when you call hasChild.
That'll effect an error and that error will see your rule fail - so the trailing || true is ineffectual.
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.
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/