{"version":3,"file":"stylelint-checkstyle-reporter.cjs","sources":["../src/checkstyle-report.ts","../src/formatter.ts"],"sourcesContent":["import { create } from 'xmlbuilder2';\nimport { XMLBuilder, XMLWriterOptions } from 'xmlbuilder2/lib/interfaces';\n\nconst checkstyleVersion = '4.3';\n\nexport interface CheckstyleError {\n    source: string;\n    line: number;\n    column: number;\n    severity: 'warning' | 'error';\n    message: string;\n}\n\nexport class CheckstyleReport {\n    private builder: XMLBuilder;\n\n    private fileLevel = false;\n\n    constructor() {\n        this.builder = create({ version: '1.0', encoding: 'utf-8' });\n        this.builder = this.builder.ele('checkstyle', {\n            version: checkstyleVersion,\n        });\n    }\n\n    startFile(path: string): void {\n        if (this.fileLevel) {\n            throw new Error('You have already started a file. Please call endFile first.');\n        }\n        this.builder = this.builder.ele('file', { name: path });\n        this.fileLevel = true;\n    }\n\n    endFile(): void {\n        if (!this.fileLevel) {\n            throw new Error('You have not started a file yet. Call startFile first.');\n        }\n        this.builder = this.builder.up();\n        this.fileLevel = false;\n    }\n\n    addError(error: CheckstyleError): void {\n        if (!this.fileLevel) {\n            throw new Error('You have not started a file yet. Call startFile first.');\n        }\n        this.builder = this.builder.ele('error', error).up();\n    }\n\n    generate(options?: XMLWriterOptions): string {\n        return this.builder.end(options ?? {});\n    }\n}\n","import { Formatter, LintResult, Warning } from 'stylelint';\nimport { CheckstyleReport } from './checkstyle-report';\nimport { XMLWriterOptions } from 'xmlbuilder2/lib/interfaces';\n\nexport const stylelintToCheckstyle = ((\n    stylelintResults: LintResult[],\n    _?: unknown,\n    outputConfig?: XMLWriterOptions,\n): string => {\n    const checkStyleReport = new CheckstyleReport();\n    stylelintResults.forEach((stylelintResult: LintResult) => {\n        if (!stylelintResult.source) {\n            return;\n        }\n        checkStyleReport.startFile(stylelintResult.source);\n        stylelintResult.warnings.forEach((warning: Warning) => {\n            checkStyleReport.addError({\n                column: warning.column,\n                line: warning.line,\n                message: warning.text,\n                severity: warning.severity,\n                source: `stylelint.rules.${warning.rule}`,\n            });\n        });\n        checkStyleReport.endFile();\n    });\n    return checkStyleReport.generate(outputConfig);\n}) satisfies Formatter;\n"],"names":["CheckstyleReport","constructor","this","fileLevel","builder","create","version","encoding","ele","startFile","path","Error","name","endFile","up","addError","error","generate","options","end","stylelintToCheckstyle","stylelintResults","_","outputConfig","checkStyleReport","forEach","stylelintResult","source","warnings","warning","column","line","message","text","severity","rule"],"mappings":"uGAaaA,EAKT,WAAAC,GAFQC,KAAAC,WAAY,EAGhBD,KAAKE,QAAUC,SAAO,CAAEC,QAAS,MAAOC,SAAU,UAClDL,KAAKE,QAAUF,KAAKE,QAAQI,IAAI,aAAc,CAC1CF,QAlBc,OAoBtB,CAEA,SAAAG,CAAUC,GACN,GAAIR,KAAKC,UACL,MAAM,IAAIQ,MAAM,+DAEpBT,KAAKE,QAAUF,KAAKE,QAAQI,IAAI,OAAQ,CAAEI,KAAMF,IAChDR,KAAKC,WAAY,CACrB,CAEA,OAAAU,GACI,IAAKX,KAAKC,UACN,MAAM,IAAIQ,MAAM,0DAEpBT,KAAKE,QAAUF,KAAKE,QAAQU,KAC5BZ,KAAKC,WAAY,CACrB,CAEA,QAAAY,CAASC,GACL,IAAKd,KAAKC,UACN,MAAM,IAAIQ,MAAM,0DAEpBT,KAAKE,QAAUF,KAAKE,QAAQI,IAAI,QAASQ,GAAOF,IACpD,CAEA,QAAAG,CAASC,GACL,OAAOhB,KAAKE,QAAQe,IAAID,GAAW,CAAA,EACvC,EC9CG,MAAME,GACTC,EACAC,EACAC,KAEA,MAAMC,EAAmB,IAAIxB,EAiB7B,OAhBAqB,EAAiBI,SAASC,IACjBA,EAAgBC,SAGrBH,EAAiBf,UAAUiB,EAAgBC,QAC3CD,EAAgBE,SAASH,SAASI,IAC9BL,EAAiBT,SAAS,CACtBe,OAAQD,EAAQC,OAChBC,KAAMF,EAAQE,KACdC,QAASH,EAAQI,KACjBC,SAAUL,EAAQK,SAClBP,OAAQ,mBAAmBE,EAAQM,QACrC,IAENX,EAAiBX,UAAS,IAEvBW,EAAiBP,SAASM,EACpC"}