Skip to content

Truncate files when opening in metadata-collector #11505

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

Merged
merged 1 commit into from
Sep 14, 2023
Merged
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
37 changes: 10 additions & 27 deletions clippy_lints/src/utils/internal_lints/metadata_collector.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ use serde::{Serialize, Serializer};
use std::collections::{BTreeSet, BinaryHeap};
use std::fmt;
use std::fmt::Write as _;
use std::fs::{self, OpenOptions};
use std::fs::{self, File};
use std::io::prelude::*;
use std::path::{Path, PathBuf};
use std::process::Command;
Expand Down Expand Up @@ -229,25 +229,10 @@ impl Drop for MetadataCollector {
collect_renames(&mut lints);

// Outputting json
if Path::new(JSON_OUTPUT_FILE).exists() {
fs::remove_file(JSON_OUTPUT_FILE).unwrap();
}
let mut file = OpenOptions::new()
.write(true)
.create(true)
.open(JSON_OUTPUT_FILE)
.unwrap();
writeln!(file, "{}", serde_json::to_string_pretty(&lints).unwrap()).unwrap();
fs::write(JSON_OUTPUT_FILE, serde_json::to_string_pretty(&lints).unwrap()).unwrap();

// Outputting markdown
if Path::new(MARKDOWN_OUTPUT_FILE).exists() {
fs::remove_file(MARKDOWN_OUTPUT_FILE).unwrap();
}
let mut file = OpenOptions::new()
.write(true)
.create(true)
.open(MARKDOWN_OUTPUT_FILE)
.unwrap();
let mut file = File::create(MARKDOWN_OUTPUT_FILE).unwrap();
writeln!(
file,
"<!--
Expand All @@ -261,17 +246,15 @@ Please use that command to update the file and do not edit it by hand.
.unwrap();

// Write configuration links to CHANGELOG.md
let mut changelog = std::fs::read_to_string(CHANGELOG_PATH).unwrap();
let mut changelog_file = OpenOptions::new().read(true).write(true).open(CHANGELOG_PATH).unwrap();

if let Some(position) = changelog.find("<!-- begin autogenerated links to configuration documentation -->") {
// I know this is kinda wasteful, we just don't have regex on `clippy_lints` so... this is the best
// we can do AFAIK.
changelog = changelog[..position].to_string();
}
let changelog = std::fs::read_to_string(CHANGELOG_PATH).unwrap();
let mut changelog_file = File::create(CHANGELOG_PATH).unwrap();
let position = changelog
.find("<!-- begin autogenerated links to configuration documentation -->")
.unwrap();
writeln!(
changelog_file,
"{changelog}<!-- begin autogenerated links to configuration documentation -->\n{}\n<!-- end autogenerated links to configuration documentation -->",
"{}<!-- begin autogenerated links to configuration documentation -->\n{}\n<!-- end autogenerated links to configuration documentation -->",
&changelog[..position],
self.configs_to_markdown(ClippyConfiguration::to_markdown_link)
)
.unwrap();
Expand Down