iamturns / eslint-config-airbnb-typescript

Airbnb's ESLint config with TypeScript support
MIT License
1.05k stars 97 forks source link

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

Open AdrienLemaire opened 4 years ago

AdrienLemaire commented 4 years ago

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 commented 4 years ago

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,
sannysoft commented 4 years ago

Got this error as well.

iamturns commented 4 years ago

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!

hbak commented 4 years ago

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

Zanderinos commented 4 years ago

Same here, while bumping Eslint 6.8.0 to 7.2.0

Using eslint-config-airbnb-typescript 7.2.1 and 8.0.2

adg29 commented 4 years ago

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

iamturns commented 4 years ago

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.

kael89 commented 4 years ago

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

fmendez89 commented 4 years ago

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.
mlenser commented 4 years ago

@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.

elado commented 4 years ago

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/eslint-plugin@3.7.1, 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/eslint-plugin@2.34.0 <-- too old
@typescript-eslint/parser@3.7.1
@company/config-eslint/node_modules/@typescript-eslint/eslint-plugin@3.7.1 <-- 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.

nstrelow commented 4 years ago

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

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.
ed-sparkes commented 3 years ago

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

Also for reference using yarn 2

Does anyone have any clue how to solve it, thanks

HassanNiazi commented 3 years ago

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

ishabo commented 3 years ago

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.

earloc commented 1 year ago

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?