From 2176712b3e2f1c1315b86c25ba042a4bb96d66f4 Mon Sep 17 00:00:00 2001 From: Sparticuz Date: Fri, 12 Apr 2024 16:01:09 -0400 Subject: [PATCH] vitest.config.ts --- README.md | 90 +++++++++++++++++++++++++++++++++++++++-------- eslint.config.js | 7 ++-- package-lock.json | 50 -------------------------- package.json | 2 -- 4 files changed, 81 insertions(+), 68 deletions(-) diff --git a/README.md b/README.md index a49df1c..f8db111 100644 --- a/README.md +++ b/README.md @@ -4,38 +4,100 @@ My eslint config I use this on projects that I develop. +Included in the readme is also Typescript, Prettier, Vitest configs for bootstrapping new projects. + ## Install -`npm install --save-dev @sparticuz/eslint-config typescript-eslint` +`npm install --save-dev @sparticuz/eslint-config typescript-eslint typescript prettier vitest @tsconfig/node20 @tsconfig/strictest` + +## Example package.json + +```json +"scripts": { + "build": "rm -rf dist/** && tsc -p tsconfig.build.json", + "lint": "eslint \"**/*.?(c|m)[jt]s?(x)\"", + "test": "vitest run --coverage" +}, +``` ## Example eslint.config.js ```js // @ts-check - import myConfig from "@sparticuz/eslint-config"; import tseslint from "typescript-eslint"; export default tseslint.config( - ...myConfig, { - languageOptions: { - parserOptions: { - project: true - } - } - } + ignores: ["dist/**/*"], + }, + ...myConfig, ); ``` -## Example prettier.config.cjs - -This is my prettier.config.cjs file. Requires `npm install --save-dev prettier @ianvs/prettier-plugin-sort-imports` +## Example prettier.config.js ```js /** @type {import("prettier").Config} */ -const config = { +export const config = { trailingComma: "all", }; -module.exports = config; +export default config; +``` + +## Example Typescript config + +### tsconfig.json + +```json +{ + "$schema": "https://json.schemastore.org/tsconfig", + "display": "Base Default TSConfig", + "extends": ["@tsconfig/node20/tsconfig", "@tsconfig/strictest/tsconfig"], + "compilerOptions": { + "declaration": true, + "declarationMap": true, + "exactOptionalPropertyTypes": false, + "lib": ["DOM", "ES2023"], + "module": "NodeNext", + "moduleResolution": "nodenext", + "noUnusedLocals": false, + "outDir": "dist", + "resolveJsonModule": true, + "sourceMap": true + }, + "include": ["src", "test"] +} +``` + +### tsconfig.build.json + +```json +{ + // extend your base config to share compilerOptions, etc + "extends": "./tsconfig.json", + "compilerOptions": { + "outDir": "dist", + "removeComments": true, + "sourceMap": false + }, + "exclude": ["test"] +} +``` + +## Example vitest.config.ts + +```ts +import { loadEnv } from "vite"; +import { defineConfig } from "vitest/config"; + +export default defineConfig({ + test: { + coverage: { + reportOnFailure: true, + reporter: ["json", "json-summary", "text"], + }, + env: loadEnv("", process.cwd(), ""), + }, +}); ``` diff --git a/eslint.config.js b/eslint.config.js index 429c851..3d130ba 100644 --- a/eslint.config.js +++ b/eslint.config.js @@ -1,4 +1,6 @@ +// @ts-expect-error There are no types import js from "@eslint/js"; +// @ts-expect-error There are no types import prettierConfig from "eslint-config-prettier"; // @ts-expect-error There are no types import arrayFuncPlugin from "eslint-plugin-array-func"; @@ -132,10 +134,11 @@ export default tseslint.config( { // Disable typechecking for Javascript files extends: [tseslint.configs.disableTypeChecked], - files: ["*.js", "eslint.config.js"], + files: ["*.js"], }, { - files: ["eslint.config.js"], + extends: [tseslint.configs.disableTypeChecked], + files: ["eslint.config.js", "vitest.config.ts"], rules: { // Everything should be included in @sparticuz/eslint-config's dependencies. "n/no-extraneous-import": "off", diff --git a/package-lock.json b/package-lock.json index 47fb120..3175c5d 100644 --- a/package-lock.json +++ b/package-lock.json @@ -9,10 +9,8 @@ "version": "8.0.3", "license": "ISC", "dependencies": { - "@eslint-community/eslint-plugin-eslint-comments": "^4.3.0", "eslint-config-prettier": "^9.1.0", "eslint-plugin-array-func": "^5.0.1", - "eslint-plugin-es-x": "^7.6.0", "eslint-plugin-n": "^17.2.0", "eslint-plugin-perfectionist": "^2.8.0", "eslint-plugin-regexp": "^2.5.0", @@ -25,8 +23,6 @@ "devDependencies": { "@tsconfig/node20": "^20.1.4", "@tsconfig/strictest": "^2.0.5", - "@types/eslint__js": "^8.42.3", - "@types/eslint-config-prettier": "^6.11.3", "eslint": "^8.57.0", "prettier": "^3.2.5", "typescript": "^5.4.5" @@ -201,21 +197,6 @@ "node": ">=4" } }, - "node_modules/@eslint-community/eslint-plugin-eslint-comments": { - "version": "4.3.0", - "resolved": "https://registry.npmjs.org/@eslint-community/eslint-plugin-eslint-comments/-/eslint-plugin-eslint-comments-4.3.0.tgz", - "integrity": "sha512-6e93KtgsndNkvwCCa07LOQJSwzzLLxwrFll3+huyFoiiQXWG0KBcmo0Q1bVgYQQDLfWOOZl2VPBsXqZL6vHIBQ==", - "dependencies": { - "escape-string-regexp": "^4.0.0", - "ignore": "^5.2.4" - }, - "engines": { - "node": "^12.22.0 || ^14.17.0 || >=16.0.0" - }, - "peerDependencies": { - "eslint": "^6.0.0 || ^7.0.0 || ^8.0.0 || ^9.0.0" - } - }, "node_modules/@eslint-community/eslint-utils": { "version": "4.4.0", "resolved": "https://registry.npmjs.org/@eslint-community/eslint-utils/-/eslint-utils-4.4.0.tgz", @@ -320,37 +301,6 @@ "integrity": "sha512-ec4tjL2Rr0pkZ5hww65c+EEPYwxOi4Ryv+0MtjeaSQRJyq322Q27eOQiFbuNgw2hpL4hB1/W/HBGk3VKS43osg==", "dev": true }, - "node_modules/@types/eslint": { - "version": "8.56.9", - "resolved": "https://registry.npmjs.org/@types/eslint/-/eslint-8.56.9.tgz", - "integrity": "sha512-W4W3KcqzjJ0sHg2vAq9vfml6OhsJ53TcUjUqfzzZf/EChUtwspszj/S0pzMxnfRcO55/iGq47dscXw71Fxc4Zg==", - "dev": true, - "dependencies": { - "@types/estree": "*", - "@types/json-schema": "*" - } - }, - "node_modules/@types/eslint__js": { - "version": "8.42.3", - "resolved": "https://registry.npmjs.org/@types/eslint__js/-/eslint__js-8.42.3.tgz", - "integrity": "sha512-alfG737uhmPdnvkrLdZLcEKJ/B8s9Y4hrZ+YAdzUeoArBlSUERA2E87ROfOaS4jd/C45fzOoZzidLc1IPwLqOw==", - "dev": true, - "dependencies": { - "@types/eslint": "*" - } - }, - "node_modules/@types/eslint-config-prettier": { - "version": "6.11.3", - "resolved": "https://registry.npmjs.org/@types/eslint-config-prettier/-/eslint-config-prettier-6.11.3.tgz", - "integrity": "sha512-3wXCiM8croUnhg9LdtZUJQwNcQYGWxxdOWDjPe1ykCqJFPVpzAKfs/2dgSoCtAvdPeaponcWPI7mPcGGp9dkKQ==", - "dev": true - }, - "node_modules/@types/estree": { - "version": "1.0.5", - "resolved": "https://registry.npmjs.org/@types/estree/-/estree-1.0.5.tgz", - "integrity": "sha512-/kYRxGDLWzHOB7q+wtSUQlFrtcdUccpfy+X+9iMBpHK8QLLhx2wIPYuS5DYtR9Wa/YlZAbIovy7qVdB1Aq6Lyw==", - "dev": true - }, "node_modules/@types/json-schema": { "version": "7.0.15", "resolved": "https://registry.npmjs.org/@types/json-schema/-/json-schema-7.0.15.tgz", diff --git a/package.json b/package.json index ec4295f..447c9cf 100644 --- a/package.json +++ b/package.json @@ -24,8 +24,6 @@ "devDependencies": { "@tsconfig/node20": "^20.1.4", "@tsconfig/strictest": "^2.0.5", - "@types/eslint__js": "^8.42.3", - "@types/eslint-config-prettier": "^6.11.3", "eslint": "^8.57.0", "prettier": "^3.2.5", "typescript": "^5.4.5"