CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/npm-loopback--build

A comprehensive set of build tools and configurations for LoopBack 4 and TypeScript projects providing CLI commands for compilation, linting, testing, and coverage

Pending
Quality

Pending

Does it follow best practices?

Impact

Pending

No eval scenarios have been run

SecuritybySnyk

Pending

The risk profile of this skill

Overview
Eval results
Files

code-formatting.mddocs/

Code Formatting

Prettier integration with automatic configuration discovery and file-first configuration precedence for consistent code formatting.

Capabilities

lb-prettier Command

Runs Prettier with automatic configuration discovery and sensible defaults.

/**
 * Prettier formatter function with configuration discovery
 * @param argv - Command line arguments including files and options
 * @param options - Execution options for dry run and process control
 * @returns ChildProcess when executed, string when dry run
 */
function prettier(argv: string[], options?: RunOptions): ChildProcess | string;

CLI Usage:

# Format files
lb-prettier "**/*.ts" "**/*.js"

# Check formatting without changes
lb-prettier --check "**/*.ts"

# List files that would be formatted
lb-prettier --list-different "**/*.ts"

# Write formatted files
lb-prettier --write "**/*.ts" "**/*.js"

# Format specific files
lb-prettier src/index.ts src/utils.ts

Programmatic Usage:

import { prettier } from "@loopback/build";

// Format TypeScript files
const child = prettier(["--write", "**/*.ts"]);

// Dry run to see command
const command = prettier(["--check", "src/"], { dryRun: true });
console.log(command); // Shows the Prettier command that would be executed

// Format with custom working directory
prettier(["--write", "src/"], { cwd: "/path/to/project" });

Configuration Discovery

Automatically discovers Prettier configuration files with file-first precedence.

Configuration Search Order:

  1. Project-specific configuration (if --config, --no-config, or --find-config-path not provided)
  2. .prettierrc in project root
  3. Falls back to @loopback/build/config/.prettierrc

Configuration Precedence: Uses --config-precedence prefer-file to prioritize project configuration files over CLI options.

Default Configuration

Provides sensible defaults for LoopBack and TypeScript projects.

// @loopback/build/config/.prettierrc contents:
interface PrettierConfig {
  bracketSpacing: false;    // {foo} instead of { foo }
  singleQuote: true;        // 'string' instead of "string"
  printWidth: 80;           // Line wrap at 80 characters
  trailingComma: "all";     // Trailing commas everywhere
  arrowParens: "avoid";     // x => x instead of (x) => x
}

File Pattern Support

Supports glob patterns and specific file targeting.

// Glob patterns for multiple files
// Specific file paths
// Supports all file types that Prettier handles

Common File Patterns:

# TypeScript and JavaScript
lb-prettier "**/*.{ts,js}"

# All supported formats
lb-prettier "**/*.{ts,js,json,md,yml,yaml}"

# Specific directories
lb-prettier "src/**/*.ts" "test/**/*.ts"

Command Line Option Passthrough

All Prettier command line options are supported and passed through.

interface PrettierOptions {
  "--write": boolean;              // Write formatted files to disk
  "--check": boolean;              // Check if files are formatted
  "--list-different": boolean;     // List files that differ from Prettier formatting
  "--config": string;              // Path to configuration file
  "--no-config": boolean;          // Do not look for configuration file
  "--find-config-path": string;    // Find and return path to configuration file
  "--ignore-path": string;         // Path to ignore file
  "--no-ignore": boolean;          // Do not look for ignore files
  "--with-node-modules": boolean;  // Process files in node_modules
  "--parser": string;              // Parser to use (auto-detected by default)
  "--print-width": number;         // Line wrap width
  "--tab-width": number;           // Tab width
  "--use-tabs": boolean;           // Use tabs instead of spaces
  "--semi": boolean;               // Print semicolons
  "--single-quote": boolean;       // Use single quotes
  "--quote-props": string;         // Quote object properties
  "--jsx-single-quote": boolean;   // Use single quotes in JSX
  "--trailing-comma": string;      // Trailing comma policy
  "--bracket-spacing": boolean;    // Print spaces inside object brackets
  "--bracket-same-line": boolean;  // Put closing bracket on same line
  "--arrow-parens": string;        // Arrow function parentheses policy
  "--range-start": number;         // Format from this character
  "--range-end": number;           // Format to this character
  "--stdin-filepath": string;      // File path for stdin input
  "--end-of-line": string;         // Line ending style
}

Usage Examples

Basic Formatting:

import { prettier } from "@loopback/build";

// Format all TypeScript files
prettier(["--write", "**/*.ts"], { dryRun: false });

// Check formatting without changes
prettier(["--check", "src/"], { dryRun: false });

Package.json Integration:

{
  "scripts": {
    "prettier:cli": "lb-prettier \"**/*.ts\" \"**/*.js\"",
    "prettier:check": "npm run prettier:cli -- --list-different",
    "prettier:fix": "npm run prettier:cli -- --write",
    "format": "npm run prettier:fix"
  }
}

Custom Configuration:

# Use custom config file
lb-prettier --config .prettierrc.custom.json --write "**/*.ts"

# Ignore configuration files
lb-prettier --no-config --write --single-quote "**/*.ts"

# Custom ignore file
lb-prettier --ignore-path .prettierignore.custom --write "**/*.ts"

Integration with Other Tools

Works seamlessly with ESLint and other development tools.

ESLint Integration:

  • LoopBack ESLint config is compatible with default Prettier settings
  • No conflicting rules between ESLint and Prettier formatting

Editor Integration:

  • Configuration files are automatically detected by editors
  • Supports format-on-save workflows
  • Compatible with VS Code, WebStorm, and other editors

Error Handling

Prettier errors are properly handled and reported.

// Syntax errors in files are reported with file location
// Configuration errors show helpful error messages  
// Process exits with non-zero code on formatting errors (when using --check)
// Invalid file patterns are reported clearly

docs

code-coverage.md

code-formatting.md

code-linting.md

file-cleanup.md

index.md

process-management.md

test-execution.md

typescript-compilation.md

tile.json