-
Notifications
You must be signed in to change notification settings - Fork 652
Expand file tree
/
Copy pathprefer-private-class-members.ts
More file actions
45 lines (41 loc) · 1.23 KB
/
prefer-private-class-members.ts
File metadata and controls
45 lines (41 loc) · 1.23 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
// Copyright 2021 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import type {TSESTree} from '@typescript-eslint/utils';
import {createRule} from './utils/ruleCreator.ts';
export default createRule({
name: 'prefer-private-class-members',
meta: {
type: 'problem',
docs: {
description: 'Prefer private properties over regular properties with `private` modifier',
category: 'Possible Errors',
},
schema: [], // no options
messages: {
doNotUsePrivate: 'Use private properties (starting with `#`) rather than the `private` modifier.',
},
},
defaultOptions: [],
create: function(context) {
function isTypeScriptPrivate(node: TSESTree.MethodDefinition|TSESTree.PropertyDefinition) {
if (node.type === 'MethodDefinition' && node.kind === 'constructor') {
return;
}
if (node.accessibility === 'private') {
context.report({
node: node.key,
messageId: 'doNotUsePrivate',
});
}
}
return {
MethodDefinition(node) {
isTypeScriptPrivate(node);
},
PropertyDefinition(node) {
isTypeScriptPrivate(node);
}
};
}
});