typescript:S7739 flags a `then` property whose value is a number

  • Language: TypeScript
  • Rule: typescript:S7739 “Do not add then to an object”
  • Product: SonarQube Cloud
  • Why it is a false positive: Promise resolution only treats an object as thenable when its then property is callable. A numeric value is never invoked. The issue is raised as a Bug with High reliability impact, which fails the default quality gate. In this project the keys mirror gherkin-lint indentation option names, so then cannot be renamed.

Reproducer:

export const INDENTATION_DEFAULTS = { Feature: 0, given: 2, when: 2, then: 2 };

Expected: no issue. Actual: S7739 is raised on then.

Source: gherkin-refine/src/rules/legacy/helpers.ts at 49c5db79441c26c122d89f4875fb83a4a56dc61b · hamzahamidi/gherkin-refine · GitHub

Suggestion: only flag then when its value is a function or of unknown type.

Hi @hamzahamidi, welcome to the Community! :waving_hand:

Thank you for taking the time to share a clear example and explain why you need to keep the then key. You’re right: because its value is a number, JavaScript cannot call it as a thenable method. S7739 should not report it. I’m sorry this also affects your quality gate.

We created JS-2758 to track the false positive. Thank you for helping us improve the rule!

-Francois