Code Quality & Patterns Todo #
Cross-References #
- Build System Issues: TypeScript compilation and export fixes
- Security Practices: Secure coding guidelines and practices
- Performance Patterns: Performance-focused coding patterns
- Package Standards: Cross-package coding standards
- Automation Tools: Automated code quality improvements
Current Linting Issues #
High Priority Lint Fixes #
Code Quality Issues (Fix in code, not config) #
- Variable abbreviations (~135 total occurrences,
down from 147)
- Use descriptive names instead of abbreviations
- NEVER use single-letter variables like
i,j,k: they provide no semantic meaning - Exception: Mathematical formulas where single letters have established meaning
TypeScript Compilation Errors (New - Critical Priority) #
Status: Critical (blocks builds)
Recent analysis shows critical TypeScript compilation errors that must be fixed:
-
iterable.is.tsmissing multiple export declarationsnumeric.type.int.tsexport name mismatches- Module export consistency issues across packages
-
getRandomIdfunction missing inany.ReplicatingStore.ts- Type constraint issues in array type definitions
- Pattern matcher type compatibility issues
Cross-Reference: See Build System Todo for complete list and fixes.
Remaining Files to Fix #
- Files with void expression issues in test assertions
- Re-inventory variable abbreviations before opening new cleanup work.
The package-wide loop-counter and
window.sweeps are complete:rg --line-number 'for \\(let [ijk]' packagesandrg --line-number '\\bwindow\\.' packagesreturn no matches on 2026-06-01.
Medium Priority Issues #
Test File Issues #
- Missing JSDoc comments in non-test files (expected for internal utilities)
Next Steps for Lint Cleanup #
- Re-inventory abbreviation usage beyond package C-style loop counters.
- Fix remaining void expression issues in test assertions.
Cross-Reference: See Automation Todo for automated linting improvements.
Code Patterns and Best Practices #
Meilisearch Task Polling Implementation Evolution #
Learning Example: The user guided progressive simplification through "Do you really need..." questions:
- Started with mutable
let taskStatusandwhileloop with inline constants - "Do you really need a mutable variable?
" → Moved to immutable
constinside loop - "Do you really need a while(true) break pattern?
" → Changed to
whilewith proper condition - "Do you really need a while loop at all?
" → Changed to
forloop with calculated iterations - "Do you really need a for loop? " → Changed to recursive helper function
Final Implementation: Simple Array with findAsync #
// Create array of 100 nulls as a counter
const polls = new Array(100,).fill(null,);
// Use findAsync where the predicate does all the work
try {
const completedStatus = await findAsync(
polls,
async () => {
const status = await client.tasks.getTask(task.taskUid,);
if (!isTaskPending(status.status,))
return status;
await wait(TASK_POLL_INTERVAL_MS,);
return false;
},
);
if (completedStatus) {
if (completedStatus.status !== 'succeeded') {
console.error(`Task ${task.taskUid} failed:`, completedStatus.error,);
allTasksSuccessful = false;
}
}
else {
console.error(`Task ${task.taskUid} timed out after ${TASK_TIMEOUT_MS}ms`,);
allTasksSuccessful = false;
}
}
catch (error) {
console.error(error,);
allTasksSuccessful = false;
}
Potential Future Improvements (1am Ideas) #
-
Different utility function: Perhaps a
timesorrepeatasync function:const status = await repeatAsync(100, async () => { /* poll logic */ })- This would eliminate the dummy array entirely
-
Parallel task validation: Instead of polling tasks sequentially:
- Create an array of all taskUids from the batch
- Use
Promise.allwithfindAsyncfor each task - Or better:
a single
findAsyncthat polls ALL tasks in each iteration
Cross-Reference: See Packages Todo for async utility function development.
Lessons from "Do you really need..." #
This questioning pattern teaches:
- Question every construct: Each programming construct adds complexity
- Prefer immutability: Mutable variables should be eliminated when possible
- Prefer declarative over imperative: Loops can often be replaced with higher-order functions
- Extract and name concepts:
Helper functions like
isTaskPendingimprove readability - Think functionally first: There's often a functional solution that's cleaner
- Simplify progressively: Don't stop at the first working solution
Cross-Reference: See Performance Todo for performance-focused patterns.
Testing Requirements and Standards #
General Testing Guidelines #
- Write a corresponding test file (using
@monochromatic-dev/module-test) that aims for 100% test coverage - Tests can only be run from workspace root using
mise run test - To run tests for specific patterns:
mise run test:unit -- package/module/es/src/boolean.equal.unit.test.tsmise run test:browser -- package/module/es/src/boolean.equal.browser.test.ts
Cross-Reference: See Automation Todo for comprehensive testing automation.
Coverage Requirements #
If certain lines or branches can't be tested, use V8 ignore comments:
/* v8 ignore next -- @preserve */
if (impossibleCondition)
throw new Error('This should never happen',);
// For multiple lines:
/* v8 ignore next 3 -- @preserve */
if (untestableCondition) {
console.error('Untestable path',);
return fallbackValue;
}
Testing Intentional Violations #
When tests intentionally violate a rule to verify behavior:
// BAD: Adding data to satisfy the linter
expect(isError(new Error('test message',),),).toBe(true,);
// GOOD: Use disable comments for intentional violations
// oxlint-disable-next-line unicorn/error-message -- Testing error without message
expect(isError(new Error(),),).toBe(true,);
TypeScript Standards and Patterns #
Function Patterns #
- Always name functions. Prefer function declarations
- Always use parentheses around arrow function parameters (even single parameter)
- Provide explicit parameter and return types for all functions
- Use function overloads for functions with multiple call signatures
Variable and Immutability Standards #
- Prefer
constoverletto encourage immutability - Strive for immutability: avoid reassigning variables and modifying objects in place
- NEVER use single-letter variables: they provide no semantic meaning
- Prefer functional approaches over imperative loops
- Remove unused variables or prefix them with underscore
- Use
satisfiesoperator for type checking without widening
Error Handling Best Practices #
- NEVER use process. exit(): throw errors instead
- Combine console. log/error messages into thrown errors
- Use string-dedent for multi-line error messages
- Always log errors in catch blocks
- Document expected errors with comments
Cross-Reference: See Security Todo for security-focused error handling.
Linting Configuration Philosophy #
When to Fix vs Configure #
- High Priority: Fix legitimate code issues in the codebase
- Medium Priority: Adjust configuration for team workflow
- Never: Disable rules just to avoid fixing code
Rule Categories #
- Code Quality Issues: Always fix in code, not config
- Style Preferences: Can be configured for team consistency
- Framework-specific: May need configuration for specific use cases
Testing-Specific Linting #
- Use disable comments for intentional rule violations in tests
- Different rules may apply to test files vs production code
- Document why test files need different linting rules
Performance and Code Efficiency #
Async Programming Standards #
- Prefer
async/awaitover explicit promise creation - Use
wait()from module-es instead ofnew Promise(resolve => setTimeout(...)) - Avoid await in loops where logically sound
- Use
Promise.all()for concurrent operations
Cross-Reference: See Performance Todo for comprehensive async optimization.
Functional Programming Utilities #
Function composition lives in @monochromatic-dev/module-pipe,
not module-es:
- Use
pipedfor eager synchronous function composition - Use
pipedAsyncfor eager async function composition - Use
pipe/pipeAsyncfor deferred, reusable function pipelines - Functions generally don't require
.bind()forthiscontext
Cross-Reference: See Packages Todo for functional utility expansion.
Code Organization Standards #
File Organization #
- Use
regionmarkers to delineate logical sections - Group imports in specific order (built-in, external, workspace, relative, type-only)
- Always include file extensions in imports
- Use absolute imports for workspace packages
Export Patterns #
- Avoid
Object.assignfor extending typed objects - Export at the end after all object construction is complete
- Prefer immediately invoked function expressions over mutable variables
Security-Focused Code Quality #
Secure Coding Practices #
Status: High Priority (security integration)
Cross-Reference: See Security Todo for comprehensive security guidelines.
Dependency Security Integration #
Cross-Reference: See Security Todo for dependency security management.
Future Quality Improvements #
Automated Code Quality #
- Implement automated code review checks
- Set up quality gates in CI/CD pipeline
- Monitor code quality metrics over time
- Integrate with development workflow
Cross-Reference: See Automation Todo for comprehensive automation.
Developer Experience #
- Provide clear error messages for common issues
- Document coding standards and best practices
- Create code templates and snippets
- Implement automated refactoring tools
Cross-Reference: See Development Todo for developer experience enhancements.
Performance Integration #
Cross-Reference: See Performance Todo for performance measurement integration.