Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

[explicit-member-accessibility] should not be part of recommended #201

Copy link
Copy link
Closed
@JamesHenry

Description

@JamesHenry
Issue body actions

I have just noticed that currently we include

"@typescript-eslint/explicit-member-accessibility": "error",

in recommended.json from eslint-plugin.

I propose that we remove it.

Rationale

TypeScript has always positioned itself as an extension of JavaScript. It is no secret that I think it does a bloody good job at it :)

With it being an extension of JavaScript, there is an expectation that the majority of what you write is JavaScript code, and any syntactic additions provided by TypeScript are there to give you functionality you otherwise do not have.

I strongly believe this does not apply to the public access modifier.

Classes have long been supported in JavaScript, and developers should understand how they work at runtime, regardless of if they use TypeScript or not. As we know, class properties are public in JavaScript.

The private and protected access modifiers do give you functionality you (currently**) otherwise do not have, so adding them to your otherwise valid JavaScript classes is a great capability.

The public access modifier is not only unarguably functionally redundant based on my previous assertions about developers needing to understand JavaScript classes, it is arguably visual clutter when reading the code, and makes it harder to read.

Readability is always subjective, I admit that, but I posit it is harder because having two words (public and private) both beginning with p, both of roughly equal length in front of every single class property makes them less likely to be explicitly distinguishable from one another when scanning code.

An interesting piece of context to this - I often see one of the main reasons people use to justify not using TypeScript is that it is "so different to JavaScript" and "looks like Java". This is absolutely not the case when you approach it in the way I suggest above, and leverage it as an extension to JavaScript. Having a high-profile project like this one recommend a rule like this to developers does not help with that image IMO.

Finally, the rationale for the rule given in the description in the README of the rule is very unclear.

It is conflating the decision of whether or not things should be private to a class, with whether or not public things should use a public access modifier.

Leaving off accessibility modifier and making everything public can make
your interface hard to use by others.
If you make all internal pieces private or protected, your interface will
be easier to use.

These are two completely different things:

Making everything public != Not using the public keyword

I do understand why some people might want to use this rule, and I am not advocating that we should not support it.

I am however, strongly suggesting that it is not appropriate to include it in recommended.

If people wish to provide counter-arguments to what I have said above please do, but please remember keep the focus on the justification as to why it should be in recommended.


**I say currently because of course private properties are coming to JavaScript very soon, and they have completely different syntax to what we are used to with TypeScript today. TypeScript will adapt to this in one way or another, but by leveraging public it means you are doubling down on custom TypeScript syntax in the interim, and so that is also a factor IMO

Metadata

Metadata

Assignees

No one assigned

    Labels

    has prthere is a PR raised to close thisthere is a PR raised to close thispackage: eslint-pluginIssues related to @typescript-eslint/eslint-pluginIssues related to @typescript-eslint/eslint-pluginrecommended-rulesDiscussion about recommended rule setsDiscussion about recommended rule sets

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      Morty Proxy This is a proxified and sanitized view of the page, visit original site.