Skip to content

Detect suggestions with spread variable in require-meta-has-suggestions #281

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

Closed
bmish opened this issue Aug 4, 2022 · 1 comment · Fixed by #287
Closed

Detect suggestions with spread variable in require-meta-has-suggestions #281

bmish opened this issue Aug 4, 2022 · 1 comment · Fixed by #287
Labels

Comments

@bmish
Copy link
Member

bmish commented Aug 4, 2022

Related of #272 but distinct and might be a bit easier to fix since we just need to evaluate the spread.

const fixOrSuggest: {
  fix: TSESLint.ReportFixFunction | null;
  suggest: TSESLint.ReportSuggestionArray<MessageIds> | null;
} = {
  fix: null,
  suggest: [
    {
      messageId: 'suggestUnknown',
      fix(fixer): TSESLint.RuleFix {
        return fixer.replaceText(node, 'unknown');
      },
    },
    {
      messageId: 'suggestNever',
      fix(fixer): TSESLint.RuleFix {
        return fixer.replaceText(node, 'never');
      },
    },
  ],
};

if (fixToUnknown) {
  fixOrSuggest.fix = (fixer): TSESLint.RuleFix =>
    fixer.replaceText(node, 'unknown');
}

context.report({
  node,
  messageId: 'unexpectedAny',
  ...fixOrSuggest,
});

https://github.com/typescript-eslint/typescript-eslint/blob/ad412cdd74dc5619fbe4bf27c0a5eb5c5a4b65ca/packages/eslint-plugin/src/rules/no-explicit-any.ts#L205

This is not specific to TypeScript.

@bmish bmish added the bug label Aug 4, 2022
@JoshuaKGoldberg
Copy link
Contributor

This might be another case like #283 🤔 . What if a rule calls to a helper function to report with suggestions? Same strategy as #283 (comment)?

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