Fix all ESLint errors: case declarations, empty blocks, display names, keys, and more

This commit is contained in:
alexsparkes
2025-10-27 23:27:13 +00:00
parent b5fbb9db9e
commit 6f05e3bf03
24 changed files with 92 additions and 45 deletions

View File

@@ -90,4 +90,6 @@ const Button = forwardRef(
},
);
Button.displayName = 'Button';
export { Button as default, Button };

View File

@@ -98,7 +98,7 @@ export default class Background extends PureComponent {
switch (backgroundAPI) {
case 'unsplash':
case 'pexels':
case 'pexels': {
const collection = localStorage.getItem('unsplashCollections');
if (collection) {
requestURL = `${variables.constants.API_URL}/images/unsplash?collections=${collection}&quality=${apiQuality}`;
@@ -106,6 +106,7 @@ export default class Background extends PureComponent {
requestURL = `${variables.constants.API_URL}/images/unsplash?categories=${apiCategories || ''}&quality=${apiQuality}`;
}
break;
}
// Defaults to Mue
default:
requestURL = `${variables.constants.API_URL}/images/random?categories=${apiCategories || ''}&quality=${apiQuality}&excludes=${backgroundExclude}`;
@@ -115,7 +116,7 @@ export default class Background extends PureComponent {
const accept = 'application/json, ' + ((await supportsAVIF()) ? 'image/avif' : 'image/webp');
try {
data = await (await fetch(requestURL, { headers: { accept } })).json();
} catch (e) {
} catch {
// if requesting to the API fails, we get an offline image
this.setState(getOfflineImage('api'));
return null;
@@ -188,7 +189,7 @@ export default class Background extends PureComponent {
const type = localStorage.getItem('backgroundType');
switch (type) {
case 'api':
case 'api': {
if (offline) {
return this.setState(getOfflineImage('api'));
}
@@ -205,8 +206,9 @@ export default class Background extends PureComponent {
); // pre-fetch data about the next image
}
break;
}
case 'colour':
case 'colour': {
let customBackgroundColour = localStorage.getItem('customBackgroundColour');
// check if its a json object
if (customBackgroundColour && customBackgroundColour.startsWith('{')) {
@@ -215,7 +217,7 @@ export default class Background extends PureComponent {
try {
localStorage.setItem('customBackgroundColour', customBackground.gradient[0].colour);
customBackgroundColour = customBackground.gradient.colour;
} catch (e) {
} catch {
// give up
customBackgroundColour = 'rgb(0,0,0)';
}
@@ -225,17 +227,18 @@ export default class Background extends PureComponent {
style: `background: ${customBackgroundColour || 'rgb(0,0,0)'}`,
});
break;
}
case 'random_colour':
case 'random_gradient':
this.setState(randomColourStyleBuilder(type));
break;
case 'custom':
case 'custom': {
let customBackground = [];
const customSaved = localStorage.getItem('customBackground');
try {
customBackground = JSON.parse(customSaved);
} catch (e) {
} catch {
if (customSaved !== '') {
// move to new format
customBackground = [customSaved];
@@ -270,8 +273,9 @@ export default class Background extends PureComponent {
localStorage.setItem('currentBackground', JSON.stringify(object));
}
break;
}
case 'photo_pack':
case 'photo_pack': {
if (offline) {
return this.setState(getOfflineImage('photo_pack'));
}
@@ -347,6 +351,7 @@ export default class Background extends PureComponent {
}
}
break;
}
default:
break;
}

View File

@@ -41,7 +41,7 @@ class Favourite extends PureComponent {
}),
);
break;
default:
default: {
let url = document
.getElementById('backgroundImage')
.style.backgroundImage.replace('url("', '')
@@ -53,9 +53,11 @@ class Favourite extends PureComponent {
if (url.startsWith('blob:')) {
const reader = new FileReader();
url = await new Promise(async (resolve) => {
url = await new Promise((resolve) => {
reader.onloadend = () => resolve(reader.result);
reader.readAsDataURL(await (await fetch(url)).blob());
fetch(url)
.then((res) => res.blob())
.then((blob) => reader.readAsDataURL(blob));
});
}
@@ -86,6 +88,8 @@ class Favourite extends PureComponent {
}),
);
}
break;
}
}
this.setState({

View File

@@ -262,9 +262,13 @@ function PhotoInformation({ info, url, api }) {
try {
setPhotoMap(true);
setMapIcon(false);
} catch (e) {}
} catch {
// Ignore errors
}
};
} catch (e) {}
} catch {
// Element not found
}
const widgetStyle = localStorage.getItem('widgetStyle');

View File

@@ -24,7 +24,6 @@ function CustomURLModal({ modalClose, urlError, modalCloseOnly }) {
type="text"
value={url}
onChange={(e) => setURL(e.target.value.replace(/(\r\n|\n|\r)/gm, ''))}
varient="outlined"
/>
<span className="dropdown-error">{urlError}</span>
<div className="resetFooter">

View File

@@ -24,9 +24,10 @@ const GreetingOptions = () => {
);
const [events, setEvents] = useState(false);
const [birthday, setBirthday] = useState(
new Date(localStorage.getItem('birthday')) || new Date(),
);
const [birthday, setBirthday] = useState(() => {
const stored = localStorage.getItem('birthday');
return stored ? new Date(stored) : new Date();
});
const [enableBirthday, setEnableBirthday] = useState(
localStorage.getItem('birthdayenabled') === 'true' ? 'preferences' : 'preferencesInactive',

View File

@@ -193,7 +193,9 @@ export default class Added extends PureComponent {
this.state.installed.forEach((item) => {
uninstall(item.type, item.name);
});
} catch (e) {}
} catch {
// Ignore errors during bulk uninstall
}
localStorage.setItem('installed', JSON.stringify([]));

View File

@@ -224,7 +224,7 @@ class Marketplace extends PureComponent {
}
switch (value) {
case 'a-z':
case 'a-z': {
// sort by name key alphabetically
const sorted = items.sort((a, b) => {
if (a.display_name < b.display_name) {
@@ -237,6 +237,7 @@ class Marketplace extends PureComponent {
});
items = sorted;
break;
}
case 'z-a':
items.sort();
items.reverse();
@@ -427,6 +428,7 @@ class Marketplace extends PureComponent {
this.state.items.map((item) =>
!item.news ? (
<div
key={item.name}
className="collection"
style={
item.news

View File

@@ -68,7 +68,7 @@ class About extends PureComponent {
})
).json()
).data;
} catch (e) {
} catch {
if (this.controller.signal.aborted === true) {
return;
}
@@ -323,7 +323,9 @@ class About extends PureComponent {
{this.state.sponsors.map(({ handle, avatar }) => {
if (handle === 'empty') {
return (
<p>{variables.getMessage('modals.main.settings.sections.about.no_supporters')}</p>
<p key="empty">
{variables.getMessage('modals.main.settings.sections.about.no_supporters')}
</p>
);
}

View File

@@ -175,7 +175,7 @@ const Overview = () => {
return null;
}
return (
<div className="previewItem" key={`item-${value}`} index={index}>
<div className="previewItem" key={`item-${value}`}>
{getTab(value)}
</div>
);

View File

@@ -4,7 +4,7 @@ import { MdPerson } from 'react-icons/md';
function QuoteSkeleton() {
return (
<div className="quoteSkeleton">
<span className="subtitle">"Never gonna give you up"</span>
<span className="subtitle">&ldquo;Never gonna give you up&rdquo;</span>
<div className="skeletonAuthor">
<div>
<MdPerson />

View File

@@ -69,7 +69,9 @@ class Navbar extends PureComponent {
try {
this.updateRefreshText();
this.setZoom();
} catch (e) {}
} catch {
// Ignore errors
}
}
});

View File

@@ -31,7 +31,9 @@ class Apps extends PureComponent {
this.forceUpdate();
try {
this.setZoom();
} catch (e) {}
} catch {
// Ignore errors
}
}
});

View File

@@ -32,7 +32,9 @@ class Notes extends PureComponent {
this.forceUpdate();
try {
this.setZoom();
} catch (e) {}
} catch {
// Ignore errors
}
}
});

View File

@@ -32,8 +32,8 @@ import {
import { CSS } from '@dnd-kit/utilities';
import EventBus from 'utils/eventbus';
const DragHandle = () => (
<div className="todo-drag-handle" {...arguments[0]}>
const DragHandle = (props) => (
<div className="todo-drag-handle" {...props}>
<MdOutlineDragIndicator />
</div>
);
@@ -88,7 +88,9 @@ class Todo extends PureComponent {
this.forceUpdate();
try {
this.setZoom();
} catch (e) {}
} catch {
// Ignore errors
}
}
});

View File

@@ -310,7 +310,11 @@ class QuickLinksOptions extends PureComponent {
if (this.handleRefresh) {
EventBus.off('refresh', this.handleRefresh);
} else {
try { EventBus.off('refresh'); } catch (e) {}
try {
EventBus.off('refresh');
} catch {
// Ignore errors
}
}
}
render() {

View File

@@ -82,7 +82,7 @@ class Quote extends PureComponent {
this.quote = createRef();
this.quotediv = createRef();
this.quoteauthor = createRef();
this.authorDetails = (localStorage.getItem('authorDetails') === 'true' || true) ? true : false;
this.authorDetails = localStorage.getItem('authorDetails') === 'true';
}
useFavourite() {
@@ -208,11 +208,11 @@ class Quote extends PureComponent {
}
switch (this.state.type) {
case 'custom':
case 'custom': {
let customQuote;
try {
customQuote = JSON.parse(localStorage.getItem('customQuote'));
} catch (e) {
} catch {
// move to new format
customQuote = [
{
@@ -242,7 +242,8 @@ class Quote extends PureComponent {
});
}
break;
case 'quote_pack':
}
case 'quote_pack': {
if (offline) {
return this.doOffline();
}
@@ -268,9 +269,11 @@ class Quote extends PureComponent {
authorimg: data.fallbackauthorimg,
});
} else {
return this.doOffline();
this.doOffline();
}
case 'api':
break;
}
case 'api': {
if (offline) {
return this.doOffline();
}
@@ -307,11 +310,12 @@ class Quote extends PureComponent {
} else {
this.doOffline();
}
} catch (e) {
} catch {
// ...and if that fails we load one locally
this.doOffline();
}
break;
}
default:
break;
}

View File

@@ -188,7 +188,7 @@ class QuoteOptions extends PureComponent {
{this.state.customQuote.length !== 0 ? (
<div className="messagesContainer">
{this.state.customQuote.map((_url, index) => (
<div className="messageMap">
<div className="messageMap" key={index}>
<div className="icon">
<MdOutlineFormatQuote />
</div>

View File

@@ -41,7 +41,7 @@ function Search() {
return () => {
EventBus.off('refresh');
};
}, []);
}, [init]);
const micIcon = createRef();

View File

@@ -50,7 +50,7 @@ export default class Clock extends PureComponent {
time: now,
});
break;
default:
default: {
// Default clock
let time,
sec = '';
@@ -112,6 +112,7 @@ export default class Clock extends PureComponent {
});
}
break;
}
}
this.startTime();

View File

@@ -10,6 +10,8 @@ const Step = memo(({ isActive, index, onClick }) => {
);
});
Step.displayName = 'Step';
function ProgressBar({ numberOfTabs, currentTab, switchTab }) {
return (
<div className="progressbar">

View File

@@ -10,17 +10,20 @@ export default function ExperimentalInit() {
const code = e.which || e.keyCode;
switch (code) {
case 222:
case 222: {
const timeout = localStorage.getItem('debugtimeout');
if (timeout !== '0') {
setTimeout(() => {
// eslint-disable-next-line no-debugger
debugger;
}, timeout);
} else {
// eslint-disable-next-line no-debugger
debugger;
}
break;
}
default:
break;
}

View File

@@ -12,7 +12,7 @@ function showReminder() {
export function install(type, input, sideload, collection) {
switch (type) {
case 'settings':
case 'settings': {
localStorage.removeItem('backup_settings');
const oldSettings = [];
@@ -29,8 +29,9 @@ export function install(type, input, sideload, collection) {
});
showReminder();
break;
}
case 'photos':
case 'photos': {
const currentPhotos = JSON.parse(localStorage.getItem('photo_packs')) || [];
input.photos.forEach((photo) => {
currentPhotos.push(photo);
@@ -49,8 +50,9 @@ export function install(type, input, sideload, collection) {
window.location.reload();
}
break;
}
case 'quotes':
case 'quotes': {
const currentQuotes = JSON.parse(localStorage.getItem('quote_packs')) || [];
input.quotes.forEach((quote) => {
currentQuotes.push(quote);
@@ -64,6 +66,7 @@ export function install(type, input, sideload, collection) {
localStorage.removeItem('quotechange');
EventBus.emit('refresh', 'quote');
break;
}
default:
break;

View File

@@ -9,7 +9,7 @@ function showReminder() {
export function uninstall(type, name) {
let installedContents, packContents;
switch (type) {
case 'settings':
case 'settings': {
const oldSettings = JSON.parse(localStorage.getItem('backup_settings'));
localStorage.clear();
oldSettings.forEach((item) => {
@@ -17,6 +17,7 @@ export function uninstall(type, name) {
});
showReminder();
break;
}
case 'quotes':
installedContents = JSON.parse(localStorage.getItem('quote_packs'));