Registry / devops / brighterscript-formatter

brighterscript-formatter

JSON →
library1.7.26jsnpmunverified

A code formatter for BrightScript and BrighterScript, a superset of Roku's BrightScript language, written in JavaScript. Current stable version is 1.7.26, with regular releases. It provides CLI and Node API for formatting, supports configurable formatting options via bsfmt.json, and integrates with editor tools. Key differentiators: specifically designed for Roku development, supports BrighterScript syntax, and offers flexibility in formatting rules.

npm install brighterscript-formatter
INSTALL
IMPORT
SIG · BRIGHTERSCRIPT-FOR
B
brighterscript-formatter
devopsjavascriptv1.7.26
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

default
import { format, formatCode, setFormatterOptions } from 'brighterscript-formatter'
const bsfmt = require('brighterscript-formatter')
Package is ESM-compatible; named exports are preferred.
FormatOptions
import type { FormatOptions } from 'brighterscript-formatter'
TypeScript type for formatting options.
formatCode
import { formatCode } from 'brighterscript-formatter'
import { formatCode } from 'brighterscript-formatter'
Main function for formatting a single string of code.

Demonstrates basic usage of formatCode and setFormatterOptions with TypeScript imports.

import { formatCode, setFormatterOptions } from 'brighterscript-formatter'; // Example: format a BrighterScript string const code = `sub main() print "hello" end sub`; const formatted = formatCode(code, { indentStyle: 'spaces', indentSpaceCount: 4, keywordCase: 'lower', includeCompilerVersion: true }); console.log(formatted); // Set global options setFormatterOptions({ indentStyle: 'spaces', indentSpaceCount: 2 }); const formatted2 = formatCode(code, {}); console.log(formatted2);
Debug
Known issues
breakingIn v1.7.0, the default value for 'includeCompilerVersion' changed from false to true, which may add a compiler version comment to formatted output.
fix
Set includeCompilerVersion: false in options to restore previous behavior.
affects: >=1.7.0
breakingIn v1.6.0, the 'keywordCase' option default changed from 'lower' to 'original', which may produce different formatting for existing projects.
fix
Explicitly set keywordCase: 'lower' in bsfmt.json or API options if you want the old default.
affects: >=1.6.0
breakingIn v1.5.0, the 'formatIndent' option was introduced; previous versions always formatted indentation. If you relied on preserving original indentation, set formatIndent: false.
fix
Add formatIndent: false to bsfmt.json or API options to skip indentation changes.
affects: >=1.5.0
deprecatedThe function 'format' (as in import { format } from 'brighterscript-formatter') is deprecated since v1.4.0; use 'formatCode' instead.
fix
Replace format with formatCode in your code.
affects: >=1.4.0
gotchaThe formatter may add a trailing newline to files; this can cause unwanted diffs if your project does not require a trailing newline.
fix
Use the 'insertFinalNewline' option (if available) to control trailing newline behavior; check documentation for current options.
affects: *
gotchaWhen using the CLI with --write, files are overwritten in-place. It is recommended to commit changes before running to avoid data loss from unexpected formatting changes.
fix
Always commit or backup files before using --write, or use --check first to preview changes.
affects: *
Errors
Common errors & fixes
TypeError: (0 , brighterscript_formatter.formatCode) is not a function
Importing package incorrectly in a CommonJS environment without using default export.
fix
Use import { formatCode } from 'brighterscript-formatter'; or if using require, use const { formatCode } = require('brighterscript-formatter');
Error: Cannot find module 'brighterscript-formatter'
Package not installed or not in node_modules.
fix
Run npm install brighterscript-formatter --save-dev
Error: No files matched the provided patterns.
Glob pattern does not match any files when using CLI.
fix
Ensure glob patterns are correct, e.g., 'source/**/*.brs' and include extension. Use absolute paths if needed with --absolute flag.
Upgrade
Version history
1.7.26latest on npm
Audit
Dependencies
brighterscriptoptionalPeer dependency for BrighterScript language features
chalkrequiredUsed for CLI output coloring
Agent activity
4 hits · last 30 days
node
4
Resources
brighterscript-formatter — npm install brighterscript-formatter · libregistry