mightyiam/eslint-config-love

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

munierujp opened this issue · 2 comments

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?

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