JSHint and issue with underscore '_' - node.js

Getting the following error when running jshint;
line 4 col 5 Redefinition of '_'.
the code is complaining out is;
var _ = require('lodash');
jshint in project
{
"node": true,
"esnext": true,
"bitwise": true,
"eqeqeq": true,
"immed": true,
"latedef": "nofunc",
"newcap": true,
"noarg": true,
"regexp": true,
"undef": true,
"smarttabs": true,
"asi": true,
"debug": true,
"globals": {
"angular": false,
"_": false
}
}

Updated the .jshintrc to the following which seems to have resolved the problem.
{
"node": true,
"browser": true,
"esnext": true,
"bitwise": false,
"camelcase": false,
"eqeqeq": true,
"immed": true,
"indent": 4,
"latedef": true,
"newcap": true,
"noarg": true,
"quotmark": "single",
"regexp": true,
"undef": true,
"unused": false,
"strict": true,
"trailing": true,
"smarttabs": true,
"globals": {
"jQuery": true,
"angular": true,
"console": true,
"AppConfig": true,
"$": true,
"_": true,
"moment": true,
"module": true,
"inject": true,
"browser": true,
"element": true,
"describe": true,
"before": true,
"beforeEach": true,
"after": true,
"afterEach": true,
"expect": true,
"it": true,
"by": true,
"chai": true
}
}
Also created a .jshintrc-spec
{
"extends": ".jshintrc",
"globals": {
"describe": true,
"it": true,
"before": true,
"beforeEach": true,
"after": true,
"afterEach": true,
"chai": true,
"inject" : true
}
}

A better (and commonly used) way to resolve this is to use double underscores __ while requiring either underscore or the lodash library. No need to make a change to the jshintrc file just for this.

Related

Why do I have an ESLint Error - overrideConfigFile?

My settings.json:
"eslint.options": {
"overrideConfigFile": {
"env": {
"browser": true,
"jest/globals": true,
"es6": true
},
"parserOptions": {
"ecmaVersion": 2019,
"sourceType": "module",
"ecmaFeatures": {
"jsx": true
}
},
"rules": {
"no-debugger": "off"
}
}
},
My previous ESLint errors were that 'env', 'parserOptions' and 'rules' had to be wrapped in an overrideConfigFile which fixed those errors, now I'm getting error "ESLint: Invalid Options: - 'overrideConfigFile' must be a non-empty string or null..". Has anybody come across this or understand why this isn't working? Google isn't being my friend & changing overrideConfigFile to be null or empty string would just bring about the previous errors.

How to pass dictionary or JSON to Invoke-AzVMRunCommand - Parameter?

I have a Input file which I read in a env variable InputConf.
[ { "name": "administrators", "description": "Default group for DSS administrators", "sourceType": "LOCAL", "admin": true, "mayManageUDM": false, "mayCreateProjects": false, "mayCreateProjectsFromMacros": false, "mayCreateProjectsFromTemplates": false, "mayCreateProjectsFromDataikuApps": false, "mayWriteUnsafeCode": false, "mayWriteSafeCode": false, "mayCreateAuthenticatedConnections": false, "mayCreateCodeEnvs": false, "mayCreateClusters": false, "mayDevelopPlugins": false, "mayEditLibFolders": false, "mayManageCodeEnvs": false, "mayManageClusters": false, "mayViewIndexedHiveConnections": false, "mayCreatePublishedAPIServices": false, "mayWriteInRootProjectFolder": false, "mayCreateActiveWebContent": false, "canObtainAPITicketFromCookiesForGroupsRegex": "" }, { "name": "dss-se-npr", "description": "ElevatedSupport", "ldapGroupNames": "dss-se-npr", "sourceType": "LDAP", "admin": true, "mayManageUDM": true, "mayCreateProjects": true, "mayCreateProjectsFromMacros": true, "mayCreateProjectsFromTemplates": true, "mayCreateProjectsFromDataikuApps": true, "mayWriteUnsafeCode": true, "mayWriteSafeCode": true, "mayCreateAuthenticatedConnections": true, "mayCreateCodeEnvs": true, "mayCreateClusters": false, "mayDevelopPlugins": true, "mayEditLibFolders": true, "mayManageCodeEnvs": true, "mayManageClusters": false, "mayViewIndexedHiveConnections": false, "mayCreatePublishedAPIServices": true, "mayWriteInRootProjectFolder": true, "mayCreateActiveWebContent": true, "canObtainAPITicketFromCookiesForGroupsRegex": "" }, { "name": "dss-au-npr", "description": "Auditor", "ldapGroupNames": "dss-au-npr", "sourceType": "LDAP", "admin": false, "mayManageUDM": false, "mayCreateProjects": false, "mayCreateProjectsFromMacros": false, "mayCreateProjectsFromTemplates": false, "mayCreateProjectsFromDataikuApps": false, "mayWriteUnsafeCode": false, "mayWriteSafeCode": false, "mayCreateAuthenticatedConnections": false, "mayCreateCodeEnvs": false, "mayCreateClusters": false, "mayDevelopPlugins": false, "mayEditLibFolders": false, "mayManageCodeEnvs": false, "mayManageClusters": false, "mayViewIndexedHiveConnections": false, "mayCreatePublishedAPIServices": false, "mayWriteInRootProjectFolder": false, "mayCreateActiveWebContent": false, "canObtainAPITicketFromCookiesForGroupsRegex": "" }, { "name": "dss-ba-npr", "description": "BusinessAnalyst", "ldapGroupNames": "dss-ba-npr", "sourceType": "LDAP", "admin": false, "mayManageUDM": false, "mayCreateProjects": false, "mayCreateProjectsFromMacros": false, "mayCreateProjectsFromTemplates": false, "mayCreateProjectsFromDataikuApps": false, "mayWriteUnsafeCode": false, "mayWriteSafeCode": false, "mayCreateAuthenticatedConnections": false, "mayCreateCodeEnvs": false, "mayCreateClusters": false, "mayDevelopPlugins": false, "mayEditLibFolders": false, "mayManageCodeEnvs": false, "mayManageClusters": false, "mayViewIndexedHiveConnections": false, "mayCreatePublishedAPIServices": false, "mayWriteInRootProjectFolder": false, "mayCreateActiveWebContent": false, "canObtainAPITicketFromCookiesForGroupsRegex": "" }, { "name": "dss-ds-npr", "description": "DataScientist", "sourceType": "LDAP", "ldapGroupNames": "dss-ds-npr", "admin": false, "mayManageUDM": false, "mayCreateProjects": false, "mayCreateProjectsFromMacros": false, "mayCreateProjectsFromTemplates": false, "mayCreateProjectsFromDataikuApps": false, "mayWriteUnsafeCode": false, "mayWriteSafeCode": true, "mayCreateAuthenticatedConnections": false, "mayCreateCodeEnvs": false, "mayCreateClusters": false, "mayDevelopPlugins": false, "mayEditLibFolders": false, "mayManageCodeEnvs": false, "mayManageClusters": false, "mayViewIndexedHiveConnections": false, "mayCreatePublishedAPIServices": false, "mayWriteInRootProjectFolder": false, "mayCreateActiveWebContent": false, "canObtainAPITicketFromCookiesForGroupsRegex": "" }, { "name": "dss-dsfe-npr", "description": "DataScientistFeatureEnhancement", "ldapGroupNames": "dss-dsfe-npr", "sourceType": "LDAP", "admin": false, "mayManageUDM": false, "mayCreateProjects": false, "mayCreateProjectsFromMacros": false, "mayCreateProjectsFromTemplates": false, "mayCreateProjectsFromDataikuApps": false, "mayWriteUnsafeCode": false, "mayWriteSafeCode": true, "mayCreateAuthenticatedConnections": false, "mayCreateCodeEnvs": false, "mayCreateClusters": false, "mayDevelopPlugins": true, "mayEditLibFolders": false, "mayManageCodeEnvs": false, "mayManageClusters": false, "mayViewIndexedHiveConnections": false, "mayCreatePublishedAPIServices": false, "mayWriteInRootProjectFolder": false, "mayCreateActiveWebContent": false, "canObtainAPITicketFromCookiesForGroupsRegex": "" }, { "name": "dss-ls-npr", "description": "LeadScientist", "ldapGroupNames": "dss-ls-npr", "sourceType": "LDAP", "admin": false, "mayManageUDM": true, "mayCreateProjects": false, "mayCreateProjectsFromMacros": false, "mayCreateProjectsFromTemplates": false, "mayCreateProjectsFromDataikuApps": false, "mayWriteUnsafeCode": false, "mayWriteSafeCode": true, "mayCreateAuthenticatedConnections": false, "mayCreateCodeEnvs": false, "mayCreateClusters": false, "mayDevelopPlugins": false, "mayEditLibFolders": false, "mayManageCodeEnvs": false, "mayManageClusters": false, "mayViewIndexedHiveConnections": false, "mayCreatePublishedAPIServices": false, "mayWriteInRootProjectFolder": false, "mayCreateActiveWebContent": false, "canObtainAPITicketFromCookiesForGroupsRegex": "" }, { "name": "dss-sp-npr", "description": "Support", "ldapGroupNames": "dss-sp-npr", "sourceType": "LDAP", "admin": false, "mayManageUDM": true, "mayCreateProjects": true, "mayCreateProjectsFromMacros": true, "mayCreateProjectsFromTemplates": true, "mayCreateProjectsFromDataikuApps": true, "mayWriteUnsafeCode": false, "mayWriteSafeCode": true, "mayCreateAuthenticatedConnections": false, "mayCreateCodeEnvs": true, "mayCreateClusters": false, "mayDevelopPlugins": true, "mayEditLibFolders": true, "mayManageCodeEnvs": true, "mayManageClusters": false, "mayViewIndexedHiveConnections": false, "mayCreatePublishedAPIServices": false, "mayWriteInRootProjectFolder": false, "mayCreateActiveWebContent": false, "canObtainAPITicketFromCookiesForGroupsRegex": "" }, { "name": "dss-rm-npr", "description": "ReleaseManager", "ldapGroupNames": "dss-rm-npr", "sourceType": "LDAP", "admin": false, "mayManageUDM": false, "mayCreateProjects": false, "mayCreateProjectsFromMacros": false, "mayCreateProjectsFromTemplates": false, "mayCreateProjectsFromDataikuApps": false, "mayWriteUnsafeCode": false, "mayWriteSafeCode": false, "mayCreateAuthenticatedConnections": false, "mayCreateCodeEnvs": false, "mayCreateClusters": false, "mayDevelopPlugins": false, "mayEditLibFolders": false, "mayManageCodeEnvs": false, "mayManageClusters": false, "mayViewIndexedHiveConnections": false, "mayCreatePublishedAPIServices": false, "mayWriteInRootProjectFolder": false, "mayCreateActiveWebContent": false, "canObtainAPITicketFromCookiesForGroupsRegex": "" }, { "name": "dss-te-npr", "description": "Tester", "ldapGroupNames": "dss-te-npr", "sourceType": "LDAP", "admin": false, "mayManageUDM": false, "mayCreateProjects": false, "mayCreateProjectsFromMacros": false, "mayCreateProjectsFromTemplates": false, "mayCreateProjectsFromDataikuApps": false, "mayWriteUnsafeCode": false, "mayWriteSafeCode": false, "mayCreateAuthenticatedConnections": false, "mayCreateCodeEnvs": false, "mayCreateClusters": false, "mayDevelopPlugins": false, "mayEditLibFolders": false, "mayManageCodeEnvs": false, "mayManageClusters": false, "mayViewIndexedHiveConnections": false, "mayCreatePublishedAPIServices": false, "mayWriteInRootProjectFolder": false, "mayCreateActiveWebContent": false, "canObtainAPITicketFromCookiesForGroupsRegex": "" } ]
I need the variable to be copied to the Linux VM - /dss/data/groups.txt
I call the script using Invoke-AzVMRunCommand using RunShellScript
Invoke-AzVMRunCommand -ResourceGroupName $ResourceGroupName -VMName $VirtualMachineName -CommandId RunShellScript -ScriptPath "$($PSScriptRoot)/scripts/$PatchScript" -Parameter #{InputConfParam=$InputConf}
In the script, I do the below
echo $InputConf > /dss/data/groups.txt
However I do not get the entire string, but only get the first character of the InputString.
This is because of the spaces/tabs in the variable.
Is there a way I can get the entire JSON passed to the shell script? so I can copy the variable to the file on the server?
Thanks
Just did a very crude workaround or replacing the newline chars and spaces and sending the parameter to the shell script and replacing it back in the script.
Blob Storage was a good option - will surely try the approach.

Eslint & Prettier conflicts (eslint-config-prettier not wokring)

I have this simple example, where statements dont have semicolons. Prettier settings have the semi to false but eslint has the semi to true. I order to not have conflicts between them i installed the eslint-config-prettier. But i still get an error with the semicolons. It is supposed to prevail the prettier setting, but its does not.
var var1, var2
var1 = 3
var2 = 4
var a = { name: "" }
"devDependencies": {
"eslint": "^7.8.1",
"eslint-config-prettier": "^6.11.0",
"eslint-plugin-prettier": "^3.1.4",
"prettier": "^2.1.1"
}
.prettierrcc
{
"arrowParens": "always",
"bracketSpacing": true,
"htmlWhitespaceSensitivity": "css",
"insertPragma": false,
"jsxBracketSameLine": false,
"jsxSingleQuote": false,
"printWidth": 86,
"proseWrap": "preserve",
"quoteProps": "preserve",
"requirePragma": false,
"semi": false,
"singleQuote": false,
"tabWidth": 2,
"trailingComma": "es5",
"useTabs": false,
"vueIndentScriptAndStyle": false
}
.eslintrcc
{
"root": true,
"env": {
"node": true
},
"extends": ["prettier"],
"plugins": ["prettier"],
"rules": {
"semi": ["error", "always"],
"prettier/prettier": ["error"]
}
}
I get the following error:
/home/nick/Documents/Coding/NodeJs/simple-node/vanilla.js
1:17 error Missing semicolon semi
2:11 error Missing semicolon semi
3:9 error Missing semicolon semi
4:21 error Missing semicolon semi
You are overwriting the Prettier config which is indeed set to "off" by default (link to config), with a custom rule who does the opposite of what you want. Simply remove it:
"rules": {
"prettier/prettier": ["error"]
}

VScode `tsx` files formatted to single quotes but `ts` files formatted to double quotes, why that happens?

I have the following configuration on my VSCode:
{
"[javascript]": {
"editor.defaultFormatter": "esbenp.prettier-vscode",
"editor.formatOnSave": false,
},
"[html]": {
"editor.defaultFormatter": "esbenp.prettier-vscode",
"editor.formatOnSave": false,
},
"[javascriptreact]": {
"editor.defaultFormatter": "esbenp.prettier-vscode",
"editor.formatOnSave": false,
},
"[typescriptreact]": {
"editor.defaultFormatter": "esbenp.prettier-vscode",
"editor.formatOnSave": false,
},
"editor.formatOnSave": true,
"eslint.autoFixOnSave": true,
"eslint.validate": [
"javascript",
"javascriptreact",
{
"language": "typescript",
"autoFix": true
},
{
"language": "typescriptreact",
"autoFix": true
}
],
}
It auto corrects double quotes to single quotes in .tsx files, but that inverse happens to .ts files, it transforms singles quotes to double quotes.
I'm using ESLint plugin.

What's the equivalent bs-config.js (Browsersync) of this command?

Browsersync is working fine with a PHP/Symfony 3 project with the following command:
browser-sync start --proxy http://localhost:8000 --files "web/css/**/*.css"
The browser will open at http://localhost:3000 and if I change something in web/css I can see the updated stylesheets without a full page reload. So far so good.
However it doesn't work with the following bs-config.js:
module.exports = {
"files": [
"web/css/**/*.css"
],
"server": false,
"proxy": "http://localhost:8000"
};
And the command:
browser-sync start
Browser will not load, changes aren't detected and reloading doesn't work. What I'm missing?
try this:
1º Create "bs-config.js" with: browser-sync init
2º Open file and edit like this:
module.exports = {
"ui": {
"port": 3001,
"weinre": {
"port": 8080
}
},
"files": "web/css/**/*.css",
"watchOptions": {},
"server": false,
"proxy": "http://localhost:8000",
"port": 3000,
"middleware": false,
"serveStatic": [],
"ghostMode": {
"clicks": true,
"scroll": true,
"forms": {
"submit": true,
"inputs": true,
"toggles": true
}
},
"logLevel": "info",
"logPrefix": "BS",
"logConnections": false,
"logFileChanges": true,
"logSnippet": true,
"rewriteRules": [],
"open": "local",
"browser": "default",
"cors": false,
"xip": false,
"hostnameSuffix": false,
"reloadOnRestart": false,
"notify": true,
"scrollProportionally": true,
"scrollThrottle": 0,
"scrollRestoreTechnique": "window.name",
"scrollElements": [],
"scrollElementMapping": [],
"reloadDelay": 0,
"reloadDebounce": 0,
"reloadThrottle": 0,
"plugins": [],
"injectChanges": true,
"startPath": null,
"minify": true,
"host": null,
"localOnly": false,
"codeSync": true,
"timestamps": true,
"clientEvents": [
"scroll",
"scroll:element",
"input:text",
"input:toggles",
"form:submit",
"form:reset",
"click"
],
"socket": {
"socketIoOptions": {
"log": false
},
"socketIoClientConfig": {
"reconnectionAttempts": 50
},
"path": "/browser-sync/socket.io",
"clientPath": "/browser-sync",
"namespace": "/browser-sync",
"clients": {
"heartbeatTimeout": 5000
}
},
"tagNames": {
"less": "link",
"scss": "link",
"css": "link",
"jpg": "img",
"jpeg": "img",
"png": "img",
"svg": "img",
"gif": "img",
"js": "script"
}};
3º Run the server: php -S localhost:8000
4º Start BrowserSync: browser-sync start --config bs-config.js

Resources