1
mirror of https://github.com/jakejarvis/jarv.is.git synced 2025-10-30 03:56:01 -04:00

*much* stricter typescript (and some js) linting 😬

This commit is contained in:
2021-07-11 11:15:53 -04:00
parent d9214d846d
commit a2d2eee612
10 changed files with 101 additions and 44 deletions

View File

@@ -1,31 +1,46 @@
{
"extends": [
"eslint:recommended",
"plugin:compat/recommended",
"plugin:prettier/recommended",
"prettier"
"plugin:import/recommended",
"plugin:prettier/recommended"
],
"plugins": [
"prettier"
],
"parser": "@babel/eslint-parser",
"parserOptions": {
"ecmaVersion": 2018,
"sourceType": "module"
"ecmaVersion": 2015,
"sourceType": "module",
"allowImportExportEverywhere": false,
"requireConfigFile": false,
"babelOptions": {
"presets": [
[
"@babel/preset-env"
]
]
}
},
"rules": {
"curly": "error",
"quotes": ["error", "double"]
},
"env": {
"browser": true,
"es6": true
},
"rules": {},
"overrides": [{
"files": [
"**/*.ts"
"api/**/*.ts"
],
"extends": [
"eslint:recommended",
"plugin:@typescript-eslint/recommended",
"plugin:@typescript-eslint/recommended-requiring-type-checking",
"plugin:import/recommended",
"plugin:import/typescript",
"plugin:prettier/recommended",
"prettier"
"plugin:prettier/recommended"
],
"plugins": [
"@typescript-eslint",
@@ -33,14 +48,18 @@
],
"parser": "@typescript-eslint/parser",
"parserOptions": {
"ecmaVersion": 2018,
"sourceType": "module"
"ecmaVersion": 2020,
"sourceType": "module",
"project": ["./tsconfig.json"]
},
"rules": {
"@typescript-eslint/restrict-template-expressions": "off"
},
"env": {
"browser": true,
"browser": false,
"node": true,
"es6": true
}
}],
"ignorePatterns": ["public/**", "postcss.config.js", "gulpfile.js", "webpack.config.js"]
"ignorePatterns": ["public/**", "static/assets/**", "postcss.config.js", "gulpfile.js", "webpack.config.js"]
}

View File

@@ -61,12 +61,13 @@ export default async (req: VercelRequest, res: VercelResponse) => {
Sentry.captureException(error);
await Sentry.flush(2000);
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-member-access
res.status(400).json({ message: error.message });
}
};
const incrementPageHits = async (slug: string | string[], client: Client): Promise<PageStats> => {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
// eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/no-unsafe-assignment
const result = await client.query<any>(
q.Let(
{ match: q.Match(q.Index("hits_by_slug"), slug) },
@@ -85,12 +86,13 @@ const incrementPageHits = async (slug: string | string[], client: Client): Promi
);
// send client the *new* hit count
// eslint-disable-next-line @typescript-eslint/no-unsafe-return, @typescript-eslint/no-unsafe-member-access
return result.data;
};
const getSiteStats = async (client: Client): Promise<OverallStats> => {
// get database and RSS results asynchronously
// eslint-disable-next-line @typescript-eslint/no-explicit-any
// eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/no-unsafe-assignment
const [feed, result] = await Promise.all<{ [key: string]: any }, any>([
parser.parse(await (await fetch(baseUrl + "feed.xml")).text()), // this is messy but it works :)
client.query(
@@ -101,6 +103,7 @@ const getSiteStats = async (client: Client): Promise<OverallStats> => {
),
]);
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-member-access
const pages: PageStats[] = result.data;
const stats: OverallStats = {
total: { hits: 0 },
@@ -109,10 +112,14 @@ const getSiteStats = async (client: Client): Promise<OverallStats> => {
pages.map((p: PageStats) => {
// match URLs from RSS feed with db to populate some metadata
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-call
const match = feed.rss.channel.item.find((x: { link: string }) => x.link === baseUrl + p.slug + "/");
if (match) {
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
p.title = decode(match.title);
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-member-access
p.url = match.link;
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
p.date = new Date(match.pubDate).toISOString();
}

View File

@@ -47,6 +47,7 @@ export default async (req: VercelRequest, res: VercelResponse) => {
Sentry.captureException(error);
await Sentry.flush(2000);
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-member-access
res.status(400).json({ message: error.message });
}
};
@@ -94,7 +95,9 @@ const fetchRepos = async (sort: string, limit: number): Promise<Repository[]> =>
}
`;
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
const response = await client.request(query, { sort, limit });
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-call, @typescript-eslint/no-unsafe-member-access
const currentRepos: Repository[] = response.user.repositories.edges.map(
({ node: repo }: { [key: string]: Repository }) => ({
...repo,

View File

@@ -63,6 +63,7 @@ export default async (req: VercelRequest, res: VercelResponse) => {
Sentry.captureException(error);
await Sentry.flush(2000);
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-member-access
res.status(400).json({ message: error.message });
}
};
@@ -84,6 +85,7 @@ const getAccessToken = async () => {
};
const getNowPlaying = async (): Promise<Track> => {
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
const { access_token } = await getAccessToken();
const response = await fetch(NOW_PLAYING_ENDPOINT, {
@@ -98,6 +100,7 @@ const getNowPlaying = async (): Promise<Track> => {
return { isPlaying: false };
}
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
const active: Activity = await response.json();
if (active.is_playing === true && active.item) {
@@ -122,6 +125,7 @@ const getNowPlaying = async (): Promise<Track> => {
};
const getTopTracks = async (): Promise<Track[]> => {
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
const { access_token } = await getAccessToken();
const response = await fetch(TOP_TRACKS_ENDPOINT, {
@@ -132,8 +136,10 @@ const getTopTracks = async (): Promise<Track[]> => {
},
});
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
const { items } = await response.json();
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-call, @typescript-eslint/no-unsafe-member-access
const tracks: Track[] = items.map((track: TrackSchema) => ({
artist: track.artists.map((_artist) => _artist.name).join(", "),
title: track.name,

View File

@@ -26,8 +26,12 @@ if (wrapper) {
const hitsComma = numeral(data.hits).format("0,0");
const hitsPlural = data.hits === 1 ? "hit" : "hits";
if (spinner) spinner.style.display = "none";
if (counter) counter.appendChild(document.createTextNode(hitsComma));
if (spinner) {
spinner.style.display = "none";
}
if (counter) {
counter.appendChild(document.createTextNode(hitsComma));
}
wrapper.title = hitsComma + " " + hitsPlural;
} else {
// something went horribly wrong, initiate coverup

View File

@@ -1,3 +1,4 @@
/* eslint-disable */
/*! Dark mode switcheroo | MIT License | jrvs.io/darkmode */
// improve variable mangling when minifying

View File

@@ -1,7 +1,7 @@
import twemoji from "twemoji";
twemoji.parse(document.body, {
callback: function (icon, options) {
callback: function (icon) {
// simpler relative URIs
return "/assets/emoji/" + icon + ".svg";
},

View File

@@ -53,14 +53,15 @@
"devDependencies": {
"@babel/cli": "^7.14.5",
"@babel/core": "^7.14.6",
"@babel/eslint-parser": "^7.14.7",
"@babel/preset-env": "^7.14.7",
"@types/node-fetch": "^2.5.11",
"@types/numeral": "^2.0.1",
"@types/twemoji": "^12.1.1",
"@types/twemoji": "^12.1.2",
"@typescript-eslint/eslint-plugin": "^4.28.2",
"@typescript-eslint/parser": "^4.28.2",
"@vercel/node": "^1.11.1",
"autoprefixer": "^10.2.6",
"autoprefixer": "^10.3.0",
"babel-loader": "^8.2.2",
"clean-css": "^5.1.3",
"copy-webpack-plugin": "^9.0.1",
@@ -106,6 +107,7 @@
"stylelint-scss": "~3.19.0",
"terser": "^5.7.1",
"terser-webpack-plugin": "^5.1.4",
"tslib": "^2.3.0",
"typescript": "^4.3.5",
"webpack": "^5.44.0",
"webpack-assets-manifest": "^5.0.6",

View File

@@ -1,18 +1,24 @@
{
"compilerOptions": {
"target": "es2018",
"target": "esnext",
"lib": [
"esnext",
"es2018",
"dom"
"es2020"
],
"module": "commonjs",
"module": "es2020",
"moduleResolution": "node",
"importHelpers": true,
"esModuleInterop": true,
"isolatedModules": true,
"alwaysStrict": true,
"strict": true,
"strictNullChecks": true,
"strictFunctionTypes": true,
"strictBindCallApply": true,
"strictPropertyInitialization": true,
"noEmit": true,
"noImplicitReturns": true,
"noImplicitThis": true,
"allowJs": true,
"typeRoots": [
"./types",
@@ -22,10 +28,10 @@
"sourceRoot": "/",
"inlineSources": true
},
"exclude": [
"node_modules"
],
"include": [
"**/*.ts"
],
"exclude": [
"node_modules"
]
}

View File

@@ -58,6 +58,15 @@
semver "^6.3.0"
source-map "^0.5.0"
"@babel/eslint-parser@^7.14.7":
version "7.14.7"
resolved "https://registry.yarnpkg.com/@babel/eslint-parser/-/eslint-parser-7.14.7.tgz#91be59a4f7dd60d02a3ef772d156976465596bda"
integrity sha512-6WPwZqO5priAGIwV6msJcdc9TsEPzYeYdS/Xuoap+/ihkgN6dzHp2bcAAwyWZ5bLzk0vvjDmKvRwkqNaiJ8BiQ==
dependencies:
eslint-scope "^5.1.1"
eslint-visitor-keys "^2.1.0"
semver "^6.3.0"
"@babel/generator@^7.14.5":
version "7.14.5"
resolved "https://registry.yarnpkg.com/@babel/generator/-/generator-7.14.5.tgz#848d7b9f031caca9d0cd0af01b063f226f52d785"
@@ -1202,9 +1211,9 @@
form-data "^3.0.0"
"@types/node@*":
version "16.3.0"
resolved "https://registry.yarnpkg.com/@types/node/-/node-16.3.0.tgz#1836664e4fad13b51b07eb6e882a53925e6543c4"
integrity sha512-OydMCocGMGqw/1BnWbhtK+AtwyWTOigtrQlRe57OQmTNcI3HKlVI5FGlh+c4mSqInMPLynFrTlYjfajPu9O/eQ==
version "16.3.1"
resolved "https://registry.yarnpkg.com/@types/node/-/node-16.3.1.tgz#24691fa2b0c3ec8c0d34bfcfd495edac5593ebb4"
integrity sha512-N87VuQi7HEeRJkhzovao/JviiqKjDKMVKxKMfUvSKw+MbkbW8R0nA3fi/MQhhlxV2fQ+2ReM+/Nt4efdrJx3zA==
"@types/normalize-package-data@^2.4.0":
version "2.4.1"
@@ -1233,10 +1242,10 @@
dependencies:
"@types/node" "*"
"@types/twemoji@^12.1.1":
version "12.1.1"
resolved "https://registry.yarnpkg.com/@types/twemoji/-/twemoji-12.1.1.tgz#34c5dcecff438b5be173889a6ee8ad51ba90445f"
integrity sha512-dW1B1WHTfrWmEzXb/tp8xsZqQHAyMB9JwLwbBqkIQVzmNUI02R7lJqxUpKFM114ygNZHKA1r74oPugCAiYHt1A==
"@types/twemoji@^12.1.2":
version "12.1.2"
resolved "https://registry.yarnpkg.com/@types/twemoji/-/twemoji-12.1.2.tgz#52578fd22665311e6a78d04f800275449d51c97e"
integrity sha512-3eMyKenMi0R1CeKzBYtk/Z2JIHsTMQrIrTah0q54o45pHTpWVNofU2oHx0jS8tqsDRhis2TbB6238WP9oh2l2w==
"@types/unist@*", "@types/unist@^2.0.0", "@types/unist@^2.0.2":
version "2.0.5"
@@ -1904,13 +1913,13 @@ atob@^2.1.2:
resolved "https://registry.yarnpkg.com/atob/-/atob-2.1.2.tgz#6d9517eb9e030d2436666651e86bd9f6f13533c9"
integrity sha512-Wm6ukoaOGJi/73p/cl2GvLjTI5JM1k/O14isD73YML8StrH/7/lRFgmg8nICZgD3bZZvjwCGxtMOD3wWNAu8cg==
autoprefixer@^10.2.6:
version "10.2.6"
resolved "https://registry.yarnpkg.com/autoprefixer/-/autoprefixer-10.2.6.tgz#aadd9ec34e1c98d403e01950038049f0eb252949"
integrity sha512-8lChSmdU6dCNMCQopIf4Pe5kipkAGj/fvTMslCsih0uHpOrXOPUEVOmYMMqmw3cekQkSD7EhIeuYl5y0BLdKqg==
autoprefixer@^10.3.0:
version "10.3.0"
resolved "https://registry.yarnpkg.com/autoprefixer/-/autoprefixer-10.3.0.tgz#c60803dce9268f7fe0a5e5c1fe48a74356d7b864"
integrity sha512-BzVzdjs47nT3MphTddr8eSsPVEIUCF96X6iC8V5iEB8RtxrU+ybtdhHV5rsqRqOsoyh/acQaYs7YupHPUECgmg==
dependencies:
browserslist "^4.16.6"
caniuse-lite "^1.0.30001230"
caniuse-lite "^1.0.30001243"
colorette "^1.2.2"
fraction.js "^4.1.1"
normalize-range "^0.1.2"
@@ -2365,7 +2374,7 @@ caniuse-api@^3.0.0:
lodash.memoize "^4.1.2"
lodash.uniq "^4.5.0"
caniuse-lite@^1.0.0, caniuse-lite@^1.0.30001109, caniuse-lite@^1.0.30001166, caniuse-lite@^1.0.30001179, caniuse-lite@^1.0.30001219, caniuse-lite@^1.0.30001230:
caniuse-lite@^1.0.0, caniuse-lite@^1.0.30001109, caniuse-lite@^1.0.30001166, caniuse-lite@^1.0.30001179, caniuse-lite@^1.0.30001219, caniuse-lite@^1.0.30001243:
version "1.0.30001243"
resolved "https://registry.yarnpkg.com/caniuse-lite/-/caniuse-lite-1.0.30001243.tgz#d9250155c91e872186671c523f3ae50cfc94a3aa"
integrity sha512-vNxw9mkTBtkmLFnJRv/2rhs1yufpDfCkBZexG3Y0xdOH2Z/eE/85E4Dl5j1YUN34nZVsSp6vVRFQRrez9wJMRA==
@@ -3560,9 +3569,9 @@ ee-first@1.1.1:
integrity sha1-WQxhFWsK4vTwJVcyoViyZrxWsh0=
electron-to-chromium@^1.3.723:
version "1.3.771"
resolved "https://registry.yarnpkg.com/electron-to-chromium/-/electron-to-chromium-1.3.771.tgz#c4aa601e6420e11926095f75fe803956a1b4bd81"
integrity sha512-zHMomTqkpnAD9W5rhXE1aiU3ogGFrqWzdvM4C6222SREiqsWQb2w0S7P2Ii44qCaGimmAP1z+OydllM438uJyA==
version "1.3.772"
resolved "https://registry.yarnpkg.com/electron-to-chromium/-/electron-to-chromium-1.3.772.tgz#fd1ed39f9f3149f62f581734e4f026e600369479"
integrity sha512-X/6VRCXWALzdX+RjCtBU6cyg8WZgoxm9YA02COmDOiNJEZ59WkQggDbWZ4t/giHi/3GS+cvdrP6gbLISANAGYA==
emoji-regex@^7.0.1:
version "7.0.3"
@@ -3822,7 +3831,7 @@ eslint-visitor-keys@^1.1.0, eslint-visitor-keys@^1.3.0:
resolved "https://registry.yarnpkg.com/eslint-visitor-keys/-/eslint-visitor-keys-1.3.0.tgz#30ebd1ef7c2fdff01c3a4f151044af25fab0523e"
integrity sha512-6J72N8UNa462wa/KFODt/PJ3IU60SDpC3QXC1Hjc1BXXpfL2C9R5+AU7jhe0F6GREqVMh4Juu+NY7xn+6dipUQ==
eslint-visitor-keys@^2.0.0:
eslint-visitor-keys@^2.0.0, eslint-visitor-keys@^2.1.0:
version "2.1.0"
resolved "https://registry.yarnpkg.com/eslint-visitor-keys/-/eslint-visitor-keys-2.1.0.tgz#f65328259305927392c938ed44eb0a5c9b2bd303"
integrity sha512-0rSmRBzXgDzIsD6mGdJgevzgezI534Cer5L/vyMX0kHzT/jiB43jRhd9YUlMGYLQy2zprNmoT8qasCGtY+QaKw==
@@ -10117,7 +10126,7 @@ tslib@^1.8.1, tslib@^1.9.0, tslib@^1.9.3:
resolved "https://registry.yarnpkg.com/tslib/-/tslib-1.14.1.tgz#cf2d38bdc34a134bcaf1091c41f6619e2f672d00"
integrity sha512-Xni35NKzjgMrwevysHTCArtLDpPvye8zV/0E4EyYn43P7/7qvQwPh9BGkHewbMulVntbigmcT7rdX3BNo9wRJg==
tslib@^2.0.3, tslib@^2.1.0:
tslib@^2.0.3, tslib@^2.1.0, tslib@^2.3.0:
version "2.3.0"
resolved "https://registry.yarnpkg.com/tslib/-/tslib-2.3.0.tgz#803b8cdab3e12ba581a4ca41c8839bbb0dacb09e"
integrity sha512-N82ooyxVNm6h1riLCoyS9e3fuJ3AMG2zIZs2Gd1ATcSFjSA23Q0fzjjZeh0jbJvWVDZ0cJT8yaNNaaXHzueNjg==