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

Error: Reference unexpected had more than one definition - please file a github issue #1108

Closed
roschaefer opened this issue May 14, 2022 · 6 comments · Fixed by #1109
Closed
Assignees

Comments

@roschaefer
Copy link

roschaefer commented May 14, 2022

I don't quite understand what's going on but since the latest update from ^26.1.5 -> ^26.2.1 I see the following error:

$ yarn workspaces foreach -pv run lint
[... a lot of workspaces exit with status code 0]
➤ YN0000: [@beteon/serverless-wrapper]:
➤ YN0000: [@beteon/serverless-wrapper]: Oops! Something went wrong! :(
➤ YN0000: [@beteon/serverless-wrapper]:
➤ YN0000: [@beteon/serverless-wrapper]: ESLint: 8.8.0
➤ YN0000: [@beteon/serverless-wrapper]:
➤ YN0000: [@beteon/serverless-wrapper]: Error: Reference unexpected had more than one definition - please file a github issue at https://github.com/jest-community/eslint-plugin-jest
➤ YN0000: [@beteon/serverless-wrapper]: Occurred while linting /home/robert/Development/auteon/beteon/cloudrun/serverless-wrapper/src/pubSubApp.ts:38
➤ YN0000: [@beteon/serverless-wrapper]: Rule: "jest/no-conditional-expect"
➤ YN0000: [@beteon/serverless-wrapper]:     at collectReferences (/home/robert/Development/auteon/beteon/.yarn/__virtual__/eslint-plugin-jest-virtual-b357a19ac6/0/cache/eslint-plugin-jest-npm-26.2.1-0c46a1ee3e-18e105a1a6.zip/node_modules/eslint-plugin-jest/lib/rules/utils.js:589:15)
➤ YN0000: [@beteon/serverless-wrapper]:     at resolveToJestFn (/home/robert/Development/auteon/beteon/.yarn/__virtual__/eslint-plugin-jest-virtual-b357a19ac6/0/cache/eslint-plugin-jest-npm-26.2.1-0c46a1ee3e-18e105a1a6.zip/node_modules/eslint-plugin-jest/lib/rules/utils.js:630:22)
➤ YN0000: [@beteon/serverless-wrapper]:     at isTestCaseCall (/home/robert/Development/auteon/beteon/.yarn/__virtual__/eslint-plugin-jest-virtual-b357a19ac6/0/cache/eslint-plugin-jest-npm-26.2.1-0c46a1ee3e-18e105a1a6.zip/node_modules/eslint-plugin-jest/lib/rules/utils.js:425:10)
➤ YN0000: [@beteon/serverless-wrapper]:     at /home/robert/Development/auteon/beteon/.yarn/__virtual__/eslint-plugin-jest-virtual-b357a19ac6/0/cache/eslint-plugin-jest-npm-26.2.1-0c46a1ee3e-18e105a1a6.zip/node_modules/eslint-plugin-jest/lib/rules/utils.js:405:107
➤ YN0000: [@beteon/serverless-wrapper]:     at Array.filter (<anonymous>)
➤ YN0000: [@beteon/serverless-wrapper]:     at /home/robert/Development/auteon/beteon/.yarn/__virtual__/eslint-plugin-jest-virtual-b357a19ac6/0/cache/eslint-plugin-jest-npm-26.2.1-0c46a1ee3e-18e105a1a6.zip/node_modules/eslint-plugin-jest/lib/rules/utils.js:405:28
➤ YN0000: [@beteon/serverless-wrapper]:     at Array.reduce (<anonymous>)
➤ YN0000: [@beteon/serverless-wrapper]:     at getTestCallExpressionsFromDeclaredVariables (/home/robert/Development/auteon/beteon/.yarn/__virtual__/eslint-plugin-jest-virtual-b357a19ac6/0/cache/eslint-plugin-jest-npm-26.2.1-0c46a1ee3e-18e105a1a6.zip/node_modules/eslint-plugin-jest/lib/rules/utils.js:401:28)
➤ YN0000: [@beteon/serverless-wrapper]:     at FunctionDeclaration (/home/robert/Development/auteon/beteon/.yarn/__virtual__/eslint-plugin-jest-virtual-b357a19ac6/0/cache/eslint-plugin-jest-npm-26.2.1-0c46a1ee3e-18e105a1a6.zip/node_modules/eslint-plugin-jest/lib/rules/no-conditional-expect.js:42:93)
➤ YN0000: [@beteon/serverless-wrapper]:     at ruleErrorHandler (/home/robert/Development/auteon/beteon/.yarn/cache/eslint-npm-8.8.0-4abd179cd9-41a7e85bf8.zip/node_modules/eslint/lib/linter/linter.js:1107:28)
➤ YN0000: [@beteon/serverless-wrapper]: Process exited (exit code 2), completed in 11s 912ms

We're using typescript and method overloading on line 38 in the mentioned file:

export function pubSubApp(
  serverlessFunction: typeof eventSearchInit
): express.Application
export function pubSubApp(
  serverlessFunction: typeof eventProcessBotOffers
): express.Application
export function pubSubApp(
  serverlessFunction: typeof eventProcessValidationResults
): express.Application
export function pubSubApp(
  serverlessFunction: typeof eventAuthorize
): express.Application
export function pubSubApp(
  serverlessFunction: typeof eventSearch
): express.Application
export function pubSubApp(
  serverlessFunction: typeof eventOrder
): express.Application
export function pubSubApp(
  serverlessFunction: typeof eventValidateCart
): express.Application
export function pubSubApp(
  serverlessFunction: ServerlessFunction
): express.Application {

image

I see this was introduced in #1094 here https://github.com/jest-community/eslint-plugin-jest/pull/1094/files#diff-1c5ed711c5adf38f4dfb60de69d029f944e90550f85ea37e087482ccbc884e91R899

I just can't get my head around this section. @G-Rath what do you mean with ref unexpected?

$> node --version
v16.15.0
$> yarn --version
3.2.1
$> yarn info eslint version
└─ eslint@npm:8.8.0
   ├─ Version: 8.8.0
Eslint configuration file
module.exports = {
  root: true,
  env: {
    es2021: true,
    node: true,
  },
  extends: [
    'eslint:recommended',
    'plugin:@typescript-eslint/recommended',
    'plugin:prettier/recommended',
    'plugin:jest/recommended',
    'plugin:import/recommended',
    'plugin:import/typescript',
  ],
  ignorePatterns: ['dist/**'],
  parser: '@typescript-eslint/parser',
  parserOptions: {
    ecmaVersion: 12,
  },
  plugins: ['@typescript-eslint', 'jest', 'import', 'unused-imports'],
  rules: {
    '@typescript-eslint/consistent-type-assertions': [
      'error',
      {
        assertionStyle: 'never',
      },
    ],
    '@typescript-eslint/no-non-null-assertion': 'error',
    '@typescript-eslint/no-unused-vars': 'off',
    'unused-imports/no-unused-imports': 'error',
    'unused-imports/no-unused-vars': [
      'warn',
      {
        args: 'after-used',
        argsIgnorePattern: '^_',
        vars: 'all',
        varsIgnorePattern: '^_',
      },
    ],
    'import/no-cycle': [2],
    'no-console': 'error',
    curly: ['error', 'multi-line'],
    '@typescript-eslint/naming-convention': [
      'warn',
      {
        selector: 'parameter',
        format: ['camelCase', 'snake_case', 'UPPER_CASE', 'PascalCase'],
        leadingUnderscore: 'allow',
        trailingUnderscore: 'allow',
      },
      {
        selector: 'variable',
        format: ['camelCase', 'snake_case', 'UPPER_CASE', 'PascalCase'],
        leadingUnderscore: 'allow',
        trailingUnderscore: 'allow',
        modifiers: ['destructured'],
      },
      {
        selector: 'variable',
        format: ['camelCase', 'snake_case', 'UPPER_CASE'],
        leadingUnderscore: 'allow',
        trailingUnderscore: 'allow',
        modifiers: ['const'],
      },
      {
        selector: 'enum',
        format: ['PascalCase'],
      },
      {
        selector: 'enumMember',
        format: ['camelCase', 'UPPER_CASE'],
      },
      {
        selector: 'variableLike',
        format: ['camelCase', 'snake_case'],
        leadingUnderscore: 'allow',
        trailingUnderscore: 'allow',
      },
    ],
    '@typescript-eslint/consistent-type-imports': 'warn',
    'sort-imports': [
      'warn',
      {
        ignoreCase: true,
        ignoreDeclarationSort: true,
      },
    ],
    'import/no-default-export': 'warn',
    "no-restricted-imports": ["error", {
      "patterns": [{
        group: ["@beteon/**/src/*"]
      },{
        group: ["src/*"],
        message: "We have an issue with absolute paths and workspaces referenced in other workspaces. See PR #1144 on Github."
      }]
    }],
    'no-return-await': 'warn',
  },
  overrides: [
    {
      files: ['**/test/**/*.ts', '**/*.spec.ts'],
      rules: {
        '@typescript-eslint/consistent-type-assertions': [
          'warn',
          {
            assertionStyle: 'as',
            objectLiteralTypeAssertions: 'never',
          },
        ],
      },
    },
    {
      files: ['bots/**'],
      rules: {
        "no-restricted-imports": ["error", {
          "patterns": ["@beteon/**/src/*" ]
        }]
      },
    },
  ],
  settings: {
    'import/resolver': {
      typescript: {}, // this loads <rootdir>/tsconfig.json to eslint
    },
  },
}
@G-Rath
Copy link
Collaborator

G-Rath commented May 14, 2022

Thanks for submitting this, I'll get a fix out ASAP.

what do you mean with ref unexpected?

two things:

  1. I have bad grammar (it should be "ref unexpectedly")
  2. I wasn't able to think of a situation where there could be more than one definition and suspected it might have been a legacy thing, but made it fail noisily incase I was wrong because the alternative (which was very possible) is that there's an exotic/rare case where we do have more than one definition, and I want to make sure we're doing the right thing in that case.

@kukhariev & @diegohaz can you confirm if you're hitting this on the same kind of code? (function overloads)

I also just realised I can produce this with duplicate imports:

import { it } from '@jest/globals';
import { it } from '@jest/globals';

it('is not a jest function', () => {});

@diegohaz
Copy link

@G-Rath I don't have time to investigate the issue right now, but here's the log if it's helpful: https://github.com/ariakit/ariakit/runs/6433896824?check_suite_focus=true

@kukhariev
Copy link

I see:

Oops! Something went wrong! :(

ESLint: 8.15.0

Error: Reference unexpected had more than one definition - please file a github issue at https://github.com/jest-community/eslint-plugin-jest
Occurred while linting E:\Documents\GitHub\node-uploadx\packages\core\src\handlers\base-handler.ts:150
Rule: "jest/expect-expect"
    at collectReferences (E:\Documents\GitHub\node-uploadx\node_modules\eslint-plugin-jest\lib\rules\utils.js:589:15)
    at resolveToJestFn (E:\Documents\GitHub\node-uploadx\node_modules\eslint-plugin-jest\lib\rules\utils.js:630:22)
    at isTestCaseCall (E:\Documents\GitHub\node-uploadx\node_modules\eslint-plugin-jest\lib\rules\utils.js:425:10)
    at CallExpression (E:\Documents\GitHub\node-uploadx\node_modules\eslint-plugin-jest\lib\rules\expect-expect.js:96:40)
    at ruleErrorHandler (E:\Documents\GitHub\node-uploadx\node_modules\eslint\lib\linter\linter.js:1114:28)
    at E:\Documents\GitHub\node-uploadx\node_modules\eslint\lib\linter\safe-emitter.js:45:58
    at Array.forEach (<anonymous>)
    at Object.emit (E:\Documents\GitHub\node-uploadx\node_modules\eslint\lib\linter\safe-emitter.js:45:38)
    at NodeEventGenerator.applySelector (E:\Documents\GitHub\node-uploadx\node_modules\eslint\lib\linter\node-event-generator.js:297:26)
    at NodeEventGenerator.applySelectors (E:\Documents\GitHub\node-uploadx\node_modules\eslint\lib\linter\node-event-generator.js:326:22)
error Command failed with exit code 2.

https://github.com/kukhariev/node-uploadx/blob/master/packages/core/src/handlers/base-handler.ts
the same error in lines 150 (pick()), 155(this.finish()), 161(this.send()) ... etc.

@G-Rath
Copy link
Collaborator

G-Rath commented May 14, 2022

thanks for that - @diegohaz that file has function overloading, so it looks like the same cause.

@kukhariev yours is slightly different as it's declaration merging (interface + class) but has the same outcome as function overloading so that's good.

I'll merge #1109 in a few minutes once CI has passed, which'll fix this :)

@G-Rath G-Rath added the bug label May 14, 2022
@G-Rath G-Rath self-assigned this May 14, 2022
@github-actions
Copy link

🎉 This issue has been resolved in version 26.2.2 🎉

The release is available on:

Your semantic-release bot 📦🚀

@roschaefer
Copy link
Author

roschaefer commented May 16, 2022

@G-Rath @kukhariev @diegohaz wow, that was super quick. We're able to update to the latest release 🙌 🥳 Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants