Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug: @typescript-eslint/no-useless-constructor failed with Abstract Class + Inheritance #7996

Closed
4 tasks done
TechQuery opened this issue Nov 25, 2023 · 5 comments
Closed
4 tasks done
Labels
bug Something isn't working fix: out of date packages user was on an old version of our tooling or ESLint, updating fixed it package: eslint-plugin Issues related to @typescript-eslint/eslint-plugin

Comments

@TechQuery
Copy link

TechQuery commented Nov 25, 2023

Before You File a Bug Report Please Confirm You Have Done The Following...

  • I have tried restarting my IDE and the issue persists.
  • I have updated to the latest version of the packages.
  • I have searched for related issues and found none that matched my issue.
  • I have read the FAQ and my problem is not listed.

Playground Link

https://typescript-eslint.io/play/#ts=5.3.2&fileType=.ts&code=JYWwDg9gTgLgBAbzgIQIYGcCmAaOAZYdGAYQAsBXAOwGs4BfOAMyghDgHIABYAE01RCoANkID0PVDFQBaLFABuwAMaZ2AbgCwAKFCRYifIRgBZCHyG4AcpgDuAEUmp6TFm3YgIAIwAe0qJiJGciF1bV1oeABHckwoAE8AZRgoYEoAcxdWDmjYuNlk1LTQrW1Mbz14VE8iKFQleCUhDHQ4ABUqoUxTcwAebTg4OzgymExKHha0LGx%2BuAAxYe9R8Zbre0ceuwA%2BOABeODWHKU2t7R2RsYnDIm7MIU3cOZ2EWYw4yiU4IQhUHgAFVBpTAACjAgMwAElxmUAFxwSjkECeWK4MFAhLAABemDhCKRKKYwCEoygcLmAEpELMBkoIJQiAZPGY4s59qgbKhgPAYKRCAA6RrAMYwPlAmA9AhEMhUagnLbA6kDOAAAwAJAgefzPBhMABVABKELoAH51Tl4kkUuk%2BTVCsBGHFgS8tErXXA%2BR7GESSTMXW6BmjIdDvL7-QHwRjsYqBnRyXRlYryZo-QN-DByFBKAZA0dUHCmTw4gBCPlCIy4GAQKRCYgQKgwfPMku0%2Bv0ZMx7R0bRAA&eslintrc=N4KABGBECmAeAu0B2ATAzpAXGA2uCU8AhgE4D2A9CdEQMbyT4C6ANPpAA4A2ArgOYBLJBmx4CUNAIC23aAFppHMiXhy0yhszYRIJHl2giwocZEUaKAMwEk0DbJDKXLkbQUiSZBhTI1qL5ipGMCTkJK74Op6yPkoq-ioUcHHwwdChyhGmAALwAJ4chrQkAhyqhlxC8BRIZHI8aNAGaGhytGTC8Hr0mQ5OLm46uQVFJWVyFVU1dWgAFkQoZADuWFD9We7UdNXq8e0yq47OGzpb9BQAVmiw9Y2tZ-Zrx4NQD1Q09ApIclc3aO2FQ7rfAAXxAIKAA&tsconfig=N4KABGBEDGD2C2AHAlgGwKYCcDyiAuysAdgM6QBcYoEEkeAhpgObp4VTokBMADAIwB2SABpwNSPFgATAK4Z2MBJKIArMqJpRM6SQDd0AYSXoieMpQBm9VCXQbxibbcz6jpPAFEiM%2BObB5MGTsxWklZDAAlTlhUGQJiBSJpdBEQjgAPRCxkeBMGVAARdDhMejxYTD8AoPtaJIBJJFRkaGQ8AEEiAE92KxtgzUhrVFgAdwBlLtMAC1YWoqs5PEbECrN2aoHxWDiC5EwFZoAjVMGkgFVvWykAGVhoayrArbrYS5lrgAVGely8LCeNTSkBIARaeAAcnJUAZZtAANaAl5QEg7TDQdAAWXoiA2z1qUCO9Fs50wqAUADpTuJMLBYHg9gdKJAqQTIGp0gptPRoHgALQc6m0YZjABSSLZThi%2BnFxEx0jkKUomzZJHhyEQN2QR1hxXheKBgzwXSyETp60oAG00q8pOgAPphRUkAD0AAFjVl1DaoEwRkTUBSpBT1mkALpiAC%2B9kg6HS0FidvY1rOyUdCow3sGUmQoMgYjDMbgSDQ6GwRHG9H0vUe6BAkaAA&tokens=false

Repro Code

import { Base, ListChunk } from '@ideamall/data-service';
import { ListModel, NewData } from 'mobx-restful';
import queryString from 'query-string';

export abstract class TableModel<
  D extends Base,
  F extends NewData<D> = NewData<D>
> extends ListModel<D, F> {
  async loadPage(pageIndex: number, pageSize: number, filter: F) {
    const { body } = await this.client.get<ListChunk<D>>(
      `${this.baseURI}?${queryString.stringify({
        ...filter,
        pageIndex,
        pageSize
      })}`
    );
    return { pageData: body!.list, totalCount: body!.count };
  }
}

IdeaMall/mini-app@0ab7e17

ESLint Config

{
  "extends": ["taro/react"],
  "plugins": ["simple-import-sort"],
  "rules": {
    "import/first": "off",
    "simple-import-sort/imports": "error",
    "simple-import-sort/exports": "error",
    "@typescript-eslint/no-shadow": "off",
    "react/sort-comp": "off",
    "react/jsx-uses-react": "off",
    "react/react-in-jsx-scope": "off"
  }
}

tsconfig

{
  "compilerOptions": {
    "target": "es2017",
    "module": "commonjs",
    "removeComments": false,
    "preserveConstEnums": true,
    "moduleResolution": "node",
    "experimentalDecorators": true,
    "noImplicitAny": false,
    "allowSyntheticDefaultImports": true,
    "outDir": "lib",
    "noUnusedLocals": true,
    "noUnusedParameters": true,
    "strictNullChecks": true,
    "sourceMap": true,
    "baseUrl": ".",
    "rootDir": ".",
    "jsx": "react-jsx",
    "allowJs": true,
    "resolveJsonModule": true,
    "skipLibCheck": true,
    "typeRoots": ["node_modules/@types", "global.d.ts"]
  },
  "exclude": ["node_modules", "dist"],
  "compileOnSave": false
}

Expected Result

ESLint run with no crash in IdeaMall/mini-app#45.

Actual Result

Oops! Something went wrong! :(

ESLint: 8.54.0

TypeError: Cannot read properties of undefined (reading 'length')
Occurred while linting ~/idea2app/IdeaMall/mini-app/src/store/Base.ts:9
Rule: "@typescript-eslint/no-useless-constructor"
    at ~/idea2app/IdeaMall/mini-app/node_modules/.pnpm/@[email protected]_@[email protected][email protected][email protected]/node_modules/@typescript-eslint/eslint-plugin/dist/rules/no-useless-constructor.js:30:26
    at Array.some (<anonymous>)
    at checkParams (~/idea2app/IdeaMall/mini-app/node_modules/.pnpm/@[email protected]_@[email protected][email protected][email protected]/node_modules/@typescript-eslint/eslint-plugin/dist/rules/no-useless-constructor.js:29:31)
    at MethodDefinition (~/idea2app/IdeaMall/mini-app/node_modules/.pnpm/@[email protected]_@[email protected][email protected][email protected]/node_modules/@typescript-eslint/eslint-plugin/dist/rules/no-useless-constructor.js:52:21)
    at ruleErrorHandler (~/idea2app/IdeaMall/mini-app/node_modules/.pnpm/[email protected]/node_modules/eslint/lib/linter/linter.js:1091:28)
    at ~/idea2app/IdeaMall/mini-app/node_modules/.pnpm/[email protected]/node_modules/eslint/lib/linter/safe-emitter.js:45:58
    at Array.forEach (<anonymous>)
    at Object.emit (~/idea2app/IdeaMall/mini-app/node_modules/.pnpm/[email protected]/node_modules/eslint/lib/linter/safe-emitter.js:45:38)
    at NodeEventGenerator.applySelector (~/idea2app/IdeaMall/mini-app/node_modules/.pnpm/[email protected]/node_modules/eslint/lib/linter/node-event-generator.js:297:26)
    at NodeEventGenerator.applySelectors (~/idea2app/IdeaMall/mini-app/node_modules/.pnpm/[email protected]/node_modules/eslint/lib/linter/node-event-generator.js:326:22)
    at NodeEventGenerator.enterNode (~/idea2app/IdeaMall/mini-app/node_modules/.pnpm/[email protected]/node_modules/eslint/lib/linter/node-event-generator.js:340:14)
    at CodePathAnalyzer.enterNode (~/idea2app/IdeaMall/mini-app/node_modules/.pnpm/[email protected]/node_modules/eslint/lib/linter/code-path-analysis/code-path-analyzer.js:803:23)
    at ~/idea2app/IdeaMall/mini-app/node_modules/.pnpm/[email protected]/node_modules/eslint/lib/linter/linter.js:1126:32
    at Array.forEach (<anonymous>)
    at runRules (~/idea2app/IdeaMall/mini-app/node_modules/.pnpm/[email protected]/node_modules/eslint/lib/linter/linter.js:1121:15)
    at Linter._verifyWithoutProcessors (~/idea2app/IdeaMall/mini-app/node_modules/.pnpm/[email protected]/node_modules/eslint/lib/linter/linter.js:1370:31)
    at Linter._verifyWithConfigArray (~/idea2app/IdeaMall/mini-app/node_modules/.pnpm/[email protected]/node_modules/eslint/lib/linter/linter.js:1822:21)
    at Linter.verify (~/idea2app/IdeaMall/mini-app/node_modules/.pnpm/[email protected]/node_modules/eslint/lib/linter/linter.js:1452:65)
    at Linter.verifyAndFix (~/idea2app/IdeaMall/mini-app/node_modules/.pnpm/[email protected]/node_modules/eslint/lib/linter/linter.js:2083:29)
    at verifyText (~/idea2app/IdeaMall/mini-app/node_modules/.pnpm/[email protected]/node_modules/eslint/lib/cli-engine/cli-engine.js:254:48)
    at CLIEngine.executeOnFiles (~/idea2app/IdeaMall/mini-app/node_modules/.pnpm/[email protected]/node_modules/eslint/lib/cli-engine/cli-engine.js:834:28)
    at ESLint.lintFiles (~/idea2app/IdeaMall/mini-app/node_modules/.pnpm/[email protected]/node_modules/eslint/lib/eslint/eslint.js:551:23)
    at Object.execute (~/idea2app/IdeaMall/mini-app/node_modules/.pnpm/[email protected]/node_modules/eslint/lib/cli.js:402:36)
    at async main (~/idea2app/IdeaMall/mini-app/node_modules/.pnpm/[email protected]/node_modules/eslint/bin/eslint.js:152:22)

Additional Info

If I turn off this rule, the error disappears:

{
  "rules": {
    "@typescript-eslint/no-useless-constructor": "off",
  }
}

May be related with #7721.

@TechQuery TechQuery added bug Something isn't working package: eslint-plugin Issues related to @typescript-eslint/eslint-plugin triage Waiting for team members to take a look labels Nov 25, 2023
@bradzacher
Copy link
Member

bradzacher commented Nov 26, 2023

Your playground doe snot reproduce the error.
It also has a bunch of config completely unrelated to the problem.

Please provide a MINIMAL reproduction that reproduces the error as described.
Once you provide this we can reopen and re-evaluate!

@bradzacher bradzacher closed this as not planned Won't fix, can't repro, duplicate, stale Nov 26, 2023
@bradzacher bradzacher added unable to repro issues that a maintainer was not able to reproduce and removed triage Waiting for team members to take a look labels Nov 26, 2023
@TechQuery
Copy link
Author

TechQuery commented Nov 26, 2023

Your playground doe snot reproduce the error.

The online playground can't select the latest version 8.54.0, which I find the bug. Earlier versions has no error with the same code.

@bradzacher
Copy link
Member

bradzacher commented Nov 26, 2023

The online playground can't select the latest version 8.54.0, which I find the bug. Earlier versions has no error with the same code

This would have been very useful information to file as part of the original issue!

When you file a bug you should make sure to include a minimal reproduction case along with all the relevant information (eg "it works on version X but not on version Y").

@bradzacher bradzacher reopened this Nov 26, 2023
@bradzacher bradzacher added triage Waiting for team members to take a look and removed unable to repro issues that a maintainer was not able to reproduce labels Nov 26, 2023
@bradzacher
Copy link
Member

You're extending taro/react.
This config depends on v5 of our tooling.
It also does require-resolve of our parser which will force eslint to use their v5 of our parser.

So you're using v6 of our plugin with v5 of our parser.

You can't mix and match like this.
https://typescript-eslint.io/linting/troubleshooting/#how-do-i-check-to-see-what-versions-are-installed

@bradzacher bradzacher closed this as not planned Won't fix, can't repro, duplicate, stale Nov 27, 2023
@bradzacher bradzacher added fix: out of date packages user was on an old version of our tooling or ESLint, updating fixed it and removed triage Waiting for team members to take a look labels Nov 27, 2023
@TechQuery
Copy link
Author

You're extending taro/react. This config depends on v5 of our tooling. It also does require-resolve of our parser which will force eslint to use their v5 of our parser.

So you're using v6 of our plugin with v5 of our parser.

@bradzacher Thanks for your research! I have submitted an issue to Taro: NervJS/taro#14904

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Dec 6, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Something isn't working fix: out of date packages user was on an old version of our tooling or ESLint, updating fixed it package: eslint-plugin Issues related to @typescript-eslint/eslint-plugin
Projects
None yet
Development

No branches or pull requests

2 participants