Break down complex conditional logic, nested structures, and verbose syntax into smaller, well-named functions or more concise expressions. This improves code readability and maintainability.
Break down complex conditional logic, nested structures, and verbose syntax into smaller, well-named functions or more concise expressions. This improves code readability and maintainability.
Key practices:
Example of improvement:
// Instead of complex nested conditions:
if (err && err.showDiff !== false && err.expected !== undefined && _sameType(err.actual, err.expected)) {
// ...
}
// Extract into named functions:
const diffCanBeShown = (err) => err && err.showDiff !== false
const hasExpectedValue = (err) => err.expected !== undefined
const hasSameTypeValues = (err) => _sameType(err.actual, err.expected)
const showDiff = (err) => diffCanBeShown(err) && hasExpectedValue(err) && hasSameTypeValues(err)
Also prefer concise TypeScript syntax:
// Instead of: const docsMenuVariant: Ref<DocsMenuVariant> = ref('main')
const docsMenuVariant = ref<DocsMenuVariant>('main')
And use idiomatic JavaScript methods:
// Instead of: indexOf() !== -1
// Use: includes()
Enter the URL of a public GitHub repository