Add line breaks and proper spacing between logical blocks within functions to improve code readability. When functions become complex with multiple logical sections, consider extracting nested logic into separate functions.
Add line breaks and proper spacing between logical blocks within functions to improve code readability. When functions become complex with multiple logical sections, consider extracting nested logic into separate functions.
For example, instead of cramped code:
function uniquePlugins (plugins: NuxtPlugin[]) {
const pluginFlags = new Set<string>()
const bucket: NuxtPlugin[] = []
for (const plugin of [...plugins].reverse()) {
const name = plugin.name ? plugin.name : filename(plugin.src)
const mode = plugin.mode ? plugin.mode : 'all'
const flag = `${name}.${mode}`
if (pluginFlags.has(flag)) {
continue
}
pluginFlags.add(flag)
bucket.push(plugin)
}
return bucket.reverse()
}
Use proper spacing between logical sections:
function uniquePlugins (plugins: NuxtPlugin[]) {
const pluginFlags = new Set<string>()
const bucket: NuxtPlugin[] = []
for (const plugin of [...plugins].reverse()) {
const name = plugin.name ? plugin.name : filename(plugin.src)
const mode = plugin.mode ? plugin.mode : 'all'
const flag = `${name}.${mode}`
if (pluginFlags.has(flag)) {
continue
}
pluginFlags.add(flag)
bucket.push(plugin)
}
return bucket.reverse()
}
Additionally, when complex logic can be extracted for better organization and readability, move it out of nested contexts into separate functions or higher-level scopes.
Enter the URL of a public GitHub repository