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

refactor(rome_cli): file process #4653

Merged
merged 7 commits into from
Jul 4, 2023
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
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
点击 这是indexloc提供的php浏览器服务,不要输入任何密码和下载