or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

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

0

# TSLint Config Airbnb

1

2

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.

3

4

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

5

6

## Package Information

7

8

- **Package Name**: tslint-config-airbnb

9

- **Package Type**: npm

10

- **Language**: JavaScript

11

- **Installation**: `npm install tslint-config-airbnb --save-dev`

12

- **Peer Dependencies**: `tslint ^5.11.0`

13

14

## Core Imports

15

16

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

17

18

```json

19

{

20

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

21

}

22

```

23

24

## Basic Usage

25

26

```bash

27

# Install the package

28

npm install tslint-config-airbnb --save-dev

29

30

# Install peer dependency if not already present

31

npm install tslint --save-dev

32

```

33

34

Create or update your `tslint.json`:

35

36

```json

37

{

38

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

39

}

40

```

41

42

Run TSLint:

43

44

```bash

45

# Check files

46

npx tslint 'src/**/*.ts'

47

48

# Auto-fix where possible

49

npx tslint 'src/**/*.ts' --fix

50

```

51

52

## Architecture

53

54

The configuration is built around several key components:

55

56

- **Rule Configuration Object**: Main export containing TSLint rule definitions and rule directory paths

57

- **External Rule Dependencies**: Integration with additional TSLint rule packages for extended functionality

58

- **Airbnb Style Guide Mapping**: 52 configured rules that directly correspond to Airbnb JavaScript Style Guide sections

59

60

## Capabilities

61

62

### TSLint Configuration Export

63

64

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

65

66

```javascript { .api }

67

/**

68

* Main TSLint configuration object implementing Airbnb JavaScript Style Guide

69

* Exported via CommonJS module.exports pattern

70

*/

71

interface TSLintConfig {

72

/** Array of directory paths containing additional TSLint rule modules */

73

rulesDirectory: string[];

74

/** Object containing all configured TSLint rules with their settings */

75

rules: Record<string, RuleConfiguration>;

76

}

77

78

/** TSLint rule configuration - can be boolean, array, or object */

79

type RuleConfiguration = boolean | any[] | Record<string, any>;

80

```

81

82

**Configuration Structure:**

83

84

```javascript { .api }

85

const config = {

86

rulesDirectory: [

87

// Path to tslint-consistent-codestyle rules

88

path.join(path.dirname(require.resolve('tslint-consistent-codestyle')), './'),

89

// Path to tslint-eslint-rules dist/rules directory

90

path.join(path.dirname(require.resolve('tslint-eslint-rules')), 'dist/rules'),

91

// Path to tslint-microsoft-contrib rules

92

path.join(path.dirname(require.resolve('tslint-microsoft-contrib')), './'),

93

],

94

rules: {

95

// 52 individual rule configurations implementing Airbnb style guide

96

'prefer-const': true,

97

'no-var-keyword': true,

98

'object-literal-shorthand': true,

99

// ... (additional 54 rules)

100

}

101

};

102

```

103

104

### Rule Categories

105

106

The configuration includes rules across these categories:

107

108

**Variable Declarations:**

109

```javascript { .api }

110

{

111

/** Prefer const over let for variables that are never reassigned (Airbnb 2.1, 13.1) */

112

'prefer-const': true,

113

/** Disallow var keyword usage (Airbnb 2.2) */

114

'no-var-keyword': true,

115

/** Require consistent variable declarations in for-loops (Airbnb 13.2) */

116

'one-variable-per-declaration': [true, 'ignore-for-loop']

117

}

118

```

119

120

**Object and Array Literals:**

121

```javascript { .api }

122

{

123

/** Require object literal shorthand syntax when possible (Airbnb 3.3, 3.4) */

124

'object-literal-shorthand': true,

125

/** Require shorthand properties to appear first (Airbnb 3.5) */

126

'object-shorthand-properties-first': true,

127

/** Control object literal key quotes (Airbnb 3.6) */

128

'object-literal-key-quotes': [true, 'as-needed'],

129

/** Prefer array literal syntax over Array constructor (Airbnb 4.1) */

130

'prefer-array-literal': true

131

}

132

```

133

134

**String and Template Literals:**

135

```javascript { .api }

136

{

137

/** Configure quote style for strings (Airbnb 6.1, 6.5) */

138

quotemark: [true, 'single', 'avoid-escape', 'avoid-template', 'jsx-double'],

139

/** Prefer template strings over string concatenation (Airbnb 6.3) */

140

'prefer-template': true,

141

/** Disallow eval() usage (Airbnb 6.4) */

142

'no-eval': true

143

}

144

```

145

146

**Function Declarations:**

147

```javascript { .api }

148

{

149

/** Configure spacing before function parentheses (Airbnb 7.11, 19.3) */

150

'space-before-function-paren': [

151

true,

152

{ anonymous: 'always', named: 'never' }

153

],

154

/** Disallow parameter reassignment (Airbnb 7.12) */

155

'no-parameter-reassignment': true,

156

/** Prefer arrow functions for callbacks (Airbnb 8.1) */

157

'ter-prefer-arrow-callback': [true],

158

/** Configure arrow function parentheses (Airbnb 8.4) */

159

'ter-arrow-parens': [true, 'as-needed', { 'requireForBlockBody': true }]

160

}

161

```

162

163

**Code Formatting and Style:**

164

```javascript { .api }

165

{

166

/** Configure indentation (Airbnb 19.1) */

167

indent: [true, 'spaces'],

168

'ter-indent': [true, 2, { 'SwitchCase': 1 }],

169

/** Configure whitespace rules (Airbnb 19.2-19.4) */

170

whitespace: [

171

true,

172

'check-branch',

173

'check-decl',

174

'check-operator',

175

'check-preblock',

176

'check-separator'

177

],

178

/** Require newline at end of file (Airbnb 19.5) */

179

eofline: true,

180

/** Configure maximum line length (Airbnb 19.12) */

181

'max-line-length': [true, 100]

182

}

183

```

184

185

**Naming Conventions:**

186

```javascript { .api }

187

{

188

/** Configure function and method naming (Airbnb 23.1) */

189

'function-name': [

190

true,

191

{

192

'function-regex': /^[a-z$][\w\d]+$/,

193

'method-regex': /^[a-z$][\w\d]+$/,

194

'private-method-regex': /^[a-z$][\w\d]+$/,

195

'protected-method-regex': /^[a-z$][\w\d]+$/,

196

'static-method-regex': /^[a-z$][\w\d]+$/

197

}

198

],

199

/** Configure variable naming (Airbnb 23.2) */

200

'variable-name': [true, 'check-format'],

201

/** Require PascalCase for class names (Airbnb 23.3) */

202

'class-name': true

203

}

204

```

205

206

### Dependencies Integration

207

208

The configuration integrates with external TSLint rule packages:

209

210

```javascript { .api }

211

/**

212

* External rule package dependencies providing additional TSLint rules

213

*/

214

interface ExternalRuleDependencies {

215

/** Consistent code style rules */

216

'tslint-consistent-codestyle': '^1.14.1';

217

/** ESLint rules ported to TSLint */

218

'tslint-eslint-rules': '^5.4.0';

219

/** Microsoft TypeScript linting rules */

220

'tslint-microsoft-contrib': '~5.2.1';

221

}

222

```

223

224

## Usage Examples

225

226

**Basic Project Setup:**

227

228

```bash

229

# Install in existing TypeScript project

230

npm install --save-dev tslint tslint-config-airbnb

231

232

# Create tslint.json

233

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

234

235

# Run linting

236

npx tslint 'src/**/*.ts'

237

```

238

239

**Extending Configuration:**

240

241

```json

242

{

243

"extends": ["tslint-config-airbnb"],

244

"rules": {

245

"max-line-length": [true, 120],

246

"quotemark": [true, "double"]

247

}

248

}

249

```

250

251

**Integration with npm scripts:**

252

253

```json

254

{

255

"scripts": {

256

"lint": "tslint 'src/**/*.ts'",

257

"lint:fix": "tslint 'src/**/*.ts' --fix"

258

}

259

}

260

```

261

262

## Migration Path

263

264

**Important**: TSLint is deprecated. Migrate to ESLint:

265

266

```bash

267

# Remove TSLint packages

268

npm uninstall tslint tslint-config-airbnb

269

270

# Install ESLint with TypeScript support

271

npm install --save-dev eslint @typescript-eslint/eslint-plugin eslint-config-airbnb

272

npx install-peerdeps --dev eslint-config-airbnb

273

```

274

275

Create `.eslintrc.json`:

276

277

```json

278

{

279

"extends": ["airbnb"],

280

"plugins": ["@typescript-eslint"],

281

"parser": "@typescript-eslint/parser",

282

"rules": {

283

"import/no-unresolved": 0,

284

"react/jsx-filename-extension": {

285

"extensions": [".jsx", ".tsx"]

286

}

287

}

288

}

289

```

290

291

## Types

292

293

```javascript { .api }

294

/**

295

* TSLint configuration object structure

296

*/

297

interface TSLintConfiguration {

298

/** Directories containing additional TSLint rule modules */

299

rulesDirectory: string[];

300

/** TSLint rules configuration mapping */

301

rules: Record<string, RuleConfiguration>;

302

}

303

304

/**

305

* TSLint rule configuration value

306

* Can be a boolean (enable/disable), array with options, or object with settings

307

*/

308

type RuleConfiguration =

309

| boolean

310

| [boolean, ...any[]]

311

| Record<string, any>;

312

313

/**

314

* Rule directory path resolution

315

* Uses Node.js require.resolve to find rule package locations

316

*/

317

type RuleDirectoryPath = string;

318

```