Skip to content

Commit

Permalink
fix: rename useComponentsOnlyModule => useComponentExportOnlyModules
Browse files Browse the repository at this point in the history
  • Loading branch information
GunseiKPaseri committed Aug 27, 2024
1 parent 286505c commit fba28fe
Show file tree
Hide file tree
Showing 75 changed files with 71 additions and 81 deletions.

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

14 changes: 7 additions & 7 deletions crates/biome_configuration/src/analyzer/linter/rules.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3020,8 +3020,8 @@ pub struct Nursery {
Option<RuleConfiguration<biome_js_analyze::options::UseAdjacentOverloadSignatures>>,
#[doc = "Enforce declaring components only within modules that export React Components exclusively."]
#[serde(skip_serializing_if = "Option::is_none")]
pub use_components_only_module:
Option<RuleConfiguration<biome_js_analyze::options::UseComponentsOnlyModule>>,
pub use_component_export_only_modules:
Option<RuleConfiguration<biome_js_analyze::options::UseComponentExportOnlyModules>>,
#[doc = "Enforce the use of new for all builtins, except String, Number, Boolean, Symbol and BigInt."]
#[serde(skip_serializing_if = "Option::is_none")]
pub use_consistent_builtin_instantiation:
Expand Down Expand Up @@ -3159,7 +3159,7 @@ impl Nursery {
"noValueAtRule",
"noYodaExpression",
"useAdjacentOverloadSignatures",
"useComponentsOnlyModule",
"useComponentExportOnlyModules",
"useConsistentBuiltinInstantiation",
"useConsistentCurlyBraces",
"useConsistentGridAreas",
Expand Down Expand Up @@ -3509,7 +3509,7 @@ impl Nursery {
index_set.insert(RuleFilter::Rule(Self::GROUP_NAME, Self::GROUP_RULES[38]));
}
}
if let Some(rule) = self.use_components_only_module.as_ref() {
if let Some(rule) = self.use_component_export_only_modules.as_ref() {
if rule.is_enabled() {
index_set.insert(RuleFilter::Rule(Self::GROUP_NAME, Self::GROUP_RULES[39]));
}
Expand Down Expand Up @@ -3818,7 +3818,7 @@ impl Nursery {
index_set.insert(RuleFilter::Rule(Self::GROUP_NAME, Self::GROUP_RULES[38]));
}
}
if let Some(rule) = self.use_components_only_module.as_ref() {
if let Some(rule) = self.use_component_export_only_modules.as_ref() {
if rule.is_disabled() {
index_set.insert(RuleFilter::Rule(Self::GROUP_NAME, Self::GROUP_RULES[39]));
}
Expand Down Expand Up @@ -4120,8 +4120,8 @@ impl Nursery {
.use_adjacent_overload_signatures
.as_ref()
.map(|conf| (conf.level(), conf.get_options())),
"useComponentsOnlyModule" => self
.use_components_only_module
"useComponentExportOnlyModules" => self
.use_component_export_only_modules
.as_ref()
.map(|conf| (conf.level(), conf.get_options())),
"useConsistentBuiltinInstantiation" => self
Expand Down
2 changes: 1 addition & 1 deletion crates/biome_diagnostics_categories/src/categories.rs
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ define_categories! {
"lint/nursery/noYodaExpression": "https://biomejs.dev/linter/rules/no-yoda-expression",
"lint/nursery/useAdjacentOverloadSignatures": "https://biomejs.dev/linter/rules/use-adjacent-overload-signatures",
"lint/nursery/useBiomeSuppressionComment": "https://biomejs.dev/linter/rules/use-biome-suppression-comment",
"lint/nursery/useComponentsOnlyModule": "https://biomejs.dev/linter/rules/use-components-only-module",
"lint/nursery/useComponentExportOnlyModules": "https://biomejs.dev/linter/rules/use-components-only-module",
"lint/nursery/useConsistentBuiltinInstantiation": "https://biomejs.dev/linter/rules/use-consistent-new-builtin",
"lint/nursery/useConsistentCurlyBraces": "https://biomejs.dev/linter/rules/use-consistent-curly-braces",
"lint/nursery/useConsistentGridAreas": "https://biomejs.dev/linter/rules/use-consistent-grid-areas",
Expand Down
4 changes: 2 additions & 2 deletions crates/biome_js_analyze/src/lint/nursery.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ pub mod no_useless_string_concat;
pub mod no_useless_undefined_initialization;
pub mod no_yoda_expression;
pub mod use_adjacent_overload_signatures;
pub mod use_components_only_module;
pub mod use_component_export_only_modules;
pub mod use_consistent_builtin_instantiation;
pub mod use_consistent_curly_braces;
pub mod use_date_now;
Expand Down Expand Up @@ -66,7 +66,7 @@ declare_lint_group! {
self :: no_useless_undefined_initialization :: NoUselessUndefinedInitialization ,
self :: no_yoda_expression :: NoYodaExpression ,
self :: use_adjacent_overload_signatures :: UseAdjacentOverloadSignatures ,
self :: use_components_only_module :: UseComponentsOnlyModule ,
self :: use_component_export_only_modules :: UseComponentExportOnlyModules ,
self :: use_consistent_builtin_instantiation :: UseConsistentBuiltinInstantiation ,
self :: use_consistent_curly_braces :: UseConsistentCurlyBraces ,
self :: use_date_now :: UseDateNow ,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,9 +101,9 @@ declare_lint_rule! {
/// [Vite]: https://vitejs.dev/
/// [`camelCase`]: https://en.wikipedia.org/wiki/Camel_case
/// [`PascalCase`]: https://en.wikipedia.org/wiki/Camel_case
pub UseComponentsOnlyModule {
pub UseComponentExportOnlyModules {
version: "next",
name: "useComponentsOnlyModule",
name: "useComponentExportOnlyModules",
language: "jsx",
sources: &[RuleSource::EslintReactRefresh("only-export-components")],
source_kind: RuleSourceKind::Inspired,
Expand All @@ -114,7 +114,7 @@ declare_lint_rule! {
#[derive(Debug, Clone, Deserialize, Deserializable, Eq, PartialEq, Serialize, Default)]
#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
#[serde(rename_all = "camelCase", deny_unknown_fields)]
pub struct UseComponentsOnlyModuleOptions {
pub struct UseComponentExportOnlyModulesOptions {
// Allow the export of constants.
// (This option is for environments that support it, such as [Vite])
#[serde(default)]
Expand All @@ -131,18 +131,18 @@ enum ErrorType {
NoExport,
}

pub struct UseComponentsOnlyModuleState {
pub struct UseComponentExportOnlyModulesState {
error: ErrorType,
range: TextRange,
}

const JSX_FILE_EXT: [&str; 2] = [".jsx", ".tsx"];

impl Rule for UseComponentsOnlyModule {
impl Rule for UseComponentExportOnlyModules {
type Query = Ast<JsModule>;
type State = UseComponentsOnlyModuleState;
type State = UseComponentExportOnlyModulesState;
type Signals = Vec<Self::State>;
type Options = UseComponentsOnlyModuleOptions;
type Options = UseComponentExportOnlyModulesOptions;

fn run(ctx: &RuleContext<Self>) -> Self::Signals {
if let Some(file_name) = ctx.file_path().file_name().and_then(|x| x.to_str()) {
Expand Down Expand Up @@ -217,32 +217,32 @@ impl Rule for UseComponentsOnlyModule {
}
});

if !exported_component_ids.is_empty() {
return exported_non_component_ids
.iter()
.filter_map(|id| {
let range = id.identifier.as_ref().map_or_else(
|| id.exported.as_ref().map(|exported| exported.range()),
|identifier| Some(identifier.range()),
);
range.map(|range| UseComponentsOnlyModuleState {
error: ErrorType::ExportedNonComponentWithComponent,
range,
})
})
.collect();
}
if !exported_component_ids.is_empty() {
return exported_non_component_ids
.iter()
.filter_map(|id| {
let range = id.identifier.as_ref().map_or_else(
|| id.exported.as_ref().map(|exported| exported.range()),
|identifier| Some(identifier.range()),
);
range.map(|range| UseComponentExportOnlyModulesState {
error: ErrorType::ExportedNonComponentWithComponent,
range,
})
})
.collect();
}

local_component_ids
.map(|id| UseComponentsOnlyModuleState {
.map(|id| UseComponentExportOnlyModulesState {
error: if exported_non_component_ids.is_empty() {
ErrorType::UnexportedComponent
} else {
ErrorType::NoExport
},
range: id,
})
.collect::<Vec<UseComponentsOnlyModuleState>>()
.collect::<Vec<UseComponentExportOnlyModulesState>>()
}

fn diagnostic(_ctx: &RuleContext<Self>, state: &Self::State) -> Option<RuleDiagnostic> {
Expand Down
2 changes: 1 addition & 1 deletion crates/biome_js_analyze/src/options.rs

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

Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
---
source: crates/biome_js_analyze/tests/spec_tests.rs
assertion_line: 84
expression: invalid_component_and_constant.jsx
---
# Input
Expand All @@ -12,7 +11,7 @@ export const Foo = () => {}

# Diagnostics
```
invalid_component_and_constant.jsx:1:14 lint/nursery/useComponentsOnlyModule ━━━━━━━━━━━━━━━━━━━━━━━
invalid_component_and_constant.jsx:1:14 lint/nursery/useComponentExportOnlyModules ━━━━━━━━━━━━━━━━━
! Exporting a non-component with components is not allowed.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
---
source: crates/biome_js_analyze/tests/spec_tests.rs
assertion_line: 84
expression: invalid_component_and_default_class.jsx
---
# Input
Expand All @@ -12,7 +11,7 @@ export default class hoge {

# Diagnostics
```
invalid_component_and_default_class.jsx:2:22 lint/nursery/useComponentsOnlyModule ━━━━━━━━━━━━━━━━━━
invalid_component_and_default_class.jsx:2:22 lint/nursery/useComponentExportOnlyModules ━━━━━━━━━━━━
! Exporting a non-component with components is not allowed.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
---
source: crates/biome_js_analyze/tests/spec_tests.rs
assertion_line: 84
expression: invalid_component_and_default_function.jsx
---
# Input
Expand All @@ -14,7 +13,7 @@ export default function hoge () {

# Diagnostics
```
invalid_component_and_default_function.jsx:2:25 lint/nursery/useComponentsOnlyModule ━━━━━━━━━━━━━━━
invalid_component_and_default_function.jsx:2:25 lint/nursery/useComponentExportOnlyModules ━━━━━━━━━━
! Exporting a non-component with components is not allowed.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
---
source: crates/biome_js_analyze/tests/spec_tests.rs
assertion_line: 84
expression: invalid_component_and_default_variable.jsx
---
# Input
Expand All @@ -12,7 +11,7 @@ export default hoge

# Diagnostics
```
invalid_component_and_default_variable.jsx:3:16 lint/nursery/useComponentsOnlyModule ━━━━━━━━━━━━━━━
invalid_component_and_default_variable.jsx:3:16 lint/nursery/useComponentExportOnlyModules ━━━━━━━━━━
! Exporting a non-component with components is not allowed.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
---
source: crates/biome_js_analyze/tests/spec_tests.rs
assertion_line: 84
expression: invalid_component_and_enum.tsx
---
# Input
Expand All @@ -16,7 +15,7 @@ export enum SampleEnum {

# Diagnostics
```
invalid_component_and_enum.tsx:2:13 lint/nursery/useComponentsOnlyModule ━━━━━━━━━━━━━━━━━━━━━━━━━━━
invalid_component_and_enum.tsx:2:13 lint/nursery/useComponentExportOnlyModules ━━━━━━━━━━━━━━━━━━━━━
! Exporting a non-component with components is not allowed.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export const foo = () => {}

# Diagnostics
```
invalid_component_and_export_non_in_ignore_export_names.jsx:3:14 lint/nursery/useComponentsOnlyModule ━━━━━━━━━━
invalid_component_and_export_non_in_ignore_export_names.jsx:3:14 lint/nursery/useComponentExportOnlyModules ━━━━━━━━━━
! Exporting a non-component with components is not allowed.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"enabled": true,
"rules": {
"nursery": {
"useComponentsOnlyModule": {
"useComponentExportOnlyModules": {
"level": "error",
"options": {
"allowExportNames": ["loader", "meta"]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
---
source: crates/biome_js_analyze/tests/spec_tests.rs
assertion_line: 84
expression: invalid_component_and_function.jsx
---
# Input
Expand All @@ -11,7 +10,7 @@ export const Bar = () => {}

# Diagnostics
```
invalid_component_and_function.jsx:1:14 lint/nursery/useComponentsOnlyModule ━━━━━━━━━━━━━━━━━━━━━━━
invalid_component_and_function.jsx:1:14 lint/nursery/useComponentExportOnlyModules ━━━━━━━━━━━━━━━━━
! Exporting a non-component with components is not allowed.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export const Bar = () => {}

# Diagnostics
```
invalid_component_and_function_with_ignore_constant_export.jsx:1:14 lint/nursery/useComponentsOnlyModule ━━━━━━━━━━
invalid_component_and_function_with_ignore_constant_export.jsx:1:14 lint/nursery/useComponentExportOnlyModules ━━━━━━━━━━
! Exporting a non-component with components is not allowed.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"enabled": true,
"rules": {
"nursery": {
"useComponentsOnlyModule": {
"useComponentExportOnlyModules": {
"level": "error",
"options": {
"allowConstantExport": true
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
---
source: crates/biome_js_analyze/tests/spec_tests.rs
assertion_line: 84
expression: invalid_component_and_variable_clause.jsx
---
# Input
Expand All @@ -14,7 +13,7 @@ export { foo, Bar, baz as qux }

# Diagnostics
```
invalid_component_and_variable_clause.jsx:4:10 lint/nursery/useComponentsOnlyModule ━━━━━━━━━━━━━━━━
invalid_component_and_variable_clause.jsx:4:10 lint/nursery/useComponentExportOnlyModules ━━━━━━━━━━
! Exporting a non-component with components is not allowed.
Expand All @@ -34,7 +33,7 @@ invalid_component_and_variable_clause.jsx:4:10 lint/nursery/useComponentsOnlyMod
```

```
invalid_component_and_variable_clause.jsx:4:27 lint/nursery/useComponentsOnlyModule ━━━━━━━━━━━━━━━━
invalid_component_and_variable_clause.jsx:4:27 lint/nursery/useComponentExportOnlyModules ━━━━━━━━━━
! Exporting a non-component with components is not allowed.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
---
source: crates/biome_js_analyze/tests/spec_tests.rs
assertion_line: 84
expression: invalid_hooked_component.jsx
---
# Input
Expand All @@ -12,7 +11,7 @@ export default hoge(Fuga)

# Diagnostics
```
invalid_hooked_component.jsx:1:7 lint/nursery/useComponentsOnlyModule ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
invalid_hooked_component.jsx:1:7 lint/nursery/useComponentExportOnlyModules ━━━━━━━━━━━━━━━━━━━━━━━━
! Components should be exported.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
---
source: crates/biome_js_analyze/tests/spec_tests.rs
assertion_line: 84
expression: invalid_hooked_non_component.jsx
---
# Input
Expand All @@ -13,7 +12,7 @@ export default memo(func)

# Diagnostics
```
invalid_hooked_non_component.jsx:3:16 lint/nursery/useComponentsOnlyModule ━━━━━━━━━━━━━━━━━━━━━━━━━
invalid_hooked_non_component.jsx:3:16 lint/nursery/useComponentExportOnlyModules ━━━━━━━━━━━━━━━━━━━
! Exporting a non-component with components is not allowed.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
---
source: crates/biome_js_analyze/tests/spec_tests.rs
assertion_line: 84
expression: invalid_unexported_component.jsx
---
# Input
Expand All @@ -11,7 +10,7 @@ createRoot(document.getElementById("root")).render(<App />);

# Diagnostics
```
invalid_unexported_component.jsx:1:7 lint/nursery/useComponentsOnlyModule ━━━━━━━━━━━━━━━━━━━━━━━━━━
invalid_unexported_component.jsx:1:7 lint/nursery/useComponentExportOnlyModules ━━━━━━━━━━━━━━━━━━━━
! Unexported components are not allowed.
Expand Down
Loading

0 comments on commit fba28fe

Please sign in to comment.