Chuyển đến nội dung
Skillpedia
Lập trình chung280k · #151

coding-standards

Skill này làm gì

Công cụ này giúp đảm bảo code được viết theo thực hành lập trình tốt. Nó kiểm tra tên biến, khả năng đọc, tính bất biến (dữ liệu không bị thay đổi sau khi tạo) và chất lượng code tổng thể.

Khi nào nên dùng

  • ✓Khi bắt đầu một dự án mới hoặc một phần của dự án.
  • ✓Khi rà soát code của người khác để đảm bảo nó rõ ràng và dễ bảo trì.
  • ✓Khi tổ chức hoặc cải thiện code đang có.

Liên kết skill

https://github.com/affaan-m/ECC/blob/main/pi/core/skills/coding-standards/SKILL.md

Sao chép rồi dán vào AI của bạn (Claude, ChatGPT hoặc Cursor) và nhờ nó làm theo hướng dẫn.

Cách dùng

Cách dễ nhất: sao chép tin nhắn và dán vào AI của bạn. AI sẽ đọc skill và làm theo hướng dẫn.

Tin nhắn có sẵn để dán

Hãy dùng skill này để giúp tôi: https://github.com/affaan-m/ECC/blob/main/pi/core/skills/coding-standards/SKILL.md Đọc tệp SKILL.md tại liên kết đó và làm theo hướng dẫn cho việc của tôi.
Bạn muốn AI tự tìm những skill như thế này?Cài MCP Skillpedia miễn phí: chỉ một dòng, và AI sẽ tìm trong 15.000+ skill trước mỗi việc.Cài đặt trong 1 phút →

Ví dụ cách nhờ AI

“Rà soát đoạn code này để đảm bảo nó tuân theo thực hành tốt về đặt tên và độ dễ đọc.”

5 skill mới mỗi tuần. Đọc chỉ 1 phút.

Cách hoạt động

Công cụ so sánh code với các quy tắc đã định về sự rõ ràng, đơn giản và tổ chức. Nó kiểm tra xem tên có mô tả rõ không và code có dễ hiểu, dễ bảo trì không.

Nội dung kỹ thuật (SKILL.md gốc)

Lấy nguyên văn từ GitHub, do tác giả viết bằng tiếng Anh.

Coding Standards & Best Practices

Baseline coding conventions applicable across projects.

This skill is the shared floor, not the detailed framework playbook.

  • Use frontend-patterns for React, state, forms, rendering, and UI architecture.
  • Use backend-patterns or api-design for repository/service layers, endpoint design, validation, and server-specific concerns.
  • Use rules/common/coding-style.md when you need the shortest reusable rule layer instead of a full skill walkthrough.

When to Activate

  • Starting a new project or module
  • Reviewing code for quality and maintainability
  • Refactoring existing code to follow conventions
  • Enforcing naming, formatting, or structural consistency
  • Setting up linting, formatting, or type-checking rules
  • Onboarding new contributors to coding conventions

Scope Boundaries

Activate this skill for:

  • descriptive naming
  • immutability defaults
  • readability, KISS, DRY, and YAGNI enforcement
  • error-handling expectations and code-smell review

Do not use this skill as the primary source for:

  • React composition, hooks, or rendering patterns
  • backend architecture, API design, or database layering
  • domain-specific framework guidance when a narrower ECC skill already exists

Code Quality Principles

1. Readability First

  • Code is read more than written
  • Clear variable and function names
  • Self-documenting code preferred over comments
  • Consistent formatting

2. KISS (Keep It Simple, Stupid)

  • Simplest solution that works
  • Avoid over-engineering
  • No premature optimization
  • Easy to understand > clever code

3. DRY (Don't Repeat Yourself)

  • Extract common logic into functions
  • Create reusable components
  • Share utilities across modules
  • Avoid copy-paste programming

4. YAGNI (You Aren't Gonna Need It)

  • Don't build features before they're needed
  • Avoid speculative generality
  • Add complexity only when required
  • Start simple, refactor when needed

TypeScript/JavaScript Standards

Variable Naming

// PASS: GOOD: Descriptive names
const marketSearchQuery = 'election'
const isUserAuthenticated = true
const totalRevenue = 1000

// FAIL: BAD: Unclear names
const q = 'election'
const flag = true
const x = 1000

Function Naming

// PASS: GOOD: Verb-noun pattern
async function fetchMarketData(marketId: string) { }
function calculateSimilarity(a: number[], b: number[]) { }
function isValidEmail(email: string): boolean { }

// FAIL: BAD: Unclear or noun-only
async function market(id: string) { }
function similarity(a, b) { }
function email(e) { }

Immutability Pattern (CRITICAL)

// PASS: ALWAYS use spread operator
const updatedUser = {
  ...user,
  name: 'New Name'
}

const updatedArray = [...items, newItem]

// FAIL: NEVER mutate directly
user.name = 'New Name'  // BAD
items.push(newItem)     // BAD

Error Handling

// PASS: GOOD: Comprehensive error handling
async function fetchData(url: string) {
  try {
    const response = await fetch(url)

    if (!response.ok) {
      throw new Error(`HTTP ${response.status}: ${response.statusText}`)
    }

    return await response.json()
  } catch (error) {
    console.error('Fetch failed:', error)
    throw new Error('Failed to fetch data')
  }
}

// FAIL: BAD: No error handling
async function fetchData(url) {
  const response = await fetch(url)
  return response.json()
}

Async/Await Best Practices

// PASS: GOOD: Parallel execution when possible
const [users, markets, stats] = await Promise.all([
  fetchUsers(),
  fetchMarkets(),
  fetchStats()
])

// FAIL: BAD: Sequential when unnecessary
const users = await fetchUsers()
const markets = await fetchMarkets()
const stats = await fetchStats()

Type Safety

// PASS: GOOD: Proper types
interface Market {
  id: string
  name: string
  status: 'active' | 'resolved' | 'closed'
  created_at: Date
}

function getMarket(id: string): Promise<Market> {
  // Implementation
}

// FAIL: BAD: Using 'any'
function getMarket(id: any): Promise<any> {
  // Implementation
}

React Best Practices

Component Structure

// PASS: GOOD: Functional component with types
interface ButtonProps {
  children: React.ReactNode
  onClick: () => void
  disabled?: boolean
  variant?: 'primary' | 'secondary'
}

export function Button({
  children,
  onClick,
  disabled = false,
  variant = 'primary'
}: ButtonProps) {
  return (

…
Câu hỏi thường gặp

“Immutability” nghĩa là gì?

Tính bất biến nghĩa là khi dữ liệu đã được tạo thì không thể thay đổi. Trong lập trình, điều này giúp tránh lỗi bất ngờ vì dữ liệu không thay đổi ngoài ý muốn.

“Coding best practices” là gì?

Đó là tập hợp các quy tắc và khuyến nghị giúp viết code chất lượng cao, dễ đọc, dễ hiểu, dễ bảo trì và hoạt động đúng.

Khi nào nên dùng công cụ này thay vì các công cụ chuyên biệt hơn?

Dùng công cụ này khi bạn cần quy tắc chất lượng code chung áp dụng cho mọi dự án, mà không tập trung vào chi tiết của một công nghệ cụ thể như React hoặc Node.js.

Chi tiết

Mô tả gốc của tác giả

Baseline cross-project coding conventions for naming, readability, immutability, and code-quality review. Use detailed frontend or backend skills for framework-specific patterns. Use when reviewing code quality or naming with no framework-specific skill that applies.

repo: affaan-m/ECC

Độ phổ biến

Sao GitHub
280k
Vị trí xếp hạng
#151
Giấy phép
MIT
Cập nhật
15/10/2026

Skill này có hữu ích không?

0

Đăng nhập để bình chọn.

Bình luận

  • …

Thêm skill từ kho mã này

Skill tương tự