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

Indentation rule conflict with prettier #372

Closed
mohsinulhaq opened this issue Mar 23, 2019 · 11 comments
Closed

Indentation rule conflict with prettier #372

mohsinulhaq opened this issue Mar 23, 2019 · 11 comments
Labels
package: eslint-plugin Issues related to @typescript-eslint/eslint-plugin wontfix This will not be worked on

Comments

@mohsinulhaq
Copy link

Repro

const isHoverTriggered = true;
const followCursor = true;
const callAll = (a, b) => {};
const that = {
  showTooltip: true
};
const props = {
  onMouseMove: true
};

const o = {
  ...(isHoverTriggered &&
    followCursor && {
      onMouseMove: callAll(that.showTooltip, props.onMouseMove)
    })
};

Config

module.exports = {
  parser: '@typescript-eslint/parser',
  extends: [
    'plugin:@typescript-eslint/recommended',
    'plugin:prettier/recommended',
    'plugin:react/recommended',
    'plugin:jsx-a11y/recommended'
  ],
  parserOptions: {
    ecmaVersion: 2018,
    sourceType: 'module',
    ecmaFeatures: {
      jsx: true
    }
  },
  settings: {
    react: {
      version: 'detect'
    }
  },
  rules: {
    '@typescript-eslint/indent': ['error', 2]
  }
};

Expected Result
No indentation error

Actual Result

When prettier is followed:

14:1   error    Expected indentation of 4 spaces but found 6  @typescript-eslint/indent
15:1   error    Expected indentation of 2 spaces but found 4  @typescript-eslint/indent

When eslint is followed:

  14:5   error    Insert `··`                             prettier/prettier
  15:1   error    Insert `··`                             prettier/prettier

Additional Info

image

Versions

package version
@typescript-eslint/eslint-plugin 1.5.0
@typescript-eslint/parser 1.5.0
TypeScript 3.3.4000
ESLint 5.15.3
node 10.15.2
npm 6.9.0
@mohsinulhaq mohsinulhaq added package: eslint-plugin Issues related to @typescript-eslint/eslint-plugin triage Waiting for maintainers to take a look labels Mar 23, 2019
@j-f1
Copy link
Contributor

j-f1 commented Mar 23, 2019

Prettier recommends disabling all formatting rules, which you can do by installing eslint-config-prettier and extending prettier/@typescript-eslint.

@j-f1 j-f1 closed this as completed Mar 23, 2019
@j-f1 j-f1 added wontfix This will not be worked on and removed triage Waiting for maintainers to take a look labels Mar 23, 2019
@mohsinulhaq
Copy link
Author

Hi, @j-f1 I just changed my config to be:

module.exports = {
  parser: '@typescript-eslint/parser',
  extends: [
    'plugin:@typescript-eslint/recommended',
    'prettier/@typescript-eslint',
    'plugin:prettier/recommended',
    'plugin:react/recommended',
    'plugin:jsx-a11y/recommended'
  ],
  parserOptions: {
    ecmaVersion: 2018,
    sourceType: 'module',
    ecmaFeatures: {
      jsx: true
    }
  },
  plugins: ['@typescript-eslint', 'react', 'jsx-a11y'],
  settings: {
    react: {
      version: 'detect'
    }
  },
  rules: {
    '@typescript-eslint/indent': ['error', 2]
  }
};

But I am still getting the same error. Please help.
Thanks.

@j-f1
Copy link
Contributor

j-f1 commented Mar 23, 2019

You also need to remove the indent rule from your own config since it overrides everything else.

@mohsinulhaq
Copy link
Author

Ok, so how do I set my lint config to allow indentation levels to be 2 instead of the default 4.

@j-f1
Copy link
Contributor

j-f1 commented Mar 23, 2019

Prettier should cover that for you.

@mohsinulhaq
Copy link
Author

That's what I had tried originally, by removing @typescript-eslint/indent': ['error', 2], but I got:
error Expected indentation of 4 spaces but found 2 @typescript-eslint/indent
all over the project
.prettierrc:

{
  "singleQuote": true,
  "bracketSpacing": false
}

@mohsinulhaq
Copy link
Author

Any suggestions? @j-f1

@j-f1
Copy link
Contributor

j-f1 commented Mar 23, 2019

This should be working:

module.exports = {
  parser: '@typescript-eslint/parser',
  extends: [
    'plugin:@typescript-eslint/recommended',
    'prettier/@typescript-eslint',
    'plugin:prettier/recommended',
    'plugin:react/recommended',
    'plugin:jsx-a11y/recommended'
  ],
  parserOptions: {
    ecmaVersion: 2018,
    sourceType: 'module',
    ecmaFeatures: {
      jsx: true
    }
  },
  plugins: ['@typescript-eslint', 'react', 'jsx-a11y'],
  settings: {
    react: {
      version: 'detect'
    }
  }
};

@mohsinulhaq
Copy link
Author

Thanks a lot! It works now. 🙂

@gho1b
Copy link

gho1b commented Aug 17, 2019

Im sorry i need to reopen this issue because i got same issue while use Dependency Injection in method parameter. Can you help me to solve this issue?

  @Query(() => Location!)
  public async location(
    @Arg('id', () => Int, { description: 'Location id' })
    id: number,
  ): Promise<Location> {
    return this.locationRepository.findOneOrFail(id);
  }

@bradzacher
Copy link
Member

I'm not sure you understand why this was closed.
This is 100% intentional.
The two should conflict because prettier does its own indentation and formatting which does not conform to eslint's indentation rules.

If you think this is another issue, please open a new issue.

Also - please do not comment on old, closed issues. ESP ones that are 6 months old.

@typescript-eslint typescript-eslint locked as resolved and limited conversation to collaborators Aug 18, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
package: eslint-plugin Issues related to @typescript-eslint/eslint-plugin wontfix This will not be worked on
Projects
None yet
Development

No branches or pull requests

4 participants