Skip to content

Commit 8278980

Browse files
authored
infra: enable no-negated-condition eslint rule (anuraghazra#3283)
* infra: enable no-negated-condition eslint rule * dev * dev
1 parent 2567a6e commit 8278980

10 files changed

+56
-56
lines changed

.eslintrc.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@
195195
// "no-lonely-if": "warn",
196196
"no-mixed-spaces-and-tabs": "warn",
197197
"no-multiple-empty-lines": "warn",
198-
// "no-negated-condition": "off",
198+
"no-negated-condition": "warn",
199199
// "no-nested-ternary": "warn",
200200
// "no-new-object": "warn",
201201
// "no-plusplus": "off",

scripts/close-stale-theme-prs.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,9 @@ const run = async () => {
155155
// Loop through all stale invalid theme pull requests and close them.
156156
for (const prNumber of staleThemePRsNumbers) {
157157
debug(`Closing #${prNumber} because it is stale...`);
158-
if (!dryRun) {
158+
if (dryRun) {
159+
debug("Dry run enabled, skipping...");
160+
} else {
159161
await octokit.rest.issues.createComment({
160162
owner,
161163
repo,
@@ -168,8 +170,6 @@ const run = async () => {
168170
pull_number: prNumber,
169171
state: "closed",
170172
});
171-
} else {
172-
debug("Dry run enabled, skipping...");
173173
}
174174
}
175175
} catch (error) {

scripts/generate-theme-doc.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ const createTableItem = ({ link, label, isRepoCard }) => {
6969
const generateTable = ({ isRepoCard }) => {
7070
const rows = [];
7171
const themesFiltered = Object.keys(themes).filter(
72-
(name) => name !== (!isRepoCard ? "default_repocard" : "default"),
72+
(name) => name !== (isRepoCard ? "default" : "default_repocard"),
7373
);
7474

7575
for (let i = 0; i < themesFiltered.length; i += 3) {

scripts/preview-theme.js

+24-24
Original file line numberDiff line numberDiff line change
@@ -172,18 +172,18 @@ const upsertComment = async (
172172
body,
173173
) => {
174174
let resp;
175-
if (commentId !== undefined) {
176-
resp = await octokit.rest.issues.updateComment({
175+
if (commentId === undefined) {
176+
resp = await octokit.rest.issues.createComment({
177177
owner,
178178
repo,
179-
comment_id: commentId,
179+
issue_number: issueNumber,
180180
body,
181181
});
182182
} else {
183-
resp = await octokit.rest.issues.createComment({
183+
resp = await octokit.rest.issues.updateComment({
184184
owner,
185185
repo,
186-
issue_number: issueNumber,
186+
comment_id: commentId,
187187
body,
188188
});
189189
}
@@ -341,10 +341,10 @@ const parseJSON = (json) => {
341341
.filter((x) => typeof x !== "string" || !!x.trim()); // Split json into array of strings and objects.
342342
if (splitJson[0].replace(/\s+/g, "") === "},") {
343343
splitJson[0] = "},";
344-
if (!/\s*}\s*,?\s*$/.test(splitJson[1])) {
345-
splitJson.push(splitJson.shift());
346-
} else {
344+
if (/\s*}\s*,?\s*$/.test(splitJson[1])) {
347345
splitJson.shift();
346+
} else {
347+
splitJson.push(splitJson.shift());
348348
}
349349
parsedJson = splitJson.join("");
350350
}
@@ -466,10 +466,7 @@ export const run = async () => {
466466
// Check if the theme colors are valid.
467467
debug("Theme preview body: Check if the theme colors are valid...");
468468
let invalidColors = false;
469-
if (!colors) {
470-
warnings.push("Theme colors are missing");
471-
invalidColors = true;
472-
} else {
469+
if (colors) {
473470
const missingKeys = REQUIRED_COLOR_PROPS.filter(
474471
(x) => !Object.keys(colors).includes(x),
475472
);
@@ -507,6 +504,9 @@ export const run = async () => {
507504
}
508505
}
509506
}
507+
} else {
508+
warnings.push("Theme colors are missing");
509+
invalidColors = true;
510510
}
511511
if (invalidColors) {
512512
themeValid[theme] = false;
@@ -597,7 +597,10 @@ export const run = async () => {
597597
// Create or update theme-preview comment.
598598
debug("Create or update theme-preview comment...");
599599
let comment_url;
600-
if (!DRY_RUN) {
600+
if (DRY_RUN) {
601+
info(`DRY_RUN: Comment body: ${commentBody}`);
602+
comment_url = "";
603+
} else {
601604
comment_url = await upsertComment(
602605
OCTOKIT,
603606
PULL_REQUEST_ID,
@@ -606,9 +609,6 @@ export const run = async () => {
606609
comment?.id,
607610
commentBody,
608611
);
609-
} else {
610-
info(`DRY_RUN: Comment body: ${commentBody}`);
611-
comment_url = "";
612612
}
613613

614614
// Change review state and add/remove `invalid` label based on theme PR validity.
@@ -620,7 +620,10 @@ export const run = async () => {
620620
const reviewReason = themesValid
621621
? undefined
622622
: INVALID_REVIEW_COMMENT(comment_url);
623-
if (!DRY_RUN) {
623+
if (DRY_RUN) {
624+
info(`DRY_RUN: Review state: ${reviewState}`);
625+
info(`DRY_RUN: Review reason: ${reviewReason}`);
626+
} else {
624627
await addReview(
625628
OCTOKIT,
626629
PULL_REQUEST_ID,
@@ -637,13 +640,13 @@ export const run = async () => {
637640
"invalid",
638641
!themesValid,
639642
);
640-
} else {
641-
info(`DRY_RUN: Review state: ${reviewState}`);
642-
info(`DRY_RUN: Review reason: ${reviewReason}`);
643643
}
644644
} catch (error) {
645645
debug("Set review state to `REQUEST_CHANGES` and add `invalid` label...");
646-
if (!DRY_RUN) {
646+
if (DRY_RUN) {
647+
info(`DRY_RUN: Review state: REQUEST_CHANGES`);
648+
info(`DRY_RUN: Review reason: ${error.message}`);
649+
} else {
647650
await addReview(
648651
OCTOKIT,
649652
PULL_REQUEST_ID,
@@ -662,9 +665,6 @@ export const run = async () => {
662665
"invalid",
663666
true,
664667
);
665-
} else {
666-
info(`DRY_RUN: Review state: REQUEST_CHANGES`);
667-
info(`DRY_RUN: Review reason: ${error.message}`);
668668
}
669669
setFailed(error.message);
670670
}

src/cards/stats-card.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ const getStyles = ({
163163
.bold { font-weight: 700 }
164164
.icon {
165165
fill: ${iconColor};
166-
display: ${!!show_icons ? "block" : "none"};
166+
display: ${show_icons ? "block" : "none"};
167167
}
168168
169169
.rank-circle-rim {

src/cards/top-languages-card.js

+8-8
Original file line numberDiff line numberDiff line change
@@ -383,14 +383,14 @@ const renderCompactLayout = (langs, width, totalLanguageSize, hideProgress) => {
383383

384384
return `
385385
${
386-
!hideProgress
387-
? `
388-
<mask id="rect-mask">
389-
<rect x="0" y="0" width="${offsetWidth}" height="8" fill="white" rx="5"/>
390-
</mask>
391-
${compactProgressBar}
392-
`
393-
: ""
386+
hideProgress
387+
? ""
388+
: `
389+
<mask id="rect-mask">
390+
<rect x="0" y="0" width="${offsetWidth}" height="8" fill="white" rx="5"/>
391+
</mask>
392+
${compactProgressBar}
393+
`
394394
}
395395
<g transform="translate(0, ${hideProgress ? "0" : "25"})">
396396
${createLanguageTextNode({

src/cards/wakatime-card.js

+10-10
Original file line numberDiff line numberDiff line change
@@ -315,11 +315,11 @@ const renderWakatimeCard = (stats = {}, options = { hide: [] }) => {
315315
: noCodingActivityNode({
316316
// @ts-ignore
317317
color: textColor,
318-
text: !stats.is_coding_activity_visible
319-
? i18n.t("wakatimecard.notpublic")
320-
: stats.is_other_usage_visible
321-
? i18n.t("wakatimecard.nocodingactivity")
322-
: i18n.t("wakatimecard.nocodedetails"),
318+
text: stats.is_coding_activity_visible
319+
? stats.is_other_usage_visible
320+
? i18n.t("wakatimecard.nocodingactivity")
321+
: i18n.t("wakatimecard.nocodedetails")
322+
: i18n.t("wakatimecard.notpublic"),
323323
})
324324
}
325325
`;
@@ -344,11 +344,11 @@ const renderWakatimeCard = (stats = {}, options = { hide: [] }) => {
344344
noCodingActivityNode({
345345
// @ts-ignore
346346
color: textColor,
347-
text: !stats.is_coding_activity_visible
348-
? i18n.t("wakatimecard.notpublic")
349-
: stats.is_other_usage_visible
350-
? i18n.t("wakatimecard.nocodingactivity")
351-
: i18n.t("wakatimecard.nocodedetails"),
347+
text: stats.is_coding_activity_visible
348+
? stats.is_other_usage_visible
349+
? i18n.t("wakatimecard.nocodingactivity")
350+
: i18n.t("wakatimecard.nocodedetails")
351+
: i18n.t("wakatimecard.notpublic"),
352352
}),
353353
],
354354
gap: lheight,

src/common/Card.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,9 @@ class Card {
3939
// returns theme based colors with proper overrides and defaults
4040
this.colors = colors;
4141
this.title =
42-
customTitle !== undefined
43-
? encodeHTML(customTitle)
44-
: encodeHTML(defaultTitle);
42+
customTitle === undefined
43+
? encodeHTML(defaultTitle)
44+
: encodeHTML(customTitle);
4545

4646
this.css = "";
4747

src/common/utils.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -415,7 +415,7 @@ const wrapTextMultiline = (text, width = 59, maxLines = 3) => {
415415
const noop = () => {};
416416
// return console instance based on the environment
417417
const logger =
418-
process.env.NODE_ENV !== "test" ? console : { log: noop, error: noop };
418+
process.env.NODE_ENV === "test" ? { log: noop, error: noop } : console;
419419

420420
const ONE_MINUTE = 60;
421421
const FIVE_MINUTES = 300;

src/fetchers/stats-fetcher.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ const GRAPHQL_STATS_QUERY = `
8989
* @returns {Promise<AxiosResponse>} Axios response.
9090
*/
9191
const fetcher = (variables, token) => {
92-
const query = !variables.after ? GRAPHQL_STATS_QUERY : GRAPHQL_REPOS_QUERY;
92+
const query = variables.after ? GRAPHQL_REPOS_QUERY : GRAPHQL_STATS_QUERY;
9393
return request(
9494
{
9595
query,
@@ -138,10 +138,10 @@ const statsFetcher = async ({
138138

139139
// Store stats data.
140140
const repoNodes = res.data.data.user.repositories.nodes;
141-
if (!stats) {
142-
stats = res;
143-
} else {
141+
if (stats) {
144142
stats.data.data.user.repositories.nodes.push(...repoNodes);
143+
} else {
144+
stats = res;
145145
}
146146

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

0 commit comments

Comments
 (0)