Thanks to visit codestin.com
Credit goes to github.com

Skip to content

[no-dupe-class-members] Rule doesn't handle class properties #618

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
odaper opened this issue Jun 17, 2019 · 2 comments
Closed

[no-dupe-class-members] Rule doesn't handle class properties #618

odaper opened this issue Jun 17, 2019 · 2 comments
Labels
accepting prs Go ahead, send a pull request that resolves this issue enhancement: new base rule extension New base rule extension required to handle a TS specific case package: eslint-plugin Issues related to @typescript-eslint/eslint-plugin

Comments

@odaper
Copy link

odaper commented Jun 17, 2019

I have configured the following .eslintrc to validate my typescript files:

module.exports = {
  env: {
    node: true,
    es6: true,
  },
  extends: ['plugin:@typescript-eslint/recommended'],
  parser: '@typescript-eslint/parser',
  parserOptions: {
    sourceType: 'module',
    typescript: true,
    modules: true,
    ecmaVersion: 6,
    ecmaFeatures: {
      experimentalObjectRestSpread: true,
    },
  },
  plugins: ['@typescript-eslint'],
  rules: {
    'no-duplicate-imports': 'error',
    'no-var': 'error',
    'no-dupe-keys': 'error',
    'no-duplicate-case': 'error',
    'no-dupe-class-members': 'error',
    indent: ['error', 4],
    'linebreak-style': ['error', 'unix'],
    quotes: ['error', 'single'],
    semi: ['error', 'always'],
  },
};

When my typescript file contains duplicated property name like:

 export class TestClassViewComponent  {

  selectedItems: TestClassModel[];
  selectedItems: TestClassModel[];
....

No error will be thrown when running the linting process.
Is "no-dupe-class-members" supported in typescript files?
Many thanks

@odaper odaper added package: eslint-plugin Issues related to @typescript-eslint/eslint-plugin triage Waiting for team members to take a look labels Jun 17, 2019
@bradzacher
Copy link
Member

this is expected. eslint core doesn't support class properties as they're not yet part of the JS spec.

We recommend just turning off this rule for typescript files because typescript does its own checks for duplicate class members.

  export class TestClassViewComponent  {
    selectedItems: TestClassModel[];
    selectedItems: TestClassModel[];
//  ^^^^^^^^^^^^^ Duplicate identifier 'selectedItems'
  }

Similar to #291 - I'll leave it open in case anyone really wants to implement a fix for this, but it's bottom of our priority because of our recommendation not to use the rule.

@bradzacher bradzacher added bug Something isn't working enhancement: new base rule extension New base rule extension required to handle a TS specific case and removed triage Waiting for team members to take a look labels Jun 17, 2019
@bradzacher bradzacher changed the title no-dupe-class-members doesn't seem to throw error for duplicated class properties [no-dupe-class-members] Rule doesn't handle class properties Jun 17, 2019
@bradzacher bradzacher removed the bug Something isn't working label Nov 18, 2019
@JoshuaKGoldberg JoshuaKGoldberg added the accepting prs Go ahead, send a pull request that resolves this issue label Oct 25, 2021
@armano2
Copy link
Collaborator

armano2 commented May 30, 2022

this issue has been fixed upstream, eslint is now supporting class properties, see Playground

@armano2 armano2 closed this as completed May 30, 2022
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jun 30, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
accepting prs Go ahead, send a pull request that resolves this issue enhancement: new base rule extension New base rule extension required to handle a TS specific case package: eslint-plugin Issues related to @typescript-eslint/eslint-plugin
Projects
None yet
Development

No branches or pull requests

4 participants