简体   繁体   中英

tslint: benefit of "object-literal-shorthand"

an example for this rule:

    this.http.post(this.apiUrl + "screenshot", {
        url: url,
        ratio: ratio
    }).subscribe(res => {
        console.log(res);
    });

tslint will complain about this code. the way tslint wants me to do this would be

    this.http.post(this.apiUrl + "screenshot", {
        url,
        ratio
    }).subscribe(res => {
        console.log(res);
    });

for me the first snippet is way more well-arranged. I disabled the corresponding rule but now I wonder if there is any benefit of using the "object-literal-shorthand" in terms of performance or something else.

I think this gets pretty messy, especially if the literal is bigger and mixed with variables that can't use the shorthand. So whats the reason for this rule, I don't get it.

This is one of the fixable rules in tslint.

https://palantir.github.io/tslint/usage/cli/

When you run:

tslint --fix

It will rewrite the code to use literal syntax.

benefit of using the "object-literal-shorthand" in terms of performance

The rule is part of a collection of shorter code fragment rules that help produce fewer lines of code.

So whats the reason for this rule, I don't get it.

Fixable rules in tslint are intended to assist with code sharing. You can add a Git hook or a build stage that will run tslint --fix automatically for you.

People who use modern IDEs that display tslint warnings don't really benefit from the fixable feature. The IDE bugs you to fix it when you write it.

Just turn off if you don't want it on.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM