-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
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
Rule proposal: prefer hash names for private members #1391
Comments
Perhaps it should allow the opposite as well – enforcing soft (compile-time-only) privacy? |
Probably best to be added as an option on the |
Then the options for type AccessibilityLevel =
| 'explicit' // require an accessor (including public)
| 'no-public' // don't require public
| 'off'; // don't check
type PrivateMemberDeclaration =
| 'private' // force private modifier
| '#' // force hash names
| 'off'; // don't check, default
type AccessibilitySetting = AccessibilityLevel | [AccessibilityLevel, PrivateMemberDeclaration];
type Options = {
accessibility?: AccessibilitySetting;
ignoredMethodNames?: string[];
overrides?: {
accessors?: AccessibilitySetting;
constructors?: AccessibilitySetting;
methods?: AccessibilitySetting | {
static?: AccessibilitySetting;
instance?: AccessibilitySetting;
};
properties?: AccessibilitySetting | {
static?: AccessibilitySetting;
instance?: AccessibilitySetting;
};
parameterProperties?: AccessibilitySetting;
};
};
const defaultOptions: Options = {
accessibility: 'explicit',
}; I'm afraid that the name |
Expect more discussions and progress on this issue. |
With any issue in opened in this project - it either has a visible progress in the form of an attached PR, or it has no progress. We are a community run project. The volunteer maintainers spend most of their time triaging issues and reviewing PRs. This means that most issues will not progress unless a member of the community steps up and champions it. If this issue is important to you - consider being that champion. If not - please just subscribe to the issue and wait patiently. |
Current workaround: '@typescript-eslint/naming-convention': [
'error',
{
selector: ['property', 'parameterProperty', 'accessor'],
modifiers: ['private'],
prefix: ['#'],
format: null,
}
], |
As per our FAQ article - this can easily be achieved using
similarly the inverse can easily be enforced as well:
I don't believe that a lint rule makes sense here. We want to avoid adding rules which just ban a specific language features unless we can add some real additional value. Given that there's no fixer we can provide (because it's unsafe), and there's no options to configure or tweak - I don't see any additional value we can provide. For this reason, we shall reject this rule proposal. |
I don't think we are banning language features here. Infact, we are asking to promote the language feature ie private properties |
What's the difference to a linter? In practice this is exactly the same as "banning" |
All we are asking is to enforce the usage of
Don't we do that already in other places like?
|
Sorry, I think you've misunderstood. My comment above gives you a solution to do exactly what you want Why would we build a separate rule when there is already existing tooling that more than meets the requirements? |
TypeScript 3.8 will add support for private named instance fields. What about creating a rule for disallowing the use of the
private
accessibility modifier in favor of the standard hash names for private members?Examples of incorrect code for this rule:
Examples of correct code for this rule:
Options
The text was updated successfully, but these errors were encountered: