diff --git a/.vscode/settings.json b/.vscode/settings.json index f9d1c86a..a81ed920 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -13,17 +13,18 @@ }, // Silent the stylistic rules in you IDE, but still auto fix them - // "eslint.rules.customizations": [ - // { "rule": "style/*", "severity": "off" }, - // { "rule": "*-indent", "severity": "off" }, - // { "rule": "*-spacing", "severity": "off" }, - // { "rule": "*-spaces", "severity": "off" }, - // { "rule": "*-order", "severity": "off" }, - // { "rule": "*-dangle", "severity": "off" }, - // { "rule": "*-newline", "severity": "off" }, - // { "rule": "*quotes", "severity": "off" }, - // { "rule": "*semi", "severity": "off" } - // ], + "eslint.rules.customizations": [ + { "rule": "style/*", "severity": "off" }, + { "rule": "format/*", "severity": "off" }, + { "rule": "*-indent", "severity": "off" }, + { "rule": "*-spacing", "severity": "off" }, + { "rule": "*-spaces", "severity": "off" }, + { "rule": "*-order", "severity": "off" }, + { "rule": "*-dangle", "severity": "off" }, + { "rule": "*-newline", "severity": "off" }, + { "rule": "*quotes", "severity": "off" }, + { "rule": "*semi", "severity": "off" } + ], // Enable eslint for all supported languages "eslint.validate": [ @@ -36,7 +37,8 @@ "markdown", "json", "jsonc", - "yaml" + "yaml", + "toml" ], "vitest.commandLine": "pnpm exec vitest", diff --git a/README.md b/README.md index 5430f3cc..c9b6d47e 100644 --- a/README.md +++ b/README.md @@ -158,7 +158,7 @@ Typed and async emitter: ```ts interface MyEvents { - inc(count: number): number + inc: (count: number) => number } const counter = 0 @@ -188,7 +188,7 @@ You can also use a global emitter that will be available even over module bounda ```ts declare global { interface ZeedGlobalEmitter { - test(x: string): void + test: (x: string) => void } } diff --git a/demos/sideeffects/README.md b/demos/sideeffects/README.md index 7e0a5e9d..37689a54 100644 --- a/demos/sideeffects/README.md +++ b/demos/sideeffects/README.md @@ -4,7 +4,7 @@ Some rules to follow to keep code [sideEffects](https://webpack.js.org/guides/tr ## Never use `export enum` -This is a major pain point because it will always create some code, i.e. an object to map values and names to. +This is a major pain point because it will always create some code, i.e. an object to map values and names to. Better use strings, like `type MyStates = 'sleep' | 'code' | 'eat'`. @@ -84,7 +84,7 @@ function encode64(data) { } ``` -## Lazy logging +## Lazy logging Logging often follows this pattern at the top level of a file: @@ -92,7 +92,7 @@ Logging often follows this pattern at the top level of a file: const log = Logger("fancy") ``` -This is a constant that stays, whether used or not. +This is a constant that stays, whether used or not. Avoid logging or do it lazily inside the function. As for [zeed](https://github.com/holtwick/zeed), I go even further and only use logging if the importing application uses logging, which looks like this @@ -102,4 +102,4 @@ getGlobalLoggerIfExists()?.('fanzy')?.info('Just FYI') ## Conclusion -There are some pitfalls, but by following some coding patterns it is doable and you will be rewarded by minimal code usage. This way I can cram even more code into a single library without worrying about the resulting app size ;) \ No newline at end of file +There are some pitfalls, but by following some coding patterns it is doable and you will be rewarded by minimal code usage. This way I can cram even more code into a single library without worrying about the resulting app size ;) diff --git a/demos/sideeffects/index-with-log.ts b/demos/sideeffects/index-with-log.ts index 7bb8e489..75eed3f6 100644 --- a/demos/sideeffects/index-with-log.ts +++ b/demos/sideeffects/index-with-log.ts @@ -1,11 +1,10 @@ -/* eslint-disable no-console */ +import type { LoggerInterface } from 'zeed' +import { Logger, arrayUnion } from 'zeed' -import { arrayUnion, Logger, LoggerInterface } from 'zeed' +const log: LoggerInterface = Logger('test') -const log: LoggerInterface = Logger("test") - -let a = [1,2,3,3] -let aa = arrayUnion(a) +const a = [1, 2, 3, 3] +const aa = arrayUnion(a) log('result arrayUnion', aa) diff --git a/demos/sideeffects/index.ts b/demos/sideeffects/index.ts index 7fc07460..d5f340bb 100644 --- a/demos/sideeffects/index.ts +++ b/demos/sideeffects/index.ts @@ -5,8 +5,8 @@ import { arrayUnion } from 'zeed' // import { Logger, LoggerInterface } from "zeed" // const log: LoggerInterface = Logger("test") -let a = [1,2,3,3] -let aa = arrayUnion(a) +const a = [1, 2, 3, 3] +const aa = arrayUnion(a) console.log('result arrayUnion', aa) diff --git a/demos/sideeffects/package.json b/demos/sideeffects/package.json index 09dd6f36..8c03b219 100644 --- a/demos/sideeffects/package.json +++ b/demos/sideeffects/package.json @@ -4,8 +4,8 @@ "version": "0.1.0", "description": "Just a demo", "author": "Dirk Holtwick", - "main": "index.js", "sideEffects": false, + "main": "index.js", "scripts": { "start": "pnpm run build && ZEED=* node dist/node/index.js", "build:zeed": "(cd ../.. && pnpm build)", diff --git a/demos/tests/src/jest.ts b/demos/tests/src/jest.ts index 3f27f7b5..df0d72b3 100644 --- a/demos/tests/src/jest.ts +++ b/demos/tests/src/jest.ts @@ -2,7 +2,7 @@ /* eslint-disable no-console */ /* eslint-disable eqeqeq */ -import { Buffer } from 'buffer' +import { Buffer } from 'node:buffer' import { format } from 'pretty-format' import { fn } from 'jest-mock' import { Logger, deepEqual, isPromise } from '../../../src/index.browser' diff --git a/demos/tests/src/shims-vue.d.ts b/demos/tests/src/shims-vue.d.ts index 20e23f03..9a745726 100644 --- a/demos/tests/src/shims-vue.d.ts +++ b/demos/tests/src/shims-vue.d.ts @@ -1,5 +1,6 @@ -declare module "*.vue" { - import { DefineComponent } from "vue" - const component: DefineComponent<{}, {}, any> +declare module '*.vue' { + import type { DefineComponent } from 'vue' + + const component: DefineComponent export default component } diff --git a/demos/tests/src/test-unit-all.ts b/demos/tests/src/test-unit-all.ts index 412d07f5..9725cf6d 100644 --- a/demos/tests/src/test-unit-all.ts +++ b/demos/tests/src/test-unit-all.ts @@ -16,15 +16,15 @@ console.log('load all browser') { const candidates = import.meta.glob('../../../src/browser/*.spec.*') - handleCandidates(candidates) + void handleCandidates(candidates) } { const candidates = import.meta.glob('../../../src/common/*.spec.*') - handleCandidates(candidates) + void handleCandidates(candidates) } { const candidates = import.meta.glob('../../../src/common/**/*.spec.*') - handleCandidates(candidates) + void handleCandidates(candidates) } diff --git a/demos/tests/tsconfig.json b/demos/tests/tsconfig.json index 64d1347a..7a249363 100644 --- a/demos/tests/tsconfig.json +++ b/demos/tests/tsconfig.json @@ -1,17 +1,17 @@ { "compilerOptions": { "target": "esnext", + "jsx": "preserve", + "lib": ["esnext", "dom"], "module": "esnext", "moduleResolution": "Bundler", - "strict": true, + "resolveJsonModule": true, + "types": ["vite/client"], "allowJs": true, "checkJs": false, - "jsx": "preserve", + "strict": true, "sourceMap": true, - "resolveJsonModule": true, - "esModuleInterop": true, - "lib": ["esnext", "dom"], - "types": ["vite/client"] + "esModuleInterop": true }, "include": ["src/**/*.ts", "src/**/*.d.ts", "src/**/*.tsx", "src/**/*.vue"] } diff --git a/demos/vite/src/components/HelloWorld.vue b/demos/vite/src/components/HelloWorld.vue index 7bc140f6..4a3ba8e5 100644 --- a/demos/vite/src/components/HelloWorld.vue +++ b/demos/vite/src/components/HelloWorld.vue @@ -1,6 +1,7 @@