or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

docs

index.md
tile.json

tessl/npm-tslint-config-airbnb

A TSLint configuration that implements the Airbnb JavaScript Style Guide rules for TypeScript projects

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

To install, run

npx @tessl/cli install tessl/npm-tslint-config-airbnb@5.11.0

index.mddocs/

TSLint Config Airbnb

TSLint Config Airbnb is a comprehensive TSLint configuration package that implements the Airbnb JavaScript Style Guide rules for TypeScript projects. It provides a curated set of 52 linting rules that enforce consistent code style and best practices across TypeScript codebases.

Important: This package is deprecated in favor of migrating to ESLint with @typescript-eslint for modern TypeScript development workflows.

Package Information

  • Package Name: tslint-config-airbnb
  • Package Type: npm
  • Language: JavaScript
  • Installation: npm install tslint-config-airbnb --save-dev
  • Peer Dependencies: tslint ^5.11.0

Core Imports

This package is imported as a TSLint configuration extension, not as a traditional ES module or CommonJS module:

{
  "extends": ["tslint-config-airbnb"]
}

Basic Usage

# Install the package
npm install tslint-config-airbnb --save-dev

# Install peer dependency if not already present
npm install tslint --save-dev

Create or update your tslint.json:

{
  "extends": ["tslint-config-airbnb"]
}

Run TSLint:

# Check files
npx tslint 'src/**/*.ts'

# Auto-fix where possible  
npx tslint 'src/**/*.ts' --fix

Architecture

The configuration is built around several key components:

  • Rule Configuration Object: Main export containing TSLint rule definitions and rule directory paths
  • External Rule Dependencies: Integration with additional TSLint rule packages for extended functionality
  • Airbnb Style Guide Mapping: 52 configured rules that directly correspond to Airbnb JavaScript Style Guide sections

Capabilities

TSLint Configuration Export

The main functionality - exports a complete TSLint configuration object that implements Airbnb JavaScript Style Guide rules.

/**
 * Main TSLint configuration object implementing Airbnb JavaScript Style Guide
 * Exported via CommonJS module.exports pattern
 */
interface TSLintConfig {
  /** Array of directory paths containing additional TSLint rule modules */
  rulesDirectory: string[];
  /** Object containing all configured TSLint rules with their settings */
  rules: Record<string, RuleConfiguration>;
}

/** TSLint rule configuration - can be boolean, array, or object */
type RuleConfiguration = boolean | any[] | Record<string, any>;

Configuration Structure:

const config = {
  rulesDirectory: [
    // Path to tslint-consistent-codestyle rules
    path.join(path.dirname(require.resolve('tslint-consistent-codestyle')), './'),
    // Path to tslint-eslint-rules dist/rules directory  
    path.join(path.dirname(require.resolve('tslint-eslint-rules')), 'dist/rules'),
    // Path to tslint-microsoft-contrib rules
    path.join(path.dirname(require.resolve('tslint-microsoft-contrib')), './'),
  ],
  rules: {
    // 52 individual rule configurations implementing Airbnb style guide
    'prefer-const': true,
    'no-var-keyword': true,
    'object-literal-shorthand': true,
    // ... (additional 54 rules)
  }
};

Rule Categories

The configuration includes rules across these categories:

Variable Declarations:

{
  /** Prefer const over let for variables that are never reassigned (Airbnb 2.1, 13.1) */
  'prefer-const': true,
  /** Disallow var keyword usage (Airbnb 2.2) */
  'no-var-keyword': true,
  /** Require consistent variable declarations in for-loops (Airbnb 13.2) */
  'one-variable-per-declaration': [true, 'ignore-for-loop']
}

Object and Array Literals:

{
  /** Require object literal shorthand syntax when possible (Airbnb 3.3, 3.4) */
  'object-literal-shorthand': true,
  /** Require shorthand properties to appear first (Airbnb 3.5) */
  'object-shorthand-properties-first': true,
  /** Control object literal key quotes (Airbnb 3.6) */
  'object-literal-key-quotes': [true, 'as-needed'],
  /** Prefer array literal syntax over Array constructor (Airbnb 4.1) */
  'prefer-array-literal': true
}

String and Template Literals:

{
  /** Configure quote style for strings (Airbnb 6.1, 6.5) */
  quotemark: [true, 'single', 'avoid-escape', 'avoid-template', 'jsx-double'],
  /** Prefer template strings over string concatenation (Airbnb 6.3) */
  'prefer-template': true,
  /** Disallow eval() usage (Airbnb 6.4) */
  'no-eval': true
}

Function Declarations:

{
  /** Configure spacing before function parentheses (Airbnb 7.11, 19.3) */
  'space-before-function-paren': [
    true,
    { anonymous: 'always', named: 'never' }
  ],
  /** Disallow parameter reassignment (Airbnb 7.12) */
  'no-parameter-reassignment': true,
  /** Prefer arrow functions for callbacks (Airbnb 8.1) */
  'ter-prefer-arrow-callback': [true],
  /** Configure arrow function parentheses (Airbnb 8.4) */
  'ter-arrow-parens': [true, 'as-needed', { 'requireForBlockBody': true }]
}

Code Formatting and Style:

{
  /** Configure indentation (Airbnb 19.1) */
  indent: [true, 'spaces'],
  'ter-indent': [true, 2, { 'SwitchCase': 1 }],
  /** Configure whitespace rules (Airbnb 19.2-19.4) */
  whitespace: [
    true,
    'check-branch',
    'check-decl', 
    'check-operator',
    'check-preblock',
    'check-separator'
  ],
  /** Require newline at end of file (Airbnb 19.5) */
  eofline: true,
  /** Configure maximum line length (Airbnb 19.12) */
  'max-line-length': [true, 100]
}

Naming Conventions:

{
  /** Configure function and method naming (Airbnb 23.1) */
  'function-name': [
    true,
    {
      'function-regex': /^[a-z$][\w\d]+$/,
      'method-regex': /^[a-z$][\w\d]+$/,
      'private-method-regex': /^[a-z$][\w\d]+$/,
      'protected-method-regex': /^[a-z$][\w\d]+$/,
      'static-method-regex': /^[a-z$][\w\d]+$/
    }
  ],
  /** Configure variable naming (Airbnb 23.2) */
  'variable-name': [true, 'check-format'],
  /** Require PascalCase for class names (Airbnb 23.3) */
  'class-name': true
}

Dependencies Integration

The configuration integrates with external TSLint rule packages:

/**
 * External rule package dependencies providing additional TSLint rules
 */
interface ExternalRuleDependencies {
  /** Consistent code style rules */
  'tslint-consistent-codestyle': '^1.14.1';
  /** ESLint rules ported to TSLint */
  'tslint-eslint-rules': '^5.4.0';
  /** Microsoft TypeScript linting rules */
  'tslint-microsoft-contrib': '~5.2.1';
}

Usage Examples

Basic Project Setup:

# Install in existing TypeScript project
npm install --save-dev tslint tslint-config-airbnb

# Create tslint.json
echo '{"extends": ["tslint-config-airbnb"]}' > tslint.json

# Run linting
npx tslint 'src/**/*.ts'

Extending Configuration:

{
  "extends": ["tslint-config-airbnb"],
  "rules": {
    "max-line-length": [true, 120],
    "quotemark": [true, "double"]
  }
}

Integration with npm scripts:

{
  "scripts": {
    "lint": "tslint 'src/**/*.ts'",
    "lint:fix": "tslint 'src/**/*.ts' --fix"
  }
}

Migration Path

Important: TSLint is deprecated. Migrate to ESLint:

# Remove TSLint packages
npm uninstall tslint tslint-config-airbnb

# Install ESLint with TypeScript support
npm install --save-dev eslint @typescript-eslint/eslint-plugin eslint-config-airbnb
npx install-peerdeps --dev eslint-config-airbnb

Create .eslintrc.json:

{
  "extends": ["airbnb"],
  "plugins": ["@typescript-eslint"],
  "parser": "@typescript-eslint/parser",
  "rules": {
    "import/no-unresolved": 0,
    "react/jsx-filename-extension": {
      "extensions": [".jsx", ".tsx"]
    }
  }
}

Types

/**
 * TSLint configuration object structure
 */
interface TSLintConfiguration {
  /** Directories containing additional TSLint rule modules */
  rulesDirectory: string[];
  /** TSLint rules configuration mapping */
  rules: Record<string, RuleConfiguration>;
}

/**
 * TSLint rule configuration value
 * Can be a boolean (enable/disable), array with options, or object with settings
 */
type RuleConfiguration = 
  | boolean 
  | [boolean, ...any[]] 
  | Record<string, any>;

/**
 * Rule directory path resolution
 * Uses Node.js require.resolve to find rule package locations
 */
type RuleDirectoryPath = string;