Skip to content

Commit

Permalink
fix(eslint-plugin): [explicit-member-accessibility] report `TSAbstrac…
Browse files Browse the repository at this point in the history
…tClassProperty` properly
  • Loading branch information
rafaelss95 committed Sep 17, 2021
1 parent b1df817 commit 07ea7bc
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 8 deletions.
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import {
AST_NODE_TYPES,
TSESTree,
AST_TOKEN_TYPES,
TSESLint,
TSESTree,
} from '@typescript-eslint/experimental-utils';
import * as util from '../util';

Expand Down Expand Up @@ -97,13 +97,13 @@ export default util.createRule<Options, MessageIds>({
fix: TSESLint.ReportFixFunction | null = null,
): void {
context.report({
node: node,
messageId: messageId,
node,
messageId,
data: {
type: nodeType,
name: nodeName,
},
fix: fix,
fix,
});
}

Expand Down Expand Up @@ -162,8 +162,9 @@ export default util.createRule<Options, MessageIds>({
*/
function getUnwantedPublicAccessibilityFixer(
node:
| TSESTree.MethodDefinition
| TSESTree.ClassProperty
| TSESTree.MethodDefinition
| TSESTree.TSAbstractClassProperty
| TSESTree.TSParameterProperty,
): TSESLint.ReportFixFunction {
return function (fixer: TSESLint.RuleFixer): TSESLint.RuleFix {
Expand Down Expand Up @@ -202,7 +203,7 @@ export default util.createRule<Options, MessageIds>({
* @param classProperty The node representing a ClassProperty.
*/
function checkPropertyAccessibilityModifier(
classProperty: TSESTree.ClassProperty,
classProperty: TSESTree.ClassProperty | TSESTree.TSAbstractClassProperty,
): void {
const nodeType = 'class property';

Expand Down Expand Up @@ -274,7 +275,8 @@ export default util.createRule<Options, MessageIds>({

return {
TSParameterProperty: checkParameterPropertyAccessibilityModifier,
ClassProperty: checkPropertyAccessibilityModifier,
'ClassProperty, TSAbstractClassProperty':
checkPropertyAccessibilityModifier,
MethodDefinition: checkMethodAccessibilityModifier,
};
},
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import rule from '../../src/rules/explicit-member-accessibility';
import { RuleTester, noFormat } from '../RuleTester';
import { noFormat, RuleTester } from '../RuleTester';

const ruleTester = new RuleTester({
parser: '@typescript-eslint/parser',
Expand Down Expand Up @@ -1070,6 +1070,47 @@ class EnsureWhiteSPaceSpan {
output: `
class EnsureWhiteSPaceSpan {
/* */ constructor() {}
}
`,
},
{
// https://github.com/typescript-eslint/typescript-eslint/issues/3835
code: `
abstract class SomeClass {
abstract x: string;
}
`,
options: [{ accessibility: 'explicit' }],
errors: [
{
messageId: 'missingAccessibility',
line: 3,
column: 3,
},
],
},
{
code: `
abstract class SomeClass {
public abstract x: string;
}
`,
options: [
{
accessibility: 'no-public',
overrides: { parameterProperties: 'no-public' },
},
],
errors: [
{
messageId: 'unwantedPublicAccessibility',
line: 3,
column: 3,
},
],
output: `
abstract class SomeClass {
abstract x: string;
}
`,
},
Expand Down

0 comments on commit 07ea7bc

Please sign in to comment.