@zthun/janitor-lint 19.4.3 → 19.5.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.
@@ -0,0 +1,918 @@
1
+ import chalk from 'chalk';
2
+ import { createRequire } from 'node:module';
3
+ import { cosmiconfig } from 'cosmiconfig';
4
+ import { resolve } from 'path';
5
+ import { resolveConfig, getFileInfo, check } from 'prettier';
6
+ import { HTMLHint } from 'htmlhint';
7
+ import { load } from 'js-yaml';
8
+ import { ESLint } from 'eslint';
9
+ import { every, some, values, uniq, noop } from 'lodash-es';
10
+ import { readFile } from 'fs';
11
+ import { sync } from 'glob';
12
+ import { promisify } from 'util';
13
+ import { lint } from 'markdownlint/promise';
14
+ import { lint as lint$1 } from 'cspell';
15
+ import stylelint from 'stylelint';
16
+
17
+ function $require(id) {
18
+ const require = createRequire(import.meta.url);
19
+ return require(id);
20
+ }
21
+ function $resolve(id, options) {
22
+ const require = createRequire(import.meta.url);
23
+ return require.resolve(id, options);
24
+ }
25
+
26
+ function _define_property$9(obj, key, value) {
27
+ if (key in obj) {
28
+ Object.defineProperty(obj, key, {
29
+ value: value,
30
+ enumerable: true,
31
+ configurable: true,
32
+ writable: true
33
+ });
34
+ } else {
35
+ obj[key] = value;
36
+ }
37
+ return obj;
38
+ }
39
+ /**
40
+ * Represents the standard extender.
41
+ *
42
+ * This extender works the same as how eslint extends their
43
+ * configuration. You can pass a key that acts as the extends key which holds paths
44
+ * to the extendable files/modules. Note that this class, unlike eslint, does not assume any naming
45
+ * conventions and ONLY shared configurations are supported. You must pass the full path of the
46
+ * configs when extending, and plugin based syntax is not recognized.
47
+ *
48
+ * It is always better to just use the extension methods of the actual
49
+ * applications if those are available, but this can be used as a fallback or an
50
+ * extension of behavior for child linters that do not support extendable configs.
51
+ */ class ZConfigExtender {
52
+ /**
53
+ * Extends the configuration value.
54
+ *
55
+ * This is similar to how eslint works. This will do an
56
+ * asynchronous require on each configuration under the key in the
57
+ * config. If the key in the config is falsy, then the config is returned.
58
+ *
59
+ * The actual key in the config is deleted.
60
+ *
61
+ * @param config
62
+ * - The config to extend.
63
+ *
64
+ * @returns
65
+ * A promise that resolves the extended configuration.
66
+ */ async extend(config) {
67
+ if (config == null || !Object.hasOwnProperty.call(config, this.key)) {
68
+ return config;
69
+ }
70
+ const extensions = config[this.key];
71
+ const modules = Array.isArray(extensions) ? extensions : [
72
+ extensions
73
+ ];
74
+ const resolved = await Promise.all(modules.map((m)=>this._read(m)));
75
+ let updated = resolved.reduce((last, current)=>Object.assign({}, last, current), {});
76
+ updated = Object.assign({}, updated, config);
77
+ delete updated[this.key];
78
+ return updated;
79
+ }
80
+ /**
81
+ * Reads a module recursively.
82
+ *
83
+ * @param module
84
+ * - The module to read.
85
+ *
86
+ * @returns
87
+ * A promise that resolves the extended inner module.
88
+ */ async _read(module) {
89
+ const data = $require(module);
90
+ return await this.extend(data);
91
+ }
92
+ /**
93
+ * Initializes a new instance of this object.
94
+ *
95
+ * @param key
96
+ * - The key to extend.
97
+ */ constructor(key = "extends"){
98
+ _define_property$9(this, "key", void 0);
99
+ this.key = key;
100
+ }
101
+ }
102
+
103
+ function _define_property$8(obj, key, value) {
104
+ if (key in obj) {
105
+ Object.defineProperty(obj, key, {
106
+ value: value,
107
+ enumerable: true,
108
+ configurable: true,
109
+ writable: true
110
+ });
111
+ } else {
112
+ obj[key] = value;
113
+ }
114
+ return obj;
115
+ }
116
+ /**
117
+ * Represents a reader that uses the cosmiconfig standard for files.
118
+ */ class ZConfigReaderCosmic {
119
+ /**
120
+ * Runs a search for the appropriate configuration file.
121
+ *
122
+ * The extension keyword is deleted from the config.
123
+ *
124
+ * @returns
125
+ * A promise that resolves with the expanded configuration.
126
+ */ async search() {
127
+ const explorer = cosmiconfig(this.name, {
128
+ searchStrategy: "project"
129
+ });
130
+ // The first step is the standard cosmiconfig
131
+ // search to see if any of these paths exists.
132
+ // These are highest priority.
133
+ const searched = await explorer.search();
134
+ if (searched) {
135
+ return searched.filepath;
136
+ }
137
+ // Try our additional paths, if any.
138
+ for (const path of this.paths){
139
+ const full = resolve(path);
140
+ const result = await explorer.load(full).catch(()=>null);
141
+ if (result) {
142
+ return result.filepath;
143
+ }
144
+ }
145
+ return null;
146
+ }
147
+ /**
148
+ * Reads the config file.
149
+ *
150
+ * @param config -
151
+ * The optional configuration file. If this is null then the cosmiconfig path is searched on the name.
152
+ *
153
+ * @returns
154
+ * A promise that resolves the json object that represents the config.
155
+ */ async read(config) {
156
+ const configLoad = config ? Promise.resolve(config) : this.search();
157
+ const configFile = await configLoad;
158
+ if (!configFile) {
159
+ return {};
160
+ }
161
+ const path = $resolve(configFile, {
162
+ paths: [
163
+ process.cwd()
164
+ ]
165
+ });
166
+ const buffer = await cosmiconfig(this.name).load(path);
167
+ return await this.extender.extend(buffer.config);
168
+ }
169
+ /**
170
+ * Initializes a new instance of this object.
171
+ *
172
+ * @param name -
173
+ * The name of the application to load.
174
+ * @param extender -
175
+ * The extender to expand upon the read configuration.
176
+ * @param paths -
177
+ * The additional paths to read if cosmic config does not find a valid config. Remember that these
178
+ * are paths, not modules in this case, so you can't load things from the node modules directory
179
+ * using these values. These only affect the search for the config file, not the actual
180
+ * read of the config.
181
+ */ constructor(name, extender, paths = []){
182
+ _define_property$8(this, "name", void 0);
183
+ _define_property$8(this, "extender", void 0);
184
+ _define_property$8(this, "paths", void 0);
185
+ this.name = name;
186
+ this.extender = extender;
187
+ this.paths = paths;
188
+ }
189
+ }
190
+
191
+ /**
192
+ * Represents a config reader that returns the empty options.
193
+ */ class ZConfigReaderNull {
194
+ /**
195
+ * Returns a null resolved promise.
196
+ *
197
+ * @returns
198
+ * A promise that resolves to null.
199
+ */ async read() {
200
+ return null;
201
+ }
202
+ }
203
+
204
+ /**
205
+ * Represents a configuration reader for prettier.
206
+ */ class ZConfigReaderPrettier {
207
+ /**
208
+ * Reads the configuration file.
209
+ *
210
+ * @param config -
211
+ * The config module to load. If this value is falsy,
212
+ * then prettier will be used to retrieve the configuration.
213
+ *
214
+ * @returns
215
+ * The options for the config file.
216
+ */ async read(config) {
217
+ const cwd = process.cwd();
218
+ const configFile = config ? $resolve(config, {
219
+ paths: [
220
+ cwd
221
+ ]
222
+ }) : undefined;
223
+ const ops = {
224
+ config: configFile
225
+ };
226
+ // This function seems to have a slight issue in that it needs one directory deeper than
227
+ // the directory you want to start the search in. The documentation on this isn't exactly correct,
228
+ // and it was this change, https://github.com/prettier/prettier/pull/15363/files#diff-6569a6bfe16237da3c47f035a6f3325a79e958507cf866a1bd703ae9210129b3,
229
+ // that broke it.
230
+ const options = await resolveConfig(resolve(process.cwd(), "some-prettier-config"), ops);
231
+ return options || {};
232
+ }
233
+ }
234
+
235
+ function _define_property$7(obj, key, value) {
236
+ if (key in obj) {
237
+ Object.defineProperty(obj, key, {
238
+ value: value,
239
+ enumerable: true,
240
+ configurable: true,
241
+ writable: true
242
+ });
243
+ } else {
244
+ obj[key] = value;
245
+ }
246
+ return obj;
247
+ }
248
+ /**
249
+ * Represents an object that can be used to hint html files.
250
+ */ class ZContentLinterHtml {
251
+ /**
252
+ * Lints the content.
253
+ *
254
+ * @param content -
255
+ * The content to check.
256
+ * @param contentPath -
257
+ * The path of the content data.
258
+ * @param options -
259
+ * The htmlhint options.
260
+ *
261
+ * @returns
262
+ * A promise that resolves if the content is lint free, and rejects if it has lint errors.
263
+ */ lint(content, contentPath, options) {
264
+ const messages = HTMLHint.verify(content, options);
265
+ if (messages.length > 0) {
266
+ const logs = HTMLHint.format(messages, this._formatOptions);
267
+ return Promise.reject(logs);
268
+ }
269
+ return Promise.resolve(`${contentPath} is lint free.`);
270
+ }
271
+ constructor(){
272
+ _define_property$7(this, "_formatOptions", {
273
+ colors: true
274
+ });
275
+ }
276
+ }
277
+
278
+ /**
279
+ * Represents the linter for json files.
280
+ */ class ZContentLinterJson {
281
+ /**
282
+ * Lints the collection of json files.
283
+ *
284
+ * @param contents -
285
+ * The json file contents.
286
+ */ async lint(contents) {
287
+ return JSON.parse(contents);
288
+ }
289
+ }
290
+
291
+ /**
292
+ * Represents an object that can be used to perform prettier checks on files.
293
+ */ class ZContentLinterPretty {
294
+ /**
295
+ * Lints the content.
296
+ *
297
+ * @param content -
298
+ * The content to check.
299
+ * @param contentPath -
300
+ * The path of the content data.
301
+ * @param options -
302
+ * The htmlhint options.
303
+ *
304
+ * @returns
305
+ * A promise that resolves if the content is lint free, and rejects if it has lint errors.
306
+ */ async lint(content, contentPath, options) {
307
+ const file = await getFileInfo(contentPath);
308
+ const finalOptions = Object.assign({}, {
309
+ parser: file.inferredParser
310
+ }, options);
311
+ const formatted = await check(content, finalOptions);
312
+ if (!formatted) {
313
+ return Promise.reject(`${contentPath} is not formatted.`);
314
+ }
315
+ return Promise.resolve(`${contentPath} is properly formatted.`);
316
+ }
317
+ }
318
+
319
+ /**
320
+ * Represents a linter for yml files.
321
+ */ class ZContentLinterYaml {
322
+ /**
323
+ * Lints yml files.
324
+ *
325
+ * @param contents -
326
+ * Yaml formatted string.
327
+ *
328
+ * @returns
329
+ * A promise that resolves if successful, or rejects if failed.
330
+ */ async lint(contents) {
331
+ return load(contents);
332
+ }
333
+ }
334
+
335
+ function _define_property$6(obj, key, value) {
336
+ if (key in obj) {
337
+ Object.defineProperty(obj, key, {
338
+ value: value,
339
+ enumerable: true,
340
+ configurable: true,
341
+ writable: true
342
+ });
343
+ } else {
344
+ obj[key] = value;
345
+ }
346
+ return obj;
347
+ }
348
+ /**
349
+ * Represents an object that can be used to perform eslint on javascript files.
350
+ */ class ZLinterEs {
351
+ /**
352
+ * Runs the lint given the specified config and source files.
353
+ *
354
+ * @param src -
355
+ * The list of files globs to lint.
356
+ * @param config -
357
+ * The optional lint config file.
358
+ *
359
+ * @returns
360
+ * A promise that resolves to true if the lint is
361
+ * fully successful, and false if the lint
362
+ * has errors.
363
+ */ async lint(src, config) {
364
+ const esOptions = {
365
+ errorOnUnmatchedPattern: false
366
+ };
367
+ if (config) {
368
+ esOptions.overrideConfigFile = $resolve(config, {
369
+ paths: [
370
+ process.cwd()
371
+ ]
372
+ });
373
+ }
374
+ try {
375
+ const engine = this.engineFactory(esOptions);
376
+ const formatter = await engine.loadFormatter();
377
+ const report = await engine.lintFiles(src);
378
+ const output = formatter.format(report);
379
+ this._logger.log(output);
380
+ return every(report, (r)=>r.errorCount === 0);
381
+ } catch (err) {
382
+ this._logger.log(err);
383
+ return false;
384
+ }
385
+ }
386
+ /**
387
+ * Initializes a new instance of this object.
388
+ *
389
+ * @param _logger -
390
+ * The logger to output to.
391
+ */ constructor(_logger){
392
+ _define_property$6(this, "_logger", void 0);
393
+ /**
394
+ * The factory that constructs a CLIEngine object.
395
+ *
396
+ * @param options -
397
+ * The engine options.
398
+ *
399
+ * @returns
400
+ * The engine that can be used to perform eslint.
401
+ */ _define_property$6(this, "engineFactory", void 0);
402
+ this._logger = _logger;
403
+ this.engineFactory = (options)=>new ESLint(options);
404
+ }
405
+ }
406
+
407
+ function _define_property$5(obj, key, value) {
408
+ if (key in obj) {
409
+ Object.defineProperty(obj, key, {
410
+ value: value,
411
+ enumerable: true,
412
+ configurable: true,
413
+ writable: true
414
+ });
415
+ } else {
416
+ obj[key] = value;
417
+ }
418
+ return obj;
419
+ }
420
+ /**
421
+ * Represents an object that can lint files one at a time.
422
+ */ class ZLinterFile {
423
+ /**
424
+ * Lints the collection of json files.
425
+ *
426
+ * @param src -
427
+ * The file list of blobs to lint.
428
+ * @param config -
429
+ * The optional path to the config file.
430
+ * @param exclude -
431
+ * The list of globs to exclude.
432
+ */ async lint(src, config, exclude) {
433
+ const readFileAsync = promisify(readFile);
434
+ let options = {};
435
+ const globOptions = {
436
+ dot: true,
437
+ ignore: exclude
438
+ };
439
+ let files = [];
440
+ src.forEach((pattern)=>files = files.concat(sync(pattern, globOptions)));
441
+ if (files.length === 0) {
442
+ this._logger.log(chalk.yellow.italic("No globs matched any files."));
443
+ return true;
444
+ }
445
+ try {
446
+ options = await this._configReader.read(config);
447
+ } catch (err) {
448
+ this._logger.error(chalk.red(err));
449
+ return false;
450
+ }
451
+ this._logger.log(chalk.green.italic(`Checking syntax for ${files.length} ${this._type} files.`));
452
+ this._logger.log();
453
+ let result = true;
454
+ for (const file of files){
455
+ const fullFilePath = resolve(file);
456
+ try {
457
+ const content = await readFileAsync(fullFilePath, "utf-8");
458
+ await this._contentLint.lint(content, fullFilePath, options, config);
459
+ } catch (err) {
460
+ result = false;
461
+ this._format(fullFilePath, err);
462
+ }
463
+ }
464
+ return result;
465
+ }
466
+ /**
467
+ * Formats a file error to the logger.
468
+ *
469
+ * @param file -
470
+ * The file that failed to parse.
471
+ * @param err -
472
+ * The error that occurred.Ø
473
+ */ _format(file, err) {
474
+ const fileFormat = `Errors in ${file}`;
475
+ this._logger.error(chalk.green.underline(fileFormat));
476
+ if (Array.isArray(err)) {
477
+ err.forEach((log)=>this._logger.error(chalk.red(log)));
478
+ } else {
479
+ this._logger.error(chalk.red(err));
480
+ }
481
+ }
482
+ /**
483
+ * Initializes a new instance of this object.
484
+ *
485
+ * @param _contentLint -
486
+ * The linter for an individual file.
487
+ * @param _configReader -
488
+ * The config reader.
489
+ * @param _logger -
490
+ * The logger to use.
491
+ * @param _type -
492
+ * The file type.
493
+ */ constructor(_contentLint, _configReader, _logger, _type){
494
+ _define_property$5(this, "_contentLint", void 0);
495
+ _define_property$5(this, "_configReader", void 0);
496
+ _define_property$5(this, "_logger", void 0);
497
+ _define_property$5(this, "_type", void 0);
498
+ this._contentLint = _contentLint;
499
+ this._configReader = _configReader;
500
+ this._logger = _logger;
501
+ this._type = _type;
502
+ }
503
+ }
504
+
505
+ function _define_property$4(obj, key, value) {
506
+ if (key in obj) {
507
+ Object.defineProperty(obj, key, {
508
+ value: value,
509
+ enumerable: true,
510
+ configurable: true,
511
+ writable: true
512
+ });
513
+ } else {
514
+ obj[key] = value;
515
+ }
516
+ return obj;
517
+ }
518
+ /**
519
+ * Represents a linter object that checks markdown.
520
+ */ class ZLinterMarkdown {
521
+ /**
522
+ * Lints all files matched by the specified glob pattern.
523
+ *
524
+ * @param src -
525
+ * The glob patterns to match and lint.
526
+ * @param cfg -
527
+ * The optional config for the linter.
528
+ * @param exclude -
529
+ * The glob patterns to exclude.
530
+ *
531
+ * @returns A promise that resolves to true if the linting is ok, and false if the linting fails.
532
+ */ async lint(src, cfg, exclude = []) {
533
+ let config;
534
+ try {
535
+ config = await this._reader.read(cfg);
536
+ } catch (err) {
537
+ this._logger.error(chalk.red(err));
538
+ return false;
539
+ }
540
+ const globOptions = {
541
+ dot: true,
542
+ ignore: exclude
543
+ };
544
+ let files = [];
545
+ src.forEach((pattern)=>files = files.concat(sync(pattern, globOptions)));
546
+ const options = {
547
+ files,
548
+ config
549
+ };
550
+ const result = await lint(options);
551
+ this._logger.log(`${result.toString().trim()}`);
552
+ return !some(values(result), (val)=>val.length > 0);
553
+ }
554
+ /**
555
+ * Initializes a new instance of this object.
556
+ *
557
+ * @param _logger -
558
+ * The logger to write messages to.
559
+ * @param _reader -
560
+ * The configuration reader.
561
+ */ constructor(_logger, _reader){
562
+ _define_property$4(this, "_logger", void 0);
563
+ _define_property$4(this, "_reader", void 0);
564
+ this._logger = _logger;
565
+ this._reader = _reader;
566
+ }
567
+ }
568
+
569
+ function _define_property$3(obj, key, value) {
570
+ if (key in obj) {
571
+ Object.defineProperty(obj, key, {
572
+ value: value,
573
+ enumerable: true,
574
+ configurable: true,
575
+ writable: true
576
+ });
577
+ } else {
578
+ obj[key] = value;
579
+ }
580
+ return obj;
581
+ }
582
+ /**
583
+ * Represents an object that will report on file globs, but will
584
+ * pass the actual linting job to another linter.
585
+ */ class ZLinterReport {
586
+ /**
587
+ * Lints the collection of json files.
588
+ *
589
+ * @param src -
590
+ * The file list of blobs to lint.
591
+ * @param config -
592
+ * The optional path to the config file.
593
+ * @param exclude -
594
+ * The list of globs to exclude.
595
+ */ async lint(src, config, exclude) {
596
+ const globOptions = {
597
+ dot: true,
598
+ ignore: exclude
599
+ };
600
+ let files = [];
601
+ src.forEach((pattern)=>files = files.concat(sync(pattern, globOptions)));
602
+ files = uniq(files);
603
+ if (files.length === 0) {
604
+ this._logger.log(chalk.yellow.italic("No globs matched any files."));
605
+ return true;
606
+ }
607
+ this._logger.log(chalk.green.italic(`Checking syntax for ${files.length} ${this._type} files.`));
608
+ return this._child.lint(src, config, exclude);
609
+ }
610
+ /**
611
+ * Initializes a new instance of this object.
612
+ *
613
+ * @param _child -
614
+ * The child linter to pass the operation off to.
615
+ * @param _logger -
616
+ * The logger to use.
617
+ * @param _type -
618
+ * The file type.
619
+ */ constructor(_child, _logger, _type){
620
+ _define_property$3(this, "_child", void 0);
621
+ _define_property$3(this, "_logger", void 0);
622
+ _define_property$3(this, "_type", void 0);
623
+ this._child = _child;
624
+ this._logger = _logger;
625
+ this._type = _type;
626
+ }
627
+ }
628
+
629
+ function _define_property$2(obj, key, value) {
630
+ if (key in obj) {
631
+ Object.defineProperty(obj, key, {
632
+ value: value,
633
+ enumerable: true,
634
+ configurable: true,
635
+ writable: true
636
+ });
637
+ } else {
638
+ obj[key] = value;
639
+ }
640
+ return obj;
641
+ }
642
+ /**
643
+ * Represents an object that can be used to perform cspell on files.
644
+ */ class ZLinterSpelling {
645
+ /**
646
+ * Runs the lint given the specified config and source files.
647
+ *
648
+ * @param src -
649
+ * The list of files globs to lint.
650
+ * @param config -
651
+ * The optional lint config file.
652
+ * @param exclude -
653
+ * The list of file globs to exclude.
654
+ *
655
+ * @returns
656
+ * A promise that resolves to true if the
657
+ * lint is fully successful, and false if the lint
658
+ * has errors.
659
+ */ async lint(src, config, exclude) {
660
+ const options = {
661
+ exclude
662
+ };
663
+ if (config) {
664
+ options.config = $resolve(config, {
665
+ paths: [
666
+ process.cwd()
667
+ ]
668
+ });
669
+ }
670
+ const info = noop;
671
+ const debug = noop;
672
+ const error = noop;
673
+ const progress = noop;
674
+ const result = noop;
675
+ const issue = (issue)=>{
676
+ const position = `${issue.row}:${issue.col}`;
677
+ this._logger.log(`${chalk.green(issue.uri)}:${chalk.yellow(position)} - Unknown word (${chalk.red(issue.text)})`);
678
+ };
679
+ const emitters = {
680
+ info,
681
+ debug,
682
+ error,
683
+ progress,
684
+ issue,
685
+ result
686
+ };
687
+ const runResult = await lint$1(src, options, emitters);
688
+ if (runResult.errors > 0 || runResult.issues > 0) {
689
+ return false;
690
+ }
691
+ this._logger.log();
692
+ return true;
693
+ }
694
+ /**
695
+ * Initializes a new instance of this object.
696
+ *
697
+ * @param _logger -
698
+ * The logger to output to.
699
+ */ constructor(_logger){
700
+ _define_property$2(this, "_logger", void 0);
701
+ this._logger = _logger;
702
+ }
703
+ }
704
+
705
+ function _define_property$1(obj, key, value) {
706
+ if (key in obj) {
707
+ Object.defineProperty(obj, key, {
708
+ value: value,
709
+ enumerable: true,
710
+ configurable: true,
711
+ writable: true
712
+ });
713
+ } else {
714
+ obj[key] = value;
715
+ }
716
+ return obj;
717
+ }
718
+ /**
719
+ * Represents a linter for stylelint.
720
+ */ class ZLinterStyle {
721
+ /**
722
+ * Runs the file globs through the stylelint application.
723
+ *
724
+ * @param content -
725
+ * The list of globs to lint.
726
+ * @param config -
727
+ * The linter config file.
728
+ * @param exclude
729
+ * The globs to exclude.
730
+ *
731
+ * @returns
732
+ * A promise that, when resolved, returns true
733
+ * if there are no lint errors, or
734
+ * false if errors are present.
735
+ */ async lint(content, config, exclude) {
736
+ const options = {
737
+ files: content,
738
+ ignorePattern: exclude
739
+ };
740
+ if (config) {
741
+ options.configFile = $resolve(config, {
742
+ paths: [
743
+ process.cwd()
744
+ ]
745
+ });
746
+ }
747
+ const result = await stylelint.lint(options);
748
+ const verbose = await stylelint.formatters.verbose;
749
+ if (result.errored) {
750
+ const output = verbose(result.results, result);
751
+ this._logger.log(output);
752
+ return false;
753
+ }
754
+ this._logger.log("");
755
+ return true;
756
+ }
757
+ /**
758
+ * Initializes a new instance of this object.
759
+ *
760
+ * @param _logger -
761
+ * The logger to log the output to.
762
+ */ constructor(_logger){
763
+ _define_property$1(this, "_logger", void 0);
764
+ this._logger = _logger;
765
+ }
766
+ }
767
+
768
+ function _define_property(obj, key, value) {
769
+ if (key in obj) {
770
+ Object.defineProperty(obj, key, {
771
+ value: value,
772
+ enumerable: true,
773
+ configurable: true,
774
+ writable: true
775
+ });
776
+ } else {
777
+ obj[key] = value;
778
+ }
779
+ return obj;
780
+ }
781
+ /**
782
+ * Represents the main entry point object for the application.
783
+ */ class ZJanitorLint {
784
+ /**
785
+ * Runs the lint given the required options.
786
+ *
787
+ * @param options -
788
+ * The lint options.
789
+ *
790
+ * @returns
791
+ * A promise that returns 0 if all linting was successful,
792
+ * and 1 if any of the linting failed.
793
+ */ async lint(options) {
794
+ let current = true;
795
+ let result = true;
796
+ const { lint = {} } = options;
797
+ const { jsonFiles, jsonFilesExclude, yamlFiles, yamlFilesExclude, markdownConfig, markdownFiles, markdownFilesExclude, esConfig, esFiles, styleConfig, styleFiles, styleFilesExclude, htmlConfig, htmlFiles, htmlFilesExclude, spellingConfig, spellingFiles, spellingFilesExclude, prettyConfig, prettyFiles, prettyFilesExclude } = lint;
798
+ if (jsonFiles) {
799
+ this._logger.log(chalk.magenta.underline(`Linting json files from ${jsonFiles.length} globs.`));
800
+ current = await this.jsonLint.lint(jsonFiles, undefined, jsonFilesExclude);
801
+ result = result && current;
802
+ }
803
+ if (yamlFiles) {
804
+ this._logger.log(chalk.magenta.underline(`Linting yaml files from ${yamlFiles.length} globs.`));
805
+ current = await this.yamlLint.lint(yamlFiles, undefined, yamlFilesExclude);
806
+ result = result && current;
807
+ }
808
+ if (markdownFiles) {
809
+ this._logger.log(chalk.magenta.underline(`Linting markdown files from ${markdownFiles.length} globs.`));
810
+ current = await this.markdownLint.lint(markdownFiles, markdownConfig, markdownFilesExclude);
811
+ result = result && current;
812
+ }
813
+ if (esFiles) {
814
+ this._logger.log(chalk.magenta.underline(`Linting ecmaScript files from ${esFiles.length} globs.`));
815
+ current = await this.esLint.lint(esFiles, esConfig, undefined);
816
+ result = result && current;
817
+ }
818
+ if (styleFiles) {
819
+ this._logger.log(chalk.magenta.underline(`Linting style files from ${styleFiles.length} globs.`));
820
+ current = await this.styleLint.lint(styleFiles, styleConfig, styleFilesExclude);
821
+ result = result && current;
822
+ }
823
+ if (htmlFiles) {
824
+ this._logger.log(chalk.magenta.underline(`Linting html files from ${htmlFiles.length} globs.`));
825
+ current = await this.htmlHint.lint(htmlFiles, htmlConfig, htmlFilesExclude);
826
+ result = result && current;
827
+ }
828
+ if (spellingFiles) {
829
+ this._logger.log(chalk.magenta.underline(`Checking spelling for ${spellingFiles.length} globs.`));
830
+ current = await this.spellLint.lint(spellingFiles, spellingConfig, spellingFilesExclude);
831
+ result = result && current;
832
+ }
833
+ if (prettyFiles) {
834
+ this._logger.log(chalk.magenta.underline(`Checking formatting for ${prettyFiles.length} globs.`));
835
+ current = await this.prettyLint.lint(prettyFiles, prettyConfig, prettyFilesExclude);
836
+ result = result && current;
837
+ }
838
+ return result ? 0 : 1;
839
+ }
840
+ /**
841
+ * Runs the application.
842
+ *
843
+ * @param args -
844
+ * The command line arguments.
845
+ *
846
+ * @returns
847
+ * A promise that returns 0 if all linting was
848
+ * successful, and 1 if any of the linting failed.
849
+ */ async run(args) {
850
+ try {
851
+ const options = await this.config.read(args.config);
852
+ return this.lint(options);
853
+ } catch (err) {
854
+ this._logger.error(err);
855
+ return 1;
856
+ }
857
+ }
858
+ /**
859
+ * Initializes a new instance of this object.
860
+ *
861
+ * @param _logger -
862
+ * The logger to use when formatting output.
863
+ */ constructor(_logger){
864
+ _define_property(this, "_logger", void 0);
865
+ /**
866
+ * The linter for js files.
867
+ */ _define_property(this, "esLint", void 0);
868
+ /**
869
+ * The linter for cspell. Useful for multiple file types.
870
+ */ _define_property(this, "spellLint", void 0);
871
+ /**
872
+ * The linter for prettier formatting checks.
873
+ */ _define_property(this, "prettyLint", void 0);
874
+ /**
875
+ * The linter for style files.
876
+ */ _define_property(this, "styleLint", void 0);
877
+ /**
878
+ * The linter for html files.
879
+ *
880
+ * Currently, htmlhint has no support for cosmiconfig based paths, so we're going to
881
+ * add them here.
882
+ */ _define_property(this, "htmlHint", void 0);
883
+ /**
884
+ * The linter for json files.
885
+ */ _define_property(this, "jsonLint", void 0);
886
+ /**
887
+ * The linter for yaml files.
888
+ */ _define_property(this, "yamlLint", void 0);
889
+ /**
890
+ * The linter for markdown files.
891
+ *
892
+ * Markdownlint is a bit annoying with this. They
893
+ * don't really fully support the cosmiconfig standard,
894
+ * and they only support the config files that are named
895
+ * .markdownlint.yaml, .markdownlint.json, and .markdownlint.cjs
896
+ */ _define_property(this, "markdownLint", void 0);
897
+ /**
898
+ * The configuration reader.
899
+ */ _define_property(this, "config", void 0);
900
+ this._logger = _logger;
901
+ this.esLint = new ZLinterReport(new ZLinterEs(this._logger), this._logger, "es");
902
+ this.spellLint = new ZLinterReport(new ZLinterSpelling(this._logger), this._logger, "various");
903
+ this.prettyLint = new ZLinterFile(new ZContentLinterPretty(), new ZConfigReaderPrettier(), this._logger, "pretty");
904
+ this.styleLint = new ZLinterReport(new ZLinterStyle(this._logger), this._logger, "style");
905
+ this.htmlHint = new ZLinterFile(new ZContentLinterHtml(), new ZConfigReaderCosmic("htmlhint", new ZConfigExtender()), this._logger, "html");
906
+ this.jsonLint = new ZLinterFile(new ZContentLinterJson(), new ZConfigReaderNull(), this._logger, "json");
907
+ this.yamlLint = new ZLinterFile(new ZContentLinterYaml(), new ZConfigReaderNull(), this._logger, "yaml");
908
+ this.markdownLint = new ZLinterReport(new ZLinterMarkdown(this._logger, new ZConfigReaderCosmic("markdownlint", new ZConfigExtender(), [
909
+ ".markdownlint.json",
910
+ ".markdownlint.yaml",
911
+ ".markdownlint.cjs"
912
+ ])), this._logger, "markdown");
913
+ this.config = new ZConfigReaderCosmic("janitor", new ZConfigExtender());
914
+ }
915
+ }
916
+
917
+ export { ZJanitorLint as Z, ZConfigExtender as a, ZConfigReaderCosmic as b, ZConfigReaderNull as c, ZConfigReaderPrettier as d, ZContentLinterHtml as e, ZContentLinterJson as f, ZContentLinterPretty as g, ZContentLinterYaml as h, ZLinterEs as i, ZLinterFile as j, ZLinterMarkdown as k, ZLinterReport as l, ZLinterSpelling as m, ZLinterStyle as n };
918
+ //# sourceMappingURL=janitor-lint-DdyMWYZn.js.map