Coder Social home page Coder Social logo

Clarify ident rule about tslint HOT 9 CLOSED

palantir avatar palantir commented on July 24, 2024
Clarify ident rule

from tslint.

Comments (9)

ashwinr avatar ashwinr commented on July 24, 2024

indent checks for indentation consistency within statement blocks. Currently, a tab character is treated as 4 spaces, but we can make it configurable if necessary. Take a look at the indentation test if you really want to understand how the rule works.

from tslint.

Bartvds avatar Bartvds commented on July 24, 2024

I think there is a bug that was part of my confusion, looks related to the one-line literals:

With this rule:

"indent": [true, 4],

In this snippet (with tabs)

        getKey(label:string, keyTerms?:any):string {
            return xm.jsonToIdent([label, keyTerms ? keyTerms : {}]);
        }

I get these 2 errors (line 75 is the indented line):

>> src/git/GitAPICached.ts[75, 27]: unexpected tab width: expected 16, got 0
>> src/git/GitAPICached.ts[75, 34]: unexpected tab width: expected 16, got 0

from tslint.

Bartvds avatar Bartvds commented on July 24, 2024

This one is interesting as well. This the content of a single file:

module xm {
    export function callAsync(callback, ...args:any[]) {
        process.nextTick(() => {
            callback.apply(null, args);
        });
    };
}

With this error: (line 6 is is next-to-last-one with the };

>> src/xm/callAsync.ts[6, 3]: unexpected tab width: expected 4, got 0

Notice the }; is my mistake, the semicolon doesn't belong there (as the brace is from a named function). If I remove the semicolon the rule passes.

from tslint.

ashwinr avatar ashwinr commented on July 24, 2024

Fixed the indentation rule to allow one-line literals always. so, the first example above should work.

from tslint.

ashwinr avatar ashwinr commented on July 24, 2024

there's not much we can do about the second one. the single semi-colon is treated as an empty statement, and tslint complains about it not indented correctly (which is a valid complaint, IMHO). In general, we advise tslint to run after the tsc compilation succeeds, so we don't get tripped up by compiler errors, but there's not much we can do in this particular case.

from tslint.

Bartvds avatar Bartvds commented on July 24, 2024

Cool, I understand. I had tslint before compilation, as it is a lot faster then compiling. But I can see how that'd could go wrong, I'll swap it.

Note the noempty doesn't warn about this particular case though (in my 0.2.1)

from tslint.

ashwinr avatar ashwinr commented on July 24, 2024

but there's no empty block in your example, right?

from tslint.

Bartvds avatar Bartvds commented on July 24, 2024

Ooops, you are right!

I was confused with your mention of 'empty statement' (which there is between the closing brace and the semicolon, but that's not this rule).

from tslint.

ashwinr avatar ashwinr commented on July 24, 2024

cool :)

from tslint.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.