fbredius/storybook

View on GitHub
addons/docs/src/frameworks/svelte/extractArgTypes.ts

Summary

Maintainability
A
2 hrs
Test Coverage

Function createArgTypes has 44 lines of code (exceeds 25 allowed). Consider refactoring.
Open

export const createArgTypes = (docgen: SvelteComponentDoc) => {
  const results: StrictArgTypes = {};
  docgen.data.forEach((item) => {
    results[item.name] = {
      control: parseTypeToControl(item.type),
Severity: Minor
Found in addons/docs/src/frameworks/svelte/extractArgTypes.ts - About 1 hr to fix

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

    const parseTypeToControl = (type: JSDocType): any => {
      if (!type) {
        return null;
      }
    
    
    Severity: Minor
    Found in addons/docs/src/frameworks/svelte/extractArgTypes.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

    Missing semicolon
    Open

    } from 'sveltedoc-parser/typings';

    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

    } from 'sveltedoc-parser/typings';

    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 {

    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.

    Shadowed name: 'type'
    Open

    const parseTypeToControl = (type: JSDocType): any => {

    Rule: no-shadowed-variable

    Disallows shadowing variable declarations.

    Rationale

    When a variable in a local scope and a variable in the containing scope have the same name, shadowing occurs. Shadowing makes it impossible to access the variable in the containing scope and obscures to what value an identifier actually refers. Compare the following snippets:

    const a = 'no shadow';
    function print() {
        console.log(a);
    }
    print(); // logs 'no shadow'.
    const a = 'no shadow';
    function print() {
        const a = 'shadow'; // TSLint will complain here.
        console.log(a);
    }
    print(); // logs 'shadow'.

    ESLint has an equivalent rule. For more background information, refer to this MDN closure doc.

    Config

    You can optionally pass an object to disable checking for certain kinds of declarations. Possible keys are "class", "enum", "function", "import", "interface", "namespace", "typeAlias" and "typeParameter". You can also pass "underscore" to ignore variable names that begin with _. Just set the value to false for the check you want to disable. All checks default to true, i.e. are enabled by default. Note that you cannot disable variables and parameters.

    The option "temporalDeadZone" defaults to true which shows errors when shadowing block scoped declarations in their temporal dead zone. When set to false parameters, classes, enums and variables declared with let or const are not considered shadowed if the shadowing occurs within their temporal dead zone.

    The following example shows how the "temporalDeadZone" option changes the linting result:

    function fn(value) {
        if (value) {
            const tmp = value; // no error on this line if "temporalDeadZone" is false
            return tmp;
        }
        let tmp = undefined;
        if (!value) {
            const tmp = value; // this line always contains an error
            return tmp;
        }
    }
    Examples
    "no-shadowed-variable": true
    "no-shadowed-variable": true,[object Object]
    Schema
    {
      "type": "object",
      "properties": {
        "class": {
          "type": "boolean"
        },
        "enum": {
          "type": "boolean"
        },
        "function": {
          "type": "boolean"
        },
        "import": {
          "type": "boolean"
        },
        "interface": {
          "type": "boolean"
        },
        "namespace": {
          "type": "boolean"
        },
        "typeAlias": {
          "type": "boolean"
        },
        "typeParameter": {
          "type": "boolean"
        },
        "temporalDeadZone": {
          "type": "boolean"
        },
        "underscore": {
          "type": "boolean"
        }
      }
    }

    For more information see this page.

    missing whitespace
    Open

      JSDocTypeConst,
    } from 'sveltedoc-parser/typings';

    Rule: whitespace

    Enforces whitespace style conventions.

    Rationale

    Helps maintain a readable, consistent style in your codebase.

    Notes
    • Has Fix

    Config

    Several arguments may be optionally provided:

    • "check-branch" checks branching statements (if/else/for/while) are followed by whitespace.
    • "check-decl"checks that variable declarations have whitespace around the equals token.
    • "check-operator" checks for whitespace around operator tokens.
    • "check-module" checks for whitespace in import & export statements.
    • "check-separator" checks for whitespace after separator tokens (,/;).
    • "check-rest-spread" checks that there is no whitespace after rest/spread operator (...).
    • "check-type" checks for whitespace before a variable type specification.
    • "check-typecast" checks for whitespace between a typecast and its target.
    • "check-type-operator" checks for whitespace between type operators | and &.
    • "check-preblock" checks for whitespace before the opening brace of a block.
    • "check-postbrace" checks for whitespace after an opening brace.
    Examples
    "whitespace": true,check-branch,check-operator,check-typecast
    Schema
    {
      "type": "array",
      "items": {
        "type": "string",
        "enum": [
          "check-branch",
          "check-decl",
          "check-operator",
          "check-module",
          "check-separator",
          "check-rest-spread",
          "check-type",
          "check-typecast",
          "check-type-operator",
          "check-preblock",
          "check-postbrace"
        ]
      },
      "minLength": 0,
      "maxLength": 11
    }

    For more information see this page.

    Do not use comma operator here because it can be easily misunderstood or lead to unintended bugs.
    Open

      SvelteComponentDoc,
      JSDocType,
      JSDocKeyword,
      JSDocTypeConst,

    Rule: ban-comma-operator

    Disallows the comma operator to be used.

    Read more about the comma operator here.

    Rationale

    Using the comma operator can create a potential for many non-obvious bugs or lead to misunderstanding of code.

    Examples

    foo((bar, baz)); // evaluates to 'foo(baz)' because of the extra parens - confusing and not obvious
    switch (foo) {
        case 1, 2: // equals 'case 2' - probably intended 'case 1: case2:'
            return true;
        case 3:
            return false;
    }
    let x = (y = 1, z = 2); // x is equal to 2 - this may not be immediately obvious.
    Examples
    "ban-comma-operator": true

    For more information see this page.

    Missing semicolon
    Open

      JSDocTypeConst,

    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.

    Do not use comma operator here because it can be easily misunderstood or lead to unintended bugs.
    Open

      SvelteComponentDoc,
      JSDocType,
      JSDocKeyword,
      JSDocTypeConst,

    Rule: ban-comma-operator

    Disallows the comma operator to be used.

    Read more about the comma operator here.

    Rationale

    Using the comma operator can create a potential for many non-obvious bugs or lead to misunderstanding of code.

    Examples

    foo((bar, baz)); // evaluates to 'foo(baz)' because of the extra parens - confusing and not obvious
    switch (foo) {
        case 1, 2: // equals 'case 2' - probably intended 'case 1: case2:'
            return true;
        case 3:
            return false;
    }
    let x = (y = 1, z = 2); // x is equal to 2 - this may not be immediately obvious.
    Examples
    "ban-comma-operator": true

    For more information see this page.

    unused expression, expected an assignment or function call
    Open

      SvelteComponentDoc,
      JSDocType,
      JSDocKeyword,
      JSDocTypeConst,

    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.

    statements are not aligned
    Open

    } from 'sveltedoc-parser/typings';

    Rule: align

    Enforces vertical alignment.

    Rationale

    Helps maintain a readable, consistent style in your codebase.

    Consistent alignment for code statements helps keep code readable and clear. Statements misaligned from the standard can be harder to read and understand.

    Notes
    • Has Fix

    Config

    Five arguments may be optionally provided:

    • "parameters" checks alignment of function parameters.
    • "arguments" checks alignment of function call arguments.
    • "statements" checks alignment of statements.
    • "members" checks alignment of members of classes, interfaces, type literal, object literals and object destructuring.
    • "elements" checks alignment of elements of array literals, array destructuring and tuple types.
    Examples
    "align": true,parameters,statements
    Schema
    {
      "type": "array",
      "items": {
        "type": "string",
        "enum": [
          "arguments",
          "elements",
          "members",
          "parameters",
          "statements"
        ]
      },
      "minLength": 1,
      "maxLength": 5
    }

    For more information see this page.

    Do not use comma operator here because it can be easily misunderstood or lead to unintended bugs.
    Open

      SvelteComponentDoc,
      JSDocType,

    Rule: ban-comma-operator

    Disallows the comma operator to be used.

    Read more about the comma operator here.

    Rationale

    Using the comma operator can create a potential for many non-obvious bugs or lead to misunderstanding of code.

    Examples

    foo((bar, baz)); // evaluates to 'foo(baz)' because of the extra parens - confusing and not obvious
    switch (foo) {
        case 1, 2: // equals 'case 2' - probably intended 'case 1: case2:'
            return true;
        case 3:
            return false;
    }
    let x = (y = 1, z = 2); // x is equal to 2 - this may not be immediately obvious.
    Examples
    "ban-comma-operator": true

    For more information see this page.

    unused expression, expected an assignment or function call
    Open

    } from 'sveltedoc-parser/typings';

    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.

    Do not use comma operator here because it can be easily misunderstood or lead to unintended bugs.
    Open

      SvelteComponentDoc,
      JSDocType,
      JSDocKeyword,

    Rule: ban-comma-operator

    Disallows the comma operator to be used.

    Read more about the comma operator here.

    Rationale

    Using the comma operator can create a potential for many non-obvious bugs or lead to misunderstanding of code.

    Examples

    foo((bar, baz)); // evaluates to 'foo(baz)' because of the extra parens - confusing and not obvious
    switch (foo) {
        case 1, 2: // equals 'case 2' - probably intended 'case 1: case2:'
            return true;
        case 3:
            return false;
    }
    let x = (y = 1, z = 2); // x is equal to 2 - this may not be immediately obvious.
    Examples
    "ban-comma-operator": true

    For more information see this page.

    There are no issues that match your filters.

    Category
    Status