目录

@performance/hp-performance-no-dynamic-cls-func

Avoid dynamically declaring functions and classes. This rule applies only to JS and TS code.

You are advised to modify the code to comply with the ArkTS Performant Programming Practices.

Rule Configuration

// code-linter.json5
{
  "rules": {
    "@performance/hp-performance-no-dynamic-cls-func": "suggestion",
  }
}

Options

This rule is not configurable.

Example of Correct Code

function foo(f: boolean, a: number, b: number): number {
  if (f) {
    return add(a, b);
  } else {
    return sub(a, b);
  }
}
function add(c: number, d: number): number {
  return c + d;
}
function sub(e: number, g: number): number {
  return e - g;
}

Example of Incorrect Code

function foo(f: boolean, a: number, b: number): number {
  if (f) {
    function add(c: number, d: number): number {
      return c + d;
    }
    return add(a, b);
  } else {
    function sub(e: number, g: number): number {
      return e - g;
    }
    return sub(a, b);
  }
}

Rule Set

plugin:@performance/all

For details about how to configure Code Linter check rules, see Code Linter.