JEStaubach/fs-helpers

View on GitHub

Showing 5 of 17 total issues

Function use has 204 lines of code (exceeds 25 allowed). Consider refactoring.
Open

function use(fsLibrary: any, seedFiles?: string[]): any { //NOSONAR
  const { existsSync, lstatSync, chmodSync, renameSync, readFileSync, copySync, removeSync, ensureFileSync, outputFileSync, mkdirpSync, seedFile } = fsLibrary;

  if (seedFile !== undefined && seedFiles !== undefined) {
    for (const file of seedFiles) {
Severity: Major
Found in src/index.ts - About 1 day to fix

    File fsHelpers.spec.ts has 475 lines of code (exceeds 250 allowed). Consider refactoring.
    Open

    import fsh from '../src/index';
    import path from 'path';
    import { beforeEach, afterEach, describe, it, expect, vi } from 'vitest';
    
    // create all test directories and files inside one root directory for easy cleanup
    Severity: Minor
    Found in __tests__/fsHelpers.spec.ts - About 7 hrs to fix

      Function use has a Cognitive Complexity of 33 (exceeds 5 allowed). Consider refactoring.
      Open

      function use(fsLibrary: any, seedFiles?: string[]): any { //NOSONAR
        const { existsSync, lstatSync, chmodSync, renameSync, readFileSync, copySync, removeSync, ensureFileSync, outputFileSync, mkdirpSync, seedFile } = fsLibrary;
      
        if (seedFile !== undefined && seedFiles !== undefined) {
          for (const file of seedFiles) {
      Severity: Minor
      Found in src/index.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 lstatSync has 34 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

      function lstatSync(filePath: fs.PathLike, _options?: fs.StatOptions & { bigint?: false }): fs.Stats {
        const [ type, _data ] = mockFileSystem.get(filePath as string) || ['',''];
        const retVal = {
          isDirectory: () => filePath === path.resolve(`.`) ? true : type === 'dir',
          isFile: () => mockFileSystem.has(filePath as string) && type === 'file',
      Severity: Minor
      Found in src/mock.ts - About 1 hr to fix

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

        function mkdirpSync(dir: string): any {
          if (lstatSync(dir).isFile()) throw Error('file exists at destination');
          let first = undefined;
          const dirs = dir.split(path.resolve(`.`)).join('').split(path.sep);
          for (let i = 0; i < dirs.length; i++){
        Severity: Minor
        Found in src/mock.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