eslint just show important errors in node express project - unit-testing

I have an Express 4 project for my backend. Normally in webstorm I use all the errors about spaces, colon, quotes, but they are not really erros. Until I've delete "transMsg()" function from ../utils/communutils.js
I was surprise that my "node run" was executed normally with that silent error. Webstorm give a underline color like another common no important errors, when when I move the mouse over ".transMsg;" I get a popup with the message 'Unresolved variable transMsg'
const t = require('./utils/commonutils').transMsg;
so I've decide to execute
npm run test
my package.json:
"test": "eslint . --ext .js --ext .jsx --ignore-path .gitignore --cache",
my .eslintrc.json:
{
"extends": ["airbnb"],
"env": {
"browser": false,
"node": true
},
"rules": {
"no-unused-vars": 0
}
}
then i get 214927 errors !
how to do to ignore those trivial errors and get important erros like 'Unresolved variable transMsg'. I know i can set up every error to get silent or just warning, but the list is very long, is there a way to do it?
In react front app, those trivial errors are hidden, but important errors abort the execution of program. In this case npm run , run silent...
Part of errors;
8:3 error Assignment to property of function parameter 'info' no-param-reassign
10:2 error Missing semicolon semi
15:62 error Missing trailing comma comma-dangle
22:34 error Unnecessarily quoted property 'context' found quote-props
22:34 error Strings must use singlequote quotes
22:45 error Strings must use singlequote quotes
22:57 error Unnecessarily quoted property 'metric' found quote-props
22:57 error Strings must use singlequote quotes
37:3 error Newline required at end of file but not found eol-last
✖ 246991 problems (243461 errors, 3530 warnings)
214927 errors, 0 warnings potentially fixable with the `--fix` option.

Related

(*testing.common).Errorf does not support error-wrapping directive %w

I was cloning a private go project.
And got below error on the code editor and when running golangci-lint.
code editor screenshot error
golangci-lint screenshot error
The sample code is this:
func TestAService(t *testing.T) {
...
err := service.AService()
if err != nil {
t.Errorf("Error on executing the test cases %w", err)
}
}
The go project runs fine on other laptop, but the one I use it has this error.
The go version used by both laptop are: go 1.17
The screenshots you post aren't errors, they're warnings from your IDE about potential problems in your code.
But testing.T.Errorf does not support %w (it's the same as fmt.Sprintf in what it does and doesn't accept), so the warnings are correct.
The messages do not stop your code from building and running, but in the case of an error, the formatting of the string will be off.
If you run the code, and there's an error, you'll get something like this (the part after %!w will depend on the exact error value you have).
Error on executing the test cases %!w(*errors.errorString=&{some error})
The specific warning you're getting might be new1, but I don't believe this error code would ever have worked satisfactorily in any version of go. Of course, since most test errors are most often not seen (because tests pass), it may be that this defect has remained invisible.
The fix is to replace %w (wrap error) with %v (format object in the default way, which for an error will be to use its string form).
1 The lint message you're seeing is from "go tool vet", created by this changelist which was committed in May 2021. It's possible on your other machine, you are linting using an earlier version of this tool.

How to make VSCode indent an if statement without brackets?

I'd like for VSCode to indent automatically indent when I create a newline in the following case:
if(statement)
func();
The default functionality does the following when hitting newline:
if(statement)
func();
This is a longstanding issue in VSCode: https://github.com/microsoft/vscode/issues/43244
I'd appreciate any kind of hack/extension that can accomplish this behavior. There are other instances of indentation getting mangled in the github issue link, but I only really care about this simple case.
Figured out how to do this without installing an extension. There may be a better way that can be done in settings.json but I couldn't find it. You can modify a languages configuration directly from the source, which for me was C:\Program Files\Microsoft VS Code\resources\app\extensions\cpp\language-configuration.json. There is a guide for these files settings. I added the following to my c++ language configuration:
"onEnterRules": [
{
"beforeText": "^\\s*(?:if|while)\\(.*\\)\\s*$",
"action": {
"indent": "indent"
}
},
{
"beforeText": "(?=)",
"previousLineText": "^\\s*(?:if|while)\\(.*\\)\\s*$",
"action": {
"indent": "outdent"
}
}
]
This works, but unfortunately the official c++ vscode extension C/C++ for Visual Studio Code breaks it for some reason.
Below was my initial method of doing this, which breaks too many things to be useful.
"indentationRules": {
"increaseIndentPattern": "^\\s*if\\(.*\\)\\s*$",
"decreaseIndentPattern": "(?!)"
}
The field decreaseIndentPattern must be set (here the regex will never capture anything), otherwise it ignores the indentationRules field (I guess they never tested whether just one would be set?) Note that these edits need to be done with administrative privleges, and I found VSCode pretty convenient for making them. Also these changes do not take effect until VSCode is closed.
So as it turns out I've run into the same issues mentioned in this PR: https://github.com/microsoft/vscode/pull/115454. This fix breaks too much other vscode indentation behavior, such as deindenting after the first properly indented line in if statements.

The Prettier Extension is not correcting inconsistent formatting of code

I have downloaded some exercise files to learn how to use Javascript. I am using Visual Studio Code as the editor and can open the exercise javascript files in the editor. I have installed the extensions Prettier - Code Formatter and ESlint and Live Server and npm-install and advised in the course video. The ESlint extension seems to work ok i.e. when I remove some of the code, errors in the code are underscored and when I move the mouse over the error a pop-up indicates what is missing. However, in the code below I removed the opening and closing brackets around the word 'update' and indented the line which begins with the word 'main.' and remove the semi colon which should follow the first bracket. However, the Prettier extension does not correct these amends, as the video advised it should and I received the error ["ERROR" - 14:55:15] Prettier could not be loaded. See previous logs for more information.
const updateBackpack = (update) => {
let main = document.querySelector("main"); // main is an element
main.innerHTML = markup(backpack);
console.info(update);
};
Do you know why Prettier is not working and how I can get it to work. Please bear in mind I am new to coding and Javascript.
Thanks,
Clive
I think you have the exact same problem as me, while following the exact same course as me :D!
First install prettier, using :
npm i prettier -g
Then configure the VS code to pick that downloaded package.
Here is what I did : Search for 'Prettier Path' in settings > select 'Edit in settings.json' and add the following config :
{
"editor.minimap.enabled": false,
"editor.fontSize": 12,
"editor.formatOnSave": true,
"editor.tabSize": 2,
"liveServer.settings.donotShowInfoMsg": true,
"editor.wordWrap": "on",
"emmet.triggerExpansionOnTab": true,
"emmet.showSuggestionsAsSnippets": true,
"editor.snippetSuggestions": "top",
"[javascript]": {
// "editor.defaultFormatter": "esbenp.prettier-vscode",
"editor.formatOnSave": true,
"editor.formatOnPaste": true
},
"workbench.colorTheme": "Monokai",
"window.zoomLevel": 0,
"editor.columnSelection": false,
"explorer.compactFolders": false,
"typescript.updateImportsOnFileMove.enabled": "always",
"javascript.updateImportsOnFileMove.enabled": "always",
"liveServer.settings.donotVerifyTags": true,
"prettier.prettierPath": "/usr/local/lib/node_modules/prettier"
}
Make sure prettier is installed at the given path : "prettier.prettierPath": "/usr/local/lib/node_modules/prettier"
You can make prettier the default also by uncommenting the code : "editor.defaultFormatter": "esbenp.prettier-vscode"
It has my custom settings of visuals, so review those and then set, for beginners try pasting as-is!

pylint doesn't work correctly when pylint_django loaded

When pylint-django is installed error messages like Class 'MyModel' has no 'objects' member disappear. But with them being disappeared some real errors are skipped too. For example, the line MyModel.objectss.all() will not throw an error (note two s in the word objects).
Actually, I find it quite interesting, how pylint is marking errors:
MyModel.objects.all() (everything is correct) - gives no error.
MyModel.objectss.all() (two s in objects) - gives no error.
MyModel.objectss.alll() (two s in objects and three l in all) - gives Class 'MyModel' has no 'objectss' member.
MyModel.objects.alll() (three l in all) - gives no error.
It's like at least two errors must occur in order for pylint to throw an error.
I am working withVisual Studio Code 1.39.1, pylint==2.4.2, pylint-django==2.0.11
My Visual Studio's settings.json file looks like this:
{
"python.linting.pylintArgs": [
"--load-plugins=pylint_django"
]
}
So, is this a bug or is there something wrong with my config?

Ember.Logger.log is deprecated and console.info gives 'no-console' build warnings, what to do?

I'm relatively new to Ember development, but keen to do things the right way.
For logging, I used to use Ember.Logger.log('blah'); but that now throws warnings in the console that it's deprecated. There's a link in the warning to https://emberjs.com/deprecations/v3.x#toc_use-console-rather-than-ember-logger, which recommends using console instead.
So I switch to console.info('blah');, but now when I do ember serve there's a bunch of "problems" like:
/Users/mick/Projects/Pop Up Eats/Vendor Website/app/routes/application.js
22:3 error Unexpected console statement no-console
27:3 error Unexpected console statement no-console
✖ 2 problems (2 errors, 0 warnings)
What am I supposed to do? Am I missing something?
This is just an Eslint error.
You can change it to be a warning/not an error anymore by going to your .eslintrc.js file and by adding this to your rules:
rules: {
"no-console": 0 //which turns the rule off
}
OR
rules: {
"no-console": 1 //which will just warn you about the console logs
}
I hope it helps.