Skip to content

Commit

Permalink
Fix linting errors
Browse files Browse the repository at this point in the history
  • Loading branch information
raksooo committed Sep 20, 2024
1 parent 0fa7884 commit ac4ac62
Show file tree
Hide file tree
Showing 52 changed files with 453 additions and 403 deletions.
2 changes: 1 addition & 1 deletion gui/scripts/extract-translations.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const { GettextExtractor, JsExtractors, HtmlExtractors } = require('gettext-extractor');
const { GettextExtractor, JsExtractors } = require('gettext-extractor');
const path = require('path');

const extractor = new GettextExtractor();
Expand Down
20 changes: 11 additions & 9 deletions gui/scripts/verify-translations-format.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,14 +62,14 @@ function checkFormatSpecifiers(translation: GetTextTranslation): boolean {
.every((result) => result);
}

function checkHtmlTagsImpl(value: string): { correct: boolean, amount: number } {
const tagsRegexp = new RegExp("<.*?>", "g");
function checkHtmlTagsImpl(value: string): { correct: boolean; amount: number } {
const tagsRegexp = new RegExp('<.*?>', 'g');
const tags = value.match(tagsRegexp) ?? [];
const tagTypes = tags.map((tag) => tag.slice(1, -1));

// Make sure tags match by pushing start-tags to a stack and matching closing tags with the last
// item.
let tagStack: string[] = [];
const tagStack: string[] = [];
for (let tag of tagTypes) {
const selfClosing = tag.endsWith('/');
const endTag = tag.startsWith('/');
Expand All @@ -94,21 +94,23 @@ function checkHtmlTagsImpl(value: string): { correct: boolean, amount: number }
}

if (tagStack.length > 0) {
console.error(`Missing closing-tags (${tagStack}) in "${value}"`);
return { correct: false, amount: NaN };
console.error(`Missing closing-tags (${tagStack}) in "${value}"`);
return { correct: false, amount: NaN };
}

return { correct: true, amount: tags.length / 2 };
}

function checkHtmlTags(translation: GetTextTranslation): boolean {
let { correct, amount: sourceAmount } = checkHtmlTagsImpl(translation.msgid);
const { correct, amount: sourceAmount } = checkHtmlTagsImpl(translation.msgid);

let translationsCorrect = translation.msgstr.every((value) => {
let { correct, amount } = checkHtmlTagsImpl(value);
const translationsCorrect = translation.msgstr.every((value) => {
const { correct, amount } = checkHtmlTagsImpl(value);
// The amount doesn't make sense if the string isn't correctly formatted.
if (correct && amount !== sourceAmount) {
console.error(`Incorrect amount of tags in translation for "${translation.msgid}": "${value}"`);
console.error(
`Incorrect amount of tags in translation for "${translation.msgid}": "${value}"`,
);
}
return correct && amount === sourceAmount;
});
Expand Down
2 changes: 0 additions & 2 deletions gui/src/main/daemon-rpc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -791,15 +791,13 @@ export class DaemonRpc {
}

private channelOptions(): grpc.ClientOptions {
/* eslint-disable @typescript-eslint/naming-convention */
return {
'grpc.max_reconnect_backoff_ms': 3000,
'grpc.initial_reconnect_backoff_ms': 3000,
'grpc.keepalive_time_ms': Math.pow(2, 30),
'grpc.keepalive_timeout_ms': Math.pow(2, 30),
'grpc.client_idle_timeout_ms': Math.pow(2, 30),
};
/* eslint-enable @typescript-eslint/naming-convention */
}

private connectivityChangeCallback(timeoutErr?: Error) {
Expand Down
5 changes: 3 additions & 2 deletions gui/src/main/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ import Version, { GUI_VERSION } from './version';
const execAsync = util.promisify(exec);

// Only import split tunneling library on correct OS.
// eslint-disable-next-line @typescript-eslint/no-require-imports
const linuxSplitTunneling = process.platform === 'linux' && require('./linux-split-tunneling');
// This is used on Windows and macOS and will be undefined on Linux.
const splitTunneling: ISplitTunnelingAppListRetriever | undefined = importSplitTunneling();
Expand Down Expand Up @@ -1115,11 +1116,11 @@ class ApplicationMain

function importSplitTunneling() {
if (process.platform === 'win32') {
// eslint-disable-next-line @typescript-eslint/no-var-requires
// eslint-disable-next-line @typescript-eslint/no-require-imports
const { WindowsSplitTunnelingAppListRetriever } = require('./windows-split-tunneling');
return new WindowsSplitTunnelingAppListRetriever();
} else if (process.platform === 'darwin') {
// eslint-disable-next-line @typescript-eslint/no-var-requires
// eslint-disable-next-line @typescript-eslint/no-require-imports
const { MacOsSplitTunnelingAppListRetriever } = require('./macos-split-tunneling');
return new MacOsSplitTunnelingAppListRetriever();
}
Expand Down
1 change: 0 additions & 1 deletion gui/src/main/linux-desktop-entry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,6 @@ function getGtkThemeDirectories(): Promise<DirectoryDescription[]> {
process.env.ORIGINAL_XDG_CURRENT_DESKTOP ?? process.env.XDG_CURRENT_DESKTOP ?? '';
child_process.exec(
'gsettings get org.gnome.desktop.interface icon-theme',
// eslint-disable-next-line @typescript-eslint/naming-convention
{ env: { XDG_CURRENT_DESKTOP: xdgCurrentDesktop } },
(error, stdout) => {
if (error) {
Expand Down
4 changes: 2 additions & 2 deletions gui/src/main/linux-split-tunneling.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ export async function getApplications(locale: string): Promise<ILinuxSplitTunnel
for (const entryPath of desktopEntryPaths) {
try {
desktopEntries.push(await readDesktopEntry(entryPath, locale));
} catch (e) {
} catch {
// no-op
}
}
Expand Down Expand Up @@ -141,7 +141,7 @@ async function replaceIconNameWithDataUrl(
}

return { ...app, icon: await getImageDataUrl(iconPath) };
} catch (e) {
} catch {
return app;
}
}
Expand Down
2 changes: 1 addition & 1 deletion gui/src/main/logging.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ function fileExists(filePath: string): boolean {
try {
fs.accessSync(filePath);
return true;
} catch (e) {
} catch {
return false;
}
}
2 changes: 1 addition & 1 deletion gui/src/main/user-interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -494,7 +494,7 @@ export default class UserInterface implements WindowControllerDelegate {
return;
}

// eslint-disable-next-line @typescript-eslint/no-var-requires
// eslint-disable-next-line @typescript-eslint/no-require-imports
const { NSEventMonitor, NSEventMask } = require('nseventmonitor');
const macEventMonitor = new NSEventMonitor();
const eventMask = NSEventMask.leftMouseDown | NSEventMask.rightMouseDown;
Expand Down
2 changes: 1 addition & 1 deletion gui/src/main/windows-split-tunneling.ts
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,7 @@ export class WindowsSplitTunnelingAppListRetriever implements ISplitTunnelingApp
let fileHandle: fs.promises.FileHandle;
try {
fileHandle = await fs.promises.open(path, fs.constants.O_RDONLY);
} catch (e) {
} catch {
return false;
}

Expand Down
2 changes: 1 addition & 1 deletion gui/src/renderer/app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -400,7 +400,7 @@ export default class AppRenderer {
this.loginState = 'too many devices';

this.history.reset(RoutePath.tooManyDevices, { transition: transitions.push });
} catch (e) {
} catch {
log.error('Failed to fetch device list');
actions.account.loginFailed('list-devices');
}
Expand Down
2 changes: 1 addition & 1 deletion gui/src/renderer/components/ClipboardLabel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ export default function ClipboardLabel(props: IProps) {
return (
<StyledLabelContainer>
<StyledLabel aria-hidden={obscured} {...otherProps}>
{obscured ? '●●●● ●●●● ●●●● ●●●●' : displayValue ?? value}
{obscured ? '●●●● ●●●● ●●●● ●●●●' : (displayValue ?? value)}
</StyledLabel>
{obscureValue !== false && (
<StyledButton
Expand Down
2 changes: 1 addition & 1 deletion gui/src/renderer/components/EditApiAccessMethod.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ function AccessMethodForm() {

const onSave = useCallback(
async (newMethod: NamedCustomProxy) => {
const enabled = id === undefined ? true : method?.enabled ?? true;
const enabled = id === undefined ? true : (method?.enabled ?? true);
updatedMethod.current = { ...newMethod, enabled };
if (
updatedMethod.current !== undefined &&
Expand Down
1 change: 0 additions & 1 deletion gui/src/renderer/components/ImageView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ export default function ImageView(props: IImageViewProps) {
? props.source
: `../../assets/images/${props.source}.svg`;

// eslint-disable-next-line @typescript-eslint/naming-convention
const style = useMemo(() => ({ WebkitMaskImage: `url('${url}')` }), [url]);

if (props.tintColor) {
Expand Down
2 changes: 1 addition & 1 deletion gui/src/renderer/components/Login.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,7 @@ export default class Login extends React.Component<IProps, IState> {
await this.props.clearAccountHistory();

// TODO: Remove account from memory
} catch (error) {
} catch {
// TODO: Show error
}
}
Expand Down
2 changes: 1 addition & 1 deletion gui/src/renderer/components/NotificationBanner.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ export function NotificationBanner(props: INotificationBannerProps) {

useEffect(() => {
const newHeight =
props.children !== undefined ? contentRef.current?.getBoundingClientRect().height ?? 0 : 0;
props.children !== undefined ? (contentRef.current?.getBoundingClientRect().height ?? 0) : 0;
if (newHeight !== contentHeight) {
setContentHeight(newHeight);
setAlignBottom((alignBottom) => alignBottom || contentHeight === 0 || newHeight === 0);
Expand Down
6 changes: 3 additions & 3 deletions gui/src/renderer/components/ProblemReport.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ function Form() {
try {
const reportId = await collectLog();
await viewLog(reportId);
} catch (error) {
} catch {
// TODO: handle error
} finally {
setDisableActions(false);
Expand Down Expand Up @@ -431,7 +431,7 @@ const ProblemReportContextProvider = ({ children }: { children: ReactNode }) =>
await sendProblemReport(email, message, reportId);
clearReportForm();
setSendState(SendState.success);
} catch (error) {
} catch {
setSendState(SendState.failed);
}
}, [email, message]);
Expand All @@ -447,7 +447,7 @@ const ProblemReportContextProvider = ({ children }: { children: ReactNode }) =>
try {
setSendState(SendState.sending);
await sendReport();
} catch (error) {
} catch {
// No-op
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ export default function FeatureIndicators(props: FeatureIndicatorsProps) {
tunnelState.state === 'connected' || tunnelState.state === 'connecting';

const featureIndicators = useRef(
featureIndicatorsVisible ? tunnelState.featureIndicators ?? [] : [],
featureIndicatorsVisible ? (tunnelState.featureIndicators ?? []) : [],
);

if (featureIndicatorsVisible && tunnelState.featureIndicators) {
Expand Down
18 changes: 9 additions & 9 deletions gui/src/renderer/lib/ip.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export abstract class IpAddress<G extends number[]> {
public static fromString(ip: string): IPv4Address | IPv6Address {
try {
return IPv4Address.fromString(ip);
} catch (e) {
} catch {
return IPv6Address.fromString(ip);
}
}
Expand Down Expand Up @@ -80,7 +80,7 @@ export class IPv4Address extends IpAddress<IPv4Octets> {
try {
const octets = IPv4Address.octetsFromString(ip);
return new IPv4Address(octets);
} catch (e) {
} catch {
throw new Error(`Invalid ip: ${ip}`);
}
}
Expand All @@ -94,7 +94,7 @@ export class IPv4Address extends IpAddress<IPv4Octets> {
return parsedOctets;
}
}
} catch (e) {
} catch {
// no-op
}

Expand All @@ -105,7 +105,7 @@ export class IPv4Address extends IpAddress<IPv4Octets> {
try {
IPv4Address.fromString(ip);
return true;
} catch (e) {
} catch {
return false;
}
}
Expand Down Expand Up @@ -135,7 +135,7 @@ export class IPv4Range extends IpRange<IPv4Octets> {
const prefixSize = parseInt(parts[1]);
return new IPv4Range(octets, prefixSize);
}
} catch (e) {
} catch {
// no-op
}

Expand Down Expand Up @@ -167,7 +167,7 @@ export class IPv6Address extends IpAddress<IPv6Groups> {
try {
const groups = IPv6Address.groupsFromString(ip);
return new IPv6Address(groups);
} catch (e) {
} catch {
throw new Error(`Invalid ip: ${ip}`);
}
}
Expand Down Expand Up @@ -200,7 +200,7 @@ export class IPv6Address extends IpAddress<IPv6Groups> {
}
}
}
} catch (e) {
} catch {
// no-op
}

Expand All @@ -211,7 +211,7 @@ export class IPv6Address extends IpAddress<IPv6Groups> {
try {
IPv6Address.fromString(ip);
return true;
} catch (e) {
} catch {
return false;
}
}
Expand Down Expand Up @@ -241,7 +241,7 @@ export class IPv6Range extends IpRange<IPv6Groups> {
const prefixSize = parseInt(parts[1], 10);
return new IPv6Range(groups, prefixSize);
}
} catch (e) {
} catch {
// no-op
}

Expand Down
9 changes: 8 additions & 1 deletion gui/tasks/assets.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,14 @@ copyHtml.displayName = 'copy-html';
copyLocales.displayName = 'copy-locales';
copyGeoData.displayName = 'copy-geo-data';

exports.copyAll = parallel(copyStaticAssets, copyConfig, copyCss, copyHtml, copyLocales, copyGeoData);
exports.copyAll = parallel(
copyStaticAssets,
copyConfig,
copyCss,
copyHtml,
copyLocales,
copyGeoData,
);
exports.copyStaticAssets = copyStaticAssets;
exports.copyCss = copyCss;
exports.copyHtml = copyHtml;
Expand Down
Loading

0 comments on commit ac4ac62

Please sign in to comment.