@zthun/janitor-lint 19.0.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/LICENSE.md +20 -0
- package/README.md +411 -0
- package/dist/app/janitor-lint-args.d.mts +9 -0
- package/dist/app/janitor-lint.d.mts +83 -0
- package/dist/app/janitor-lint.spec.d.ts +1 -0
- package/dist/cli.cjs +10 -0
- package/dist/cli.cjs.map +1 -0
- package/dist/cli.d.ts +2 -0
- package/dist/cli.js +8 -0
- package/dist/cli.js.map +1 -0
- package/dist/config/config-discovery.d.mts +13 -0
- package/dist/config/config-extender.class.spec.d.ts +1 -0
- package/dist/config/config-extender.d.mts +61 -0
- package/dist/config/config-reader-cosmic.class.spec.d.ts +1 -0
- package/dist/config/config-reader-cosmic.d.mts +44 -0
- package/dist/config/config-reader-null.class.spec.d.ts +1 -0
- package/dist/config/config-reader-null.d.mts +13 -0
- package/dist/config/config-reader-prettier.class.spec.d.ts +1 -0
- package/dist/config/config-reader-prettier.d.mts +18 -0
- package/dist/config/config-reader.d.mts +15 -0
- package/dist/config/config-resolve.d.mts +4 -0
- package/dist/content/content-linter-html.class.spec.d.ts +1 -0
- package/dist/content/content-linter-html.d.mts +21 -0
- package/dist/content/content-linter-json.class.spec.d.ts +1 -0
- package/dist/content/content-linter-json.d.mts +13 -0
- package/dist/content/content-linter-pretty.class.spec.d.ts +1 -0
- package/dist/content/content-linter-pretty.d.mts +21 -0
- package/dist/content/content-linter-yaml.class.spec.d.ts +1 -0
- package/dist/content/content-linter-yaml.d.mts +16 -0
- package/dist/content/content-linter.d.mts +21 -0
- package/dist/index.cjs +58 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.ts +21 -0
- package/dist/index.js +39 -0
- package/dist/index.js.map +1 -0
- package/dist/janitor-lint-CA0qEXKV.cjs +1370 -0
- package/dist/janitor-lint-CA0qEXKV.cjs.map +1 -0
- package/dist/janitor-lint-QMZ00oXe.js +1353 -0
- package/dist/janitor-lint-QMZ00oXe.js.map +1 -0
- package/dist/linter/linter-es.class.spec.d.ts +1 -0
- package/dist/linter/linter-es.d.mts +39 -0
- package/dist/linter/linter-file.class.spec.d.ts +1 -0
- package/dist/linter/linter-file.d.mts +45 -0
- package/dist/linter/linter-markdown.class.spec.d.ts +1 -0
- package/dist/linter/linter-markdown.d.mts +31 -0
- package/dist/linter/linter-report.class.spec.d.ts +1 -0
- package/dist/linter/linter-report.d.mts +32 -0
- package/dist/linter/linter-silent.class.spec.d.ts +1 -0
- package/dist/linter/linter-silent.d.mts +21 -0
- package/dist/linter/linter-spelling.class.spec.d.ts +1 -0
- package/dist/linter/linter-spelling.d.mts +30 -0
- package/dist/linter/linter-style.class.spec.d.ts +1 -0
- package/dist/linter/linter-style.d.mts +28 -0
- package/dist/linter/linter.d.mts +21 -0
- package/package.json +61 -0
package/LICENSE.md
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
# MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2024 Anthony Bonta
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
|
6
|
+
this software and associated documentation files (the "Software"), to deal in
|
|
7
|
+
the Software without restriction, including without limitation the rights to
|
|
8
|
+
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
|
9
|
+
the Software, and to permit persons to whom the Software is furnished to do so,
|
|
10
|
+
subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
|
17
|
+
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
|
18
|
+
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
|
19
|
+
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
|
20
|
+
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,411 @@
|
|
|
1
|
+
# Janitor Lint
|
|
2
|
+
|
|
3
|
+
Code gets messy. You will find that most places you work at will always have a
|
|
4
|
+
big long list of tech debt tasks that need to be taken care of and this becomes
|
|
5
|
+
a maintenance nightmare as it becomes very expensive to fix. Companies rarely
|
|
6
|
+
want to let developers fix these issues because they tend to only look at the
|
|
7
|
+
short term ROI, which isn't high for this kind of task. What then happens is
|
|
8
|
+
that more functional, but messy, code gets introduced and the software begins to
|
|
9
|
+
rot.
|
|
10
|
+
|
|
11
|
+
One way to fix something like this is to start with linters. Linters will scour
|
|
12
|
+
through your code base and notify you that you have various issues. In a good
|
|
13
|
+
development pipeline, they will prevent developers from generating a messy room
|
|
14
|
+
and will force them to write clean consistent code with the rest of the
|
|
15
|
+
development team. They aren't a silver bullet, and messy solutions can still
|
|
16
|
+
crop up, but linters take care of most of the inconsistent and formatting errors
|
|
17
|
+
that can develop in a code base. Good developers love them - it keeps the entire
|
|
18
|
+
team consistent in their code structure.
|
|
19
|
+
|
|
20
|
+
Of course, linters are not without their issues as well. There's an outrageous
|
|
21
|
+
amount of them out there and you have to be well versed in each one of them in
|
|
22
|
+
order to set each one of them up and run them in your pipeline to verify all of
|
|
23
|
+
the different code files you have. There's linters for code, applications,
|
|
24
|
+
spelling, and formatting; it's easy to get overwhelmed.
|
|
25
|
+
|
|
26
|
+
**Janitor Lint** was created under the guise that there is beauty in simplicity.
|
|
27
|
+
Having a single application that takes care of ones needs leads to greater
|
|
28
|
+
happiness then having to piece meal together tons of tools, each with individual
|
|
29
|
+
needs and maintainability issues. Just let **Janitor Lint** do the heavy lifting
|
|
30
|
+
for you.
|
|
31
|
+
|
|
32
|
+
## Getting Started
|
|
33
|
+
|
|
34
|
+
```sh
|
|
35
|
+
# NPM
|
|
36
|
+
npm install @zthun/janitor-lint --save-dev
|
|
37
|
+
# Yarn
|
|
38
|
+
yarn add @zthun/janitor-lint --dev
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
## Configuration
|
|
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.
|
|
49
|
+
|
|
50
|
+
Janitor Lint uses the [cosmiconfig](https://www.npmjs.com/package/cosmiconfig)
|
|
51
|
+
standard for loading its configuration. In short, it will search the current
|
|
52
|
+
working directory for the following files:
|
|
53
|
+
|
|
54
|
+
1. A property in your package.json named **janitor-lint**.
|
|
55
|
+
1. A json file or yaml file named **janitor-lintrc**.
|
|
56
|
+
1. A json file named **janitor-lintrc.json**.
|
|
57
|
+
1. A yaml file named **janitor-lintrc.yaml** or **janitor-lintrc.yml**.
|
|
58
|
+
1. A javascript file named **janitor-lintrc.js**, **janitor-lint.config.js**.
|
|
59
|
+
|
|
60
|
+
> It is highly recommended to use a config.js convention for these types of
|
|
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.
|
|
64
|
+
|
|
65
|
+
The configuration file uses the following schema.
|
|
66
|
+
|
|
67
|
+
```ts
|
|
68
|
+
{
|
|
69
|
+
// The configuration file or module for ECMAScript based linting.
|
|
70
|
+
esConfig?: string;
|
|
71
|
+
// The configuration file or module for CSS, Less, and Sass based linting.
|
|
72
|
+
styleConfig?: string;
|
|
73
|
+
// The configuration file or module for HTML linting.
|
|
74
|
+
htmlConfig?: string;
|
|
75
|
+
// The configuration file or module for Markdown based linting
|
|
76
|
+
markdownConfig?: string;
|
|
77
|
+
// The configuration file or module for Spelling checks
|
|
78
|
+
spellingConfig?: string;
|
|
79
|
+
// The configuration file or module for formatting checks
|
|
80
|
+
prettyConfig?: string;
|
|
81
|
+
|
|
82
|
+
// The white list of ECMAScript globs to lint. This should
|
|
83
|
+
// include JavaScript and TypeScript based files
|
|
84
|
+
// Note that eslint supports excludes directly in the
|
|
85
|
+
// config file so there is no exclude support for it here.
|
|
86
|
+
esFiles?: string[];
|
|
87
|
+
// The white list of CSS, Less, and Sass globs to lint.
|
|
88
|
+
// Note that stylelint supports excludes directly in
|
|
89
|
+
// the config file so there is no exclude support for it here.
|
|
90
|
+
styleFiles?: string[];
|
|
91
|
+
// The white list of HTML globs to lint.
|
|
92
|
+
htmlFiles?: string[];
|
|
93
|
+
// The black list of HTML globs to exclude from linting.
|
|
94
|
+
htmlFilesExclude?: string[];
|
|
95
|
+
// The white list of Markdown globs to lint.
|
|
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.
|
|
100
|
+
jsonFiles?: string[];
|
|
101
|
+
// The black list of JSON globs to exclude from linting.
|
|
102
|
+
jsonFilesExclude?: string[];
|
|
103
|
+
// The white list of YAML globs to lint.
|
|
104
|
+
yamlFiles?: string[];
|
|
105
|
+
// The black list of YAML globs to exclude from linting.
|
|
106
|
+
yamlFilesExclude?: string[];
|
|
107
|
+
// The white list of globs to check for spelling errors.
|
|
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.
|
|
112
|
+
prettyFiles?: string[];
|
|
113
|
+
// The black list of globs to exclude from code formatting.
|
|
114
|
+
prettyFilesExclude?: string[];
|
|
115
|
+
}
|
|
116
|
+
```
|
|
117
|
+
|
|
118
|
+
The following is an example configuration that janitor-lint will read.
|
|
119
|
+
|
|
120
|
+
```js
|
|
121
|
+
// janitor-lint.config.js
|
|
122
|
+
|
|
123
|
+
module.exports = {
|
|
124
|
+
// Configurations are generally optional and will load using the
|
|
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
|
|
151
|
+
|
|
152
|
+
```json
|
|
153
|
+
{
|
|
154
|
+
"scripts": {
|
|
155
|
+
"lint": "janitor-lint"
|
|
156
|
+
}
|
|
157
|
+
}
|
|
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
|
+
|
|
179
|
+
```json
|
|
180
|
+
[
|
|
181
|
+
{
|
|
182
|
+
"option": "--version",
|
|
183
|
+
"description": "Show version number",
|
|
184
|
+
"type": "boolean"
|
|
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"],
|
|
278
|
+
}
|
|
279
|
+
```
|
|
280
|
+
|
|
281
|
+
### HTML
|
|
282
|
+
|
|
283
|
+
There is not a lot of support for HTML linters, so we are using HTMLHint.
|
|
284
|
+
|
|
285
|
+
HTMLHint does NOT support shared configurations at all. To do that,
|
|
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.
|
|
295
|
+
|
|
296
|
+
If you do choose to use a shared configuration, you can just use a
|
|
297
|
+
htmlhint.config.js file at the root of your repository.
|
|
298
|
+
|
|
299
|
+
```js
|
|
300
|
+
//htmlhint.config.js
|
|
301
|
+
module.exports = require("@zthun/janitor-htmlhint-config");
|
|
302
|
+
```
|
|
303
|
+
|
|
304
|
+
### Markdown
|
|
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.
|
|
361
|
+
|
|
362
|
+
```js
|
|
363
|
+
//.prettierrc.js
|
|
364
|
+
module.exports = require("@zthun/janitor-prettier-config");
|
|
365
|
+
```
|
|
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.
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import { IZJanitorOptions } from '@zthun/janitor-options';
|
|
2
|
+
import { IZConfigReader } from '../config/config-reader.mjs';
|
|
3
|
+
import { IZLinter } from '../linter/linter.mjs';
|
|
4
|
+
import { IZJanitorLintArgs } from './janitor-lint-args.mjs';
|
|
5
|
+
/**
|
|
6
|
+
* Represents the main entry point object for the application.
|
|
7
|
+
*/
|
|
8
|
+
export declare class ZJanitorLint {
|
|
9
|
+
private readonly _logger;
|
|
10
|
+
/**
|
|
11
|
+
* The linter for js files.
|
|
12
|
+
*/
|
|
13
|
+
esLint: IZLinter;
|
|
14
|
+
/**
|
|
15
|
+
* The linter for cspell. Useful for multiple file types.
|
|
16
|
+
*/
|
|
17
|
+
spellLint: IZLinter;
|
|
18
|
+
/**
|
|
19
|
+
* The linter for prettier formatting checks.
|
|
20
|
+
*/
|
|
21
|
+
prettyLint: IZLinter;
|
|
22
|
+
/**
|
|
23
|
+
* The linter for style files.
|
|
24
|
+
*/
|
|
25
|
+
styleLint: IZLinter;
|
|
26
|
+
/**
|
|
27
|
+
* The linter for html files.
|
|
28
|
+
*
|
|
29
|
+
* Currently, htmlhint has no support for cosmiconfig based paths, so we're going to
|
|
30
|
+
* add them here.
|
|
31
|
+
*/
|
|
32
|
+
htmlHint: IZLinter;
|
|
33
|
+
/**
|
|
34
|
+
* The linter for json files.
|
|
35
|
+
*/
|
|
36
|
+
jsonLint: IZLinter;
|
|
37
|
+
/**
|
|
38
|
+
* The linter for yaml files.
|
|
39
|
+
*/
|
|
40
|
+
yamlLint: IZLinter;
|
|
41
|
+
/**
|
|
42
|
+
* The linter for markdown files.
|
|
43
|
+
*
|
|
44
|
+
* Markdownlint is a bit annoying with this. They
|
|
45
|
+
* don't really fully support the cosmiconfig standard,
|
|
46
|
+
* and they only support the config files that are named
|
|
47
|
+
* .markdownlint.yaml, .markdownlint.json, and .markdownlint.cjs
|
|
48
|
+
*/
|
|
49
|
+
markdownLint: IZLinter;
|
|
50
|
+
/**
|
|
51
|
+
* The configuration reader.
|
|
52
|
+
*/
|
|
53
|
+
config: IZConfigReader;
|
|
54
|
+
/**
|
|
55
|
+
* Initializes a new instance of this object.
|
|
56
|
+
*
|
|
57
|
+
* @param _logger -
|
|
58
|
+
* The logger to use when formatting output.
|
|
59
|
+
*/
|
|
60
|
+
constructor(_logger: Console);
|
|
61
|
+
/**
|
|
62
|
+
* Runs the lint given the required options.
|
|
63
|
+
*
|
|
64
|
+
* @param options -
|
|
65
|
+
* The lint options.
|
|
66
|
+
*
|
|
67
|
+
* @returns
|
|
68
|
+
* A promise that returns 0 if all linting was successful,
|
|
69
|
+
* and 1 if any of the linting failed.
|
|
70
|
+
*/
|
|
71
|
+
lint(options: IZJanitorOptions): Promise<number>;
|
|
72
|
+
/**
|
|
73
|
+
* Runs the application.
|
|
74
|
+
*
|
|
75
|
+
* @param args -
|
|
76
|
+
* The command line arguments.
|
|
77
|
+
*
|
|
78
|
+
* @returns
|
|
79
|
+
* A promise that returns 0 if all linting was
|
|
80
|
+
* successful, and 1 if any of the linting failed.
|
|
81
|
+
*/
|
|
82
|
+
run(args: IZJanitorLintArgs): Promise<number>;
|
|
83
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/dist/cli.cjs
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
'use strict';
|
|
3
|
+
|
|
4
|
+
const usage = require('yargs');
|
|
5
|
+
const janitorLint = require('./janitor-lint-CA0qEXKV.cjs');
|
|
6
|
+
|
|
7
|
+
const args = usage("$0 [options]").alias("c", "config").describe("c", "Optional config file to use.").string("c").help().parse();
|
|
8
|
+
const janitor = new janitorLint.ZJanitorLint(console);
|
|
9
|
+
janitor.run(args).then((result)=>process.exitCode = result);
|
|
10
|
+
//# sourceMappingURL=cli.cjs.map
|
package/dist/cli.cjs.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cli.cjs","sources":["../src/cli.ts"],"sourcesContent":["#!/usr/bin/env node\n\nimport usage from \"yargs\";\nimport { IZJanitorLintArgs } from \"./app/janitor-lint-args.mjs\";\nimport { ZJanitorLint } from \"./app/janitor-lint.mjs\";\n\nconst args: IZJanitorLintArgs = usage(\"$0 [options]\")\n .alias(\"c\", \"config\")\n .describe(\"c\", \"Optional config file to use.\")\n .string(\"c\")\n .help()\n .parse() as any;\nconst janitor = new ZJanitorLint(console);\njanitor.run(args).then((result) => (process.exitCode = result));\n"],"names":["args","usage","alias","describe","string","help","parse","janitor","ZJanitorLint","console","run","then","result","process","exitCode"],"mappings":";;;;;;AAMA,MAAMA,OAA0BC,KAAM,CAAA,cAAA,CAAA,CACnCC,KAAK,CAAC,KAAK,QACXC,CAAAA,CAAAA,QAAQ,CAAC,GAAA,EAAK,gCACdC,MAAM,CAAC,GACPC,CAAAA,CAAAA,IAAI,GACJC,KAAK,EAAA;AACR,MAAMC,OAAAA,GAAU,IAAIC,wBAAaC,CAAAA,OAAAA,CAAAA;AACjCF,OAAQG,CAAAA,GAAG,CAACV,IAAMW,CAAAA,CAAAA,IAAI,CAAC,CAACC,MAAAA,GAAYC,OAAQC,CAAAA,QAAQ,GAAGF,MAAAA,CAAAA;;"}
|
package/dist/cli.d.ts
ADDED
package/dist/cli.js
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import usage from 'yargs';
|
|
3
|
+
import { Z as ZJanitorLint } from './janitor-lint-QMZ00oXe.js';
|
|
4
|
+
|
|
5
|
+
const args = usage("$0 [options]").alias("c", "config").describe("c", "Optional config file to use.").string("c").help().parse();
|
|
6
|
+
const janitor = new ZJanitorLint(console);
|
|
7
|
+
janitor.run(args).then((result)=>process.exitCode = result);
|
|
8
|
+
//# sourceMappingURL=cli.js.map
|
package/dist/cli.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cli.js","sources":["../src/cli.ts"],"sourcesContent":["#!/usr/bin/env node\n\nimport usage from \"yargs\";\nimport { IZJanitorLintArgs } from \"./app/janitor-lint-args.mjs\";\nimport { ZJanitorLint } from \"./app/janitor-lint.mjs\";\n\nconst args: IZJanitorLintArgs = usage(\"$0 [options]\")\n .alias(\"c\", \"config\")\n .describe(\"c\", \"Optional config file to use.\")\n .string(\"c\")\n .help()\n .parse() as any;\nconst janitor = new ZJanitorLint(console);\njanitor.run(args).then((result) => (process.exitCode = result));\n"],"names":["args","usage","alias","describe","string","help","parse","janitor","ZJanitorLint","console","run","then","result","process","exitCode"],"mappings":";;;;AAMA,MAAMA,OAA0BC,KAAM,CAAA,cAAA,CAAA,CACnCC,KAAK,CAAC,KAAK,QACXC,CAAAA,CAAAA,QAAQ,CAAC,GAAA,EAAK,gCACdC,MAAM,CAAC,GACPC,CAAAA,CAAAA,IAAI,GACJC,KAAK,EAAA;AACR,MAAMC,OAAAA,GAAU,IAAIC,YAAaC,CAAAA,OAAAA,CAAAA;AACjCF,OAAQG,CAAAA,GAAG,CAACV,IAAMW,CAAAA,CAAAA,IAAI,CAAC,CAACC,MAAAA,GAAYC,OAAQC,CAAAA,QAAQ,GAAGF,MAAAA,CAAAA"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Represents an object that can be used to discover a config file.
|
|
3
|
+
*/
|
|
4
|
+
export interface IZConfigDiscovery {
|
|
5
|
+
/**
|
|
6
|
+
* Searches for a configuration file.
|
|
7
|
+
*
|
|
8
|
+
* @returns
|
|
9
|
+
* The path to the discovered configuration file
|
|
10
|
+
* or null if no such configuration can be found.
|
|
11
|
+
*/
|
|
12
|
+
search(): Promise<string>;
|
|
13
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Represents an object that can be used to build configs using an extends pattern.
|
|
3
|
+
*/
|
|
4
|
+
export interface IZConfigExtender {
|
|
5
|
+
/**
|
|
6
|
+
* Expands a configuration object.
|
|
7
|
+
*
|
|
8
|
+
* @param config -
|
|
9
|
+
* The current configuration object.
|
|
10
|
+
*/
|
|
11
|
+
extend(config: any): Promise<string>;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Represents the standard extender.
|
|
15
|
+
*
|
|
16
|
+
* This extender works the same as how eslint extends their
|
|
17
|
+
* configuration. You can pass a key that acts as the extends key which holds paths
|
|
18
|
+
* to the extendable files/modules. Note that this class, unlike eslint, does not assume any naming
|
|
19
|
+
* conventions and ONLY shared configurations are supported. You must pass the full path of the
|
|
20
|
+
* configs when extending, and plugin based syntax is not recognized.
|
|
21
|
+
*
|
|
22
|
+
* It is always better to just use the extension methods of the actual
|
|
23
|
+
* applications if those are available, but this can be used as a fallback or an
|
|
24
|
+
* extension of behavior for child linters that do not support extendable configs.
|
|
25
|
+
*/
|
|
26
|
+
export declare class ZConfigExtender implements IZConfigExtender {
|
|
27
|
+
key: string;
|
|
28
|
+
/**
|
|
29
|
+
* Initializes a new instance of this object.
|
|
30
|
+
*
|
|
31
|
+
* @param key
|
|
32
|
+
* - The key to extend.
|
|
33
|
+
*/
|
|
34
|
+
constructor(key?: string);
|
|
35
|
+
/**
|
|
36
|
+
* Extends the configuration value.
|
|
37
|
+
*
|
|
38
|
+
* This is similar to how eslint works. This will do an
|
|
39
|
+
* asynchronous require on each configuration under the key in the
|
|
40
|
+
* config. If the key in the config is falsy, then the config is returned.
|
|
41
|
+
*
|
|
42
|
+
* The actual key in the config is deleted.
|
|
43
|
+
*
|
|
44
|
+
* @param config
|
|
45
|
+
* - The config to extend.
|
|
46
|
+
*
|
|
47
|
+
* @returns
|
|
48
|
+
* A promise that resolves the extended configuration.
|
|
49
|
+
*/
|
|
50
|
+
extend(config: any): Promise<any>;
|
|
51
|
+
/**
|
|
52
|
+
* Reads a module recursively.
|
|
53
|
+
*
|
|
54
|
+
* @param module
|
|
55
|
+
* - The module to read.
|
|
56
|
+
*
|
|
57
|
+
* @returns
|
|
58
|
+
* A promise that resolves the extended inner module.
|
|
59
|
+
*/
|
|
60
|
+
private _read;
|
|
61
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|