Skip to content
This repository has been archived by the owner on Aug 31, 2023. It is now read-only.

Commit

Permalink
refactor(rome_cli): file process (#4653)
Browse files Browse the repository at this point in the history
  • Loading branch information
ematipico authored Jul 4, 2023
1 parent 0affcbf commit c4ceec3
Show file tree
Hide file tree
Showing 76 changed files with 1,319 additions and 560 deletions.
7 changes: 6 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,14 @@

This wasn't ideal for users, because this could have created false positives in linting, or formatted
code with a configuration that wasn't the of the user.
- The command `rome check` now shows formatter diagnostics when checking the code.

The presence of the diagnostics will result in an error code when the command finishes.

This is in line with semantic and behaviour meant for the command `rome check`.

#### Other changes

- The command `rome check` now shows formatter diagnostics when checking the code.
- Fix [#4556](https://github.com/rome/tools/issues/4556), which correctly handles new lines in the
`.gitignore` file across OS.
- Add a new option to ignore unknown files `--files-ignore-unknown`:
Expand All @@ -34,6 +37,8 @@

Rome won't exit with an error code in case no files were processed in the given paths.

- Fixed the diagnostics emitted when running the `rome format` command;

### Configuration

#### Other changes
Expand Down
40 changes: 20 additions & 20 deletions crates/rome_cli/src/execute/diagnostics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,23 +8,23 @@ use std::io;
category = "format",
message = "File content differs from formatting output"
)]
pub(crate) struct CIFormatDiffDiagnostic<'a> {
pub(crate) struct CIFormatDiffDiagnostic {
#[location(resource)]
pub(crate) file_name: &'a str,
pub(crate) file_name: String,
#[advice]
pub(crate) diff: ContentDiffAdvice<'a>,
pub(crate) diff: ContentDiffAdvice,
}

#[derive(Debug, Diagnostic)]
#[diagnostic(
category = "organizeImports",
message = "Import statements differs from the output"
)]
pub(crate) struct CIOrganizeImportsDiffDiagnostic<'a> {
pub(crate) struct CIOrganizeImportsDiffDiagnostic {
#[location(resource)]
pub(crate) file_name: &'a str,
pub(crate) file_name: String,
#[advice]
pub(crate) diff: ContentDiffAdvice<'a>,
pub(crate) diff: ContentDiffAdvice,
}

#[derive(Debug, Diagnostic)]
Expand All @@ -33,11 +33,11 @@ category = "format",
severity = Information,
message = "Formatter would have printed the following content:"
)]
pub(crate) struct FormatDiffDiagnostic<'a> {
pub(crate) struct FormatDiffDiagnostic {
#[location(resource)]
pub(crate) file_name: &'a str,
pub(crate) file_name: String,
#[advice]
pub(crate) diff: ContentDiffAdvice<'a>,
pub(crate) diff: ContentDiffAdvice,
}

#[derive(Debug, Diagnostic)]
Expand All @@ -46,11 +46,11 @@ pub(crate) struct FormatDiffDiagnostic<'a> {
severity = Information,
message = "Import statements could be sorted:"
)]
pub(crate) struct OrganizeImportsDiffDiagnostic<'a> {
pub(crate) struct OrganizeImportsDiffDiagnostic {
#[location(resource)]
pub(crate) file_name: &'a str,
pub(crate) file_name: String,
#[advice]
pub(crate) diff: ContentDiffAdvice<'a>,
pub(crate) diff: ContentDiffAdvice,
}

#[derive(Debug, Diagnostic)]
Expand All @@ -59,22 +59,22 @@ pub(crate) struct OrganizeImportsDiffDiagnostic<'a> {
severity = Information,
message = "Configuration file can be updated."
)]
pub(crate) struct MigrateDiffDiagnostic<'a> {
pub(crate) struct MigrateDiffDiagnostic {
#[location(resource)]
pub(crate) file_name: &'a str,
pub(crate) file_name: String,
#[advice]
pub(crate) diff: ContentDiffAdvice<'a>,
pub(crate) diff: ContentDiffAdvice,
}

#[derive(Debug)]
pub(crate) struct ContentDiffAdvice<'a> {
pub(crate) old: &'a str,
pub(crate) new: &'a str,
pub(crate) struct ContentDiffAdvice {
pub(crate) old: String,
pub(crate) new: String,
}

impl Advices for ContentDiffAdvice<'_> {
impl Advices for ContentDiffAdvice {
fn record(&self, visitor: &mut dyn Visit) -> io::Result<()> {
let diff = TextEdit::from_unicode_words(self.old, self.new);
let diff = TextEdit::from_unicode_words(&self.old, &self.new);
visitor.record_diff(&diff)
}
}
Expand Down
6 changes: 3 additions & 3 deletions crates/rome_cli/src/execute/migrate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,10 +81,10 @@ pub(crate) fn run(
} else {
let file_name = configuration_path.display().to_string();
let diagnostic = MigrateDiffDiagnostic {
file_name: &file_name,
file_name,
diff: ContentDiffAdvice {
old: configuration_content.as_str(),
new: new_configuration_content.as_str(),
old: configuration_content,
new: new_configuration_content,
},
};
console.error(markup! {
Expand Down
Loading

0 comments on commit c4ceec3

Please sign in to comment.