# S7757: Rule does not report static assignments in mixed constructors and ignores empty array initial

**URL:** <https://community.sonarsource.com/t/s7757-rule-does-not-report-static-assignments-in-mixed-constructors-and-ignores-empty-array-initial/189250>\
**Category:** Report False-positive / False-negative...\
**Tags:** typescript, sonarqube\
**Created:** [October 5, 2026, 10:41am UTC](https://community.sonarsource.com/t/s7757-rule-does-not-report-static-assignments-in-mixed-constructors-and-ignores-empty-array-initial/189250 "2026-10-05T10:41:53Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Nilesh\_Lad](https://dub1.discourse-cdn.com/sonarsource/user_avatar/community.sonarsource.com/nilesh_lad/32/77725_2.png) [@Nilesh\_Lad](https://community.sonarsource.com/u/Nilesh_Lad)\
**Post date:** [October 5, 2026, 10:41am UTC](https://community.sonarsource.com/t/s7757-rule-does-not-report-static-assignments-in-mixed-constructors-and-ignores-empty-array-initial/189250/1 "2026-10-05T10:41:53Z")

</div>

Hi Sonar team,

I am using SonarQube version 4.45.0 and observed the following behavior.

typescript:S7757 | (TypeScript) Class properties should be declared as fields rather than assigned in constructors

**Case 1: Mixed constructor assignments**

While testing this rule, I noticed that Sonar initially reports only the first eligible static assignment in the constructor. After resolving that issue, Sonar reports the next eligible assignment on a subsequent scan.

```auto
export class SampleModel {
  public id: string;
  public name: string;
  public count: number;

 constructor() {
     this.name = ""
     this.id = generateUniqueId();
     this.count = 0;
  }
}

```

Initially Sonar reports `this.name = ""`. After fixing it and re-running the analysis, Sonar should report `this.count = 0`.

However, if a non-static assignment such as `this.id = generateUniqueId()` or an empty array initialization such as `this.items = []` exists in the constructor, Sonar does not report issues for eligible assignments that appear later in the constructor.

However, if the runtime assignment is removed:

```auto
export class SampleModel {
   public count: number;

  constructor() {
      this.count = 0;
  }
}

```

the rule reports:

“Prefer class field declaration over `this` assignment in constructor for static values.”

It appears that the presence of a non-static assignment prevents the rule from reporting other eligible static assignments in the same constructor.

Is this intentional, or should `this.count = 0` still be detected and reported?

**Case 2: Empty array initialization**

The following code is also not reported:

```auto
export class SampleModel {
  public items: ItemModel[];
  public results: ResultModel[];

  constructor() {
    this.items = [];
    this.results = [];
  }
}

```

Is excluding empty array initializations an intentional design choice, or is this a limitation of the current implementation?

**Expected behavior**

I would expect either:

1. Eligible static assignments to be reported individually, even when mixed with non-static assignments in the same constructor, or
2. The rule documentation to clarify that it only triggers when the entire constructor can be replaced by field initializers.

Could you please clarify whether this behavior is expected?

Thanks.

---

<div class="post-metadata">

**Author:** ![andres](https://dub1.discourse-cdn.com/sonarsource/user_avatar/community.sonarsource.com/andres/32/76342_2.png) [@andres](https://community.sonarsource.com/u/andres)\
**Post date:** [October 8, 2026, 8:50am UTC](https://community.sonarsource.com/t/s7757-rule-does-not-report-static-assignments-in-mixed-constructors-and-ignores-empty-array-initial/189250/2 "2026-10-08T08:50:25Z")

</div>

Hey @Nilesh_Lad, welcome to the Community! Before diving deeper into your report, could you clarify this?

> I am using SonarQube version 4.45.0

There’s no SonarQube version 4.45.0 (and if there was one, it would likely be incredibly old!) Could you clarify which product (SonarQube Server/SonarQube Community Edition/SonarQube for IDE/SonarQube Cloud…) are you using and which version if applicable?

---

<div class="post-metadata">

**Author:** ![Nilesh\_Lad](https://dub1.discourse-cdn.com/sonarsource/user_avatar/community.sonarsource.com/nilesh_lad/32/77725_2.png) [@Nilesh\_Lad](https://community.sonarsource.com/u/Nilesh_Lad)\
**Post date:** [October 8, 2026, 11:37am UTC](https://community.sonarsource.com/t/s7757-rule-does-not-report-static-assignments-in-mixed-constructors-and-ignores-empty-array-initial/189250/3 "2026-10-08T11:37:38Z")

</div>

Hi, I am currently using “SonarQube for IDE” VS code Extension.

 ![image](https://europe1.discourse-cdn.com/sonarsource/uploads/sonarcommunity/original/3X/1/d/1d5a16956d30a70cef4174a73a21a685dd724d1c.png)

---

<div class="post-metadata">

**Author:** ![andres](https://dub1.discourse-cdn.com/sonarsource/user_avatar/community.sonarsource.com/andres/32/76342_2.png) [@andres](https://community.sonarsource.com/u/andres)\
**Post date:** [October 8, 2026, 12:54pm UTC](https://community.sonarsource.com/t/s7757-rule-does-not-report-static-assignments-in-mixed-constructors-and-ignores-empty-array-initial/189250/4 "2026-10-08T12:54:48Z")

</div>

Hey @Nilesh_Lad, could you please try updating to the latest version and testing the rule again? Moreover, just one thing to clarify: are you using the IDE extension in connected mode (connected to a SonarQube Server instance or to SonarQube Cloud), or in standandalone mode (not connected)?

---

<div class="post-metadata">

**Author:** ![Nilesh\_Lad](https://dub1.discourse-cdn.com/sonarsource/user_avatar/community.sonarsource.com/nilesh_lad/32/77725_2.png) [@Nilesh\_Lad](https://community.sonarsource.com/u/Nilesh_Lad)\
**Post date:** [November 20, 2026, 6:58am UTC](https://community.sonarsource.com/t/s7757-rule-does-not-report-static-assignments-in-mixed-constructors-and-ignores-empty-array-initial/189250/5 "2026-11-20T06:58:56Z")

</div>

Hi, thanks for the suggestion. I’m currently using **SonarQube Community Build v25.11.0.114957 with the Standard Experience** , along with the **SonarQube for VS Code extension**. The VS Code extension is running in **standalone mode** and is not connected to a SonarQube Server or SonarQube Cloud instance.

I updated the extension to the latest available version and tested the rule again, but I’m still experiencing the same issue.

---

<div class="post-metadata">

**Author:** ![andres](https://dub1.discourse-cdn.com/sonarsource/user_avatar/community.sonarsource.com/andres/32/76342_2.png) [@andres](https://community.sonarsource.com/u/andres)\
**Post date:** [November 23, 2026, 1:20pm UTC](https://community.sonarsource.com/t/s7757-rule-does-not-report-static-assignments-in-mixed-constructors-and-ignores-empty-array-initial/189250/6 "2026-11-23T13:20:15Z")

</div>

Okay @Nilesh_Lad, thanks for clarifying. SonarQube Community Build 25.11 is quite old but if you’re using SonarQube for IDE in standalone mode, then it shouldn’t matter. I’m going to flag this for the team.

---

<div class="post-metadata">

**Author:** ![victor.diez](https://dub1.discourse-cdn.com/sonarsource/user_avatar/community.sonarsource.com/victor.diez/32/38525_2.png) [@victor.diez](https://community.sonarsource.com/u/victor.diez)\
**Post date:** [November 24, 2026, 10:02am UTC](https://community.sonarsource.com/t/s7757-rule-does-not-report-static-assignments-in-mixed-constructors-and-ignores-empty-array-initial/189250/9 "2026-11-24T10:02:03Z")

</div>

Hello @Nilesh_Lad,

I agree with both cases, I think we should report empty array literals and also we should not stop after the first finding.

I’ve opened [a SonarJS PR](https://github.com/SonarSource/SonarJS/pull/8471) to detect empty arrays and report all eligible assignments in one analysis. With this change, your first example reports both `this.name = ""` and `this.count = 0`. Your second example reports both empty-array assignments.

Some assignments will remain excluded when moving them to a field initializer could change behavior, for example when earlier constructor code reads the instance.

I also opened [an upstream issue](https://github.com/sindresorhus/eslint-plugin-unicorn/issues/4054), as this rule comes from ESLint Plugin Unicorn. The SonarJS fix is still under review.

Thanks!  
Victor
