{"version":3,"sources":["../src/linter.ts"],"names":[],"mappings":";AAyBA,OAAO,EAAC,MAAM,EAAC,MAAM,UAAU,CAAC;AAChC,OAAO,EAAC,MAAM,EAAC,MAAM,QAAQ,CAAC;AAC9B,OAAO,EAAC,YAAY,EAAC,MAAM,QAAQ,CAAC;AACpC,OAAO,EAAC,aAAa,EAAC,MAAM,kBAAkB,CAAC;AAC/C,OAAO,KAAK,EAAC,YAAY,EAAC,MAAM,iBAAiB,CAAC;AAClD,OAAO,EAAC,GAAG,EAAC,MAAM,aAAa,CAAC;AAKhC,qBAAa,MAAM;IAClB,SAAgB,OAAO,EAAE,MAAM,CAAC;IAChC,SAAgB,GAAG,EAAE,GAAG,CAAC;IACzB,SAAgB,GAAG,EAAE,MAAM,CAAC;IAC5B,SAAgB,MAAM,EAAE,YAAY,CAAC;gBAEzB,GAAG,EAAE,MAAM,EAAE,MAAM,EAAE,YAAY,EAAE,GAAG,EAAE,GAAG;IAShD,YAAY,CAAC,GAAG,EAAE,YAAY,GAAG,IAAI;IAc/B,OAAO,CAAC,GAAG,EAAE,YAAY,GAAG,OAAO,CAAC,aAAa,CAAC;CAgC/D","file":"linter.d.ts","sourcesContent":["/**\n *\tMIT License\n *\n *\tCopyright (c) 2019 - 2022 Toreda, Inc.\n *\n *\tPermission is hereby granted, free of charge, to any person obtaining a copy\n *\tof this software and associated documentation files (the \"Software\"), to deal\n *\tin the Software without restriction, including without limitation the rights\n *\tto use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n *\tcopies of the Software, and to permit persons to whom the Software is\n *\tfurnished to do so, subject to the following conditions:\n\n * \tThe above copyright notice and this permission notice shall be included in all\n * \tcopies or substantial portions of the Software.\n *\n * \tTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n *\tIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n *\tFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n * \tAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n *\tLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n *\tOUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\n * \tSOFTWARE.\n *\n */\n\nimport {Config} from './config';\nimport {ESLint} from 'eslint';\nimport {EventEmitter} from 'stream';\nimport {LinterSummary} from './linter/summary';\nimport type {LinterTarget} from './linter/target';\nimport {Log} from '@toreda/log';\n\n/**\n * @category Linter\n */\nexport class Linter {\n\tpublic readonly _eslint: ESLint;\n\tpublic readonly log: Log;\n\tpublic readonly cfg: Config;\n\tpublic readonly events: EventEmitter;\n\n\tconstructor(cfg: Config, events: EventEmitter, log: Log) {\n\t\tthis.log = log.makeLog('Linter');\n\t\tthis.cfg = cfg;\n\t\tthis.events = events;\n\n\t\tthis._eslint = new ESLint(cfg.linter.eslintOptions());\n\t\tthis.execute = this.execute.bind(this);\n\t}\n\n\tpublic assertTarget(tgt: LinterTarget): void {\n\t\tif (!tgt) {\n\t\t\tthrow new Error(`linter:tgt:missing`);\n\t\t}\n\n\t\tif (tgt.srcPatterns === undefined || tgt.srcPatterns === null) {\n\t\t\tthrow new Error(`linter:tgt.srcPatterns:missing.`);\n\t\t}\n\n\t\tif (!Array.isArray(tgt.srcPatterns)) {\n\t\t\tthrow new Error(`linter:tgt.srcPatterns:bad_format`);\n\t\t}\n\t}\n\n\tpublic async execute(tgt: LinterTarget): Promise<LinterSummary> {\n\t\tconst summary = new LinterSummary();\n\t\tconst fnLog = this.log.makeLog('execute');\n\t\tfnLog.debug('Linter execution started');\n\n\t\tthis.assertTarget(tgt);\n\n\t\ttry {\n\t\t\tconst results = await this._eslint.lintFiles(tgt.srcPatterns);\n\t\t\tconst formatterId = typeof tgt?.formatterId === 'string' ? tgt?.formatterId : 'stylish';\n\t\t\tconst formatter = await this._eslint.loadFormatter(formatterId);\n\n\t\t\tconst resultText = await formatter.format(results);\n\n\t\t\tsummary.resultText = resultText;\n\t\t\tfor (const result of results) {\n\t\t\t\tsummary.add(result);\n\t\t\t}\n\n\t\t\tfnLog.info(resultText);\n\t\t\tsummary.done();\n\t\t} catch (e: unknown) {\n\t\t\tif (e instanceof Error) {\n\t\t\t\tfnLog.error(e.message);\n\t\t\t} else {\n\t\t\t\tfnLog.error(`Unknown error type thrown during execute call.`);\n\t\t\t}\n\t\t}\n\n\t\tfnLog.debug('Linter execution complete.');\n\t\treturn summary;\n\t}\n}\n"]}