@sun-asterisk/sunlint 1.1.7 β 1.2.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.
- package/.sunlint.json +1 -1
- package/CHANGELOG.md +83 -0
- package/README.md +66 -4
- package/config/presets/all.json +125 -0
- package/config/presets/beginner.json +16 -8
- package/config/presets/ci.json +12 -4
- package/config/presets/maintainability.json +38 -0
- package/config/presets/performance.json +32 -0
- package/config/presets/quality.json +103 -0
- package/config/presets/recommended.json +36 -12
- package/config/presets/security.json +88 -0
- package/config/presets/strict.json +15 -5
- package/config/rules/rules-registry-generated.json +6312 -0
- package/config/rules-summary.json +1941 -0
- package/core/adapters/sunlint-rule-adapter.js +452 -0
- package/core/analysis-orchestrator.js +4 -4
- package/core/config-manager.js +28 -5
- package/core/rule-selection-service.js +52 -55
- package/docs/CONFIGURATION.md +111 -3
- package/docs/LANGUAGE-SPECIFIC-RULES.md +308 -0
- package/docs/README.md +3 -0
- package/docs/STANDARDIZED-CATEGORY-FILTERING.md +156 -0
- package/engines/eslint-engine.js +92 -2
- package/engines/heuristic-engine.js +8 -31
- package/origin-rules/common-en.md +1320 -0
- package/origin-rules/dart-en.md +289 -0
- package/origin-rules/java-en.md +60 -0
- package/origin-rules/kotlin-mobile-en.md +453 -0
- package/origin-rules/reactjs-en.md +102 -0
- package/origin-rules/security-en.md +1055 -0
- package/origin-rules/swift-en.md +449 -0
- package/origin-rules/typescript-en.md +136 -0
- package/package.json +6 -5
- package/scripts/copy-rules.js +86 -0
- package/rules/README.md +0 -252
- package/rules/common/C002_no_duplicate_code/analyzer.js +0 -65
- package/rules/common/C002_no_duplicate_code/config.json +0 -23
- package/rules/common/C003_no_vague_abbreviations/analyzer.js +0 -418
- package/rules/common/C003_no_vague_abbreviations/config.json +0 -35
- package/rules/common/C006_function_naming/analyzer.js +0 -349
- package/rules/common/C006_function_naming/config.json +0 -86
- package/rules/common/C010_limit_block_nesting/analyzer.js +0 -389
- package/rules/common/C013_no_dead_code/analyzer.js +0 -206
- package/rules/common/C014_dependency_injection/analyzer.js +0 -338
- package/rules/common/C017_constructor_logic/analyzer.js +0 -314
- package/rules/common/C019_log_level_usage/analyzer.js +0 -362
- package/rules/common/C019_log_level_usage/config.json +0 -121
- package/rules/common/C029_catch_block_logging/analyzer.js +0 -373
- package/rules/common/C029_catch_block_logging/config.json +0 -59
- package/rules/common/C031_validation_separation/analyzer.js +0 -186
- package/rules/common/C041_no_sensitive_hardcode/analyzer.js +0 -292
- package/rules/common/C042_boolean_name_prefix/analyzer.js +0 -300
- package/rules/common/C043_no_console_or_print/analyzer.js +0 -304
- package/rules/common/C047_no_duplicate_retry_logic/analyzer.js +0 -351
- package/rules/common/C075_explicit_return_types/analyzer.js +0 -103
- package/rules/common/C076_single_test_behavior/analyzer.js +0 -121
- package/rules/docs/C002_no_duplicate_code.md +0 -57
- package/rules/docs/C031_validation_separation.md +0 -72
- package/rules/index.js +0 -149
- package/rules/migration/converter.js +0 -385
- package/rules/migration/mapping.json +0 -164
- package/rules/security/S026_json_schema_validation/analyzer.js +0 -251
- package/rules/security/S026_json_schema_validation/config.json +0 -27
- package/rules/security/S027_no_hardcoded_secrets/analyzer.js +0 -263
- package/rules/security/S027_no_hardcoded_secrets/config.json +0 -29
- package/rules/security/S029_csrf_protection/analyzer.js +0 -264
- package/rules/tests/C002_no_duplicate_code.test.js +0 -50
- package/rules/universal/C010/generic.js +0 -0
- package/rules/universal/C010/tree-sitter-analyzer.js +0 -0
- package/rules/utils/ast-utils.js +0 -191
- package/rules/utils/base-analyzer.js +0 -98
- package/rules/utils/pattern-matchers.js +0 -239
- package/rules/utils/rule-helpers.js +0 -264
- package/rules/utils/severity-constants.js +0 -93
|
@@ -0,0 +1,1320 @@
|
|
|
1
|
+
# π Code Quality Common Rules
|
|
2
|
+
|
|
3
|
+
> Below is a list of Common Rules, established based on core Principles. Each rule includes a description and recommended tools for enforcement.
|
|
4
|
+
|
|
5
|
+
### π Rule C001 β Functions should not exceed 50 lines
|
|
6
|
+
|
|
7
|
+
- **Objective**: Improve readability and maintainability, reduce cognitive load, and enhance testability.
|
|
8
|
+
- **Details**:
|
|
9
|
+
- Warn if the function exceeds 30 lines; error if over 50 lines.
|
|
10
|
+
- Encourage breaking functions into smaller ones with meaningful names.
|
|
11
|
+
- Short functions are easier to understand, test, and debug.
|
|
12
|
+
- Adheres to the Single Responsibility Principle.
|
|
13
|
+
- Helps reduce cyclomatic complexity.
|
|
14
|
+
- **Applies to**: All languages
|
|
15
|
+
- **Tools**: SonarQube, detekt, ESLint, PMD
|
|
16
|
+
- **Principles**: CODE_QUALITY
|
|
17
|
+
- **Version**:
|
|
18
|
+
- **Status**: draft
|
|
19
|
+
|
|
20
|
+
### π Rule C002 β Avoid code duplication > 10 lines
|
|
21
|
+
|
|
22
|
+
- **Objective**: Prevent messy code, make refactoring easier, and apply the DRY principle.
|
|
23
|
+
- **Details**:
|
|
24
|
+
- Warn when duplicate code β₯ 10 lines across functions/classes
|
|
25
|
+
- Extract common logic into functions or utilities
|
|
26
|
+
- Use inheritance or composition when appropriate
|
|
27
|
+
- Create shared libraries for reusable logic
|
|
28
|
+
- **Applies to**: All languages
|
|
29
|
+
- **Tools**: PMD, SonarQube, jscpd
|
|
30
|
+
- **Principles**: CODE_QUALITY
|
|
31
|
+
- **Version**:
|
|
32
|
+
- **Status**: draft
|
|
33
|
+
|
|
34
|
+
### π Rule C003 β Use clear variable names; avoid arbitrary abbreviations
|
|
35
|
+
|
|
36
|
+
- **Objective**: Improve readability, searchability, and enable self-documenting code.
|
|
37
|
+
- **Details**:
|
|
38
|
+
- Avoid uncommon abbreviations (except i, j in loops)
|
|
39
|
+
- Avoid single-character variables unless used as counters
|
|
40
|
+
- Use descriptive names that clearly indicate purpose
|
|
41
|
+
- Variable names should express *what*, not *how*
|
|
42
|
+
- **Applies to**: All languages
|
|
43
|
+
- **Tools**: ESLint (custom rule), detekt
|
|
44
|
+
- **Principles**: CODE_QUALITY
|
|
45
|
+
- **Version**: 1.0
|
|
46
|
+
- **Status**: activated
|
|
47
|
+
|
|
48
|
+
### π Rule C004 β No TODOs older than 14 days
|
|
49
|
+
|
|
50
|
+
- **Objective**: Keep the codebase clean and updated, avoid accumulating technical debt.
|
|
51
|
+
- **Details**:
|
|
52
|
+
- Warn if a TODO comment is older than 14 days
|
|
53
|
+
- Enforce a standard format with assignee and deadline
|
|
54
|
+
- Use issue tracking for large tasks instead of TODO comments
|
|
55
|
+
- Regularly clean up outdated TODOs
|
|
56
|
+
- **Applies to**: All languages
|
|
57
|
+
- **Tools**: Custom Git hook, linter TODO scanner
|
|
58
|
+
- **Principles**: CODE_QUALITY
|
|
59
|
+
- **Version**:
|
|
60
|
+
- **Status**: draft
|
|
61
|
+
|
|
62
|
+
### π Rule C005 β Each function should do only one thing
|
|
63
|
+
|
|
64
|
+
- **Objective**: Ensure single responsibility, better testability and readability.
|
|
65
|
+
- **Details**:
|
|
66
|
+
- Validate via review + cyclomatic complexity < 10
|
|
67
|
+
- Function names should clearly reflect a single purpose
|
|
68
|
+
- Break down large functions into smaller ones
|
|
69
|
+
- A function should have only one reason to change
|
|
70
|
+
- **Applies to**: All languages
|
|
71
|
+
- **Tools**: SonarQube, CodeClimate
|
|
72
|
+
- **Principles**: CODE_QUALITY
|
|
73
|
+
- **Version**:
|
|
74
|
+
- **Status**: draft
|
|
75
|
+
|
|
76
|
+
### π Rule C006 β Function names must be verbs or verb-noun combinations
|
|
77
|
+
|
|
78
|
+
- **Objective**: Clearly express the purpose of the action and promote self-documenting code.
|
|
79
|
+
- **Details**:
|
|
80
|
+
- Avoid vague names like `doSomething()`
|
|
81
|
+
- Use verbs that describe specific actions
|
|
82
|
+
- Boolean functions should start with is/has/can/should
|
|
83
|
+
- Avoid generic names that lack context
|
|
84
|
+
- **Applies to**: All languages
|
|
85
|
+
- **Tools**: PR review, AI Suggestion (Copilot Review)
|
|
86
|
+
- **Principles**: CODE_QUALITY
|
|
87
|
+
- **Version**: 1.0
|
|
88
|
+
- **Status**: activated
|
|
89
|
+
|
|
90
|
+
### π Rule C007 β Avoid comments that just restate the code
|
|
91
|
+
|
|
92
|
+
- **Objective**: Eliminate redundancy and encourage self-explanatory code.
|
|
93
|
+
- **Details**:
|
|
94
|
+
- Warn if a comment duplicates the logic of the line below
|
|
95
|
+
- Comments should explain **why**, not **what**
|
|
96
|
+
- Good code should be self-documenting
|
|
97
|
+
- Reserve comments for complex business logic, not syntax
|
|
98
|
+
- **Applies to**: All languages
|
|
99
|
+
- **Tools**: AI review, Lint static analyzer
|
|
100
|
+
- **Principles**: CODE_QUALITY
|
|
101
|
+
- **Version**:
|
|
102
|
+
- **Status**: draft
|
|
103
|
+
|
|
104
|
+
### π Rule C008 β Declare variables close to where they are used
|
|
105
|
+
|
|
106
|
+
- **Objective**: Improve locality, avoid "dangling" variables, and reduce cognitive load.
|
|
107
|
+
- **Details**:
|
|
108
|
+
- Warn if a variable is declared far from where it is used
|
|
109
|
+
- Declare variables right before use
|
|
110
|
+
- Use block scope to limit lifetime
|
|
111
|
+
- Minimize the variable scope as much as possible
|
|
112
|
+
- **Applies to**: All languages
|
|
113
|
+
- **Tools**: Linter (e.g., ktlint, ESLint)
|
|
114
|
+
- **Principles**: CODE_QUALITY
|
|
115
|
+
- **Version**:
|
|
116
|
+
- **Status**: draft
|
|
117
|
+
|
|
118
|
+
### π Rule C009 β Each class should have a single responsibility
|
|
119
|
+
|
|
120
|
+
- **Objective**: Improve maintainability and scalability, avoid bloated classes.
|
|
121
|
+
- **Details**:
|
|
122
|
+
- Warn if a class exceeds 300 lines or has more than 10 methods
|
|
123
|
+
- Apply the Single Responsibility Principle
|
|
124
|
+
- Break large classes into smaller, more focused ones
|
|
125
|
+
- Each class should have only one reason to change
|
|
126
|
+
- **Applies to**: All languages
|
|
127
|
+
- **Tools**: SonarQube, CodeClimate
|
|
128
|
+
- **Principles**: CODE_QUALITY, DESIGN_PATTERNS
|
|
129
|
+
- **Version**:
|
|
130
|
+
- **Status**: draft
|
|
131
|
+
|
|
132
|
+
### π Rule C010 β Avoid more than 3 levels of nested blocks
|
|
133
|
+
|
|
134
|
+
- **Objective**: Reduce code complexity by limiting nesting, improving readability and maintainability.
|
|
135
|
+
- **Details**:
|
|
136
|
+
- Warn when nesting exceeds 3 levels for if/for/while/switch
|
|
137
|
+
- Deeply nested code is harder to read and understand
|
|
138
|
+
- Each nested level increases cognitive complexity
|
|
139
|
+
- Use early returns, guard clauses, or split into smaller functions
|
|
140
|
+
- Apply "flattening" to reduce nesting depth
|
|
141
|
+
- 3 nesting levels is the generally accepted maximum
|
|
142
|
+
- Excessive nesting increases the risk of bugs and makes testing harder
|
|
143
|
+
- **Applies to**: All languages
|
|
144
|
+
- **Tools**: ESLint, SonarQube, TSLint, Detekt, PMD
|
|
145
|
+
- **Principles**: CODE_QUALITY, DESIGN_PATTERNS
|
|
146
|
+
- **Version**:
|
|
147
|
+
- **Status**: draft
|
|
148
|
+
- **Severity**: major
|
|
149
|
+
|
|
150
|
+
### π Rule C011 β Avoid catching generic exceptions (e.g., `catch (Exception)`)
|
|
151
|
+
|
|
152
|
+
- **Objective**: Prevent hiding real issues and ensure specific and recoverable error handling.
|
|
153
|
+
- **Details**:
|
|
154
|
+
- Warn when catching generic exceptions without clearly logging the root cause
|
|
155
|
+
- Catch specific exceptions to handle each error type appropriately
|
|
156
|
+
- Avoid silent failures or overly generic error handling
|
|
157
|
+
- Log sufficient information for debugging and troubleshooting
|
|
158
|
+
- Only catch exceptions that the code is able to handle
|
|
159
|
+
- **Applies to**: All languages
|
|
160
|
+
- **Tools**: Static analysis, SonarQube
|
|
161
|
+
- **Principles**: CODE_QUALITY
|
|
162
|
+
- **Version**:
|
|
163
|
+
- **Status**: draft
|
|
164
|
+
|
|
165
|
+
### π Rule C012 β Clearly separate Command and Query
|
|
166
|
+
|
|
167
|
+
- **Objective**: Ensure single responsibility and clear side-effects following the Command Query Separation (CQS) principle.
|
|
168
|
+
- **Details**:
|
|
169
|
+
- A function should not both return data and modify state
|
|
170
|
+
- Command functions: change state, return void
|
|
171
|
+
- Query functions: return data, do not modify state
|
|
172
|
+
- Makes code easier to read, test, and avoids unintended side effects
|
|
173
|
+
- Increases the predictability of functions
|
|
174
|
+
- **Applies to**: All languages
|
|
175
|
+
- **Tools**: PR review, AI code review
|
|
176
|
+
- **Principles**: CODE_QUALITY
|
|
177
|
+
- **Version**:
|
|
178
|
+
- **Status**: draft
|
|
179
|
+
|
|
180
|
+
### π Rule C013 β Do not use dead code
|
|
181
|
+
|
|
182
|
+
- **Objective**: Keep the codebase clean; rely on Git history instead of commenting out code.
|
|
183
|
+
- **Details**:
|
|
184
|
+
- Warn when code is commented out instead of deleted
|
|
185
|
+
- Remove unused functions, variables, and imports
|
|
186
|
+
- Don't keep code "just in case" β Git tracks history
|
|
187
|
+
- Dead code clutters the codebase and hurts maintainability
|
|
188
|
+
- Increases bundle size unnecessarily
|
|
189
|
+
- **Applies to**: All languages
|
|
190
|
+
- **Tools**: Linter + Git hook
|
|
191
|
+
- **Principles**: CODE_QUALITY
|
|
192
|
+
- **Version**: 1.0
|
|
193
|
+
- **Status**: activated
|
|
194
|
+
|
|
195
|
+
### π Rule C014 β Use Dependency Injection instead of directly instantiating dependencies
|
|
196
|
+
|
|
197
|
+
- **Objective**: Improve testability and decoupling by applying the Dependency Inversion Principle.
|
|
198
|
+
- **Details**:
|
|
199
|
+
- Warn if a class/service directly instantiates a dependency inside the constructor
|
|
200
|
+
- Inject dependencies via constructor, setter, or method parameters
|
|
201
|
+
- Makes mocking easier in unit tests
|
|
202
|
+
- Reduces coupling between modules
|
|
203
|
+
- Allows changing implementations without affecting client code
|
|
204
|
+
- **Applies to**: All languages
|
|
205
|
+
- **Tools**: Static analyzer, PR review
|
|
206
|
+
- **Principles**: CODE_QUALITY
|
|
207
|
+
- **Version**: 1.0
|
|
208
|
+
- **Status**: activated
|
|
209
|
+
|
|
210
|
+
### π Rule C015 β Use domain language in class/function names
|
|
211
|
+
|
|
212
|
+
- **Objective**: Ensure correct domain understanding, reduce cognitive load, and improve communication with domain experts.
|
|
213
|
+
- **Details**:
|
|
214
|
+
- Ensure function/class names map to business terminology
|
|
215
|
+
- Use terms that business stakeholders can understand
|
|
216
|
+
- Avoid technical jargon when business terms are available
|
|
217
|
+
- Code should read like business requirements
|
|
218
|
+
- Enables shared understanding between developers and business users
|
|
219
|
+
- **Applies to**: All languages
|
|
220
|
+
- **Tools**: Review + AI Suggestion
|
|
221
|
+
- **Principles**: CODE_QUALITY
|
|
222
|
+
- **Version**:
|
|
223
|
+
- **Status**: draft
|
|
224
|
+
|
|
225
|
+
### π Rule C016 β TODOs must have a specific reason
|
|
226
|
+
|
|
227
|
+
- **Objective**: Avoid vague TODOs and ensure traceability and accountability.
|
|
228
|
+
- **Details**:
|
|
229
|
+
- Enforce format: `// TODO(username): specific reason`
|
|
230
|
+
- Must include assignee and clear description
|
|
231
|
+
- Should include deadline or issue reference
|
|
232
|
+
- TODOs should not exist for more than 30 days
|
|
233
|
+
- Use `FIXME` for bugs, `TODO` for planned features
|
|
234
|
+
- **Applies to**: All languages
|
|
235
|
+
- **Tools**: Regex + Linter rule
|
|
236
|
+
- **Principles**: CODE_QUALITY
|
|
237
|
+
- **Version**:
|
|
238
|
+
- **Status**: draft
|
|
239
|
+
|
|
240
|
+
### π Rule C017 β Do not put business logic inside constructors
|
|
241
|
+
|
|
242
|
+
- **Objective**: Ensure constructors only initialize objects, not perform business logic, to improve testability.
|
|
243
|
+
- **Details**:
|
|
244
|
+
- Warn if constructors call APIs, perform logic, or log data
|
|
245
|
+
- Constructors should only assign dependencies and initialize fields
|
|
246
|
+
- Avoid side effects in constructors
|
|
247
|
+
- Business logic should be placed in separate methods
|
|
248
|
+
- Keeps object creation fast and predictable
|
|
249
|
+
- **Applies to**: All languages
|
|
250
|
+
- **Tools**: Static analyzer / Manual review
|
|
251
|
+
- **Principles**: CODE_QUALITY, TESTABILITY, RELIABILITY, INTEGRATION
|
|
252
|
+
- **Version**: 1.0
|
|
253
|
+
- **Status**: activated
|
|
254
|
+
|
|
255
|
+
### π Rule C018 β Do not throw generic errors; always provide detailed messages
|
|
256
|
+
|
|
257
|
+
- **Objective**: Facilitate debugging, ensure traceability, and provide full context.
|
|
258
|
+
- **Details**:
|
|
259
|
+
- Always include meaningful messages in exceptions; avoid `throw new RuntimeException()` without context
|
|
260
|
+
- Error messages should explain what happened, why, and in what context
|
|
261
|
+
- Include relevant data in error messages
|
|
262
|
+
- Use custom exception classes for business errors
|
|
263
|
+
- Error messages should guide developers on how to fix the issue
|
|
264
|
+
- **Applies to**: All languages
|
|
265
|
+
- **Tools**: Linter + Manual review
|
|
266
|
+
- **Principles**: CODE_QUALITY
|
|
267
|
+
- **Version**: 1.0
|
|
268
|
+
- **Status**: activated
|
|
269
|
+
|
|
270
|
+
### π Rule C019 β Do not use `error` log level for non-critical issues
|
|
271
|
+
|
|
272
|
+
- **Objective**: Avoid noisy logs and false alarms; ensure meaningful log levels.
|
|
273
|
+
- **Details**:
|
|
274
|
+
- Use `info` or `warn` for recoverable or normal issues
|
|
275
|
+
- Reserve `error` for critical failures that require immediate attention
|
|
276
|
+
- Use `warn` for potential issues that don't crash the system
|
|
277
|
+
- Use `info` for normal business flow events
|
|
278
|
+
- Use `debug` for detailed information when troubleshooting
|
|
279
|
+
- **Applies to**: All languages
|
|
280
|
+
- **Tools**: Log linter / Custom rule
|
|
281
|
+
- **Principles**: CODE_QUALITY
|
|
282
|
+
- **Version**: 1.0
|
|
283
|
+
- **Status**: activated
|
|
284
|
+
|
|
285
|
+
### π Rule C020 β Do not import unused modules or libraries
|
|
286
|
+
|
|
287
|
+
- **Objective**: Reduce noise, improve build performance and code readability, and minimize bundle size.
|
|
288
|
+
- **Details**:
|
|
289
|
+
- Use linters to automatically detect unused imports
|
|
290
|
+
- Remove leftover imports after refactoring
|
|
291
|
+
- Automatically clean up unused imports via CI/CD
|
|
292
|
+
- Reduces bundle size and compile time
|
|
293
|
+
- Prevents unnecessary dependency conflicts
|
|
294
|
+
- Helps detect logic bugs (e.g., declared but unused variables)
|
|
295
|
+
- **Applies to**: All languages
|
|
296
|
+
- **Tools**: Linter (e.g., ESLint, ktlint)
|
|
297
|
+
- **Principles**: CODE_QUALITY
|
|
298
|
+
- **Version**:
|
|
299
|
+
- **Status**: draft
|
|
300
|
+
|
|
301
|
+
### π Rule C021 β Consistently order import statements
|
|
302
|
+
|
|
303
|
+
- **Objective**: Improve consistency, readability, and manageability of imports; reduce merge conflicts.
|
|
304
|
+
- **Details**:
|
|
305
|
+
- Group imports in order: system libraries β third-party libraries β internal project modules
|
|
306
|
+
- Within each group, sort alphabetically
|
|
307
|
+
- Add a blank line between import groups for clarity
|
|
308
|
+
- Avoid wildcard imports (`import *`) unless necessary
|
|
309
|
+
- Helps reduce merge conflicts and improves code review experience
|
|
310
|
+
- Speeds up dependency lookup
|
|
311
|
+
- **Applies to**: All languages
|
|
312
|
+
- **Tools**: Import sorter (e.g., ESLint sort-imports, IntelliJ organize imports, ktlint)
|
|
313
|
+
- **Principles**: CODE_QUALITY
|
|
314
|
+
- **Version**:
|
|
315
|
+
- **Status**: draft
|
|
316
|
+
|
|
317
|
+
### π Rule C022 β Do not leave unused variables
|
|
318
|
+
|
|
319
|
+
- **Objective**: Eliminate clutter, improve code clarity, and reduce memory footprint.
|
|
320
|
+
- **Details**:
|
|
321
|
+
- Automatically remove unused variables using lint tools or IDE plugins
|
|
322
|
+
- Reduce cognitive load when reading code
|
|
323
|
+
- Prevent confusion over variable purpose
|
|
324
|
+
- Reduce bundle size in JavaScript/TypeScript
|
|
325
|
+
- Allow compilers to optimize more effectively
|
|
326
|
+
- Help detect early logic bugs (variables created but never used)
|
|
327
|
+
- **Applies to**: All languages
|
|
328
|
+
- **Tools**: Linter / Compiler warning
|
|
329
|
+
- **Principles**: CODE_QUALITY
|
|
330
|
+
- **Version**:
|
|
331
|
+
- **Status**: draft
|
|
332
|
+
|
|
333
|
+
### π Rule C023 β Do not declare duplicate variable names in the same scope, including nested closures
|
|
334
|
+
|
|
335
|
+
- **Objective**: Avoid confusion and hard-to-trace bugs; prevent variable shadowing.
|
|
336
|
+
- **Details**:
|
|
337
|
+
- Do not redeclare a variable already defined in the same scope or within a nested callback
|
|
338
|
+
- Avoid variable shadowing which obscures which variable is actually in use
|
|
339
|
+
- Especially dangerous in closures and nested functions
|
|
340
|
+
- Enables IDEs and tools to analyze code more accurately
|
|
341
|
+
- Prevents hard-to-debug runtime errors
|
|
342
|
+
- Improves code clarity
|
|
343
|
+
- **Applies to**: All languages
|
|
344
|
+
- **Tools**: Compiler / Linter
|
|
345
|
+
- **Principles**: CODE_QUALITY
|
|
346
|
+
- **Version**: 1.0
|
|
347
|
+
- **Status**: activated
|
|
348
|
+
|
|
349
|
+
### π Rule C024 β Do not scatter hardcoded constants throughout the logic
|
|
350
|
+
|
|
351
|
+
- **Objective**: Improve reusability, readability, and ease of configuration changes.
|
|
352
|
+
- **Details**:
|
|
353
|
+
- Extract constants to a separate file or to the top of the class/module
|
|
354
|
+
- Avoid magic numbers and magic strings in logic
|
|
355
|
+
- Centralize constants for easier maintenance
|
|
356
|
+
- Give constants meaningful, descriptive names
|
|
357
|
+
- Makes changing values easier without searching the entire codebase
|
|
358
|
+
- Improves consistency when the same value is used across multiple places
|
|
359
|
+
- **Applies to**: All languages
|
|
360
|
+
- **Tools**: Linter / Convention
|
|
361
|
+
- **Principles**: CODE_QUALITY, MAINTAINABILITY
|
|
362
|
+
- **Version**: 1.0
|
|
363
|
+
- **Status**: activated
|
|
364
|
+
|
|
365
|
+
### π Rule C025 β Each file should contain only one main class
|
|
366
|
+
|
|
367
|
+
- **Objective**: Reduce cognitive load when reading code; improve searchability and maintainability.
|
|
368
|
+
- **Details**:
|
|
369
|
+
- Avoid putting multiple business logic classes in the same file
|
|
370
|
+
- Allow nested classes or supporting DTOs that are directly related
|
|
371
|
+
- File name should match the primary class name
|
|
372
|
+
- Improves IDE navigation and search
|
|
373
|
+
- Reduces merge conflicts in collaborative development
|
|
374
|
+
- Makes refactoring and code movement easier
|
|
375
|
+
- Increases cohesion of the module
|
|
376
|
+
- **Applies to**: All languages
|
|
377
|
+
- **Tools**: Convention / Linter warning
|
|
378
|
+
- **Principles**: CODE_QUALITY
|
|
379
|
+
- **Version**:
|
|
380
|
+
- **Status**: draft
|
|
381
|
+
|
|
382
|
+
### π Rule C026 β Avoid functions with too many parameters (>6)
|
|
383
|
+
|
|
384
|
+
- **Objective**: Simplify functions, reduce confusion when calling, and minimize coupling.
|
|
385
|
+
- **Details**:
|
|
386
|
+
- If a function has more than 6 parameters, consider converting to an object, DTO, or splitting into smaller functions
|
|
387
|
+
- Too many parameters make functions harder to use and more error-prone
|
|
388
|
+
- Hard to remember parameter order when calling the function
|
|
389
|
+
- Increases likelihood of passing incorrect arguments
|
|
390
|
+
- Use object parameters to group related data
|
|
391
|
+
- Consider builder pattern for complex object creation
|
|
392
|
+
- **Applies to**: All languages
|
|
393
|
+
- **Tools**: SonarQube, Static Analyzer
|
|
394
|
+
- **Principles**: CODE_QUALITY
|
|
395
|
+
- **Version**:
|
|
396
|
+
- **Status**: draft
|
|
397
|
+
|
|
398
|
+
### π Rule C027 β Each module should have a README.md if it is independent
|
|
399
|
+
|
|
400
|
+
- **Objective**: Improve onboarding, maintenance, and knowledge sharing.
|
|
401
|
+
- **Details**:
|
|
402
|
+
- README.md should describe purpose, usage, and main structure of the module
|
|
403
|
+
- Helps new developers quickly understand the module
|
|
404
|
+
- Document APIs, dependencies, and setup requirements
|
|
405
|
+
- Include examples and common use cases
|
|
406
|
+
- Reduces onboarding time for new team members
|
|
407
|
+
- Acts as a single source of truth for module documentation
|
|
408
|
+
- **Applies to**: All languages
|
|
409
|
+
- **Tools**: CI check / Manual review
|
|
410
|
+
- **Principles**: CODE_QUALITY
|
|
411
|
+
- **Version**:
|
|
412
|
+
- **Status**: draft
|
|
413
|
+
|
|
414
|
+
### π Rule C028 β Use guard clauses instead of nested ifs
|
|
415
|
+
|
|
416
|
+
- **Objective**: Improve readability and avoid deep nesting, reducing cognitive complexity.
|
|
417
|
+
- **Details**:
|
|
418
|
+
- Use early returns instead of deeply nested `if` blocks
|
|
419
|
+
- Guard clauses check for invalid conditions first and exit early
|
|
420
|
+
- Reduces nesting levels and improves code readability
|
|
421
|
+
- Keeps the happy path (main logic) at the end of the function, not nested
|
|
422
|
+
- Reduces cognitive load while reading code
|
|
423
|
+
- Makes it easier to add new validations without bloating the structure
|
|
424
|
+
- **Applies to**: All languages
|
|
425
|
+
- **Tools**: PR review, linter
|
|
426
|
+
- **Principles**: CODE_QUALITY
|
|
427
|
+
- **Version**:
|
|
428
|
+
- **Status**: draft
|
|
429
|
+
|
|
430
|
+
### π Rule C029 β All `catch` blocks must log the root cause of the error
|
|
431
|
+
|
|
432
|
+
- **Objective**: Improve traceability and incident resolution; avoid silent failures.
|
|
433
|
+
- **Details**:
|
|
434
|
+
- Always log message and stack trace in `catch`; avoid empty `catch(e) {}`
|
|
435
|
+
- Logs should include context information to assist debugging
|
|
436
|
+
- Never ignore errors silently without action
|
|
437
|
+
- Use appropriate log levels (error, warn, info)
|
|
438
|
+
- Include relevant data like user ID, request ID, input parameters
|
|
439
|
+
- Helps monitoring and alerting systems operate effectively
|
|
440
|
+
- **Applies to**: All languages
|
|
441
|
+
- **Tools**: Static analyzer / PR review
|
|
442
|
+
- **Principles**: CODE_QUALITY
|
|
443
|
+
- **Version**: 1.0
|
|
444
|
+
- **Status**: activated
|
|
445
|
+
|
|
446
|
+
### π Rule C030 β Use custom error classes instead of generic system errors
|
|
447
|
+
|
|
448
|
+
- **Objective**: Improve error classification and handling; increase maintainability.
|
|
449
|
+
- **Details**:
|
|
450
|
+
- Create custom `Error` subclasses with specific codes and messages instead of using `throw new Error()`
|
|
451
|
+
- Custom errors help callers handle different error types appropriately
|
|
452
|
+
- Include error codes, HTTP status codes, and metadata
|
|
453
|
+
- Make it easier to categorize and handle errors in centralized error handlers
|
|
454
|
+
- Ensure consistent error handling throughout the application
|
|
455
|
+
- Enables accurate classification in monitoring and alerting systems
|
|
456
|
+
- **Applies to**: All languages
|
|
457
|
+
- **Tools**: Linter / Convention
|
|
458
|
+
- **Principles**: CODE_QUALITY
|
|
459
|
+
- **Version**: 1.0
|
|
460
|
+
- **Status**: activated
|
|
461
|
+
|
|
462
|
+
### π Rule C031 β Validation logic must be separated
|
|
463
|
+
|
|
464
|
+
- **Objective**:
|
|
465
|
+
- Clearly separate validation logic from business logic
|
|
466
|
+
- Enable easy unit testing of validation rules
|
|
467
|
+
- Improve reusability of validation logic
|
|
468
|
+
- Reduce complexity in controllers and use cases
|
|
469
|
+
- Simplify maintenance and extension of validation rules
|
|
470
|
+
|
|
471
|
+
- **Details**:
|
|
472
|
+
- Validation should be placed in separate services or middleware
|
|
473
|
+
- Avoid placing validation logic in controllers or core use cases
|
|
474
|
+
- You can use validation frameworks or create your own validation service
|
|
475
|
+
- Validation services should return clear success/error results with detailed messages
|
|
476
|
+
- Support both field-level and object-level validation
|
|
477
|
+
- Define validation rules declaratively and make them readable
|
|
478
|
+
|
|
479
|
+
- **Applies to**: All languages
|
|
480
|
+
- **Tools**: Convention, PR review
|
|
481
|
+
- **Principles**: CODE_QUALITY, TESTABILITY, MAINTAINABILITY
|
|
482
|
+
- **Version**: 1.0
|
|
483
|
+
- **Status**: activated
|
|
484
|
+
|
|
485
|
+
### π Rule C032 β Do not call external APIs in constructors or static blocks
|
|
486
|
+
|
|
487
|
+
- **Objective**:
|
|
488
|
+
- Avoid unexpected code execution during module loading
|
|
489
|
+
- Prevent unwanted side effects during initialization
|
|
490
|
+
- Increase application predictability
|
|
491
|
+
- Simplify testing and mocking dependencies
|
|
492
|
+
|
|
493
|
+
- **Details**:
|
|
494
|
+
- Do not call external APIs (HTTP, database, file system) inside constructors or static blocks
|
|
495
|
+
- Warn when `fetch`, `axios`, or similar calls are used in constructors or static blocks
|
|
496
|
+
- Move complex initialization logic outside constructors
|
|
497
|
+
- Use factory pattern or async initialization pattern if necessary
|
|
498
|
+
|
|
499
|
+
- **Applies to**: All languages
|
|
500
|
+
- **Tools**: Static analyzer
|
|
501
|
+
- **Principles**: CODE_QUALITY
|
|
502
|
+
- **Version**:
|
|
503
|
+
- **Status**: draft
|
|
504
|
+
|
|
505
|
+
### π Rule C033 β Separate processing logic and data access in the service layer
|
|
506
|
+
|
|
507
|
+
- **Objective**:
|
|
508
|
+
- Improve reusability and testability
|
|
509
|
+
- Clearly separate business logic from data access logic
|
|
510
|
+
- Make it easier to change data access implementations
|
|
511
|
+
- Improve maintainability of the code
|
|
512
|
+
- Follow the Single Responsibility Principle
|
|
513
|
+
|
|
514
|
+
- **Details**:
|
|
515
|
+
- Business logic should not contain query statements; separate Repository and Service
|
|
516
|
+
- Repositories should only contain basic data access methods (CRUD)
|
|
517
|
+
- Services should contain business logic and use Repositories for queries
|
|
518
|
+
- Each Service should correspond to a Repository
|
|
519
|
+
- Do not place business logic inside Repositories
|
|
520
|
+
- Use dependency injection to inject Repositories into Services
|
|
521
|
+
|
|
522
|
+
- **Applies to**: All languages
|
|
523
|
+
- **Tools**: Architectural review
|
|
524
|
+
- **Principles**: CODE_QUALITY
|
|
525
|
+
- **Version**: 1.0
|
|
526
|
+
- **Status**: activated
|
|
527
|
+
|
|
528
|
+
### π Rule C034 β Avoid directly accessing global state in domain logic
|
|
529
|
+
|
|
530
|
+
- **Objective**:
|
|
531
|
+
- Reduce reliance on global state
|
|
532
|
+
- Improve testability of the code
|
|
533
|
+
- Allow easier replacement of dependencies
|
|
534
|
+
- Avoid unwanted side effects
|
|
535
|
+
- Follow the Dependency Inversion Principle
|
|
536
|
+
|
|
537
|
+
- **Details**:
|
|
538
|
+
- Do not directly access global variables, singletons, or static methods in business logic
|
|
539
|
+
- Use dependency injection to pass in required dependencies
|
|
540
|
+
- Define dependencies clearly through interfaces
|
|
541
|
+
- Avoid using static methods for business logic
|
|
542
|
+
- Separate configuration from business logic
|
|
543
|
+
|
|
544
|
+
- **Applies to**: All languages
|
|
545
|
+
- **Tools**: Static analyzer, Code review
|
|
546
|
+
- **Principles**: CODE_QUALITY, DESIGN_PATTERNS
|
|
547
|
+
- **Version**:
|
|
548
|
+
- **Status**: draft
|
|
549
|
+
|
|
550
|
+
### π Rule C035 β Log all relevant context when handling errors
|
|
551
|
+
|
|
552
|
+
- **Objective**:
|
|
553
|
+
- Simplify debugging and troubleshooting
|
|
554
|
+
- Provide full context for error analysis
|
|
555
|
+
- Improve system observability and monitoring
|
|
556
|
+
- Speed up error detection and resolution
|
|
557
|
+
- Follow the principle of observability
|
|
558
|
+
|
|
559
|
+
- **Details**:
|
|
560
|
+
- Log error message, stack trace, and error code
|
|
561
|
+
- Include error context: request ID, user ID, input data
|
|
562
|
+
- Classify log level appropriately (ERROR, WARN, INFO)
|
|
563
|
+
- Log both at the throw and catch locations
|
|
564
|
+
- Do not log sensitive data (e.g., passwords, tokens)
|
|
565
|
+
- Use structured logging format
|
|
566
|
+
|
|
567
|
+
- **Applies to**: All languages
|
|
568
|
+
- **Tools**: Logging framework
|
|
569
|
+
- **Principles**: CODE_QUALITY
|
|
570
|
+
- **Version**: 1.0
|
|
571
|
+
- **Status**: activated
|
|
572
|
+
|
|
573
|
+
### π Rule C036 β Do not throw generic exceptions like `RuntimeException` or `Exception`
|
|
574
|
+
|
|
575
|
+
- **Objective**:
|
|
576
|
+
- Improve clarity and specificity of error handling
|
|
577
|
+
- Make it easier to classify and handle errors
|
|
578
|
+
- Provide detailed information about the root cause
|
|
579
|
+
- Enhance maintainability and debugging
|
|
580
|
+
- Follow the principles of fail-fast and explicit failure
|
|
581
|
+
|
|
582
|
+
- **Details**:
|
|
583
|
+
- Avoid using generic exceptions like `Exception`, `RuntimeException`, `Error`
|
|
584
|
+
- Create custom exception classes for specific error types
|
|
585
|
+
- Include useful information in exceptions (error code, context)
|
|
586
|
+
- Name exceptions clearly to reflect the error meaning
|
|
587
|
+
- Inherit from the appropriate base exception class for the language
|
|
588
|
+
|
|
589
|
+
- **Applies to**: All languages
|
|
590
|
+
- **Tools**: Static analyzer
|
|
591
|
+
- **Principles**: CODE_QUALITY
|
|
592
|
+
- **Version**:
|
|
593
|
+
- **Status**: draft
|
|
594
|
+
|
|
595
|
+
### π Rule C037 β API handler functions should return a standardized response object (not raw strings)
|
|
596
|
+
|
|
597
|
+
- **Objective**:
|
|
598
|
+
- Ensure consistency in API responses
|
|
599
|
+
- Simplify response handling on the client side
|
|
600
|
+
- Support API versioning and extensibility
|
|
601
|
+
- Improve maintainability and debugging
|
|
602
|
+
- Follow REST API best practices
|
|
603
|
+
|
|
604
|
+
- **Details**:
|
|
605
|
+
- Use a standard response object with fixed fields
|
|
606
|
+
- Include necessary metadata (status, message, timestamp)
|
|
607
|
+
- Separate data from metadata clearly
|
|
608
|
+
- Use appropriate HTTP status codes
|
|
609
|
+
- Support pagination if needed
|
|
610
|
+
- Handle error responses in a consistent way
|
|
611
|
+
|
|
612
|
+
- **Applies to**: All languages
|
|
613
|
+
- **Tools**: API documentation tools
|
|
614
|
+
- **Principles**: CODE_QUALITY
|
|
615
|
+
- **Version**:
|
|
616
|
+
- **Status**: draft
|
|
617
|
+
|
|
618
|
+
### π Rule C038 β Avoid logic that depends on file/module load order
|
|
619
|
+
|
|
620
|
+
- **Objective**:
|
|
621
|
+
- Increase code independence and reusability
|
|
622
|
+
- Reduce implicit dependencies between modules
|
|
623
|
+
- Make code easier to test and maintain
|
|
624
|
+
- Prevent hard-to-debug execution order issues
|
|
625
|
+
- Follow the principle of loose coupling
|
|
626
|
+
|
|
627
|
+
- **Details**:
|
|
628
|
+
- Do not rely on the order of module imports/requires
|
|
629
|
+
- Avoid using global state to pass data between modules
|
|
630
|
+
- Use dependency injection instead of direct imports
|
|
631
|
+
- Avoid executing complex logic during module import
|
|
632
|
+
- Clearly separate module definition and initialization
|
|
633
|
+
- Use factory pattern or lazy loading if necessary
|
|
634
|
+
|
|
635
|
+
- **Applies to**: All languages
|
|
636
|
+
- **Tools**: Architectural Review
|
|
637
|
+
- **Principles**: CODE_QUALITY
|
|
638
|
+
- **Version**:
|
|
639
|
+
- **Status**: draft
|
|
640
|
+
|
|
641
|
+
### π Rule C039 β Do not store temporary data in global or static mutable fields
|
|
642
|
+
|
|
643
|
+
- **Objective**:
|
|
644
|
+
Prevent issues related to shared state and race conditions in concurrent environments. Ensure thread-safety and testability. Using global or static mutable fields can introduce hard-to-detect and hard-to-fix bugs.
|
|
645
|
+
- **Details**:
|
|
646
|
+
- Use context-passing in functions instead of relying on global state
|
|
647
|
+
- Ensure thread-safety using appropriate synchronization mechanisms
|
|
648
|
+
- Prefer dependency injection to manage state and dependencies
|
|
649
|
+
- Avoid mutable static fields in classes
|
|
650
|
+
- Use local or instance variables instead of global/static ones
|
|
651
|
+
- **Applies to**: All languages
|
|
652
|
+
- **Tools**: Static Analyzer
|
|
653
|
+
- **Principles**: CODE_QUALITY
|
|
654
|
+
- **Version**:
|
|
655
|
+
- **Status**: draft
|
|
656
|
+
|
|
657
|
+
### π Rule C040 β Do not spread validation logic across multiple classes
|
|
658
|
+
|
|
659
|
+
- **Objective**:
|
|
660
|
+
Centralize validation logic to simplify maintenance, increase reusability, and ensure consistency. Centralized validation helps reduce bugs and simplifies updating validation rules.
|
|
661
|
+
- **Details**:
|
|
662
|
+
- Place validation logic in a dedicated validator or shared service
|
|
663
|
+
- Avoid duplicating the same validation condition in multiple places
|
|
664
|
+
- Use available validation frameworks where possible
|
|
665
|
+
- Clearly separate validation logic from business logic
|
|
666
|
+
- Ensure validation rules are well-documented
|
|
667
|
+
|
|
668
|
+
- **Applies to**: All languages
|
|
669
|
+
- **Tools**: Architectural Refactor Review
|
|
670
|
+
- **Principles**: CODE_QUALITY
|
|
671
|
+
- **Version**: 1.0
|
|
672
|
+
- **Status**: activated
|
|
673
|
+
|
|
674
|
+
### π Rule C041 β Do not hardcode or push sensitive information (token, API key, secret, URL) into the repo
|
|
675
|
+
|
|
676
|
+
- **Objective**: Protect sensitive application data, avoid security risks, and comply with security standards. Exposing sensitive information can lead to serious security and privacy issues.
|
|
677
|
+
|
|
678
|
+
- **Details**
|
|
679
|
+
- Use environment variables or separate config files to store secrets
|
|
680
|
+
- Add secret files to `.gitignore` to prevent committing them
|
|
681
|
+
- Use secret management tools such as Vault or AWS Secrets Manager
|
|
682
|
+
- Encrypt sensitive information when necessary
|
|
683
|
+
- Use different environment variables for different environments (dev, staging, prod)
|
|
684
|
+
|
|
685
|
+
- **Applies to**: All languages
|
|
686
|
+
- **Tools**: Git Hooks, Secret Scanner
|
|
687
|
+
- **Principles**: SECURITY
|
|
688
|
+
- **Version**: 1.0
|
|
689
|
+
- **Status**: activated
|
|
690
|
+
|
|
691
|
+
### π Rule C042 β Boolean variable names should start with `is`, `has`, or `should`
|
|
692
|
+
|
|
693
|
+
- **Objective**: Ensure clarity and readability by making boolean variables self-explanatory. This naming convention improves code maintainability and documentation.
|
|
694
|
+
|
|
695
|
+
- **Details**
|
|
696
|
+
- Use `is` for state attributes (e.g., `isActive`, `isEnabled`)
|
|
697
|
+
- Use `has` for ownership (e.g., `hasPermission`, `hasChildren`)
|
|
698
|
+
- Use `should` for decision flags (e.g., `shouldUpdate`, `shouldRetry`)
|
|
699
|
+
- Avoid inconsistent prefixes like `can`, `will`, or `does`
|
|
700
|
+
- Ensure the variable name accurately represents its boolean meaning
|
|
701
|
+
|
|
702
|
+
- **Applies to**: All languages
|
|
703
|
+
- **Tools**: Linter (ESLint, SonarQube)
|
|
704
|
+
- **Principles**: CODE_QUALITY
|
|
705
|
+
- **Version**: 1.0
|
|
706
|
+
- **Status**: activated
|
|
707
|
+
|
|
708
|
+
### π Rule C043 β Do not use `print` or `console.log` in production code
|
|
709
|
+
|
|
710
|
+
- **Objective**: Ensure logging is done in a controlled and effective manner in production. Using `print` or `console.log` can lead to performance issues, security risks, and log management difficulties.
|
|
711
|
+
|
|
712
|
+
- **Details**
|
|
713
|
+
- Use a dedicated logging framework instead of `print` or `console.log`
|
|
714
|
+
- Set appropriate log levels for each environment (debug, info, warn, error)
|
|
715
|
+
- Ensure logs contain useful metadata like timestamp, level, and context
|
|
716
|
+
- Avoid logging sensitive data like passwords, tokens, or personal information
|
|
717
|
+
- Use structured logging for easier analysis and search
|
|
718
|
+
|
|
719
|
+
- **Applies to**: All languages
|
|
720
|
+
- **Tools**: Linter, Log Analyzer
|
|
721
|
+
- **Principles**: CODE_QUALITY, PERFORMANCE
|
|
722
|
+
- **Version**: 1.0
|
|
723
|
+
- **Status**: activated
|
|
724
|
+
|
|
725
|
+
### π Rule C044 β Avoid reimplementing functions that already exist in standard libraries or helper utilities
|
|
726
|
+
|
|
727
|
+
- **Objective**: Leverage well-tested, optimized, and community-maintained libraries to reduce bugs and improve development efficiency.
|
|
728
|
+
|
|
729
|
+
- **Details**
|
|
730
|
+
- Prefer using standard language libraries
|
|
731
|
+
- Use trusted and popular community libraries
|
|
732
|
+
- Evaluate library compatibility and performance
|
|
733
|
+
- Ensure the library is actively maintained
|
|
734
|
+
- Only implement custom logic when necessary and justified
|
|
735
|
+
|
|
736
|
+
- **Applies to**: All languages
|
|
737
|
+
- **Tools**: Package Manager, Dependency Analyzer
|
|
738
|
+
- **Principles**: CODE_QUALITY, PERFORMANCE
|
|
739
|
+
- **Version**:
|
|
740
|
+
- **Status**: draft
|
|
741
|
+
|
|
742
|
+
### π Rule C045 β APIs should not return 500 errors for known business errors
|
|
743
|
+
|
|
744
|
+
- **Objective**: Ensure APIs return appropriate HTTP status codes so clients can handle errors effectively. HTTP 500 should be reserved for unexpected system errors.
|
|
745
|
+
|
|
746
|
+
- **Details**
|
|
747
|
+
- Use specific HTTP status codes based on error type:
|
|
748
|
+
- 400 for validation errors
|
|
749
|
+
- 401 for authentication failures
|
|
750
|
+
- 403 for authorization failures
|
|
751
|
+
- 404 for resource not found
|
|
752
|
+
- 409 for data conflict
|
|
753
|
+
- 422 for business logic errors
|
|
754
|
+
- 500 only for unexpected internal server errors
|
|
755
|
+
|
|
756
|
+
- **Applies to**: All languages
|
|
757
|
+
- **Tools**: API Testing, Error Monitoring
|
|
758
|
+
- **Principles**: CODE_QUALITY
|
|
759
|
+
- **Version**:
|
|
760
|
+
- **Status**: draft
|
|
761
|
+
|
|
762
|
+
### π Rule C046 β Avoid complex and lengthy regular expressions in core logic
|
|
763
|
+
|
|
764
|
+
- **Objective**: Keep code readable, maintainable, and efficient by avoiding the use of overly complex regular expressions in business-critical logic.
|
|
765
|
+
|
|
766
|
+
- **Details**
|
|
767
|
+
- Move complex regex into constants or helper functions
|
|
768
|
+
- Prefer string manipulation libraries over complex regex
|
|
769
|
+
- Break down complex regex into simpler processing steps
|
|
770
|
+
- Add comments for regex that must be used and are hard to read
|
|
771
|
+
- Use dedicated parsers for complex parsing needs
|
|
772
|
+
- Avoid using regex to parse structured data formats
|
|
773
|
+
|
|
774
|
+
- **Applies to**: All languages
|
|
775
|
+
- **Tools**: Code Review, Static Code Analyzer
|
|
776
|
+
- **Principles**: CODE_QUALITY, PERFORMANCE
|
|
777
|
+
- **Version**:
|
|
778
|
+
- **Status**: draft
|
|
779
|
+
|
|
780
|
+
### π Rule C047 β Retry logic must not be duplicated in multiple places
|
|
781
|
+
|
|
782
|
+
- **Objective**: Centralize retry logic to improve consistency, maintainability, and observability of error handling and retry mechanisms.
|
|
783
|
+
|
|
784
|
+
- **Details**
|
|
785
|
+
- Create a dedicated utility class or service for retry logic
|
|
786
|
+
- Centralize retry policy configuration (retry count, delay, backoff)
|
|
787
|
+
- Use decorator pattern or AOP to apply retry logic
|
|
788
|
+
- Support different retry strategies (immediate, exponential backoff)
|
|
789
|
+
- Allow customizing retry conditions per use case
|
|
790
|
+
- Log all retry attempts with sufficient context
|
|
791
|
+
|
|
792
|
+
- **Applies to**: All languages
|
|
793
|
+
- **Tools**: Code Review, Static Code Analyzer
|
|
794
|
+
- **Principles**: CODE_QUALITY
|
|
795
|
+
- **Version**: 1.0
|
|
796
|
+
- **Status**: activated
|
|
797
|
+
|
|
798
|
+
### π Rule C048 β Do not bypass architectural layers (controller/service/repository)
|
|
799
|
+
|
|
800
|
+
- **Objective**: Maintain a clear layered architecture, ensuring logic and data flow are well-structured and maintainable.
|
|
801
|
+
|
|
802
|
+
- **Details**
|
|
803
|
+
- Controllers should only call Services, not Repositories directly
|
|
804
|
+
- Services should only call Repositories, not Controllers
|
|
805
|
+
- Repositories should only handle data access, not call Services
|
|
806
|
+
- Each layer should only know the layer directly below it
|
|
807
|
+
- Use dependency injection to manage dependencies
|
|
808
|
+
- Define clear interfaces for each layer
|
|
809
|
+
- Avoid circular dependencies between layers
|
|
810
|
+
|
|
811
|
+
- **Applies to**: All languages
|
|
812
|
+
- **Tools**: Static Analyzer, Architectural boundary checker
|
|
813
|
+
- **Principles**: DESIGN_PATTERNS, MAINTAINABILITY
|
|
814
|
+
- **Version**: 1.0
|
|
815
|
+
- **Status**: activated
|
|
816
|
+
|
|
817
|
+
### π Rule C049 β Always include a clear default case in switch/case statements
|
|
818
|
+
|
|
819
|
+
- **Objective**: Avoid missing logic for unexpected values, increasing stability and safety of the application.
|
|
820
|
+
|
|
821
|
+
- **Details**:
|
|
822
|
+
- Every `switch/case` should include a `default` or `else` branch for unknown values
|
|
823
|
+
- Without a default, the system may silently skip or crash on unexpected input
|
|
824
|
+
- The default case should log the issue or throw an appropriate error
|
|
825
|
+
- Applies to `enum`, `status`, `type`, `command`, especially when handling external/user input
|
|
826
|
+
|
|
827
|
+
- **Applies to**: All languages
|
|
828
|
+
- **Tools**: Linter
|
|
829
|
+
- **Principles**: CODE_QUALITY
|
|
830
|
+
- **Version**:
|
|
831
|
+
- **Status**: draft
|
|
832
|
+
- **Severity**: major
|
|
833
|
+
|
|
834
|
+
### π Rule C050 β Do not call APIs in loops without batching or throttling
|
|
835
|
+
|
|
836
|
+
- **Objective**: Prevent system overload, resource contention, API rate limit violations, or the backend being perceived as under attack (DDoS).
|
|
837
|
+
|
|
838
|
+
- **Details**:
|
|
839
|
+
- Do not call APIs inside loops without concurrency control (`throttle`), grouping (`batching`), or async pooling (`async pool`, `concurrent queue`)
|
|
840
|
+
- When calling multiple APIs, use libraries to manage concurrency and retries
|
|
841
|
+
- Respect API rate limits using client-side throttling mechanisms
|
|
842
|
+
- Prefer using `bulk API` endpoints when available for list-based operations
|
|
843
|
+
|
|
844
|
+
- **Applies to**: All languages
|
|
845
|
+
- **Tools**: Performance review
|
|
846
|
+
- **Principles**: CODE_QUALITY, PERFORMANCE
|
|
847
|
+
- **Version**:
|
|
848
|
+
- **Status**: draft
|
|
849
|
+
- **Severity**: major
|
|
850
|
+
|
|
851
|
+
### π Rule C051 β Do not use `sleep`, `wait`, or `delay` in business logic
|
|
852
|
+
|
|
853
|
+
- **Objective**: Avoid uncontrolled delays that cause asynchronous issues, make debugging and testing harder, and increase the risk of race conditions in production environments.
|
|
854
|
+
|
|
855
|
+
- **Details**:
|
|
856
|
+
- Do not use `sleep`, `wait`, `delay`, `Thread.sleep`, `setTimeout`, `delay()`, etc., directly inside business logic (services, use cases, repositories)
|
|
857
|
+
- Manual delays block threads and increase latency unnecessarily, reducing system throughput
|
|
858
|
+
- Use a proper retry strategy with timeout, backoff, and limit (applied in orchestrators, schedulers, or middleware) instead
|
|
859
|
+
- Do not use arbitrary delay values unless required for security purposes (e.g., brute-force mitigation)
|
|
860
|
+
- Delay is acceptable in tests, demos, or orchestration logic β not core business logic
|
|
861
|
+
|
|
862
|
+
- **Applies to**: All languages
|
|
863
|
+
- **Tools**: Static analyzer, manual review
|
|
864
|
+
- **Principles**: CODE_QUALITY, PERFORMANCE
|
|
865
|
+
- **Version**:
|
|
866
|
+
- **Status**: draft
|
|
867
|
+
- **Severity**: major
|
|
868
|
+
|
|
869
|
+
### π Rule C052 β Parsing or data transformation logic must be separated from controllers
|
|
870
|
+
|
|
871
|
+
- **Objective**: Enforce separation of concerns β controllers should only handle requests and delegate processing, improving testability, maintainability, and reuse.
|
|
872
|
+
|
|
873
|
+
- **Details**:
|
|
874
|
+
- Controllers should not perform heavy processing like JSON parsing, data transformation, or domain mapping
|
|
875
|
+
- Input/output conversions (DTO β domain) should be handled in mappers, transformers, or services
|
|
876
|
+
- This separation allows easy unit testing of controllers by mocking services and reducing duplication
|
|
877
|
+
- Avoid formatting date/time, numeric conversions, or mini business logic in controllers
|
|
878
|
+
|
|
879
|
+
- **Applies to**: All languages
|
|
880
|
+
- **Tools**: Code review / Architecture enforcement
|
|
881
|
+
- **Principles**: CODE_QUALITY, DESIGN_PATTERNS, MAINTAINABILITY
|
|
882
|
+
- **Version**: 1.0
|
|
883
|
+
- **Status**: activated
|
|
884
|
+
- **Severity**: major
|
|
885
|
+
|
|
886
|
+
### π Rule C053 β Avoid vague function names like "handle" or "process"
|
|
887
|
+
|
|
888
|
+
- **Objective**: Clarify function behavior, reduce hidden logic, and improve code readability and traceability.
|
|
889
|
+
|
|
890
|
+
- **Details**:
|
|
891
|
+
- Avoid vague names like `handleData()` or `processSomething()` that do not clearly convey intent
|
|
892
|
+
- Prefer descriptive names such as `calculateInvoice()`, `validateUser()`, `fetchProductList()`
|
|
893
|
+
- Clear function names help with debugging, logging, tracing, and onboarding
|
|
894
|
+
- If using `handle`, clarify the context: e.g., `handleUserLoginError()`; but consider `logLoginError()` or `redirectToLoginFailure()` instead
|
|
895
|
+
|
|
896
|
+
- **Applies to**: All languages
|
|
897
|
+
- **Tools**: AI reviewer / naming linter
|
|
898
|
+
- **Principles**: CODE_QUALITY
|
|
899
|
+
- **Version**:
|
|
900
|
+
- **Status**: draft
|
|
901
|
+
- **Severity**: minor
|
|
902
|
+
|
|
903
|
+
### π Rule C054 β Do not process large datasets without pagination or lazy loading
|
|
904
|
+
|
|
905
|
+
- **Objective**: Prevent loading all data into memory, avoid out-of-memory errors, and improve performance and response time.
|
|
906
|
+
|
|
907
|
+
- **Details**:
|
|
908
|
+
- Never use unrestricted queries like `SELECT *`, `findAll()`, or `getAll()` for large datasets
|
|
909
|
+
- APIs returning lists must support pagination: `limit/offset`, `cursor`, or `keyset pagination`
|
|
910
|
+
- Use lazy iterators, stream readers, or batch processing when working with large DB/file/stream data
|
|
911
|
+
- Avoid mapping large datasets into memory when only part of the data is needed
|
|
912
|
+
|
|
913
|
+
- **Applies to**: All languages
|
|
914
|
+
- **Tools**: Code review, ORM warning, API response profiler
|
|
915
|
+
- **Principles**: PERFORMANCE
|
|
916
|
+
- **Version**:
|
|
917
|
+
- **Status**: draft
|
|
918
|
+
- **Severity**: major
|
|
919
|
+
|
|
920
|
+
### π Rule C055 β Cache results of expensive functions if reused
|
|
921
|
+
|
|
922
|
+
- **Objective**: Reduce processing time and resource usage by caching results of resource-heavy operations.
|
|
923
|
+
|
|
924
|
+
- **Details**:
|
|
925
|
+
- If a function performs slow processing, external API calls, or heavy queries with stable results β use caching
|
|
926
|
+
- Caching options: in-memory (e.g., Map/LRU), function memoization, HTTP cache, Redis, service-level cache
|
|
927
|
+
- Ensure:
|
|
928
|
+
- TTL is defined
|
|
929
|
+
- Proper invalidation is implemented when data changes
|
|
930
|
+
- Caching does not break transactional integrity or cause stale data
|
|
931
|
+
- Only cache pure functions with predictable outputs based solely on input
|
|
932
|
+
|
|
933
|
+
- **Applies to**: All languages
|
|
934
|
+
- **Tools**: Code review, performance profiler
|
|
935
|
+
- **Principles**: CODE_QUALITY, PERFORMANCE
|
|
936
|
+
- **Version**:
|
|
937
|
+
- **Status**: draft
|
|
938
|
+
- **Severity**: major
|
|
939
|
+
|
|
940
|
+
### π Rule C056 β Do not process large datasets without logging or resource monitoring
|
|
941
|
+
|
|
942
|
+
- **Objective**: Track resource usage (CPU, RAM, I/O), detect anomalies early, and ensure system stability.
|
|
943
|
+
|
|
944
|
+
- **Details**:
|
|
945
|
+
- When processing large datasets (e.g., >10,000 records), log key metrics: record count, processing time, RAM usage, CPU peak
|
|
946
|
+
- For scheduled jobs (cron, batch, ETL), integrate with monitoring tools like Prometheus, CloudWatch, Grafana
|
|
947
|
+
- Define soft thresholds to log/warn when limits are exceeded (execution time, memory, volume)
|
|
948
|
+
- Logs should include: job ID, name, start/end time, input/output size, and context
|
|
949
|
+
|
|
950
|
+
- **Applies to**: All languages
|
|
951
|
+
- **Tools**: Logging, APM (Application Performance Monitoring)
|
|
952
|
+
- **Principles**: PERFORMANCE, RELIABILITY
|
|
953
|
+
- **Version**: 1.0
|
|
954
|
+
- **Status**: activated
|
|
955
|
+
- **Severity**: major
|
|
956
|
+
|
|
957
|
+
### π Rule C057 β Use optimal data structures instead of arrays for frequent lookups
|
|
958
|
+
|
|
959
|
+
- **Objective**: Reduce algorithm complexity, improve access speed, and optimize performance.
|
|
960
|
+
|
|
961
|
+
- **Details**:
|
|
962
|
+
- For repeated key-based lookups, avoid repeated `array.find()` or `array.filter()` β use `Map`, `Set`, `Dictionary`, `HashMap`, etc.
|
|
963
|
+
- Avoid redundant loops to search for the same value multiple times
|
|
964
|
+
- Convert lists to maps for constant-time key access
|
|
965
|
+
- Use `Set` instead of `Array` for membership checks (`includes`, `contains`)
|
|
966
|
+
- Choosing the wrong structure increases complexity from `O(1)` to `O(n)` or `O(n^2)`
|
|
967
|
+
|
|
968
|
+
- **Applies to**: All languages
|
|
969
|
+
- **Tools**: Static analyzer, AI reviewer
|
|
970
|
+
- **Principles**: PERFORMANCE
|
|
971
|
+
- **Version**:
|
|
972
|
+
- **Status**: draft
|
|
973
|
+
- **Severity**: major
|
|
974
|
+
|
|
975
|
+
### π Rule C058 β Enums must have clear display labels
|
|
976
|
+
|
|
977
|
+
- **Objective**: Ensure enums shown in logs, UIs, or APIs are understandable and user-friendly.
|
|
978
|
+
|
|
979
|
+
- **Details**:
|
|
980
|
+
- Avoid showing raw enum values like `STATUS_APPROVED` or `CODE_1` directly
|
|
981
|
+
- Enums should implement `getLabel()`, `getDescription()`, or override `toString()` for meaningful values
|
|
982
|
+
- In TypeScript (frontend), use a clear mapping from enum β label
|
|
983
|
+
- In Java/Go (backend), override `toString()` or include a description field and ensure proper serialization in JSON/logs
|
|
984
|
+
- UI enums must use domain-meaningful, human-readable labels: `DELIVERED` β "Delivered"
|
|
985
|
+
|
|
986
|
+
- **Applies to**: All languages
|
|
987
|
+
- **Tools**: Manual review
|
|
988
|
+
- **Principles**: CODE_QUALITY
|
|
989
|
+
- **Version**:
|
|
990
|
+
- **Status**: draft
|
|
991
|
+
- **Severity**: minor
|
|
992
|
+
|
|
993
|
+
### π Rule C059 β Do not create abstractions just to group constants
|
|
994
|
+
|
|
995
|
+
- **Objective**: Avoid unnecessary abstractions (class, enum) that add complexity without behavior or clear domain meaning.
|
|
996
|
+
|
|
997
|
+
- **Details**:
|
|
998
|
+
- Do not create `class`, `interface`, or `enum` just to group constants if they don't represent a meaningful domain concept
|
|
999
|
+
- If constants are internal to a module, keep them as module-level constants
|
|
1000
|
+
- Use `enum` only when values represent distinct domain concepts with potential behavior
|
|
1001
|
+
- Avoid generic names like `Constants`, `CommonKeys`, or `GlobalValues`, especially if disconnected from logic
|
|
1002
|
+
|
|
1003
|
+
- **Applies to**: All languages
|
|
1004
|
+
- **Tools**: Manual review
|
|
1005
|
+
- **Principles**: CODE_QUALITY, MAINTAINABILITY
|
|
1006
|
+
- **Version**:
|
|
1007
|
+
- **Status**: draft
|
|
1008
|
+
- **Severity**: minor
|
|
1009
|
+
|
|
1010
|
+
### π Rule C060 β Do not override superclass methods and ignore critical logic
|
|
1011
|
+
|
|
1012
|
+
- **Objective**: Preserve important behavior or lifecycle logic defined in the superclass to ensure correctness and prevent silent errors.
|
|
1013
|
+
|
|
1014
|
+
- **Details**:
|
|
1015
|
+
- When overriding a superclass method, be cautious if it contains:
|
|
1016
|
+
- Resource initialization
|
|
1017
|
+
- Precondition checks
|
|
1018
|
+
- Logging, auditing, statistics
|
|
1019
|
+
- Hooks or extension logic
|
|
1020
|
+
- If overriding without calling `super.method()` or equivalent logic, important behavior may be skipped
|
|
1021
|
+
- In lifecycle-based frameworks (Spring, React, Android, etc.), omitting `super` calls can break the system
|
|
1022
|
+
|
|
1023
|
+
- **Applies to**: All languages
|
|
1024
|
+
- **Tools**: Manual review
|
|
1025
|
+
- **Principles**: CODE_QUALITY
|
|
1026
|
+
- **Version**: 1.0
|
|
1027
|
+
- **Status**: activated
|
|
1028
|
+
- **Severity**: major
|
|
1029
|
+
|
|
1030
|
+
### π Rule C061 β Write unit tests for business logic
|
|
1031
|
+
|
|
1032
|
+
- **Objective**: Ensure that core business flows are verifiable, help catch bugs early, avoid regressions, and increase system reliability.
|
|
1033
|
+
|
|
1034
|
+
- **Details**:
|
|
1035
|
+
- Each business function (use case, service method, business rule) must have at least one unit test verifying correctness.
|
|
1036
|
+
- Cover both common scenarios and edge cases (null, empty, large values, exceptions, etc.)
|
|
1037
|
+
- Prioritize testing pure logic (not dependent on DB, network, or I/O)
|
|
1038
|
+
- Unit tests should be fast, independent, easy to read, and not require special setup
|
|
1039
|
+
- Follow the AAA (Arrange β Act β Assert) or Given β When β Then structure for clarity
|
|
1040
|
+
|
|
1041
|
+
- **Applies to**: All languages
|
|
1042
|
+
- **Tools**: Manual review
|
|
1043
|
+
- **Principles**: CODE_QUALITY, TESTABILITY, MAINTAINABILITY
|
|
1044
|
+
- **Version**: 1.0
|
|
1045
|
+
- **Status**: activated
|
|
1046
|
+
- **Severity**: major
|
|
1047
|
+
|
|
1048
|
+
### π Rule C062 β Interfaces or abstractions should not hold state
|
|
1049
|
+
|
|
1050
|
+
- **Objective**: Keep interfaces focused on defining behavior, making them easier to mock, implement, and test.
|
|
1051
|
+
|
|
1052
|
+
- **Details**:
|
|
1053
|
+
- Interfaces or abstract classes should define method signatures, not hold state (fields, properties, variables)
|
|
1054
|
+
- State should reside in the implementation layer, not in the interface
|
|
1055
|
+
- Avoid interfaces with default fields or abstract classes with complex logic and member variables unless using the Template Method pattern intentionally
|
|
1056
|
+
- Follow the Interface Segregation Principle β keep interfaces simple, clear, and side-effect free
|
|
1057
|
+
|
|
1058
|
+
- **Applies to**: All languages
|
|
1059
|
+
- **Tools**: Manual review
|
|
1060
|
+
- **Principles**: CODE_QUALITY, DESIGN_PATTERNS
|
|
1061
|
+
- **Version**:
|
|
1062
|
+
- **Status**: draft
|
|
1063
|
+
- **Severity**: major
|
|
1064
|
+
|
|
1065
|
+
### π Rule C063 β Do not repeat the same test logic
|
|
1066
|
+
|
|
1067
|
+
- **Objective**: Avoid duplication in tests, making them easier to maintain, read, and extend when business logic changes.
|
|
1068
|
+
|
|
1069
|
+
- **Details**:
|
|
1070
|
+
- Do not write multiple similar test cases that differ only in input/output
|
|
1071
|
+
- Instead, use table-driven tests, parameterized tests, or combine variations into one clear test case
|
|
1072
|
+
- Follow the DRY (Don't Repeat Yourself) principle in tests, not just production code
|
|
1073
|
+
- If identical test logic appears across files, extract it into helper functions or shared fixtures
|
|
1074
|
+
|
|
1075
|
+
- **Applies to**: All languages
|
|
1076
|
+
- **Tools**: Manual review
|
|
1077
|
+
- **Principles**: CODE_QUALITY, TESTABILITY, MAINTAINABILITY
|
|
1078
|
+
- **Version**:
|
|
1079
|
+
- **Status**: draft
|
|
1080
|
+
- **Severity**: minor
|
|
1081
|
+
|
|
1082
|
+
### π Rule C064 β Interfaces should expose only necessary behavior
|
|
1083
|
+
|
|
1084
|
+
- **Objective**: Prevent leaking implementation details, improve encapsulation, and reduce coupling between modules.
|
|
1085
|
+
|
|
1086
|
+
- **Details**:
|
|
1087
|
+
- Interfaces should only define methods needed by consumers
|
|
1088
|
+
- Do not expose internal or helper methods intended only for implementation
|
|
1089
|
+
- Fat interfaces make implementation harder, reduce mockability and testability, and introduce unnecessary coupling
|
|
1090
|
+
- Follow the Interface Segregation Principle β split interfaces by role so implementations aren't forced to support unrelated methods
|
|
1091
|
+
|
|
1092
|
+
- **Applies to**: All languages
|
|
1093
|
+
- **Tools**: Manual review
|
|
1094
|
+
- **Principles**: CODE_QUALITY, DESIGN_PATTERNS
|
|
1095
|
+
- **Version**:
|
|
1096
|
+
- **Status**: draft
|
|
1097
|
+
- **Severity**: major
|
|
1098
|
+
|
|
1099
|
+
### π Rule C065 β Each test case should verify only one behavior
|
|
1100
|
+
|
|
1101
|
+
- **Objective**: Make test failures easier to diagnose and ensure clarity and maintainability in test code.
|
|
1102
|
+
|
|
1103
|
+
- **Details**:
|
|
1104
|
+
- Each test should focus on one specific scenario or behavior
|
|
1105
|
+
- Do not include multiple logic branches in a single test β failures become harder to trace
|
|
1106
|
+
- Split logic with multiple conditions into separate test cases
|
|
1107
|
+
- Follow AAA (Arrange β Act β Assert), and avoid unrelated assertions in the same test
|
|
1108
|
+
|
|
1109
|
+
- **Applies to**: All languages
|
|
1110
|
+
- **Tools**: Manual review
|
|
1111
|
+
- **Principles**: CODE_QUALITY, TESTABILITY
|
|
1112
|
+
- **Version**: 1.0
|
|
1113
|
+
- **Status**: activated
|
|
1114
|
+
- **Severity**: major
|
|
1115
|
+
|
|
1116
|
+
### π Rule C066 β Test names should reflect what is being tested
|
|
1117
|
+
|
|
1118
|
+
- **Objective**: Help readers quickly understand the purpose of a test, making the test suite self-documenting and easier to trace on failure.
|
|
1119
|
+
|
|
1120
|
+
- **Details**:
|
|
1121
|
+
- Test function/method names should clearly state the input condition, behavior being tested, and expected result
|
|
1122
|
+
- Avoid vague names like `testSomething()`, `testLogic1()`, or `it should work`
|
|
1123
|
+
- Recommended formats:
|
|
1124
|
+
- `should_<expected_behavior>_when_<condition>`
|
|
1125
|
+
- `test_<action>_<expected_result>`
|
|
1126
|
+
- Clear naming eliminates the need to read test contents to understand its purpose
|
|
1127
|
+
|
|
1128
|
+
- **Applies to**: All languages
|
|
1129
|
+
- **Tools**: Manual review
|
|
1130
|
+
- **Principles**: CODE_QUALITY, TESTABILITY
|
|
1131
|
+
- **Version**:
|
|
1132
|
+
- **Status**: draft
|
|
1133
|
+
- **Severity**: minor
|
|
1134
|
+
|
|
1135
|
+
### π Rule C067 β Do not hardcode configuration inside code
|
|
1136
|
+
|
|
1137
|
+
- **Objective**: Improve configurability, reduce risk when changing environments, and make configuration management flexible and maintainable.
|
|
1138
|
+
|
|
1139
|
+
- **Details**:
|
|
1140
|
+
- Avoid hardcoding values such as:
|
|
1141
|
+
- API URLs, endpoints
|
|
1142
|
+
- Timeouts, retry intervals, batch sizes
|
|
1143
|
+
- Credentials (username, password, API key)
|
|
1144
|
+
- Feature flags, toggles, thresholds
|
|
1145
|
+
- Manage these values through:
|
|
1146
|
+
- Environment variables
|
|
1147
|
+
- Config files (`.env`, `config.yaml`, `application.properties`)
|
|
1148
|
+
- Constructor or DI-based injection
|
|
1149
|
+
- Centralized configuration simplifies environment-specific overrides and avoids sensitive info leaks
|
|
1150
|
+
- Keep all config in one central place (e.g., `config.ts`, `Config.java`, `config.go`, or `settings.py`), not scattered across services/modules
|
|
1151
|
+
|
|
1152
|
+
- **Applies to**: All languages
|
|
1153
|
+
- **Tools**: Manual review
|
|
1154
|
+
- **Principles**: CODE_QUALITY, MAINTAINABILITY
|
|
1155
|
+
- **Version**: 1.0
|
|
1156
|
+
- **Status**: activated
|
|
1157
|
+
- **Severity**: major
|
|
1158
|
+
|
|
1159
|
+
### π Rule C068 β Avoid unclear return types in functions
|
|
1160
|
+
|
|
1161
|
+
- **Objective**: Help callers know what data they receive, enable type checking, reduce hidden errors, and improve predictability.
|
|
1162
|
+
|
|
1163
|
+
- **Details**:
|
|
1164
|
+
- Avoid returning vague types like `any`, `Object`, `dynamic`, `Map<String, dynamic>`, or `interface{}` (in Go) without a clear schema
|
|
1165
|
+
- Define return types using interfaces/classes/structs or generics with explicit types
|
|
1166
|
+
- Unclear types make property access unsafe, introduce runtime bugs, reduce testability, and make APIs harder to use
|
|
1167
|
+
- In large or multi-team systems, strong typing is key to scaling and maintaining quality
|
|
1168
|
+
|
|
1169
|
+
- **Applies to**: All languages
|
|
1170
|
+
- **Tools**: Manual review
|
|
1171
|
+
- **Principles**: CODE_QUALITY
|
|
1172
|
+
- **Version**:
|
|
1173
|
+
- **Status**: draft
|
|
1174
|
+
- **Severity**: major
|
|
1175
|
+
|
|
1176
|
+
### π Rule C069 β Components should communicate via abstractions
|
|
1177
|
+
|
|
1178
|
+
- **Objective**: Reduce module coupling, improve testability, ease mocking, and ensure replaceability without affecting callers.
|
|
1179
|
+
|
|
1180
|
+
- **Details**:
|
|
1181
|
+
- Services, repositories, clients, and modules should communicate via interfaces, protocols, ports, or abstract classes β not direct implementation
|
|
1182
|
+
- Benefits of abstraction:
|
|
1183
|
+
- Easier to swap implementations (e.g., mock DB or fake API)
|
|
1184
|
+
- Enables testing without infrastructure (real DB/network)
|
|
1185
|
+
- Complies with the Dependency Inversion Principle in SOLID
|
|
1186
|
+
- Inject dependencies (via constructor or DI container), don't instantiate them directly
|
|
1187
|
+
|
|
1188
|
+
- **Applies to**: All languages
|
|
1189
|
+
- **Tools**: Manual review
|
|
1190
|
+
- **Principles**: CODE_QUALITY, DESIGN_PATTERNS, TESTABILITY
|
|
1191
|
+
- **Version**:
|
|
1192
|
+
- **Status**: draft
|
|
1193
|
+
- **Severity**: major
|
|
1194
|
+
|
|
1195
|
+
### π Rule C070 β Tests should not rely on real time
|
|
1196
|
+
|
|
1197
|
+
- **Objective**: Improve test stability and speed; avoid flaky tests caused by system clock or real-world timing.
|
|
1198
|
+
|
|
1199
|
+
- **Details**:
|
|
1200
|
+
- Avoid using `delay()`, `sleep()`, `Thread.sleep()`, `setTimeout()`, or `time.Sleep()` in tests to wait for results
|
|
1201
|
+
- Donβt write tests like: `someSetup() β wait 5s β assert result`
|
|
1202
|
+
- They run slowly
|
|
1203
|
+
- Are unstable due to system/CPU/network variability
|
|
1204
|
+
- Often fail in CI or under load
|
|
1205
|
+
- Instead, mock async components, inject a clock/timer, or observe behavior via hooks, callbacks, or queues
|
|
1206
|
+
|
|
1207
|
+
- **Applies to**: All languages
|
|
1208
|
+
- **Tools**: Manual review
|
|
1209
|
+
- **Principles**: CODE_QUALITY, TESTABILITY
|
|
1210
|
+
- **Version**: 1.0
|
|
1211
|
+
- **Status**: activated
|
|
1212
|
+
- **Severity**: major
|
|
1213
|
+
|
|
1214
|
+
### π Rule C071 β Test class names should reflect the corresponding module
|
|
1215
|
+
|
|
1216
|
+
- **Objective**: Make it easy to identify the scope of testing, improve discoverability, and provide clear organization in the test structure.
|
|
1217
|
+
|
|
1218
|
+
- **Details**:
|
|
1219
|
+
- Test class names should clearly indicate the module or subject under test and use standard suffixes like `Test`, `Spec`, `Tests`, or `TestCase`.
|
|
1220
|
+
- This helps:
|
|
1221
|
+
- Locate the test associated with a specific module
|
|
1222
|
+
- Allow CI/CD tools to detect the correct test suite
|
|
1223
|
+
- Enable automatic test detection by naming conventions (e.g., JUnit, Jest, Pytest, etc.)
|
|
1224
|
+
- Avoid vague names like `UtilsTest`, `MainTest`, or naming misalignment (e.g., testing controller but naming it `ServiceTest`)
|
|
1225
|
+
|
|
1226
|
+
- **Applies to**: All languages
|
|
1227
|
+
- **Tools**: Manual Review
|
|
1228
|
+
- **Principles**: CODE_QUALITY, MAINTAINABILITY
|
|
1229
|
+
- **Version**:
|
|
1230
|
+
- **Status**: draft
|
|
1231
|
+
- **Severity**: minor
|
|
1232
|
+
|
|
1233
|
+
### π Rule C072 β Each test should assert only one behavior
|
|
1234
|
+
|
|
1235
|
+
- **Objective**: Reduce ambiguity when a test fails, ensuring each test case validates a single, specific logic path.
|
|
1236
|
+
|
|
1237
|
+
- **Details**:
|
|
1238
|
+
- A test case should assert only one distinct behavior β avoid bundling multiple asserts or unrelated checks in the same test
|
|
1239
|
+
- When a test includes several assertions, it becomes unclear which one caused the failure, complicating debugging
|
|
1240
|
+
- If testing multiple aspects, split them into separate test cases with descriptive names
|
|
1241
|
+
- Prioritize isolation and clarity over minimizing lines of code
|
|
1242
|
+
|
|
1243
|
+
- **Applies to**: All languages
|
|
1244
|
+
- **Tools**: Manual Review
|
|
1245
|
+
- **Principles**: CODE_QUALITY, TESTABILITY
|
|
1246
|
+
- **Version**: 1.0
|
|
1247
|
+
- **Status**: activated
|
|
1248
|
+
- **Severity**: major
|
|
1249
|
+
|
|
1250
|
+
### π Rule C073 β All required configurations must be validated at startup
|
|
1251
|
+
|
|
1252
|
+
- **Objective**: Prevent unclear runtime errors due to missing or incorrect config. Ensure the app fails fast if essential settings are absent.
|
|
1253
|
+
|
|
1254
|
+
- **Details**:
|
|
1255
|
+
- All required configurations such as `API key`, `base URL`, `database credentials`, `secrets`, and `feature flags` must be checked at app startup
|
|
1256
|
+
- If missing or invalid, the app must clearly log the error and **refuse to run** (panic/exit/throw)
|
|
1257
|
+
- Avoid cases where the app starts normally but later fails due to `undefined`, `null`, or `connection failed`
|
|
1258
|
+
- Use validation schema tools (e.g., `zod`, `Joi`, `dotenv-safe`) or implement explicit checks
|
|
1259
|
+
|
|
1260
|
+
- **Applies to**: All languages
|
|
1261
|
+
- **Tools**: Manual Review
|
|
1262
|
+
- **Principles**: CODE_QUALITY
|
|
1263
|
+
- **Version**: 1.0
|
|
1264
|
+
- **Status**: activated
|
|
1265
|
+
- **Severity**: major
|
|
1266
|
+
|
|
1267
|
+
### π Rule C074 β Avoid magic numbers/values in code
|
|
1268
|
+
|
|
1269
|
+
- **Objective**: Improve clarity and self-documentation in code, so readers can understand the meaning of values without additional context.
|
|
1270
|
+
|
|
1271
|
+
- **Details**:
|
|
1272
|
+
- Avoid hardcoding numbers (`60`, `1024`, `3600`, `-1`, ...) or strings (`"admin"`, `"success"`, `"N/A"`) without descriptive context
|
|
1273
|
+
- Magic values make code harder to read, update, and reuse; they often lead to subtle logic bugs
|
|
1274
|
+
- Use named constants, enums, or config variables with meaningful names
|
|
1275
|
+
- Applies to business logic, condition checks, default settings, and HTTP/API responses
|
|
1276
|
+
|
|
1277
|
+
- **Applies to**: All languages
|
|
1278
|
+
- **Tools**: Linter (ESLint, PMD, Detekt, etc.)
|
|
1279
|
+
- **Principles**: CODE_QUALITY, MAINTAINABILITY
|
|
1280
|
+
- **Version**:
|
|
1281
|
+
- **Status**: draft
|
|
1282
|
+
- **Severity**: major
|
|
1283
|
+
|
|
1284
|
+
### π Rule C075 β All functions must explicitly declare return types
|
|
1285
|
+
|
|
1286
|
+
- **Objective**: Improve clarity, predictability, and enforce strict type control to avoid silent errors during refactoring or logic changes.
|
|
1287
|
+
|
|
1288
|
+
- **Details**:
|
|
1289
|
+
- Functions should explicitly declare the return type, especially for public, exported, or widely-used functions
|
|
1290
|
+
- Avoid vague return types like `Any`, `interface{}`, `Object`, `Map<String, dynamic>` without a defined schema
|
|
1291
|
+
- Clear return types enable:
|
|
1292
|
+
- Early detection of type errors
|
|
1293
|
+
- Easier understanding of code without reading the entire function body
|
|
1294
|
+
- Safer refactoring and branching
|
|
1295
|
+
- Not mandatory for inline or narrow-scope lambdas/functions
|
|
1296
|
+
|
|
1297
|
+
- **Applies to**: All languages
|
|
1298
|
+
- **Tools**: Type checker, Linter
|
|
1299
|
+
- **Principles**: CODE_QUALITY
|
|
1300
|
+
- **Version**: 1.0
|
|
1301
|
+
- **Status**: activated
|
|
1302
|
+
|
|
1303
|
+
### π Rule C076 β All public functions must declare explicit types for arguments
|
|
1304
|
+
|
|
1305
|
+
- **Objective**: Ensure type safety for function inputs, reduce runtime errors, and enable static analysis during compilation or code review.
|
|
1306
|
+
|
|
1307
|
+
- **Details**:
|
|
1308
|
+
- Public or exported functions must define explicit types for all arguments
|
|
1309
|
+
- Avoid generic types like `any`, `Object`, `dynamic`, or `Map<String, dynamic>` unless backed by a clear schema
|
|
1310
|
+
- Clearly typed arguments help:
|
|
1311
|
+
- Catch incorrect usage early
|
|
1312
|
+
- Improve automatic documentation
|
|
1313
|
+
- Simplify testing, mocking, and input validation
|
|
1314
|
+
- Internal or inline private functions can be more flexible, but public functions require strict control
|
|
1315
|
+
|
|
1316
|
+
- **Applies to**: All languages
|
|
1317
|
+
- **Tools**: Type checker, Linter
|
|
1318
|
+
- **Principles**: CODE_QUALITY, MAINTAINABILITY
|
|
1319
|
+
- **Version**: 1.0
|
|
1320
|
+
- **Status**: activated
|