stalniy/casl

View on GitHub

Showing 9 of 40 total issues

Function _indexAndAnalyzeRules has a Cognitive Complexity of 17 (exceeds 5 allowed). Consider refactoring.
Open

  private _indexAndAnalyzeRules(rawRules: RawRuleFrom<A, Conditions>[]) {
    const indexedRules: IndexTree<A, Conditions> = new Map();
    let typeOfSubjectType: string | undefined;

    for (let i = rawRules.length - 1; i >= 0; i--) {
Severity: Minor
Found in packages/casl-ability/src/RuleIndex.ts - About 2 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 rulesToQuery has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
Open

export function rulesToQuery<T extends AnyAbility, R = object>(
  ability: T,
  action: Parameters<T['rulesFor']>[0],
  subjectType: ExtractSubjectType<Parameters<T['rulesFor']>[1]>,
  convert: RuleToQueryConverter<T, R>
Severity: Minor
Found in packages/casl-ability/src/extra/rulesToQuery.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 run has 26 lines of code (exceeds 25 allowed). Consider refactoring.
Open

function run(name, args) {
  if (!name || !(name in COMMANDS)) {
    printHelp();
    return;
  }
Severity: Minor
Found in packages/dx/lib/dx.js - About 1 hr to fix

    Function _indexAndAnalyzeRules has 26 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

      private _indexAndAnalyzeRules(rawRules: RawRuleFrom<A, Conditions>[]) {
        const indexedRules: IndexTree<A, Conditions> = new Map();
        let typeOfSubjectType: string | undefined;
    
        for (let i = rawRules.length - 1; i >= 0; i--) {
    Severity: Minor
    Found in packages/casl-ability/src/RuleIndex.ts - About 1 hr to fix

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

      function validateForCycles(aliasMap: AliasesMap, reservedAction: string) {
        if (reservedAction in aliasMap) {
          throw new Error(`Cannot use "${reservedAction}" as an alias because it's reserved action.`);
        }
      
      
      Severity: Minor
      Found in packages/casl-ability/src/utils.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

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

        private _addRule(
          action: string | string[],
          subject?: SubjectType | SubjectType[],
          conditionsOrFields?: string | string[] | Generics<T>['conditions'],
          conditions?: Generics<T>['conditions'],
      Severity: Minor
      Found in packages/casl-ability/src/AbilityBuilder.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

      Function mergePrioritized has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
      Open

      export function mergePrioritized<T extends { priority: number }>(
        array?: T[],
        anotherArray?: T[]
      ): T[] {
        if (!array || !array.length) {
      Severity: Minor
      Found in packages/casl-ability/src/utils.ts - About 35 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 run has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
      Open

      function run(name, args) {
        if (!name || !(name in COMMANDS)) {
          printHelp();
          return;
        }
      Severity: Minor
      Found in packages/dx/lib/dx.js - About 35 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 permittedFieldsOf has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
      Open

      export function permittedFieldsOf<T extends AnyAbility>(
        ability: T,
        action: Parameters<T['can']>[0],
        subject: Parameters<T['can']>[1],
        options: PermittedFieldsOptions<T>
      Severity: Minor
      Found in packages/casl-ability/src/extra/permittedFieldsOf.ts - About 25 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