diff options
| author | bors <bors@rust-lang.org> | 2024-10-11 14:18:54 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2024-10-11 14:18:54 +0000 |
| commit | 6f1def79dd372e380357e1dfd2b8a54254ffe2d0 (patch) | |
| tree | 8056cae564346d262ff72f3bc58f209b7aadf684 /tests | |
| parent | 8125cd5c2af8f609577c7d3b740a859fdde40c6c (diff) | |
| parent | 603934336dea3c8385f0c7a03ebf2ecebfe913a2 (diff) | |
| download | rust-6f1def79dd372e380357e1dfd2b8a54254ffe2d0.tar.gz rust-6f1def79dd372e380357e1dfd2b8a54254ffe2d0.zip | |
Auto merge of #13269 - GuillaumeGomez:rewrite-lints-page, r=Alexendoo
Rewrite lints page This PR has multiple goals: * Make lints page to work without needing a web server by removing the json file. * Prepare the field to also make the page work with JS (not done in this PR but should be straightforward). * Remove angular dependency. r? `@Alexendoo` changelog: make lint page work without web server
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/compile-test.rs | 40 |
1 files changed, 36 insertions, 4 deletions
diff --git a/tests/compile-test.rs b/tests/compile-test.rs index 8734bd41364..5774e20e0be 100644 --- a/tests/compile-test.rs +++ b/tests/compile-test.rs @@ -8,7 +8,10 @@ use clippy_config::ClippyConfiguration; use clippy_lints::LintInfo; use clippy_lints::declared_lints::LINTS; use clippy_lints::deprecated_lints::{DEPRECATED, DEPRECATED_VERSION, RENAMED}; -use serde::{Deserialize, Serialize}; +use pulldown_cmark::{Options, Parser, html}; +use rinja::Template; +use rinja::filters::Safe; +use serde::Deserialize; use test_utils::IS_RUSTC_TEST_SUITE; use ui_test::custom_flags::Flag; use ui_test::custom_flags::rustfix::RustfixMode; @@ -385,6 +388,22 @@ fn ui_cargo_toml_metadata() { } } +#[derive(Template)] +#[template(path = "index_template.html")] +struct Renderer<'a> { + lints: &'a Vec<LintMetadata>, +} + +impl Renderer<'_> { + fn markdown(input: &str) -> Safe<String> { + let parser = Parser::new_ext(input, Options::all()); + let mut html_output = String::new(); + html::push_html(&mut html_output, parser); + // Oh deer, what a hack :O + Safe(html_output.replace("<table", "<table class=\"table\"")) + } +} + #[derive(Deserialize)] #[serde(untagged)] enum DiagnosticOrMessage { @@ -448,8 +467,11 @@ impl DiagnosticCollector { metadata.sort_unstable_by(|a, b| a.id.cmp(&b.id)); - let json = serde_json::to_string_pretty(&metadata).unwrap(); - fs::write("util/gh-pages/lints.json", json).unwrap(); + fs::write( + "util/gh-pages/index.html", + Renderer { lints: &metadata }.render().unwrap(), + ) + .unwrap(); }); (Self { sender }, handle) @@ -488,7 +510,7 @@ impl Flag for DiagnosticCollector { } } -#[derive(Debug, Serialize)] +#[derive(Debug)] struct LintMetadata { id: String, id_location: Option<&'static str>, @@ -560,4 +582,14 @@ impl LintMetadata { applicability: Applicability::Unspecified, } } + + fn applicability_str(&self) -> &str { + match self.applicability { + Applicability::MachineApplicable => "MachineApplicable", + Applicability::HasPlaceholders => "HasPlaceholders", + Applicability::MaybeIncorrect => "MaybeIncorrect", + Applicability::Unspecified => "Unspecified", + _ => panic!("needs to update this code"), + } + } } |
