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: remove support for rome-ignore #4252

Merged
merged 7 commits into from
Oct 11, 2024
Merged
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
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`
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
19 changes: 2 additions & 17 deletions crates/biome_cli/src/commands/mod.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crate::changed::{get_changed_files, get_staged_files};
use crate::cli_options::{cli_options, CliOptions, CliReporter, ColorsArg};
use crate::diagnostics::{DeprecatedArgument, DeprecatedConfigurationFile};
use crate::diagnostics::DeprecatedArgument;
use crate::execute::Stdin;
use crate::logging::LoggingKind;
use crate::{
Expand All @@ -22,7 +22,7 @@ use biome_configuration::{
};
use biome_configuration::{BiomeDiagnostic, PartialConfiguration};
use biome_console::{markup, Console, ConsoleExt};
use biome_diagnostics::{Diagnostic, PrintDiagnostic};
use biome_diagnostics::PrintDiagnostic;
use biome_fs::{BiomePath, FileSystem};
use biome_service::configuration::{
load_configuration, load_editorconfig, LoadedConfiguration, PartialConfigurationExt,
Expand Down Expand Up @@ -618,21 +618,6 @@ pub(crate) fn validate_configuration_diagnostics(
console: &mut dyn Console,
verbose: bool,
) -> Result<(), CliDiagnostic> {
if let Some(file_path) = loaded_configuration
.file_path
.as_ref()
.and_then(|f| f.file_name())
.and_then(|f| f.to_str())
{
if file_path == "rome.json" {
let diagnostic = DeprecatedConfigurationFile::new(file_path);
if diagnostic.tags().is_verbose() && verbose {
console.error(markup! {{PrintDiagnostic::verbose(&diagnostic)}})
} else {
console.error(markup! {{PrintDiagnostic::simple(&diagnostic)}})
}
}
}
let diagnostics = loaded_configuration.as_diagnostics_iter();
for diagnostic in diagnostics {
if diagnostic.tags().is_verbose() && verbose {
Expand Down
20 changes: 0 additions & 20 deletions crates/biome_cli/src/diagnostics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -475,26 +475,6 @@ impl Termination for CliDiagnostic {
}
}

#[derive(Debug, Diagnostic)]
#[diagnostic(
category = "internalError/fs",
severity = Warning,
message(
description = "The configuration file {path} is deprecated. Use biome.json instead.",
message("The configuration file "<Emphasis>{self.path}</Emphasis>" is deprecated. Use "<Emphasis>"biome.json"</Emphasis>" instead."),
)
)]
pub struct DeprecatedConfigurationFile {
#[location(resource)]
pub path: String,
}

impl DeprecatedConfigurationFile {
pub fn new(path: impl Into<String>) -> Self {
Self { path: path.into() }
}
}

#[derive(Debug, Default, Diagnostic)]
#[diagnostic(
severity = Error,
Expand Down
6 changes: 3 additions & 3 deletions crates/biome_cli/tests/commands/check.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1091,7 +1091,7 @@ fn fs_files_ignore_symlink() {
check_windows_symlink!(symlink_dir(&testcase2_path, symlink_testcase2_path));
}

let config_path = root_path.join("rome.json");
let config_path = root_path.join("biome.json");
let mut config_file = File::create(config_path).unwrap();
config_file
.write_all(CONFIG_IGNORE_SYMLINK.as_bytes())
Expand Down Expand Up @@ -1383,7 +1383,7 @@ fn deprecated_suppression_comment() {
let file_path = Path::new("file.js");
fs.insert(
file_path.into(),
*b"// rome-ignore lint(suspicious/noDoubleEquals): test
*b"// biome-ignore lint(suspicious/noDoubleEquals): test
a == b;",
);

Expand Down Expand Up @@ -1530,7 +1530,7 @@ fn suppression_syntax_error() {
let mut console = BufferConsole::default();

let file_path = Path::new("check.js");
fs.insert(file_path.into(), *b"// rome-ignore(:\n");
fs.insert(file_path.into(), *b"// biome-ignore(:\n");

let result = run_cli(
DynRef::Borrowed(&mut fs),
Expand Down
2 changes: 1 addition & 1 deletion crates/biome_cli/tests/commands/format.rs
Original file line number Diff line number Diff line change
Expand Up @@ -395,7 +395,7 @@ fn custom_config_file_path() {
let mut fs = MemoryFileSystem::default();
let mut console = BufferConsole::default();

let config_path = Path::new("/test/rome.json");
let config_path = Path::new("/test/biome.json");
fs.insert(config_path.into(), CONFIG_FORMAT.as_bytes());

let file_path = Path::new("file.js");
Expand Down
6 changes: 3 additions & 3 deletions crates/biome_cli/tests/commands/lint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1118,7 +1118,7 @@ fn fs_files_ignore_symlink() {
check_windows_symlink!(symlink_dir(&testcase2_path, symlink_testcase2_path));
}

let config_path = root_path.join("rome.json");
let config_path = root_path.join("biome.json");
let mut config_file = File::create(config_path).unwrap();
config_file
.write_all(CONFIG_IGNORE_SYMLINK.as_bytes())
Expand Down Expand Up @@ -1564,7 +1564,7 @@ fn deprecated_suppression_comment() {
let file_path = Path::new("file.js");
fs.insert(
file_path.into(),
*b"// rome-ignore lint(suspicious/noDoubleEquals): test
*b"// biome-ignore lint(suspicious/noDoubleEquals): test
a == b;",
);

Expand Down Expand Up @@ -1678,7 +1678,7 @@ fn suppression_syntax_error() {
let mut console = BufferConsole::default();

let file_path = Path::new("check.js");
fs.insert(file_path.into(), *b"// rome-ignore(:\n");
fs.insert(file_path.into(), *b"// biome-ignore(:\n");

let result = run_cli(
DynRef::Borrowed(&mut fs),
Expand Down
54 changes: 0 additions & 54 deletions crates/biome_cli/tests/commands/migrate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,60 +79,6 @@ fn missing_configuration_file() {
));
}

#[test]
fn emit_diagnostic_for_rome_json() {
let mut fs = MemoryFileSystem::default();
let mut console = BufferConsole::default();

let configuration = r#"{ "linter": { "enabled": true } }"#;

let configuration_path = Path::new("rome.json");
fs.insert(configuration_path.into(), configuration.as_bytes());

let result = run_cli(
DynRef::Borrowed(&mut fs),
&mut console,
Args::from([("migrate")].as_slice()),
);

assert!(result.is_ok(), "run_cli returned {result:?}");

assert_cli_snapshot(SnapshotPayload::new(
module_path!(),
"emit_diagnostic_for_rome_json",
fs,
console,
result,
));
}

#[test]
fn should_create_biome_json_file() {
let mut fs = MemoryFileSystem::default();
let mut console = BufferConsole::default();

let configuration = r#"{ "linter": { "enabled": true } }"#;

let configuration_path = Path::new("rome.json");
fs.insert(configuration_path.into(), configuration.as_bytes());

let result = run_cli(
DynRef::Borrowed(&mut fs),
&mut console,
Args::from([("migrate"), "--write"].as_slice()),
);

assert!(result.is_ok(), "run_cli returned {result:?}");

assert_cli_snapshot(SnapshotPayload::new(
module_path!(),
"should_create_biome_json_file",
fs,
console,
result,
));
}

#[test]
fn should_emit_incompatible_arguments_error() {
let mut fs = MemoryFileSystem::default();
Expand Down
Loading