complete-lint 1.0.2 → 1.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +131 -13
- package/package.json +4 -2
package/README.md
CHANGED
|
@@ -24,6 +24,8 @@ npm install complete-lint --save-dev
|
|
|
24
24
|
|
|
25
25
|
(It should be a development dependency because it is only used to lint your code before compilation/deployment.)
|
|
26
26
|
|
|
27
|
+
Note that if you use [pnpm](https://pnpm.io/), you cannot use `complete-lint`, since pnpm does not handle transitive dependencies properly.
|
|
28
|
+
|
|
27
29
|
### Step 2 - Create `eslint.config.mjs`
|
|
28
30
|
|
|
29
31
|
Create a `eslint.config.mjs` file in the root of your repository:
|
|
@@ -32,22 +34,56 @@ Create a `eslint.config.mjs` file in the root of your repository:
|
|
|
32
34
|
// This is the configuration file for ESLint, the TypeScript linter:
|
|
33
35
|
// https://eslint.org/docs/latest/use/configure/
|
|
34
36
|
|
|
37
|
+
// @ts-check
|
|
38
|
+
|
|
35
39
|
import tseslint from "typescript-eslint";
|
|
40
|
+
import { completeConfigBase } from "eslint-config-complete";
|
|
36
41
|
|
|
37
42
|
export default tseslint.config(
|
|
38
|
-
//
|
|
39
|
-
// https://github.com/complete-ts/complete/blob/main/packages/eslint-config-complete/base.js
|
|
40
|
-
...
|
|
43
|
+
// We use "eslint-config-complete" as the base of the config:
|
|
44
|
+
// https://github.com/complete-ts/complete/blob/main/packages/eslint-config-complete/src/base.js
|
|
45
|
+
...completeConfigBase,
|
|
41
46
|
|
|
42
47
|
{
|
|
43
48
|
rules: {
|
|
44
49
|
// Insert changed or disabled rules here, if necessary.
|
|
45
50
|
},
|
|
46
|
-
}
|
|
51
|
+
},
|
|
52
|
+
);
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
### Step 3 - Create `prettier.config.mjs`
|
|
56
|
+
|
|
57
|
+
Create a `prettier.config.mjs` file at the root of your repository:
|
|
58
|
+
|
|
59
|
+
```js
|
|
60
|
+
// This is the configuration file for Prettier, the auto-formatter:
|
|
61
|
+
// https://prettier.io/docs/en/configuration.html
|
|
62
|
+
|
|
63
|
+
// @ts-check
|
|
64
|
+
|
|
65
|
+
/** @type {import("prettier").Config} */
|
|
66
|
+
const config = {
|
|
67
|
+
plugins: [
|
|
68
|
+
"prettier-plugin-organize-imports", // Prettier does not format imports by default.
|
|
69
|
+
"prettier-plugin-packagejson", // Prettier does not format "package.json" by default.
|
|
70
|
+
],
|
|
71
|
+
|
|
72
|
+
overrides: [
|
|
73
|
+
// Allow proper formatting of JSONC files that have JSON file extensions.
|
|
74
|
+
{
|
|
75
|
+
files: ["**/.vscode/*.json", "**/tsconfig.json", "**/tsconfig.*.json"],
|
|
76
|
+
options: {
|
|
77
|
+
parser: "jsonc",
|
|
78
|
+
},
|
|
79
|
+
},
|
|
80
|
+
],
|
|
47
81
|
};
|
|
82
|
+
|
|
83
|
+
export default config;
|
|
48
84
|
```
|
|
49
85
|
|
|
50
|
-
### Step
|
|
86
|
+
### Step 4 - IDE Integration
|
|
51
87
|
|
|
52
88
|
You will probably want to set up your code editor such that both ESLint and Prettier are automatically run every time the file is saved. Below, we show how to do that with [VSCode](https://code.visualstudio.com/), the most popular TypeScript editor / IDE. It is also possible to set this up in other editors such as [Webstorm](https://www.jetbrains.com/webstorm/) and [Neovim](https://neovim.io/), but we don't provide detailed instructions for that here.
|
|
53
89
|
|
|
@@ -70,30 +106,26 @@ Once installed, these extensions provide a nice dichotomy:
|
|
|
70
106
|
|
|
71
107
|
#### `.vscode/settings.json`
|
|
72
108
|
|
|
73
|
-
Furthermore, you will probably want Prettier and ESLint to be run automatically every time you save a
|
|
109
|
+
Furthermore, you will probably want Prettier and ESLint to be run automatically every time you save a file. You can tell VSCode to do this by adding the following to your project's `.vscode/settings.json` file:
|
|
74
110
|
|
|
75
111
|
```ts
|
|
76
112
|
// These are Visual Studio Code settings that should apply to this particular repository.
|
|
77
113
|
{
|
|
78
|
-
"[javascript]": {
|
|
114
|
+
"[javascript][typescript][javascriptreact][typescriptreact]": {
|
|
79
115
|
"editor.codeActionsOnSave": {
|
|
80
116
|
"source.fixAll.eslint": "explicit",
|
|
81
117
|
},
|
|
82
118
|
"editor.defaultFormatter": "esbenp.prettier-vscode",
|
|
83
119
|
"editor.formatOnSave": true,
|
|
84
120
|
},
|
|
85
|
-
|
|
86
|
-
"[typescript]": {
|
|
87
|
-
"editor.codeActionsOnSave": {
|
|
88
|
-
"source.fixAll.eslint": "explicit",
|
|
89
|
-
},
|
|
121
|
+
"[css][html][json][jsonc][markdown][postcss][yaml]": {
|
|
90
122
|
"editor.defaultFormatter": "esbenp.prettier-vscode",
|
|
91
123
|
"editor.formatOnSave": true,
|
|
92
124
|
},
|
|
93
125
|
}
|
|
94
126
|
```
|
|
95
127
|
|
|
96
|
-
(Create
|
|
128
|
+
(Create the ".vscode" directory and the "settings.json" file if they do not already exist.)
|
|
97
129
|
|
|
98
130
|
You should also commit this file to your project's repository so that this behavior is automatically inherited by anyone who clones the project (and uses VSCode).
|
|
99
131
|
|
|
@@ -113,9 +145,94 @@ Optionally, you can also provide a hint to anyone cloning your repository that t
|
|
|
113
145
|
}
|
|
114
146
|
```
|
|
115
147
|
|
|
148
|
+
### Step 5 - Create a Lint Script
|
|
149
|
+
|
|
150
|
+
At this point, we should be able to see squiggly lines when errors happen, making for a nice editor experience. However, there might be errors in files that are not currently open in our editor. Thus, we might want to run a command to check the entire repository for errors. Since we use several different tools, we need to run several different commands to invoke each tool. One way to accomplish this is to create a "./scripts/lint.ts" file that runs all the tools in parallel:
|
|
151
|
+
|
|
152
|
+
```ts
|
|
153
|
+
import { $, lintScript } from "complete-node";
|
|
154
|
+
|
|
155
|
+
await lintScript(async () => {
|
|
156
|
+
const promises = [
|
|
157
|
+
// Use TypeScript to type-check the code.
|
|
158
|
+
$`tsc --noEmit`,
|
|
159
|
+
|
|
160
|
+
// Use ESLint to lint the TypeScript code.
|
|
161
|
+
// - "--max-warnings 0" makes warnings fail, since we set all ESLint errors to warnings.
|
|
162
|
+
$`eslint --max-warnings 0 .`,
|
|
163
|
+
|
|
164
|
+
// Use Prettier to check formatting.
|
|
165
|
+
// - "--log-level=warn" makes it only output errors.
|
|
166
|
+
$`prettier --log-level=warn --check .`,
|
|
167
|
+
|
|
168
|
+
// Use Knip to check for unused files, exports, and dependencies.
|
|
169
|
+
$`knip --no-progress`,
|
|
170
|
+
|
|
171
|
+
// Use CSpell to spell check every file.
|
|
172
|
+
// - "--no-progress" and "--no-summary" make it only output errors.
|
|
173
|
+
$`cspell --no-progress --no-summary .`,
|
|
174
|
+
|
|
175
|
+
// Check for unused words in the CSpell configuration file.
|
|
176
|
+
$`cspell-check-unused-words`,
|
|
177
|
+
];
|
|
178
|
+
|
|
179
|
+
await Promise.all(promises);
|
|
180
|
+
});
|
|
181
|
+
```
|
|
182
|
+
|
|
183
|
+
If you want, you can also put the script in your "package.json" file:
|
|
184
|
+
|
|
185
|
+
```json
|
|
186
|
+
"scripts": {
|
|
187
|
+
"lint": "tsx ./scripts/lint.ts"
|
|
188
|
+
},
|
|
189
|
+
```
|
|
190
|
+
|
|
191
|
+
That allows you to type `npm run lint` to more easily run the script.
|
|
192
|
+
|
|
193
|
+
### Step 6 - Lint in CI
|
|
194
|
+
|
|
195
|
+
If you use GitHub, you can create a [GitHub Actions](https://docs.github.com/en/actions) file to automatically run linting for [continuous integration](https://en.wikipedia.org/wiki/Continuous_integration) (CI). This is nice because the linting will automatically run on every commit, showing a green checkmark or a red x when you look at the repository on GitHub. You can also do things like configure alerts for when linting fails.
|
|
196
|
+
|
|
197
|
+
To set this up, create a `./.github/workflows/ci.yml` file:
|
|
198
|
+
|
|
199
|
+
```yml
|
|
200
|
+
name: CI
|
|
201
|
+
|
|
202
|
+
on: [push, pull_request]
|
|
203
|
+
|
|
204
|
+
jobs:
|
|
205
|
+
build:
|
|
206
|
+
runs-on: ubuntu-latest
|
|
207
|
+
steps:
|
|
208
|
+
- uses: actions/checkout@v4
|
|
209
|
+
- uses: actions/setup-node@v4
|
|
210
|
+
with:
|
|
211
|
+
node-version: lts/*
|
|
212
|
+
cache: npm
|
|
213
|
+
- run: npm ci
|
|
214
|
+
- run: npm run build
|
|
215
|
+
|
|
216
|
+
lint:
|
|
217
|
+
runs-on: ubuntu-latest
|
|
218
|
+
steps:
|
|
219
|
+
- uses: actions/checkout@v4
|
|
220
|
+
- uses: actions/setup-node@v4
|
|
221
|
+
with:
|
|
222
|
+
node-version: lts/*
|
|
223
|
+
cache: npm
|
|
224
|
+
- run: npm ci
|
|
225
|
+
- run: npm run lint
|
|
226
|
+
|
|
227
|
+
# You can add a "test" job too if your repository includes tests.
|
|
228
|
+
```
|
|
229
|
+
|
|
116
230
|
## Package Documentation
|
|
117
231
|
|
|
232
|
+
These are the specific packages that `complete-lint` provides:
|
|
233
|
+
|
|
118
234
|
- [`@prettier/plugin-xml`](https://github.com/prettier/plugin-xml) - Allows Prettier to format XML files, which are common in some kinds of projects.
|
|
235
|
+
- [`complete-node`](TODO) - A library that allows you to easily create a linting script to run several tools at once.
|
|
119
236
|
- [`cspell`](https://github.com/streetsidesoftware/cspell) - A spell checker for code that is intended to be paired with the [Code Spell Checker VSCode extension](https://marketplace.visualstudio.com/items?itemName=streetsidesoftware.code-spell-checker). Even though this does not have to do with ESLint or Prettier, this is included in the meta-package because most projects should be linting for misspelled words.
|
|
120
237
|
- [`cspell-check-unused-words`](https://github.com/Zamiell/cspell-check-unused-words) - A helpful script that can detect unused words inside your CSpell configuration, allowing you to clean up unnecessary entries.
|
|
121
238
|
- [`eslint`](https://github.com/eslint/eslint) - The main linter engine for JavaScript/TypeScript, as explained above.
|
|
@@ -124,6 +241,7 @@ Optionally, you can also provide a hint to anyone cloning your repository that t
|
|
|
124
241
|
- [`prettier`](https://github.com/prettier/prettier) - The main code formatter, as explained above.
|
|
125
242
|
- [`prettier-plugin-organize-imports`](https://github.com/simonhaenisch/prettier-plugin-organize-imports) - A plugin used because Prettier will not organize imports automatically.
|
|
126
243
|
- [`prettier-plugin-packagejson`](https://github.com/matzkoh/prettier-plugin-packagejson) - A plugin used because Prettier will not organize "package.json" files automatically.
|
|
244
|
+
- [`tsx`](https://github.com/privatenumber/tsx) - A tool to run a TypeScript file directly. This is included so that you can execute your linting script without having to explicitly install it.
|
|
127
245
|
|
|
128
246
|
## Why Code Formatting is Important
|
|
129
247
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "complete-lint",
|
|
3
|
-
"version": "1.0
|
|
3
|
+
"version": "1.1.0",
|
|
4
4
|
"description": "A linting dependency meta-package for TypeScript projects.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"lint",
|
|
@@ -26,6 +26,7 @@
|
|
|
26
26
|
],
|
|
27
27
|
"dependencies": {
|
|
28
28
|
"@prettier/plugin-xml": "^3.4.1",
|
|
29
|
+
"complete-node": "^1.1.0",
|
|
29
30
|
"cspell": "^8.14.2",
|
|
30
31
|
"cspell-check-unused-words": "^1.3.1",
|
|
31
32
|
"eslint": "^9.10.0",
|
|
@@ -33,7 +34,8 @@
|
|
|
33
34
|
"knip": "^5.30.0",
|
|
34
35
|
"prettier": "^3.3.3",
|
|
35
36
|
"prettier-plugin-organize-imports": "^4.0.0",
|
|
36
|
-
"prettier-plugin-packagejson": "^2.5.2"
|
|
37
|
+
"prettier-plugin-packagejson": "^2.5.2",
|
|
38
|
+
"tsx": "^4.19.0"
|
|
37
39
|
},
|
|
38
40
|
"peerDependencies": {
|
|
39
41
|
"typescript": ">= 5.0.0"
|