@mytechtoday/augment-extensions 0.1.0 → 0.1.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/AGENTS.md +83 -3
- package/README.md +6 -5
- package/augment-extensions/coding-standards/python/README.md +44 -0
- package/augment-extensions/coding-standards/python/module.json +26 -0
- package/augment-extensions/coding-standards/python/rules/best-practices.md +232 -0
- package/augment-extensions/coding-standards/python/rules/code-organization.md +220 -0
- package/augment-extensions/coding-standards/python/rules/error-handling.md +221 -0
- package/augment-extensions/coding-standards/python/rules/naming-conventions.md +172 -0
- package/augment-extensions/coding-standards/python/rules/type-hints.md +188 -0
- package/augment-extensions/coding-standards/react/README.md +45 -0
- package/augment-extensions/coding-standards/react/module.json +27 -0
- package/augment-extensions/coding-standards/react/rules/component-patterns.md +214 -0
- package/augment-extensions/coding-standards/react/rules/hooks-best-practices.md +235 -0
- package/augment-extensions/coding-standards/react/rules/performance.md +300 -0
- package/augment-extensions/coding-standards/react/rules/state-management.md +265 -0
- package/augment-extensions/coding-standards/react/rules/typescript-react.md +271 -0
- package/augment-extensions/domain-rules/api-design/README.md +41 -0
- package/augment-extensions/domain-rules/api-design/module.json +27 -0
- package/augment-extensions/domain-rules/api-design/rules/authentication.md +263 -0
- package/augment-extensions/domain-rules/api-design/rules/documentation.md +395 -0
- package/augment-extensions/domain-rules/api-design/rules/error-handling.md +290 -0
- package/augment-extensions/domain-rules/api-design/rules/graphql-api.md +313 -0
- package/augment-extensions/domain-rules/api-design/rules/rest-api.md +214 -0
- package/augment-extensions/domain-rules/api-design/rules/versioning.md +268 -0
- package/augment-extensions/domain-rules/security/README.md +41 -0
- package/augment-extensions/domain-rules/security/module.json +28 -0
- package/augment-extensions/domain-rules/security/rules/authentication-security.md +361 -0
- package/augment-extensions/domain-rules/security/rules/encryption.md +208 -0
- package/augment-extensions/domain-rules/security/rules/input-validation.md +294 -0
- package/augment-extensions/domain-rules/security/rules/owasp-top-10.md +339 -0
- package/augment-extensions/domain-rules/security/rules/secure-coding.md +293 -0
- package/augment-extensions/domain-rules/security/rules/web-security.md +268 -0
- package/augment-extensions/examples/design-patterns/README.md +37 -0
- package/augment-extensions/examples/design-patterns/examples/behavioral-patterns.md +370 -0
- package/augment-extensions/examples/design-patterns/examples/creational-patterns.md +250 -0
- package/augment-extensions/examples/design-patterns/examples/structural-patterns.md +264 -0
- package/augment-extensions/examples/design-patterns/module.json +27 -0
- package/{modules → augment-extensions}/workflows/beads/examples/complete-workflow-example.md +5 -5
- package/{modules → augment-extensions}/workflows/beads/rules/file-format.md +45 -1
- package/{modules → augment-extensions}/workflows/beads/rules/workflow.md +41 -0
- package/{modules → augment-extensions}/workflows/openspec/examples/complete-change-example.md +14 -0
- package/{modules → augment-extensions}/workflows/openspec/rules/spec-format.md +44 -1
- package/{modules → augment-extensions}/workflows/openspec/rules/workflow.md +25 -0
- package/cli/dist/cli.js +64 -0
- package/cli/dist/cli.js.map +1 -1
- package/cli/dist/commands/coord.d.ts +30 -0
- package/cli/dist/commands/coord.d.ts.map +1 -0
- package/cli/dist/commands/coord.js +150 -0
- package/cli/dist/commands/coord.js.map +1 -0
- package/cli/dist/commands/link.js +1 -1
- package/cli/dist/commands/link.js.map +1 -1
- package/cli/dist/commands/list.js +1 -1
- package/cli/dist/commands/list.js.map +1 -1
- package/cli/dist/commands/search.d.ts.map +1 -1
- package/cli/dist/commands/search.js +107 -5
- package/cli/dist/commands/search.js.map +1 -1
- package/cli/dist/commands/show.js +1 -1
- package/cli/dist/commands/show.js.map +1 -1
- package/cli/dist/commands/sync.d.ts +26 -0
- package/cli/dist/commands/sync.d.ts.map +1 -0
- package/cli/dist/commands/sync.js +106 -0
- package/cli/dist/commands/sync.js.map +1 -0
- package/cli/dist/commands/update.d.ts.map +1 -1
- package/cli/dist/commands/update.js +132 -7
- package/cli/dist/commands/update.js.map +1 -1
- package/cli/dist/utils/auto-sync.d.ts +34 -0
- package/cli/dist/utils/auto-sync.d.ts.map +1 -0
- package/cli/dist/utils/auto-sync.js +172 -0
- package/cli/dist/utils/auto-sync.js.map +1 -0
- package/cli/dist/utils/beads-sync.d.ts +51 -0
- package/cli/dist/utils/beads-sync.d.ts.map +1 -0
- package/cli/dist/utils/beads-sync.js +171 -0
- package/cli/dist/utils/beads-sync.js.map +1 -0
- package/cli/dist/utils/coordination-queries.d.ts +79 -0
- package/cli/dist/utils/coordination-queries.d.ts.map +1 -0
- package/cli/dist/utils/coordination-queries.js +155 -0
- package/cli/dist/utils/coordination-queries.js.map +1 -0
- package/cli/dist/utils/file-tracking.d.ts +42 -0
- package/cli/dist/utils/file-tracking.d.ts.map +1 -0
- package/cli/dist/utils/file-tracking.js +155 -0
- package/cli/dist/utils/file-tracking.js.map +1 -0
- package/cli/dist/utils/migrate.d.ts +25 -0
- package/cli/dist/utils/migrate.d.ts.map +1 -0
- package/cli/dist/utils/migrate.js +204 -0
- package/cli/dist/utils/migrate.js.map +1 -0
- package/cli/dist/utils/openspec-sync.d.ts +48 -0
- package/cli/dist/utils/openspec-sync.d.ts.map +1 -0
- package/cli/dist/utils/openspec-sync.js +167 -0
- package/cli/dist/utils/openspec-sync.js.map +1 -0
- package/{MODULES.md → modules.md} +1 -1
- package/package.json +9 -7
- /package/{modules → augment-extensions}/coding-standards/typescript/README.md +0 -0
- /package/{modules → augment-extensions}/coding-standards/typescript/module.json +0 -0
- /package/{modules → augment-extensions}/coding-standards/typescript/rules/naming-conventions.md +0 -0
- /package/{modules → augment-extensions}/workflows/beads/README.md +0 -0
- /package/{modules → augment-extensions}/workflows/beads/module.json +0 -0
- /package/{modules → augment-extensions}/workflows/beads/rules/best-practices.md +0 -0
- /package/{modules → augment-extensions}/workflows/beads/rules/manual-setup.md +0 -0
- /package/{modules → augment-extensions}/workflows/openspec/README.md +0 -0
- /package/{modules → augment-extensions}/workflows/openspec/module.json +0 -0
- /package/{modules → augment-extensions}/workflows/openspec/rules/best-practices.md +0 -0
- /package/{modules → augment-extensions}/workflows/openspec/rules/manual-setup.md +0 -0
|
@@ -0,0 +1,221 @@
|
|
|
1
|
+
# Python Error Handling
|
|
2
|
+
|
|
3
|
+
Proper exception handling patterns for robust Python code.
|
|
4
|
+
|
|
5
|
+
## Basic Exception Handling
|
|
6
|
+
|
|
7
|
+
```python
|
|
8
|
+
# Good - Specific exception
|
|
9
|
+
try:
|
|
10
|
+
result = int(user_input)
|
|
11
|
+
except ValueError as e:
|
|
12
|
+
print(f"Invalid input: {e}")
|
|
13
|
+
result = 0
|
|
14
|
+
|
|
15
|
+
# Bad - Bare except
|
|
16
|
+
try:
|
|
17
|
+
result = int(user_input)
|
|
18
|
+
except: # Don't do this
|
|
19
|
+
result = 0
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
## Multiple Exceptions
|
|
23
|
+
|
|
24
|
+
```python
|
|
25
|
+
# Handle different exceptions differently
|
|
26
|
+
try:
|
|
27
|
+
with open(file_path) as f:
|
|
28
|
+
data = json.load(f)
|
|
29
|
+
except FileNotFoundError:
|
|
30
|
+
print(f"File not found: {file_path}")
|
|
31
|
+
data = {}
|
|
32
|
+
except json.JSONDecodeError as e:
|
|
33
|
+
print(f"Invalid JSON: {e}")
|
|
34
|
+
data = {}
|
|
35
|
+
except PermissionError:
|
|
36
|
+
print(f"Permission denied: {file_path}")
|
|
37
|
+
data = {}
|
|
38
|
+
|
|
39
|
+
# Handle multiple exceptions the same way
|
|
40
|
+
try:
|
|
41
|
+
result = perform_operation()
|
|
42
|
+
except (ValueError, TypeError, KeyError) as e:
|
|
43
|
+
print(f"Operation failed: {e}")
|
|
44
|
+
result = None
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
## Finally and Else
|
|
48
|
+
|
|
49
|
+
```python
|
|
50
|
+
# Using finally for cleanup
|
|
51
|
+
try:
|
|
52
|
+
file = open(file_path)
|
|
53
|
+
data = file.read()
|
|
54
|
+
except FileNotFoundError:
|
|
55
|
+
print("File not found")
|
|
56
|
+
data = None
|
|
57
|
+
finally:
|
|
58
|
+
if 'file' in locals():
|
|
59
|
+
file.close()
|
|
60
|
+
|
|
61
|
+
# Using else for success case
|
|
62
|
+
try:
|
|
63
|
+
result = risky_operation()
|
|
64
|
+
except ValueError:
|
|
65
|
+
print("Operation failed")
|
|
66
|
+
else:
|
|
67
|
+
print("Operation succeeded")
|
|
68
|
+
process_result(result)
|
|
69
|
+
finally:
|
|
70
|
+
cleanup()
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
## Context Managers
|
|
74
|
+
|
|
75
|
+
```python
|
|
76
|
+
# Preferred - Automatic cleanup
|
|
77
|
+
with open(file_path) as f:
|
|
78
|
+
data = f.read()
|
|
79
|
+
|
|
80
|
+
# Multiple context managers
|
|
81
|
+
with open(input_file) as f_in, open(output_file, 'w') as f_out:
|
|
82
|
+
data = f_in.read()
|
|
83
|
+
f_out.write(process(data))
|
|
84
|
+
|
|
85
|
+
# Custom context manager
|
|
86
|
+
from contextlib import contextmanager
|
|
87
|
+
|
|
88
|
+
@contextmanager
|
|
89
|
+
def database_connection(db_url: str):
|
|
90
|
+
conn = connect(db_url)
|
|
91
|
+
try:
|
|
92
|
+
yield conn
|
|
93
|
+
finally:
|
|
94
|
+
conn.close()
|
|
95
|
+
|
|
96
|
+
# Usage
|
|
97
|
+
with database_connection("postgresql://...") as conn:
|
|
98
|
+
conn.execute("SELECT * FROM users")
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
## Custom Exceptions
|
|
102
|
+
|
|
103
|
+
```python
|
|
104
|
+
# Define custom exceptions
|
|
105
|
+
class ValidationError(Exception):
|
|
106
|
+
"""Raised when validation fails"""
|
|
107
|
+
pass
|
|
108
|
+
|
|
109
|
+
class AuthenticationError(Exception):
|
|
110
|
+
"""Raised when authentication fails"""
|
|
111
|
+
def __init__(self, user_id: int, message: str = "Authentication failed"):
|
|
112
|
+
self.user_id = user_id
|
|
113
|
+
self.message = message
|
|
114
|
+
super().__init__(self.message)
|
|
115
|
+
|
|
116
|
+
# Usage
|
|
117
|
+
def validate_email(email: str) -> None:
|
|
118
|
+
if '@' not in email:
|
|
119
|
+
raise ValidationError(f"Invalid email: {email}")
|
|
120
|
+
|
|
121
|
+
def authenticate_user(user_id: int, password: str) -> User:
|
|
122
|
+
if not verify_password(user_id, password):
|
|
123
|
+
raise AuthenticationError(user_id)
|
|
124
|
+
return get_user(user_id)
|
|
125
|
+
```
|
|
126
|
+
|
|
127
|
+
## Exception Chaining
|
|
128
|
+
|
|
129
|
+
```python
|
|
130
|
+
# Preserve original exception
|
|
131
|
+
try:
|
|
132
|
+
result = process_data(data)
|
|
133
|
+
except ValueError as e:
|
|
134
|
+
raise ProcessingError("Failed to process data") from e
|
|
135
|
+
|
|
136
|
+
# Suppress original exception (rare)
|
|
137
|
+
try:
|
|
138
|
+
result = process_data(data)
|
|
139
|
+
except ValueError:
|
|
140
|
+
raise ProcessingError("Failed to process data") from None
|
|
141
|
+
```
|
|
142
|
+
|
|
143
|
+
## Logging Exceptions
|
|
144
|
+
|
|
145
|
+
```python
|
|
146
|
+
import logging
|
|
147
|
+
|
|
148
|
+
logger = logging.getLogger(__name__)
|
|
149
|
+
|
|
150
|
+
# Log exception with traceback
|
|
151
|
+
try:
|
|
152
|
+
result = risky_operation()
|
|
153
|
+
except Exception as e:
|
|
154
|
+
logger.exception("Operation failed") # Includes traceback
|
|
155
|
+
raise
|
|
156
|
+
|
|
157
|
+
# Log without traceback
|
|
158
|
+
try:
|
|
159
|
+
result = risky_operation()
|
|
160
|
+
except ValueError as e:
|
|
161
|
+
logger.error(f"Invalid value: {e}")
|
|
162
|
+
result = default_value
|
|
163
|
+
```
|
|
164
|
+
|
|
165
|
+
## Best Practices
|
|
166
|
+
|
|
167
|
+
1. **Catch specific exceptions** - Never use bare `except:`
|
|
168
|
+
2. **Use context managers** - Prefer `with` for resource management
|
|
169
|
+
3. **Don't silence exceptions** - Log or handle them properly
|
|
170
|
+
4. **Create custom exceptions** - For domain-specific errors
|
|
171
|
+
5. **Use exception chaining** - Preserve error context with `from`
|
|
172
|
+
6. **Clean up resources** - Use `finally` or context managers
|
|
173
|
+
7. **Fail fast** - Don't catch exceptions you can't handle
|
|
174
|
+
8. **Document exceptions** - Use docstrings to document raised exceptions
|
|
175
|
+
|
|
176
|
+
## Anti-Patterns to Avoid
|
|
177
|
+
|
|
178
|
+
```python
|
|
179
|
+
# DON'T: Bare except
|
|
180
|
+
try:
|
|
181
|
+
do_something()
|
|
182
|
+
except:
|
|
183
|
+
pass
|
|
184
|
+
|
|
185
|
+
# DON'T: Catch Exception without re-raising
|
|
186
|
+
try:
|
|
187
|
+
critical_operation()
|
|
188
|
+
except Exception:
|
|
189
|
+
print("Error occurred")
|
|
190
|
+
|
|
191
|
+
# DON'T: Use exceptions for flow control
|
|
192
|
+
try:
|
|
193
|
+
value = my_dict[key]
|
|
194
|
+
except KeyError:
|
|
195
|
+
value = default
|
|
196
|
+
|
|
197
|
+
# DO: Use get() instead
|
|
198
|
+
value = my_dict.get(key, default)
|
|
199
|
+
```
|
|
200
|
+
|
|
201
|
+
## Exception Hierarchy
|
|
202
|
+
|
|
203
|
+
```python
|
|
204
|
+
# Create exception hierarchy
|
|
205
|
+
class AppError(Exception):
|
|
206
|
+
"""Base exception for application"""
|
|
207
|
+
pass
|
|
208
|
+
|
|
209
|
+
class DatabaseError(AppError):
|
|
210
|
+
"""Database-related errors"""
|
|
211
|
+
pass
|
|
212
|
+
|
|
213
|
+
class ConnectionError(DatabaseError):
|
|
214
|
+
"""Database connection errors"""
|
|
215
|
+
pass
|
|
216
|
+
|
|
217
|
+
class QueryError(DatabaseError):
|
|
218
|
+
"""Database query errors"""
|
|
219
|
+
pass
|
|
220
|
+
```
|
|
221
|
+
|
|
@@ -0,0 +1,172 @@
|
|
|
1
|
+
# Python Naming Conventions
|
|
2
|
+
|
|
3
|
+
Follow PEP 8 naming conventions strictly.
|
|
4
|
+
|
|
5
|
+
## Module Names
|
|
6
|
+
|
|
7
|
+
- Use lowercase with underscores: `my_module.py`
|
|
8
|
+
- Keep names short and descriptive
|
|
9
|
+
- Avoid single-letter names except for common abbreviations
|
|
10
|
+
|
|
11
|
+
```python
|
|
12
|
+
# Good
|
|
13
|
+
user_authentication.py
|
|
14
|
+
data_processor.py
|
|
15
|
+
api_client.py
|
|
16
|
+
|
|
17
|
+
# Bad
|
|
18
|
+
UserAuthentication.py
|
|
19
|
+
dataProcessor.py
|
|
20
|
+
ua.py
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
## Class Names
|
|
24
|
+
|
|
25
|
+
- Use CapWords (PascalCase)
|
|
26
|
+
- Use nouns or noun phrases
|
|
27
|
+
- Avoid abbreviations unless widely known
|
|
28
|
+
|
|
29
|
+
```python
|
|
30
|
+
# Good
|
|
31
|
+
class UserAccount:
|
|
32
|
+
pass
|
|
33
|
+
|
|
34
|
+
class HTTPClient:
|
|
35
|
+
pass
|
|
36
|
+
|
|
37
|
+
class DataProcessor:
|
|
38
|
+
pass
|
|
39
|
+
|
|
40
|
+
# Bad
|
|
41
|
+
class user_account:
|
|
42
|
+
pass
|
|
43
|
+
|
|
44
|
+
class Http_Client:
|
|
45
|
+
pass
|
|
46
|
+
|
|
47
|
+
class DP:
|
|
48
|
+
pass
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
## Function and Method Names
|
|
52
|
+
|
|
53
|
+
- Use lowercase with underscores (snake_case)
|
|
54
|
+
- Use verbs or verb phrases
|
|
55
|
+
- Be descriptive and clear
|
|
56
|
+
|
|
57
|
+
```python
|
|
58
|
+
# Good
|
|
59
|
+
def calculate_total_price():
|
|
60
|
+
pass
|
|
61
|
+
|
|
62
|
+
def get_user_by_id(user_id: int):
|
|
63
|
+
pass
|
|
64
|
+
|
|
65
|
+
def is_valid_email(email: str) -> bool:
|
|
66
|
+
pass
|
|
67
|
+
|
|
68
|
+
# Bad
|
|
69
|
+
def CalcPrice():
|
|
70
|
+
pass
|
|
71
|
+
|
|
72
|
+
def getUserById(userId):
|
|
73
|
+
pass
|
|
74
|
+
|
|
75
|
+
def valid(e):
|
|
76
|
+
pass
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
## Variable Names
|
|
80
|
+
|
|
81
|
+
- Use lowercase with underscores
|
|
82
|
+
- Be descriptive
|
|
83
|
+
- Avoid single letters except in loops or comprehensions
|
|
84
|
+
|
|
85
|
+
```python
|
|
86
|
+
# Good
|
|
87
|
+
user_count = 10
|
|
88
|
+
total_price = 99.99
|
|
89
|
+
is_authenticated = True
|
|
90
|
+
|
|
91
|
+
# Bad
|
|
92
|
+
userCount = 10
|
|
93
|
+
tp = 99.99
|
|
94
|
+
x = True
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
## Constants
|
|
98
|
+
|
|
99
|
+
- Use UPPERCASE with underscores
|
|
100
|
+
- Define at module level
|
|
101
|
+
|
|
102
|
+
```python
|
|
103
|
+
# Good
|
|
104
|
+
MAX_CONNECTIONS = 100
|
|
105
|
+
DEFAULT_TIMEOUT = 30
|
|
106
|
+
API_BASE_URL = "https://api.example.com"
|
|
107
|
+
|
|
108
|
+
# Bad
|
|
109
|
+
maxConnections = 100
|
|
110
|
+
default_timeout = 30
|
|
111
|
+
apiBaseUrl = "https://api.example.com"
|
|
112
|
+
```
|
|
113
|
+
|
|
114
|
+
## Private Members
|
|
115
|
+
|
|
116
|
+
- Use single leading underscore for internal use
|
|
117
|
+
- Use double leading underscore for name mangling (rare)
|
|
118
|
+
|
|
119
|
+
```python
|
|
120
|
+
class MyClass:
|
|
121
|
+
def __init__(self):
|
|
122
|
+
self._internal_value = 0 # Internal use
|
|
123
|
+
self.__private_value = 0 # Name mangling (rare)
|
|
124
|
+
|
|
125
|
+
def _internal_method(self):
|
|
126
|
+
"""Internal method, not part of public API"""
|
|
127
|
+
pass
|
|
128
|
+
|
|
129
|
+
def public_method(self):
|
|
130
|
+
"""Public API method"""
|
|
131
|
+
pass
|
|
132
|
+
```
|
|
133
|
+
|
|
134
|
+
## Special Methods
|
|
135
|
+
|
|
136
|
+
- Use double underscores on both sides (dunder methods)
|
|
137
|
+
- Only for Python special methods
|
|
138
|
+
|
|
139
|
+
```python
|
|
140
|
+
class MyClass:
|
|
141
|
+
def __init__(self):
|
|
142
|
+
pass
|
|
143
|
+
|
|
144
|
+
def __str__(self):
|
|
145
|
+
return "MyClass instance"
|
|
146
|
+
|
|
147
|
+
def __repr__(self):
|
|
148
|
+
return "MyClass()"
|
|
149
|
+
```
|
|
150
|
+
|
|
151
|
+
## Type Variable Names
|
|
152
|
+
|
|
153
|
+
- Use CapWords for type variables
|
|
154
|
+
- Use descriptive names or single capital letters
|
|
155
|
+
|
|
156
|
+
```python
|
|
157
|
+
from typing import TypeVar
|
|
158
|
+
|
|
159
|
+
T = TypeVar('T')
|
|
160
|
+
UserType = TypeVar('UserType')
|
|
161
|
+
KeyType = TypeVar('KeyType')
|
|
162
|
+
ValueType = TypeVar('ValueType')
|
|
163
|
+
```
|
|
164
|
+
|
|
165
|
+
## Best Practices
|
|
166
|
+
|
|
167
|
+
1. **Consistency**: Follow the same naming pattern throughout the codebase
|
|
168
|
+
2. **Clarity**: Prefer clarity over brevity
|
|
169
|
+
3. **Context**: Use context to avoid redundant names
|
|
170
|
+
4. **Avoid**: Hungarian notation, type prefixes
|
|
171
|
+
5. **Use**: Meaningful names that convey intent
|
|
172
|
+
|
|
@@ -0,0 +1,188 @@
|
|
|
1
|
+
# Python Type Hints
|
|
2
|
+
|
|
3
|
+
Use type hints extensively for better code quality and IDE support.
|
|
4
|
+
|
|
5
|
+
## Basic Type Hints
|
|
6
|
+
|
|
7
|
+
```python
|
|
8
|
+
from typing import List, Dict, Set, Tuple, Optional, Union
|
|
9
|
+
|
|
10
|
+
# Function parameters and return types
|
|
11
|
+
def greet(name: str) -> str:
|
|
12
|
+
return f"Hello, {name}"
|
|
13
|
+
|
|
14
|
+
def add_numbers(a: int, b: int) -> int:
|
|
15
|
+
return a + b
|
|
16
|
+
|
|
17
|
+
def get_user_age(user_id: int) -> Optional[int]:
|
|
18
|
+
"""Returns age or None if user not found"""
|
|
19
|
+
pass
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
## Collection Types
|
|
23
|
+
|
|
24
|
+
```python
|
|
25
|
+
from typing import List, Dict, Set, Tuple
|
|
26
|
+
|
|
27
|
+
# Lists
|
|
28
|
+
def process_items(items: List[str]) -> List[int]:
|
|
29
|
+
return [len(item) for item in items]
|
|
30
|
+
|
|
31
|
+
# Dictionaries
|
|
32
|
+
def get_user_data() -> Dict[str, str]:
|
|
33
|
+
return {"name": "John", "email": "john@example.com"}
|
|
34
|
+
|
|
35
|
+
# Sets
|
|
36
|
+
def get_unique_ids() -> Set[int]:
|
|
37
|
+
return {1, 2, 3, 4, 5}
|
|
38
|
+
|
|
39
|
+
# Tuples
|
|
40
|
+
def get_coordinates() -> Tuple[float, float]:
|
|
41
|
+
return (10.5, 20.3)
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
## Optional and Union Types
|
|
45
|
+
|
|
46
|
+
```python
|
|
47
|
+
from typing import Optional, Union
|
|
48
|
+
|
|
49
|
+
# Optional (value or None)
|
|
50
|
+
def find_user(user_id: int) -> Optional[User]:
|
|
51
|
+
"""Returns User or None if not found"""
|
|
52
|
+
pass
|
|
53
|
+
|
|
54
|
+
# Union (multiple possible types)
|
|
55
|
+
def process_value(value: Union[int, str]) -> str:
|
|
56
|
+
return str(value)
|
|
57
|
+
|
|
58
|
+
# Multiple optional parameters
|
|
59
|
+
def create_user(
|
|
60
|
+
name: str,
|
|
61
|
+
email: str,
|
|
62
|
+
age: Optional[int] = None,
|
|
63
|
+
phone: Optional[str] = None
|
|
64
|
+
) -> User:
|
|
65
|
+
pass
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
## Generic Types
|
|
69
|
+
|
|
70
|
+
```python
|
|
71
|
+
from typing import TypeVar, Generic, List
|
|
72
|
+
|
|
73
|
+
T = TypeVar('T')
|
|
74
|
+
|
|
75
|
+
class Stack(Generic[T]):
|
|
76
|
+
def __init__(self) -> None:
|
|
77
|
+
self._items: List[T] = []
|
|
78
|
+
|
|
79
|
+
def push(self, item: T) -> None:
|
|
80
|
+
self._items.append(item)
|
|
81
|
+
|
|
82
|
+
def pop(self) -> T:
|
|
83
|
+
return self._items.pop()
|
|
84
|
+
|
|
85
|
+
# Usage
|
|
86
|
+
int_stack: Stack[int] = Stack()
|
|
87
|
+
str_stack: Stack[str] = Stack()
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
## Callable Types
|
|
91
|
+
|
|
92
|
+
```python
|
|
93
|
+
from typing import Callable
|
|
94
|
+
|
|
95
|
+
# Function that takes a callback
|
|
96
|
+
def process_data(
|
|
97
|
+
data: List[int],
|
|
98
|
+
callback: Callable[[int], str]
|
|
99
|
+
) -> List[str]:
|
|
100
|
+
return [callback(item) for item in data]
|
|
101
|
+
|
|
102
|
+
# Function that returns a function
|
|
103
|
+
def create_multiplier(factor: int) -> Callable[[int], int]:
|
|
104
|
+
def multiply(x: int) -> int:
|
|
105
|
+
return x * factor
|
|
106
|
+
return multiply
|
|
107
|
+
```
|
|
108
|
+
|
|
109
|
+
## Class Type Hints
|
|
110
|
+
|
|
111
|
+
```python
|
|
112
|
+
from typing import ClassVar, List
|
|
113
|
+
from dataclasses import dataclass
|
|
114
|
+
|
|
115
|
+
class User:
|
|
116
|
+
# Class variable
|
|
117
|
+
user_count: ClassVar[int] = 0
|
|
118
|
+
|
|
119
|
+
def __init__(self, name: str, age: int) -> None:
|
|
120
|
+
self.name: str = name
|
|
121
|
+
self.age: int = age
|
|
122
|
+
User.user_count += 1
|
|
123
|
+
|
|
124
|
+
def get_info(self) -> Dict[str, Union[str, int]]:
|
|
125
|
+
return {"name": self.name, "age": self.age}
|
|
126
|
+
|
|
127
|
+
# Using dataclasses
|
|
128
|
+
@dataclass
|
|
129
|
+
class Product:
|
|
130
|
+
name: str
|
|
131
|
+
price: float
|
|
132
|
+
quantity: int = 0
|
|
133
|
+
```
|
|
134
|
+
|
|
135
|
+
## Protocol and Abstract Types
|
|
136
|
+
|
|
137
|
+
```python
|
|
138
|
+
from typing import Protocol
|
|
139
|
+
from abc import ABC, abstractmethod
|
|
140
|
+
|
|
141
|
+
# Protocol (structural subtyping)
|
|
142
|
+
class Drawable(Protocol):
|
|
143
|
+
def draw(self) -> None:
|
|
144
|
+
...
|
|
145
|
+
|
|
146
|
+
# Abstract base class
|
|
147
|
+
class Shape(ABC):
|
|
148
|
+
@abstractmethod
|
|
149
|
+
def area(self) -> float:
|
|
150
|
+
pass
|
|
151
|
+
|
|
152
|
+
@abstractmethod
|
|
153
|
+
def perimeter(self) -> float:
|
|
154
|
+
pass
|
|
155
|
+
```
|
|
156
|
+
|
|
157
|
+
## Type Aliases
|
|
158
|
+
|
|
159
|
+
```python
|
|
160
|
+
from typing import List, Dict, Tuple
|
|
161
|
+
|
|
162
|
+
# Simple aliases
|
|
163
|
+
UserId = int
|
|
164
|
+
UserName = str
|
|
165
|
+
Coordinates = Tuple[float, float]
|
|
166
|
+
|
|
167
|
+
# Complex aliases
|
|
168
|
+
UserData = Dict[str, Union[str, int, List[str]]]
|
|
169
|
+
Matrix = List[List[float]]
|
|
170
|
+
|
|
171
|
+
def get_user(user_id: UserId) -> UserName:
|
|
172
|
+
pass
|
|
173
|
+
|
|
174
|
+
def process_matrix(matrix: Matrix) -> Matrix:
|
|
175
|
+
pass
|
|
176
|
+
```
|
|
177
|
+
|
|
178
|
+
## Best Practices
|
|
179
|
+
|
|
180
|
+
1. **Always use type hints** for function parameters and return values
|
|
181
|
+
2. **Use Optional** instead of Union[X, None]
|
|
182
|
+
3. **Use specific types** instead of Any when possible
|
|
183
|
+
4. **Use TypeVar** for generic functions and classes
|
|
184
|
+
5. **Use Protocol** for duck typing
|
|
185
|
+
6. **Run mypy** or pyright for type checking
|
|
186
|
+
7. **Use dataclasses** for simple data containers
|
|
187
|
+
8. **Document complex types** with comments
|
|
188
|
+
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
# React Patterns
|
|
2
|
+
|
|
3
|
+
Modern React patterns and best practices for building scalable applications.
|
|
4
|
+
|
|
5
|
+
## Overview
|
|
6
|
+
|
|
7
|
+
This module provides comprehensive guidelines for React development including component patterns, hooks usage, state management, and TypeScript integration.
|
|
8
|
+
|
|
9
|
+
## Key Benefits
|
|
10
|
+
|
|
11
|
+
- **Modern Patterns**: React 18+ features and patterns
|
|
12
|
+
- **Type Safety**: TypeScript integration best practices
|
|
13
|
+
- **Performance**: Optimization techniques and patterns
|
|
14
|
+
- **Maintainability**: Clean, testable component architecture
|
|
15
|
+
|
|
16
|
+
## Installation
|
|
17
|
+
|
|
18
|
+
```bash
|
|
19
|
+
augx link coding-standards/react
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
## Contents
|
|
23
|
+
|
|
24
|
+
### Rules
|
|
25
|
+
|
|
26
|
+
- **component-patterns.md** - Component design patterns
|
|
27
|
+
- **hooks-best-practices.md** - React Hooks usage
|
|
28
|
+
- **state-management.md** - State management patterns
|
|
29
|
+
- **typescript-react.md** - TypeScript with React
|
|
30
|
+
- **performance.md** - Performance optimization
|
|
31
|
+
|
|
32
|
+
### Examples
|
|
33
|
+
|
|
34
|
+
- **component-examples.md** - Component pattern examples
|
|
35
|
+
- **hooks-examples.md** - Custom hooks examples
|
|
36
|
+
- **state-examples.md** - State management examples
|
|
37
|
+
|
|
38
|
+
## Character Count
|
|
39
|
+
|
|
40
|
+
~32,000 characters
|
|
41
|
+
|
|
42
|
+
## Version
|
|
43
|
+
|
|
44
|
+
1.0.0
|
|
45
|
+
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "react-patterns",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"displayName": "React Patterns",
|
|
5
|
+
"description": "Modern React patterns including component design, hooks, and state management best practices",
|
|
6
|
+
"type": "coding-standards",
|
|
7
|
+
"author": "Augment Extensions",
|
|
8
|
+
"license": "MIT",
|
|
9
|
+
"augment": {
|
|
10
|
+
"characterCount": 32000,
|
|
11
|
+
"priority": "medium",
|
|
12
|
+
"category": "coding-standards"
|
|
13
|
+
},
|
|
14
|
+
"installation": {
|
|
15
|
+
"required": false,
|
|
16
|
+
"dependencies": []
|
|
17
|
+
},
|
|
18
|
+
"tags": [
|
|
19
|
+
"react",
|
|
20
|
+
"hooks",
|
|
21
|
+
"components",
|
|
22
|
+
"state-management",
|
|
23
|
+
"typescript",
|
|
24
|
+
"best-practices"
|
|
25
|
+
]
|
|
26
|
+
}
|
|
27
|
+
|