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

Skip to content

[no-parameter-properties] Support enforcing the inverse #103

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
sindresorhus opened this issue Jan 21, 2019 · 4 comments · Fixed by #4622
Closed

[no-parameter-properties] Support enforcing the inverse #103

sindresorhus opened this issue Jan 21, 2019 · 4 comments · Fixed by #4622
Labels
accepting prs Go ahead, send a pull request that resolves this issue breaking change This change will require a new major version to be released enhancement: plugin rule option New rule option for an existing eslint-plugin rule package: eslint-plugin Issues related to @typescript-eslint/eslint-plugin

Comments

@sindresorhus
Copy link

sindresorhus commented Jan 21, 2019

The no-parameter-properties rule enforces not using parameter properties, but I would like to enforce use of parameter properties whenever possible. I actually like the shorthand.

I would suggest renaming the rule to parameter-properties (without the no- prefix) and support enforcing both use and non-use of parameter properties.


Relevant TSLint issue: palantir/tslint#2638

@sindresorhus sindresorhus added package: eslint-plugin Issues related to @typescript-eslint/eslint-plugin triage Waiting for team members to take a look labels Jan 21, 2019
@j-f1 j-f1 added enhancement: plugin rule option New rule option for an existing eslint-plugin rule breaking change This change will require a new major version to be released and removed triage Waiting for team members to take a look labels Jan 21, 2019
armanio123 pushed a commit to armanio123/typescript-eslint that referenced this issue Jan 24, 2019
@SamVerschueren
Copy link

I agree, it's much cleaner with parameter properties.

@jednano
Copy link

jednano commented Jan 25, 2019

I've always used them as well. What are y'all's thoughts about the argument for introducing the rule in the first place?

Parameter properties can be confusing to those new to TypeScript as they are less explicit than other ways of declaring and initializing class members.

@typescript-eslint/no-parameter-properties

It sounds like the argument is that it confuses people who don't know TypeScript? A bit of a weak argument, if you ask me.

@bradzacher
Copy link
Member

@jedmao - Some people don't like parameter properties.
I, for one, don't like them - I don't like their look or the way they allow you to have class properties defined in two places.

As with all rules, it's there to enforce a stylistic/personal preference for code - enforcing consistent code throughout a codebase.


We should probably look at re-evaluating all of our no- rules to see if we can make them work in both directions for greater flexibility.

@JoshuaKGoldberg
Copy link
Member

Copying a relevant code snippet from palantir/tslint#2638 (comment): FWIW, parameter properties are quite nice when using libraries such as Inversify:

@injectable()
class Ninja implements Warrior {

    private _katana: Weapon;
    private _shuriken: ThrowableWeapon;

    public constructor(
        @inject(TYPES.Weapon) katana: Weapon,
        @inject(TYPES.ThrowableWeapon) shuriken: ThrowableWeapon
    ) {
        this._katana = katana;
        this._shuriken = shuriken;
    }

    public fight() { return this._katana.hit(); };
    public sneak() { return this._shuriken.throw(); };
}

..compared to...

@injectable()
class Ninja implements Warrior {
    public constructor(
        @inject(TYPES.Weapon)
        private readonly katana: Weapon,

        @inject(TYPES.ThrowableWeapon)
        private readonly shuriken: ThrowableWeapon,
    ) {  }

    public fight() { return this.katana.hit(); };
    public sneak() { return this.shuriken.throw(); };
}

@bradzacher bradzacher modified the milestones: 2.0.0, 3.0.0 Jul 25, 2019
@bradzacher bradzacher removed this from the 3.0.0 milestone Jan 22, 2020
SkReD pushed a commit to SkReD/typescript-eslint that referenced this issue Jul 9, 2021
@JoshuaKGoldberg JoshuaKGoldberg added the accepting prs Go ahead, send a pull request that resolves this issue label Oct 25, 2021
@github-actions github-actions bot locked as resolved and limited conversation to collaborators May 23, 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 breaking change This change will require a new major version to be released enhancement: plugin rule option New rule option for an existing eslint-plugin rule package: eslint-plugin Issues related to @typescript-eslint/eslint-plugin
Projects
None yet
6 participants