1 | "use strict";
|
2 | Object.defineProperty(exports, "__esModule", { value: true });
|
3 | const fs_1 = require("fs");
|
4 | const prettier_1 = require("prettier");
|
5 | const _1 = require(".");
|
6 | const init_tslint_1 = require("./commands/init-tslint");
|
7 | const init_typescript_1 = require("./commands/init-typescript");
|
8 | const rules_1 = require("./rules");
|
9 | const utils_1 = require("./utils");
|
10 | const comments = {
|
11 | 'no-unused-variable': [
|
12 | 'Deprecated since TypeScript 2.9. Please use the built-in compiler checks instead.'
|
13 | ],
|
14 | 'switch-default': [
|
15 | '**TypeScript-only**: Unnecessary because of the TypeScript setting `--noImplicitReturns`.'
|
16 | ]
|
17 | };
|
18 | for (const ruleName of Object.keys(rules_1.prettierRules)) {
|
19 | comments[ruleName] = [
|
20 | ...(comments[ruleName] || []),
|
21 | 'Unnecessary because of Prettier.'
|
22 | ];
|
23 | }
|
24 |
|
25 | const packageName = require('../package.json').name;
|
26 |
|
27 | const tsLintVersion = require('tslint/package.json').version;
|
28 | const readme = `
|
29 | # ${packageName}
|
30 |
|
31 | [![Package Version](https://img.shields.io/npm/v/${packageName}.svg)](https://yarnpkg.com/en/package/${packageName})
|
32 | [![Build Status](https://travis-ci.org/clebert/${packageName}.svg?branch=master)](https://travis-ci.org/clebert/${packageName})
|
33 |
|
34 | > An opinionated TSLint configuration preset. Works best together with strict
|
35 | > TypeScript settings and Prettier.
|
36 |
|
37 | ## Getting started
|
38 |
|
39 | First, install \`${packageName}\` as a dev dependency:
|
40 |
|
41 | \`\`\`sh
|
42 | # Install using Yarn
|
43 | yarn add -D ${packageName} tslint typescript
|
44 | \`\`\`
|
45 |
|
46 | \`\`\`sh
|
47 | # Install using NPM
|
48 | npm install -D ${packageName} tslint typescript
|
49 | \`\`\`
|
50 |
|
51 | Then use the [CLI](#${init_tslint_1.commandName}) to create a TSLint configuration
|
52 | file that extends this configuration preset:
|
53 |
|
54 | \`\`\`sh
|
55 | npx ts-config ${init_tslint_1.commandName}
|
56 | \`\`\`
|
57 |
|
58 | _Optional:_ Use the [CLI](#${init_typescript_1.commandName}) to create a TypeScript
|
59 | configuration file with strict settings:
|
60 |
|
61 | \`\`\`sh
|
62 | npx ts-config ${init_typescript_1.commandName}
|
63 | \`\`\`
|
64 |
|
65 | Now you can run TSLint as follows (assuming that TypeScript and Prettier are
|
66 | configured accordingly):
|
67 |
|
68 | \`\`\`sh
|
69 | # Lint your TS sources
|
70 | npx tslint --config tslint.json --project . '**/*.{ts,tsx}'
|
71 | \`\`\`
|
72 |
|
73 | \`\`\`sh
|
74 | # Lint your JS sources
|
75 | npx tslint --config tslint.json '**/*.{js,jsx}'
|
76 | \`\`\`
|
77 |
|
78 | ## CLI commands
|
79 |
|
80 | ### ${init_tslint_1.commandName}
|
81 |
|
82 | \`\`\`sh
|
83 | $ npx ts-config ${init_tslint_1.commandName} help
|
84 |
|
85 | ${utils_1.getHelp(init_tslint_1.commandName)}
|
86 | \`\`\`
|
87 |
|
88 | ### ${init_typescript_1.commandName}
|
89 |
|
90 | \`\`\`sh
|
91 | $ npx ts-config ${init_typescript_1.commandName} help
|
92 |
|
93 | ${utils_1.getHelp(init_typescript_1.commandName)}
|
94 | \`\`\`
|
95 |
|
96 | ## Configuration preset
|
97 |
|
98 | This dynamically generated configuration preset is compatible to
|
99 | [TSLint](https://palantir.github.io/tslint/) in version \`^5.10.0\`. It is based
|
100 | on the built-in configuration preset \`tslint:all\`:
|
101 |
|
102 | > **\`tslint:all\`** turns on all rules to their strictest settings. This will
|
103 | > use type checking, so it must be combined with the \`--project option\`.
|
104 | > (Exceptions include rules such as \`"ban"\`, \`"import-blacklist"\`, and
|
105 | > \`"file-header"\`, which have no sensible defaults, and deprecated rules.)
|
106 |
|
107 | **It is assumed that [TypeScript](https://www.typescriptlang.org/) is configured
|
108 | with strict settings. Also, it is assumed that [Prettier](https://prettier.io/)
|
109 | is used for formatting your sources.**
|
110 |
|
111 | The deviations from the configuration preset
|
112 | [\`tslint:all@${tsLintVersion}\`](https://github.com/palantir/tslint/blob/${tsLintVersion}/src/configs/all.ts)
|
113 | are documented below:
|
114 |
|
115 | - [TypeScript and JavaScript rule overrides](#typescript-and-javascript-rule-overrides)
|
116 | - [TypeScript-only rule overrides](#typescript-only-rule-overrides)
|
117 | - [JavaScript-only rule overrides](#javascript-only-rule-overrides)
|
118 |
|
119 | ### TypeScript and JavaScript rule overrides
|
120 |
|
121 | ${Object.keys(_1.rules)
|
122 | .sort()
|
123 | .filter(ruleName => ruleName in _1.jsRules)
|
124 | .map(ruleName => utils_1.renderRule(ruleName, rules_1.allRules, _1.rules, comments[ruleName]))
|
125 | .filter(Boolean)
|
126 | .join('\n\n')}
|
127 |
|
128 | ### TypeScript-only rule overrides
|
129 |
|
130 | ${Object.keys(_1.rules)
|
131 | .sort()
|
132 | .filter(ruleName => !(ruleName in _1.jsRules))
|
133 | .map(ruleName => utils_1.renderRule(ruleName, rules_1.allRules, _1.rules, comments[ruleName]))
|
134 | .filter(Boolean)
|
135 | .join('\n\n')}
|
136 |
|
137 | ### JavaScript-only rule overrides
|
138 |
|
139 | ${Object.keys(_1.jsRules)
|
140 | .sort()
|
141 | .map(ruleName => utils_1.renderRule(ruleName, _1.rules, _1.jsRules, comments[ruleName]))
|
142 | .filter(Boolean)
|
143 | .join('\n\n')}
|
144 |
|
145 | ---
|
146 |
|
147 | Copyright (c) 2016-present, Clemens Akens. Released under the terms of the
|
148 | [MIT License](https://github.com/clebert/${packageName}/blob/master/LICENSE).
|
149 | `.trimLeft();
|
150 | const formattedReadme = prettier_1.format(readme, {
|
151 | parser: 'markdown',
|
152 | proseWrap: 'always'
|
153 | });
|
154 | fs_1.writeFileSync('README.md', formattedReadme, { encoding: 'utf8' });
|
155 |
|
\ | No newline at end of file |