sinpro.dev
Docs
Git
Git Branches and Commits
  • Company Information
    • Portfolio
    • About
    • Services
    • Events
  • Dev Environment
    • macOS Settings
    • Chrome Extensions
    • VSCode Workspace Settings
    • VSCode Workspace Extensions
    • Global NPM Packages
    • npm-check-updates
    • SvelteKit
    • Customize Zsh
    • ChatGPT Prompts
    • Tailwind CSS
    • Warp
    • Keyboard Shortcuts
  • Assets
    • Assets
    • JPG/PNG to AVIF
    • TTF to WOFF2
  • Clean Code
    • Clean Code
    • Format
    • Quality
    • Variables
    • Functions
    • Objects and Data Structures
    • Classes
    • Concurrency
    • Error handling
    • Comments
  • Code Style
    • TypeScript Config
    • Prettier
    • ESLint
    • Stylelint
  • Testing
    • Vitest
    • Playwright
  • Git
    • Git Branches and Commits
    • Git Hooks
    • Git User Profiles
    • Git for Windows
  • GitHub
    • GitHub Issues
    • GitHub Pull Requests
    • GitHub Repository Settings
    • GitHub Branch Protection
    • GitHub Actions
  • Code Quality
    • SonarCloud Coverage
  • Server
    • SSH
    • PM2
    • Caddy
    • Updating the server
    • ngrok
  • Team sinProject
    • Our Team Policy
    • Equipment and Supplies
    • Books
    • Slack
    • Locales
    • Funny Apps
    • Docs History
  • Talk
    • Talk
    • Creating a Project
    • App Structure

Clean Code

Format

Edit this page

Naming of files and directories

Use snake_case.
However, for things that constitute a URL, such as HTML, JavaScript, CSS files, image files, and API paths, use kebab-case.

Use single quotes

Both double quotes and single quotes has their own pros and cons. However, achieving consistency within a project is a necessity.

Delimit ordinary string literals with single quotes ('), rather than double quotes (").

Tip: if a string contains a single quote character, consider using a template string to avoid having to escape the quote.

For more information: Google JavaScript Style Guide

Bad
console.log("Hello")
console.log('World')
Good
console.log('Hello')
console.log('World')

Don’t append semicolons at the end of lines

For more information: Don’t use Semicolons in TypeScript!

General
console.log('Hello');
Our Style
console.log('Hello')

Use template literals

Old-fashioned
const first_name = 'John'
const last_name = 'Smith'

console.log(first_name + ' ' + last_name)
Good
const first_name = 'John'
const last_name = 'Smith'

console.log(`${first_name} ${last_name}`)

Use white space for readability

Bad
for(let i=1;i<=10;i++){
  // ...
}
Good
for (let i = 0; i <= 10; i++) {
  // ...
}

Use blank lines for readability

Bad
function foo(): number {
  let sum = 0
  for (...) {
    const buz = ''
    if (...) {
      // ...
    }
    console.log(...)
  }
  return sum
}
function bar(): void {
  // ...
}
Good
function foo(): void {
  let sum = 0

  for (...) {
    const buz = ''

    if (...) {
      // ...
    }

    console.log(...)
  }

  return sum
}

function bar(): void {
  // ...
}

Explicit function return type

Bad
function foo() {
  // ...
  return true
}
Good
function foo(): boolean {
  // ...
  return true
}

Don’t allow unreachable code

Bad
function foo(): boolean {
  // ...
  return true
  console.log('Hello')
}
Good
function foo(): boolean {
  // ...
  return true
}

Variable names, argument names, and function names should be in snake_case

General
function fooBar(pageCount: number): void {
  const maxCount = 5
  // ...
}
Our Style
function foo_bar(page_count: number): void {
  const max_count = 5
  // ...
}

Explicit member accessibility

Bad
class Foo {
  bar(): void {
    // ...
  }
}
Good
class Foo {
  public bar(): void {
    // ...
  }
}
Clean Code Quality
© sinProject. v0.73.0
On this page
  • Format
  • Naming of files and directories
  • Use single quotes
  • Don’t append semicolons at the end of lines
  • Use template literals
  • Use white space for readability
  • Use blank lines for readability
  • Explicit function return type
  • Don’t allow unreachable code
  • Variable names, argument names, and function names should be in snake_case
  • Explicit member accessibility