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