eslint-config-airbnb-typescript icon indicating copy to clipboard operation
eslint-config-airbnb-typescript copied to clipboard

Invalid configuration for rule "@typescript-eslint/indent"

Open AdrienLemaire opened this issue 4 years ago • 16 comments

Getting an error with this plugin which breaks my vim eslint plugin integration:

[Error  - 1:08:39 PM] .eslintrc.yml » eslint-config-airbnb-typescript » 
/home/dori/Projects/Work/project-v3/client/node_modules/eslint-config-airbnb-typescript/lib/shared.js: 	
Configuration for rule "@typescript-eslint/indent" is invalid: 	
Value {"SwitchCase":1,"VariableDeclarator":1,"outerIIFEBody":1,"FunctionDeclaration":{"parameters":1,"body":1},"FunctionExpression":{"parameters":1,"body":1},"CallExpression":{"arguments":1},"ArrayExpression":1,"ObjectExpression":1,"ImportDeclaration":1,"flatTernaryExpressions":false,"ignoredNodes":["JSXElement","JSXElement > *","JSXAttribute","JSXIdentifier","JSXNamespacedName","JSXMemberExpression","JSXSpreadAttribute","JSXExpressionContainer","JSXOpeningElement","JSXClosingElement","JSXFragment","JSXOpeningFragment","JSXClosingFragment","JSXText","JSXEmptyExpression","JSXSpreadChild"],"ignoreComments":false,"offsetTernaryExpressions":false} 
should NOT have additional properties. 

Using eslint-config-airbnb-typescript 7.2.1

AdrienLemaire avatar May 29 '20 04:05 AdrienLemaire

Strangely, not even settings

rules:
  "@typescript-eslint/indent":
    - off
    - 2
    - {}

in my .eslintrc.yml file could fix it. I had to comment l.49 of node_modules/eslint-config-airbnb-typescript/lib/shared.js

    //'@typescript-eslint/indent': baseStyleRules.indent,

AdrienLemaire avatar May 29 '20 05:05 AdrienLemaire

Got this error as well.

sannysoft avatar May 30 '20 12:05 sannysoft

Hey @AdrienLemaire and @sannysoft

Sorry, I'm not sure how to replicate this problem. Is it easy to set this up from scratch? Would appreciate any additional details. Cheers!

iamturns avatar Jun 03 '20 11:06 iamturns

I was getting this issue and found that it does not happen when I run npx eslint myfile.ts in the same directory where I have eslint installed, i.e. it's in ./node_modules/eslint

When it's not installed in node_modules, and npx d/ls and runs it from a temporary npx location e.g. /home/user/_npx/... I do get this issue.

Hope this helps

hbak avatar Jun 09 '20 00:06 hbak

Same here, while bumping Eslint 6.8.0 to 7.2.0

Using eslint-config-airbnb-typescript 7.2.1 and 8.0.2

Zanderinos avatar Jun 12 '20 11:06 Zanderinos

Same issue, observed after running eslint-config-prettier CLI tool npx eslint --print-config index.js | npx eslint-config-prettier-check

adg29 avatar Jun 16 '20 20:06 adg29

This might be caused by updating to ESLint v7, which was not supported.

v9.0.0 of this library has just been released, and includes support for ESLint v7. Hopefully this fixes the issue.

iamturns avatar Jul 18 '20 12:07 iamturns

Still getting this error when using v9.0.0 of this library

kael89 avatar Jul 23 '20 07:07 kael89

Still getting the same issue with version 9.0.0

Error: .eslintrc » eslint-config-airbnb-typescript » ...\node_modules\eslint-config-airbnb-typescript\lib\shared.js:
Configuration for rule "@typescript-eslint/indent" is invalid:
Value {"SwitchCase":1,"VariableDeclarator":1,"outerIIFEBody":1,"FunctionDeclaration":{"parameters":1,"body":1},"FunctionExpression":{"parameters":1,"body":1},"CallExpression":{"arguments":1},"ArrayExpression":1,"ObjectExpression":1,"ImportDeclaration":1,"flatTernaryExpressions":false,"ignoredNodes":["JSXElement","JSXElement > *","JSXAttribute","JSXIdentifier","JSXNamespacedName","JSXMemberExpression","JSXSpreadAttribute","JSXExpressionContainer","JSXOpeningElement","JSXClosingElement","JSXFragment","JSXOpeningFragment","JSXClosingFragment","JSXText","JSXEmptyExpression","JSXSpreadChild"],"ignoreComments":false,"offsetTernaryExpressions":false} should NOT have additional properties.






fmendez89 avatar Jul 27 '20 13:07 fmendez89

@iamturns would you be willing to put out a quick version that comments out the @typescript-eslint/indent rule until you have time to do a proper fix? Line 71 below.

image

Else we're in a pretty bad position with options of having to manually comment it out for many developers each time we run yarn, downgrade, or abandon this package.

mlenser avatar Jul 28 '20 14:07 mlenser

Also experiencing this, and I looks like the root cause is multiple versions of @typescript-eslint/eslint-plugin in the hierarchy of node_modules, and eslint resolving to root node_modules packages that may be in different versions than the expectation.

Like airbnb, I encapsulate configs in a package (say @company/config-eslint), the package has a dep on @typescript-eslint/[email protected], but when this package is installed elsewhere with another dep that has an older version, yarn installs both, and the newer is nested under node_modules/@company/config-eslint/node_modules:

# node_modules

@typescript-eslint/[email protected] <-- too old
@typescript-eslint/[email protected]
@company/config-eslint/node_modules/@typescript-eslint/[email protected] <-- the new one is nested

when eslint resolves the plugins by name, it uses the one at the root of node_modules, which is 2.34.0, and the error shows.

In a different repo without the additional older version as a sub dep of one of the deps, v9.0.0 works without the indent config error.

This can possibly be resolved by using full paths (require.resolve) in the eslint config, instead of plugin names. A support for this is coming to eslint. See: https://github.com/eslint/rfcs/pull/14 / https://github.com/eslint/rfcs/pull/9

I was able to solve it, quite hackishly, using yarn resolutions, in the root package.json of the repo.

  "resolutions": {
    "@typescript-eslint/eslint-plugin": "^3.7.1"
  }

and this will also work if I add it as a local dependency.

EDIT: I hit this again in a different project, and the solution was to install eslint at the root.

elado avatar Jul 28 '20 22:07 elado

Still having this using globally installed eslint with typescript-eslint and airbnb-typescript:

  • eslint: 7.9.0
  • @typescript-eslint/eslint-plugin: 4.1.1
  • eslint-config-airbnb-typescript: 10.0.0
Error: .eslintrc.json » eslint-config-airbnb-typescript » xxxxxx/node_modules/eslint-config-airbnb-typescript/lib/shared.js:
	Configuration for rule "@typescript-eslint/indent" is invalid:
	Value {"SwitchCase":1,"VariableDeclarator":1,"outerIIFEBody":1,"FunctionDeclaration":{"parameters":1,"body":1},"FunctionExpression":{"parameters":1,"body":1},"CallExpression":{"arguments":1},"ArrayExpression":1,"ObjectExpression":1,"ImportDeclaration":1,"flatTernaryExpressions":false,"ignoredNodes":["JSXElement","JSXElement > *","JSXAttribute","JSXIdentifier","JSXNamespacedName","JSXMemberExpression","JSXSpreadAttribute","JSXExpressionContainer","JSXOpeningElement","JSXClosingElement","JSXFragment","JSXOpeningFragment","JSXClosingFragment","JSXText","JSXEmptyExpression","JSXSpreadChild"],"ignoreComments":false,"offsetTernaryExpressions":false} should NOT have additional properties.

nstrelow avatar Sep 15 '20 09:09 nstrelow

Still having this using globally installed eslint with typescript-eslint and airbnb-typescript:

  • eslint: 7.17.0
  • @typescript-eslint/eslint-plugin: 4.9.0
  • eslint-config-airbnb-typescript: 12.0.0

Also for reference using yarn 2

Does anyone have any clue how to solve it, thanks

ed-sparkes avatar Jan 04 '21 14:01 ed-sparkes

For a temporary fix to this problem use the following package versions.

  • eslint-config-airbnb-typescript: "^12.3.1"
  • eslint-plugin-import: "^2.22.1"
  • eslint: "^7.19.0"
  • @typescript-eslint/eslint-plugin: "^4.15.0"

HassanNiazi avatar Feb 15 '21 18:02 HassanNiazi

I tried multiple versions. The latest for all those libraries to this day, as well as some of the suggested combinations. What's weird is that it works fine when I add those packages to the project I am linting, but when I separate the eslint config to be a standalone yarn workspace I get the same issue with type "@typescript-eslint/indent" and commenting //@typescript-eslint/indent': baseStyleRules.indent, removes that issue.

ishabo avatar Apr 12 '21 15:04 ishabo

just faced the same issue (one and a half year later) on a project I have to maintain, running on a linux-based (ubuntu-latest) vsts-worker, using lerna, when I initially enabled eslint with latest packages:

Error: .eslintrc.js » eslint-config-airbnb-typescript/base » /home/vsts/work/1/s/packages/util-health-check/node_modules/eslint-config-airbnb-typescript/lib/shared.js:
	Configuration for rule "@typescript-eslint/indent" is invalid:
	Value {"SwitchCase":1,"VariableDeclarator":1,"outerIIFEBody":1,"FunctionDeclaration":{"parameters":1,"body":1},"FunctionExpression":{"parameters":1,"body":1},"CallExpression":{"arguments":1},"ArrayExpression":1,"ObjectExpression":1,"ImportDeclaration":1,"flatTernaryExpressions":false,"ignoredNodes":["JSXElement","JSXElement > *","JSXAttribute","JSXIdentifier","JSXNamespacedName","JSXMemberExpression","JSXSpreadAttribute","JSXExpressionContainer","JSXOpeningElement","JSXClosingElement","JSXFragment","JSXOpeningFragment","JSXClosingFragment","JSXText","JSXEmptyExpression","JSXSpreadChild"],"ignoreComments":false,"offsetTernaryExpressions":false} should NOT have additional properties.

    at ConfigValidator.validateRuleOptions (/home/vsts/work/1/s/node_modules/@eslint/eslintrc/dist/eslintrc.cjs:2027:23)
    at /home/vsts/work/1/s/node_modules/@eslint/eslintrc/dist/eslintrc.cjs:2082:18
    at Array.forEach (<anonymous>)
    at ConfigValidator.validateRules (/home/vsts/work/1/s/node_modules/@eslint/eslintrc/dist/eslintrc.cjs:2079:34)
    at ConfigValidator.validateConfigArray (/home/vsts/work/1/s/node_modules/@eslint/eslintrc/dist/eslintrc.cjs:2205:18)
    at CascadingConfigArrayFactory._finalizeConfigArray (/home/vsts/work/1/s/node_modules/@eslint/eslintrc/dist/eslintrc.cjs:3962:23)
    at CascadingConfigArrayFactory.getConfigArrayForFile (/home/vsts/work/1/s/node_modules/@eslint/eslintrc/dist/eslintrc.cjs:3768:21)
    at FileEnumerator._iterateFilesRecursive (/home/vsts/work/1/s/packages/util-health-check/node_modules/eslint/lib/cli-engine/file-enumerator.js:448:49)
    at _iterateFilesRecursive.next (<anonymous>)
    at FileEnumerator.iterateFiles (/home/vsts/work/1/s/packages/util-health-check/node_modules/eslint/lib/cli-engine/file-enumerator.js:299:49)

package.json:

...
"scripts": {
    "build": "tsc",
    "test": "jest --coverage",
    "test:watch": "jest --watch",
    "lint": "npx eslint src --ext .ts",
    "lint:fix": "npx eslint src --ext .ts --fix"
  },
  "devDependencies": {
    "@types/jest": "^29.2.4",
    "@types/node": "^18.11.18",
    "@typescript-eslint/eslint-plugin": "^5.47.1",
    "@typescript-eslint/parser": "^5.47.1",
    "eslint": "^8.30.0",
    "eslint-config-airbnb": "^19.0.4",
    "eslint-config-airbnb-typescript": "^17.0.0",
    "eslint-plugin-import": "^2.22.1",
    "jest": "^29.3.1",
    "jest-junit": "^15.0.0",
    "ts-jest": "^29.0.3",
    "ts-node": "^10.9.1",
    "typescript": "^4.9.4"
  }
...

.eslintrc.js

module.exports = {
    "env": {
        "browser": false,
        "node": true
    },
    "parser": "@typescript-eslint/parser",
    "parserOptions": {
        "project": "tsconfig.json",
        "sourceType": "module"
    },
    "extends": [
        'airbnb-base',
        'airbnb-typescript/base'
    ],
    "plugins": [
        "@typescript-eslint"
    ],
    "rules": {
        "max-len": ["error", { "code": 250 }]
    },
    "ignorePatterns": [
        ".eslintrc.js"
    ]
};

When running the same command on WSL2 for Windows, everything works as expected, though.

Am I missing sth?

earloc avatar Dec 29 '22 17:12 earloc