or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

docs

index.md
tile.json

tessl/npm-loopback--tslint-config

Shared TSLint config to enforce a consistent code style for LoopBack development

Workspace
tessl
Visibility
Public
Created
Last updated
Describes
npmpkg:npm/@loopback/tslint-config@2.1.x

To install, run

npx @tessl/cli install tessl/npm-loopback--tslint-config@2.1.0

index.mddocs/

@loopback/tslint-config

@loopback/tslint-config provides shared TSLint configurations to enforce consistent code style and quality standards for LoopBack TypeScript development. It offers two main configuration files: a core common configuration for essential development-time linting, and an extended build configuration that includes type-checking rules for comprehensive build-time validation.

Package Information

  • Package Name: @loopback/tslint-config
  • Package Type: npm
  • Language: TypeScript (TSLint configuration)
  • Installation: npm install @loopback/tslint-config

Core Imports

This package doesn't provide programmatic imports. Instead, configurations are consumed through TSLint's extends mechanism:

Basic tslint.json:

{
  "$schema": "http://json.schemastore.org/tslint",
  "extends": ["@loopback/tslint-config/tslint.common.json"]
}

Build-time tslint.build.json:

{
  "$schema": "http://json.schemastore.org/tslint",
  "extends": ["@loopback/tslint-config/tslint.build.json"]
}

Basic Usage

After installing the package, configure TSLint to extend the LoopBack configurations:

For development-time linting (editor integration):

{
  "$schema": "http://json.schemastore.org/tslint",
  "extends": ["@loopback/tslint-config/tslint.common.json"],
  "rules": {
    // Add any project-specific rule overrides here
  }
}

For comprehensive build-time linting:

{
  "$schema": "http://json.schemastore.org/tslint",
  "extends": ["@loopback/tslint-config/tslint.build.json"],
  "rules": {
    // Add any project-specific rule overrides here
  }
}

Capabilities

Common Configuration (tslint.common.json)

Core TSLint configuration with essential rules for TypeScript development that work without type checking.

{
  "$schema": "http://json.schemastore.org/tslint",
  "rulesDirectory": ["tslint-consistent-codestyle"],
  "rules": {
    "adjacent-overload-signatures": true,
    "prefer-for-of": true,
    "unified-signatures": true,
    "no-any": true,
    "label-position": true,
    "no-arg": true,
    "no-construct": true,
    "no-duplicate-variable": true,
    "no-invalid-this": true,
    "no-misused-new": true,
    "no-shadowed-variable": true,
    "no-string-throw": true,
    "no-unused": [true, "ignore-parameters"],
    "no-unused-expression": true,
    "no-var-keyword": true,
    "triple-equals": [true, "allow-null-check", "allow-undefined-check"]
  }
}

Configuration Path: @loopback/tslint-config/tslint.common.json

Rule Categories:

  • TypeScript Features: adjacent-overload-signatures, prefer-for-of, unified-signatures, no-any
  • Error Prevention: label-position, no-arg, no-construct, no-duplicate-variable, no-invalid-this, no-misused-new, no-shadowed-variable, no-string-throw
  • Code Quality: no-unused, no-unused-expression, no-var-keyword, triple-equals

Dependencies Required: tslint-consistent-codestyle plugin for enhanced code style consistency.

Build Configuration (tslint.build.json)

Extended TSLint configuration that includes all common rules plus additional type-checking rules for build-time validation.

{
  "$schema": "http://json.schemastore.org/tslint",
  "extends": ["./tslint.common.json"],
  "rules": {
    "await-promise": [true, "PromiseLike", "RequestPromise"],
    "no-floating-promises": [true, "PromiseLike", "RequestPromise"],
    "no-unused-variable": false,
    "no-void-expression": [true, "ignore-arrow-function-shorthand"]
  }
}

Configuration Path: @loopback/tslint-config/tslint.build.json

Inherits: All rules from tslint.common.json

Additional Rules:

  • Promise Handling: await-promise, no-floating-promises (supports PromiseLike and RequestPromise types)
  • Expression Rules: no-void-expression with arrow function shorthand support
  • Rule Overrides: Explicitly disables no-unused-variable in favor of the no-unused rule from common config

Use Case: Build pipelines and comprehensive type-checking validation where full TypeScript compilation context is available.

Configuration Details

Rule Descriptions

TypeScript-specific rules:

  • adjacent-overload-signatures: Ensures overloaded functions are grouped together
  • prefer-for-of: Recommends for-of loops over traditional for loops when possible
  • unified-signatures: Warns for overloads that could be unified into a single signature
  • no-any: Prohibits usage of the any type

Error prevention rules:

  • no-arg: Disallows access to arguments.callee
  • no-construct: Disallows calling constructor of String, Number, and Boolean
  • no-duplicate-variable: Disallows duplicate variable declarations
  • no-invalid-this: Disallows using this in classes incorrectly
  • no-misused-new: Warns on apparent attempts to define constructors for interfaces
  • no-shadowed-variable: Disallows shadowing variable declarations
  • no-string-throw: Flags throwing plain strings or concatenations of strings
  • no-unused-expression: Disallows unused expression statements
  • triple-equals: Requires === and !== over == and !=

Build-time specific rules:

  • await-promise: Warns for awaiting a value that is not a Promise
  • no-floating-promises: Requires Promise-returning functions to be handled appropriately
  • no-void-expression: Requires expressions of type void to be used in statement position

Dependencies

Runtime Dependencies:

{
  "dependencies": {
    "tslint-consistent-codestyle": "^1.14.1"
  }
}

Peer Dependencies:

{
  "peerDependencies": {
    "tslint": ">=5.11.0"
  }
}

Environment Requirements:

{
  "engines": {
    "node": ">=8.9"
  }
}

Usage Examples

Basic Project Setup

Create a tslint.json file in your project root:

{
  "$schema": "http://json.schemastore.org/tslint",
  "extends": ["@loopback/tslint-config/tslint.common.json"],
  "rules": {
    // Override specific rules if needed
    "no-console": true
  }
}

Build Pipeline Integration

Create a separate tslint.build.json for your build process:

{
  "$schema": "http://json.schemastore.org/tslint",
  "extends": ["@loopback/tslint-config/tslint.build.json"],
  "rules": {
    // Build-specific overrides
  }
}

Then run TSLint with type checking:

tslint --project tsconfig.json --config tslint.build.json 'src/**/*.ts'

IDE Integration

Most TypeScript-enabled editors will automatically use tslint.json for real-time linting. The common configuration is optimized for this use case as it doesn't require type information and provides fast feedback.

Custom Rule Extensions

You can extend the LoopBack configuration with your own rules:

{
  "$schema": "http://json.schemastore.org/tslint",
  "extends": ["@loopback/tslint-config/tslint.common.json"],
  "rules": {
    // Disable a rule from the base config
    "no-any": false,
    // Add additional rules
    "max-line-length": [true, 120],
    "prefer-const": true
  }
}