@bemoje/eslint 1.0.0 → 1.0.1
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.
- package/README.md +3 -92
- package/index.d.ts +25 -1
- package/index.mjs +31 -2
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# @bemoje/eslint
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
asdasd
|
|
4
4
|
|
|
5
5
|
[](https://www.typescriptlang.org/)
|
|
6
6
|
[](https://nodejs.org/api/esm.html)
|
|
@@ -8,95 +8,6 @@ TypeScript eslint for lazy property initialization and method memoization.
|
|
|
8
8
|
## Installation
|
|
9
9
|
|
|
10
10
|
```bash
|
|
11
|
-
npm install @bemoje/eslint
|
|
11
|
+
npm install --D @bemoje/eslint
|
|
12
|
+
yarn add --D @bemoje/eslint
|
|
12
13
|
```
|
|
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
CHANGED
|
@@ -10,8 +10,32 @@ declare const createRule: <Options extends readonly unknown[], MessageIds extend
|
|
|
10
10
|
name: string;
|
|
11
11
|
};
|
|
12
12
|
|
|
13
|
+
declare function eslintPluginBemoje(): {
|
|
14
|
+
configs: {
|
|
15
|
+
readonly recommended: {
|
|
16
|
+
plugins: {
|
|
17
|
+
readonly 'eslint-plugin-bemoje': any;
|
|
18
|
+
};
|
|
19
|
+
rules: {
|
|
20
|
+
'no-blank-line-between-comment-and-declaration': _typescript_eslint_utils_ts_eslint.RuleModule<"no-blank-line-between-comment-and-declaration", [string], ExampleTypedLintingRuleDocs, _typescript_eslint_utils_ts_eslint.RuleListener> & {
|
|
21
|
+
name: string;
|
|
22
|
+
};
|
|
23
|
+
};
|
|
24
|
+
};
|
|
25
|
+
};
|
|
26
|
+
meta: {
|
|
27
|
+
name: string;
|
|
28
|
+
version: string;
|
|
29
|
+
};
|
|
30
|
+
rules: {
|
|
31
|
+
'no-blank-line-between-comment-and-declaration': _typescript_eslint_utils_ts_eslint.RuleModule<"no-blank-line-between-comment-and-declaration", [string], ExampleTypedLintingRuleDocs, _typescript_eslint_utils_ts_eslint.RuleListener> & {
|
|
32
|
+
name: string;
|
|
33
|
+
};
|
|
34
|
+
};
|
|
35
|
+
};
|
|
36
|
+
|
|
13
37
|
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
38
|
name: string;
|
|
15
39
|
};
|
|
16
40
|
|
|
17
|
-
export { type ExampleTypedLintingRuleDocs, createRule, noBlankLineBetweenCommentAndDeclaration };
|
|
41
|
+
export { type ExampleTypedLintingRuleDocs, createRule, eslintPluginBemoje, noBlankLineBetweenCommentAndDeclaration };
|
package/index.mjs
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { ESLintUtils, AST_TOKEN_TYPES } from '@typescript-eslint/utils';
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
4
5
|
var createRule = ESLintUtils.RuleCreator((name) => {
|
|
5
6
|
return `https://github.com/bemoje/tsmono/libs/eslint-plugin-bemoje/docs/rules/${name}.md`;
|
|
6
7
|
});
|
|
@@ -69,4 +70,32 @@ var noBlankLineBetweenCommentAndDeclaration = createRule({
|
|
|
69
70
|
}
|
|
70
71
|
});
|
|
71
72
|
|
|
72
|
-
|
|
73
|
+
// src/plugin.ts
|
|
74
|
+
function eslintPluginBemoje() {
|
|
75
|
+
const rules = {
|
|
76
|
+
"no-blank-line-between-comment-and-declaration": noBlankLineBetweenCommentAndDeclaration
|
|
77
|
+
};
|
|
78
|
+
const plugins = {
|
|
79
|
+
get "eslint-plugin-bemoje"() {
|
|
80
|
+
return eslintPluginBemoje();
|
|
81
|
+
}
|
|
82
|
+
};
|
|
83
|
+
return {
|
|
84
|
+
configs: {
|
|
85
|
+
get recommended() {
|
|
86
|
+
return {
|
|
87
|
+
plugins,
|
|
88
|
+
rules
|
|
89
|
+
};
|
|
90
|
+
}
|
|
91
|
+
},
|
|
92
|
+
meta: {
|
|
93
|
+
name: "eslint-plugin-bemoje",
|
|
94
|
+
version: "1.0.1"
|
|
95
|
+
},
|
|
96
|
+
rules
|
|
97
|
+
};
|
|
98
|
+
}
|
|
99
|
+
__name(eslintPluginBemoje, "eslintPluginBemoje");
|
|
100
|
+
|
|
101
|
+
export { createRule, eslintPluginBemoje, noBlankLineBetweenCommentAndDeclaration };
|