Skip to content

linter: no-used-vars is tricked by comma #12592

@JakobJingleheimer

Description

@JakobJingleheimer

What version of Oxlint are you using?

1.9.0

What command did you run?

oxlint ./packages ./test

What does your .oxlintrc.json config file look like?

.oxlintrc.json
{
  "$schema": "./node_modules/oxlint/configuration_schema.json",
  "categories": {
    "correctness": "error",
    "suspicious": "warn"
  },
  "env": {
    "builtin": true
  },
  "globals": {
    "React": "writeable"
  },
  "ignorePatterns": [
    "node_modules",
    ".next",
    "build",
    "*.snap.cjs",
    "packages/app/src/@types/schema.d.ts"
  ],
  "rules": {
    "import/no-named-as-default": "off", // TODO: turn this back on
    "jsx-a11y/label-has-associated-control": "off",
    "no-console": "error",
    "no-unassigned-import": "warn",
    "no-unused-vars": [ "error", { "ignoreRestSiblings": true }],
    "react/no-unescaped-entities": "off",
    "react/react-in-jsx-scope": "off",
    "typescript/explicit-module-boundary-types": "off",
    "typescript/no-explicit-any": "off",
    "typescript/no-extraneous-class": "off",
    "typescript/no-non-null-assertion": "off",
    "typescript/no-var-requires": "off"
  },
  "plugins": [
    "import",
    "jsx-a11y",
    "react",
    "typescript"
  ]
}

What happened?

Obviously, nobody should do this because it's insane, but I just ran into it in a codebase, and it tricked oxlint into thinking onDismiss is unused.

const Foo = ({ onDismiss }) => {
  const { remove } = useToaster();

  return (
    <button
      onClick={() => (onDismiss?.(), remove())}
    >x</button>
  );
};

Specifically this is the miscreant: () => (onDismiss?.(), remove())

Oxlint detects onDismiss's use when that changed to () => { onDismiss?.(); remove() }

Metadata

Metadata

Assignees

Labels

Type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions