This document outlines the coding standards and guidelines for contributing to the TypeUp Parser project.
TypeUp.parser is a TypeScript library providing an event-based parser for TypeUp documents. The project follows strict coding conventions to maintain consistency and quality.
- Install dependencies:
npm install- Build the project:
npm run build- Run tests:
npm test- Run tests in watch mode:
npm run test:watch- Run full verification:
npm run verify- All code must be written in TypeScript
- Always provide type definitions with the following pattern for exported types:
- Define the type/interface
- Create a namespace with the same name
- Provide
type,isandflaweddefinitions inside the namespace
Example:
export type MyType = {
// type definition
}
export namespace MyType {
export const { type, is, flawed } = isly
.object<MyType>({
// type definition
})
.rename("isly.MyType")
.bind()
}- Functions should have single return points
- Use
resultas the variable name for function return values - Prefer fewer lines of code over shorter lines
- Prefer expressions over statements
- Avoid unnecessary braces
- Use strict equality (
===and!==) only when necessary - Rely on TypeScript's type system for type checking
-
Implementation files:
- Aim to keep files under 200 lines of code
- Files containing primarily data structures (e.g., country codes, encodings) may be longer
- Split large files into focused modules when they exceed 300 lines
- Each file should have a single core responsibility
-
Test files:
- Keep individual test cases focused and concise
- Use
it.eachto reduce code duplication - Test files may be longer than implementation files due to comprehensive test cases
- Consider splitting test files if they exceed 400 lines
-
File organization:
- Group related functionality in subdirectories
- Use index files to re-export functionality
- Keep directory structures shallow (max 3 levels deep)
-
No abbreviations except:
- "UI" (uppercase because it's a two-letter multi-word abbreviation)
- "Id" (regular casing)
- "max"
- "min"
-
When using abbreviations:
- Multi-word abbreviations of 1-2 letters stay uppercase (e.g., "UI")
- All other abbreviations follow normal casing rules regardless of word count:
- In PascalCase: "Id", "Utf", "Iso", etc.
- In camelCase: "id", "utf", "iso", etc.
-
Prefer single word identifiers
-
Single letter identifiers only allowed if usage is within 3 lines
-
Use descriptive and clear names for variables and functions
-
Always import from the package's index file:
import { parser } from "../index"
-
Prefer using
it.eachfor test cases with similar patterns:it.each([ ["input1", expected1], ["input2", expected2], ])("test description %s", (input, expected) => { expect(someFunction(input)).toBe(expected) })
-
Keep test descriptions short and focused
-
Test file names should match the implementation file with
.spec.tsextension -
Each test file should have one top-level
describeblock
The project uses ESLint and Prettier with the following configuration:
- Print width: 120 characters
- Use tabs for indentation
- No semicolons
- Double quotes for strings
- LF line endings
- Import order is enforced by eslint-plugin-simple-import-sort
- Imports are grouped in the following order:
- Core/framework imports
- External packages
- Internal modules
- Relative imports
- Create a branch for your feature/fix
- Ensure code passes all tests:
npm test - Ensure code passes linting:
npm run lint - Run the verification script:
npm run verify - Update documentation as needed
- Create a pull request with a clear description
-
Run tests in watch mode during development:
npm run test:watch
-
Use the coverage command to check test coverage:
npm run coverage
Coverage thresholds are set to 90% for:
- Statements
- Functions
- Lines
And 85% for:
- Branches
-
Fix linting issues:
npm run fix
-
Event-based Architecture: The parser uses an event-based API. Ensure all new parsing logic follows this pattern.
-
Error Handling: Use
mendly.Error.Regionfor proper error location tracking. -
Performance: Be mindful of parsing performance, especially for large documents.
-
Backward Compatibility: Consider backward compatibility when making API changes.
-
DOM Integration: Ensure proper integration with
@typeup/domfor element creation and manipulation.