refactor: enable curly eslint rule (#3137)

This commit is contained in:
Alexandr Garbuzov 2023-09-12 11:06:01 +03:00 committed by GitHub
parent b611018476
commit c42798b39e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
14 changed files with 71 additions and 24 deletions

View file

@ -39,7 +39,7 @@
}],
"block-scoped-var": "warn",
"consistent-return": "error",
// "curly": "error",
"curly": "error",
// "default-case": "warn",
// the dot goes with the property when doing multiline

View file

@ -60,9 +60,12 @@ const generateLinks = (fn) => {
};
const createTableItem = ({ link, label, isRepoCard }) => {
if (!link || !label) return "";
if (!link || !label) {
return "";
}
return `\`${label}\` ![${link}][${link}${isRepoCard ? "_repo" : ""}]`;
};
const generateTable = ({ isRepoCard }) => {
const rows = [];
const themesFiltered = Object.keys(themes).filter(

View file

@ -75,7 +75,9 @@ class IncorrectJsonFormatError extends Error {
* @returns {number} PR number.
*/
const getPrNumber = () => {
if (process.env.MOCK_PR_NUMBER) return process.env.MOCK_PR_NUMBER; // For testing purposes.
if (process.env.MOCK_PR_NUMBER) {
return process.env.MOCK_PR_NUMBER; // For testing purposes.
}
const pullRequest = github.context.payload.pull_request;
if (!pullRequest) {

View file

@ -358,7 +358,9 @@ const renderStatsCard = (stats, options = {}) => {
card.setHideTitle(hide_title);
card.setCSS(cssStyles);
if (disable_animations) card.disableAnimations();
if (disable_animations) {
card.disableAnimations();
}
/**
* Calculates the right rank circle translation values such that the rank circle

View file

@ -87,7 +87,9 @@ const polarToCartesian = (centerX, centerY, radius, angleInDegrees) => {
const cartesianToPolar = (centerX, centerY, x, y) => {
const radius = Math.sqrt(Math.pow(x - centerX, 2) + Math.pow(y - centerY, 2));
let angleInDegrees = radiansToDegrees(Math.atan2(y - centerY, x - centerX));
if (angleInDegrees < 0) angleInDegrees += 360;
if (angleInDegrees < 0) {
angleInDegrees += 360;
}
return { radius, angleInDegrees };
};
@ -808,7 +810,9 @@ const renderTopLanguages = (topLangs, options = {}) => {
colors,
});
if (disable_animations) card.disableAnimations();
if (disable_animations) {
card.disableAnimations();
}
card.setHideBorder(hide_border);
card.setHideTitle(hide_title);

View file

@ -150,7 +150,9 @@ class Card {
* @returns {string} The rendered card gradient.
*/
renderGradient() {
if (typeof this.colors.bgColor !== "object") return "";
if (typeof this.colors.bgColor !== "object") {
return "";
}
const gradients = this.colors.bgColor.slice(1);
return typeof this.colors.bgColor === "object"

View file

@ -60,7 +60,9 @@ const createLanguageNode = (langName, langColor) => {
* @returns {string} Icon with label SVG object.
*/
const iconWithLabel = (icon, label, testid, iconSize) => {
if (typeof label === "number" && label <= 0) return "";
if (typeof label === "number" && label <= 0) {
return "";
}
const iconSvg = `
<svg
class="icon"
@ -124,7 +126,9 @@ const isValidHexColor = (hexColor) => {
* @returns {boolean | undefined } The parsed value.
*/
const parseBoolean = (value) => {
if (typeof value === "boolean") return value;
if (typeof value === "boolean") {
return value;
}
if (typeof value === "string") {
if (value.toLowerCase() === "true") {
@ -143,7 +147,9 @@ const parseBoolean = (value) => {
* @returns {string[]} The array of strings.
*/
const parseArray = (str) => {
if (!str) return [];
if (!str) {
return [];
}
return str.split(",");
};
@ -157,7 +163,9 @@ const parseArray = (str) => {
*/
const clampValue = (number, min, max) => {
// @ts-ignore
if (Number.isNaN(parseInt(number))) return min;
if (Number.isNaN(parseInt(number))) {
return min;
}
return Math.max(min, Math.min(number, max));
};
@ -501,7 +509,9 @@ const chunkArray = (arr, perChunk) => {
* @returns {string} String with emoji parsed.
*/
const parseEmojis = (str) => {
if (!str) throw new Error("[parseEmoji]: str argument not provided");
if (!str) {
throw new Error("[parseEmoji]: str argument not provided");
}
return str.replace(/:\w+:/gm, (emoji) => {
return toEmoji.get(emoji) || "";
});

View file

@ -57,10 +57,16 @@ const fetcher = async (variables, token) => {
* @returns {Promise<GistData>} Gist data.
*/
const fetchGist = async (id) => {
if (!id) throw new MissingParamError(["id"], "/api/gist?id=GIST_ID");
if (!id) {
throw new MissingParamError(["id"], "/api/gist?id=GIST_ID");
}
const res = await retryer(fetcher, { gistName: id });
if (res.data.errors) throw new Error(res.data.errors[0].message);
if (!res.data.data.viewer.gist) throw new Error("Gist not found");
if (res.data.errors) {
throw new Error(res.data.errors[0].message);
}
if (!res.data.data.viewer.gist) {
throw new Error("Gist not found");
}
const data = res.data.data.viewer.gist;
return {
name: data.files[Object.keys(data.files)[0]].name,

View file

@ -73,8 +73,12 @@ const fetchRepo = async (username, reponame) => {
if (!username && !reponame) {
throw new MissingParamError(["username", "repo"], urlExample);
}
if (!username) throw new MissingParamError(["username"], urlExample);
if (!reponame) throw new MissingParamError(["repo"], urlExample);
if (!username) {
throw new MissingParamError(["username"], urlExample);
}
if (!reponame) {
throw new MissingParamError(["repo"], urlExample);
}
let res = await retryer(fetcher, { login: username, repo: reponame });

View file

@ -116,7 +116,9 @@ const statsFetcher = async (username) => {
while (hasNextPage) {
const variables = { login: username, first: 100, after: endCursor };
let res = await retryer(fetcher, variables);
if (res.data.errors) return res;
if (res.data.errors) {
return res;
}
// Store stats data.
const repoNodes = res.data.data.user.repositories.nodes;
@ -199,7 +201,9 @@ const fetchStats = async (
include_all_commits = false,
exclude_repo = [],
) => {
if (!username) throw new MissingParamError(["username"]);
if (!username) {
throw new MissingParamError(["username"]);
}
const stats = {
name: "",

View file

@ -71,7 +71,9 @@ const fetchTopLanguages = async (
size_weight = 1,
count_weight = 0,
) => {
if (!username) throw new MissingParamError(["username"]);
if (!username) {
throw new MissingParamError(["username"]);
}
const res = await retryer(fetcher, { login: username });

View file

@ -8,7 +8,9 @@ import { CustomError, MissingParamError } from "../common/utils.js";
* @returns {Promise<WakaTimeData>} WakaTime data response.
*/
const fetchWakatimeStats = async ({ username, api_domain }) => {
if (!username) throw new MissingParamError(["username"]);
if (!username) {
throw new MissingParamError(["username"]);
}
try {
const { data } = await axios.get(

View file

@ -10,8 +10,12 @@ const calculateCircleProgress = (value) => {
const radius = 40;
const c = Math.PI * (radius * 2);
if (value < 0) value = 0;
if (value > 100) value = 100;
if (value < 0) {
value = 0;
}
if (value > 100) {
value = 100;
}
return ((100 - value) / 100) * c;
};

View file

@ -70,7 +70,9 @@ const langPercentFromDonutLayoutSvg = (d, centerX, centerY) => {
cartesianToPolar(centerX, centerY, dTmp[0], dTmp[1]).angleInDegrees + 90;
let startAngle =
cartesianToPolar(centerX, centerY, dTmp[7], dTmp[8]).angleInDegrees + 90;
if (startAngle > endAngle) startAngle -= 360;
if (startAngle > endAngle) {
startAngle -= 360;
}
return (endAngle - startAngle) / 3.6;
};