elcharitas/waxe

View on GitHub
src/compiler/parser.ts

Summary

Maintainability
A
1 hr
Test Coverage

Function parseString has 28 lines of code (exceeds 25 allowed). Consider refactoring.
Open

export function parseString(literal: WaxLiteral, argLiteral?: WaxLiteral, createScope?: boolean): string {
    const list: string[] = literal.split('');
    let inString: string = null;

    list.forEach((char: string, index: number, list: string[], nextChar: string = list[index + 1]) => {
Severity: Minor
Found in src/compiler/parser.ts - About 1 hr to fix

    Shadowed name: 'list'
    Open

        list.forEach((char: string, index: number, list: string[], nextChar: string = list[index + 1]) => {
    Severity: Minor
    Found in src/compiler/parser.ts by tslint

    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

        return new Function('call,tpl', 'return tpl['+strfy(name)+']=function(){return call(this,arguments)}')(
    Severity: Minor
    Found in src/compiler/parser.ts by tslint

    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.

    missing whitespace
    Open

        return createScope === true ? `new Function(${strfy('return '+list.join(''))}).apply(this,[${argLiteral ? argLiteral.text() : ''}]);`: list.join('');
    Severity: Minor
    Found in src/compiler/parser.ts by tslint

    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.

    Multiple variable declarations in the same statement are forbidden
    Open

        const { tag, argLiteral, configs } = tagOpts,
            node: WaxNode = walker.parser.getTag(tagOpts);
    Severity: Minor
    Found in src/compiler/parser.ts by tslint

    Rule: one-variable-per-declaration

    Disallows multiple variable definitions in the same declaration statement.

    Config

    One argument may be optionally provided:

    • ignore-for-loop allows multiple variable definitions in a for loop declaration.
    Examples
    "one-variable-per-declaration": true
    "one-variable-per-declaration": true,ignore-for-loop
    Schema
    {
      "type": "array",
      "items": {
        "type": "string",
        "enum": [
          "ignore-for-loop"
        ]
      },
      "minLength": 0,
      "maxLength": 1
    }

    For more information see this page.

    missing whitespace
    Open

        return new Function('call,tpl', 'return tpl['+strfy(name)+']=function(){return call(this,arguments)}')(
    Severity: Minor
    Found in src/compiler/parser.ts by tslint

    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.

    Throwing plain strings (not instances of Error) gives no stack traces
    Open

            throw 'Wax'+error;
    Severity: Minor
    Found in src/compiler/parser.ts by tslint

    Rule: no-string-throw

    Flags throwing plain strings or concatenations of strings.

    Rationale

    Example – Doing it right

    // throwing an Error from typical function, whether sync or async
    if (!productToAdd) {
        throw new Error("How can I add new product when no value provided?");
    }

    Example – Anti Pattern

    // throwing a string lacks any stack trace information and other important data properties
    if (!productToAdd) {
        throw ("How can I add new product when no value provided?");
    }

    Only Error objects contain a .stack member equivalent to the current stack trace. Primitives such as strings do not.

    Notes
    • Has Fix

    Config

    Not configurable.

    Examples
    "no-string-throw": true

    For more information see this page.

    missing whitespace
    Open

            throw 'Wax'+error;
    Severity: Minor
    Found in src/compiler/parser.ts by tslint

    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.

    != should be !==
    Open

            else if(!inString && char === '$' && nextChar != '[') {
    Severity: Minor
    Found in src/compiler/parser.ts by tslint

    Rule: triple-equals

    Requires === and !== in place of == and !=.

    Config

    Two arguments may be optionally provided:

    • "allow-null-check" allows == and != when comparing to null.
    • "allow-undefined-check" allows == and != when comparing to undefined.
    Examples
    "triple-equals": true
    "triple-equals": true,allow-null-check
    "triple-equals": true,allow-undefined-check
    Schema
    {
      "type": "array",
      "items": {
        "type": "string",
        "enum": [
          "allow-null-check",
          "allow-undefined-check"
        ]
      },
      "minLength": 0,
      "maxLength": 2
    }

    For more information see this page.

    missing whitespace
    Open

        return createScope === true ? `new Function(${strfy('return '+list.join(''))}).apply(this,[${argLiteral ? argLiteral.text() : ''}]);`: list.join('');
    Severity: Minor
    Found in src/compiler/parser.ts by tslint

    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.

    Throwing plain strings (not instances of Error) gives no stack traces
    Open

            throw `WaxNodeError: Unknown Tag "${tag}"`;
    Severity: Minor
    Found in src/compiler/parser.ts by tslint

    Rule: no-string-throw

    Flags throwing plain strings or concatenations of strings.

    Rationale

    Example – Doing it right

    // throwing an Error from typical function, whether sync or async
    if (!productToAdd) {
        throw new Error("How can I add new product when no value provided?");
    }

    Example – Anti Pattern

    // throwing a string lacks any stack trace information and other important data properties
    if (!productToAdd) {
        throw ("How can I add new product when no value provided?");
    }

    Only Error objects contain a .stack member equivalent to the current stack trace. Primitives such as strings do not.

    Notes
    • Has Fix

    Config

    Not configurable.

    Examples
    "no-string-throw": true

    For more information see this page.

    missing whitespace
    Open

        return new Function('call,tpl', 'return tpl['+strfy(name)+']=function(){return call(this,arguments)}')(
    Severity: Minor
    Found in src/compiler/parser.ts by tslint

    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 the Function constructor to create functions.
    Open

        return new Function('call,tpl', 'return tpl['+strfy(name)+']=function(){return call(this,arguments)}')(
    Severity: Minor
    Found in src/compiler/parser.ts by tslint

    Rule: function-constructor

    Prevents using the built-in Function constructor.

    Rationale

    Calling the constructor directly is similar to eval, which is a symptom of design issues. String inputs don't receive type checking and can cause performance issues, particularly when dynamically created.

    If you need to dynamically create functions, use "factory" functions that themselves return functions.

    Config

    Not configurable.

    Examples
    "function-constructor": true

    For more information see this page.

    missing whitespace
    Open

            throw 'Wax'+error;
    Severity: Minor
    Found in src/compiler/parser.ts by tslint

    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.

    Multiple variable declarations in the same statement are forbidden
    Open

        const { argList, blockSyntax, tagName, endPrefix } = delimiter,
            text: string = strfy(source),
            directives: RegExpMatchArray = text.match(new RegExp(blockSyntax, 'g'));
    Severity: Minor
    Found in src/compiler/parser.ts by tslint

    Rule: one-variable-per-declaration

    Disallows multiple variable definitions in the same declaration statement.

    Config

    One argument may be optionally provided:

    • ignore-for-loop allows multiple variable definitions in a for loop declaration.
    Examples
    "one-variable-per-declaration": true
    "one-variable-per-declaration": true,ignore-for-loop
    Schema
    {
      "type": "array",
      "items": {
        "type": "string",
        "enum": [
          "ignore-for-loop"
        ]
      },
      "minLength": 0,
      "maxLength": 1
    }

    For more information see this page.

    missing whitespace
    Open

        return createScope === true ? `new Function(${strfy('return '+list.join(''))}).apply(this,[${argLiteral ? argLiteral.text() : ''}]);`: list.join('');
    Severity: Minor
    Found in src/compiler/parser.ts by tslint

    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.

    missing whitespace
    Open

        return new Function('call,tpl', 'return tpl['+strfy(name)+']=function(){return call(this,arguments)}')(
    Severity: Minor
    Found in src/compiler/parser.ts by tslint

    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 the Function constructor to create functions.
    Open

            template = new Function(out, `this.merge(arguments);${out}+=${source};return ${out}`);
    Severity: Minor
    Found in src/compiler/parser.ts by tslint

    Rule: function-constructor

    Prevents using the built-in Function constructor.

    Rationale

    Calling the constructor directly is similar to eval, which is a symptom of design issues. String inputs don't receive type checking and can cause performance issues, particularly when dynamically created.

    If you need to dynamically create functions, use "factory" functions that themselves return functions.

    Config

    Not configurable.

    Examples
    "function-constructor": true

    For more information see this page.

    There are no issues that match your filters.

    Category
    Status