zenflow/composite-service

View on GitHub

Showing 6 of 8 total issues

Function validateDependencyTree has a Cognitive Complexity of 14 (exceeds 5 allowed). Consider refactoring.
Open

function validateDependencyTree(services: { [id: string]: NormalizedServiceConfig }): void {
  const serviceIds = Object.keys(services);
  for (const [serviceId, { dependencies }] of Object.entries(services)) {
    for (const dependency of dependencies) {
      if (!serviceIds.includes(dependency)) {
Severity: Minor
Found in src/validateAndNormalizeConfig.ts - About 1 hr to fix

Cognitive Complexity

Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

A method's cognitive complexity is based on a few simple rules:

  • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
  • Code is considered more complex for each "break in the linear flow of the code"
  • Code is considered more complex when "flow breaking structures are nested"

Further reading

Function validateDependencyTree has 33 lines of code (exceeds 25 allowed). Consider refactoring.
Open

function validateDependencyTree(services: { [id: string]: NormalizedServiceConfig }): void {
  const serviceIds = Object.keys(services);
  for (const [serviceId, { dependencies }] of Object.entries(services)) {
    for (const dependency of dependencies) {
      if (!serviceIds.includes(dependency)) {
Severity: Minor
Found in src/validateAndNormalizeConfig.ts - About 1 hr to fix

    Function constructor has 32 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

      constructor(config: NormalizedCompositeServiceConfig) {
        this.config = config;
    
        if (this.config.windowsCtrlCShutdown) {
          require("generate-ctrl-c-event"); // make sure this module loads before we even start
    Severity: Minor
    Found in src/CompositeService.ts - About 1 hr to fix

      Function handleCrash has 30 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

        private async handleCrash(proc: ServiceProcess) {
          this.logger.log("info", `Service '${this.id}' crashed`);
          const delayPromise = delay(this.config.minimumRestartDelay);
          const crash: ServiceCrash = {
            date: new Date(),
      Severity: Minor
      Found in src/Service.ts - About 1 hr to fix

        Function constructor has 27 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

          constructor(
            serviceId: string,
            serviceConfig: NormalizedServiceConfig,
            logger: Logger,
            onCrash: () => void
        Severity: Minor
        Found in src/ServiceProcess.ts - About 1 hr to fix

          Function end has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
          Open

            public end(windowsCtrlCShutdown: boolean) {
              if (!this.wasEndCalled) {
                this.wasEndCalled = true;
                if (this.isRunning()) {
                  if (windowsCtrlCShutdown) {
          Severity: Minor
          Found in src/ServiceProcess.ts - About 45 mins to fix

          Cognitive Complexity

          Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

          A method's cognitive complexity is based on a few simple rules:

          • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
          • Code is considered more complex for each "break in the linear flow of the code"
          • Code is considered more complex when "flow breaking structures are nested"

          Further reading

          Severity
          Category
          Status
          Source
          Language