@bemoje/eslint 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (4) hide show
  1. package/README.md +102 -0
  2. package/index.d.ts +17 -0
  3. package/index.mjs +72 -0
  4. package/package.json +34 -0
package/README.md ADDED
@@ -0,0 +1,102 @@
1
+ # @bemoje/eslint
2
+
3
+ TypeScript eslint for lazy property initialization and method memoization.
4
+
5
+ [![TypeScript](https://img.shields.io/badge/TypeScript-5-blue)](https://www.typescriptlang.org/)
6
+ [![Module](https://img.shields.io/badge/Module-ESM-yellow)](https://nodejs.org/api/esm.html)
7
+
8
+ ## Installation
9
+
10
+ ```bash
11
+ npm install @bemoje/eslint
12
+ ```
13
+
14
+ ## Usage
15
+
16
+ ### Lazy Properties
17
+
18
+ Defer expensive computation until first access, then cache the result:
19
+
20
+ ```ts
21
+ import { lazyProp } from '@bemoje/eslint'
22
+
23
+ class Config {
24
+ @lazyProp
25
+ get expensiveValue() {
26
+ console.log('Computing...')
27
+ return Array.from({ length: 1000 }, (_, i) => i * i)
28
+ }
29
+ }
30
+
31
+ const config = new Config()
32
+ config.expensiveValue // logs 'Computing...', returns array
33
+ config.expensiveValue // returns cached array (no recomputation)
34
+ ```
35
+
36
+ ### Lazy Properties with Expiry
37
+
38
+ Cache values with automatic timeout-based invalidation:
39
+
40
+ ```ts
41
+ import { lazyProp } from '@bemoje/eslint'
42
+
43
+ class DataService {
44
+ @lazyProp('5 min') // re-fetches after 5 minutes
45
+ get cachedData() {
46
+ return fetchFromDatabase()
47
+ }
48
+
49
+ @lazyProp(30000) // re-fetches after 30 seconds
50
+ get frequentlyUpdated() {
51
+ return getLatestMetrics()
52
+ }
53
+ }
54
+ ```
55
+
56
+ ### Sync Memoization
57
+
58
+ Cache method results based on arguments:
59
+
60
+ ```ts
61
+ import { memoizeSync } from '@bemoje/eslint'
62
+
63
+ class MathService {
64
+ @memoizeSync()
65
+ fibonacci(n: number): number {
66
+ if (n <= 1) return n
67
+ return this.fibonacci(n - 1) + this.fibonacci(n - 2)
68
+ }
69
+ }
70
+
71
+ const svc = new MathService()
72
+ svc.fibonacci(40) // computed once, cached for subsequent calls
73
+ ```
74
+
75
+ ### Async Memoization
76
+
77
+ Cache async method results with optional TTL:
78
+
79
+ ```ts
80
+ import { memoizeAsync } from '@bemoje/eslint'
81
+
82
+ class ApiClient {
83
+ @memoizeAsync('10 min')
84
+ async fetchUser(id: string) {
85
+ const res = await fetch(`/api/users/${id}`)
86
+ return res.json()
87
+ }
88
+ }
89
+
90
+ const client = new ApiClient()
91
+ await client.fetchUser('123') // fetches from API
92
+ await client.fetchUser('123') // returns cached result
93
+ ```
94
+
95
+ ## API Reference
96
+
97
+ | Export | Description |
98
+ | --------------------------------- | -------------------------------------------------------------------- |
99
+ | `lazyProp` | Decorator for lazy-initialized getters and methods with optional TTL |
100
+ | `memoizeSync` | Decorator for caching synchronous method results |
101
+ | `memoizeAsync` | Decorator for caching async method results with Promise support |
102
+ | `assertDescriptorValueIsFunction` | Guard asserting a descriptor value is a function |
package/index.d.ts ADDED
@@ -0,0 +1,17 @@
1
+ import * as _typescript_eslint_utils_ts_eslint from '@typescript-eslint/utils/ts-eslint';
2
+ import { ESLintUtils } from '@typescript-eslint/utils';
3
+
4
+ interface ExampleTypedLintingRuleDocs {
5
+ description: string;
6
+ recommended?: boolean;
7
+ requiresTypeChecking?: boolean;
8
+ }
9
+ declare const createRule: <Options extends readonly unknown[], MessageIds extends string>({ meta, name, ...rule }: Readonly<ESLintUtils.RuleWithMetaAndName<Options, MessageIds, ExampleTypedLintingRuleDocs>>) => ESLintUtils.RuleModule<MessageIds, Options, ExampleTypedLintingRuleDocs, ESLintUtils.RuleListener> & {
10
+ name: string;
11
+ };
12
+
13
+ declare const noBlankLineBetweenCommentAndDeclaration: _typescript_eslint_utils_ts_eslint.RuleModule<"no-blank-line-between-comment-and-declaration", [string], ExampleTypedLintingRuleDocs, _typescript_eslint_utils_ts_eslint.RuleListener> & {
14
+ name: string;
15
+ };
16
+
17
+ export { type ExampleTypedLintingRuleDocs, createRule, noBlankLineBetweenCommentAndDeclaration };
package/index.mjs ADDED
@@ -0,0 +1,72 @@
1
+ import { ESLintUtils, AST_TOKEN_TYPES } from '@typescript-eslint/utils';
2
+
3
+ // src/rules/noBlankLineBetweenCommentAndDeclaration.ts
4
+ var createRule = ESLintUtils.RuleCreator((name) => {
5
+ return `https://github.com/bemoje/tsmono/libs/eslint-plugin-bemoje/docs/rules/${name}.md`;
6
+ });
7
+
8
+ // src/rules/noBlankLineBetweenCommentAndDeclaration.ts
9
+ var noBlankLineBetweenCommentAndDeclaration = createRule({
10
+ name: "no-blank-line-between-comment-and-declaration",
11
+ meta: {
12
+ fixable: "whitespace",
13
+ docs: {
14
+ description: "Consistant whitespace "
15
+ },
16
+ messages: {
17
+ "no-blank-line-between-comment-and-declaration": "Block comments for a declaration must not leave blank lines between them."
18
+ },
19
+ type: "suggestion",
20
+ schema: []
21
+ },
22
+ defaultOptions: [
23
+ "error"
24
+ ],
25
+ create(context) {
26
+ return {
27
+ Program(program) {
28
+ if (!program.comments) {
29
+ return;
30
+ }
31
+ program.comments.forEach((comment) => {
32
+ if (comment.type !== AST_TOKEN_TYPES.Block) {
33
+ return;
34
+ }
35
+ if (Math.abs(comment.loc.start.line - comment.loc.end.line) < 2) {
36
+ return;
37
+ }
38
+ const nextToken = context.sourceCode.getTokenAfter(comment);
39
+ if (!nextToken) {
40
+ return;
41
+ }
42
+ const actualNextTokenStartLine = nextToken.loc.start.line;
43
+ const expectedTokenStartLine = comment.loc.end.line + 1;
44
+ if (!(actualNextTokenStartLine > expectedTokenStartLine)) {
45
+ return;
46
+ }
47
+ const lineBeforeNextToken = context.sourceCode.lines[nextToken.loc.start.line - 1 - 1];
48
+ const hasLineCommentBetween = lineBeforeNextToken.trim().startsWith("//");
49
+ if (hasLineCommentBetween) {
50
+ return;
51
+ }
52
+ return context.report({
53
+ node: program,
54
+ messageId: "no-blank-line-between-comment-and-declaration",
55
+ fix(fixer) {
56
+ const start = comment.range[0];
57
+ const end = nextToken.range[1];
58
+ const rangeCode = context.sourceCode.text.slice(start, end);
59
+ const rangeCodeFixed = rangeCode.replaceAll(/\*\/\n\n+/gi, "*/\n");
60
+ return fixer.replaceTextRange([
61
+ start,
62
+ end
63
+ ], rangeCodeFixed);
64
+ }
65
+ });
66
+ });
67
+ }
68
+ };
69
+ }
70
+ });
71
+
72
+ export { createRule, noBlankLineBetweenCommentAndDeclaration };
package/package.json ADDED
@@ -0,0 +1,34 @@
1
+ {
2
+ "name": "@bemoje/eslint",
3
+ "version": "1.0.0",
4
+ "description": "eslint",
5
+ "type": "module",
6
+ "sideEffects": false,
7
+ "keywords": [
8
+ "eslint"
9
+ ],
10
+ "exports": {
11
+ ".": {
12
+ "types": "./index.d.ts",
13
+ "import": "./index.mjs",
14
+ "default": "./index.mjs"
15
+ }
16
+ },
17
+ "dependencies": {
18
+ "@typescript-eslint/utils": "^8.56.1"
19
+ },
20
+ "publishConfig": {
21
+ "access": "public"
22
+ },
23
+ "license": "MIT",
24
+ "author": {
25
+ "name": "Benjamin Møller Jensen",
26
+ "email": "bemoje@bemoje.net",
27
+ "url": "https://github.com/bemoje/"
28
+ },
29
+ "repository": {
30
+ "type": "git",
31
+ "url": "git+https://github.com/bemoje/mono.git",
32
+ "directory": "libs/eslint"
33
+ }
34
+ }