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

[no-unused-vars] TypeError: context.report() called with a messageId, but no messages were present in the rule metadata. #2451

Closed
3 tasks done
esetnik opened this issue Aug 31, 2020 · 14 comments · Fixed by #2461
Labels
bug Something isn't working package: eslint-plugin Issues related to @typescript-eslint/eslint-plugin

Comments

@esetnik
Copy link
Contributor

esetnik commented Aug 31, 2020

  • I have tried restarting my IDE and the issue persists.
  • I have updated to the latest version of the packages.
  • I have read the FAQ and my problem is not listed.

Repro

module.exports = {
  extends: [
    'react-app',
    'eslint:recommended',
    'plugin:@typescript-eslint/eslint-recommended',
    'plugin:@typescript-eslint/recommended',
    'plugin:prettier/recommended',
  ],
  rules: {
    '@typescript-eslint/no-unused-vars': [1, { argsIgnorePattern: '^_' }],
    '@typescript-eslint/explicit-function-return-type': 'off',
    'no-restricted-imports': [
      'error',
      {
        paths: [
          {
            name: 'styled-components',
            message: 'Please import from styled-components/macro.',
          },
        ],
        patterns: ['!styled-components/macro'],
      },
    ],
  },
};
// jest-styled-components.d.ts
declare namespace jest {
  interface Matchers<R> {
    toHaveStyleRule: import('jest-styled-components').jest.Matchers<
      R
    >['toHaveStyleRule'];
  }
}
{
  "compilerOptions": {
    "target": "es5",
    "lib": ["dom", "dom.iterable", "esnext"],
    "allowJs": true,
    "skipLibCheck": true,
    "esModuleInterop": true,
    "allowSyntheticDefaultImports": true,
    "strict": true,
    "forceConsistentCasingInFileNames": true,
    "module": "esnext",
    "moduleResolution": "node",
    "resolveJsonModule": true,
    "isolatedModules": true,
    "noEmit": true,
    "jsx": "react"
  },
  "include": ["src", "test"],
  "plugins": [
    {
      "name": "typescript-styled-plugin"
    }
  ]
}

Expected Result

No crash. The same configuration and file works fine in v3.10.1

Actual Result

After upgrading to v4.0.1

TypeError: context.report() called with a messageId, but no messages were present in the rule metadata.
Occurred while linting /Users/redacted/frontend/src/types/jest-styled-components.d.ts:1
    at /Users/redacted/frontend/node_modules/eslint/lib/linter/report-translator.js:317:23
    at Object.report (/Users/redacted/frontend/node_modules/eslint/lib/linter/linter.js:905:41)
    at TSModuleDeclaration (/Users/redacted/frontend/node_modules/@typescript-eslint/eslint-plugin/dist/rules/no-unused-vars.js:124:33)
    at /Users/redacted/frontend/node_modules/eslint/lib/linter/safe-emitter.js:45:58
    at Array.forEach (<anonymous>)
    at Object.emit (/Users/redacted/frontend/node_modules/eslint/lib/linter/safe-emitter.js:45:38)
    at NodeEventGenerator.applySelector (/Users/redacted/frontend/node_modules/eslint/lib/linter/node-event-generator.js:254:26)
    at NodeEventGenerator.applySelectors (/Users/redacted/frontend/node_modules/eslint/lib/linter/node-event-generator.js:283:22)
    at NodeEventGenerator.enterNode (/Users/redacted/frontend/node_modules/eslint/lib/linter/node-event-generator.js:297:14)
    at CodePathAnalyzer.enterNode (/Users/redacted/frontend/node_modules/eslint/lib/linter/code-path-analysis/code-path-analyzer.js:634:23)

Additional Info

typescript-eslint-debug.log

Versions

package version
@typescript-eslint/eslint-plugin 4.0.1
@typescript-eslint/parser 4.0.1
TypeScript 4.0.2
ESLint 6.8.0
node 12.8.3
@esetnik esetnik added package: eslint-plugin Issues related to @typescript-eslint/eslint-plugin triage Waiting for maintainers to take a look labels Aug 31, 2020
@bradzacher bradzacher added bug Something isn't working and removed triage Waiting for maintainers to take a look labels Aug 31, 2020
@bradzacher
Copy link
Member

This happens because you're on ESLint v6, but the messageID we're using was released in v7.

@esetnik
Copy link
Contributor Author

esetnik commented Aug 31, 2020

@bradzacher is @typescript-eslint v4.0.1 supposed to be compatible with eslint v6? I see it is included in the peerDeps range "eslint": "^5.0.0 || ^6.0.0 || ^7.0.0".

https://github.com/typescript-eslint/typescript-eslint/blob/master/packages/eslint-plugin/package.json#L64

@bradzacher bradzacher changed the title TypeError: context.report() called with a messageId, but no messages were present in the rule metadata. [no-unused-vars] TypeError: context.report() called with a messageId, but no messages were present in the rule metadata. Aug 31, 2020
@bradzacher
Copy link
Member

Which is why I marked this as a bug.
It should work with v6 but it doesn't.

@esetnik
Copy link
Contributor Author

esetnik commented Aug 31, 2020

Ok now I understand. I'm not too familiar with the project but I'm happy to work on a PR or provide any additional info if you can point me in the right direction.

@bradzacher
Copy link
Member

It's actually a super simple fix.

Has to handle the case where there are no messages defined, and default to something like the current v7 messages config:

https://github.com/eslint/eslint/blob/9250ab3e63836c71af87b10f29157bed278054e7/lib/rules/no-unused-vars.js#L78-L80

I.e. the above line becomes something like

messages: baseRule.meta.messages ?? {
  unusedVar: "'{{varName}}' is {{action}} but never used{{additional}}."
},

Happy to accept a PR if you want to do it!

@esetnik
Copy link
Contributor Author

esetnik commented Aug 31, 2020

It looks like a lot of the other rules need to be fixed e.g. no-unused-expressions. Do you want one PR to fix them all?

@bradzacher
Copy link
Member

Yeah definitely. That'll be much easier to submit and merge. Go for it!

@esetnik
Copy link
Contributor Author

esetnik commented Aug 31, 2020

I'm also thinking that the automated test suite should include different eslint versions in the test matrix to catch issues like this automatically. I'm looking into the best way to achieve that.

@bradzacher
Copy link
Member

Yeah testing old versions of things has always been a problem for us.

Usually eslint isn't too much of a problem because its api and internals are pretty stable for our use case.

We have an integration test for v6, but it's mostly there to make sure that we don't do any incompatible deep requires from eslint.

If you can figure out a good way to do it, that'd be fantastic!

@esetnik
Copy link
Contributor Author

esetnik commented Sep 1, 2020

@bradzacher I have implemented the missing messages fallbacks in #2461. I will look to improving the test configuration to support testing multiple eslint versions in a separate PR.

@esetnik
Copy link
Contributor Author

esetnik commented Sep 1, 2020

@bradzacher I have implemented eslint version matrix in test runner in #2463. It is currently failing because it is based off master (which is not compatible with eslint v5 or v6 due to #2451). The tests should start to pass after it is rebased off #2461.

@esetnik
Copy link
Contributor Author

esetnik commented Sep 2, 2020

@bradzacher Will you be publishing a new version including this fix in the near future? It's currently the only thing blocking us from using the new @typescript-eslint with create-react-app.

@bradzacher
Copy link
Member

We release every Monday morning (PST).

This weekend I'm planning on fixing all of the scope analysis bugs people found in this version (see milestone), so Monday's version will be a much better version for you to upgrade CRA to.

@jarretmoses
Copy link

jarretmoses commented Sep 3, 2020

@bradzacher @esetnik Just for clarification I am getting this error too but it only occurs when trying to lint declaration files. If I use ignorePatterns: ['*.d.ts'] it seems to work fine. Does this resolve this issue?

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Oct 4, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Something isn't working package: eslint-plugin Issues related to @typescript-eslint/eslint-plugin
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants