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

@typescript-eslint/explicit-function-return-type error detected in JS file #1525

Open
munierujp opened this issue Apr 14, 2024 · 1 comment

Comments

@munierujp
Copy link
Contributor

munierujp commented Apr 14, 2024

Run ESLint with eslint-config-love on a file like the following.

/**
 * @param {string} username - user name
 * @returns {void}
 */
const sayHello = (username) => {
  console.log(`Hello, ${username}`)
}

const myName = 'Alice'
sayHello(myName)

Then, the following error is then detected.

  5:29  error  Missing return type on function  @typescript-eslint/explicit-function-return-type

This is an odd behavior since JavaScript does not allow for return types.

Solution

Perhaps this rule should be enabled for TS files only.

{
  "rules": {
    // disable the rule for all files
    "@typescript-eslint/explicit-function-return-type": "off",
  },
  "overrides": [
    {
      // enable the rule specifically for TypeScript files
      "files": ["*.ts", "*.mts", "*.cts", "*.tsx"],
      "rules": {
        "@typescript-eslint/explicit-function-return-type": "error",
      },
    },
  ],
}

cf. https://typescript-eslint.io/rules/explicit-function-return-type/#configuring-in-a-mixed-jsts-codebase

Or should eslint-config-love be configured on the user side to apply only to TS files?

@mightyiam
Copy link
Owner

Ideally, rules that only apply to TS wouldn't be run for JS. Isn't that the case?

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

No branches or pull requests

2 participants