Skip to content

Commit c638e5b

Browse files
committed
Merge branch 'feature/gh-pages-docs' of https://github.com/killercup/rust-clippy into killercup-feature/gh-pages-docs
2 parents 94fcdad + c2baf5f commit c638e5b

File tree

5 files changed

+329
-0
lines changed

5 files changed

+329
-0
lines changed

.editorconfig

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# EditorConfig helps developers define and maintain consistent
2+
# coding styles between different editors and IDEs
3+
# editorconfig.org
4+
5+
root = true
6+
7+
[*]
8+
end_of_line = lf
9+
charset = utf-8
10+
trim_trailing_whitespace = true
11+
insert_final_newline = true
12+
indent_style = space
13+
indent_size = 4
14+
15+
[*.md]
16+
trim_trailing_whitespace = false

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,3 +16,6 @@ Cargo.lock
1616

1717
# Generated by dogfood
1818
/target_recur/
19+
20+
# gh pages docs
21+
util/gh-pages/lints.json

.travis.yml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,3 +46,11 @@ after_success:
4646
else
4747
echo "Ignored"
4848
fi
49+
- |
50+
if [ "$TRAVIS_PULL_REQUEST" == "false" ] &&
51+
[ "$TRAVIS_REPO_SLUG" == "Manishearth/rust-clippy" ] &&
52+
[ "$TRAVIS_BRANCH" == "master" ] ; then
53+
54+
python util/export.py
55+
56+
fi

util/export.py

Lines changed: 145 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,145 @@
1+
#!/usr/bin/env python
2+
3+
import os
4+
import re
5+
import json
6+
7+
level_re = re.compile(r'''(Forbid|Deny|Warn|Allow)''')
8+
conf_re = re.compile(r'''define_Conf! {\n([^}]*)\n}''', re.MULTILINE)
9+
confvar_re = re.compile(r'''/// Lint: (\w+). (.*).*\n *\("([^"]*)", (?:[^,]*), (.*) => (.*)\),''')
10+
lint_subheadline = re.compile(r'''^\*\*([\w\s]+?)[:?.!]?\*\*(.*)''')
11+
12+
conf_template = """
13+
This lint has the following configuration variables:
14+
15+
* `%s: %s`: %s (defaults to `%s`).
16+
"""
17+
18+
# TODO: actual logging
19+
def warn(*args): print(args)
20+
def debug(*args): print(args)
21+
def info(*args): print(args)
22+
23+
def parse_path(p="clippy_lints/src"):
24+
lints = []
25+
for f in os.listdir(p):
26+
if f.endswith(".rs"):
27+
parse_file(lints, os.path.join(p, f))
28+
29+
conf = parse_conf(p)
30+
info(conf)
31+
32+
for lint_id in conf:
33+
lint = next(l for l in lints if l['id'] == lint_id)
34+
if lint:
35+
lint['docs']['Configuration'] = (conf_template % conf[lint_id]).strip()
36+
37+
return lints
38+
39+
40+
def parse_conf(p):
41+
c = {}
42+
with open(p + '/utils/conf.rs') as f:
43+
f = f.read()
44+
45+
m = re.search(conf_re, f)
46+
m = m.groups()[0]
47+
48+
m = re.findall(confvar_re, m)
49+
50+
for (lint, doc, name, default, ty) in m:
51+
c[lint.lower()] = (name, ty, doc, default)
52+
53+
return c
54+
55+
def parseLintDef(level, comment, name):
56+
lint = {}
57+
lint['id'] = name
58+
lint['level'] = level
59+
lint['docs'] = {}
60+
61+
last_section = None
62+
63+
for line in comment:
64+
if len(line.strip()) == 0:
65+
continue
66+
67+
match = re.match(lint_subheadline, line)
68+
if match:
69+
last_section = match.groups()[0]
70+
if match:
71+
text = match.groups()[1]
72+
else:
73+
text = line
74+
75+
if not last_section:
76+
warn("Skipping comment line as it was not preceded by a heading")
77+
debug("in lint `%s`, line `%s`" % name, line)
78+
79+
lint['docs'][last_section] = (lint['docs'].get(last_section, "") + "\n" + text).strip()
80+
81+
return lint
82+
83+
def parse_file(d, f):
84+
last_comment = []
85+
comment = True
86+
87+
with open(f) as rs:
88+
for line in rs:
89+
if comment:
90+
if line.startswith("///"):
91+
if line.startswith("/// "):
92+
last_comment.append(line[4:])
93+
else:
94+
last_comment.append(line[3:])
95+
elif line.startswith("declare_lint!"):
96+
comment = False
97+
deprecated = False
98+
restriction = False
99+
elif line.startswith("declare_restriction_lint!"):
100+
comment = False
101+
deprecated = False
102+
restriction = True
103+
elif line.startswith("declare_deprecated_lint!"):
104+
comment = False
105+
deprecated = True
106+
else:
107+
last_comment = []
108+
if not comment:
109+
l = line.strip()
110+
m = re.search(r"pub\s+([A-Z_][A-Z_0-9]*)", l)
111+
112+
if m:
113+
name = m.group(1).lower()
114+
115+
# Intentionally either a never looping or infinite loop
116+
while not deprecated and not restriction:
117+
m = re.search(level_re, line)
118+
if m:
119+
level = m.group(0)
120+
break
121+
122+
line = next(rs)
123+
124+
if deprecated:
125+
level = "Deprecated"
126+
elif restriction:
127+
level = "Allow"
128+
129+
info("found %s with level %s in %s" % (name, level, f))
130+
d.append(parseLintDef(level, last_comment, name=name))
131+
last_comment = []
132+
comment = True
133+
if "}" in l:
134+
warn("Warning: Missing Lint-Name in", f)
135+
comment = True
136+
137+
def main():
138+
lints = parse_path()
139+
info("got %s lints" % len(lints))
140+
with open("util/gh-pages/lints.json", "w") as file:
141+
json.dump(lints, file, indent=2)
142+
info("wrote JSON for great justice")
143+
144+
if __name__ == "__main__":
145+
main()

util/gh-pages/index.html

Lines changed: 157 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,157 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8"/>
5+
<meta name="viewport" content="width=device-width, initial-scale=1"/>
6+
7+
<title>Clippy</title>
8+
9+
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.6/css/bootstrap.min.css"/>
10+
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/9.5.0/styles/github.min.css"/>
11+
<style>
12+
blockquote { font-size: 1em; }
13+
[ng\:cloak], [ng-cloak], [data-ng-cloak], [x-ng-cloak], .ng-cloak, .x-ng-cloak { display: none !important; }
14+
.panel .anchor { display: none; }
15+
.panel:hover .anchor { display: inline; color: #fff; }
16+
</style>
17+
</head>
18+
<body>
19+
<div class="container" ng-app="clippy" ng-controller="lintList">
20+
<div class="page-header">
21+
<h1>ALL the Clippy Lints</h1>
22+
</div>
23+
24+
<noscript>
25+
<div class="alert alert-danger" role="alert">
26+
Sorry, this site only works with JavaScript!
27+
</div>
28+
</noscript>
29+
30+
<div ng-cloak>
31+
32+
<div class="alert alert-info" role="alert" ng-if="loading">
33+
Loading&#x2026;
34+
</div>
35+
<div class="alert alert-danger" role="alert" ng-if="error">
36+
Error loading lints!
37+
</div>
38+
39+
<div class="panel panel-default" ng-show="data">
40+
<div class="panel-body row">
41+
<div class="col-md-6 form-inline">
42+
<div class="form-group form-group-lg">
43+
<div class="checkbox" ng-repeat="(level, enabled) in levels" style="margin-right: 0.6em">
44+
<label>
45+
<input type="checkbox" ng-model="levels[level]" />
46+
{{level}}
47+
</label>
48+
</div>
49+
</div>
50+
</div>
51+
<div class="col-md-6">
52+
<div class="input-group">
53+
<span class="input-group-addon" id="filter-label">Filter:</span>
54+
<input type="text" class="form-control" placeholder="Keywords or search string" aria-describedby="filter-label" ng-model="search" />
55+
<span class="input-group-btn">
56+
<button class="btn btn-default" type="button" ng-click="search = ''">
57+
Clear
58+
</button>
59+
</span>
60+
</div>
61+
</div>
62+
</div>
63+
</div>
64+
65+
<article class="panel panel-default" id="{{lint.id}}" ng-repeat="lint in data | filter:byLevels | filter:search | orderBy:'id' track by lint.id">
66+
<header class="panel-heading" ng-click="open[lint.id] = !open[lint.id]">
67+
<button class="btn btn-default btn-sm pull-right" style="margin-top: -6px;">
68+
<span ng-show="open[lint.id]">&minus;</span>
69+
<span ng-hide="open[lint.id]">&plus;</span>
70+
</button>
71+
72+
<h2 class="panel-title">
73+
{{lint.id}}
74+
75+
<span ng-if="lint.level == 'Allow'" class="label label-info">Allow</span>
76+
<span ng-if="lint.level == 'Warn'" class="label label-warning">Warn</span>
77+
<span ng-if="lint.level == 'Deny'" class="label label-danger">Deny</span>
78+
<span ng-if="lint.level == 'Deprecated'" class="label label-default">Deprecated</span>
79+
80+
<a href="#{{lint.id}}" class="anchor label label-default">&para;</a>
81+
</h2>
82+
</header>
83+
84+
<ul class="list-group" ng-if="lint.docs" ng-class="{collapse: true, in: open[lint.id]}">
85+
<li class="list-group-item" ng-repeat="(title, text) in lint.docs">
86+
<h4 class="list-group-item-heading">
87+
{{title}}
88+
</h4>
89+
<div class="list-group-item-text" ng-bind-html="text | markdown"></div>
90+
</li>
91+
</ul>
92+
</article>
93+
</div>
94+
</div>
95+
96+
<a href="https://github.com/Manishearth/rust-clippy">
97+
<img style="position: absolute; top: 0; right: 0; border: 0;" src="https://s3.amazonaws.com/github/ribbons/forkme_right_darkblue_121621.png"/>
98+
</a>
99+
100+
<script src="https://cdnjs.cloudflare.com/ajax/libs/markdown-it/7.0.0/markdown-it.min.js"></script>
101+
<script src="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/9.5.0/highlight.min.js"></script>
102+
<script src="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/9.5.0/languages/rust.min.js"></script>
103+
<script src="https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.4.12/angular.min.js"></script>
104+
<script>
105+
(function () {
106+
var md = window.markdownit({
107+
html: true,
108+
linkify: true,
109+
typographer: true,
110+
highlight: function (str, lang) {
111+
if (lang && hljs.getLanguage(lang)) {
112+
try {
113+
return '<pre class="hljs"><code>' +
114+
hljs.highlight(lang, str, true).value +
115+
'</code></pre>';
116+
} catch (__) {}
117+
}
118+
119+
return '<pre class="hljs"><code>' + md.utils.escapeHtml(str) + '</code></pre>';
120+
}
121+
});
122+
123+
angular.module("clippy", [])
124+
.filter('markdown', function ($sce) {
125+
return function (text) {
126+
return $sce.trustAsHtml(
127+
md.render(text || '')
128+
// Oh deer, what a hack :O
129+
.replace('<table', '<table class="table"')
130+
);
131+
};
132+
})
133+
.controller("lintList", function ($scope, $http) {
134+
// Level filter
135+
$scope.levels = {Allow: true, Warn: true, Deny: true, Deprecated: true};
136+
$scope.byLevels = function (lint) {
137+
return $scope.levels[lint.level];
138+
};
139+
140+
// Get data
141+
$scope.open = {};
142+
$scope.loading = true;
143+
144+
$http.get('./lints.json')
145+
.success(function (data) {
146+
$scope.data = data;
147+
$scope.loading = false;
148+
})
149+
.error(function (data) {
150+
$scope.error = data;
151+
$scope.loading = false;
152+
});
153+
})
154+
})();
155+
</script>
156+
</body>
157+
</html>

0 commit comments

Comments
 (0)