Skip to content

[java] New Rule: VariableCanBeInlined: Local variables should not be declared and then immediately returned or thrown #5770

@Pankraz76

Description

@Pankraz76

VariableCanBeInlined

Proposed Category: codestyle

Description:

Inline variables when they are immediately used to return or throw.

Code Sample: This should include code, that should be flagged by the rule. If possible, the "correct" code
according to this new rule should also be demonstrated.

public long ComputeDurationInMilliseconds()
{
  long duration = (((hours * 60) + minutes) * 60 + seconds ) * 1000 ;
  return duration;
}

public void DoSomething()
{
  ApplicationException myException = new ApplicationException();
  throw myException;
}

Possible Properties:

  • Should this rule be customizable via properties?

Metadata

Metadata

Assignees

No one assigned

    Labels

    a:new-ruleProposal to add a new built-in rulean:enhancementAn improvement on existing features / rules

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions