UnlyEd/conditions-matcher

View on GitHub

Showing 3 of 12 total issues

Function checkContextMatchesConditions has a Cognitive Complexity of 27 (exceeds 8 allowed). Consider refactoring.
Open

const checkContextMatchesConditions = (filter: IFilter, context: object, options: object = defaultOptions) => {
  let returnValues: IReturnValuesType = {};
  let ignoredConditionsCollection: object[] = [];
  const formattedFilter: IFilter = formatFilter(Object.assign({}, filter));

Severity: Minor
Found in src/checkMatches.ts - About 3 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 formatFilter has a Cognitive Complexity of 15 (exceeds 8 allowed). Consider refactoring.
Open

export const formatFilter = (filter: IFilter) => {
  for (let [logicalOperator, conditions] of Object.entries(filter)) {
    if (logicalOperator in logicalOperators) {
      for (let i = 0; i < conditions.length; i++) {
        if (Object.keys(conditions[i]).length > 1) {
Severity: Minor
Found in src/checkMatches.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

Avoid deeply nested control flow statements.
Open

          for (let [rule, expected] of Object.entries(ruleObjectBackup)) {
            let newObj: IFilter = {};
            newObj[rule] = expected;
            filter[logicalOperator].push(newObj);
          }
Severity: Major
Found in src/checkMatches.ts - About 45 mins to fix
    Severity
    Category
    Status
    Source
    Language