Skip to content
This repository was archived by the owner on Apr 13, 2025. It is now read-only.

Commit 07a0a1a

Browse files
authored
chore:Format configs & scripts (#421)
* chore:Format configs & scripts - Add JSDoc types to `jest.config.js`, `.eslintrc.js` & `.prettierrc.js` - Set more prettier configs explicitly to circumvent an issue I experienced with the prettier vscode extension, where it would format some stuff based on my global preferences and not the defaults. - Use Set in `esbuild.config.js` - Format all js and ts files Tim Signed-off-by: Tim_Tech_Dev <Tim_Tech_Dev@protonmail.com> * Update jest configs - Use module syntax - Automaticly add packages with jest config to root jest projects - Add .mjs extension to files formated by prettier - Enable type checking JS files project wide Tim Signed-off-by: Tim_Tech_Dev <Tim_Tech_Dev@protonmail.com>
1 parent 20fd3e7 commit 07a0a1a

File tree

13 files changed

+89
-46
lines changed

13 files changed

+89
-46
lines changed

.eslintrc.js

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,19 @@
1+
/** @type {import("eslint").ESLint.Options} */
12
module.exports = {
23
parser: "@typescript-eslint/parser",
34
parserOptions: {
45
ecmaVersion: 2017,
56
sourceType: "module",
67
},
7-
extends: [
8-
"eslint:recommended",
9-
"plugin:@typescript-eslint/recommended",
10-
],
8+
extends: ["eslint:recommended", "plugin:@typescript-eslint/recommended"],
119
// Don't traverse fs up to root.
1210
// This caused problems when nodecg-io was cloned into a NodeCG installation as it then
1311
// tried to lint nodecg-io with that config.
1412
root: true,
1513
rules: {
1614
// Allow for unused function arguments when they are prefixed with an underscore.
1715
// This is the TypeScript convention to mark unused arguments.
18-
"@typescript-eslint/no-unused-vars": ["warn", {argsIgnorePattern: "^_"}],
16+
"@typescript-eslint/no-unused-vars": ["warn", { argsIgnorePattern: "^_" }],
1917

2018
// We simply have empty functions at some places, so we ignore this rule.
2119
"@typescript-eslint/no-empty-function": ["warn", { allow: ["arrowFunctions"] }],
@@ -24,6 +22,6 @@ module.exports = {
2422
"no-console": ["warn"],
2523

2624
// Enforce triple equals for comparisons
27-
"eqeqeq": ["warn"]
25+
"eqeqeq": ["warn"],
2826
},
2927
};

.prettierrc.js

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,16 @@
1+
/** @type {import("prettier").RequiredOptions} */
12
module.exports = {
2-
semi: true,
3-
trailingComma: "all",
4-
singleQuote: false,
53
printWidth: 120,
64
tabWidth: 4,
75
useTabs: false,
8-
endOfLine: "auto"
6+
semi: true,
7+
singleQuote: false,
8+
quoteProps: "consistent",
9+
jsxSingleQuote: false,
10+
trailingComma: "all",
11+
bracketSpacing: true,
12+
arrowParens: "always",
13+
proseWrap: "preserve",
14+
vueIndentScriptAndStyle: false,
15+
endOfLine: "lf",
916
};

.vscode/settings.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,5 +13,6 @@
1313
"**/*.tsbuildinfo": true
1414
},
1515
"typescript.tsc.autoDetect": "off",
16-
"npm.autoDetect": "off"
16+
"npm.autoDetect": "off",
17+
"js/ts.implicitProjectConfig.checkJs": true
1718
}

jest.config.js

Lines changed: 0 additions & 3 deletions
This file was deleted.

jest.config.mjs

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
import path from "path";
2+
import { readdirSync } from "fs";
3+
import { cwd } from "process";
4+
import { getPackages } from "@manypkg/get-packages";
5+
6+
let projects = [];
7+
// @ts-ignore
8+
const { root, packages } = await getPackages(cwd());
9+
10+
/** @param pkg {import("@manypkg/get-packages").Package} */
11+
function hasJestConfig(pkg) {
12+
return (
13+
readdirSync(pkg.dir).some(
14+
(file) =>
15+
file === "jest.config.js" ||
16+
file === "jest.config.ts" ||
17+
file === "jest.config.cjs" ||
18+
file === "jest.config.mjs" ||
19+
file === "jest.config.json",
20+
) || pkg.packageJson["jest"]
21+
);
22+
}
23+
24+
projects = packages.filter((pkg) => hasJestConfig(pkg)).map((v) => `<rootDir>/${path.relative(root.dir, v.dir)}`);
25+
26+
console.log(projects);
27+
28+
/** @type {import('@jest/types').Config.InitialOptions} */
29+
const config = {
30+
projects,
31+
};
32+
33+
export default config;

nodecg-io-core/dashboard/esbuild.config.js

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ const path = require("path");
88
const process = require("process");
99
const fs = require("fs");
1010

11-
const args = process.argv.slice(2);
11+
const args = new Set(process.argv.slice(2));
1212
const prod = process.env.NODE_ENV === "production";
1313

1414
const entryPoints = [
@@ -17,19 +17,20 @@ const entryPoints = [
1717
"main.ts",
1818
];
1919

20-
if (args.includes("--clean") || args.includes("--rebuild")) {
21-
// remove dist folder
20+
if (args.has("--clean") || args.has("--rebuild")) {
21+
// Remove dist folder
2222
try {
2323
fs.rmSync(path.join(__dirname, "dist"), { recursive: true, force: true });
24-
} catch (err) {
25-
console.log(err);
24+
} catch (error) {
25+
console.log(error);
2626
}
27-
if (!args.includes("--rebuild")) {
27+
28+
if (!args.has("--rebuild")) {
2829
process.exit(0);
2930
}
3031
}
3132

32-
/**@type {import('esbuild').BuildOptions}*/
33+
/** @type {import('esbuild').BuildOptions} */
3334
const BuildOptions = {
3435
/**
3536
* By default, esbuild will not bundle the input files. Bundling must be
@@ -45,7 +46,7 @@ const BuildOptions = {
4546
* This is an array of files that each serve as an input to the bundling
4647
* algorithm.
4748
*/
48-
entryPoints: entryPoints,
49+
entryPoints,
4950
/**
5051
* This sets the output format for the generated JavaScript files. We are
5152
* using the `iife`, which format stands for "immediately-invoked function
@@ -88,7 +89,7 @@ const BuildOptions = {
8889
* on the file system and to rebuild whenever a file changes that could
8990
* invalidate the build.
9091
*/
91-
watch: args.includes("--watch")
92+
watch: args.has("--watch"),
9293
};
9394

9495
esbuild
@@ -98,6 +99,7 @@ esbuild
9899
if (result.errors.length > 0) {
99100
console.error(result.errors);
100101
}
102+
101103
if (result.warnings.length > 0) {
102104
console.error(result.warnings);
103105
}

nodecg-io-core/jest.config.js

Lines changed: 0 additions & 8 deletions
This file was deleted.

nodecg-io-core/jest.config.mjs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
/** @type {import('@jest/types').Config.InitialOptions} */
2+
const config = {
3+
preset: "ts-jest",
4+
testEnvironment: "node",
5+
testMatch: ["<rootDir>/extension/__tests__/**/*.ts", "!**/extension/__tests__/mocks.ts"],
6+
// Exclude mocks.ts from coverage. It doesn't matter because it is mock code not used
7+
// but required to make TypeScript compile it.
8+
coveragePathIgnorePatterns: ["<rootDir>/extension/__tests__/"],
9+
};
10+
11+
export default config;

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@
1515
"watch": "node .scripts/exec.mjs watch",
1616
"watch:root": "tsc -b -w --pretty --preserveWatchOutput",
1717
"lint": "eslint . --ext ts --ignore-pattern '**/*.d.ts'",
18-
"format": "prettier --write \"./**/*.{ts,html,css,json}\"",
19-
"format-pre-commit": "pretty-quick --staged --pattern '*/**/*.{ts,html,css,json}'",
18+
"format": "prettier --write \"./**/*.{ts,html,css,json,mjs}\"",
19+
"format-pre-commit": "pretty-quick --staged --pattern '*/**/*.{ts,html,css,json,mjs}'",
2020
"prepare": "husky install"
2121
},
2222
"devDependencies": {

services/nodecg-io-curseforge/extension/curseforgeClient.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ export class CurseForge {
168168
const response = await fetch(`https://addons-ecs.forgesvc.net/api/v2/${endpoint}`, {
169169
method: method,
170170
headers: {
171-
Accept: "application/json",
171+
"Accept": "application/json",
172172
"Content-Type": "application/json",
173173
},
174174
body: data === undefined ? undefined : JSON.stringify(data),

0 commit comments

Comments
 (0)