eslint does not automatically fix on --fix - eslint

I use eslint to lint, but it does not automatically fix although I use --fix
PS C:\Users\issac\IdeaProjects\discord-bot> eslint --fix --ext .ts src
Warning: React version was set to "detect" in eslint-plugin-react settings, but the "react" package is not installed. Assuming latest React version for linting.
C:\Users\issac\IdeaProjects\discord-bot\src\bot.ts
16:1 error Expected indentation of 4 spaces but found 2 indent
17:1 error Expected indentation of 8 spaces but found 4 indent
18:1 error Expected indentation of 12 spaces but found 6 indent
19:1 error Expected indentation of 16 spaces but found 8 indent
... all most errors indent
75:1 error Expected indentation of 12 spaces but found 6 indent
76:1 error Expected indentation of 12 spaces but found 6 indent
76:34 error Unexpected use of '<<' no-bitwise
77:1 error Expected indentation of 8 spaces but found 4 indent
✖ 862 problems (852 errors, 10 warnings)
790 errors and 0 warnings potentially fixable with the `--fix` option.
Although I run with --fix every time, those errors won't disappear.
This is my .eslintrc.js
module.exports = {
root: true,
env: {
es2021: true,
node: true,
},
parser: '#typescript-eslint/parser',
plugins: [
'#typescript-eslint',
],
extends: [
'airbnb',
'airbnb-typescript'
],
parserOptions: {
ecmaVersion: 13,
project: './tsconfig.json',
sourceType: 'module',
},
rules: {
'max-len': [1, 150, 4],
'object-curly-spacing': [2, 'always'],
'require-jsdoc': [0],
'indent': [2, 4],
'linebreak-style': [0],
'keyword-spacing': [2],
},
overrides: [
{
"files": ["*.ts"],
rules: {
"#typescript-eslint/explicit-function-return-type": ["error"]
}
}
]
};
Is there any way to make eslint fix those all indents?

Related

Using eslint causes my string to fail with no-irregular-whitespace error

I've started to use eslint (migrated from tslint) but this is throwing an error, not sure why!
Code snippet
const url = `${this.url}​/members​/${memberId}​/profile`;
It's super strange as other similar lines of code are not causing a problem! I'm not sure how to resolve this problem.
Full error message
Irregular whitespace not allowed.
eslint version = ^7.31.0
Thanks!!
Update
I have the following config but it produces an error when running lint
plugins: ["#typescript-eslint", "react"],
extends: [
"eslint:recommended",
"plugin:#typescript-eslint/recommended",
"plugin:react/recommended"
],
rules: {},
Error message
ESLint couldn't find the plugin "eslint-plugin-react".
Solution
Add this to the eslint config file:
rules: {
"no-irregular-whitespace": [
"error",
{ skipRegExps: true, skipTemplates: true },
],
},
Make sure your eslint config has:
"extends": [
"plugin:react/recommended"
]
...
"plugins": [
"react"
]

eslint mulitline-ternary rule not fixing errors

I am one of those who prefers to have ternary expressions span multiple lines for readability. However, my current set-up is not fixing it as expected.
eslint v7.17.0
Here is the relevant part of my .eslintrc.js:
rules: {
'multiline-ternary': 'error',
'operator-linebreak': ['error', 'after', { overrides: { '?': 'before', ':': 'before' } }],
},
...
Both rules are fixable according to the docs:
My npm lint script is eslint --fix --ext .js,.vue --ignore-path .gitignore .
However, I'm getting this in my console:
Why is it telling me that it is potentially fixable without fixing it?

stylelint config for SCSS & StyledComponent

Our repos have a mix of SCSS & newer StyledComponents and I believe having StyleLint try to manage both SCSS & *.css.js StyledComponents conflicts with rules/processors. I currently run this with lintstaged during a commit:
.lintstagedrc file:
{
"**/*.(js|jsx|ts|tsx)": [
"npm run lint:fix",
"npm run prettier:write",
],
"**/*.(css|less|scss)+?(.js)": [
"npm run stylelint",
]
}
Let's say an SCSS file gets updated:
#import '../../../styles/variables.scss';
.account-search-list {
color: $light-grey;
}
and here is my StyledComponent:
export const StyledData = styled.div`
margin-bottom: 0.75rem;
`;
For example, if I try to use this stylelint config, I get an error :
{
"processors": ["stylelint-processor-styled-components"],
"extends": [
"stylelint-config-sass-guidelines",
"stylelint-config-recommended",
"stylelint-config-styled-components"
],
"plugins": ["stylelint-scss"],
"syntax": "scss",
"rules": {
"scss/at-import-partial-extension": "always",
"scss/at-import-partial-extension-blacklist": [".scss"],
"max-nesting-depth": [3, { "ignore": "pseudo-classes", "ignoreAtRules": "media" }],
"selector-max-compound-selectors": [4]
}
}
This returns an error:
src/components/common/AccountSearchList/index.scss
1:1 ✖ Unexpected keyword 'import' (1:1)
Because this is an error with SCSS, let's remove the processors field for StyledComponents 🤷‍♂️. Well that's good, the import error is gone!! But now there are StyledComponent issues:
7:3 ✖ Expected indentation of 4 spaces indentation
My ESLinter/Prettier formatter requires 2 spaces, but that's OK there's a stylelint rule for that, so I will add: indentation: 2 to the rules above, but that doesn't work either as the processor is missing and likely cannot pickup the JS rules.
So, how can I combine rules, or run certain rules for certain file types?
Thanks!

eslint Parsing error: ecmaVersion must be 3, 5, 6, or 7

I'm using the eslint 3.18.0 and node 7.7.4. I'm setting the ecmaVersion to 8 (per the documentation), but getting this error: Parsing error: ecmaVersion must be 3, 5, 6, or 7. Is ecmaVersion 8 not supported? If it is why am I getting this parsing error?
Here's the full .eslintrc.json:
{
"env": {
"node": true,
"mocha": true
},
"parserOptions": {
"ecmaVersion": 8,
"sourceType": "module"
},
"extends": "eslint:recommended",
"rules": {
"semi": ["error", "always"],
"quotes": ["error", "single"]
}
}
ESLint currently supports versions 3, 5, 6 (es2015), 7(es2016) and 8(es2017). If you are having trouble enabling es2017, verify that your ESLint installation is up to date. es2017 was added to ESLint as of v3.6.0 that was released on Sep 23, 2016. Verify global/local version (whichever you are using).
The ecmaVersion is not valid; I recently installed eslint and ecamVersion was set to 13
"parserOptions": {
"ecmaVersion": 13
},
The valid versions are 3 to 12 or latest. I use 'latest' :)
I solved this by doing the following
Deleted the node-modules directory & package-lock.json
npm install
Changed the ecmaScript version in .eslint file
It worked for me.

Getting wrong line numbers and report not reacting to changes with `rollup-plugin-eslint`

I'm consistently getting wrong line numbers on the eslint output:
$ ./node_modules/.bin/rollup -c
/Users/asko/Git/es6-trial/src/main.js
31:7 error Expected indentation of 4 space characters but found 6 indent
60:7 error Expected indentation of 4 space characters but found 6 indent
61:7 error Expected indentation of 4 space characters but found 6 indent
134:7 error Expected indentation of 4 space characters but found 6 indent
142:9 error Expected indentation of 6 space characters but found 8 indent
✖ 5 problems (5 errors, 0 warnings)
The reported numbers are one larger than where the problems actually are.
But if I edit the file, the eslint output does not change! Is it doing caching of some type?
Unfortunately, the repo where this originates from is not public.
.eslintrs.json is:
{
"parserOptions": {
"ecmaVersion": 6,
"sourceType": "module",
"ecmaFeatures": {
"impliedStrict": true
}
},
"env": {
"browser": true,
"es6": true
},
"globals": {
"assert": false
},
"extends": "eslint:recommended",
"parserOptions": {
"sourceType": "module"
},
"rules": {
"indent": ["error", 2],
"linebreak-style": ["error", "unix"],
// "quotes": ["warn", "single"],
"semi": ["error", "always"],
"no-console": "off",
"no-unused-vars": "warn"
}
}
All of this is weird. Has anyone else, ever, seen this?
It has to do with running eslint via Rollup. If I run things directly with ./node_modules/.bin/eslint src/*.js, there is nothing to report.
Ensure that the eslint plugin is configured before the babel plugin otherwise linting will run on transpiled code, e.g.:
plugins: [
eslint({
exclude: 'node_modules/**'
}),
babel({
exclude: 'node_modules/**'
})
]
instead of
plugins: [
babel({
exclude: 'node_modules/**'
}),
eslint({
exclude: 'node_modules/**'
})
]
See https://github.com/TrySound/rollup-plugin-eslint/issues/10

Resources