Is it possible to fix all ESLint warning by CLI ?
I've try this, but don't fix all error (unused var for example) :
eslint --fix src
As the old adage goes, "RTFM".
See: https://eslint.org/docs/user-guide/command-line-interface#fixing-problems
--fix
This option instructs ESLint to try to fix as many issues as possible. The fixes are made to the actual files themselves and only the remaining unfixed issues are output. Not all problems are fixable using this option, and the option does not work in these situations:
This option throws an error when code is piped to ESLint.
This option has no effect on code that uses a processor, unless the
processor opts into allowing autofixes.
Related
When I run ESLint with the --fix flag, I'd like for the changes made to be output to the terminal. By default it displays no output except for errors or warnings that cannot be fixed, as the ESLint docs say:
The fixes are made to the actual files themselves and only the remaining unfixed issues are output.
Is there any way to force ESLint to print all the issues that were fixed to the terminal?
For the sake of clarity, here's the command I'm currently running: eslint src --fix --ext js,ts,tsx.
I've set up a new nodeJS project with typescript. My linter is flagging me with errors, for example:
import authentication from "./routes/authentication"; // Flags "Cannot find module ..."
I would like it to flag a warning/error for these statements, as they break my app when I try to load it:
const pool = require("../database/db"); // Currently not flagging as a warning either for the fact that the file does not exist, or that it is using a require() statement.
I'm guessing eslint is doing my linting. But I haven't explicitly set it up. I tried creating and playing with a .eslint.rc file, but nothing happened.
How do I check what my linter is? I can't find anything in my VS-Code settings to say what I'm using. I can't find any reference to it in my package.json or tsconfig.json files that reference a linter either?
How do I then get my linter to flag require() statements?
So it looks like eslint was already running. It was installed in my extensions, but I've no idea what rules it was using. It must have been some defaults?
I ran yarn add eslint -D and npx eslint --init to set up eslint. Then I changed the rules: object in my .eslintrc.js file. This seems to have changed the linting, which suggests I was already using eslint.
I haven't yet worked out how to flag errors for the require() statements. I've found this YouTube video, which explains that:
require() statements are just functions. We can write require() statements within if() conditions and functions. This is not possible with import ... from ... statements
Because require() statements are functions, they are only being called in runtime. imports are static, so they are being checked by typescript in parse time. This is useful as it means we can get errors before moving into runtime.
I never found a better way of checking what linter my VS-Code was running other than setting up eslint with the github.com/typescript-eslint/... instructions and then playing with the .eslintrc.js file to see that the rules changed. Even then I had to runyarn eslint . --ext .js,.jsx,.ts,.tsx before the rules:{} in my .eslintrc.js started to take effect.
In order to get the require() statements to flag up with my linter, I added the following to my .eslintrc.js rules:{} property:
rules: {
"#typescript-eslint/no-var-requires": 1,
...
}
Although this didn't take effect until after I'd followed the steps described in item 1. As stated above, for some reason I had to run yarn eslint . --ext .js,.jsx,.ts,.tsx before the rules:{} in my .eslintrc.js started to take effect.
Is there a way to change all eslint errors to warnings using eslintrc.js file?
I just hate it at the moment, especially when it stops the entire program because I added an extra space.
I was wondering is there a way to turn all errors off and let prettier handle the rearranging of the code?
P.S. I am using vscode as the IDE and
I know about the comment thingy at the beginning of the code. It does not work on a vue or nuxt project
If you're using the ESLint extension, you can customize the severity of ESLint rules using the setting eslint.rules.customizations.
For example, if you add the following snippet to your .vscode/settings.json, all ESLint errors will be shown as warnings in VSCode.
"eslint.rules.customizations": [
{ "rule": "*", "severity": "warn" }
]
I have a problem with my Angular project build, and ultimately deployment to heroku. I'm using an old(ish) npm package called binary parser, which causes the following error on when I build / deploy to heroku:
Module not found: Error: Can't resolve 'console' in '/tmp/build_e75b87f248f44978f9537d83b3172254/node_modules/binary-parser/dist'
The binary-parser.js has a line require("console"); which is used in exactly one place, so local builds succeed and the application works perfectly, if only I remove console from that line altogether. But as, heroku installs node modules when deploying, this only helps when I manually build the prod version.
I have installed typings for binary-parser and for TS, and also included "types": ["node"] in both tsconfig.json and tsconfig.app.json compilerOptions.
As angular these days doesn't really allow for webpack configuration, I've tried adding global.console = global.console || require('console-browserify');
(or)
global.console = global.console || require('console');
to my polyfills, to no avail.
Any ideas on how to solve this? Do I need to configure a custom webpack to circumvent this? I'll gladly post additional information if necessary!
Here's a possible cause, may or may not be what you or others reading this question are experiencing...
My IDE's auto importing added import * as console from "console"; when I typed console.log.
Solution was of course to remove that import statement.
After trying for multiple hours to come up with the right configuration, the only solution I could come up with was forking the repo in question and changing tsconfig target from es5 to es6, which got rid of the console import altogether upon compilation.
According to ESLint: Docs: Rules,
Some rules are fixable using the --fix command line flag.
What does that mean?
Running the command eslint --help, tells us that the --fix command line flag "automatically fix[es] problems."
ESLint: Docs: User Guide: Command Line Interface: --fix provides more explanation:
This option instructs ESLint to try to fix as many issues as possible.
The fixes are made to the actual files themselves and only the
remaining unfixed issues are output. Not all problems are fixable
using this flag, and the flag does not work in these situations:
This option throws an error when code is piped to ESLint.
This option has no effect on code that uses processors.