javascript-typescript-standards
JavaScript/TypeScript Standards
Apply these standards when writing or reviewing JavaScript/TypeScript code.
Core Coding Standards
Language Features
- Use JavaScript with ES2022 features and Node.js (22+) ESM modules
- Use Node.js built-in modules and avoid external dependencies where possible
- Ask the user if you require any additional dependencies before adding them
- Always use async/await for asynchronous code
Code Quality
- Keep the code simple, readable, and maintainable
- Use descriptive variable and function names
- Do not add comments unless absolutely necessary, the code should be self-explanatory
- Never use
null, always useundefinedfor optional values
Syntax Preferences
- Prefer functions over classes
- Use arrow functions for callbacks
- Use
constfor variables that are not reassigned, andletfor those that are - Use template literals for strings that require interpolation
- Use destructuring for objects and arrays where appropriate
- Use
for...ofloops for iterating over arrays andfor...inloops for iterating over objects - Use semicolons at the end of statements
- Prefer single quotes for strings
Component & Module Structure
- Use function-based components
- Use arrow functions for callbacks
- Organize code by feature/module
- Write clear, concise JSDoc/TSDoc comments when necessary
Testing Standards
Framework
- Use Vitest for testing
Best Practices
- Write tests for all new features and bug fixes
- Ensure tests cover edge cases and error handling
- Name tests clearly:
shouldDoSomethingWhenCondition() - NEVER change the original code to make it easier to test; instead, write tests that cover the original code as it is
Examples
Good: Modern async/await
const fetchUserData = async userId => {
const response = await fetch(`/api/users/${userId}`)
const data = await response.json()
return data
}
Bad: Promises with .then()
const fetchUserData = userId => {
return fetch(`/api/users/${userId}`)
.then(response => response.json())
.then(data => data)
}
Good: Descriptive names and const
const maxRetryAttempts = 3
const isValidEmail = email => /^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(email)
Bad: Unclear names and var
var x = 3
var check = e => /^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(e)
Good: Template literals and destructuring
const getUserGreeting = ({ firstName, lastName }) => {
return `Hello, ${firstName} ${lastName}!`
}
Bad: String concatenation
const getUserGreeting = user => {
return 'Hello, ' + user.firstName + ' ' + user.lastName + '!'
}
When to Apply
Apply these standards when:
- Creating new JavaScript/TypeScript files
- Reviewing or refactoring existing code
- User asks about JavaScript/TypeScript best practices
- Working with Node.js projects
- Writing or reviewing tests with Vitest
More from devbyray/github-copilot-starter
css-standards
Guidelines for writing CSS that is simple, readable, and maintainable. Use when working with .css, .scss, .sass files, CSS-in-JS, styled-components, or when the user asks about CSS organization, selectors, specificity, reusability, performance, or responsive design patterns.
4testing-tdd
Test-Driven Development workflow and testing standards. Use when writing tests, implementing TDD, working with Vitest (frontend), xUnit or MsTest (backend), or when the user asks about testing strategies, test coverage, or TDD methodology.
3csharp-standards
C# coding standards and conventions including naming, formatting, and best practices. Use when working with .cs files, writing C# code, or when the user asks about C# naming conventions, code structure, XML documentation, or .NET development patterns.
3dotnet-development
.NET coding standards and conventions including project structure, dependency injection, and best practices. Use when working with .NET projects, ASP.NET Core, or when the user asks about .NET architecture, dependency injection, async patterns, or project organization.
2