salesforce / eslint-plugin-lwc

Official ESLint rules for LWC
MIT License
98 stars 32 forks source link

Wire to a property is failing the `@lwc/lwc/no-unknown-wire-adapters` rule #142

Closed constantine-prokopenko-vrp closed 9 months ago

constantine-prokopenko-vrp commented 9 months ago

I faced a strange issue where @wire to a property causing the @lwc/lwc/no-unknown-wire-adapters rule to fail.

@wire(MessageContext)
messageContext;

@wire(getObjectInfo, { objectApiName: ACCOUNT })
accountInfo;

Below you can find the trace.

Rule: "@lwc/lwc/no-unknown-wire-adapters"
    at Decorator (node_modules/@lwc/eslint-plugin-lwc/lib/rules/no-unknown-wire-adapters.js:82:18)
    at ruleErrorHandler (node_modules/eslint/lib/linter/linter.js:1076:28)
    at node_modules/eslint/lib/linter/safe-emitter.js:45:58
    at Array.forEach (<anonymous>)
    at Object.emit (node_modules/eslint/lib/linter/safe-emitter.js:45:38)
    at NodeEventGenerator.applySelector (node_modules/eslint/lib/linter/node-event-generator.js:297:26)
    at NodeEventGenerator.applySelectors (node_modules/eslint/lib/linter/node-event-generator.js:326:22)
    at NodeEventGenerator.enterNode (node_modules/eslint/lib/linter/node-event-generator.js:340:14)
    at CodePathAnalyzer.enterNode (node_modules/eslint/lib/linter/code-path-analysis/code-path-analyzer.js:803:23)
    at node_modules/eslint/lib/linter/linter.js:1111:32
    at Array.forEach (<anonymous>)
    at runRules (node_modules/eslint/lib/linter/linter.js:1106:15)
    at Linter._verifyWithoutProcessors (node_modules/eslint/lib/linter/linter.js:1355:31)
    at Linter._verifyWithConfigArray (node_modules/eslint/lib/linter/linter.js:1807:21)
    at Linter.verify (node_modules/eslint/lib/linter/linter.js:1437:65)
    at Linter.verifyAndFix (node_modules/eslint/lib/linter/linter.js:2068:29)
    at verifyText (node_modules/eslint/lib/cli-engine/cli-engine.js:254:48)
    at CLIEngine.executeOnText (node_modules/eslint/lib/cli-engine/cli-engine.js:928:26)
    at ESLint.lintText (node_modules/eslint/lib/eslint/eslint.js:593:23)
    at /.vscode/extensions/dbaeumer.vscode-eslint-2.4.4/server/out/eslintServer.js:1:24962
    at E (/.vscode/extensions/dbaeumer.vscode-eslint-2.4.4/server/out/eslintServer.js:1:19120)
    at e.validate (/.vscode/extensions/dbaeumer.vscode-eslint-2.4.4/server/out/eslintServer.js:1:24921)
    at /.vscode/extensions/dbaeumer.vscode-eslint-2.4.4/server/out/eslintServer.js:1:220305

Project packages are listed below.

"devDependencies": {
    "@babel/core": "^7.23.9",
    "@babel/eslint-parser": "^7.23.10",
    "@locker/eslint-config-locker": "^0.21.0",
    "@lwc/eslint-plugin-lwc": "^1.7.2",
    "@playwright/test": "^1.41.1",
    "@prettier/plugin-xml": "^3.2.2",
    "@salesforce/eslint-config-lwc": "^3.5.2",
    "@salesforce/eslint-plugin-aura": "^2.1.0",
    "@salesforce/eslint-plugin-lightning": "^1.0.0",
    "@salesforce/sfdx-lwc-jest": "^3.1.1",
    "@tsconfig/node20": "^20.1.2",
    "@types/node": "^20.11.14",
    "csvtojson": "^2.0.10",
    "dotenv": "^16.4.1",
    "envfile": "^7.1.0",
    "eslint": "^8.56.0",
    "eslint-plugin-import": "^2.29.1",
    "eslint-plugin-jest": "^27.6.3",
    "glob": "^10.3.10",
    "husky": "^9.0.7",
    "husky-init": "^8.0.0",
    "lint-staged": "^15.2.1",
    "prettier": "^3.2.4",
    "prettier-plugin-apex": "^2.0.1",
    "readline-sync": "^1.4.10",
    "typescript": "^5.3.3",
    "xml2js": "^0.6.2"
}

ESLint configuration you can find below.

{
    "parserOptions": {
        "ecmaVersion": "latest",
        "sourceType": "module"
    },
    "overrides": [
        {
            "env": {
                "es6": false,
                "node": false,
                "browser": true
            },
            "files": ["**/aura/**/*.js"],
            "plugins": ["@salesforce/eslint-plugin-aura"],
            "extends": [
                "plugin:@salesforce/eslint-plugin-aura/recommended",
                "plugin:@salesforce/eslint-plugin-aura/locker"
            ],
            "globals": {
                "$A": "readonly",
                "$": "readonly"
            }
        },
        {
            "files": ["**/lwc/**/*.js"],
            "parser": "@babel/eslint-parser",
            "parserOptions": {
                "requireConfigFile": false,
                "babelOptions": {
                    "parserOpts": {
                        "plugins": [
                            "classProperties",
                            ["decorators", { "decoratorsBeforeExport": false }]
                        ]
                    }
                }
            },
            "plugins": ["@lwc/eslint-plugin-lwc"],
            "rules": {
                "@lwc/lwc/no-deprecated": "error",
                "@lwc/lwc/valid-api": "error",
                "@lwc/lwc/no-document-query": "error"
            },
            "extends": [
                "eslint:recommended",
                "@salesforce/eslint-config-lwc/recommended",
                "@locker/eslint-config-locker/recommended"
            ]
        }
    ]
}
nolanlawson commented 9 months ago

@constantine-prokopenko-vrp Thanks for filing. What is the exact error message you're getting? Is it ... is not a known adapter?

https://github.com/salesforce/eslint-plugin-lwc/blob/35b9b526fdecc53803187859af16207bff9ee4fa/lib/rules/no-unknown-wire-adapters.js#L78-L88

constantine-prokopenko-vrp commented 9 months ago

Good day @nolanlawson. It was failing in the code below.

const adapterVariable = scope.references.find(
    (r) => r.identifier === adapterNode,
).resolved;

It was failing with the following error message. Cannot read property 'resolved' of null.

Today I removed and reinstalled all the npm modules and now it works fine.