Skip to content

Commit

Permalink
refactor: enable curly eslint rule (anuraghazra#3137)
Browse files Browse the repository at this point in the history
  • Loading branch information
qwerty541 authored and setdebarr committed Jan 12, 2024
1 parent 9fbfd49 commit ebe0cb5
Show file tree
Hide file tree
Showing 14 changed files with 71 additions and 24 deletions.
2 changes: 1 addition & 1 deletion .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 4 additions & 1 deletion scripts/generate-theme-doc.js
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
4 changes: 3 additions & 1 deletion scripts/preview-theme.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
4 changes: 3 additions & 1 deletion src/cards/stats-card.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 6 additions & 2 deletions src/cards/top-languages-card.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 };
};

Expand Down Expand Up @@ -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);
Expand Down
4 changes: 3 additions & 1 deletion src/common/Card.js
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
20 changes: 15 additions & 5 deletions src/common/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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") {
Expand All @@ -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(",");
};

Expand All @@ -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));
};

Expand Down Expand Up @@ -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) || "";
});
Expand Down
12 changes: 9 additions & 3 deletions src/fetchers/gist-fetcher.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
8 changes: 6 additions & 2 deletions src/fetchers/repo-fetcher.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 });

Expand Down
8 changes: 6 additions & 2 deletions src/fetchers/stats-fetcher.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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: "",
Expand Down
4 changes: 3 additions & 1 deletion src/fetchers/top-languages-fetcher.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 });

Expand Down
4 changes: 3 additions & 1 deletion src/fetchers/wakatime-fetcher.js
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
8 changes: 6 additions & 2 deletions src/getStyles.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};
Expand Down
4 changes: 3 additions & 1 deletion tests/renderTopLanguagesCard.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};

Expand Down

0 comments on commit ebe0cb5

Please sign in to comment.