Docstring Guidelines¶
This document defines standards for writing docstrings in the gaslamp project.
Docstrings are used to generate API documentation via TypeDoc and help developers understand code intent at a glance.
Quick Standard Template¶
Every exported function, class, and interface should follow this pattern:
/**
* One-line summary of what this does.
*
* Optional extra explanation here if needed.
*
* @param paramName Description of parameter
* @returns Description of return value
*
* @example
* ```javascript
* const df = gaslamp.BareFrame.fromSheet(sheet);
* const result = df.filter(row => row.get('age') >= 18);
* ```
*
* @category DataFrame
*/
Essential Rules¶
1. Use TypeDoc Format¶
Use /** ... */ block comments with @ tags.
Do not use JSDoc-only tags like @typedef or @callback.
2. One-Line Summary (Required)¶
A single sentence describing what the symbol does, in present tense.
/** Filters rows where a column value matches a condition. */
Not:
- ✗ "Filter rows" (incomplete sentence)
- ✗ "Used to filter rows" (passive voice)
3. Parameters (@param)¶
Describe what each parameter does. Do not repeat the type (TypeScript already shows it).
/**
* @param predicate Function that returns true for rows to keep
* @param options Optional configuration (default: {})
*/
4. Return Value (@returns)¶
Describe what the caller receives.
Omit only if the function returns void.
/**
* @returns A new BareFrame with only matching rows
*/
5. Example (@example) — Highly Recommended¶
Show the most common use case in a code block.
Always use javascript language identifier and gaslamp. prefix:
/**
* @example
* ```javascript
* const df = gaslamp.BareFrame.fromSheet(sheet);
* const adults = df.filter(row => row.get('age') >= 18);
* ```
*/
Why:
javascriptmakes examples copy-paste executable in Google Apps Scriptgaslamp.prefix is required since GAS doesn't support ES modules
6. Category (@category)¶
Required for exported symbols. Choose one:
DataFrame— BareFrame, GroupedFrame, operationsFlameFrame— Validation gatesFlame— FlameGuards, FlameWright type validationExpression— Expression builders and predicatesConvert— Data conversion utilitiesLogger— AfterGlow loggingGaslets— Google Apps Script utilitiesGears— General utilitiesJestLite— Testing framework
7. Extra Sections (Optional)¶
Use @remarks for important context:
/**
* Filters rows where a column value matches a condition.
*
* @remarks
* This uses eager evaluation (applied immediately).
* For deferred evaluation with optimizations, use LazyFrame.
*/
Use @since for version information:
/**
* @since 0.62.0
*/
Use @deprecated when removing features:
/**
* @deprecated Use BareFrame.filter() instead.
*/
Complete Examples¶
Function¶
/**
* Filters rows where a column value matches a condition.
*
* This method applies the filter immediately (eager evaluation).
*
* @param predicate Function that returns true for rows to keep
* @returns A new BareFrame with only matching rows
*
* @example
* ```javascript
* const df = gaslamp.BareFrame.fromSheet(sheet);
* const adults = df.filter(row => row.get('age') >= 18);
* ```
*
* @category DataFrame
* @since 0.60.0
*/
public filter(predicate: (row: Map<string, Cell>) => boolean): BareFrame {
// implementation
}
Class¶
/**
* A tabular data structure with column-oriented access.
*
* BareFrame is the primary way to read, transform, and write data in gaslamp.
* All filtering, selection, and aggregation operations return new BareFrame instances.
*
* @example
* ```javascript
* const sheet = SpreadsheetApp.getActiveSheet();
* const df = gaslamp.BareFrame.fromSheet(sheet);
* const filtered = df.filter(row => row.get('age') >= 18);
* const selected = filtered.select(['name', 'age']);
* selected.toSheet(sheet);
* ```
*
* @category DataFrame
*/
export class BareFrame { ... }
Interface¶
/**
* Options for DataFrame.filter() operation.
*
* @category DataFrame
*/
export interface FilterOptions {
/** Throw on error if true; return null if false. Default: false. */
strict?: boolean;
}
Language Guidelines¶
Write for developers new to gaslamp:
- Be concrete. "Removes duplicate rows" not "Operates on duplicates"
- Use active voice. "Returns a filtered DataFrame" not "Filtering returns a DataFrame"
- Explain benefits. Why would someone use this?
- Avoid jargon. Explain technical terms if used
Good:
/** Removes duplicate rows, keeping the first of each group. Useful for cleaning imported data. */
Bad:
/** Deduplicates using a hash-based algorithm. */
Sample Code Requirements¶
All code examples in docstrings must:
- Use
javascriptlanguage identifier (nottypescript) - Examples must be executable in Google Apps Script
-
No type annotations in function signatures
-
Use
gaslamp.prefix for all API calls - ✓
gaslamp.BareFrame.fromSheet() - ✓
gaslamp.FlameGuards.isNumber() -
✗
BareFrame.fromSheet()(wrong) -
Show realistic GAS usage when applicable
- Reference
SpreadsheetAppcorrectly -
Show complete workflows (read → transform → write)
-
Use
consolemethods for logging (V8 runtime) - ✓
console.log()— General output (DEBUG level) - ✓
console.info()— Informational messages (INFO level) - ✓
console.warn()— Warning messages (WARNING level) - ✓
console.error()— Error messages (ERROR level) - ✗
console.debug()— Not supported in GAS - Never use
Logger.log()—consoleis preferred for V8 runtime
Example:
// Read from active sheet
const sheet = SpreadsheetApp.getActiveSheet();
const df = gaslamp.BareFrame.fromSheet(sheet);
// Transform
const filtered = df.filter(row => row.get('age') >= 18);
const selected = filtered.select(['name', 'age']);
// Output results
if (selected.length === 0) {
console.warn('No rows matched the filter');
} else {
console.log(`Found ${selected.length} rows`);
}
// Write to new sheet
const output = SpreadsheetApp.getActiveSpreadsheet().insertSheet('clean');
selected.toSheet(output);
Pre-Commit Checklist¶
Before committing, verify:
- Summary is one sentence, present tense?
- All parameters documented in
@param? - Return value documented in
@returns? - Has a
@category? - Example uses
javascriptidentifier? - Example uses
gaslamp.prefix? - Example uses
consolemethods (notLogger.log)? - Example is executable in GAS (no TypeScript syntax)?
- No implementation details leaked into the description?
Related Documents¶
- Naming Guidelines — How to name functions, variables, and classes
- Style Guides — Code formatting and syntax preferences
- Build Documentation — Generating and publishing API docs