Skip to content

Commit 6f1def7

Browse files
committed
Auto merge of rust-lang#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
2 parents 8125cd5 + 6039343 commit 6f1def7

File tree

11 files changed

+877
-894
lines changed

11 files changed

+877
-894
lines changed

.github/deploy.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ rm -rf out/master/ || exit 0
88
echo "Making the docs for master"
99
mkdir out/master/
1010
cp util/gh-pages/index.html out/master
11+
cp util/gh-pages/theme.js out/master
1112
cp util/gh-pages/script.js out/master
12-
cp util/gh-pages/lints.json out/master
1313
cp util/gh-pages/style.css out/master
1414

1515
if [[ -n $TAG_NAME ]]; then

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ out
3434

3535
# gh pages docs
3636
util/gh-pages/lints.json
37+
util/gh-pages/index.html
3738

3839
# rustfmt backups
3940
*.rs.bk

Cargo.toml

+2
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@ toml = "0.7.3"
3939
walkdir = "2.3"
4040
filetime = "0.2.9"
4141
itertools = "0.12"
42+
pulldown-cmark = "0.11"
43+
rinja = { version = "0.3", default-features = false, features = ["config"] }
4244

4345
# UI test dependencies
4446
clippy_utils = { path = "clippy_utils" }

clippy_dev/src/serve.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,9 @@ pub fn run(port: u16, lint: Option<String>) -> ! {
1919
});
2020

2121
loop {
22-
if mtime("util/gh-pages/lints.json") < mtime("clippy_lints/src") {
22+
let index_time = mtime("util/gh-pages/index.html");
23+
24+
if index_time < mtime("clippy_lints/src") || index_time < mtime("util/gh-pages/index_template.html") {
2325
Command::new(env::var("CARGO").unwrap_or("cargo".into()))
2426
.arg("collect-metadata")
2527
.spawn()

rinja.toml

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[general]
2+
dirs = ["util/gh-pages/"]
3+
whitespace = "suppress"

tests/compile-test.rs

+36-4
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,10 @@ use clippy_config::ClippyConfiguration;
88
use clippy_lints::LintInfo;
99
use clippy_lints::declared_lints::LINTS;
1010
use clippy_lints::deprecated_lints::{DEPRECATED, DEPRECATED_VERSION, RENAMED};
11-
use serde::{Deserialize, Serialize};
11+
use pulldown_cmark::{Options, Parser, html};
12+
use rinja::Template;
13+
use rinja::filters::Safe;
14+
use serde::Deserialize;
1215
use test_utils::IS_RUSTC_TEST_SUITE;
1316
use ui_test::custom_flags::Flag;
1417
use ui_test::custom_flags::rustfix::RustfixMode;
@@ -385,6 +388,22 @@ fn ui_cargo_toml_metadata() {
385388
}
386389
}
387390

391+
#[derive(Template)]
392+
#[template(path = "index_template.html")]
393+
struct Renderer<'a> {
394+
lints: &'a Vec<LintMetadata>,
395+
}
396+
397+
impl Renderer<'_> {
398+
fn markdown(input: &str) -> Safe<String> {
399+
let parser = Parser::new_ext(input, Options::all());
400+
let mut html_output = String::new();
401+
html::push_html(&mut html_output, parser);
402+
// Oh deer, what a hack :O
403+
Safe(html_output.replace("<table", "<table class=\"table\""))
404+
}
405+
}
406+
388407
#[derive(Deserialize)]
389408
#[serde(untagged)]
390409
enum DiagnosticOrMessage {
@@ -448,8 +467,11 @@ impl DiagnosticCollector {
448467

449468
metadata.sort_unstable_by(|a, b| a.id.cmp(&b.id));
450469

451-
let json = serde_json::to_string_pretty(&metadata).unwrap();
452-
fs::write("util/gh-pages/lints.json", json).unwrap();
470+
fs::write(
471+
"util/gh-pages/index.html",
472+
Renderer { lints: &metadata }.render().unwrap(),
473+
)
474+
.unwrap();
453475
});
454476

455477
(Self { sender }, handle)
@@ -488,7 +510,7 @@ impl Flag for DiagnosticCollector {
488510
}
489511
}
490512

491-
#[derive(Debug, Serialize)]
513+
#[derive(Debug)]
492514
struct LintMetadata {
493515
id: String,
494516
id_location: Option<&'static str>,
@@ -560,4 +582,14 @@ impl LintMetadata {
560582
applicability: Applicability::Unspecified,
561583
}
562584
}
585+
586+
fn applicability_str(&self) -> &str {
587+
match self.applicability {
588+
Applicability::MachineApplicable => "MachineApplicable",
589+
Applicability::HasPlaceholders => "HasPlaceholders",
590+
Applicability::MaybeIncorrect => "MaybeIncorrect",
591+
Applicability::Unspecified => "Unspecified",
592+
_ => panic!("needs to update this code"),
593+
}
594+
}
563595
}

util/gh-pages/index.html

-330
This file was deleted.

util/gh-pages/index_template.html

+232
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,232 @@
1+
<!DOCTYPE html>
2+
<!--
3+
Welcome to a Clippy's lint list, at least the source code of it. If you are
4+
interested in contributing to this website checkout `util/gh-pages/index_template.html`
5+
inside the rust-clippy repository.
6+
7+
Otherwise, have a great day =^.^=
8+
-->
9+
<html lang="en"> {# #}
10+
<head> {# #}
11+
<meta charset="UTF-8"/> {# #}
12+
<meta name="viewport" content="width=device-width, initial-scale=1"/> {# #}
13+
<meta name="description" content="A collection of lints to catch common mistakes and improve your Rust code."> {# #}
14+
15+
<title>Clippy Lints</title> {# #}
16+
17+
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.6/css/bootstrap.min.css"/> {# #}
18+
<link id="githubLightHighlight" rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.6.0/styles/github.min.css" disabled="true" /> {# #}
19+
<link id="githubDarkHighlight" rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.6.0/styles/github-dark.min.css" disabled="true" /> {# #}
20+
21+
<!-- The files are not copied over into the Clippy project since they use the MPL-2.0 License -->
22+
<link rel="stylesheet" href="https://rust-lang.github.io/mdBook/css/variables.css"/> {# #}
23+
<link id="styleHighlight" rel="stylesheet" href="https://rust-lang.github.io/mdBook/highlight.css"> {# #}
24+
<link id="styleNight" rel="stylesheet" href="https://rust-lang.github.io/mdBook/tomorrow-night.css" disabled="true"> {# #}
25+
<link id="styleAyu" rel="stylesheet" href="https://rust-lang.github.io/mdBook/ayu-highlight.css" disabled="true"> {# #}
26+
<link rel="stylesheet" href="style.css"> {# #}
27+
</head> {# #}
28+
<body> {# #}
29+
<script src="theme.js"></script> {# #}
30+
<div id="settings-dropdown"> {# #}
31+
<button class="settings-icon" tabindex="-1"></button> {# #}
32+
<div class="settings-menu" tabindex="-1"> {# #}
33+
<div class="setting-radio-name">Theme</div> {# #}
34+
<select id="theme-choice" onchange="setTheme(this.value, true)"> {# #}
35+
<option value="ayu">Ayu</option> {# #}
36+
<option value="coal">Coal</option> {# #}
37+
<option value="light">Light</option> {# #}
38+
<option value="navy">Navy</option> {# #}
39+
<option value="rust">Rust</option> {# #}
40+
</select> {# #}
41+
<label> {# #}
42+
<input type="checkbox" id="disable-shortcuts" onchange="changeSetting(this)"> {#+ #}
43+
<span>Disable keyboard shortcuts</span> {# #}
44+
</label> {# #}
45+
</div> {# #}
46+
</div> {# #}
47+
48+
<div class="container"> {# #}
49+
<div class="page-header"> {# #}
50+
<h1>Clippy Lints</h1> {# #}
51+
</div> {# #}
52+
53+
<noscript> {# #}
54+
<div class="alert alert-danger" role="alert"> {# #}
55+
Sorry, this site only works with JavaScript! :( {# #}
56+
</div> {# #}
57+
</noscript> {# #}
58+
59+
<div> {# #}
60+
<div class="panel panel-default"> {# #}
61+
<div class="panel-body row"> {# #}
62+
<div id="upper-filters" class="col-12 col-md-5"> {# #}
63+
<div class="btn-group" id="lint-levels" tabindex="-1"> {# #}
64+
<button type="button" class="btn btn-default dropdown-toggle"> {# #}
65+
Lint levels <span class="badge">4</span> <span class="caret"></span> {# #}
66+
</button> {# #}
67+
<ul class="dropdown-menu" id="lint-levels-selector"> {# #}
68+
<li class="checkbox"> {# #}
69+
<button onclick="toggleElements('levels_filter', true)">All</button> {# #}
70+
</li> {# #}
71+
<li class="checkbox"> {# #}
72+
<button onclick="toggleElements('levels_filter', false)">None</button> {# #}
73+
</li> {# #}
74+
<li role="separator" class="divider"></li> {# #}
75+
</ul> {# #}
76+
</div> {# #}
77+
<div class="btn-group" id="lint-groups" tabindex="-1"> {# #}
78+
<button type="button" class="btn btn-default dropdown-toggle"> {# #}
79+
Lint groups <span class="badge">9</span> <span class="caret"></span> {# #}
80+
</button> {# #}
81+
<ul class="dropdown-menu" id="lint-groups-selector"> {# #}
82+
<li class="checkbox"> {# #}
83+
<button onclick="toggleElements('groups_filter', true)">All</button> {# #}
84+
</li> {# #}
85+
<li class="checkbox"> {# #}
86+
<button onclick="resetGroupsToDefault()">Default</button> {# #}
87+
</li> {# #}
88+
<li class="checkbox"> {# #}
89+
<button onclick="toggleElements('groups_filter', false)">None</button> {# #}
90+
</li> {# #}
91+
<li role="separator" class="divider"></li> {# #}
92+
</ul> {# #}
93+
</div> {# #}
94+
<div class="btn-group" id="version-filter" tabindex="-1"> {# #}
95+
<button type="button" class="btn btn-default dropdown-toggle"> {# #}
96+
Version {#+ #}
97+
<span id="version-filter-count" class="badge">0</span> {#+ #}
98+
<span class="caret"></span> {# #}
99+
</button> {# #}
100+
<ul id="version-filter-selector" class="dropdown-menu"> {# #}
101+
<li class="checkbox"> {# #}
102+
<button onclick="clearVersionFilters()">Clear filters</button> {# #}
103+
</li> {# #}
104+
<li role="separator" class="divider"></li> {# #}
105+
</ul> {# #}
106+
</div> {# #}
107+
<div class="btn-group", id="lint-applicabilities" tabindex="-1"> {# #}
108+
<button type="button" class="btn btn-default dropdown-toggle"> {# #}
109+
Applicability {#+ #}
110+
<span class="badge">4</span> {#+ #}
111+
<span class="caret"></span> {# #}
112+
</button> {# #}
113+
<ul class="dropdown-menu" id="lint-applicabilities-selector"> {# #}
114+
<li class="checkbox"> {# #}
115+
<button onclick="toggleElements('applicabilities_filter', true)">All</button> {# #}
116+
</li> {# #}
117+
<li class="checkbox"> {# #}
118+
<button onclick="toggleElements('applicabilities_filter', false)">None</button> {# #}
119+
</li> {# #}
120+
<li role="separator" class="divider"></li> {# #}
121+
</ul> {# #}
122+
</div> {# #}
123+
</div> {# #}
124+
<div class="col-12 col-md-5 search-control"> {# #}
125+
<div class="input-group"> {# #}
126+
<label class="input-group-addon" id="filter-label" for="search-input">Filter:</label> {# #}
127+
<input type="text" class="form-control filter-input" placeholder="Keywords or search string (`S` or `/` to focus)" id="search-input" /> {# #}
128+
<span class="input-group-btn"> {# #}
129+
<button class="filter-clear btn" type="button" onclick="searchState.clearInput(event)"> {# #}
130+
Clear {# #}
131+
</button> {# #}
132+
</span> {# #}
133+
</div> {# #}
134+
</div> {# #}
135+
<div class="col-12 col-md-2 btn-group expansion-group"> {# #}
136+
<button title="Collapse All" class="btn btn-default expansion-control" type="button" onclick="toggleExpansion(false)"> {# #}
137+
<span class="glyphicon glyphicon-collapse-up"></span> {# #}
138+
</button> {# #}
139+
<button title="Expand All" class="btn btn-default expansion-control" type="button" onclick="toggleExpansion(true)"> {# #}
140+
<span class="glyphicon glyphicon-collapse-down"></span> {# #}
141+
</button> {# #}
142+
</div> {# #}
143+
</div> {# #}
144+
</div>
145+
{% for lint in lints %}
146+
<article class="panel panel-default collapsed" id="{{lint.id}}"> {# #}
147+
<header class="panel-heading" onclick="expandLint('{{lint.id}}')"> {# #}
148+
<h2 class="panel-title"> {# #}
149+
<div class="panel-title-name" id="lint-{{lint.id}}"> {# #}
150+
<span>{{lint.id}}</span> {#+ #}
151+
<a href="#{{lint.id}}" class="anchor label label-default" onclick="openLint(event)">&para;</a> {#+ #}
152+
<a href="" class="anchor label label-default" onclick="copyToClipboard(event)"> {# #}
153+
&#128203; {# #}
154+
</a> {# #}
155+
</div> {# #}
156+
157+
<div class="panel-title-addons"> {# #}
158+
<span class="label label-lint-group label-default label-group-{{lint.group}}">{{lint.group}}</span> {#+ #}
159+
160+
<span class="label label-lint-level label-lint-level-{{lint.level}}">{{lint.level}}</span> {#+ #}
161+
162+
<span class="label label-doc-folding">&plus;</span> {# #}
163+
</div> {# #}
164+
</h2> {# #}
165+
</header> {# #}
166+
167+
<div class="list-group lint-docs"> {# #}
168+
<div class="list-group-item lint-doc-md">{{Self::markdown(lint.docs)}}</div> {# #}
169+
<div class="lint-additional-info-container">
170+
{# Applicability #}
171+
<div class="lint-additional-info-item"> {# #}
172+
<span> Applicability: </span> {# #}
173+
<span class="label label-default label-applicability">{{ lint.applicability_str() }}</span> {# #}
174+
<a href="https://doc.rust-lang.org/nightly/nightly-rustc/rustc_lint_defs/enum.Applicability.html#variants">(?)</a> {# #}
175+
</div>
176+
{# Clippy version #}
177+
<div class="lint-additional-info-item"> {# #}
178+
<span>{% if lint.group == "deprecated" %}Deprecated{% else %} Added{% endif +%} in: </span> {# #}
179+
<span class="label label-default label-version">{{lint.version}}</span> {# #}
180+
</div>
181+
{# Open related issues #}
182+
<div class="lint-additional-info-item"> {# #}
183+
<a href="https://github.com/rust-lang/rust-clippy/issues?q=is%3Aissue+{{lint.id}}">Related Issues</a> {# #}
184+
</div>
185+
186+
{# Jump to source #}
187+
{% if let Some(id_location) = lint.id_location %}
188+
<div class="lint-additional-info-item"> {# #}
189+
<a href="https://github.com/rust-lang/rust-clippy/blob/master/clippy_lints/{{id_location}}">View Source</a> {# #}
190+
</div>
191+
{% endif %}
192+
</div> {# #}
193+
</div> {# #}
194+
</article>
195+
{% endfor %}
196+
</div> {# #}
197+
</div> {# #}
198+
199+
<a {#+ #}
200+
aria-label="View source on GitHub" {#+ #}
201+
class="github-corner" {#+ #}
202+
href="https://github.com/rust-lang/rust-clippy" {#+ #}
203+
rel="noopener noreferrer" {#+ #}
204+
target="_blank" {# #}
205+
> {# #}
206+
<svg {#+ #}
207+
width="80" {#+ #}
208+
height="80" {#+ #}
209+
viewBox="0 0 250 250" {#+ #}
210+
style="position: absolute; top: 0; border: 0; right: 0" {#+ #}
211+
aria-hidden="true" {# #}
212+
> {# #}
213+
<path d="M0,0 L115,115 L130,115 L142,142 L250,250 L250,0 Z" fill="var(--theme-color)"></path> {# #}
214+
<path {#+ #}
215+
d="M128.3,109.0 C113.8,99.7 119.0,89.6 119.0,89.6 C122.0,82.7 120.5,78.6 120.5,78.6 C119.2,72.0 123.4,76.3 123.4,76.3 C127.3,80.9 125.5,87.3 125.5,87.3 C122.9,97.6 130.6,101.9 134.4,103.2" {#+ #}
216+
fill="currentColor" {#+ #}
217+
style="transform-origin: 130px 106px" {#+ #}
218+
class="octo-arm" {# #}
219+
></path> {# #}
220+
<path {#+ #}
221+
d="M115.0,115.0 C114.9,115.1 118.7,116.5 119.8,115.4 L133.7,101.6 C136.9,99.2 139.9,98.4 142.2,98.6 C133.8,88.0 127.5,74.4 143.8,58.0 C148.5,53.4 154.0,51.2 159.7,51.0 C160.3,49.4 163.2,43.6 171.4,40.1 C171.4,40.1 176.1,42.5 178.8,56.2 C183.1,58.6 187.2,61.8 190.9,65.4 C194.5,69.0 197.7,73.2 200.1,77.6 C213.8,80.2 216.3,84.9 216.3,84.9 C212.7,93.1 206.9,96.0 205.4,96.6 C205.1,102.4 203.0,107.8 198.3,112.5 C181.9,128.9 168.3,122.5 157.7,114.1 C157.9,116.9 156.7,120.9 152.7,124.9 L141.0,136.5 C139.8,137.7 141.6,141.9 141.8,141.8 Z" {#+ #}
222+
fill="currentColor" {#+ #}
223+
class="octo-body" {# #}
224+
></path> {# #}
225+
</svg> {# #}
226+
</a> {# #}
227+
228+
<script src="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.6.0/highlight.min.js"></script> {# #}
229+
<script src="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.6.0/languages/rust.min.js"></script> {# #}
230+
<script src="script.js"></script> {# #}
231+
</body> {# #}
232+
</html> {# #}

0 commit comments

Comments
 (0)