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

  1. Indentation: 2 spaces (no tabs)

  2. Line length: Max 100 characters

  3. Spacing: Spaces around operators and after commas

  4. Braces: Always use braces for blocks

  5. Semicolons: Use semicolons (se richiesto da ESLint config)

Organization Rules

  1. Imports: External first, then internal, then assets

  2. Functions: Helpers before main functions

  3. Constants: At the top after imports

  4. Exports: At the bottom of file

  5. Blank lines: Between logical sections

Consistency Rules

  1. Single style: Stick to one formatting style

  2. Prettier: Use Prettier for automatic formatting

  3. ESLint: Follow ESLint rules for consistency

  4. Team agreement: Follow team conventions

  5. 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?