@zthun/janitor-lint 19.5.0 → 19.5.1
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 +167 -375
- package/package.json +4 -4
package/README.md
CHANGED
|
@@ -1,411 +1,203 @@
|
|
|
1
1
|
# Janitor Lint
|
|
2
2
|
|
|
3
|
-
Code gets messy.
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
needs and maintainability issues. Just let **Janitor Lint** do the heavy lifting
|
|
30
|
-
for you.
|
|
31
|
-
|
|
32
|
-
## Getting Started
|
|
3
|
+
Code gets messy. Most places you work will have a long backlog of tech-debt tasks
|
|
4
|
+
that never quite get addressed, and over time this becomes a maintenance nightmare.
|
|
5
|
+
Fixing old problems is expensive, and companies tend to focus on short-term ROI —
|
|
6
|
+
which means these issues often stay unresolved. New features get built on top of
|
|
7
|
+
messy foundations, and the software slowly begins to rot.
|
|
8
|
+
|
|
9
|
+
A common way to fight this is to start with linters. Linters scan your codebase
|
|
10
|
+
and notify you of issues. In a healthy development pipeline, they prevent developers
|
|
11
|
+
from creating a metaphorical messy room and encourage clean, consistent code across
|
|
12
|
+
the team. They’re not a silver bullet — messy solutions can still appear — but
|
|
13
|
+
linters eliminate most inconsistent patterns and formatting errors. Good developers
|
|
14
|
+
love them because they keep everyone aligned.
|
|
15
|
+
|
|
16
|
+
However, linters come with their own problems. There are so many of them. Each
|
|
17
|
+
has its own configuration style, quirks, and ecosystem. To cover your full
|
|
18
|
+
codebase, you often need multiple tools: ones for code quality, formatting, spelling,
|
|
19
|
+
applications, and more. It’s easy to feel overwhelmed, and maintaining a stack of
|
|
20
|
+
linters becomes its own form of tech debt.
|
|
21
|
+
|
|
22
|
+
Janitor Lint was created with the belief that there is beauty in simplicity. A
|
|
23
|
+
single tool that handles your linting needs is far better than stitching together
|
|
24
|
+
a pile of utilities, each with its own configuration and upkeep. Let Janitor
|
|
25
|
+
Lint take on the heavy lifting so you can keep your codebase clean — and your
|
|
26
|
+
developers happy.
|
|
27
|
+
|
|
28
|
+
## Install
|
|
33
29
|
|
|
34
30
|
```sh
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
yarn add @zthun/janitor-lint --dev
|
|
31
|
+
yarn add -D @zthun/janitor-lint
|
|
32
|
+
# Optionally pull in the shared rules
|
|
33
|
+
yarn add -D @zthun/janitor-lint-config
|
|
39
34
|
```
|
|
40
35
|
|
|
41
|
-
##
|
|
42
|
-
|
|
43
|
-
Janitor Lint uses an opt-in approach to linting, meaning that it will not lint
|
|
44
|
-
any files that you do not tell it to lint. You will need to add a configuration
|
|
45
|
-
file that describes the list of files to lint and the sub configurations of each
|
|
46
|
-
internal linter. Each linter is described in further detail. In the end, the
|
|
47
|
-
expectation is that you will provide you're own collection of shared
|
|
48
|
-
configurations that you can reuse in all your projects.
|
|
36
|
+
## CLI
|
|
49
37
|
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
38
|
+
```sh
|
|
39
|
+
janitor-lint
|
|
40
|
+
```
|
|
53
41
|
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
1. A javascript file named **janitor-lintrc.js**, **janitor-lint.config.js**.
|
|
42
|
+
- `--config` is optional. Without it, the CLI searches for a `janitor`
|
|
43
|
+
config using cosmiconfig (in order: `package.json#janitor`, `janitorrc`,
|
|
44
|
+
`janitorrc.json`, `janitorrc.yaml|yml`, `janitorrc.mjs`).
|
|
45
|
+
- Exit code is `0` when every enabled linter passes and `1` when any fail.
|
|
59
46
|
|
|
60
|
-
|
|
61
|
-
> configurations. The main reason is that config.js offers the most flexible way
|
|
62
|
-
> to configure an application and also naturally allows you to use the module
|
|
63
|
-
> syntax to import other configurations.
|
|
47
|
+
## Configuration shape
|
|
64
48
|
|
|
65
|
-
|
|
49
|
+
Janitor Lint reads a `janitor` options config object with a `lint` section. Every
|
|
50
|
+
field is optional—only the linters you configure will run. You can configure this
|
|
51
|
+
manually, OR you can use the package, @zthun/janitor-options, to just build a
|
|
52
|
+
configuration.
|
|
66
53
|
|
|
67
54
|
```ts
|
|
68
|
-
|
|
69
|
-
|
|
55
|
+
/**
|
|
56
|
+
* Represents options for linting in the zthunworks janitor system.
|
|
57
|
+
*/
|
|
58
|
+
export interface IZJanitorOptionsLint {
|
|
59
|
+
/**
|
|
60
|
+
* The path to the config file for eslint.
|
|
61
|
+
*/
|
|
70
62
|
esConfig?: string;
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
63
|
+
/**
|
|
64
|
+
* The path to the config file for htmlhint.
|
|
65
|
+
*/
|
|
74
66
|
htmlConfig?: string;
|
|
75
|
-
|
|
67
|
+
/**
|
|
68
|
+
* The path to the config file for markdownlint.
|
|
69
|
+
*/
|
|
76
70
|
markdownConfig?: string;
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
71
|
+
/**
|
|
72
|
+
* The path to the config file for prettier.
|
|
73
|
+
*/
|
|
80
74
|
prettyConfig?: string;
|
|
75
|
+
/**
|
|
76
|
+
* The path to the config file for cspell.
|
|
77
|
+
*/
|
|
78
|
+
spellingConfig?: string;
|
|
79
|
+
/**
|
|
80
|
+
* The path to the config file for stylelint.
|
|
81
|
+
*/
|
|
82
|
+
styleConfig?: string;
|
|
81
83
|
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
// config file so there is no exclude support for it here.
|
|
84
|
+
/**
|
|
85
|
+
* The file globs to lint with eslint.
|
|
86
|
+
*/
|
|
86
87
|
esFiles?: string[];
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
styleFiles?: string[];
|
|
91
|
-
// The white list of HTML globs to lint.
|
|
88
|
+
/**
|
|
89
|
+
* The file globs to lint with htmlhint.
|
|
90
|
+
*/
|
|
92
91
|
htmlFiles?: string[];
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
markdownFiles?: string[];
|
|
97
|
-
// The black list of Markdown globs to exclude from linting.
|
|
98
|
-
markdownFilesExclude?: string[];
|
|
99
|
-
// The white list of JSON globs to lint.
|
|
92
|
+
/**
|
|
93
|
+
* The file globs to lint with json.
|
|
94
|
+
*/
|
|
100
95
|
jsonFiles?: string[];
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
spellingFiles?: string[];
|
|
109
|
-
// The black list of globs to exclude from spell checking.
|
|
110
|
-
spellingFilesExclude?: string[];
|
|
111
|
-
// The white list of globs to check for code formatting.
|
|
96
|
+
/**
|
|
97
|
+
* The file globs to lint with markdownlint.
|
|
98
|
+
*/
|
|
99
|
+
markdownFiles?: string[];
|
|
100
|
+
/**
|
|
101
|
+
* The file globs to lint with prettier.
|
|
102
|
+
*/
|
|
112
103
|
prettyFiles?: string[];
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
The
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
// default rules of the application if not specified. However, you
|
|
126
|
-
// can always override the configurations in this file.
|
|
127
|
-
esConfig: 'configs/.eslintrc',
|
|
128
|
-
// Using globs to find files
|
|
129
|
-
esFiles: ['packages/**/src/**/*.ts'],
|
|
130
|
-
// The configurations can also be shared configuration modules
|
|
131
|
-
// found in node_modules if you're not using IDE extensions.
|
|
132
|
-
styleConfig: '@zthun/janitor-stylelint-config';
|
|
133
|
-
// Globs are relative to the current working directory.
|
|
134
|
-
styleFiles: ['packages/**/src/**/*.less'],
|
|
135
|
-
// See notes on html below
|
|
136
|
-
htmlFiles: ['packages/**/src/**/*.html'],
|
|
137
|
-
// You can have as many globs as you want.
|
|
138
|
-
markdownFiles: ['packages/**/*.md', '*.md'],
|
|
139
|
-
// You can also exclude files from the include list. These are normally
|
|
140
|
-
// used for code generated files and should not be linted.
|
|
141
|
-
markdownFilesExclude: ['**/CHANGELOG.md'],
|
|
142
|
-
// You can also specify specific files - json and yaml have no
|
|
143
|
-
// configurations as they are very specific formats.
|
|
144
|
-
jsonFiles: ['package.json'],
|
|
145
|
-
// Removes the linter
|
|
146
|
-
spellingFiles: null
|
|
147
|
-
};
|
|
148
|
-
```
|
|
149
|
-
|
|
150
|
-
In your package json, add the following
|
|
104
|
+
/**
|
|
105
|
+
* The file globs to lint with cspell.
|
|
106
|
+
*/
|
|
107
|
+
spellingFiles?: string[];
|
|
108
|
+
/**
|
|
109
|
+
* The file globs to lint with stylelint.
|
|
110
|
+
*/
|
|
111
|
+
styleFiles?: string[];
|
|
112
|
+
/**
|
|
113
|
+
* The file globs to lint with yaml.
|
|
114
|
+
*/
|
|
115
|
+
yamlFiles?: string[];
|
|
151
116
|
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
117
|
+
/**
|
|
118
|
+
* The files globs to exclude from linting with htmlhint.
|
|
119
|
+
*/
|
|
120
|
+
htmlFilesExclude?: string[];
|
|
121
|
+
/**
|
|
122
|
+
* The files globs to exclude from linting with json.
|
|
123
|
+
*/
|
|
124
|
+
jsonFilesExclude?: string[];
|
|
125
|
+
/**
|
|
126
|
+
* The files globs to exclude from linting with markdownlint.
|
|
127
|
+
*/
|
|
128
|
+
markdownFilesExclude?: string[];
|
|
129
|
+
/**
|
|
130
|
+
* The files globs to exclude from linting with prettier.
|
|
131
|
+
*/
|
|
132
|
+
prettyFilesExclude?: string[];
|
|
133
|
+
/**
|
|
134
|
+
* The files globs to exclude from linting with cspell.
|
|
135
|
+
*/
|
|
136
|
+
spellingFilesExclude?: string[];
|
|
137
|
+
/**
|
|
138
|
+
* The files to exclude from linting with stylelint.
|
|
139
|
+
*/
|
|
140
|
+
styleFilesExclude?: string[];
|
|
141
|
+
/**
|
|
142
|
+
* The files globs to exclude from linting with yaml.
|
|
143
|
+
*/
|
|
144
|
+
yamlFilesExclude?: string[];
|
|
157
145
|
}
|
|
158
|
-
```
|
|
159
|
-
|
|
160
|
-
Now you can lint everything with a single command.
|
|
161
|
-
|
|
162
|
-
```sh
|
|
163
|
-
# NPM
|
|
164
|
-
npm run lint
|
|
165
|
-
# Yarn
|
|
166
|
-
yarn lint
|
|
167
|
-
# NPX
|
|
168
|
-
npx janitor-lint
|
|
169
|
-
```
|
|
170
|
-
|
|
171
|
-
## Command Line
|
|
172
|
-
|
|
173
|
-
You can always run janitor-lint on the command line using npx or if it is
|
|
174
|
-
installed globally, which is not recommended. There are very few command line
|
|
175
|
-
options, as janitor-lint intends to be fully driven by the config file.
|
|
176
|
-
|
|
177
|
-
**janitor-lint** [options]
|
|
178
146
|
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
"option": "--config",
|
|
188
|
-
"alias": "-c",
|
|
189
|
-
"description": "Optional config file to use",
|
|
190
|
-
"type": "string"
|
|
191
|
-
},
|
|
192
|
-
{
|
|
193
|
-
"option": "--help",
|
|
194
|
-
"description": "Show help",
|
|
195
|
-
"type": "boolean"
|
|
196
|
-
}
|
|
197
|
-
]
|
|
198
|
-
```
|
|
199
|
-
|
|
200
|
-
## Linters
|
|
201
|
-
|
|
202
|
-
### Shared Configurations
|
|
203
|
-
|
|
204
|
-
While you can always recreate individual configurations for each linter, it is
|
|
205
|
-
**HIGHLY** recommended to create a set of shared configurations for your
|
|
206
|
-
organization. Most linters supported by Janitor Lint have some form of support
|
|
207
|
-
for extending configurations and sharing them so you don't need to reinvent the
|
|
208
|
-
wheel. In the place that such extensions are missing, Janitor Lint attempts to
|
|
209
|
-
bridge this gap but it will not add support for IDE based tooling and
|
|
210
|
-
extensions. You'll have to decide what's best for your project and your
|
|
211
|
-
organization.
|
|
212
|
-
|
|
213
|
-
One note is that the housing repository for janitor-lint contains multiple
|
|
214
|
-
shared configurations used by zthun scoped projects. You can use them, but it is
|
|
215
|
-
recommended for your organization to create it's own set of configurations that
|
|
216
|
-
meets its needs.
|
|
217
|
-
|
|
218
|
-
### JSON and YAML
|
|
219
|
-
|
|
220
|
-
JSON does not use an external tool. It's impossible to have lint errors in JSON
|
|
221
|
-
as if there are, it wouldn't be valid JSON and you won't be able to parse it.
|
|
222
|
-
Thus, when we talk about linting JSON, it's really just a parse check to make
|
|
223
|
-
sure you're JSON is valid.
|
|
224
|
-
|
|
225
|
-
For YAML, the same rule applies. It's just a parse check, but since YAML isn't
|
|
226
|
-
supported in JavaScript out of the box, it uses
|
|
227
|
-
[js-yaml](https://www.npmjs.com/package/js-yaml) under the hood to parse and
|
|
228
|
-
check your files.
|
|
229
|
-
|
|
230
|
-
Neither of these checks verify schemas so be warned about that.
|
|
231
|
-
|
|
232
|
-
### ECMAScript
|
|
233
|
-
|
|
234
|
-
The linter of choice for ECMAScript, is [ESLint](https://eslint.org/). ESLint
|
|
235
|
-
has a very large eco system with support for shared configurations and plugins.
|
|
236
|
-
It supports both TypeScript and JavaScript so it covers the entire feature
|
|
237
|
-
spectrum. The configuration file for ESLint uses something similar to a
|
|
238
|
-
[cosmiconfig](https://www.npmjs.com/package/cosmiconfig) standard but it's more
|
|
239
|
-
restrictive.
|
|
240
|
-
|
|
241
|
-
There is also a
|
|
242
|
-
[VisualStudio Code plugin](https://marketplace.visualstudio.com/items?itemName=dbaeumer.vscode-eslint)
|
|
243
|
-
that will give you highlighting for any linting errors while you type. This
|
|
244
|
-
makes ESLint the go to linter for web based ECMAScript code.
|
|
245
|
-
|
|
246
|
-
For the configuration schema, you can find it
|
|
247
|
-
[at the eslint configuration guide](https://eslint.org/docs/user-guide/configuring/).
|
|
248
|
-
If you create a shared configuration, as recommended, you can simply add that to
|
|
249
|
-
the extends key in the ESLint configuration file to share configuration throughout
|
|
250
|
-
your organization.
|
|
251
|
-
|
|
252
|
-
```js
|
|
253
|
-
// .eslintrc.js
|
|
254
|
-
module.exports = require("@zthun/janitor-eslint-config");
|
|
255
|
-
```
|
|
256
|
-
|
|
257
|
-
### Styles (CSS, Less, SASS)
|
|
258
|
-
|
|
259
|
-
There are several linters for style based files.
|
|
260
|
-
|
|
261
|
-
1. [CSSLint](https://github.com/CSSLint/csslint)
|
|
262
|
-
2. [SassLint](https://github.com/sasstools/sass-lint)
|
|
263
|
-
3. [StyleLint](https://stylelint.io/)
|
|
264
|
-
|
|
265
|
-
CSSLint and SassLint are no longer actively maintained. Thus, for linting style
|
|
266
|
-
based files, Janitor Lint uses StyleLint under the hood.
|
|
267
|
-
|
|
268
|
-
StyleLint is similar to [ESLint](https://eslint.org/). It too, has a nice
|
|
269
|
-
ecosystem of plugins and it supports shared configurations.
|
|
270
|
-
|
|
271
|
-
You can find the configuration schema [in the user guid for stylelint](https://stylelint.io/user-guide/configure)
|
|
272
|
-
and you can use the extends key in the configuration to load a shared configuration.
|
|
273
|
-
|
|
274
|
-
```jsonc
|
|
275
|
-
// .stylelintrc.json
|
|
276
|
-
{
|
|
277
|
-
"extends": ["@zthun/janitor-stylelint-config"],
|
|
147
|
+
/**
|
|
148
|
+
* Options for the zthunworks janitor system.
|
|
149
|
+
*/
|
|
150
|
+
export interface IZJanitorOptions {
|
|
151
|
+
/**
|
|
152
|
+
* Linting options for janitor-lint.
|
|
153
|
+
*/
|
|
154
|
+
lint?: IZJanitorOptionsLint;
|
|
278
155
|
}
|
|
279
156
|
```
|
|
280
157
|
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
158
|
+
The value of each `*Config` can be a local path or a shared module such as
|
|
159
|
+
`@zthun/janitor-*-config`. HTMLHint and Markdownlint configs support `extends`
|
|
160
|
+
via Janitor Lint even though the underlying tools have limited support.
|
|
284
161
|
|
|
285
|
-
|
|
286
|
-
[this issue](https://github.com/htmlhint/HTMLHint/issues/621) would need to be
|
|
287
|
-
approved and supported. In the meantime, Janitor Lint bridges this gap by
|
|
288
|
-
sending just the content to HTMLHint instead of the file list. This allows Lint
|
|
289
|
-
Janitor to implement a [cosmiconfig](https://www.npmjs.com/package/cosmiconfig)
|
|
290
|
-
standard for loading and extending the configuration to support shared configs.
|
|
291
|
-
It will be up to you if you want to do this because the
|
|
292
|
-
[VisualStudio Code plugin](https://marketplace.visualstudio.com/items?itemName=mkaufman.HTMLHint)
|
|
293
|
-
does not support this and expects the standard json file to be at the root of
|
|
294
|
-
your project.
|
|
162
|
+
## Example config
|
|
295
163
|
|
|
296
|
-
|
|
297
|
-
htmlhint.config.js file at the root of your repository.
|
|
164
|
+
The repo keeps its settings in `.config/janitorrc.mjs`:
|
|
298
165
|
|
|
299
166
|
```js
|
|
300
|
-
//
|
|
301
|
-
|
|
167
|
+
// .config/janitorrc.mjs
|
|
168
|
+
import {
|
|
169
|
+
ZJanitorOptionsBuilder,
|
|
170
|
+
ZJanitorOptionsLintBuilder,
|
|
171
|
+
} from "@zthun/janitor-options";
|
|
172
|
+
|
|
173
|
+
const lint = new ZJanitorOptionsLintBuilder()
|
|
174
|
+
// Conventional globs for this workspace
|
|
175
|
+
.commonEsFiles()
|
|
176
|
+
.commonCssFiles()
|
|
177
|
+
.commonLessFiles()
|
|
178
|
+
.commonSassFiles()
|
|
179
|
+
.commonHtmlFiles()
|
|
180
|
+
.commonMarkdownFiles()
|
|
181
|
+
.commonJsonFiles()
|
|
182
|
+
.commonYamlFiles()
|
|
183
|
+
// Reuse the same files for spell checks and format checks
|
|
184
|
+
.generateSpellingFiles()
|
|
185
|
+
.generatePrettyFiles()
|
|
186
|
+
// Ignore build artifacts and vendored content
|
|
187
|
+
.commonExcludes()
|
|
188
|
+
.build();
|
|
189
|
+
|
|
190
|
+
export default new ZJanitorOptionsBuilder().lint(lint).build();
|
|
302
191
|
```
|
|
303
192
|
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
Good old markdown has a couple of linters available, but considering that
|
|
307
|
-
[MarkdownLint](https://github.com/DavidAnson/markdownlint) has a working
|
|
308
|
-
[VisualStudio Code plugin](https://marketplace.visualstudio.com/items?itemName=DavidAnson.vscode-markdownlint),
|
|
309
|
-
that's the one that Janitor Lint uses.
|
|
310
|
-
|
|
311
|
-
There's not a lot of rules to markdown. You can find
|
|
312
|
-
the list of rules [at the markdown lint github](https://github.com/DavidAnson/markdownlint).
|
|
313
|
-
|
|
314
|
-
### Spelling
|
|
315
|
-
|
|
316
|
-
This one is pretty optional, but it's useful in that it keeps you honest. With
|
|
317
|
-
spelling, you won't use a shared configuration as this is truly unique across
|
|
318
|
-
all projects. It is not possible to have a be all end all language that knows
|
|
319
|
-
every word in existence so this will look for the
|
|
320
|
-
[CSpell](https://www.npmjs.com/package/cspell) configuration at the root of the
|
|
321
|
-
repository. If you combine this with the
|
|
322
|
-
[VisualStudio Code plugin](https://marketplace.visualstudio.com/items?itemName=streetsidesoftware.code-spell-checker),
|
|
323
|
-
it's pretty powerful and lets you add words as the repository vocabulary grows.
|
|
324
|
-
When using spelling here, you'll need to decide if there are words you want to
|
|
325
|
-
support, what dictionaries your repository is going to support, and what are
|
|
326
|
-
your forbidden words and phrases. There are no rules here, just lists of allowed
|
|
327
|
-
words and dictionaries.
|
|
328
|
-
|
|
329
|
-
You may want to consider having a shared dictionary for your organizations
|
|
330
|
-
custom lingo. You can do this through the dictionaryDefinitions key, but you'll
|
|
331
|
-
have to export a txt file for reuse.
|
|
332
|
-
|
|
333
|
-
```json
|
|
334
|
-
// cspell.json
|
|
335
|
-
{
|
|
336
|
-
"version": "0.1",
|
|
337
|
-
"$schema": "https://raw.githubusercontent.com/streetsidesoftware/cspell/master/cspell.schema.json",
|
|
338
|
-
"language": "en",
|
|
339
|
-
"words": ["errored"],
|
|
340
|
-
"dictionaries": ["typescript", "en_US"]
|
|
341
|
-
}
|
|
342
|
-
```
|
|
343
|
-
|
|
344
|
-
### Formatting
|
|
345
|
-
|
|
346
|
-
Finally, and possibly most importantly, is code formatting consistency. There
|
|
347
|
-
are generally two tools that are used for this.
|
|
348
|
-
|
|
349
|
-
1. [EditorConfig](https://editorconfig.org/)
|
|
350
|
-
1. [Prettier](https://prettier.io/)
|
|
351
|
-
|
|
352
|
-
For code formatting, Janitor Lint went with Prettier since it supports all the
|
|
353
|
-
features of EditorConfig and a bunch of others. Prettier also supports shared
|
|
354
|
-
configurations and is highly recommended to use them because the
|
|
355
|
-
[VisualStudio Code plugin](https://marketplace.visualstudio.com/items?itemName=esbenp.prettier-vscode)
|
|
356
|
-
has support to auto format your files when you save them, making sure that your
|
|
357
|
-
teams formatting is completely consistent.
|
|
358
|
-
|
|
359
|
-
It's file lookup is similar to that of ESLint, but we recommended using
|
|
360
|
-
.prettierrc.js to enable support for shared configurations.
|
|
193
|
+
Point to shared configs if you want opinionated defaults:
|
|
361
194
|
|
|
362
195
|
```js
|
|
363
|
-
|
|
364
|
-
|
|
196
|
+
const lint = new ZJanitorOptionsLintBuilder()
|
|
197
|
+
.esConfig("@zthun/janitor-eslint-config")
|
|
198
|
+
.styleConfig("@zthun/janitor-stylelint-config")
|
|
199
|
+
.htmlConfig("@zthun/janitor-htmlhint-config")
|
|
200
|
+
.markdownConfig("@zthun/janitor-markdownlint-config")
|
|
201
|
+
.prettyConfig("@zthun/janitor-prettier-config")
|
|
202
|
+
.build();
|
|
365
203
|
```
|
|
366
|
-
|
|
367
|
-
Options are [located at the prettier documentation](https://prettier.io/docs/en/options.html),
|
|
368
|
-
and there's not a lot of them. See [why](https://prettier.io/docs/en/option-philosophy.html),
|
|
369
|
-
as there's a good reason for this.
|
|
370
|
-
|
|
371
|
-
When doing formatting linting, only the formatting is checked and you are
|
|
372
|
-
notified if the files are formatted or unformatted. The best way to prevent
|
|
373
|
-
these issues all together is to just use the Prettier IDE extension and auto
|
|
374
|
-
format as you type.
|
|
375
|
-
|
|
376
|
-
### FAQ
|
|
377
|
-
|
|
378
|
-
Q. Can this support my other favorite linter?
|
|
379
|
-
|
|
380
|
-
A. Possibly, but whether or not Janitor Lint will bother at the moment depends
|
|
381
|
-
on a few factors:
|
|
382
|
-
|
|
383
|
-
1. Is there an IDE plugin that makes it so you can validate, lint, and cleanup
|
|
384
|
-
while you go along so you're not left with a lot of surprises at the end?
|
|
385
|
-
1. Does the linter support shared configuration to not reinvent the wheel
|
|
386
|
-
everywhere? Does Janitor Lint have to bridge that gap?
|
|
387
|
-
1. Is the linter in question a node linter that has its API exported and can be
|
|
388
|
-
integrated into a node application? **Important!**
|
|
389
|
-
|
|
390
|
-
If you answered No to the last question, then the answer is No. Janitor Lint
|
|
391
|
-
does not invoke external command lines of linters and instead calls into their
|
|
392
|
-
node API directly. This is how Janitor Lint succeeds in not having you worry
|
|
393
|
-
about what tools to install and what versions to use; it uses transitive
|
|
394
|
-
dependencies.
|
|
395
|
-
|
|
396
|
-
If the last question is a Yes, then it becomes a question of, is it worth it?
|
|
397
|
-
That'll need to be prioritized. For the most part, using
|
|
398
|
-
[Prettier](https://prettier.io/) takes care of almost all linting issues so you
|
|
399
|
-
may not need more than what is available here. If you need the mother of all
|
|
400
|
-
linters, there is the heavy
|
|
401
|
-
[Mega Linter](https://github.com/nvuillam/mega-linter) which aggregates every
|
|
402
|
-
linter in existence. Very cool, but a bit overkill for the solution we are
|
|
403
|
-
trying to solve with Janitor Lint.
|
|
404
|
-
|
|
405
|
-
Q. Is there an IDE plugin for Janitor Lint?
|
|
406
|
-
|
|
407
|
-
A. Not yet. That would solve the issue of wanting an IDE plugin for each
|
|
408
|
-
individual linter and would allow you to just have a single
|
|
409
|
-
janitor-lint.config.js file at the root of your repository that would handle all
|
|
410
|
-
linting needs. There is one planned, but it still need to be researched and
|
|
411
|
-
scoped out.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@zthun/janitor-lint",
|
|
3
|
-
"version": "19.5.
|
|
3
|
+
"version": "19.5.1",
|
|
4
4
|
"description": "Style checks with tools for web projects using common rules.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"linters"
|
|
@@ -33,7 +33,7 @@
|
|
|
33
33
|
},
|
|
34
34
|
"author": "Anthony Bonta",
|
|
35
35
|
"dependencies": {
|
|
36
|
-
"@zthun/janitor-options": "^19.5.
|
|
36
|
+
"@zthun/janitor-options": "^19.5.1",
|
|
37
37
|
"chalk": "^5.6.2",
|
|
38
38
|
"cosmiconfig": "^9.0.0",
|
|
39
39
|
"cspell": "^9.3.2",
|
|
@@ -51,11 +51,11 @@
|
|
|
51
51
|
"dist"
|
|
52
52
|
],
|
|
53
53
|
"devDependencies": {
|
|
54
|
-
"@zthun/janitor-build-config": "^19.5.
|
|
54
|
+
"@zthun/janitor-build-config": "^19.5.1",
|
|
55
55
|
"typescript": "~5.9.3",
|
|
56
56
|
"vite": "^7.2.2",
|
|
57
57
|
"vitest": "^4.0.10",
|
|
58
58
|
"vitest-mock-extended": "^3.1.0"
|
|
59
59
|
},
|
|
60
|
-
"gitHead": "
|
|
60
|
+
"gitHead": "8b2a09566d2d71c762189c7e94dcb1b8500f1863"
|
|
61
61
|
}
|