Eslint integration (#2885)

* eslint integration

* ci & pre commit

* dev

* dev

* dev
This commit is contained in:
Alexandr Garbuzov 2023-07-03 09:54:19 +03:00 committed by GitHub
parent de4efa9ea1
commit 6c92fe9d2a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
26 changed files with 1677 additions and 229 deletions

234
.eslintrc.json Normal file
View File

@ -0,0 +1,234 @@
{
"env": {
"node": true,
"browser": true,
"es2021": true
},
"extends": [
// "eslint:recommended",
"prettier"
],
"parserOptions": {
"sourceType": "module"
},
"rules": {
// Possible Errors (overrides from recommended set)
// "no-extra-parens": "error",
// "no-unexpected-multiline": "error",
// All JSDoc comments must be valid
// "valid-jsdoc": [ "error", {
// "requireReturn": false,
// "requireReturnDescription": false,
// "requireParamDescription": true,
// "prefer": {
// "return": "returns"
// }
// }],
// Best Practices
// Allowed a getter without setter, but all setters require getters
// "accessor-pairs": [ "error", {
// "getWithoutSet": false,
// "setWithoutGet": true
// }],
// "block-scoped-var": "warn",
// "consistent-return": "error",
// "curly": "error",
// "default-case": "warn",
// the dot goes with the property when doing multiline
// "dot-location": [ "warn", "property" ],
// "dot-notation": "warn",
// "eqeqeq": [ "error", "smart" ],
// "guard-for-in": "warn",
// "no-alert": "error",
// "no-caller": "error",
// "no-case-declarations": "warn",
// "no-div-regex": "warn",
// "no-else-return": "warn",
// "no-empty-label": "warn",
// "no-empty-pattern": "warn",
// "no-eq-null": "warn",
// "no-eval": "error",
// "no-extend-native": "error",
// "no-extra-bind": "warn",
// "no-floating-decimal": "warn",
// "no-implicit-coercion": [ "warn", {
// "boolean": true,
// "number": true,
// "string": true
// }],
// "no-implied-eval": "error",
// "no-invalid-this": "error",
// "no-iterator": "error",
// "no-labels": "warn",
// "no-lone-blocks": "warn",
// "no-loop-func": "error",
// "no-magic-numbers": "warn",
// "no-multi-spaces": "error",
// "no-multi-str": "warn",
// "no-native-reassign": "error",
// "no-new-func": "error",
// "no-new-wrappers": "error",
// "no-new": "error",
// "no-octal-escape": "error",
// "no-param-reassign": "error",
// "no-process-env": "warn",
// "no-proto": "error",
// "no-redeclare": "error",
// "no-return-assign": "error",
// "no-script-url": "error",
// "no-self-compare": "error",
// "no-throw-literal": "error",
// "no-unused-expressions": "error",
// "no-useless-call": "error",
// "no-useless-concat": "error",
// "no-void": "warn",
// Produce warnings when something is commented as TODO or FIXME
// "no-warning-comments": [ "warn", {
// "terms": [ "TODO", "FIXME" ],
// "location": "start"
// }],
// "no-with": "warn",
// "radix": "warn",
// "vars-on-top": "error",
// Enforces the style of wrapped functions
// "wrap-iife": [ "error", "outside" ],
// "yoda": "error",
// Strict Mode - for ES6, never use strict.
// "strict": [ "error", "never" ],
// Variables
// "init-declarations": [ "error", "always" ],
// "no-catch-shadow": "warn",
// "no-delete-var": "error",
// "no-label-var": "error",
// "no-shadow-restricted-names": "error",
// "no-shadow": "warn",
// We require all vars to be initialized (see init-declarations)
// If we NEED a var to be initialized to undefined, it needs to be explicit
"no-undef-init": "off",
"no-undef": "error",
"no-undefined": "off",
"no-unused-vars": "warn",
// Disallow hoisting - let & const don't allow hoisting anyhow
// "no-use-before-define": "error",
// Node.js and CommonJS
// "callback-return": [ "warn", [ "callback", "next" ]],
// "global-require": "error",
// "handle-callback-err": "warn",
// "no-mixed-requires": "warn",
// "no-new-require": "error",
// Use path.concat instead
// "no-path-concat": "error",
// "no-process-exit": "error",
// "no-restricted-modules": "off",
// "no-sync": "warn",
// ECMAScript 6 support
// "arrow-body-style": [ "error", "always" ],
// "arrow-parens": [ "error", "always" ],
// "arrow-spacing": [ "error", { "before": true, "after": true }],
// "constructor-super": "error",
// "generator-star-spacing": [ "error", "before" ],
// "no-arrow-condition": "error",
// "no-class-assign": "error",
// "no-const-assign": "error",
// "no-dupe-class-members": "error",
// "no-this-before-super": "error",
// "no-var": "warn",
"object-shorthand": [ "warn" ]
// "prefer-arrow-callback": "warn",
// "prefer-spread": "warn",
// "prefer-template": "warn",
// "require-yield": "error",
// Stylistic - everything here is a warning because of style.
// "array-bracket-spacing": [ "warn", "always" ],
// "block-spacing": [ "warn", "always" ],
// "brace-style": [ "warn", "1tbs", { "allowSingleLine": false } ],
// "camelcase": "warn",
// "comma-spacing": [ "warn", { "before": false, "after": true } ],
// "comma-style": [ "warn", "last" ],
// "computed-property-spacing": [ "warn", "never" ],
// "consistent-this": [ "warn", "self" ],
// "eol-last": "warn",
// "func-names": "warn",
// "func-style": [ "warn", "declaration" ],
// "id-length": [ "warn", { "min": 2, "max": 32 } ],
// "indent": [ "warn", 4 ],
// "jsx-quotes": [ "warn", "prefer-double" ],
// "linebreak-style": [ "warn", "unix" ],
// "lines-around-comment": [ "warn", { "beforeBlockComment": true } ],
// "max-depth": [ "warn", 8 ],
// "max-len": [ "warn", 132 ],
// "max-nested-callbacks": [ "warn", 8 ],
// "max-params": [ "warn", 8 ],
// "new-cap": "warn",
// "new-parens": "warn",
// "no-array-constructor": "warn",
// "no-bitwise": "off",
// "no-continue": "off",
// "no-inline-comments": "off",
// "no-lonely-if": "warn",
// "no-mixed-spaces-and-tabs": "warn",
// "no-multiple-empty-lines": "warn",
// "no-negated-condition": "off",
// "no-nested-ternary": "warn",
// "no-new-object": "warn",
// "no-plusplus": "off",
// "no-spaced-func": "warn",
// "no-ternary": "off",
// "no-trailing-spaces": "warn",
// "no-underscore-dangle": "warn",
// "no-unneeded-ternary": "warn",
// "object-curly-spacing": [ "warn", "always" ],
// "one-var": "off",
// "operator-assignment": [ "warn", "never" ],
// "operator-linebreak": [ "warn", "after" ],
// "padded-blocks": [ "warn", "never" ],
// "quote-props": [ "warn", "consistent-as-needed" ],
// "quotes": [ "warn", "single" ],
// "require-jsdoc": [ "warn", {
// "require": {
// "FunctionDeclaration": true,
// "MethodDefinition": true,
// "ClassDeclaration": false
// }
// }],
// "semi-spacing": [ "warn", { "before": false, "after": true }],
// "semi": [ "error", "always" ],
// "sort-vars": "off",
// "space-after-keywords": [ "warn", "always" ],
// "space-before-blocks": [ "warn", "always" ],
// "space-before-function-paren": [ "warn", "never" ],
// "space-before-keywords": [ "warn", "always" ],
// "space-in-parens": [ "warn", "never" ],
// "space-infix-ops": [ "warn", { "int32Hint": true } ],
// "space-return-throw-case": "error",
// "space-unary-ops": "error",
// "spaced-comment": [ "warn", "always" ],
// "wrap-regex": "warn"
}
}

View File

@ -31,6 +31,10 @@ jobs:
npm ci
npm run test
- name: Run ESLint
run: |
npm run lints
- name: Run Prettier
run: |
npm run format:check

View File

@ -2,4 +2,5 @@
. "$(dirname -- "$0")/_/husky.sh"
npm test
npm run lints
npx lint-staged

1625
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -29,7 +29,8 @@
"generate-langs-json": "node scripts/generate-langs-json",
"format": "prettier --write .",
"format:check": "prettier --check .",
"prepare": "husky install"
"prepare": "husky install",
"lints": "npx eslint --max-warnings 0 \"./src/**.js\" \"./scripts/**.js\" \"./tests/**.js\" \"./api/**.js\" \"./themes/**.js\""
},
"author": "Anurag Hazra",
"license": "MIT",
@ -41,6 +42,8 @@
"@uppercod/css-to-object": "^1.1.1",
"axios-mock-adapter": "^1.21.2",
"color-contrast-checker": "^2.1.0",
"eslint": "^8.43.0",
"eslint-config-prettier": "^8.8.0",
"hjson": "^3.2.2",
"husky": "^8.0.0",
"jest": "^29.5.0",

View File

@ -25,6 +25,7 @@ function calculateRank({
commits,
prs,
issues,
// eslint-disable-next-line no-unused-vars
repos, // unused
stars,
followers,

View File

@ -1,4 +1,5 @@
// @ts-check
/**
* Calculates progress along the boundary of the circle i.e it's circumference.
*
@ -75,6 +76,7 @@ const getAnimations = () => {
* @returns {string} Card CSS styles.
*/
const getStyles = ({
// eslint-disable-next-line no-unused-vars
titleColor,
textColor,
iconColor,

View File

@ -5,6 +5,7 @@ import api from "../api/index.js";
import { calculateRank } from "../src/calculateRank.js";
import { renderStatsCard } from "../src/cards/stats-card.js";
import { CONSTANTS, renderError } from "../src/common/utils.js";
import { expect, it, describe, afterEach } from "@jest/globals";
const stats = {
name: "Anurag Hazra",

View File

@ -1,5 +1,6 @@
import "@testing-library/jest-dom";
import { calculateRank } from "../src/calculateRank.js";
import { expect, it, describe } from "@jest/globals";
describe("Test calculateRank", () => {
it("new user gets C rank", () => {

View File

@ -4,6 +4,7 @@ import { cssToObject } from "@uppercod/css-to-object";
import { Card } from "../src/common/Card.js";
import { icons } from "../src/common/icons.js";
import { getCardColors } from "../src/common/utils.js";
import { expect, it, describe } from "@jest/globals";
describe("Card", () => {
it("should hide border", () => {

View File

@ -4,12 +4,12 @@
import dotenv from "dotenv";
dotenv.config();
import { describe } from "@jest/globals";
import axios from "axios";
import { renderRepoCard } from "../../src/cards/repo-card.js";
import { renderStatsCard } from "../../src/cards/stats-card.js";
import { renderTopLanguages } from "../../src/cards/top-languages-card.js";
import { renderWakatimeCard } from "../../src/cards/wakatime-card.js";
import { expect, describe, beforeAll, test } from "@jest/globals";
const REPO = "curly-fiesta";
const USER = "catelinemnemosyne";

View File

@ -2,6 +2,7 @@ import "@testing-library/jest-dom";
import axios from "axios";
import MockAdapter from "axios-mock-adapter";
import { fetchRepo } from "../src/fetchers/repo-fetcher.js";
import { expect, it, describe, afterEach } from "@jest/globals";
const data_repo = {
repository: {

View File

@ -3,6 +3,7 @@ import axios from "axios";
import MockAdapter from "axios-mock-adapter";
import { calculateRank } from "../src/calculateRank.js";
import { fetchStats } from "../src/fetchers/stats-fetcher.js";
import { expect, it, describe, beforeEach, afterEach } from "@jest/globals";
// Test parameters.
const data_stats = {

View File

@ -2,6 +2,7 @@ import "@testing-library/jest-dom";
import axios from "axios";
import MockAdapter from "axios-mock-adapter";
import { fetchTopLanguages } from "../src/fetchers/top-languages-fetcher.js";
import { expect, it, describe, afterEach } from "@jest/globals";
const mock = new MockAdapter(axios);

View File

@ -2,6 +2,8 @@ import "@testing-library/jest-dom";
import axios from "axios";
import MockAdapter from "axios-mock-adapter";
import { fetchWakatimeStats } from "../src/fetchers/wakatime-fetcher.js";
import { expect, it, describe, afterEach } from "@jest/globals";
const mock = new MockAdapter(axios);
afterEach(() => {

View File

@ -1,4 +1,5 @@
import { flexLayout } from "../src/common/utils.js";
import { expect, it, describe } from "@jest/globals";
describe("flexLayout", () => {
it("should work with row & col layouts", () => {

View File

@ -8,6 +8,7 @@ import { jest } from "@jest/globals";
import axios from "axios";
import MockAdapter from "axios-mock-adapter";
import patInfo, { RATE_LIMIT_SECONDS } from "../api/status/pat-info.js";
import { expect, it, describe, afterEach, beforeAll } from "@jest/globals";
const mock = new MockAdapter(axios);

View File

@ -5,6 +5,7 @@ import MockAdapter from "axios-mock-adapter";
import pin from "../api/pin.js";
import { renderRepoCard } from "../src/cards/repo-card.js";
import { renderError } from "../src/common/utils.js";
import { expect, it, describe, afterEach } from "@jest/globals";
const data_repo = {
repository: {

View File

@ -2,6 +2,7 @@ import { queryByTestId } from "@testing-library/dom";
import "@testing-library/jest-dom";
import { cssToObject } from "@uppercod/css-to-object";
import { renderRepoCard } from "../src/cards/repo-card.js";
import { expect, it, describe } from "@jest/globals";
import { themes } from "../themes/index.js";

View File

@ -5,6 +5,8 @@ import {
} from "@testing-library/dom";
import { cssToObject } from "@uppercod/css-to-object";
import { renderStatsCard } from "../src/cards/stats-card.js";
import { expect, it, describe } from "@jest/globals";
// adds special assertions like toHaveTextContent
import "@testing-library/jest-dom";

View File

@ -18,6 +18,7 @@ import {
MIN_CARD_WIDTH,
getDefaultLanguagesCountByLayout,
} from "../src/cards/top-languages-card.js";
import { expect, it, describe } from "@jest/globals";
// adds special assertions like toHaveTextContent
import "@testing-library/jest-dom";

View File

@ -3,10 +3,11 @@ import "@testing-library/jest-dom";
import { renderWakatimeCard } from "../src/cards/wakatime-card.js";
import { getCardColors } from "../src/common/utils.js";
import { wakaTimeData } from "./fetchWakatime.test.js";
import { expect, it, describe } from "@jest/globals";
describe("Test Render Wakatime Card", () => {
it("should render correctly", () => {
const card = renderWakatimeCard(wakaTimeData.data);
// const card = renderWakatimeCard(wakaTimeData.data);
expect(getCardColors).toMatchSnapshot();
});

View File

@ -2,20 +2,21 @@ import { jest } from "@jest/globals";
import "@testing-library/jest-dom";
import { retryer } from "../src/common/retryer.js";
import { logger } from "../src/common/utils.js";
import { expect, it, describe } from "@jest/globals";
const fetcher = jest.fn((variables, token) => {
logger.log(variables, token);
return new Promise((res, rej) => res({ data: "ok" }));
return new Promise((res) => res({ data: "ok" }));
});
const fetcherFail = jest.fn(() => {
return new Promise((res, rej) =>
return new Promise((res) =>
res({ data: { errors: [{ type: "RATE_LIMITED" }] } }),
);
});
const fetcherFailOnSecondTry = jest.fn((_vars, _token, retries) => {
return new Promise((res, rej) => {
return new Promise((res) => {
// faking rate limit
if (retries < 1) {
return res({ data: { errors: [{ type: "RATE_LIMITED" }] } });
@ -40,10 +41,8 @@ describe("Test Retryer", () => {
});
it("retryer should throw error if maximum retries reached", async () => {
let res;
try {
res = await retryer(fetcherFail, {});
await retryer(fetcherFail, {});
} catch (err) {
expect(fetcherFail).toBeCalledTimes(8);
expect(err.message).toBe("Maximum retries exceeded");

View File

@ -5,6 +5,7 @@ import { jest } from "@jest/globals";
import axios from "axios";
import MockAdapter from "axios-mock-adapter";
import up, { RATE_LIMIT_SECONDS } from "../api/status/up.js";
import { expect, it, describe, afterEach } from "@jest/globals";
const mock = new MockAdapter(axios);

View File

@ -5,6 +5,7 @@ import MockAdapter from "axios-mock-adapter";
import topLangs from "../api/top-langs.js";
import { renderTopLanguages } from "../src/cards/top-languages-card.js";
import { renderError } from "../src/common/utils.js";
import { expect, it, describe, afterEach } from "@jest/globals";
const data_langs = {
data: {

View File

@ -8,6 +8,7 @@ import {
renderError,
wrapTextMultiline,
} from "../src/common/utils.js";
import { expect, it, describe } from "@jest/globals";
describe("Test utils.js", () => {
it("should test kFormatter", () => {