ESLint: Unexpected property "indent" in eslintrc - visual-studio-code

As documented here, there is an ESLint property for indentation called indent. The example looks like this:
Or for tabbed indentation:
{
"indent": ["error", "tab"]
}
However, if I paste this exact code into my .eslintrc file, VS Code shows this as an error:
ESLint: ESLint configuration in .eslintrc is invalid: - Unexpected top-level property "indent". . Please see the 'ESLint' output channel for details.
The .eslintrc file that I had before has a number of rules already, and there are no errors printed with those. If I add "indent" to that list, or by itself, it fails.
Here is the error and stack trace printed in the ESLint output channel in VS Code:
[Error - 10:38:55 PM] ESLint stack trace:
[Error - 10:38:55 PM] Error: ESLint configuration in .eslintrc is invalid:
- Unexpected top-level property "indent".
at validateConfigSchema (/home/aaronfranke/workspace/OddJobs/node_modules/eslint/lib/shared/config-validator.js:286:15)
at ConfigArrayFactory._normalizeConfigData (/home/aaronfranke/workspace/OddJobs/node_modules/eslint/lib/cli-engine/config-array-factory.js:469:9)
at ConfigArrayFactory._loadConfigDataInDirectory (/home/aaronfranke/workspace/OddJobs/node_modules/eslint/lib/cli-engine/config-array-factory.js:445:33)
at ConfigArrayFactory.loadInDirectory (/home/aaronfranke/workspace/OddJobs/node_modules/eslint/lib/cli-engine/config-array-factory.js:401:18)
at CascadingConfigArrayFactory._loadConfigInAncestors (/home/aaronfranke/workspace/OddJobs/node_modules/eslint/lib/cli-engine/cascading-config-array-factory.js:305:46)
at CascadingConfigArrayFactory.getConfigArrayForFile (/home/aaronfranke/workspace/OddJobs/node_modules/eslint/lib/cli-engine/cascading-config-array-factory.js:250:18)
at CLIEngine.executeOnText (/home/aaronfranke/workspace/OddJobs/node_modules/eslint/lib/cli-engine/cli-engine.js:860:47)
at /home/aaronfranke/.vscode/extensions/dbaeumer.vscode-eslint-1.9.1/server/out/eslintServer.js:1:60107
at /home/aaronfranke/.vscode/extensions/dbaeumer.vscode-eslint-1.9.1/server/out/eslintServer.js:1:61116
What's going on? Is this option not valid somehow? Is the example config wrong? Is there something wrong with my ESLint extension? Is there something wrong with VS Code? I'm using Ubuntu 18.04 Linux 64-bit with VS Code 1.40.1, ESLint extension 1.9.1, and eslint --version is v5.16.0.

It is not allowed to put this settings as a top level property, which means it has to be nested in another property, which is "rules". So you have to write it like this:
{
//... other stuff ...
"rules": {
"indent": [ "error", "tab" ]
}
}

Related

When I type "npm run generate" in my code block vscode out and deleting the letter i

When I type "npm run generate" in my code block, codegen generates my graphql file automatically. But while generating vscode is freaking out and deleting the letter i. When I make a new change, I have to constantly change it. Has anyone encountered such a problem before?
My codegen.yml file looks like this:
overwrite: true
schema: "http://localhost:3000/graphql"
#schema:
# - https://***/graphql:
# headers:
# Cookie: "***"
documents: "src/**/*.graphql"
generates:
src/generated/graphql.tsx:
plugins:
- "typescript"
- "typescript-operations"
- "typescript-react-apollo"
- "fragment-matcher"
./graphql.schema.json:
plugins:
- "introspection"
It's probably something on your env, replacing io with O.
Could you create a minimal isolated reproduction of this issue, maybe via StackBlitz or CodeSandbox?

Eslint prettier error on new line incomprehensible

I have and error of eslint in my code that I cannot understand how turn off, these are some examples:
As you can see there is a eslint(prettier/prettier) rule that is incomprehensible and I can't understand how to turn off.
This is my eslint and prettier config:
eslint
module.exports = {
root: true,
extends: ['#react-native-community'],
parser: '#typescript-eslint/parser',
plugins: ['#typescript-eslint'],
overrides: [
{
files: ['*.ts', '*.tsx'],
rules: {
'#typescript-eslint/no-shadow': ['error'],
'no-shadow': 'off',
'no-undef': 'off',
},
},
],
};
prettier
module.exports = {
printWidth: 100,
arrowParens: 'avoid',
bracketSameLine: false,
singleQuote: true,
tabWidth: 2
};
Oh Pierro... Its you again.
Your Prettier configuration is not in sync with your ESLint configuration.
When you set Prettier's print-width rule, you need to always make sure that you set ESLint's max-len rule to the same value. This is very import, and is likely causing your issue. You seem to have some other stuff going on though.
#see this post
You need to synchronize the two. Ir looks like a JSX configuration that's causing problems. Try changing the value of bracketSameLine in your prettier configuration to true, or try getting rid of it all together.
You see where it says that the rule prettier/prettier is causing the issue? That should be in your configuration.
That's odd... You don't seem to have your .eslintrc.* file configured properly. It looks like your not properly configuring the eslint-plugin-prettier plugin for ESLint.
If you look at the plugin's documentation, which is where the prettier/prettier rule comes from (the first prettier is the name if the plugin, the second prettier is the name of the rule) it says you need to add the following values to the correct settings in your .eslintrc.* configuration file.
{
"plugins": ["prettier"],
"rules": {
"prettier/prettier": "error"
}
}
Its odd that the prettier/prettier rule shows up at all without you having added that configuration.
#see this answer here, it thoroughly explains what the prettier/prettier rule is.
The if the prettier config file is not present, the auto-formatting properties of vscode are taken as the default. the settings.json in the .vscode settings should be in sync with the linter properties. In your case you don't have prettier configured thats why the error is being thrown from prettier/prettier

How do I get flake8 to reliably ignore rules in VS Code?

Two things that annoy me. First is the warning Flake8 gives me when I type more than 80 characters on a line. Second is the warnings I get when I haven't yet used a module name that I imported. I've looked at all the documentation on using Flake8 in the terminal. No use.
flake8 --ignore=E402
flake8 --max-line-length=120
This doesn't work. At least VS Code doesn't show any effect.
Add your arguments to your USER SETTINGS json file like this:
"python.linting.flake8Args": [
"--max-line-length=120",
"--ignore=E402,F841,F401,E302,E305",
],
note that flake8 uses
"python.linting.flake8Args": [
whereas black seems to use:
"python.formatting.blackArgs": [
if you're using both (or toggling) these settings maybe helpful:
{
"python.linting.pylintEnabled": false,
"python.linting.flake8Enabled": true,
"python.linting.enabled": true,
"python.formatting.provider": "black",
"python.formatting.blackArgs": [
"--line-length",
"120"
],
"python.linting.flake8Args": [
"--max-line-length=120",
"--ignore=E402",
],
"python.pythonPath": "venv/bin/python"
}
In my case (vscode 1.72.2, flake 5.0.4) it only worked by adding:
"flake8.args": [
"--max-line-length=120"
]
in the settings.json
I prefer editing the Workspace settings, namely <root project folder>/.vscode/settings.json, because I store it in version control. This way it is backed up and everyone working on the project will get it.
What was suggested in most of the other answers:
"python.linting.flake8Args": [
"--max-line-length=120",
],
had no effect for me.
I ran into this problem recently. I ran into problems because I was setting the argument to --config flake8.cfg instead of --config=flake8.cfg. Under the hood, vscode puts the CLI argument in quotes. Adding "--config flake8.cfg" to the flake8 command seems to confuse flake8 into thinking that it's looking at a file path and not a CLI argument.
The solution for me was to either set the args as --config=flake8.cfg (with the equals sign) or the args up into separate items in the array:
"python.linting.flake8Args": [
"--config",
"flake8.cfg"
]
The solution proposed by reka18 is great and was no doubt written specifically for the original question.
From a more general stand point, I would advise against using this kind of trick
if you work on a project that has dedicated configuration files.
You are guaranteed to run into incomprehensible configuration conflicts
and will possibly ignore rules that were purposefully enforced by the project.
In this case, you should use the following instead:
assuming the file is named .flake8 and is present at the project's root folder
// .vscode/settings.json
"python.linting.flake8Args": ["--config", ".flake8"],
Using --config .flake8 ensures only this file will be read (See official doc).
So it is important to use this option, even though it is a default value. Otherwise, a custom user configuration in a parent folder could accidentally be used.
To extend (change) the default Flake8 line length I added the following in my VS Code workspace: project.code-workspace:
{
...
"settings": {
"flake8.args": [
"--max-line-length=120",
]
}
}

Need help to complete installation of linter-stylelint for Atom

I am really sorry for this newbie question but I can't see how solve that...
I installed linter-stylelint and tried to configure it like it's said there:
https://atom.io/packages/linter-stylelint
So:
- I placed a stylelint.config.js file in my project.
- In the settings, I checked Use standard
- But can't see what I have to do to "Add a stylelint section in your package.json"
On my Mac I see the file:
/Users/eric/node_modules/stylelint-config-standard
But I don't know what code do I have to insert inside...
By the way, when I try to use linter-stylelint in a css file I get the error message:
Unable to parse stylelint configuration
Unexpected token :
In my stylelint.config.js, I have the following code for now:
{
"extends": "stylelint-config-standard"
"rules" {
"no-unsupported-browser-features": [ true, { "severity": "warning" }]
}
}
Thanks if you can help me!
;)
Paul
So: - I placed a stylelint.config.js file in my project. - In the settings, I checked Use standard
According to the docs you reference, you should either place a stylelint.config.js file or check "Use standard".
I get the error message Unable to parse stylelint configuration Unexpected token :
This is because the JSON of your configuration file is invalid. It is missing both a comma and a colon. Use a service like JSONLint to validate JSON. Your fixed config is:
{
"extends": "stylelint-config-standard",
"rules": {
"no-unsupported-browser-features": [true, {
"severity": "warning"
}]
}
}
Even though this config is valid JSON, it won't work because the no-unsupported-browser-features rule is no longer built into stylelint. It is, however, available as a plugin. You'll need to follow the plugin's instructions if you wish to use it.
I am really sorry for this newbie question
It's fine. We are all newbies in the beginning! As you're just getting started with stylelint, I suggest you remove the stylelint.config.js file and ensure the "Use Standard" box is checked. This is likely the quickest way to get going. Once you are more comfortable with the tool, you can investigate creating your own configuration file for your specific needs.

TSLint Config in VS Code

I'm trying to configure the max line length (among other settings) for TS Lint in VS code but no matter what changes I make it doesn't 'take'.
So, the first strange thing is that VS code's TS Lint error for max line length says I've exceeded the 140 character limit but in the various config files I've found it only ever mentions 120 characters as the default.
I've changed this to 200 characters, disabled / enabled the extension but still get the 140 character warning. Does anyone know where and how to configure this setting? The documentation online is clear enough but I don't appear to have a tslint.json file and within the node_modules => tslint => lib => rules folder the setting is 120 and changing it makes no difference.
Edit 2020-09-30
Microsoft deprectaded the old plugin and released a newer, completely rewritten version with additional features here.
For the new plugin the setting "tslint.enable": true does not exists and is not needed anymore.
Original Answer
You need to create a tslint.json (in your workspace root) and set something like this to disable the maximum line length:
{
"defaultSeverity": "error",
"extends": [
"tslint:recommended"
],
"jsRules": {},
"rules": {
"max-line-length": [false]
},
"rulesDirectory": []
}
Furthermore, ensure that the following options are set in the in the vscode user settings (settings.json):
"tslint.configFile": "./path/to/tslint/relative/from/workspaceroot/tslint.json",
"tslint.enable": true
The tslint.configFile option can be empty if the file is in the root directory of your workspace.
Further rules can be found here.