Skip to content

Commit 20ca605

Browse files
committed
Add First Draft of Lint Listing Page
1 parent b14114f commit 20ca605

File tree

4 files changed

+252
-0
lines changed

4 files changed

+252
-0
lines changed

.gitignore

+3
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

+8
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

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

util/gh-pages/index.html

+114
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8">
5+
<title>Clippy</title>
6+
7+
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.1/css/bootstrap.min.css"/>
8+
<meta name="viewport" content="width=device-width, initial-scale=1"/>
9+
</head>
10+
<body>
11+
<div class="container" ng-app="clippy" ng-controller="lintList">
12+
<div class="page-header">
13+
<h1>ALL the Clippy Lints</h1>
14+
</div>
15+
16+
<div class="alert alert-info" role="alert" ng-if="loading">
17+
Loading&#x2026;
18+
</div>
19+
<div class="alert alert-danger" role="alert" ng-if="error">
20+
Error loading commits!
21+
</div>
22+
23+
<div class="panel panel-default" ng-show="data">
24+
<div class="panel-body row">
25+
<div class="col-md-6 form-inline">
26+
<div class="form-group">
27+
<label for="filter-level">Level</label>
28+
<select class="form-control" id="filter-level" ng-model="level.level">
29+
<option value="">All</option>
30+
<option value="Allow">Allow</option>
31+
<option value="Warn">Warn</option>
32+
<option value="Deny">Deny</option>
33+
</select>
34+
</div>
35+
</div>
36+
<div class="col-md-6">
37+
<div class="input-group">
38+
<span class="input-group-addon" id="filter-label">Filter:</span>
39+
<input type="text" class="form-control" placeholder="Keywords or search string" aria-describedby="filter-label" ng-model="search" />
40+
<span class="input-group-btn">
41+
<button class="btn btn-default" type="button" ng-click="search = ''">
42+
Clear
43+
</button>
44+
</span>
45+
</div>
46+
</div>
47+
</div>
48+
</div>
49+
50+
<article class="panel panel-default" ng-repeat="lint in data | filter:level | filter:search | orderBy:'id' track by lint.id">
51+
<header class="panel-heading" ng-click="open[lint.id] = !open[lint.id]">
52+
<button class="btn btn-default btn-sm pull-right" style="margin-top: -6px;">
53+
<span ng-show="open[lint.id]">&minus;</span>
54+
<span ng-hide="open[lint.id]">&plus;</span>
55+
</button>
56+
57+
<h2 class="panel-title">
58+
{{lint.id}}
59+
<span ng-if="lint.level == 'Allow'" class="label label-info">Allow</span>
60+
<span ng-if="lint.level == 'Warn'" class="label label-warning">Warn</span>
61+
<span ng-if="lint.level == 'Deny'" class="label label-danger">Deny</span>
62+
</h2>
63+
</header>
64+
65+
<ul class="list-group" ng-if="lint.docs" ng-class="{collapse: true, in: open[lint.id]}">
66+
<li class="list-group-item" ng-repeat="(title, text) in lint.docs">
67+
<h4 class="list-group-item-heading">
68+
{{title}}
69+
</h4>
70+
<div class="list-group-item-text" ng-bind-html="text | markdown"></div>
71+
</li>
72+
</ul>
73+
</article>
74+
</div>
75+
76+
<a href="https://github.com/Manishearth/rust-clippy">
77+
<img style="position: absolute; top: 0; right: 0; border: 0;" src="https://s3.amazonaws.com/github/ribbons/forkme_right_darkblue_121621.png"/>
78+
</a>
79+
80+
<script src="https://cdnjs.cloudflare.com/ajax/libs/marked/0.3.2/marked.min.js"></script>
81+
<script src="https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.4.12/angular.min.js"></script>
82+
<script>
83+
(function () {
84+
angular.module("clippy", [])
85+
.filter('markdown', function ($sce) {
86+
return function (text) {
87+
if (typeof text !== 'string') {
88+
text = ''
89+
};
90+
91+
return $sce.trustAsHtml(
92+
marked(text)
93+
);
94+
};
95+
})
96+
.controller("lintList", function ($scope, $http) {
97+
// Get data
98+
$scope.open = {};
99+
$scope.loading = true;
100+
101+
$http.get('./lints.json')
102+
.success(function (data) {
103+
$scope.data = data;
104+
$scope.loading = false;
105+
})
106+
.error(function (data) {
107+
$scope.error = data;
108+
$scope.loading = false;
109+
});
110+
})
111+
})();
112+
</script>
113+
</body>
114+
</html>

0 commit comments

Comments
 (0)