EsLint: Hide undefined functions Warnings - eslint

How can i hide all un-used Functions warnings in Javascript (using EsLint)? If i use following command, it will only hide warnings of the defined functions.
/* global lg, storeKeys, mergeDeep, count, preg_match */
Is there a way to hide all functions warnings without hiding the un-defined Variables? Like:
/* eslint-disable no-undef-functions */

Related

ESLINT error messages

I am trying to use extern libraries on my SAPUI5 project and follow tutorials https://blogs.sap.com/2017/04/30/how-to-include-third-party-libraries-modules-in-sapui5/.
For example, I include lodash as you can see on the image:
On the image, you can see, that the sap web ide complains about third library.
How to avoid the complaint?
Just add /* eslint-disable */ at the top of your target file:
/* eslint-disable */
/**
* ...
*/
;(function(){function n(n)...

Allow debugger; statements in certain files, using ESLint

Say I want to use this rule:
https://eslint.org/docs/rules/no-debugger
however, I have about 15 files where I want to keep debugger; statements.
Is there something I can add at the top of the .ts/.js files, that can tell ESLint to ignore the no-debugger rule for this particular file?
You can also disable ESLint in the same line:
debugger; // eslint-disable-line no-debugger
You can do that like this:
/* eslint-disable no-debugger */
... code that violates rule ...
/* eslint-enable no-debugger */
Update your eslint configuration file (.eslintrc etc) with such rule:
"rules": {
"no-debugger":"off"
}
Probably your IDE can help. If you are using VS Code, you can mouse over debugger, click Quick Fix..., and select Disable no-debugger for the entire file, as shown as below:
Then the IDE will add the following comment at the top of the file to disable the rule for you:
/* eslint-disable no-debugger */
See more on the eslint no-debugger rule.
OR, add:
"no-debugger": false
to the bottom of tslint.json, to disable this warning for all files.
I think debugger need to removed, and briefly used in a development environment.
So you're better off ignoring it where you use.
For example:
disable no-debugger for this line
// eslint-disable-next-line no-debugger
debugger
or disable no-debugger for the entire file
/* eslint-disable no-debugger */

ESLint / VSCode, the whole object is underlined

Since the last VSCode or Eslint extension update, the whole object is underlined when an error or a warning is detected. An idea why ?
I’m guessing you’re exporting this function from Webpack configuration module. I can think of two options that come to play.
First, define named function:
module.exports = function withBaseConfiguration() {
return { /* configuration goes here */ }
}
Second, disable the ESLint rule for this file by placing following at the top:
/* eslint-disable func-names */

When use istanbul, is there any way to dynamic require config.js?

The logEnable is write in config.js, is there any way to change the value during testing? So than I can improve the branch coverage.
You could ignore parts of code from testing: https://github.com/gotwarlost/istanbul/blob/master/ignoring-code-for-coverage.md
Skip an if or else path with /* istanbul ignore if */ or /* istanbul ignore else */ respectively.
For all other cases, skip the next 'thing' in the source with: /* istanbul ignore next */
Or add a single test that checks just those logging functions with both logging enabled and disabled (you can override required modules, like your config, for example with proxyquire: https://github.com/thlorenz/proxyquire).

How to disable warnings 4510 and 4610 from std::list class?

I have a bunch of warnings C4510 and C4610 when I use std::list with my class. It is a warning stating that default constructor is not available, and I want to disable them.
When I put:
#pragma warning(disable: 4510)
inside .cpp file that is instantiating this list nothing happens.
I tried placing this pragmas around function where I instantiate lists and even on top of the .cpp file but the results are the same - nothing happens. It only works if I disable warnings in properties dialog of .cpp file. I hate hiding stuff in properties like that because they get overlooked by developers. I would like to have them localized around the function. Is there something I could do about this?
EDIT:
Ok. This is how my code basically looks like. This code generates warnings 4510 and 4610 on warning level 4:
#include <list>
class foo {
public:
foo(int) { }
};
class bar {};
class problem_class {
foo m_foo;
const bar *m_bar;
public:
problem_class(const foo &_foo, const bar *_bar) : m_foo(_foo), m_bar(_bar) { }
};
void problem_fn(std::list<problem_class> &problem_collection) {
foo _foo(3);
problem_collection.clear();
problem_collection.push_back(problem_class(_foo, new bar));
}
int main(int , char **)
{
std::list<problem_class> collection;
problem_fn(collection);
return 0;
}
Instead of hiding the problem by disabling warnings, how about wrapping your class w/o a default constructor in a proxy class that does have a default constructor*. The proxy's default constructor can then do the proper initialization of the wrapped class. Then store the proxy class in the std::list. This would make your intent clear and eliminate the warning.
*assuming you can't for whatever reason actually make the wrapped class have an appropriatte default constructor.
Include #pragma before including <list>
#pragma warning (disable:4510)
#pragma warning (disable:4610)
#include <list>
You need to post some code that illustrates exactly what you are doing. Warning C4510 says:
The compiler cannot generate a default
constructor for the specified class
and no user-defined constructor was
created. You will not be able to
create objects of this type.
This doesn't seem to have anything to do with std::list, so it maybe that there is something wrong with your code.
I know this is not very helpful, but the code you posted looks fine to me and compiled with no warnings with g++ and comeau. I don't use VC++ anymore, so can't reall help further, I'm afraid.
Further Edit: Purely in the spirit of experimentation, what happens if you change:
const bar *m_bar;
to
bar *m_bar;
The MSDN docs for this warning say that:
There are several situations that
prevent the compiler from generating a
default constructor, including:
* A const data member.
Now the m_bar member isn't const (the thing it points to is) but I wonder if the compiler is a little confused about this.
#pragma warning (disable : 4510 4610)
#pragma warning (push, 3)
#include <list>
#pragma warning (pop)
#pragma warning (default : 4510 4610)
Ok, found it.
My project uses precompiled headers so in some header file that is included from StdAfx.h someone included list. When I added #pragma directives on top of the StdAfx.h everything worked. The thing that confused me is that when I added #pragma in .cpp file in front of
#include "StdAfx.h"
nothing worked (warnings were still displayed). Since list was included in precompiled headers, it had the same warning settings no matter what the .cpp file specified later on.
But, the strange thing is that even if I could not override settings in .cpp file, I could override them by specifying compile properties for that same file. How is that any different?

Resources