Skip to content
This repository has been archived by the owner on Mar 25, 2021. It is now read-only.

no-inferrable-types rule doesn't detect Infinity as an inferrable numeric literal #2777

Closed
mindjuice opened this issue May 17, 2017 · 2 comments · Fixed by #2885
Closed

no-inferrable-types rule doesn't detect Infinity as an inferrable numeric literal #2777

mindjuice opened this issue May 17, 2017 · 2 comments · Fixed by #2885

Comments

@mindjuice
Copy link

Bug Report

The no-inferrable-types rule should trigger if a variable is assigned the value of Infinity (or -Infinity).

The line in the link below is where the rule checks for a ts.SyntaxKind.NumericLiteral. I took a quick look through the TS code, but wasn't able to find how Infinity is handled. It doesn't seem to be included as a ts.SyntaxKind.NumericLiteral (or this rule would work), nor does there seem to be a ts.SyntaxKind.InfinityKeyword.

https://github.com/palantir/tslint/blob/master/src/rules/noInferrableTypesRule.ts#L112

  • TSLint version: 4.5.1
  • TypeScript version: 2.3
  • Running TSLint via: VSCode

TypeScript code being linted

let foo: number = Infinity

with tslint.json configuration:

{
    "extends": ["tslint-react"],
    "rules": {
        "align": [
            true,
            "parameters",
            "arguments",
            "statements"
        ],
        "array-type": [true, "array"],
        "arrow-return-shorthand": [true, "multiline"],
        "ban": false,
        "class-name": true,
        "comment-format": [
            true,
            "check-space"
        ],
        "curly": true,
        "forin": true,
        "import-spacing": true,
        "indent": [ true, "spaces" ],
        "interface-name": [true, "never-prefix"],
        "jsdoc-format": true,
        "jsx-no-lambda": false,
        "jsx-no-multiline-js": false,
        "label-position": true,
        "max-line-length": [ true, 120 ],
        "member-ordering": [
            true,
            "public-before-private",
            "static-before-instance",
            "variables-before-functions"
        ],
        "new-parens": true,
        "no-angle-bracket-type-assertion": true,
        "no-arg": true,
        "no-bitwise": true,
        "no-conditional-assignment": true,
        "no-console": [
            true,
            "log",
            "error",
            "debug",
            "info",
            "time",
            "timeEnd",
            "trace"
        ],
        "no-consecutive-blank-lines": [true],
        "no-construct": true,
        "no-debugger": true,
        "no-duplicate-super": true,
        "no-duplicate-variable": true,
        "no-empty": true,
        "no-eval": true,
        "no-inferrable-types": [true, "ignore-params"],
        "no-invalid-template-strings": true,
        "no-invalid-this": [true, "check-function-in-method"],
        "no-irregular-whitespace": true,
        "no-misused-new": true,
        "no-null-keyword": true,
        "no-shadowed-variable": true,
        "no-string-literal": true,
        "no-switch-case-fall-through": true,
        "no-trailing-whitespace": true,
        "no-unnecessary-callback-wrapper": true,
        "no-unused-expression": true,
        "no-var-keyword": true,
        "number-literal-format": true,
        "eofline": true,
        "object-literal-key-quotes": [true, "as-needed"],
        "object-literal-shorthand": true,
        "one-line": [
            true,
            "check-catch",
            "check-else",
            "check-open-brace",
            "check-whitespace"
        ],
        "one-variable-per-declaration": [true, "ignore-for-loop"],
        "ordered-imports": [
            true,
            {
                "import-sources-order": "lowercase-last",
                "named-imports-order": "lowercase-first"
            }
        ],
        "prefer-const": true,
        "prefer-for-of": true,
        "prefer-function-over-method": true,
        "prefer-switch": ["true", { "min-cases": 2 }],
        "quotemark": [true, "single"],
        "radix": true,
        "semicolon": [true, "never"],
        "space-before-function-paren": [true, "never"],
        "switch-default": true,
        "trailing-comma": [true, {"multiline": "always", "singleline": "never"}],
        "triple-equals": [ true, "allow-null-check" ],
        "typedef": [
            true,
            "parameter",
            "property-declaration"
        ],
        "typedef-whitespace": [
            true,
            {
                "call-signature": "nospace",
                "index-signature": "nospace",
                "parameter": "nospace",
                "property-declaration": "nospace",
                "variable-declaration": "nospace"
            }
        ],
        "variable-name": [true, "ban-keywords", "check-format", "allow-leading-underscore", "allow-pascal-case"],
        "whitespace": [
            true,
            "check-branch",
            "check-decl",
            "check-module",
            "check-operator",
            "check-separator",
            "check-type",
            "check-typecast"
        ]
    }
}

Actual behavior

The no-inferrable-types message is not shown

Expected behavior

The no-inferrable-types message is shown

@adidahiya
Copy link
Contributor

Can you try and reproduce this bug with the latest TSLint please?

@mindjuice
Copy link
Author

Sorry about that.

I've just confirmed that the same bug occurs in v5.2.0.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants