Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: useExhaustiveDependencies not recommended #4294

Open
wants to merge 9 commits into
base: next
Choose a base branch
from
Open
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
12 changes: 12 additions & 0 deletions .changeset/reduced_accepted_values.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
---
cli: major
---

# Reduced accepted values for formatter options

- The option `--quote-style` doesn't accept `Single` and `Double` anymore.
- The option `--quote-properties` doesn't accept `AsNeeded` and `Preserve` anymore.
- The option `--semicolons` doesn't accept `AsNeeded` and `Always` anymore.
- The option `--arrow-parenthesis` doesn't accept `AsNeeded` and `Always` anymore.
- The option `--trailing-commas` doesn't accept `ES5`, `All` and `None` anymore.
- The option `--attribute-position` doesn't accept `Single` and `Multiline` anymore.
9 changes: 9 additions & 0 deletions .changeset/reduced_accepted_values_for_js_options.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
---
biome_js_formatter: major
---

# Reduced accepted values for js options

- The type `Semicolon` can't be converted from `"AsNeeded"` and `"Always"`.
- The type `TrailingCommas` can't be converted from `"ES5"`, `"All"` and `"None"`.
- The type `ArrowParenthesis` can't be converted from `"AsNeeded"` and `"Always"`.
9 changes: 9 additions & 0 deletions .changeset/reduced_accepted_values_of_options.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
---
biome_formatter: major
---

# Reduced accepted values of options

- The type `QuoteStyle` can't be converted from `"Double"` and `"Single"`.
- The type `QuoteProperties` can't be converted from `"AsNeeded"` and `"Preserve"`.
- The type `AttributePosition` can't be converted from `"Multiline"` and `"Auto"`.
9 changes: 9 additions & 0 deletions .changeset/remove_biome_log_dir.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
---
cli: major
---

# Remove `BIOME_LOG_DIR`

The environment variable `BIOME_LOG_DIR` isn't supported anymore.

Use `BIOME_LOG_PATH` instead.
15 changes: 15 additions & 0 deletions .changeset/remove_indentsize_option.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
---
cli: major
---

# Remove `indentSize` deprecated option

The deprecated option `indentSize`, and its relative CLI options, has been removed:
- Configuration file: `formatter.indentSize`
- Configuration file: `javascript.formatter.indentSize`
- Configuration file: `json.formatter.indentSize`
- CLI option `--indent-size`
- CLI option `--javascript-formatter-indent-size`
- CLI option `--json-formatter-indent-size`

Use `indentWidth` and its relative CLI options instead.
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
cli: major
---

# Remove support for `rome-ignore` suppression comment

Use the `biome-ignore` suppression comment instead.
5 changes: 5 additions & 0 deletions .changeset/remove_support_for_romejson.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
cli: major
---

# Remove support for `rome.json`
23 changes: 23 additions & 0 deletions .changeset/remove_trailingcomma.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
---
cli: major
---

# Remove `trailingComma`

Removed the option `trailingComma` from the configuration and the CLI. Use the option `trailingCommas` instead:

```diff
{
"javascript": {
"formatter": {
- "trailingComma": "es5"
+ "trailingCommas": "es5"
}
}
}
```

```diff
-biome format --trailing-comma=es5
+biome format --trailing-commas=es5
```
17 changes: 17 additions & 0 deletions .changeset/removed_apply_and_apply_unsafe.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
---
cli: major
---

# Removed `--apply` and `--apply-unsafe`

The CLI options `--apply` and `--apply-unasfe` aren't accepted anymore. Use `--write` and `--write --unafe` instead:

```diff
-biome check --apply-unsafe
+biome check --write --unsafe
```

```diff
-biome check --apply
+biome check --write
```
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
---
cli: major
---

# The rule `useExhaustiveDependencies` isn't recommended anymore

The rule `useExhaustiveDependencies` is not recommended anymore. If your codebase uses `react` and relies on that rule, you have to enable it:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hopefully this will be improved before the actual release then.



```jsonc
// biome.json
{
"linter": {
"rules": {
"correctness": {
"useExhaustiveDependencies": "error"
}
}
}
}
```
3 changes: 2 additions & 1 deletion Cargo.lock

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

80 changes: 5 additions & 75 deletions crates/biome_analyze/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,16 +45,13 @@ pub use crate::signals::{
};
pub use crate::syntax::{Ast, SyntaxVisitor};
pub use crate::visitor::{NodeVisitor, Visitor, VisitorContext, VisitorFinishContext};
pub use suppression_action::{ApplySuppression, SuppressionAction};

use biome_console::markup;
use biome_diagnostics::{
category, Applicability, Diagnostic, DiagnosticExt, DiagnosticTags, Severity,
};
use biome_diagnostics::{category, Applicability, Diagnostic, DiagnosticExt, DiagnosticTags};
use biome_rowan::{
AstNode, BatchMutation, Direction, Language, SyntaxElement, SyntaxToken, TextLen, TextRange,
TextSize, TokenAtOffset, TriviaPiece, TriviaPieceKind, WalkEvent,
AstNode, BatchMutation, Direction, Language, SyntaxElement, SyntaxToken, TextRange, TextSize,
TokenAtOffset, TriviaPieceKind, WalkEvent,
};
pub use suppression_action::{ApplySuppression, SuppressionAction};

/// The analyzer is the main entry point into the `biome_analyze` infrastructure.
/// Its role is to run a collection of [Visitor]s over a syntax tree, with each
Expand Down Expand Up @@ -474,27 +471,11 @@ where
}
};

if matches!(kind, SuppressionKind::Deprecated) {
let signal = DiagnosticSignal::new(move || {
SuppressionDiagnostic::new(
category!("suppressions/deprecatedSuppressionComment"),
range,
"// rome-ignore is deprecated, use // biome-ignore instead",
)
.with_tags(DiagnosticTags::DEPRECATED_CODE)
.with_severity(Severity::Information)
})
.with_action(move || create_suppression_comment_action(token));

(self.emit_signal)(&signal)?;
}

let (rule, instance) = match kind {
SuppressionKind::Everything => (None, None),
SuppressionKind::Rule(rule) => (Some(rule), None),
SuppressionKind::RuleInstance(rule, instance) => (Some(rule), Some(instance)),
SuppressionKind::MaybeLegacy(rule) => (Some(rule), None),
SuppressionKind::Deprecated => (None, None),
};

if let Some(rule) = rule {
Expand Down Expand Up @@ -637,55 +618,6 @@ where
}
}

fn create_suppression_comment_action<L: Language>(
token: &SyntaxToken<L>,
) -> Option<AnalyzerAction<L>> {
let first_node = token.parent()?;
let mut new_leading_trivia = vec![];
let mut token_text = String::new();
let mut new_trailing_trivia = vec![];
let mut mutation = BatchMutation::new(first_node);

for piece in token.leading_trivia().pieces() {
if !piece.is_comments() {
new_leading_trivia.push(TriviaPiece::new(piece.kind(), piece.text_len()));
token_text.push_str(piece.text());
}

if piece.text().contains("rome-ignore") {
let new_text = piece.text().replace("rome-ignore", "biome-ignore");
new_leading_trivia.push(TriviaPiece::new(piece.kind(), new_text.text_len()));
token_text.push_str(&new_text);
}
}

token_text.push_str(token.text_trimmed());

for piece in token.trailing_trivia().pieces() {
new_trailing_trivia.push(TriviaPiece::new(piece.kind(), piece.text_len()));
token_text.push_str(piece.text());
}

let new_token = SyntaxToken::new_detached(
token.kind(),
&token_text,
new_leading_trivia,
new_trailing_trivia,
);

mutation.replace_token_discard_trivia(token.clone(), new_token);
Some(AnalyzerAction {
mutation,
applicability: Applicability::MaybeIncorrect,
category: ActionCategory::QuickFix,
message: markup! {
"Use // biome-ignore instead"
}
.to_owned(),
rule_name: None,
})
}

fn range_match(filter: Option<TextRange>, range: TextRange) -> bool {
filter.map_or(true, |filter| filter.intersect(range).is_some())
}
Expand Down Expand Up @@ -717,8 +649,6 @@ pub enum SuppressionKind<'a> {
RuleInstance(&'a str, &'a str),
/// A suppression using the legacy syntax to disable a specific rule eg. `// biome-ignore lint(style/useWhile)`
MaybeLegacy(&'a str),
/// `rome-ignore` is legacy
Deprecated,
}

fn update_suppression<L: Language>(
Expand Down Expand Up @@ -782,7 +712,7 @@ pub struct SuppressionCommentEmitterPayload<'a, L: Language> {
pub token_offset: TokenAtOffset<SyntaxToken<L>>,
/// A [BatchMutation] where the consumer can apply the suppression comment
pub mutation: &'a mut BatchMutation<L>,
/// A string equals to "rome-ignore: lint(<RULE_GROUP>/<RULE_NAME>)"
/// A string equals to "biome-ignore: lint(<RULE_GROUP>/<RULE_NAME>)"
pub suppression_text: &'a str,
/// The original range of the diagnostic where the rule was triggered
pub diagnostic_text_range: &'a TextRange,
Expand Down
17 changes: 5 additions & 12 deletions crates/biome_cli/src/commands/check.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@ use biome_service::{configuration::LoadedConfiguration, DynRef, Workspace, Works
use std::ffi::OsString;

pub(crate) struct CheckCommandPayload {
pub(crate) apply: bool,
pub(crate) apply_unsafe: bool,
pub(crate) write: bool,
pub(crate) fix: bool,
pub(crate) unsafe_: bool,
Expand Down Expand Up @@ -136,16 +134,11 @@ impl CommandRunner for CheckCommandPayload {
console: &mut dyn Console,
_workspace: &dyn Workspace,
) -> Result<Execution, CliDiagnostic> {
let fix_file_mode = determine_fix_file_mode(
FixFileModeOptions {
apply: self.apply,
apply_unsafe: self.apply_unsafe,
write: self.write,
fix: self.fix,
unsafe_: self.unsafe_,
},
console,
)?;
let fix_file_mode = determine_fix_file_mode(FixFileModeOptions {
write: self.write,
fix: self.fix,
unsafe_: self.unsafe_,
})?;

Ok(Execution::new(TraversalMode::Check {
fix_file_mode,
Expand Down
6 changes: 1 addition & 5 deletions crates/biome_cli/src/commands/daemon.rs
Original file line number Diff line number Diff line change
Expand Up @@ -232,11 +232,7 @@ fn setup_tracing_subscriber(log_path: Option<PathBuf>, log_file_name_prefix: Opt
pub fn default_biome_log_path() -> PathBuf {
match env::var_os("BIOME_LOG_PATH") {
Some(directory) => PathBuf::from(directory),
// TODO: Remove in Biome v2, and use the None part as fallback.
None => match env::var_os("BIOME_LOG_DIR") {
Some(directory) => PathBuf::from(directory),
None => biome_fs::ensure_cache_dir().join("biome-logs"),
},
None => biome_fs::ensure_cache_dir().join("biome-logs"),
}
}

Expand Down
Loading