Skip to content

linter: false positive for explicit-module-boundary-types #20220

@alex3683

Description

@alex3683

What version of Oxlint are you using?

1.53.0

What command did you run?

npm exec oxlint -- -c=.oxlintrc.json

What does your .oxlintrc.json (or oxlint.config.ts) config file look like?

// Replace this with your actual config file contents.
// It can be helpful to keep it minimal, if possible, but please ensure that it actually reproduces the issue you're reporting.
{
  "$schema": "./node_modules/oxlint/configuration_schema.json",
  "plugins": ["import", "unicorn", "react", "typescript"],
  "categories": {
    "correctness": "warn",
    "pedantic": "allow", // "warn" would be nice, but currently gives about a 1000 warnings ...
    "restriction": "warn",
    "suspicious": "warn"
  },
  "env": {
    "browser": true,
    "builtin": true,
    "es2020": true
  },
  "ignorePatterns": [
    "**/build/**",
    "**/dist/**",
    "**/node_modules/**",
    "**/public/**",
    "**/temp/**",
    "**/vite.config.*",
    "eslint.config.mjs"
  ],
  "options": {
    "typeAware": true,
    "typeCheck": true
  },
  "settings": {
    "react": {
      "version": "17.0"
    }
  },
  "rules": {
    // no further configuration for explicit-module-boundary-types
  }
}

What happened?

The following code triggers two oxlint warnings:

export const widgetSettingsDeserializer = new JsonInterfaceDeserializer<WidgetSettings, SupportedWidget>(
  raw => raw.widgetSpecificationId as SupportedWidget
);

Specifically the lambda passed to the JsonInterfaceDeserializer constructor is reported as a problem twice:

    ╭─[some-file.ts:22:3]
 21 │ export const widgetSettingsDeserializer = new JsonInterfaceDeserializer<WidgetSettings, SupportedWidget>(
 22 │   raw => raw.widgetSpecificationId as SupportedWidget
    ·   ───
 23 │ );
    ╰────
  help: Define an explicit argument type for each argument.

  ⚠ typescript-eslint(explicit-module-boundary-types): Missing return type on function
    ╭─[some-file.ts:21:14]
 20 │
 21 │ export const widgetSettingsDeserializer = new JsonInterfaceDeserializer<WidgetSettings, SupportedWidget>(
    ·              ──────────────────────────
 22 │   raw => raw.widgetSpecificationId as SupportedWidget
    ╰────
  help: Define an explicit return type for the function.

This is a false positive since the inner arrow function is not part of the exported api, but just an argument to the exported fully typed class instance.

This can be proofed changing it to this code, which is technically exactly the same and doesn't trigger a linter warning:

const widgetSettingsDeserializerInternal = new JsonInterfaceDeserializer<WidgetSettings, SupportedWidget>(
  raw => raw.widgetSpecificationId as SupportedWidget
);
export const widgetSettingsDeserializer = widgetSettingsDeserializerInternal;

My guess is that the rule parser sees the untyped function argument as part of the full export statement and thus wrongly assumes this being part of the api.

Metadata

Metadata

Assignees

Labels

Type

Priority

None yet

Effort

None yet

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions