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

Fixer for "no-angle-bracket-type-assertion" broke my code #4805

Closed
fr0 opened this issue Jul 22, 2019 · 0 comments · Fixed by #4823
Closed

Fixer for "no-angle-bracket-type-assertion" broke my code #4805

fr0 opened this issue Jul 22, 2019 · 0 comments · Fixed by #4823

Comments

@fr0
Copy link

fr0 commented Jul 22, 2019

Bug Report

  • TSLint version: 5.18.0
  • TypeScript version: 3.5.1
  • Running TSLint via: (pick one) CLI

Reproduction using TSLint Playground

https://palantir.github.io/tslint-playground/?saved=N4Igxg9gJgpiBcID0SAEBlALgQwE6dUwE8AHASwDsBzVSwgCxlUllQCMIAPQiVKmAgGcc+GFAB0AHQqVMMXADNsYJgEEwmMhAqpg01AdQBtAOTLMAV2wAbALTC8mEwF14qChYC2beQB8l1oIwANzSAL7S0goWFBpaOgoQEAAU5vFu6praADSo2IKCXmLo8gBu8gAqZJ4wbh7e8rkA7ngkAGLmELh1Xj64AJS6+oaQFMKoMNbYJEFQqAC8qACy2Jj04p7YnMmpBUVQJbjluFU1qLaoADz1fQB8adqm5lZ2DvgugwBUqC247Z24XIABn6oQoEQoIGy4G0CjIVAQyDQAE0IBZmNgdJ5oGQFEQGExRnCqBZcKt4qhGLgmE0yGtUEQ0bhUBAmhQpBQUMtsABrJiFakMVYMpmoABWgm0tEEqFKNjIUFymLmuJF6NwMVoFEwEGkXIga3k0sKMEEuUwuHxYEYYB5lBohuY2kl1iYiWZ8lwXUEHOkeh0hkkIBgnDkFCggiDbiMQcwgmssng1Mgnhq4bEQec2WGBiDGtdkYQujCqC52Cgc3LUDp8RsqHzpry4YJZGZRPhpPJ2nC0hAYSAA

TypeScript code being linted

interface Action {
    ['actual-start']: number|false;
}

function foo(action: Action, assumedServerTime: number, warpFactor: number) {
    const elapsed = Math.max((assumedServerTime - <number>action['actual-start']) * warpFactor, 0);
}

with tslint.json configuration:

{
    "defaultSeverity": "error",
    "extends": [
        "tslint:recommended"
    ],
    "jsRules": {},
    "rules": {
        "max-line-length": [true, 240],
        "interface-name": false,
        "quotemark": [true, "single", "avoid-escape"],
        "member-access": [true, "no-public"],
        "no-string-literal": false,
        "member-ordering": false,
        "arrow-parens": [true, "ban-single-arg-parens"],
        "one-line": false,
        "trailing-comma": [true, {
            "multiline": "never",
            "singleline": "never"
        }],
        "object-literal-sort-keys": false,
        "only-arrow-functions": false,
        "no-empty": false,
        "ban-types": {
            "options": [
                ["Object", "Avoid using the `Object` type. Did you mean `object`?"],
                ["Boolean", "Avoid using the `Boolean` type. Did you mean `boolean`?"],
                ["Number", "Avoid using the `Number` type. Did you mean `number`?"],
                ["String", "Avoid using the `String` type. Did you mean `string`?"],
                ["Symbol", "Avoid using the `Symbol` type. Did you mean `symbol`?"]
            ]
        },
        "max-classes-per-file": false,
        "variable-name": false,
        "ordered-imports": false,
        "no-console": false,
        "no-bitwise": false
    },
    "rulesDirectory": []
}

Actual behavior

The --fix option produced the following code:

const elapsed = Math.max((this.assumedServerTime - action['actual-start'] as number) * warpFactor, 0);

but this is erroneous, there are missing parens. It should be:

const elapsed = Math.max((this.assumedServerTime - (action['actual-start'] as number)) * warpFactor, 0);

Expected behavior

See above.

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