Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[indent] multiple false positives in recent versions #121

Closed
43081j opened this issue Jan 22, 2019 · 11 comments
Closed

[indent] multiple false positives in recent versions #121

43081j opened this issue Jan 22, 2019 · 11 comments
Labels
bug Something isn't working package: eslint-plugin Issues related to @typescript-eslint/eslint-plugin

Comments

@43081j
Copy link
Contributor

43081j commented Jan 22, 2019

Example

{
  "rules": {
    "@typescript-eslint/indent": "error"
  }
}
export type Foo = A
  | B
  | C;

Expected Result

Identation is linted.

Actual Result

Indentation is not linted.

Additional Info

It seems we simply don't deal with type aliases.


We should probably be handling TSIntersectionType and TSUnionType. I am happy to PR this but wasn't sure what the best solution is... maybe to transform into a LogicalExpression?

@43081j 43081j added package: eslint-plugin Issues related to @typescript-eslint/eslint-plugin triage Waiting for maintainers to take a look labels Jan 22, 2019
@43081j
Copy link
Contributor Author

43081j commented Jan 22, 2019

In actual fact, the indent rule seems broken in a few places since the last change to it...

  private static _store: Map<string, Foo> =
    new Map<string, Foo>();

// linter complains that it doesn't look like this
  private static _store: Map<string, Foo> =
  new Map<string, Foo>();

Another:

  private _endpoint: string =
    '/foo';

// linter complains that it should be
  private _endpoint: string =
  '/foo';

Another:

  protected _messageMap =
    new Map<number, Message>([
      [-1, msg]
    ]);

// linter complains that it should be
  protected _messageMap =
  new Map<number, Message>([
    [-1, msg]
  ]);

There are too many instances of this for it to be a coincidence. My guess is something broke the rule in the most recent changes.

This is all with config:

    "@typescript-eslint/indent": ["warn", 2, {
      "FunctionDeclaration": {
        "parameters": 2
      },
      "FunctionExpression": {
        "parameters": 2
      },
      "CallExpression": {
        "arguments": 1
      },
      "SwitchCase": 1
    }],

Before I updated to the scoped package from the monorepo, there were no lint errors with the same config and sources.

@43081j 43081j changed the title [@typescript-eslint/indent] type alias support [@typescript-eslint/indent] multiple false positives in recent versions Jan 22, 2019
@bradzacher bradzacher added bug Something isn't working and removed triage Waiting for maintainers to take a look labels Jan 22, 2019
@bradzacher
Copy link
Member

confirmed against master.
Need to add more cases for these nodes.
Probably need to transform TSUnionType/TSIntersectionType to a binary expression or similar.

@ivanvoznyakovsky
Copy link

this one bradzacher/eslint-plugin-typescript#271 is still an issue in latest release

@Philipp91
Copy link

Philipp91 commented Jul 6, 2019

'@typescript-eslint/indent': ['error', 4, {SwitchCase: 1, /* ... Ignore JSX nodes ...*/}]
Note: I use TypeScript 3.5.1 and am getting a warning about lacking typescript-estree support for that.

Let me add another test case, where currently there's a false positive error:

const doSomething = <P extends object, V>(
    {something, ...props}: SomePropsType<P>
): P => ({
    ...props as P, // Here it wants 8 instead of 4 spaces.
    ...something, // Here it wants 8 instead of 4 spaces.
});

I simplified it to this, which still throws an error:

const test = <T extends object>(
) =>
    true; // Here it wants 8 instead of 4 spaces.

Also, removing the generic type parameter and/or the multi-line "parameter list" solves the problem:

const test = (
) =>
    true; // Now it agrees with my 4 spaces.
const test = <T extends object>() =>
    true; // Now it agrees with my 4 spaces.
const test = () =>
    true; // Now it agrees with my 4 spaces.

@dacioromero
Copy link

dacioromero commented Jul 17, 2019

I'm getting this

const foo = [1, 2, 3]

const bar = foo
  .reduce<number>((acc, val) => {
    return acc + val
  }, 0)

to throw errors

  3:5   warning  'bar' is assigned a value but never used      @typescript-eslint/no-unused-vars
  6:19  warning  Missing return type on function               @typescript-eslint/explicit-function-return-type
  7:1   error    Expected indentation of 2 spaces but found 4  @typescript-eslint/indent
  8:1   error    Expected indentation of 0 spaces but found 2  @typescript-eslint/indent

with this config

module.exports = {
  parser: '@typescript-eslint/parser',
  plugins: ['@typescript-eslint'],
  extends: ['plugin:@typescript-eslint/recommended'],
  rules: { "@typescript-eslint/indent": ["error", 2] }
}

So running it with --fix produces this

const foo = [1, 2, 3]

const bar = foo
  .reduce<number>((acc, val) => {
  return acc + val
}, 0)

@lostfields
Copy link

I got the same issue with indenting using generics, both of this is valid using indent of 4;

let list = [1, 2, 3]
    .map(value => {
        return String(value)
    })

let list = [1, 2, 3]
    .map<string>(value => {
    return String(value)
})

@nolazybits
Copy link

nolazybits commented Nov 27, 2019

I also have an issue with the indent on enums

export enum AnEnum
{
    SOMETHING = "something",
    ELSE = "else",
}

with the following rules

                "@typescript-eslint/brace-style": ["error", "allman"],
                "@typescript-eslint/indent": [ 
                    "error",
                    4,
                    {
                        "ArrayExpression": "first",
                        "ObjectExpression": "first",
                        "FunctionDeclaration": {
                            "parameters": "first"
                        },
                        "FunctionExpression": {
                            "parameters": "first"
                        }
                    }
                ],

will show an error on the opening brace on the new line, saying the indentation of 0 should be 4 :/

[edit] could it be related to the brace-style not picking up enums, opened here #1274 [/edit]

@stevenhair
Copy link

I also see this issue with annotations:

@injectable()
class FooClass {
    public constructor(
        @inject(mongoClientProviderToken) mongoClientProvider: MongoClientProvider,
        @inject(FooConfig) config: FooConfig
    ) {
        // code
    }

eslint wants it to look like:

@injectable()
class FooClass {
    public constructor(
    @inject(mongoClientProviderToken) mongoClientProvider: MongoClientProvider,
        @inject(FooConfig) config: FooConfig
    ) {
        // code
    }

If I remove the first annotation, everything is fine.

@bradzacher bradzacher changed the title [@typescript-eslint/indent] multiple false positives in recent versions [indent] multiple false positives in recent versions Dec 28, 2019
@AnthonyIacono
Copy link

@stevenhair Same issue here. Did you ever manage to figure out a workaround short of disabling the indentation rule?

@stevenhair
Copy link

@AnthonyIacono unfortunately not, I just disabled the rule for the file.

@bradzacher
Copy link
Member

Merging into #1824

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Apr 29, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Something isn't working package: eslint-plugin Issues related to @typescript-eslint/eslint-plugin
Projects
None yet
Development

No branches or pull requests

9 participants