Skip to content

Commit

Permalink
infra: enable no-negated-condition eslint rule (anuraghazra#3283)
Browse files Browse the repository at this point in the history
* infra: enable no-negated-condition eslint rule

* dev

* dev
  • Loading branch information
qwerty541 authored and setdebarr committed Jan 12, 2024
1 parent ab7bb24 commit e931af8
Show file tree
Hide file tree
Showing 10 changed files with 56 additions and 56 deletions.
2 changes: 1 addition & 1 deletion .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@
// "no-lonely-if": "warn",
"no-mixed-spaces-and-tabs": "warn",
"no-multiple-empty-lines": "warn",
// "no-negated-condition": "off",
"no-negated-condition": "warn",
// "no-nested-ternary": "warn",
// "no-new-object": "warn",
// "no-plusplus": "off",
Expand Down
6 changes: 3 additions & 3 deletions scripts/close-stale-theme-prs.js
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,9 @@ const run = async () => {
// Loop through all stale invalid theme pull requests and close them.
for (const prNumber of staleThemePRsNumbers) {
debug(`Closing #${prNumber} because it is stale...`);
if (!dryRun) {
if (dryRun) {
debug("Dry run enabled, skipping...");
} else {
await octokit.rest.issues.createComment({
owner,
repo,
Expand All @@ -168,8 +170,6 @@ const run = async () => {
pull_number: prNumber,
state: "closed",
});
} else {
debug("Dry run enabled, skipping...");
}
}
} catch (error) {
Expand Down
2 changes: 1 addition & 1 deletion scripts/generate-theme-doc.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ const createTableItem = ({ link, label, isRepoCard }) => {
const generateTable = ({ isRepoCard }) => {
const rows = [];
const themesFiltered = Object.keys(themes).filter(
(name) => name !== (!isRepoCard ? "default_repocard" : "default"),
(name) => name !== (isRepoCard ? "default" : "default_repocard"),
);

for (let i = 0; i < themesFiltered.length; i += 3) {
Expand Down
48 changes: 24 additions & 24 deletions scripts/preview-theme.js
Original file line number Diff line number Diff line change
Expand Up @@ -172,18 +172,18 @@ const upsertComment = async (
body,
) => {
let resp;
if (commentId !== undefined) {
resp = await octokit.rest.issues.updateComment({
if (commentId === undefined) {
resp = await octokit.rest.issues.createComment({
owner,
repo,
comment_id: commentId,
issue_number: issueNumber,
body,
});
} else {
resp = await octokit.rest.issues.createComment({
resp = await octokit.rest.issues.updateComment({
owner,
repo,
issue_number: issueNumber,
comment_id: commentId,
body,
});
}
Expand Down Expand Up @@ -341,10 +341,10 @@ const parseJSON = (json) => {
.filter((x) => typeof x !== "string" || !!x.trim()); // Split json into array of strings and objects.
if (splitJson[0].replace(/\s+/g, "") === "},") {
splitJson[0] = "},";
if (!/\s*}\s*,?\s*$/.test(splitJson[1])) {
splitJson.push(splitJson.shift());
} else {
if (/\s*}\s*,?\s*$/.test(splitJson[1])) {
splitJson.shift();
} else {
splitJson.push(splitJson.shift());
}
parsedJson = splitJson.join("");
}
Expand Down Expand Up @@ -466,10 +466,7 @@ export const run = async () => {
// Check if the theme colors are valid.
debug("Theme preview body: Check if the theme colors are valid...");
let invalidColors = false;
if (!colors) {
warnings.push("Theme colors are missing");
invalidColors = true;
} else {
if (colors) {
const missingKeys = REQUIRED_COLOR_PROPS.filter(
(x) => !Object.keys(colors).includes(x),
);
Expand Down Expand Up @@ -507,6 +504,9 @@ export const run = async () => {
}
}
}
} else {
warnings.push("Theme colors are missing");
invalidColors = true;
}
if (invalidColors) {
themeValid[theme] = false;
Expand Down Expand Up @@ -597,7 +597,10 @@ export const run = async () => {
// Create or update theme-preview comment.
debug("Create or update theme-preview comment...");
let comment_url;
if (!DRY_RUN) {
if (DRY_RUN) {
info(`DRY_RUN: Comment body: ${commentBody}`);
comment_url = "";
} else {
comment_url = await upsertComment(
OCTOKIT,
PULL_REQUEST_ID,
Expand All @@ -606,9 +609,6 @@ export const run = async () => {
comment?.id,
commentBody,
);
} else {
info(`DRY_RUN: Comment body: ${commentBody}`);
comment_url = "";
}

// Change review state and add/remove `invalid` label based on theme PR validity.
Expand All @@ -620,7 +620,10 @@ export const run = async () => {
const reviewReason = themesValid
? undefined
: INVALID_REVIEW_COMMENT(comment_url);
if (!DRY_RUN) {
if (DRY_RUN) {
info(`DRY_RUN: Review state: ${reviewState}`);
info(`DRY_RUN: Review reason: ${reviewReason}`);
} else {
await addReview(
OCTOKIT,
PULL_REQUEST_ID,
Expand All @@ -637,13 +640,13 @@ export const run = async () => {
"invalid",
!themesValid,
);
} else {
info(`DRY_RUN: Review state: ${reviewState}`);
info(`DRY_RUN: Review reason: ${reviewReason}`);
}
} catch (error) {
debug("Set review state to `REQUEST_CHANGES` and add `invalid` label...");
if (!DRY_RUN) {
if (DRY_RUN) {
info(`DRY_RUN: Review state: REQUEST_CHANGES`);
info(`DRY_RUN: Review reason: ${error.message}`);
} else {
await addReview(
OCTOKIT,
PULL_REQUEST_ID,
Expand All @@ -662,9 +665,6 @@ export const run = async () => {
"invalid",
true,
);
} else {
info(`DRY_RUN: Review state: REQUEST_CHANGES`);
info(`DRY_RUN: Review reason: ${error.message}`);
}
setFailed(error.message);
}
Expand Down
2 changes: 1 addition & 1 deletion src/cards/stats-card.js
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ const getStyles = ({
.bold { font-weight: 700 }
.icon {
fill: ${iconColor};
display: ${!!show_icons ? "block" : "none"};
display: ${show_icons ? "block" : "none"};
}
.rank-circle-rim {
Expand Down
16 changes: 8 additions & 8 deletions src/cards/top-languages-card.js
Original file line number Diff line number Diff line change
Expand Up @@ -383,14 +383,14 @@ const renderCompactLayout = (langs, width, totalLanguageSize, hideProgress) => {

return `
${
!hideProgress
? `
<mask id="rect-mask">
<rect x="0" y="0" width="${offsetWidth}" height="8" fill="white" rx="5"/>
</mask>
${compactProgressBar}
`
: ""
hideProgress
? ""
: `
<mask id="rect-mask">
<rect x="0" y="0" width="${offsetWidth}" height="8" fill="white" rx="5"/>
</mask>
${compactProgressBar}
`
}
<g transform="translate(0, ${hideProgress ? "0" : "25"})">
${createLanguageTextNode({
Expand Down
20 changes: 10 additions & 10 deletions src/cards/wakatime-card.js
Original file line number Diff line number Diff line change
Expand Up @@ -315,11 +315,11 @@ const renderWakatimeCard = (stats = {}, options = { hide: [] }) => {
: noCodingActivityNode({
// @ts-ignore
color: textColor,
text: !stats.is_coding_activity_visible
? i18n.t("wakatimecard.notpublic")
: stats.is_other_usage_visible
? i18n.t("wakatimecard.nocodingactivity")
: i18n.t("wakatimecard.nocodedetails"),
text: stats.is_coding_activity_visible
? stats.is_other_usage_visible
? i18n.t("wakatimecard.nocodingactivity")
: i18n.t("wakatimecard.nocodedetails")
: i18n.t("wakatimecard.notpublic"),
})
}
`;
Expand All @@ -344,11 +344,11 @@ const renderWakatimeCard = (stats = {}, options = { hide: [] }) => {
noCodingActivityNode({
// @ts-ignore
color: textColor,
text: !stats.is_coding_activity_visible
? i18n.t("wakatimecard.notpublic")
: stats.is_other_usage_visible
? i18n.t("wakatimecard.nocodingactivity")
: i18n.t("wakatimecard.nocodedetails"),
text: stats.is_coding_activity_visible
? stats.is_other_usage_visible
? i18n.t("wakatimecard.nocodingactivity")
: i18n.t("wakatimecard.nocodedetails")
: i18n.t("wakatimecard.notpublic"),
}),
],
gap: lheight,
Expand Down
6 changes: 3 additions & 3 deletions src/common/Card.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,9 @@ class Card {
// returns theme based colors with proper overrides and defaults
this.colors = colors;
this.title =
customTitle !== undefined
? encodeHTML(customTitle)
: encodeHTML(defaultTitle);
customTitle === undefined
? encodeHTML(defaultTitle)
: encodeHTML(customTitle);

this.css = "";

Expand Down
2 changes: 1 addition & 1 deletion src/common/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -415,7 +415,7 @@ const wrapTextMultiline = (text, width = 59, maxLines = 3) => {
const noop = () => {};
// return console instance based on the environment
const logger =
process.env.NODE_ENV !== "test" ? console : { log: noop, error: noop };
process.env.NODE_ENV === "test" ? { log: noop, error: noop } : console;

const ONE_MINUTE = 60;
const FIVE_MINUTES = 300;
Expand Down
8 changes: 4 additions & 4 deletions src/fetchers/stats-fetcher.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ const GRAPHQL_STATS_QUERY = `
* @returns {Promise<AxiosResponse>} Axios response.
*/
const fetcher = (variables, token) => {
const query = !variables.after ? GRAPHQL_STATS_QUERY : GRAPHQL_REPOS_QUERY;
const query = variables.after ? GRAPHQL_REPOS_QUERY : GRAPHQL_STATS_QUERY;
return request(
{
query,
Expand Down Expand Up @@ -138,10 +138,10 @@ const statsFetcher = async ({

// Store stats data.
const repoNodes = res.data.data.user.repositories.nodes;
if (!stats) {
stats = res;
} else {
if (stats) {
stats.data.data.user.repositories.nodes.push(...repoNodes);
} else {
stats = res;
}

// Disable multi page fetching on public Vercel instance due to rate limits.
Expand Down

0 comments on commit e931af8

Please sign in to comment.