The rule https://sonar.etalytics.net/coding_rules?open=typescript%3AS2424&rule_key=typescript%3AS2424 checks that no local identifier shadow global ones.
In version 21, Angular introduced validation for signal forms that uses `valueOf` for conditional validation rules, see Validation • Angular and example below.
Now, at every place were we use this, sonar detects a violation of this rule, which technically is correct.
However, (as far as I understand) valueOf() is defined in Object.prototype.valueOf so it expects to be called upon an object. I can simply call valueOf() without a calling object specified, but then this is undefined and I get Uncaught TypeError: Cannot convert undefined or null to object.
In this case, I’d say it’s pretty unlikely that someone really would like to use valueOf() as global function call, so this could be excluded from this rule without causing harm.
I really would like to keep this rule enabled, and I would also prefer not to mark each of the validation rules manually as false positives.
@Component({
selector: 'app-root',
template: `
<input type="checkbox" [field]="valueForm.mayNotBeEmpty" />
<input type="text" [field]="valueForm.name" />
<br/>{{valueForm().valid()}}`,
changeDetection: ChangeDetectionStrategy.OnPush,
imports: [Field],
})
export class App {
protected readonly value = signal({ mayNotBeEmpty: true, name: '' });
protected readonly valueForm = form(this.value, (p) => {
required(p.name, { when: ({ valueOf }) => valueOf(p.mayNotBeEmpty) });
});
}
Many thanks for considering this! ![]()