Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -196,8 +196,10 @@ export default createRule<Options, MessageIds>({
*/
function findPublicKeyword(
node:
| TSESTree.AccessorProperty
| TSESTree.MethodDefinition
| TSESTree.PropertyDefinition
| TSESTree.TSAbstractAccessorProperty
| TSESTree.TSAbstractMethodDefinition
| TSESTree.TSAbstractPropertyDefinition
| TSESTree.TSParameterProperty,
Expand Down Expand Up @@ -238,8 +240,10 @@ export default createRule<Options, MessageIds>({
*/
function getMissingAccessibilitySuggestions(
node:
| TSESTree.AccessorProperty
| TSESTree.MethodDefinition
| TSESTree.PropertyDefinition
| TSESTree.TSAbstractAccessorProperty
| TSESTree.TSAbstractMethodDefinition
| TSESTree.TSAbstractPropertyDefinition
| TSESTree.TSParameterProperty,
Expand Down Expand Up @@ -284,7 +288,9 @@ export default createRule<Options, MessageIds>({
*/
function checkPropertyAccessibilityModifier(
propertyDefinition:
| TSESTree.AccessorProperty
| TSESTree.PropertyDefinition
| TSESTree.TSAbstractAccessorProperty
| TSESTree.TSAbstractPropertyDefinition,
): void {
if (propertyDefinition.key.type === AST_NODE_TYPES.PrivateIdentifier) {
Expand Down Expand Up @@ -389,7 +395,7 @@ export default createRule<Options, MessageIds>({
return {
'MethodDefinition, TSAbstractMethodDefinition':
checkMethodAccessibilityModifier,
'PropertyDefinition, TSAbstractPropertyDefinition':
'PropertyDefinition, TSAbstractPropertyDefinition, AccessorProperty, TSAbstractAccessorProperty':
checkPropertyAccessibilityModifier,
TSParameterProperty: checkParameterPropertyAccessibilityModifier,
};
Expand Down
2 changes: 2 additions & 0 deletions packages/eslint-plugin/src/util/getMemberHeadLoc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,10 @@ import {
export function getMemberHeadLoc(
sourceCode: Readonly<TSESLint.SourceCode>,
node:
| TSESTree.AccessorProperty
| TSESTree.MethodDefinition
| TSESTree.PropertyDefinition
| TSESTree.TSAbstractAccessorProperty
| TSESTree.TSAbstractMethodDefinition
| TSESTree.TSAbstractPropertyDefinition,
): TSESTree.SourceLocation {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,6 @@ class Test {
`,
options: [{ accessibility: 'no-public' }],
},
// private members
{
code: `
class Test {
Expand All @@ -318,6 +317,20 @@ class Test {
`,
options: [{ accessibility: 'explicit' }],
},
{
code: `
class Test {
private accessor foo = 1;
}
`,
},
{
code: `
abstract class Test {
private abstract accessor foo: number;
}
`,
},
],
invalid: [
{
Expand Down Expand Up @@ -1919,6 +1932,98 @@ abstract class SomeClass {
},
{
code: `
class SomeClass {
accessor foo = 1;
}
`,
errors: [
{
column: 3,
endColumn: 15,
endLine: 3,
line: 3,
messageId: 'missingAccessibility',
suggestions: [
{
data: { type: 'public' },
messageId: 'addExplicitAccessibility',
output: `
class SomeClass {
public accessor foo = 1;
}
`,
},
{
data: { type: 'private' },
messageId: 'addExplicitAccessibility',
output: `
class SomeClass {
private accessor foo = 1;
}
`,
},
{
data: { type: 'protected' },
messageId: 'addExplicitAccessibility',
output: `
class SomeClass {
protected accessor foo = 1;
}
`,
},
],
},
],
options: [{ accessibility: 'explicit' }],
},
{
code: `
abstract class SomeClass {
abstract accessor foo: string;
}
`,
errors: [
{
column: 3,
endColumn: 24,
endLine: 3,
line: 3,
messageId: 'missingAccessibility',
suggestions: [
{
data: { type: 'public' },
messageId: 'addExplicitAccessibility',
output: `
abstract class SomeClass {
public abstract accessor foo: string;
}
`,
},
{
data: { type: 'private' },
messageId: 'addExplicitAccessibility',
output: `
abstract class SomeClass {
private abstract accessor foo: string;
}
`,
},
{
data: { type: 'protected' },
messageId: 'addExplicitAccessibility',
output: `
abstract class SomeClass {
protected abstract accessor foo: string;
}
`,
},
],
},
],
options: [{ accessibility: 'explicit' }],
},
{
code: `
class DecoratedClass {
constructor(@foo @bar() readonly arg: string) {}
@foo @bar() x: string;
Expand Down
Loading