Skip to content

[camelcase] False positive with optional chaining #1196

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

Closed
thomasgazzoni opened this issue Nov 12, 2019 · 0 comments · Fixed by #1204
Closed

[camelcase] False positive with optional chaining #1196

thomasgazzoni opened this issue Nov 12, 2019 · 0 comments · Fixed by #1204
Labels
bug Something isn't working good first issue Good for newcomers has pr there is a PR raised to close this package: eslint-plugin Issues related to @typescript-eslint/eslint-plugin

Comments

@thomasgazzoni
Copy link

thomasgazzoni commented Nov 12, 2019

Hi guys,

I updated my project to latest typescript and eslint-plugin (2.7.0) version to use the new optional chaining operator and I encounter a problem when enforcing the CamelCase rule. Below a I am posting an example:

interface IData {
  snake_id?: number;
  user_snake?: {
    first_name: string;
    last_name: string;
  };
  userCamel?: {
    firstName: string;
    lastName: string;
    snake_name: string;
  };
}

const data: IData = {};

// RIGHT: No problem when accessing CamelCase fields
console.log('CamelFirstName:', data.userCamel?.firstName);

// RIGHT: No problem when accessing snake_case's fields methods
console.log('CamelFirstName:', data.snake_id?.toString());

// WRONG: Error when accessing snake_case fields after optional chaining operator
console.log('snake_first_name:', data.user_snake?.first_name);
console.log('snake_first_name:', data.userCamel?.snake_name);

Expected Result

Accessing snake_case fields of an object with the rule "@typescript-eslint/camelcase":2 should not throw an linting error.

Actual Result

Lint error when accessing an object's fields if they are in snake_case

Repro

{
  "extends": [
    "airbnb-typescript",
    "plugin:@typescript-eslint/recommended",
    "prettier",
    "prettier/react",
    "prettier/@typescript-eslint",
    "prettier/babel",
    "prettier/standard",
  ],
  "rules": {
    "@typescript-eslint/camelcase": 2,
  }
}

Versions

package version
@typescript-eslint/eslint-plugin 2.7.0
@typescript-eslint/parser 2.7.0
TypeScript 3.7.2
ESLint 6.6.0
node 10.16.0
npm 6.9.0
@thomasgazzoni thomasgazzoni added package: eslint-plugin Issues related to @typescript-eslint/eslint-plugin triage Waiting for team members to take a look labels Nov 12, 2019
@bradzacher bradzacher added bug Something isn't working and removed triage Waiting for team members to take a look labels Nov 12, 2019
@bradzacher bradzacher added the good first issue Good for newcomers label Nov 12, 2019
@bradzacher bradzacher added the has pr there is a PR raised to close this label Nov 13, 2019
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Apr 20, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Something isn't working good first issue Good for newcomers has pr there is a PR raised to close this package: eslint-plugin Issues related to @typescript-eslint/eslint-plugin
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants