2022-04-26 22:22:37 +00:00
|
|
|
(function () {
|
2024-07-29 14:49:56 +00:00
|
|
|
const md = window.markdownit({
|
2022-04-26 22:22:37 +00:00
|
|
|
html: true,
|
|
|
|
linkify: true,
|
|
|
|
typographer: true,
|
|
|
|
highlight: function (str, lang) {
|
|
|
|
if (lang && hljs.getLanguage(lang)) {
|
|
|
|
try {
|
|
|
|
return '<pre class="hljs"><code>' +
|
2022-05-17 16:12:31 +00:00
|
|
|
hljs.highlight(str, { language: lang, ignoreIllegals: true }).value +
|
2022-04-26 22:22:37 +00:00
|
|
|
'</code></pre>';
|
|
|
|
} catch (__) {}
|
|
|
|
}
|
|
|
|
|
|
|
|
return '<pre class="hljs"><code>' + md.utils.escapeHtml(str) + '</code></pre>';
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
function scrollToLint(lintId) {
|
2024-07-29 14:49:56 +00:00
|
|
|
const target = document.getElementById(lintId);
|
2022-04-26 22:22:37 +00:00
|
|
|
if (!target) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
target.scrollIntoView();
|
|
|
|
}
|
|
|
|
|
2023-05-26 01:05:47 +00:00
|
|
|
function scrollToLintByURL($scope, $location) {
|
2024-07-29 14:49:56 +00:00
|
|
|
const removeListener = $scope.$on('ngRepeatFinished', function (ngRepeatFinishedEvent) {
|
2023-05-26 01:05:47 +00:00
|
|
|
scrollToLint($location.path().substring(1));
|
2022-04-26 22:22:37 +00:00
|
|
|
removeListener();
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
function selectGroup($scope, selectedGroup) {
|
2024-07-29 14:49:56 +00:00
|
|
|
const groups = $scope.groups;
|
|
|
|
for (const group in groups) {
|
2022-04-26 22:22:37 +00:00
|
|
|
if (groups.hasOwnProperty(group)) {
|
2024-07-29 14:49:56 +00:00
|
|
|
groups[group] = group === selectedGroup;
|
2022-04-26 22:22:37 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
angular.module("clippy", [])
|
|
|
|
.filter('markdown', function ($sce) {
|
|
|
|
return function (text) {
|
|
|
|
return $sce.trustAsHtml(
|
|
|
|
md.render(text || '')
|
|
|
|
// Oh deer, what a hack :O
|
|
|
|
.replace('<table', '<table class="table"')
|
|
|
|
);
|
|
|
|
};
|
|
|
|
})
|
|
|
|
.directive('filterDropdown', function ($document) {
|
|
|
|
return {
|
|
|
|
restrict: 'A',
|
|
|
|
link: function ($scope, $element, $attr) {
|
|
|
|
$element.bind('click', function (event) {
|
|
|
|
if (event.target.closest('button')) {
|
|
|
|
$element.toggleClass('open');
|
|
|
|
} else {
|
|
|
|
$element.addClass('open');
|
|
|
|
}
|
|
|
|
$element.addClass('open-recent');
|
|
|
|
});
|
|
|
|
|
|
|
|
$document.bind('click', function () {
|
|
|
|
if (!$element.hasClass('open-recent')) {
|
|
|
|
$element.removeClass('open');
|
|
|
|
}
|
|
|
|
$element.removeClass('open-recent');
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|
|
|
|
.directive('onFinishRender', function ($timeout) {
|
|
|
|
return {
|
|
|
|
restrict: 'A',
|
|
|
|
link: function (scope, element, attr) {
|
|
|
|
if (scope.$last === true) {
|
|
|
|
$timeout(function () {
|
|
|
|
scope.$emit(attr.onFinishRender);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
})
|
2023-05-27 17:50:56 +00:00
|
|
|
.controller("lintList", function ($scope, $http, $location, $timeout) {
|
2022-04-26 22:22:37 +00:00
|
|
|
// Level filter
|
2024-07-29 14:49:56 +00:00
|
|
|
const LEVEL_FILTERS_DEFAULT = {allow: true, warn: true, deny: true, none: true};
|
2023-05-26 01:05:47 +00:00
|
|
|
$scope.levels = { ...LEVEL_FILTERS_DEFAULT };
|
2022-04-26 22:22:37 +00:00
|
|
|
$scope.byLevels = function (lint) {
|
|
|
|
return $scope.levels[lint.level];
|
|
|
|
};
|
|
|
|
|
2022-10-09 14:35:52 +00:00
|
|
|
const GROUPS_FILTER_DEFAULT = {
|
2022-04-26 22:22:37 +00:00
|
|
|
cargo: true,
|
|
|
|
complexity: true,
|
|
|
|
correctness: true,
|
|
|
|
nursery: true,
|
|
|
|
pedantic: true,
|
|
|
|
perf: true,
|
|
|
|
restriction: true,
|
|
|
|
style: true,
|
|
|
|
suspicious: true,
|
2024-08-05 14:08:04 +00:00
|
|
|
deprecated: false,
|
2022-10-09 14:35:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
$scope.groups = {
|
|
|
|
...GROUPS_FILTER_DEFAULT
|
2022-04-26 22:22:37 +00:00
|
|
|
};
|
2022-10-09 14:35:52 +00:00
|
|
|
|
2022-05-05 22:27:56 +00:00
|
|
|
$scope.versionFilters = {
|
2022-05-15 00:08:10 +00:00
|
|
|
"≥": {enabled: false, minorVersion: null },
|
|
|
|
"≤": {enabled: false, minorVersion: null },
|
|
|
|
"=": {enabled: false, minorVersion: null },
|
2022-04-26 22:22:37 +00:00
|
|
|
};
|
|
|
|
|
2023-05-26 01:05:47 +00:00
|
|
|
// Map the versionFilters to the query parameters in a way that is easier to work with in a URL
|
|
|
|
const versionFilterKeyMap = {
|
|
|
|
"≥": "gte",
|
|
|
|
"≤": "lte",
|
|
|
|
"=": "eq"
|
|
|
|
};
|
|
|
|
const reverseVersionFilterKeyMap = Object.fromEntries(
|
|
|
|
Object.entries(versionFilterKeyMap).map(([key, value]) => [value, key])
|
|
|
|
);
|
|
|
|
|
2024-04-09 19:00:12 +00:00
|
|
|
const APPLICABILITIES_FILTER_DEFAULT = {
|
|
|
|
MachineApplicable: true,
|
|
|
|
MaybeIncorrect: true,
|
2024-08-05 14:08:04 +00:00
|
|
|
HasPlaceholders: true,
|
|
|
|
Unspecified: true,
|
2024-04-05 00:02:42 +00:00
|
|
|
};
|
|
|
|
|
2024-04-09 19:00:12 +00:00
|
|
|
$scope.applicabilities = {
|
|
|
|
...APPLICABILITIES_FILTER_DEFAULT
|
|
|
|
}
|
2024-04-05 00:02:42 +00:00
|
|
|
|
2023-05-26 01:05:47 +00:00
|
|
|
// loadFromURLParameters retrieves filter settings from the URL parameters and assigns them
|
|
|
|
// to corresponding $scope variables.
|
|
|
|
function loadFromURLParameters() {
|
|
|
|
// Extract parameters from URL
|
|
|
|
const urlParameters = $location.search();
|
|
|
|
|
|
|
|
// Define a helper function that assigns URL parameters to a provided scope variable
|
2023-05-27 00:24:29 +00:00
|
|
|
const handleParameter = (parameter, scopeVariable, defaultValues) => {
|
2023-05-26 01:05:47 +00:00
|
|
|
if (urlParameters[parameter]) {
|
|
|
|
const items = urlParameters[parameter].split(',');
|
|
|
|
for (const key in scopeVariable) {
|
|
|
|
if (scopeVariable.hasOwnProperty(key)) {
|
|
|
|
scopeVariable[key] = items.includes(key);
|
|
|
|
}
|
|
|
|
}
|
2023-05-27 00:24:29 +00:00
|
|
|
} else if (defaultValues) {
|
|
|
|
for (const key in defaultValues) {
|
|
|
|
if (scopeVariable.hasOwnProperty(key)) {
|
|
|
|
scopeVariable[key] = defaultValues[key];
|
|
|
|
}
|
|
|
|
}
|
2023-05-26 01:05:47 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2023-05-27 00:24:29 +00:00
|
|
|
handleParameter('levels', $scope.levels, LEVEL_FILTERS_DEFAULT);
|
|
|
|
handleParameter('groups', $scope.groups, GROUPS_FILTER_DEFAULT);
|
2024-04-09 19:00:12 +00:00
|
|
|
handleParameter('applicabilities', $scope.applicabilities, APPLICABILITIES_FILTER_DEFAULT);
|
2023-05-26 01:05:47 +00:00
|
|
|
|
|
|
|
// Handle 'versions' parameter separately because it needs additional processing
|
|
|
|
if (urlParameters.versions) {
|
|
|
|
const versionFilters = urlParameters.versions.split(',');
|
|
|
|
for (const versionFilter of versionFilters) {
|
|
|
|
const [key, minorVersion] = versionFilter.split(':');
|
|
|
|
const parsedMinorVersion = parseInt(minorVersion);
|
|
|
|
|
|
|
|
// Map the key from the URL parameter to its original form
|
|
|
|
const originalKey = reverseVersionFilterKeyMap[key];
|
|
|
|
|
|
|
|
if (originalKey in $scope.versionFilters && !isNaN(parsedMinorVersion)) {
|
|
|
|
$scope.versionFilters[originalKey].enabled = true;
|
|
|
|
$scope.versionFilters[originalKey].minorVersion = parsedMinorVersion;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Load the search parameter from the URL path
|
|
|
|
const searchParameter = $location.path().substring(1); // Remove the leading slash
|
|
|
|
if (searchParameter) {
|
|
|
|
$scope.search = searchParameter;
|
|
|
|
$scope.open[searchParameter] = true;
|
|
|
|
scrollToLintByURL($scope, $location);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// updateURLParameter updates the URL parameter with the given key to the given value
|
2023-06-03 02:57:45 +00:00
|
|
|
function updateURLParameter(filterObj, urlKey, defaultValue = {}, processFilter = filter => filter) {
|
2023-05-26 01:05:47 +00:00
|
|
|
const parameter = Object.keys(filterObj)
|
|
|
|
.filter(filter => filterObj[filter])
|
2023-06-03 02:57:45 +00:00
|
|
|
.sort()
|
|
|
|
.map(processFilter)
|
|
|
|
.filter(Boolean) // Filters out any falsy values, including null
|
|
|
|
.join(',');
|
|
|
|
|
|
|
|
const defaultParameter = Object.keys(defaultValue)
|
|
|
|
.filter(filter => defaultValue[filter])
|
|
|
|
.sort()
|
2023-05-26 01:05:47 +00:00
|
|
|
.map(processFilter)
|
|
|
|
.filter(Boolean) // Filters out any falsy values, including null
|
|
|
|
.join(',');
|
|
|
|
|
2023-06-03 02:57:45 +00:00
|
|
|
// if we ended up back at the defaults, just remove it from the URL
|
|
|
|
if (parameter === defaultParameter) {
|
|
|
|
$location.search(urlKey, null);
|
|
|
|
} else {
|
|
|
|
$location.search(urlKey, parameter || null);
|
|
|
|
}
|
2023-05-26 01:05:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// updateVersionURLParameter updates the version URL parameter with the given version filters
|
|
|
|
function updateVersionURLParameter(versionFilters) {
|
|
|
|
updateURLParameter(
|
|
|
|
versionFilters,
|
2023-06-03 02:57:45 +00:00
|
|
|
'versions', {},
|
2023-05-26 01:05:47 +00:00
|
|
|
versionFilter => versionFilters[versionFilter].enabled && versionFilters[versionFilter].minorVersion != null
|
|
|
|
? `${versionFilterKeyMap[versionFilter]}:${versionFilters[versionFilter].minorVersion}`
|
|
|
|
: null
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
// updateAllURLParameters updates all the URL parameters with the current filter settings
|
|
|
|
function updateAllURLParameters() {
|
2023-06-03 02:57:45 +00:00
|
|
|
updateURLParameter($scope.levels, 'levels', LEVEL_FILTERS_DEFAULT);
|
|
|
|
updateURLParameter($scope.groups, 'groups', GROUPS_FILTER_DEFAULT);
|
2023-05-26 01:05:47 +00:00
|
|
|
updateVersionURLParameter($scope.versionFilters);
|
2024-04-09 19:00:12 +00:00
|
|
|
updateURLParameter($scope.applicabilities, 'applicabilities', APPLICABILITIES_FILTER_DEFAULT);
|
2023-05-26 01:05:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Add $watches to automatically update URL parameters when the data changes
|
|
|
|
$scope.$watch('levels', function (newVal, oldVal) {
|
|
|
|
if (newVal !== oldVal) {
|
2023-06-03 02:57:45 +00:00
|
|
|
updateURLParameter(newVal, 'levels', LEVEL_FILTERS_DEFAULT);
|
2023-05-26 01:05:47 +00:00
|
|
|
}
|
|
|
|
}, true);
|
|
|
|
|
|
|
|
$scope.$watch('groups', function (newVal, oldVal) {
|
|
|
|
if (newVal !== oldVal) {
|
2023-06-03 02:57:45 +00:00
|
|
|
updateURLParameter(newVal, 'groups', GROUPS_FILTER_DEFAULT);
|
2023-05-26 01:05:47 +00:00
|
|
|
}
|
|
|
|
}, true);
|
|
|
|
|
|
|
|
$scope.$watch('versionFilters', function (newVal, oldVal) {
|
|
|
|
if (newVal !== oldVal) {
|
|
|
|
updateVersionURLParameter(newVal);
|
|
|
|
}
|
|
|
|
}, true);
|
|
|
|
|
2024-04-09 19:00:12 +00:00
|
|
|
$scope.$watch('applicabilities', function (newVal, oldVal) {
|
|
|
|
if (newVal !== oldVal) {
|
|
|
|
updateURLParameter(newVal, 'applicabilities', APPLICABILITIES_FILTER_DEFAULT)
|
|
|
|
}
|
|
|
|
}, true);
|
|
|
|
|
2023-05-26 01:05:47 +00:00
|
|
|
// Watch for changes in the URL path and update the search and lint display
|
2023-06-03 02:57:04 +00:00
|
|
|
$scope.$watch(function () { return $location.path(); }, function (newPath) {
|
2023-05-26 01:05:47 +00:00
|
|
|
const searchParameter = newPath.substring(1);
|
|
|
|
if ($scope.search !== searchParameter) {
|
|
|
|
$scope.search = searchParameter;
|
|
|
|
$scope.open[searchParameter] = true;
|
|
|
|
scrollToLintByURL($scope, $location);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2023-05-27 17:50:56 +00:00
|
|
|
let debounceTimeout;
|
|
|
|
$scope.$watch('search', function (newVal, oldVal) {
|
|
|
|
if (newVal !== oldVal) {
|
|
|
|
if (debounceTimeout) {
|
|
|
|
$timeout.cancel(debounceTimeout);
|
|
|
|
}
|
|
|
|
|
|
|
|
debounceTimeout = $timeout(function () {
|
|
|
|
$location.path(newVal);
|
|
|
|
}, 1000);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2023-06-03 02:57:04 +00:00
|
|
|
$scope.$watch(function () { return $location.search(); }, function (newParameters) {
|
2023-06-03 02:57:45 +00:00
|
|
|
loadFromURLParameters();
|
2023-06-03 02:57:04 +00:00
|
|
|
}, true);
|
2023-05-27 00:24:29 +00:00
|
|
|
|
2023-05-27 17:50:56 +00:00
|
|
|
$scope.updatePath = function () {
|
|
|
|
if (debounceTimeout) {
|
|
|
|
$timeout.cancel(debounceTimeout);
|
|
|
|
}
|
|
|
|
|
|
|
|
$location.path($scope.search);
|
|
|
|
}
|
|
|
|
|
2022-04-26 22:22:37 +00:00
|
|
|
$scope.toggleLevels = function (value) {
|
|
|
|
const levels = $scope.levels;
|
|
|
|
for (const key in levels) {
|
|
|
|
if (levels.hasOwnProperty(key)) {
|
|
|
|
levels[key] = value;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
$scope.toggleGroups = function (value) {
|
|
|
|
const groups = $scope.groups;
|
|
|
|
for (const key in groups) {
|
|
|
|
if (groups.hasOwnProperty(key)) {
|
|
|
|
groups[key] = value;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
2022-10-09 14:35:52 +00:00
|
|
|
|
2024-04-09 19:00:12 +00:00
|
|
|
$scope.toggleApplicabilities = function (value) {
|
|
|
|
const applicabilities = $scope.applicabilities;
|
|
|
|
for (const key in applicabilities) {
|
|
|
|
if (applicabilities.hasOwnProperty(key)) {
|
|
|
|
applicabilities[key] = value;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-10-09 14:35:52 +00:00
|
|
|
$scope.resetGroupsToDefault = function () {
|
2023-06-03 02:57:45 +00:00
|
|
|
$scope.groups = {
|
|
|
|
...GROUPS_FILTER_DEFAULT
|
|
|
|
};
|
2022-10-09 14:35:52 +00:00
|
|
|
};
|
2022-04-26 22:22:37 +00:00
|
|
|
|
|
|
|
$scope.selectedValuesCount = function (obj) {
|
|
|
|
return Object.values(obj).filter(x => x).length;
|
|
|
|
}
|
|
|
|
|
|
|
|
$scope.clearVersionFilters = function () {
|
2024-07-29 14:49:56 +00:00
|
|
|
for (const filter in $scope.versionFilters) {
|
2022-05-15 00:08:10 +00:00
|
|
|
$scope.versionFilters[filter] = { enabled: false, minorVersion: null };
|
2022-05-05 22:27:56 +00:00
|
|
|
}
|
2022-04-26 22:22:37 +00:00
|
|
|
}
|
|
|
|
|
2022-04-29 23:57:16 +00:00
|
|
|
$scope.versionFilterCount = function(obj) {
|
|
|
|
return Object.values(obj).filter(x => x.enabled).length;
|
2022-04-26 22:22:37 +00:00
|
|
|
}
|
|
|
|
|
2022-05-15 00:08:10 +00:00
|
|
|
$scope.updateVersionFilters = function() {
|
|
|
|
for (const filter in $scope.versionFilters) {
|
2024-07-29 14:49:56 +00:00
|
|
|
const minorVersion = $scope.versionFilters[filter].minorVersion;
|
2022-04-26 22:22:37 +00:00
|
|
|
|
2022-05-15 00:08:10 +00:00
|
|
|
// 1.29.0 and greater
|
|
|
|
if (minorVersion && minorVersion > 28) {
|
|
|
|
$scope.versionFilters[filter].enabled = true;
|
2022-05-15 15:30:00 +00:00
|
|
|
continue;
|
2022-05-15 00:08:10 +00:00
|
|
|
}
|
2022-04-26 22:22:37 +00:00
|
|
|
|
2022-05-15 00:08:10 +00:00
|
|
|
$scope.versionFilters[filter].enabled = false;
|
|
|
|
}
|
|
|
|
}
|
2022-04-26 22:22:37 +00:00
|
|
|
|
2022-05-15 00:08:10 +00:00
|
|
|
$scope.byVersion = function(lint) {
|
2024-07-29 14:49:56 +00:00
|
|
|
const filters = $scope.versionFilters;
|
2022-04-26 22:22:37 +00:00
|
|
|
for (const filter in filters) {
|
2022-05-15 00:08:10 +00:00
|
|
|
if (filters[filter].enabled) {
|
2024-07-29 14:49:56 +00:00
|
|
|
const minorVersion = filters[filter].minorVersion;
|
2022-05-15 00:08:10 +00:00
|
|
|
|
|
|
|
// Strip the "pre " prefix for pre 1.29.0 lints
|
2024-07-29 14:49:56 +00:00
|
|
|
const lintVersion = lint.version.startsWith("pre ") ? lint.version.substring(4, lint.version.length) : lint.version;
|
|
|
|
const lintMinorVersion = lintVersion.substring(2, 4);
|
2022-05-15 00:08:10 +00:00
|
|
|
|
|
|
|
switch (filter) {
|
2022-05-15 15:30:00 +00:00
|
|
|
// "=" gets the highest priority, since all filters are inclusive
|
|
|
|
case "=":
|
|
|
|
return (lintMinorVersion == minorVersion);
|
2022-05-15 00:08:10 +00:00
|
|
|
case "≥":
|
2022-05-15 15:30:00 +00:00
|
|
|
if (lintMinorVersion < minorVersion) { return false; }
|
2022-05-15 00:08:10 +00:00
|
|
|
break;
|
|
|
|
case "≤":
|
2022-05-15 15:30:00 +00:00
|
|
|
if (lintMinorVersion > minorVersion) { return false; }
|
2022-05-15 00:08:10 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
return true
|
|
|
|
}
|
2022-04-26 22:22:37 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
$scope.byGroups = function (lint) {
|
|
|
|
return $scope.groups[lint.group];
|
|
|
|
};
|
|
|
|
|
|
|
|
$scope.bySearch = function (lint, index, array) {
|
|
|
|
let searchStr = $scope.search;
|
|
|
|
// It can be `null` I haven't missed this value
|
2024-06-09 12:37:05 +00:00
|
|
|
if (searchStr == null) {
|
2022-04-26 22:22:37 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
searchStr = searchStr.toLowerCase();
|
2022-05-22 19:24:47 +00:00
|
|
|
if (searchStr.startsWith("clippy::")) {
|
|
|
|
searchStr = searchStr.slice(8);
|
|
|
|
}
|
2022-04-26 22:22:37 +00:00
|
|
|
|
|
|
|
// Search by id
|
2024-04-26 18:58:08 +00:00
|
|
|
if (lint.id.indexOf(searchStr.replaceAll("-", "_")) !== -1) {
|
2022-04-26 22:22:37 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Search the description
|
|
|
|
// The use of `for`-loops instead of `foreach` enables us to return early
|
2024-07-29 14:49:56 +00:00
|
|
|
const terms = searchStr.split(" ");
|
|
|
|
const docsLowerCase = lint.docs.toLowerCase();
|
2022-04-26 22:22:37 +00:00
|
|
|
for (index = 0; index < terms.length; index++) {
|
2024-04-23 12:31:26 +00:00
|
|
|
// This is more likely and will therefore be checked first
|
2022-04-26 22:22:37 +00:00
|
|
|
if (docsLowerCase.indexOf(terms[index]) !== -1) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (lint.id.indexOf(terms[index]) !== -1) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2024-04-09 19:00:12 +00:00
|
|
|
$scope.byApplicabilities = function (lint) {
|
2024-08-05 14:08:04 +00:00
|
|
|
return $scope.applicabilities[lint.applicability];
|
2024-04-09 19:00:12 +00:00
|
|
|
};
|
|
|
|
|
2023-05-26 01:05:47 +00:00
|
|
|
// Show details for one lint
|
|
|
|
$scope.openLint = function (lint) {
|
|
|
|
$scope.open[lint.id] = true;
|
|
|
|
$location.path(lint.id);
|
|
|
|
};
|
|
|
|
|
2024-04-04 21:47:05 +00:00
|
|
|
$scope.toggleExpansion = function(lints, isExpanded) {
|
|
|
|
lints.forEach(lint => {
|
|
|
|
$scope.open[lint.id] = isExpanded;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2022-05-18 14:19:50 +00:00
|
|
|
$scope.copyToClipboard = function (lint) {
|
|
|
|
const clipboard = document.getElementById("clipboard-" + lint.id);
|
|
|
|
if (clipboard) {
|
|
|
|
let resetClipboardTimeout = null;
|
2024-07-29 14:49:56 +00:00
|
|
|
const resetClipboardIcon = clipboard.innerHTML;
|
2022-05-18 14:19:50 +00:00
|
|
|
|
|
|
|
function resetClipboard() {
|
|
|
|
resetClipboardTimeout = null;
|
2022-05-18 19:37:05 +00:00
|
|
|
clipboard.innerHTML = resetClipboardIcon;
|
2022-05-18 14:19:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
navigator.clipboard.writeText("clippy::" + lint.id);
|
|
|
|
|
2022-05-18 19:37:05 +00:00
|
|
|
clipboard.innerHTML = "✓";
|
2022-05-18 14:19:50 +00:00
|
|
|
if (resetClipboardTimeout !== null) {
|
|
|
|
clearTimeout(resetClipboardTimeout);
|
|
|
|
}
|
|
|
|
resetClipboardTimeout = setTimeout(resetClipboard, 1000);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-04-26 22:22:37 +00:00
|
|
|
// Get data
|
|
|
|
$scope.open = {};
|
|
|
|
$scope.loading = true;
|
2023-05-26 01:05:47 +00:00
|
|
|
|
2022-04-26 22:22:37 +00:00
|
|
|
// This will be used to jump into the source code of the version that this documentation is for.
|
|
|
|
$scope.docVersion = window.location.pathname.split('/')[2] || "master";
|
|
|
|
|
2023-05-26 01:05:47 +00:00
|
|
|
// Set up the filters from the URL parameters before we start loading the data
|
|
|
|
loadFromURLParameters();
|
2022-04-26 22:22:37 +00:00
|
|
|
|
|
|
|
$http.get('./lints.json')
|
|
|
|
.success(function (data) {
|
|
|
|
$scope.data = data;
|
|
|
|
$scope.loading = false;
|
|
|
|
|
2024-07-29 14:49:56 +00:00
|
|
|
const selectedGroup = getQueryVariable("sel");
|
2022-04-26 22:22:37 +00:00
|
|
|
if (selectedGroup) {
|
|
|
|
selectGroup($scope, selectedGroup.toLowerCase());
|
|
|
|
}
|
|
|
|
|
2023-05-26 01:05:47 +00:00
|
|
|
scrollToLintByURL($scope, $location);
|
2022-04-26 22:22:37 +00:00
|
|
|
|
|
|
|
setTimeout(function () {
|
2024-07-29 14:49:56 +00:00
|
|
|
const el = document.getElementById('filter-input');
|
2022-04-26 22:22:37 +00:00
|
|
|
if (el) { el.focus() }
|
|
|
|
}, 0);
|
|
|
|
})
|
|
|
|
.error(function (data) {
|
|
|
|
$scope.error = data;
|
|
|
|
$scope.loading = false;
|
|
|
|
});
|
|
|
|
});
|
|
|
|
})();
|
|
|
|
|
|
|
|
function getQueryVariable(variable) {
|
2024-07-29 14:49:56 +00:00
|
|
|
const query = window.location.search.substring(1);
|
|
|
|
const vars = query.split('&');
|
|
|
|
for (const entry of vars) {
|
|
|
|
const pair = entry.split('=');
|
2022-04-26 22:22:37 +00:00
|
|
|
if (decodeURIComponent(pair[0]) == variable) {
|
|
|
|
return decodeURIComponent(pair[1]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-07-30 15:31:42 +00:00
|
|
|
function storeValue(settingName, value) {
|
|
|
|
try {
|
|
|
|
localStorage.setItem(`clippy-lint-list-${settingName}`, value);
|
|
|
|
} catch (e) { }
|
|
|
|
}
|
|
|
|
|
|
|
|
function loadValue(settingName) {
|
|
|
|
return localStorage.getItem(`clippy-lint-list-${settingName}`);
|
|
|
|
}
|
|
|
|
|
2022-04-26 22:22:37 +00:00
|
|
|
function setTheme(theme, store) {
|
|
|
|
let enableHighlight = false;
|
|
|
|
let enableNight = false;
|
|
|
|
let enableAyu = false;
|
|
|
|
|
2022-05-19 22:33:16 +00:00
|
|
|
switch(theme) {
|
|
|
|
case "ayu":
|
|
|
|
enableAyu = true;
|
|
|
|
break;
|
|
|
|
case "coal":
|
|
|
|
case "navy":
|
|
|
|
enableNight = true;
|
|
|
|
break;
|
|
|
|
case "rust":
|
|
|
|
enableHighlight = true;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
enableHighlight = true;
|
|
|
|
theme = "light";
|
|
|
|
break;
|
2022-04-26 22:22:37 +00:00
|
|
|
}
|
2022-05-19 22:33:16 +00:00
|
|
|
|
2022-04-26 22:22:37 +00:00
|
|
|
document.getElementsByTagName("body")[0].className = theme;
|
|
|
|
|
2022-05-17 16:12:31 +00:00
|
|
|
document.getElementById("githubLightHighlight").disabled = enableNight || !enableHighlight;
|
|
|
|
document.getElementById("githubDarkHighlight").disabled = !enableNight && !enableAyu;
|
|
|
|
|
2022-04-26 22:22:37 +00:00
|
|
|
document.getElementById("styleHighlight").disabled = !enableHighlight;
|
|
|
|
document.getElementById("styleNight").disabled = !enableNight;
|
|
|
|
document.getElementById("styleAyu").disabled = !enableAyu;
|
|
|
|
|
|
|
|
if (store) {
|
2024-07-30 15:31:42 +00:00
|
|
|
storeValue("theme", theme);
|
2024-08-06 19:38:14 +00:00
|
|
|
} else {
|
|
|
|
document.getElementById(`theme-choice`).value = theme;
|
2022-04-26 22:22:37 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-07-29 14:44:12 +00:00
|
|
|
function handleShortcut(ev) {
|
2024-07-30 15:31:42 +00:00
|
|
|
if (ev.ctrlKey || ev.altKey || ev.metaKey || disableShortcuts) {
|
2024-07-29 14:44:12 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (document.activeElement.tagName === "INPUT") {
|
|
|
|
if (ev.key === "Escape") {
|
|
|
|
document.activeElement.blur();
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
switch (ev.key) {
|
|
|
|
case "s":
|
|
|
|
case "S":
|
|
|
|
case "/":
|
|
|
|
ev.preventDefault(); // To prevent the key to be put into the input.
|
|
|
|
document.getElementById("search-input").focus();
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
document.addEventListener("keypress", handleShortcut);
|
|
|
|
document.addEventListener("keydown", handleShortcut);
|
|
|
|
|
2024-07-30 15:31:42 +00:00
|
|
|
function changeSetting(elem) {
|
|
|
|
if (elem.id === "disable-shortcuts") {
|
|
|
|
disableShortcuts = elem.checked;
|
|
|
|
storeValue(elem.id, elem.checked);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-08-06 19:38:14 +00:00
|
|
|
function onEachLazy(lazyArray, func) {
|
|
|
|
const arr = Array.prototype.slice.call(lazyArray);
|
|
|
|
for (const el of arr) {
|
|
|
|
func(el);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function handleBlur(event) {
|
|
|
|
const parent = document.getElementById("settings-dropdown");
|
|
|
|
if (!parent.contains(document.activeElement) &&
|
|
|
|
!parent.contains(event.relatedTarget)
|
|
|
|
) {
|
|
|
|
parent.classList.remove("open");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function generateSettings() {
|
|
|
|
const settings = document.getElementById("settings-dropdown");
|
|
|
|
const settingsButton = settings.querySelector(".settings-icon")
|
|
|
|
settingsButton.onclick = () => settings.classList.toggle("open");
|
|
|
|
settingsButton.onblur = handleBlur;
|
|
|
|
const settingsMenu = settings.querySelector(".settings-menu");
|
|
|
|
settingsMenu.onblur = handleBlur;
|
|
|
|
onEachLazy(
|
|
|
|
settingsMenu.querySelectorAll("input"),
|
|
|
|
el => el.onblur = handleBlur,
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
generateSettings();
|
|
|
|
|
2022-04-26 22:22:37 +00:00
|
|
|
// loading the theme after the initial load
|
2022-05-19 22:33:16 +00:00
|
|
|
const prefersDark = window.matchMedia("(prefers-color-scheme: dark)");
|
2024-07-30 15:31:42 +00:00
|
|
|
const theme = loadValue('theme');
|
2022-05-19 22:33:16 +00:00
|
|
|
if (prefersDark.matches && !theme) {
|
|
|
|
setTheme("coal", false);
|
|
|
|
} else {
|
|
|
|
setTheme(theme, false);
|
|
|
|
}
|
2024-07-30 15:31:42 +00:00
|
|
|
let disableShortcuts = loadValue('disable-shortcuts') === "true";
|
|
|
|
document.getElementById("disable-shortcuts").checked = disableShortcuts;
|