ESlint rule conflicting with Prettier - eslint

So, I have t his ESlint rule:
'space-before-function-paren': 'error'
But when I run git commit, husky and lint-staged do its thing and also run prettier, which it fails:
[warn] layouts/default.vue
[warn] layouts/error.vue
[warn] Code style issues found in 2 files. Forgot to run Prettier?
Basically prettier doesn't like that rule that I have given, and when I fix prettier, it puts the parentheses back to the way I don't want to.
I also didn't find any prettier rule to disable it there.

Related

Does eslint automatically exclude node_modules/?

I don't have an .eslintignore file and .eslintrc has no ignore patterns. When I run the following: ./node_modules/.bin/eslint **/*.js, it appears that files in the node_modules folder are ignored.
The ESLint documentation makes no mention of any default excluded folders or files. What is the real situation?
node_modules is ignored by default
It is in the doc: https://eslint.org/docs/latest/user-guide/configuring/
relevant part:
In addition to any patterns in the .eslintignore file, ESLint always
follows a couple of implicit ignore rules even if the --no-ignore flag
is passed. The implicit rules are as follows:
node_modules/ is ignored.
dot-files (except for .eslintrc.*), as well as dot-folders and their contents, are ignored.

Avoid nodejs project build to fail due to eslint error

Context
We have a nodejs project which gets built and deployed through Jenkins pipeline. During the build step, it performs eslint for all the .js files under a directory and generate eslint report. In case of any eslint error, the Jenkins pipeline fails.
Problem statement
We have introduced a sub-directory which contains further .js files. We want to generate eslint report for this, but don't want to fail the pipeline in case of any eslint error.
Can anyone please suggest how can we solve this?
Thanks in advnace.
It depends how eslint is performed.
With gyandeeps/gruntify-eslint task, there is a silent option which allows to not fail the job on errors.
In a regular shell step, you can force the command to not fail with:
sh "<your eslint command> || true"

How to configure ESlint to fix indent only

I am linting old NodeJS code and I want to clear out all indent issues before I start fixing the rest.
How do I configure ESlint to only show and fix the indent issues only?
By using eslint in the command line with the proper options:
node node_modules/eslint/bin/eslint --fix --parser babel-eslint --ext js --no-eslintrc --rule 'indent: [1,4,{SwitchCase: 1}]' src/
Change these options according to your requirements
--fix to auto fix.
--parser babel-eslint the parser from my eslint.rc.
--ext js to lint only js files.
--no-eslintrc otherwise all rules from your eslintrc will be executed.
--rule 'indent: [1,4,{SwitchCase: 1}]' the rule you want to execute (you can copy paste it from your eslint.rc, it has to be single quoted (the double quotes from the original json were removed).
src/ the target folder.
eslint documentation
If you want to use your normal .eslintrc file to keep your configuration (parser, plugins, rule config, etc), you can use eslint-nibble with the --rule= indent flag. This will respect your normal configuration, but only show you errors from that rule, and give you the option to fix only those, if the rule is auto-fixable.
Disclaimer: I'm the creator of eslint-nibble.

Configuring .eslintrc

I ran the command ./node_modules/.bin/eslint --init after installing the eslint package. But the first line after setting up the configuration which is module.exports gives the following warning
file will be ignored by default.
I'm unable to implement my custom rules.Need assistance with configuring my path.
The message is saying that ESLint will not lint the contents of .eslintrc.js by default. It'll still read the configuration just fine. If you want ESLint to check the code style of .eslintrc.js, you can create a file named .eslintignore with the contents !.eslintrc.js.

eslint ignore project .eslintrc

I'm working on a project that has an .eslintrc file checked in to source control at the root of the project.
The problem is that it has custom dependencies and when I use a tool to run my linting (syntastic with Vim) it fails. The dependencies are custom and I wish to skip running them in my editor.
I want to use another .eslintrc file, rather than the one which is in the root of the project.
How can I ignore <projectroot>/.eslintrc and instead use /custom/path/.eslintrc?
A glance at the ESLint docs tells us that you want to pass the --no-eslintrc option to make it ignore the .eslintrc in the project root and --config /custom/path/.eslintrc to make it use that file instead.
The Syntastic README says you can configure the arguments given to eslint like so:
let g:syntastic_javascript_eslint_args = "--no-eslintrc --config /custom/path/.eslintrc"

Resources