fbredius/storybook

View on GitHub
lib/csf-tools/src/ConfigFile.ts

Summary

Maintainability
D
2 days
Test Coverage

Function parse has a Cognitive Complexity of 18 (exceeds 5 allowed). Consider refactoring.
Open

  parse() {
    // eslint-disable-next-line @typescript-eslint/no-this-alias
    const self = this;
    traverse(this._ast, {
      ExportNamedDeclaration: {
Severity: Minor
Found in lib/csf-tools/src/ConfigFile.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 parse has 56 lines of code (exceeds 25 allowed). Consider refactoring.
Open

  parse() {
    // eslint-disable-next-line @typescript-eslint/no-this-alias
    const self = this;
    traverse(this._ast, {
      ExportNamedDeclaration: {
Severity: Major
Found in lib/csf-tools/src/ConfigFile.ts - About 2 hrs to fix

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

            enter({ node, parent }) {
              if (t.isAssignmentExpression(node.expression) && node.expression.operator === '=') {
                const { left, right } = node.expression;
                if (
                  t.isMemberExpression(left) &&
    Severity: Minor
    Found in lib/csf-tools/src/ConfigFile.ts - About 1 hr to fix

      Avoid deeply nested control flow statements.
      Open

                          if (t.isIdentifier(exportVal)) {
                            exportVal = _findVarInitialization(exportVal.name, parent as t.Program);
                          }
      Severity: Major
      Found in lib/csf-tools/src/ConfigFile.ts - About 45 mins to fix

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

        const _findVarInitialization = (identifier: string, program: t.Program) => {
          let init: t.Expression = null;
          let declarations: t.VariableDeclarator[] = null;
          program.body.find((node: t.Node) => {
            if (t.isVariableDeclaration(node)) {
        Severity: Major
        Found in lib/csf-tools/src/ConfigFile.ts and 1 other location - About 1 day to fix
        lib/csf-tools/src/CsfFile.ts on lines 40..66

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

        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 writeConfig = async (config: ConfigFile, fileName?: string) => {
          const fname = fileName || config.fileName;
          if (!fname) throw new Error('Please specify a fileName for writeConfig');
          await fs.writeFile(fname, await formatConfig(config));
        };
        Severity: Major
        Found in lib/csf-tools/src/ConfigFile.ts and 1 other location - About 2 hrs to fix
        lib/csf-tools/src/CsfFile.ts on lines 422..426

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

        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 formatConfig = (config: ConfigFile) => {
          const { code } = generate(config._ast, {});
          return code;
        };
        Severity: Minor
        Found in lib/csf-tools/src/ConfigFile.ts and 1 other location - About 40 mins to fix
        lib/csf-tools/src/CsfFile.ts on lines 412..415

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

        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

        Assigning this reference to local variable not allowed: self.
        Open

            const self = this;
        Severity: Minor
        Found in lib/csf-tools/src/ConfigFile.ts by tslint

        Rule: no-this-assignment

        Disallows unnecessary references to this.

        Rationale

        Assigning a variable to this instead of properly using arrow lambdas may be a symptom of pre-ES6 practices or not managing scope well.

        Instead of storing a reference to this and using it inside a function () {:

        const self = this;
        
        setTimeout(function () {
            self.doWork();
        });

        Use () => arrow lambdas, as they preserve this scope for you:

        setTimeout(() => {
            this.doWork();
        });

        Config

        Two options may be provided on an object:

        • allow-destructuring allows using destructuring to access members of this (e.g. { foo, bar } = this;).
        • allowed-names may be specified as a list of regular expressions to match allowed variable names.
        Examples
        "no-this-assignment": true
        "no-this-assignment": true,[object Object]
        Schema
        {
          "additionalProperties": false,
          "properties": {
            "allow-destructuring": {
              "type": "boolean"
            },
            "allowed-names": {
              "listType": "string",
              "type": "list"
            }
          },
          "type": "object"
        }

        For more information see this page.

        forbidden eval
        Open

              const value = eval(`(() => (${code}))()`);
        Severity: Minor
        Found in lib/csf-tools/src/ConfigFile.ts by tslint

        Rule: no-eval

        Disallows eval function invocations.

        Rationale

        eval() is dangerous as it allows arbitrary code execution with full privileges. There are alternatives for most of the use cases for eval().

        Config

        Not configurable.

        Examples
        "no-eval": true

        For more information see this page.

        There are no issues that match your filters.

        Category
        Status