Skip to content

Commit

Permalink
feat(biome_js_analyzer): implement useConsistentMemberAccessibility (
Browse files Browse the repository at this point in the history
…#3536)

Co-authored-by: Victorien Elvinger <[email protected]>
  • Loading branch information
seitarof and Conaclos authored Aug 30, 2024
1 parent c253e20 commit bba3412
Show file tree
Hide file tree
Showing 30 changed files with 2,207 additions and 40 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ our [guidelines for writing a good changelog entry](https://github.com/biomejs/b

### Analyzer

#### New features

- Implement [nursery/useConsistentMemberAccessibility](https://github.com/biomejs/biome/issues/3271). Contributed by @seitarof

#### Enhancements

- Implement [css suppression action](https://github.com/biomejs/biome/issues/3278). Contributed by @togami2864
Expand Down Expand Up @@ -322,6 +326,8 @@ our [guidelines for writing a good changelog entry](https://github.com/biomejs/b
- Add [nursery/noUselessEscapeInRegex](https://biomejs.dev/linter/rules/no-useless-escape-in-regex/).
Contributed by @Conaclos

- Add [nursery/useConsistentMemberAccessibility](https://biomejs.dev/linter/rules/use-consistent-member-accessibility/). Contributed by @seitarof

#### Enhancements

- [noInvalidUseBeforeDeclaration](https://biomejs.dev/linter/rules/no-invalid-use-before-declaration) now reports direct use of an enum member before its declaration.
Expand Down
10 changes: 10 additions & 0 deletions crates/biome_cli/src/execute/migrate/eslint_any_rule_to_biome.rs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 11 additions & 0 deletions crates/biome_cli/src/execute/migrate/eslint_eslint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -494,6 +494,11 @@ impl Deserializable for Rules {
result.insert(Rule::TypeScriptArrayType(conf));
}
}
"@typescript-eslint/explicit-member-accessibility" => {
if let Some(conf) = RuleConf::deserialize(&value, name, diagnostics) {
result.insert(Rule::TypeScriptExplicitMemberAccessibility(conf));
}
}
"@typescript-eslint/naming-convention" => {
if let Some(conf) = RuleConf::deserialize(&value, name, diagnostics) {
result.insert(Rule::TypeScriptNamingConvention(conf));
Expand Down Expand Up @@ -567,6 +572,9 @@ pub(crate) enum Rule {
// Eslint plugins
Jsxa11yArioaRoles(RuleConf<Box<eslint_jsxa11y::AriaRoleOptions>>),
TypeScriptArrayType(RuleConf<eslint_typescript::ArrayTypeOptions>),
TypeScriptExplicitMemberAccessibility(
RuleConf<eslint_typescript::ExplicitMemberAccessibilityOptions>,
),
TypeScriptNamingConvention(RuleConf<Box<eslint_typescript::NamingConventionSelection>>),
UnicornFilenameCase(RuleConf<eslint_unicorn::FilenameCaseOptions>),
// If you add new variants, don't forget to update [Rules::deserialize].
Expand All @@ -578,6 +586,9 @@ impl Rule {
Rule::NoRestrictedGlobals(_) => Cow::Borrowed("no-restricted-globals"),
Rule::Jsxa11yArioaRoles(_) => Cow::Borrowed("jsx-a11y/aria-role"),
Rule::TypeScriptArrayType(_) => Cow::Borrowed("@typescript-eslint/array-type"),
Rule::TypeScriptExplicitMemberAccessibility(_) => {
Cow::Borrowed("@typescript-eslint/explicit-member-accessibility")
}
Rule::TypeScriptNamingConvention(_) => {
Cow::Borrowed("@typescript-eslint/naming-convention")
}
Expand Down
14 changes: 14 additions & 0 deletions crates/biome_cli/src/execute/migrate/eslint_to_biome.rs
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,20 @@ fn migrate_eslint_rule(
}
}
}
eslint_eslint::Rule::TypeScriptExplicitMemberAccessibility(conf) => {
if migrate_eslint_any_rule(rules, &name, conf.severity(), opts, results) {
if let eslint_eslint::RuleConf::Option(severity, rule_options) = conf {
let group = rules.nursery.get_or_insert_with(Default::default);
group.use_consistent_member_accessibility =
Some(biome_config::RuleConfiguration::WithOptions(
biome_config::RuleWithOptions {
level: severity.into(),
options: rule_options.into(),
},
));
}
}
}
eslint_eslint::Rule::TypeScriptNamingConvention(conf) => {
if migrate_eslint_any_rule(rules, &name, conf.severity(), opts, results) {
let severity = conf.severity();
Expand Down
33 changes: 33 additions & 0 deletions crates/biome_cli/src/execute/migrate/eslint_typescript.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ use std::{cmp::Ordering, str::FromStr};
use biome_deserialize::Deserializable;
use biome_deserialize_macros::Deserializable;
use biome_js_analyze::{
lint::nursery::use_consistent_member_accessibility,
lint::style::{use_consistent_array_type, use_naming_convention},
utils::regex::RestrictedRegex,
};
Expand Down Expand Up @@ -44,6 +45,38 @@ impl From<ArrayType> for use_consistent_array_type::ConsistentArrayType {
}
}

#[derive(Debug, Default, Deserializable)]
#[deserializable(unknown_fields = "allow")]
pub(crate) struct ExplicitMemberAccessibilityOptions {
accessibility: Option<AccessibilityLevel>,
}
impl From<ExplicitMemberAccessibilityOptions>
for use_consistent_member_accessibility::ConsistentMemberAccessibilityOptions
{
fn from(value: ExplicitMemberAccessibilityOptions) -> Self {
use_consistent_member_accessibility::ConsistentMemberAccessibilityOptions {
accessibility: value.accessibility.map(|x| x.into()).unwrap_or_default(),
}
}
}
#[derive(Clone, Copy, Debug, Default, Deserializable)]
pub(crate) enum AccessibilityLevel {
#[default]
#[deserializable(rename = "no-public")]
NoPublic,
Explicit,
None,
}
impl From<AccessibilityLevel> for use_consistent_member_accessibility::Accessibility {
fn from(value: AccessibilityLevel) -> Self {
match value {
AccessibilityLevel::NoPublic => Self::NoPublic,
AccessibilityLevel::Explicit => Self::Explicit,
AccessibilityLevel::None => Self::None,
}
}
}

#[derive(Debug)]
pub(crate) struct NamingConventionOptions(Vec<NamingConventionSelection>);
impl NamingConventionOptions {
Expand Down
Loading

0 comments on commit bba3412

Please sign in to comment.