TSLint configuration that disables all formatting-related rules to enable seamless use of TSLint with Prettier
npx @tessl/cli install tessl/npm-tslint-config-prettier@1.18.00
# TSLint Config Prettier
1
2
TSLint Config Prettier is a TSLint configuration package that disables all formatting-related rules that conflict with Prettier. It ensures seamless integration between TSLint and Prettier by preventing rule conflicts, allowing TSLint to handle code quality while Prettier handles consistent formatting.
3
4
## Package Information
5
6
- **Package Name**: tslint-config-prettier
7
- **Package Type**: npm
8
- **Language**: TypeScript/JavaScript
9
- **Installation**: `npm install --save-dev tslint-config-prettier`
10
11
## Core Imports
12
13
For TSLint configuration usage (extends):
14
15
```json
16
{
17
"extends": [
18
"tslint:latest",
19
"tslint-config-prettier"
20
]
21
}
22
```
23
24
For programmatic conflict checking:
25
26
```typescript
27
import { check } from "tslint-config-prettier/lib/checker";
28
```
29
30
CommonJS:
31
32
```javascript
33
const { check } = require("tslint-config-prettier/lib/checker");
34
```
35
36
## Basic Usage
37
38
### As TSLint Configuration Extension
39
40
Add to your `tslint.json` file (must be at the end of extends array):
41
42
```json
43
{
44
"extends": [
45
"tslint:latest",
46
"tslint-react",
47
"tslint-eslint-rules",
48
"tslint-config-prettier"
49
]
50
}
51
```
52
53
### Using the CLI Checker Tool
54
55
```bash
56
# Check for conflicts between TSLint config and Prettier
57
npx tslint-config-prettier-check ./tslint.json
58
59
# Check multiple configuration files
60
npx tslint-config-prettier-check ./tslint.json ./other-tslint.json
61
```
62
63
### Programmatic Conflict Detection
64
65
```typescript
66
import { check } from "tslint-config-prettier/lib/checker";
67
68
// Check for conflicts in configuration files
69
check(["./tslint.json", "./other-tslint.json"]);
70
```
71
72
## Capabilities
73
74
### TSLint Configuration
75
76
The main package export is a TSLint configuration that systematically disables 57 formatting rules that conflict with Prettier across 10 different rule providers.
77
78
**Main Configuration File**: `lib/index.json`
79
80
```json { .api }
81
{
82
"rules": {
83
"align": false,
84
"array-bracket-spacing": false,
85
"arrow-parens": false,
86
"block-spacing": false,
87
"brace-style": false,
88
"conditional-expression-parens": false,
89
"eofline": false,
90
"import-destructuring-spacing": false,
91
"import-spacing": false,
92
"indent": false,
93
"jsx-alignment": false,
94
"jsx-attribute-spacing": false,
95
"jsx-curly-spacing": false,
96
"jsx-equals-spacing": false,
97
"jsx-expression-spacing": false,
98
"jsx-no-closing-bracket-newline": false,
99
"jsx-no-multiline-js": false,
100
"jsx-space-before-trailing-slash": false,
101
"jsx-wrap-multiline": false,
102
"linebreak-style": false,
103
"literal-spacing": false,
104
"max-line-length": false,
105
"multiline-arrow": false,
106
"new-parens": false,
107
"newline-per-chained-call": false,
108
"no-consecutive-blank-lines": false,
109
"no-empty-line-after-opening-brace": false,
110
"no-extra-semi": false,
111
"no-irregular-whitespace": false,
112
"no-multi-spaces": false,
113
"no-semicolon-interface": false,
114
"no-trailing-whitespace": false,
115
"no-unnecessary-parens-for-arrow-function-arguments": false,
116
"no-unnecessary-semicolons": false,
117
"number-literal-format": false,
118
"object-curly-spacing": false,
119
"object-literal-key-quotes": false,
120
"one-line": false,
121
"quotemark": false,
122
"react-tsx-curly-spacing": false,
123
"semicolon": false,
124
"space-before-function-paren": false,
125
"space-in-parens": false,
126
"space-within-parens": false,
127
"ter-arrow-parens": false,
128
"ter-arrow-spacing": false,
129
"ter-computed-property-spacing": false,
130
"ter-func-call-spacing": false,
131
"ter-indent": false,
132
"ter-max-len": false,
133
"ter-no-irregular-whitespace": false,
134
"ter-no-tabs": false,
135
"ter-padded-blocks": false,
136
"trailing-comma": false,
137
"type-literal-delimiter": false,
138
"typedef-whitespace": false,
139
"whitespace": false
140
},
141
"jsRules": {
142
"align": false,
143
"array-bracket-spacing": false,
144
"arrow-parens": false,
145
"block-spacing": false,
146
"brace-style": false,
147
"conditional-expression-parens": false,
148
"eofline": false,
149
"import-destructuring-spacing": false,
150
"import-spacing": false,
151
"indent": false,
152
"jsx-alignment": false,
153
"jsx-attribute-spacing": false,
154
"jsx-curly-spacing": false,
155
"jsx-equals-spacing": false,
156
"jsx-expression-spacing": false,
157
"jsx-no-closing-bracket-newline": false,
158
"jsx-no-multiline-js": false,
159
"jsx-space-before-trailing-slash": false,
160
"jsx-wrap-multiline": false,
161
"linebreak-style": false,
162
"literal-spacing": false,
163
"max-line-length": false,
164
"multiline-arrow": false,
165
"new-parens": false,
166
"newline-per-chained-call": false,
167
"no-consecutive-blank-lines": false,
168
"no-empty-line-after-opening-brace": false,
169
"no-extra-semi": false,
170
"no-irregular-whitespace": false,
171
"no-multi-spaces": false,
172
"no-semicolon-interface": false,
173
"no-trailing-whitespace": false,
174
"no-unnecessary-parens-for-arrow-function-arguments": false,
175
"no-unnecessary-semicolons": false,
176
"number-literal-format": false,
177
"object-curly-spacing": false,
178
"object-literal-key-quotes": false,
179
"one-line": false,
180
"quotemark": false,
181
"react-tsx-curly-spacing": false,
182
"semicolon": false,
183
"space-before-function-paren": false,
184
"space-in-parens": false,
185
"space-within-parens": false,
186
"ter-arrow-parens": false,
187
"ter-arrow-spacing": false,
188
"ter-computed-property-spacing": false,
189
"ter-func-call-spacing": false,
190
"ter-indent": false,
191
"ter-max-len": false,
192
"ter-no-irregular-whitespace": false,
193
"ter-no-tabs": false,
194
"ter-padded-blocks": false,
195
"trailing-comma": false,
196
"type-literal-delimiter": false,
197
"typedef-whitespace": false,
198
"whitespace": false
199
}
200
}
201
```
202
203
**Supported Rule Providers:**
204
- codelyzer - Angular-specific TSLint rules
205
- tslint - Core TSLint rules
206
- tslint-consistent-codestyle - Consistent code style rules
207
- tslint-divid - Additional linting rules
208
- tslint-eslint-rules - ESLint rules ported to TSLint
209
- tslint-immutable - Immutable programming rules
210
- tslint-microsoft-contrib - Microsoft-contributed rules
211
- tslint-misc-rules - Miscellaneous rules
212
- tslint-react - React-specific TSLint rules
213
- vrsource-tslint-rules - VRSource TSLint rules
214
215
### CLI Conflict Checker
216
217
Command-line tool for detecting conflicts between TSLint configuration and Prettier formatting rules.
218
219
**Binary**: `tslint-config-prettier-check`
220
221
```bash { .api }
222
# Usage: tslint-config-prettier-check <pathToConfigFile> [pathToConfigFile2] [...]
223
tslint-config-prettier-check ./tslint.json
224
tslint-config-prettier-check ./tslint.json ./other-config.json
225
```
226
227
**Behavior**:
228
- Analyzes provided TSLint configuration files
229
- Detects rules that conflict with Prettier formatting
230
- Reports conflicting rules to stderr with file paths
231
- Exits with code 1 if conflicts found, 0 if no conflicts
232
- Shows usage message if no configuration files provided
233
234
**Example Output**:
235
```
236
Conflict rule(s) detected in ./tslint.json:
237
quotemark
238
semicolon
239
trailing-comma
240
```
241
242
### Programmatic Conflict Detection
243
244
Node.js module providing programmatic access to conflict detection functionality.
245
246
```typescript { .api }
247
/**
248
* Check for conflicts between TSLint configuration files and Prettier
249
* @param configFilePaths - Array of TSLint configuration file paths to check
250
* @returns void - Logs conflicts and sets process.exitCode on conflicts/errors
251
*/
252
function check(configFilePaths: string[]): void;
253
```
254
255
**Usage Example**:
256
257
```typescript
258
import { check } from "tslint-config-prettier/lib/checker";
259
260
// Check single configuration file
261
check(["./tslint.json"]);
262
263
// Check multiple configuration files
264
check(["./tslint.json", "./shared-tslint.json"]);
265
266
// Check will log conflicts to console and set process.exitCode = 1 if conflicts found
267
```
268
269
**Error Handling**:
270
- Logs usage information if empty array provided
271
- Logs error messages for file reading errors or configuration parsing errors
272
- Sets `process.exitCode = 1` when conflicts detected or errors occur
273
- Continues processing all provided files even if some fail
274
275
## Types
276
277
```typescript { .api }
278
// TSLint Configuration structure (from tslint library)
279
interface Configuration.RawConfigFile {
280
rules?: { [key: string]: any };
281
jsRules?: { [key: string]: any };
282
extends?: string | string[];
283
}
284
285
// Internal conflict detection types
286
interface Configuration.IConfigurationFile {
287
rules: Map<string, Configuration.IRule>;
288
jsRules: Map<string, Configuration.IRule>;
289
}
290
291
interface Configuration.IRule {
292
ruleSeverity: "error" | "warning" | "off";
293
ruleArguments: any[];
294
}
295
```
296
297
## Architecture
298
299
TSLint Config Prettier follows a simple but effective architecture:
300
301
1. **Rule Discovery**: Build-time process scans source rule directories to identify all formatting rules across supported rule providers
302
2. **Configuration Generation**: Automatically generates `lib/index.json` with all discovered rules disabled (`false`)
303
3. **Conflict Detection**: Runtime analysis compares active TSLint rules against the comprehensive list of disabled formatting rules
304
4. **Multiple Interfaces**: Provides both CLI and programmatic access to conflict detection functionality
305
306
The package operates as both a passive configuration (when extended in `tslint.json`) and an active analysis tool (via CLI or programmatic API) to ensure TSLint and Prettier work harmoniously together.