Rule S2301 (typescript:S2301) with object

  • JavaScript / TypeScript
  • typescript:S2301
  • We understand that the main idea of the rule and agree. For example, we should do something like this:
export function getFieldTitle ({ isField }: TestObject) {
    return isField ? getCoolValue() : getUndefined();
}

But we believe that when we use objects the rule is redundant. When working with objects, we do not have a problem with “developers calling the method won’t see the parameter name, only its value”, and it would be better to exclude this case from this rule.

  • Community Build v24.12.0.100206
  • Code example:
export function getFieldTitle ({ isField }: TestObject) {
    return isField ? TITLES.COOL_VALUE : undefined;
}

Hello Osmyslitelny,

Thank you for your feedback!

I didn’t manage to raise an issue using both samples that you provide. What change are you asking for?

In simple terms, for this rule:

  1. Do not catch cases when we use TestObject
  2. Catch cases when we use just bool value (current behave)

As I mentioned, the rule is not raising an issue for both coding examples that you mentionned in the latest version of the analyzer.
Is it raising an issue for you?