meteor/meteor

View on GitHub
tools/fs/watch.ts

Summary

Maintainability
F
4 days
Test Coverage

File watch.ts has 590 lines of code (exceeds 250 allowed). Consider refactoring.
Open

import { Stats, BigIntStats, FSWatcher, Dirent } from "fs";
import * as files from "./files";
import * as safeWatcher from "./safe-watcher";
import { createHash } from "crypto";
import { coalesce } from "../utils/func-utils";
Severity: Major
Found in tools/fs/watch.ts - About 1 day to fix

    Function updateStatForWatch has a Cognitive Complexity of 29 (exceeds 5 allowed). Consider refactoring.
    Open

      private updateStatForWatch(absPath: string) {
        const entry = this.watches[absPath];
        const lastStat = entry.lastStat;
        let stat = files.statOrNull(absPath);
        const mustNotExist = this.mustNotExist(absPath);
    Severity: Minor
    Found in tools/fs/watch.ts - About 4 hrs 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 processBatches has a Cognitive Complexity of 14 (exceeds 5 allowed). Consider refactoring.
    Open

      private processBatches<T>(
        array: T[],
        handleItem: (item: T) => any,
      ) {
        let index = 0;
    Severity: Minor
    Found in tools/fs/watch.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 watchFileOrDirectory has a Cognitive Complexity of 14 (exceeds 5 allowed). Consider refactoring.
    Open

      private watchFileOrDirectory(absPath: string, skipCheck = false) {
        if (! _.has(this.watches, absPath)) {
          this.watches[absPath] = {
            watcher: null,
            // Initially undefined (instead of null) to indicate we have never
    Severity: Minor
    Found in tools/fs/watch.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 updateStatForWatch has 38 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

      private updateStatForWatch(absPath: string) {
        const entry = this.watches[absPath];
        const lastStat = entry.lastStat;
        let stat = files.statOrNull(absPath);
        const mustNotExist = this.mustNotExist(absPath);
    Severity: Minor
    Found in tools/fs/watch.ts - About 1 hr to fix

      Function toJSON has 37 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

        toJSON() {
          if (this.alwaysFire) {
            return { alwaysFire: true };
          }
      
      
      Severity: Minor
      Found in tools/fs/watch.ts - About 1 hr to fix

        Function makeWatchEventCallback has 35 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

          private makeWatchEventCallback(absPath: string) {
            // Sometimes we receive a rapid succession of change events, perhaps
            // because several files were modified at once (e.g. by git reset
            // --hard), or a file was deleted and then recreated by an editor like
            // Vim. Because detecting changes can be costly, and because we care
        Severity: Minor
        Found in tools/fs/watch.ts - About 1 hr to fix

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

            private watchFileOrDirectory(absPath: string, skipCheck = false) {
              if (! _.has(this.watches, absPath)) {
                this.watches[absPath] = {
                  watcher: null,
                  // Initially undefined (instead of null) to indicate we have never
          Severity: Minor
          Found in tools/fs/watch.ts - About 1 hr to fix

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

              static fromJSON(json: any) {
                const watchSet = new WatchSet();
            
                if (! json) {
                  return watchSet;
            Severity: Minor
            Found in tools/fs/watch.ts - About 1 hr to fix

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

                private fireIfFileChanged(absPath: string) {
                  if (this.stopped) {
                    return true;
                  }
              
              
              Severity: Minor
              Found in tools/fs/watch.ts - About 1 hr to fix

                Function fireIfFileChanged has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
                Open

                  private fireIfFileChanged(absPath: string) {
                    if (this.stopped) {
                      return true;
                    }
                
                
                Severity: Minor
                Found in tools/fs/watch.ts - About 55 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

                Function toJSON has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
                Open

                  toJSON() {
                    if (this.alwaysFire) {
                      return { alwaysFire: true };
                    }
                
                
                Severity: Minor
                Found in tools/fs/watch.ts - About 55 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

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

                export function readAndWatchFileWithHash(watchSet: WatchSet, absPath: string) {
                  const result: {
                    contents: string | Buffer | null;
                    hash: string | null;
                  } = {
                Severity: Minor
                Found in tools/fs/watch.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

                Avoid too many return statements within this function.
                Open

                      return true;
                Severity: Major
                Found in tools/fs/watch.ts - About 30 mins to fix

                  Avoid too many return statements within this function.
                  Open

                      return true;
                  Severity: Major
                  Found in tools/fs/watch.ts - About 30 mins to fix

                    Avoid too many return statements within this function.
                    Open

                          return false;
                    Severity: Major
                    Found in tools/fs/watch.ts - About 30 mins to fix

                      Similar blocks of code found in 2 locations. Consider refactoring.
                      Open

                      export const sha1 = Profile("sha1", function (...args: (string | Buffer)[]) {
                        const hash = createHash('sha1');
                        args.forEach(arg => hash.update(arg));
                        return hash.digest('hex');
                      });
                      Severity: Major
                      Found in tools/fs/watch.ts and 1 other location - About 2 hrs to fix
                      tools/fs/watch.ts on lines 333..337

                      Duplicated Code

                      Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

                      Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

                      When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

                      Tuning

                      This issue has a mass of 81.

                      We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

                      The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

                      If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

                      See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

                      Refactorings

                      Further Reading

                      Similar blocks of code found in 2 locations. Consider refactoring.
                      Open

                      export const sha512 = Profile("sha512", function (...args: (string | Buffer)[]) {
                        const hash = createHash('sha512');
                        args.forEach(arg => hash.update(arg));
                        return hash.digest('base64');
                      });
                      Severity: Major
                      Found in tools/fs/watch.ts and 1 other location - About 2 hrs to fix
                      tools/fs/watch.ts on lines 327..331

                      Duplicated Code

                      Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

                      Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

                      When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

                      Tuning

                      This issue has a mass of 81.

                      We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

                      The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

                      If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

                      See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

                      Refactorings

                      Further Reading

                      Similar blocks of code found in 2 locations. Consider refactoring.
                      Open

                            directories: this.directories.map(d => ({
                              absPath: d.absPath,
                              include: d.include.map(reToJSON),
                              exclude: d.exclude.map(reToJSON),
                              names: d.names,
                      Severity: Major
                      Found in tools/fs/watch.ts and 1 other location - About 1 hr to fix
                      tools/fs/watch.ts on lines 301..307

                      Duplicated Code

                      Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

                      Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

                      When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

                      Tuning

                      This issue has a mass of 63.

                      We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

                      The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

                      If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

                      See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

                      Refactorings

                      Further Reading

                      Similar blocks of code found in 2 locations. Consider refactoring.
                      Open

                            watchSet.directories.push({
                              absPath: d.absPath,
                              include: d.include.map(reFromJSON),
                              exclude: d.exclude.map(reFromJSON),
                              names: d.names,
                      Severity: Major
                      Found in tools/fs/watch.ts and 1 other location - About 1 hr to fix
                      tools/fs/watch.ts on lines 261..267

                      Duplicated Code

                      Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

                      Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

                      When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

                      Tuning

                      This issue has a mass of 63.

                      We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

                      The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

                      If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

                      See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

                      Refactorings

                      Further Reading

                      Similar blocks of code found in 2 locations. Consider refactoring.
                      Open

                          } else if (stat && stat.isDirectory()) {
                            entry.lastStat = stat;
                            if (! lastStat || ! lastStat.isDirectory()) {
                              this.fire();
                            }
                      Severity: Minor
                      Found in tools/fs/watch.ts and 1 other location - About 35 mins to fix
                      tools/fs/watch.ts on lines 707..724

                      Duplicated Code

                      Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

                      Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

                      When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

                      Tuning

                      This issue has a mass of 47.

                      We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

                      The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

                      If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

                      See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

                      Refactorings

                      Further Reading

                      Similar blocks of code found in 2 locations. Consider refactoring.
                      Open

                          } else if (stat && stat.isFile()) {
                            entry.lastStat = stat;
                            if (! lastStat || ! lastStat.isFile()) {
                              this.fire();
                            }
                      Severity: Minor
                      Found in tools/fs/watch.ts and 1 other location - About 35 mins to fix
                      tools/fs/watch.ts on lines 713..724

                      Duplicated Code

                      Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

                      Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

                      When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

                      Tuning

                      This issue has a mass of 47.

                      We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

                      The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

                      If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

                      See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

                      Refactorings

                      Further Reading

                      There are no issues that match your filters.

                      Category
                      Status