Skip to content

linter: promise/prefer-await-to-callbacks false positive for WebSocket error event handler #12530

@KieranP

Description

@KieranP

What version of Oxlint are you using?

1.8.0

What command did you run?

oxlint src/**/*.{js,ts}

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

{
  "$schema": "./node_modules/oxlint/configuration_schema.json",
  "ignorePatterns": ["/node_modules", "/dist", "/*.{js,ts}"],
  "plugins": ["eslint", "oxc", "typescript", "import", "promise", "unicorn"],
  "categories": {
    "correctness": "error",
    "suspicious": "error",
    "perf": "error"
  },
  "rules": {
    "eslint/arrow-body-style": "error",
    "eslint/array-callback-return": "error",
    "eslint/block-scoped-var": "error",
    // "eslint/curly": "error",
    "eslint/default-case": "error",
    "eslint/default-case-last": "error",
    "eslint/default-param-last": "error",
    "eslint/eqeqeq": "error",
    "eslint/for-direction": "error",
    "eslint/func-names": "error",
    "eslint/func-style": ["error", "declaration"],
    "eslint/getter-return": "error",
    "eslint/grouped-accessor-pairs": "error",
    "eslint/guard-for-in": "error",
    // "eslint/id-length": "error",
    "eslint/init-declarations": "error",
    "eslint/max-classes-per-file": "error",
    "eslint/max-depth": "error",
    // "eslint/max-lines": "error",
    // "eslint/max-lines-per-function": "error",
    "eslint/max-nested-callbacks": "error",
    "eslint/max-params": "error",
    // "eslint/new-cap": "error",
    "eslint/no-alert": "error",
    "eslint/no-array-constructor": "error",
    "eslint/no-async-promise-executor": "error",
    "eslint/no-await-in-loop": "error",
    "eslint/no-bitwise": "error",
    "eslint/no-caller": "error",
    "eslint/no-case-declarations": "error",
    "eslint/no-class-assign": "error",
    "eslint/no-compare-neg-zero": "error",
    "eslint/no-cond-assign": "error",
    // "eslint/no-console": "error",
    "eslint/no-const-assign": "error",
    "eslint/no-constant-binary-expression": "error",
    "eslint/no-constant-condition": "error",
    "eslint/no-constructor-return": "error",
    "eslint/no-continue": "error",
    "eslint/no-control-regex": "error",
    "eslint/no-debugger": "error",
    "eslint/no-delete-var": "error",
    "eslint/no-div-regex": "error",
    "eslint/no-dupe-class-members": "error",
    "eslint/no-dupe-else-if": "error",
    "eslint/no-dupe-keys": "error",
    "eslint/no-duplicate-case": "error",
    "eslint/no-duplicate-imports": "error",
    "eslint/no-else-return": "error",
    "eslint/no-empty": "error",
    "eslint/no-empty-character-class": "error",
    "eslint/no-empty-function": "error",
    "eslint/no-empty-pattern": "error",
    "eslint/no-empty-static-block": "error",
    "eslint/no-eq-null": "error",
    "eslint/no-eval": "error",
    "eslint/no-ex-assign": "error",
    "eslint/no-extend-native": "error",
    "eslint/no-extra-bind": "error",
    "eslint/no-extra-boolean-cast": "error",
    "eslint/no-extra-label": "error",
    "eslint/no-fallthrough": "error",
    "eslint/no-func-assign": "error",
    "eslint/no-global-assign": "error",
    "eslint/no-import-assign": "error",
    "eslint/no-inner-declarations": "error",
    "eslint/no-invalid-regexp": "error",
    "eslint/no-irregular-whitespace": "error",
    "eslint/no-iterator": "error",
    "eslint/no-label-var": "error",
    "eslint/no-labels": "error",
    "eslint/no-lone-blocks": "error",
    "eslint/no-lonely-if": "error",
    "eslint/no-loss-of-precision": "error",
    // "eslint/no-magic-numbers": "error",
    "eslint/no-multi-assign": "error",
    "eslint/no-multi-str": "error",
    "eslint/no-negated-condition": "error",
    "eslint/no-nested-ternary": "error",
    "eslint/no-new": "error",
    "eslint/no-new-func": "error",
    "eslint/no-new-native-nonconstructor": "error",
    "eslint/no-new-wrappers": "error",
    "eslint/no-nonoctal-decimal-escape": "error",
    "eslint/no-obj-calls": "error",
    "eslint/no-object-constructor": "error",
    "eslint/no-plusplus": "error",
    "eslint/no-proto": "error",
    "eslint/no-prototype-builtins": "error",
    "eslint/no-redeclare": "error",
    "eslint/no-regex-spaces": "error",
    "eslint/no-restricted-globals": "error",
    "eslint/no-restricted-imports": "error",
    "eslint/no-return-assign": "error",
    "eslint/no-script-url": "error",
    "eslint/no-self-assign": "error",
    "eslint/no-self-compare": "error",
    "eslint/no-setter-return": "error",
    "eslint/no-shadow-restricted-names": "error",
    "eslint/no-sparse-arrays": "error",
    "eslint/no-template-curly-in-string": "error",
    // "eslint/no-ternary": "error",
    "eslint/no-this-before-super": "error",
    "eslint/no-throw-literal": "error",
    "eslint/no-undef": "error",
    // "eslint/no-undefined": "error",
    "eslint/no-unexpected-multiline": "error",
    "eslint/no-unneeded-ternary": "error",
    "eslint/no-unreachable": "error",
    "eslint/no-unsafe-finally": "error",
    "eslint/no-unsafe-negation": "error",
    "eslint/no-unsafe-optional-chaining": "error",
    "eslint/no-unused-expressions": "error",
    "eslint/no-unused-labels": "error",
    "eslint/no-unused-private-class-members": "error",
    "eslint/no-unused-vars": "error",
    "eslint/no-useless-backreference": "error",
    "eslint/no-useless-call": "error",
    "eslint/no-useless-catch": "error",
    "eslint/no-useless-concat": "error",
    "eslint/no-useless-constructor": "error",
    "eslint/no-useless-escape": "error",
    "eslint/no-useless-rename": "error",
    "eslint/no-var": "error",
    // "eslint/no-void": "error",
    "eslint/no-with": "error",
    "eslint/operator-assignment": "error",
    "eslint/prefer-exponentiation-operator": "error",
    "eslint/prefer-numeric-literals": "error",
    "eslint/prefer-object-has-own": "error",
    "eslint/prefer-object-spread": "error",
    "eslint/prefer-promise-reject-errors": "error",
    "eslint/prefer-rest-params": "error",
    "eslint/prefer-spread": "error",
    "eslint/radix": "error",
    "eslint/require-await": "error",
    "eslint/require-yield": "error",
    // "eslint/sort-imports": "error",
    "eslint/sort-keys": "error",
    "eslint/sort-vars": "error",
    "eslint/symbol-description": "error",
    "eslint/unicode-bom": "error",
    "eslint/use-isnan": "error",
    "eslint/valid-typeof": "error",
    "eslint/vars-on-top": "error",
    "eslint/yoda": "error",
    // "import/consistent-type-specifier-style": "error",
    "import/default": "error",
    "import/export": "error",
    "import/exports-last": "error",
    "import/extensions": "error",
    "import/first": "error",
    // "import/group-exports": "error",
    // "import/max-dependencies": "error",
    "import/named": "error",
    "import/namespace": "error",
    "import/no-absolute-path": "error",
    "import/no-amd": "error",
    "import/no-anonymous-default-export": "error",
    "import/no-commonjs": "error",
    "import/no-cycle": "error",
    // "import/no-default-export": "error",
    "import/no-duplicates": "error",
    "import/no-dynamic-require": "error",
    "import/no-empty-named-blocks": "error",
    "import/no-mutable-exports": "error",
    "import/no-named-as-default": "error",
    "import/no-named-as-default-member": "error",
    "import/no-named-default": "error",
    "import/no-namespace": "error",
    "import/no-self-import": "error",
    "import/no-unassigned-import": [
      "error",
      {
        "allow": [
          "*.css",
          "@babylonjs/core/Debug/debugLayer",
          "@babylonjs/inspector"
        ]
      }
    ],
    "import/no-webpack-loader-syntax": "error",
    "import/prefer-default-export": "error",
    // "import/unambiguous": "error",
    "oxc/approx-constant": "error",
    "oxc/bad-array-method-on-arguments": "error",
    "oxc/bad-bitwise-operator": "error",
    "oxc/bad-char-at-comparison": "error",
    "oxc/bad-comparison-sequence": "error",
    "oxc/bad-min-max-func": "error",
    "oxc/bad-object-literal-comparison": "error",
    "oxc/bad-replace-all-arg": "error",
    "oxc/const-comparisons": "error",
    "oxc/double-comparisons": "error",
    "oxc/erasing-op": "error",
    "oxc/misrefactored-assign-op": "error",
    "oxc/missing-throw": "error",
    "oxc/no-accumulating-spread": "error",
    // "oxc/no-async-await": "error",
    "oxc/no-async-endpoint-handlers": "error",
    "oxc/no-barrel-file": "error",
    "oxc/no-const-enum": "error",
    "oxc/no-map-spread": "error",
    // "oxc/no-optional-chaining": "error",
    // "oxc/no-rest-spread-properties": "error",
    "oxc/number-arg-out-of-range": "error",
    "oxc/only-used-in-recursion": "error",
    "oxc/uninvoked-array-callback": "error",
    "promise/avoid-new": "error",
    "promise/catch-or-return": "error",
    "promise/no-callback-in-promise": "error",
    "promise/no-nesting": "error",
    "promise/no-new-statics": "error",
    "promise/no-promise-in-callback": "error",
    "promise/no-return-in-finally": "error",
    "promise/no-return-wrap": "error",
    "promise/param-names": "error",
    "promise/prefer-await-to-callbacks": "error",
    "promise/prefer-await-to-then": "error",
    "promise/prefer-catch": "error",
    "promise/spec-only": "error",
    "promise/valid-params": "error",
    "typescript/adjacent-overload-signatures": "error",
    "typescript/array-type": ["error", { "default": "array-simple" }],
    "typescript/ban-ts-comment": "error",
    "typescript/ban-tslint-comment": "error",
    "typescript/ban-types": "error",
    "typescript/consistent-generic-constructors": "error",
    "typescript/consistent-indexed-object-style": "error",
    "typescript/consistent-type-definitions": "error",
    "typescript/consistent-type-imports": "error",
    "typescript/explicit-function-return-type": "error",
    "typescript/no-confusing-non-null-assertion": "error",
    "typescript/no-duplicate-enum-values": "error",
    "typescript/no-dynamic-delete": "error",
    "typescript/no-empty-interface": "error",
    "typescript/no-empty-object-type": "error",
    "typescript/no-explicit-any": "error",
    "typescript/no-extra-non-null-assertion": "error",
    "typescript/no-extraneous-class": "error",
    "typescript/no-import-type-side-effects": "error",
    "typescript/no-inferrable-types": "error",
    "typescript/no-misused-new": "error",
    "typescript/no-namespace": "error",
    "typescript/no-non-null-asserted-nullish-coalescing": "error",
    "typescript/no-non-null-asserted-optional-chain": "error",
    "typescript/no-non-null-assertion": "error",
    "typescript/no-require-imports": "error",
    "typescript/no-this-alias": "error",
    "typescript/no-unnecessary-parameter-property-assignment": "error",
    "typescript/no-unnecessary-type-constraint": "error",
    "typescript/no-unsafe-declaration-merging": "error",
    "typescript/no-unsafe-function-type": "error",
    "typescript/no-useless-empty-export": "error",
    "typescript/no-var-requires": "error",
    "typescript/no-wrapper-object-types": "error",
    "typescript/prefer-as-const": "error",
    "typescript/prefer-enum-initializers": "error",
    "typescript/prefer-for-of": "error",
    "typescript/prefer-function-type": "error",
    "typescript/prefer-literal-enum-member": "error",
    "typescript/prefer-namespace-keyword": "error",
    "typescript/prefer-ts-expect-error": "error",
    "typescript/triple-slash-reference": "error",
    "unicorn/catch-error-name": "error",
    "unicorn/consistent-assert": "error",
    "unicorn/consistent-date-clone": "error",
    "unicorn/consistent-empty-array-spread": "error",
    "unicorn/consistent-existence-index-check": "error",
    "unicorn/consistent-function-scoping": "error",
    "unicorn/empty-brace-spaces": "error",
    "unicorn/error-message": "error",
    "unicorn/escape-case": "error",
    "unicorn/explicit-length-check": "error",
    // "unicorn/filename-case": "error",
    "unicorn/new-for-builtins": "error",
    "unicorn/no-abusive-eslint-disable": "error",
    "unicorn/no-accessor-recursion": "error",
    "unicorn/no-anonymous-default-export": "error",
    "unicorn/no-array-for-each": "error",
    "unicorn/no-array-method-this-argument": "error",
    "unicorn/no-array-reduce": "error",
    "unicorn/no-await-expression-member": "error",
    "unicorn/no-await-in-promise-methods": "error",
    "unicorn/no-console-spaces": "error",
    "unicorn/no-document-cookie": "error",
    "unicorn/no-empty-file": "error",
    "unicorn/no-hex-escape": "error",
    "unicorn/no-instanceof-array": "error",
    "unicorn/no-instanceof-builtins": "error",
    "unicorn/no-invalid-fetch-options": "error",
    "unicorn/no-invalid-remove-event-listener": "error",
    "unicorn/no-length-as-slice-end": "error",
    "unicorn/no-lonely-if": "error",
    "unicorn/no-magic-array-flat-depth": "error",
    "unicorn/no-negation-in-equality-check": "error",
    "unicorn/no-nested-ternary": "error",
    "unicorn/no-new-array": "error",
    "unicorn/no-new-buffer": "error",
    // "unicorn/no-null": "error",
    "unicorn/no-object-as-default-parameter": "error",
    "unicorn/no-process-exit": "error",
    "unicorn/no-single-promise-in-promise-methods": "error",
    "unicorn/no-static-only-class": "error",
    "unicorn/no-thenable": "error",
    "unicorn/no-this-assignment": "error",
    "unicorn/no-typeof-undefined": "error",
    "unicorn/no-unnecessary-array-flat-depth": "error",
    "unicorn/no-unnecessary-await": "error",
    "unicorn/no-unnecessary-slice-end": "error",
    "unicorn/no-unreadable-array-destructuring": "error",
    "unicorn/no-unreadable-iife": "error",
    "unicorn/no-useless-fallback-in-spread": "error",
    "unicorn/no-useless-length-check": "error",
    "unicorn/no-useless-promise-resolve-reject": "error",
    "unicorn/no-useless-spread": "error",
    "unicorn/no-useless-switch-case": "error",
    "unicorn/no-useless-undefined": "error",
    "unicorn/no-zero-fractions": "error",
    "unicorn/number-literal-case": "error",
    "unicorn/numeric-separators-style": "error",
    "unicorn/prefer-add-event-listener": "error",
    "unicorn/prefer-array-find": "error",
    "unicorn/prefer-array-flat": "error",
    "unicorn/prefer-array-flat-map": "error",
    "unicorn/prefer-array-index-of": "error",
    "unicorn/prefer-array-some": "error",
    "unicorn/prefer-blob-reading-methods": "error",
    "unicorn/prefer-code-point": "error",
    "unicorn/prefer-date-now": "error",
    "unicorn/prefer-dom-node-append": "error",
    "unicorn/prefer-dom-node-dataset": "error",
    "unicorn/prefer-dom-node-remove": "error",
    "unicorn/prefer-dom-node-text-content": "error",
    "unicorn/prefer-event-target": "error",
    // "unicorn/prefer-global-this": "error",
    "unicorn/prefer-includes": "error",
    "unicorn/prefer-logical-operator-over-ternary": "error",
    "unicorn/prefer-math-min-max": "error",
    "unicorn/prefer-math-trunc": "error",
    "unicorn/prefer-modern-dom-apis": "error",
    "unicorn/prefer-modern-math-apis": "error",
    "unicorn/prefer-native-coercion-functions": "error",
    "unicorn/prefer-negative-index": "error",
    "unicorn/prefer-node-protocol": "error",
    "unicorn/prefer-number-properties": "error",
    "unicorn/prefer-object-from-entries": "error",
    "unicorn/prefer-optional-catch-binding": "error",
    "unicorn/prefer-prototype-methods": "error",
    "unicorn/prefer-query-selector": "error",
    "unicorn/prefer-reflect-apply": "error",
    "unicorn/prefer-regexp-test": "error",
    "unicorn/prefer-set-has": "error",
    "unicorn/prefer-set-size": "error",
    "unicorn/prefer-spread": "error",
    "unicorn/prefer-string-raw": "error",
    "unicorn/prefer-string-replace-all": "error",
    "unicorn/prefer-string-slice": "error",
    "unicorn/prefer-string-starts-ends-with": "error",
    "unicorn/prefer-string-trim-start-end": "error",
    "unicorn/prefer-structured-clone": "error",
    "unicorn/prefer-type-error": "error",
    "unicorn/require-array-join-separator": "error",
    "unicorn/require-number-to-fixed-digits-argument": "error",
    "unicorn/require-post-message-target-origin": "error",
    "unicorn/switch-case-braces": "error",
    "unicorn/text-encoding-identifier-case": "error",
    "unicorn/throw-new-error": "error"
  },
  "env": {
    "builtin": true,
    "browser": true
  }
}

What happened?

socket = new WebSocket(`SNIPPED`)

socket.addEventListener('message', (event) => {
  // snipped
})

socket.addEventListener('close', (event) => {
  // snipped
})

socket.addEventListener('error', (error) => {
  // snipped
})

That last addEventListener for error is triggering promise/prefer-await-to-callbacks but this is not a async/await situation.

I can bypass this linter by changing the variable to anything other then error or err.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions