Skip to content

Commit

Permalink
Use early returns
Browse files Browse the repository at this point in the history
  • Loading branch information
Serial-ATA committed May 15, 2022
1 parent a30587e commit b81d703
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 15 deletions.
7 changes: 4 additions & 3 deletions util/gh-pages/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@
left: auto;
}

<!-- TODO -->
#version-filter-count {
display: none;
}
Expand Down Expand Up @@ -291,7 +292,7 @@
border: 1px solid var(--theme-popup-border);
}

#version-filter-selector .item {
#version-filter-selector .checkbox {
display: flex;
}

Expand Down Expand Up @@ -440,14 +441,14 @@ <h1>Clippy Lints</h1>
<span class="caret"></span>
</button>
<ul id="version-filter-selector" class="dropdown-menu">
<li class="item">
<li class="checkbox">
<label ng-click="clearVersionFilters()">
<input type="checkbox" class="invisible" />
Clear filters
</label>
</li>
<li role="separator" class="divider"></li>
<li class="item" ng-repeat="(filter, vars) in versionFilters">
<li class="checkbox" ng-repeat="(filter, vars) in versionFilters">
<label ng-attr-for="filter-{filter}">{{filter}}</label>
<span>1.</span>
<input type="number"
Expand Down
20 changes: 8 additions & 12 deletions util/gh-pages/script.js
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,7 @@
// 1.29.0 and greater
if (minorVersion && minorVersion > 28) {
$scope.versionFilters[filter].enabled = true;
continue;
}

$scope.versionFilters[filter].enabled = false;
Expand All @@ -201,25 +202,20 @@
let lintVersion = lint.version.startsWith("pre ") ? lint.version.substring(4, lint.version.length) : lint.version;
let lintMinorVersion = lintVersion.substring(2, 4);

let result;
switch (filter) {
// "=" gets the highest priority, since all filters are inclusive
case "=":
return (lintMinorVersion == minorVersion);
case "≥":
result = (lintMinorVersion >= minorVersion);
if (lintMinorVersion < minorVersion) { return false; }
break;
case "≤":
result = (lintMinorVersion <= minorVersion);
if (lintMinorVersion > minorVersion) { return false; }
break;
// "=" gets the highest priority, since all filters are inclusive
case "=":
return (lintMinorVersion == minorVersion);
default:
return true
}

if (!result) {
return false;
}

let cmpFilter;
if (filter === "≥") {
cmpFilter = "≤";
Expand All @@ -229,10 +225,10 @@

if (filters[cmpFilter].enabled) {
let cmpMinorVersion = filters[cmpFilter].minorVersion;
result = (cmpFilter === "≥") ? (lintMinorVersion >= cmpMinorVersion) : (lintMinorVersion <= cmpMinorVersion);
return (cmpFilter === "≥") ? (lintMinorVersion >= cmpMinorVersion) : (lintMinorVersion <= cmpMinorVersion);
}

return result;
return true;
}
}

Expand Down

0 comments on commit b81d703

Please sign in to comment.