Skip to content

Commit

Permalink
fix(useConsistentMemberAccessibility): ignore #private class members
Browse files Browse the repository at this point in the history
  • Loading branch information
Conaclos committed Oct 14, 2024
1 parent 1d240cc commit 355195e
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 38 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,8 @@ our [guidelines for writing a good changelog entry](https://github.com/biomejs/b

Contributed by @Conaclos

- [useConsistentMemberAccessibility](https://biomejs.dev/linter/rules/use-consistent-member-accessibility/) now ignore private class members such as `#property` ([#4276](https://github.com/biomejs/biome/issues/4276)). Contributed by @Conaclos

- [noUnknownFunction](https://biomejs.dev/linter/rules/no-unknown-function/) correctly handles `calc-size` function ([#4212](https://github.com/biomejs/biome/issues/4212)).

The following code `calc-size` is no longer reported as unknown:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ use biome_analyze::{
use biome_console::markup;
use biome_deserialize_macros::Deserializable;
use biome_js_syntax::{
JsConstructorClassMember, JsGetterClassMember, JsMethodClassMember, JsPropertyClassMember,
JsSetterClassMember, TsAccessibilityModifier, TsConstructorSignatureClassMember,
TsGetterSignatureClassMember, TsMethodSignatureClassMember, TsPropertyParameter,
TsPropertySignatureClassMember, TsSetterSignatureClassMember,
AnyJsClassMemberName, JsConstructorClassMember, JsGetterClassMember, JsMethodClassMember,
JsPropertyClassMember, JsSetterClassMember, TsAccessibilityModifier,
TsConstructorSignatureClassMember, TsGetterSignatureClassMember, TsMethodSignatureClassMember,
TsPropertyParameter, TsPropertySignatureClassMember, TsSetterSignatureClassMember,
};
use biome_rowan::{declare_node_union, AstNode, TextRange};
use serde::{Deserialize, Serialize};
Expand Down Expand Up @@ -246,6 +246,10 @@ impl Rule for UseConsistentMemberAccessibility {

fn run(ctx: &RuleContext<Self>) -> Self::Signals {
let node = ctx.query();
// Ignore private class members such as `#property`
if node.is_private_class_member_name() {
return None;
}
let accessibility = node.accessibility_modifier();
let options = ctx.options();
match &options.accessibility {
Expand Down Expand Up @@ -304,6 +308,25 @@ declare_node_union! {
}

impl AnyJsMemberWithAccessibility {
fn is_private_class_member_name(&self) -> bool {
let name = match self {
Self::JsConstructorClassMember(_)
| Self::TsConstructorSignatureClassMember(_)
| Self::TsPropertyParameter(_) => {
return false;
}
Self::JsPropertyClassMember(member) => member.name(),
Self::JsMethodClassMember(member) => member.name(),
Self::JsGetterClassMember(member) => member.name(),
Self::JsSetterClassMember(member) => member.name(),
Self::TsMethodSignatureClassMember(member) => member.name(),
Self::TsPropertySignatureClassMember(member) => member.name(),
Self::TsGetterSignatureClassMember(member) => member.name(),
Self::TsSetterSignatureClassMember(member) => member.name(),
};
matches!(name, Ok(AnyJsClassMemberName::JsPrivateClassMemberName(_)))
}

fn accessibility_modifier(&self) -> Option<TsAccessibilityModifier> {
match self {
Self::JsConstructorClassMember(member) => member
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,37 +52,3 @@ class ValidExplicit9 {
}

```

# Diagnostics
```
validExplicit.ts:44:3 lint/nursery/useConsistentMemberAccessibility ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
! Missing accessibility modifier on this member.
43 │ class ValidExplicit9 {
> 44 │ #foo = 1;
│ ^^^^^^^^^
45 │ #bar() {}
46 │ }
i Use public to explicitly make a member public.
```

```
validExplicit.ts:45:3 lint/nursery/useConsistentMemberAccessibility ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
! Missing accessibility modifier on this member.
43 │ class ValidExplicit9 {
44 │ #foo = 1;
> 45 │ #bar() {}
│ ^^^^^^^^^
46 │ }
47 │
i Use public to explicitly make a member public.
```

0 comments on commit 355195e

Please sign in to comment.