fbredius/storybook

View on GitHub
addons/docs/src/frameworks/vue/sourceDecorator.ts

Summary

Maintainability
C
1 day
Test Coverage

Function vnodeToString has a Cognitive Complexity of 15 (exceeds 5 allowed). Consider refactoring.
Open

export function vnodeToString(vnode: Vue.VNode): string {
  const attrString = [
    ...(vnode.data?.slot ? ([['slot', vnode.data.slot]] as [string, any][]) : []),
    ['class', stringifyClassAttribute(vnode)],
    ...(vnode.componentOptions?.propsData ? Object.entries(vnode.componentOptions.propsData) : []),
Severity: Minor
Found in addons/docs/src/frameworks/vue/sourceDecorator.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 sourceDecorator has 37 lines of code (exceeds 25 allowed). Consider refactoring.
Open

export const sourceDecorator = (storyFn: any, context: StoryContext<VueFramework>) => {
  const story = storyFn();

  // See ../react/jsxDecorator.tsx
  if (skipSourceRender(context)) {
Severity: Minor
Found in addons/docs/src/frameworks/vue/sourceDecorator.ts - About 1 hr to fix

    Function vnodeToString has 34 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

    export function vnodeToString(vnode: Vue.VNode): string {
      const attrString = [
        ...(vnode.data?.slot ? ([['slot', vnode.data.slot]] as [string, any][]) : []),
        ['class', stringifyClassAttribute(vnode)],
        ...(vnode.componentOptions?.propsData ? Object.entries(vnode.componentOptions.propsData) : []),
    Severity: Minor
    Found in addons/docs/src/frameworks/vue/sourceDecorator.ts - About 1 hr to fix

      Avoid too many return statements within this function.
      Open

          return `<${tag} ${attrString}/>`;
      Severity: Major
      Found in addons/docs/src/frameworks/vue/sourceDecorator.ts - About 30 mins to fix

        Avoid too many return statements within this function.
        Open

          return [];
        Severity: Major
        Found in addons/docs/src/frameworks/vue/sourceDecorator.ts - About 30 mins to fix

          Avoid too many return statements within this function.
          Open

              return '';
          Severity: Major
          Found in addons/docs/src/frameworks/vue/sourceDecorator.ts - About 30 mins to fix

            Avoid too many return statements within this function.
            Open

              return `<${tag} ${attrString}>${vnode.componentOptions.children
                .map(vnodeToString)
                .join('')}</${tag}>`;
            Severity: Major
            Found in addons/docs/src/frameworks/vue/sourceDecorator.ts - About 30 mins to fix

              Function sourceDecorator has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
              Open

              export const sourceDecorator = (storyFn: any, context: StoryContext<VueFramework>) => {
                const story = storyFn();
              
                // See ../react/jsxDecorator.tsx
                if (skipSourceRender(context)) {
              Severity: Minor
              Found in addons/docs/src/frameworks/vue/sourceDecorator.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

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

              export const skipSourceRender = (context: StoryContext<VueFramework>) => {
                const sourceParams = context?.parameters.docs?.source;
                const isArgsStory = context?.parameters.__isArgsStory;
              
                // always render if the user forces it
              Severity: Major
              Found in addons/docs/src/frameworks/vue/sourceDecorator.ts and 1 other location - About 4 hrs to fix
              addons/docs/src/frameworks/react/jsxDecorator.tsx on lines 147..159

              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 123.

              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

              Missing semicolon
              Open

              import type Vue from 'vue';

              Rule: semicolon

              Enforces consistent semicolon usage at the end of every statement.

              Notes
              • Has Fix

              Config

              One of the following arguments must be provided:

              • "always" enforces semicolons at the end of every statement.
              • "never" disallows semicolons at the end of every statement except for when they are necessary.

              The following arguments may be optionally provided:

              • "ignore-interfaces" skips checking semicolons at the end of interface members.
              • "ignore-bound-class-methods" skips checking semicolons at the end of bound class methods.
              • "strict-bound-class-methods" disables any special handling of bound class methods and treats them as any other assignment. This option overrides "ignore-bound-class-methods".
              Examples
              "semicolon": true,always
              "semicolon": true,never
              "semicolon": true,always,ignore-interfaces
              "semicolon": true,always,ignore-bound-class-methods
              Schema
              {
                "type": "array",
                "items": [
                  {
                    "type": "string",
                    "enum": [
                      "always",
                      "never"
                    ]
                  },
                  {
                    "type": "string",
                    "enum": [
                      "ignore-interfaces"
                    ]
                  }
                ],
                "additionalItems": false
              }

              For more information see this page.

              unused expression, expected an assignment or function call
              Open

              import type Vue from 'vue';

              Rule: no-unused-expression

              Disallows unused expression statements.

              Unused expressions are expression statements which are not assignments or function calls (and thus usually no-ops).

              Rationale

              Detects potential errors where an assignment or function call was intended.

              Config

              Three arguments may be optionally provided:

              • allow-fast-null-checks allows to use logical operators to perform fast null checks and perform method or function calls for side effects (e.g. e && e.preventDefault()).
              • allow-new allows 'new' expressions for side effects (e.g. new ModifyGlobalState();.
              • allow-tagged-template allows tagged templates for side effects (e.g. this.add\foo`;`.
              Examples
              "no-unused-expression": true
              "no-unused-expression": true,allow-fast-null-checks
              Schema
              {
                "type": "array",
                "items": {
                  "type": "string",
                  "enum": [
                    "allow-fast-null-checks",
                    "allow-new",
                    "allow-tagged-template"
                  ]
                },
                "minLength": 0,
                "maxLength": 3
              }

              For more information see this page.

              Missing semicolon
              Open

              import type Vue from 'vue';

              Rule: semicolon

              Enforces consistent semicolon usage at the end of every statement.

              Notes
              • Has Fix

              Config

              One of the following arguments must be provided:

              • "always" enforces semicolons at the end of every statement.
              • "never" disallows semicolons at the end of every statement except for when they are necessary.

              The following arguments may be optionally provided:

              • "ignore-interfaces" skips checking semicolons at the end of interface members.
              • "ignore-bound-class-methods" skips checking semicolons at the end of bound class methods.
              • "strict-bound-class-methods" disables any special handling of bound class methods and treats them as any other assignment. This option overrides "ignore-bound-class-methods".
              Examples
              "semicolon": true,always
              "semicolon": true,never
              "semicolon": true,always,ignore-interfaces
              "semicolon": true,always,ignore-bound-class-methods
              Schema
              {
                "type": "array",
                "items": [
                  {
                    "type": "string",
                    "enum": [
                      "always",
                      "never"
                    ]
                  },
                  {
                    "type": "string",
                    "enum": [
                      "ignore-interfaces"
                    ]
                  }
                ],
                "additionalItems": false
              }

              For more information see this page.

              unused expression, expected an assignment or function call
              Open

              import type Vue from 'vue';

              Rule: no-unused-expression

              Disallows unused expression statements.

              Unused expressions are expression statements which are not assignments or function calls (and thus usually no-ops).

              Rationale

              Detects potential errors where an assignment or function call was intended.

              Config

              Three arguments may be optionally provided:

              • allow-fast-null-checks allows to use logical operators to perform fast null checks and perform method or function calls for side effects (e.g. e && e.preventDefault()).
              • allow-new allows 'new' expressions for side effects (e.g. new ModifyGlobalState();.
              • allow-tagged-template allows tagged templates for side effects (e.g. this.add\foo`;`.
              Examples
              "no-unused-expression": true
              "no-unused-expression": true,allow-fast-null-checks
              Schema
              {
                "type": "array",
                "items": {
                  "type": "string",
                  "enum": [
                    "allow-fast-null-checks",
                    "allow-new",
                    "allow-tagged-template"
                  ]
                },
                "minLength": 0,
                "maxLength": 3
              }

              For more information see this page.

              There are no issues that match your filters.

              Category
              Status