Layout
Regole di formattazione e organizzazione del codice JavaScript per progetti PANDEV.
π¨ Spacing e Indentation
Indentation
β Evitare:
// bad - mixed tabs and spaces
function processUser(user) {
const name = user.name
const email = user.email // spaces instead of tabs
return { name, email }
}
// bad - inconsistent indentation
if (condition) {
doSomething()
doSomethingElse() // wrong indentation
}β Preferire:
// good - consistent 2-space indentation
function processUser(user) {
const name = user.name
const email = user.email
return { name, email }
}
// good - consistent indentation in blocks
if (condition) {
doSomething()
doSomethingElse()
}Spacing Around Operators
β Evitare:
β Preferire:
Function Calls e Declarations
β Evitare:
β Preferire:
π§ Code Organization
File Structure
β Evitare:
β Preferire:
Import Organization
β Evitare:
β Preferire:
Function Organization
β Evitare:
β Preferire:
π Line Length e Breaking
Line Length
β Evitare:
β Preferire:
Object e Array Breaking
β Evitare:
β Preferire:
Method Chaining
β Evitare:
β Preferire:
ποΈ Block Organization
Conditional Blocks
β Evitare:
β Preferire:
Function Blocks
β Evitare:
β Preferire:
π Comments e Spacing
Comment Spacing
β Evitare:
β Preferire:
JSDoc Spacing
β Evitare:
β Preferire:
π― Best Practices Summary
Formatting Rules
Indentation: 2 spaces (no tabs)
Line length: Max 100 characters
Spacing: Spaces around operators and after commas
Braces: Always use braces for blocks
Semicolons: Use semicolons (se richiesto da ESLint config)
Organization Rules
Imports: External first, then internal, then assets
Functions: Helpers before main functions
Constants: At the top after imports
Exports: At the bottom of file
Blank lines: Between logical sections
Consistency Rules
Single style: Stick to one formatting style
Prettier: Use Prettier for automatic formatting
ESLint: Follow ESLint rules for consistency
Team agreement: Follow team conventions
Documentation: Comment formatting standards
Queste regole di layout garantiscono codice JavaScript ben organizzato e leggibile in tutti i progetti PANDEV.
Last updated
Was this helpful?