Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 9691ad0

Browse files
committedDec 29, 2018
Fix all non-bug lints
This change fixes all non-bug lints. A few lint rules are tweaked, and a few code lines are tweaked (almost all dead code elimination). Also, update the rustdoc-js tester in anticipation of let/const statements.
1 parent 43d26b1 commit 9691ad0

File tree

6 files changed

+24
-17
lines changed

6 files changed

+24
-17
lines changed
 

‎src/librustdoc/html/static/.eslintrc.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ module.exports = {
66
"extends": "eslint:recommended",
77
"parserOptions": {
88
"ecmaVersion": 2015,
9-
"sourceType": "module"
9+
"sourceType": "script"
1010
},
1111
"rules": {
1212
"linebreak-style": [
@@ -16,6 +16,10 @@ module.exports = {
1616
"semi": [
1717
"error",
1818
"always"
19+
],
20+
"no-constant-condition": [
21+
"error",
22+
{ "checkLoops": false }
1923
]
2024
}
2125
};

‎src/librustdoc/html/static/main.js

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
11
// From rust:
22
/* global ALIASES, currentCrate, rootPath */
33

4+
// From DOM global ids:
5+
/* global help */
6+
47
// Local js definitions:
58
/* global addClass, getCurrentValue, hasClass */
6-
/* global isHidden onEach, removeClass, updateLocalStorage */
9+
/* global isHidden, onEachLazy, removeClass, updateLocalStorage */
710

811
if (!String.prototype.startsWith) {
912
String.prototype.startsWith = function(searchString, position) {
@@ -79,8 +82,6 @@ if (!DOMTokenList.prototype.remove) {
7982
// 2 for "In Return Types"
8083
var currentTab = 0;
8184

82-
var themesWidth = null;
83-
8485
var titleBeforeSearch = document.title;
8586

8687
function getPageId() {
@@ -378,7 +379,7 @@ if (!DOMTokenList.prototype.remove) {
378379
len = rootPath.match(/\.\.\//g).length + 1;
379380

380381
for (i = 0; i < len; ++i) {
381-
match = url.match(/\/[^\/]*$/);
382+
match = url.match(/\/[^/]*$/);
382383
if (i < len - 1) {
383384
stripped = match[0] + stripped;
384385
}
@@ -631,8 +632,6 @@ if (!DOMTokenList.prototype.remove) {
631632
if (obj.length > GENERICS_DATA &&
632633
obj[GENERICS_DATA].length >= val.generics.length) {
633634
var elems = obj[GENERICS_DATA].slice(0);
634-
var total = 0;
635-
var done = 0;
636635
// We need to find the type that matches the most to remove it in order
637636
// to move forward.
638637
var vlength = val.generics.length;
@@ -649,8 +648,6 @@ if (!DOMTokenList.prototype.remove) {
649648
if (lev.pos !== -1) {
650649
elems.splice(lev.pos, 1);
651650
lev_distance = Math.min(lev.lev, lev_distance);
652-
total += lev.lev;
653-
done += 1;
654651
} else {
655652
return MAX_LEV_DISTANCE + 1;
656653
}
@@ -912,7 +909,6 @@ if (!DOMTokenList.prototype.remove) {
912909
fullId = generateId(ty);
913910

914911
// allow searching for void (no output) functions as well
915-
var typeOutput = type.length > OUTPUT_DATA ? type[OUTPUT_DATA].name : "";
916912
returned = checkReturned(ty, output, true);
917913
if (output.name === "*" || returned === true) {
918914
in_args = false;
@@ -959,7 +955,7 @@ if (!DOMTokenList.prototype.remove) {
959955
query.output = val;
960956
query.search = val;
961957
// gather matching search results up to a certain maximum
962-
val = val.replace(/\_/g, "");
958+
val = val.replace(/_/g, "");
963959

964960
var valGenerics = extractGenerics(val);
965961

@@ -976,12 +972,10 @@ if (!DOMTokenList.prototype.remove) {
976972

977973
for (j = 0; j < nSearchWords; ++j) {
978974
var lev;
979-
var lev_distance;
980975
ty = searchIndex[j];
981976
if (!ty || (filterCrates !== undefined && ty.crate !== filterCrates)) {
982977
continue;
983978
}
984-
var lev_distance;
985979
var lev_add = 0;
986980
if (paths.length > 1) {
987981
lev = checkPath(contains, paths[paths.length - 1], ty);

‎src/librustdoc/html/static/settings.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
// Local js definitions:
2+
/* global getCurrentValue, updateLocalStorage */
3+
14
(function () {
25
function changeSetting(settingName, isEnabled) {
36
updateLocalStorage('rustdoc-' + settingName, isEnabled);

‎src/librustdoc/html/static/source-script.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
// From rust:
22
/* global sourcesIndex */
33

4+
// From DOM global ids:
5+
/* global search */
6+
47
// Local js definitions:
58
/* global addClass, getCurrentValue, hasClass, removeClass, updateLocalStorage */
69

‎src/librustdoc/html/static/storage.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
// From rust:
22
/* global resourcesSuffix */
33

4+
// eslint doesn't understand the functions here are used elsewhere
5+
/*eslint no-unused-vars: "off"*/
6+
47
var currentTheme = document.getElementById("themeStyle");
58
var mainTheme = document.getElementById("mainThemeStyle");
69

‎src/tools/rustdoc-js/tester.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -81,9 +81,9 @@ function extractFunction(content, functionName) {
8181

8282
// Stupid function extractor for array.
8383
function extractArrayVariable(content, arrayName) {
84-
var splitter = "var " + arrayName;
84+
var splitter = new RegExp("(?:var|const|let) " + arrayName);
8585
while (true) {
86-
var start = content.indexOf(splitter);
86+
var start = content.search(splitter);
8787
if (start === -1) {
8888
break;
8989
}
@@ -126,9 +126,9 @@ function extractArrayVariable(content, arrayName) {
126126

127127
// Stupid function extractor for variable.
128128
function extractVariable(content, varName) {
129-
var splitter = "var " + varName;
129+
var splitter = new RegExp("(?:var|const|let) " + varName);
130130
while (true) {
131-
var start = content.indexOf(splitter);
131+
var start = content.search(splitter);
132132
if (start === -1) {
133133
break;
134134
}

0 commit comments

Comments
 (0)
Please sign in to comment.