stylelint-checkstyle-reporter
Version:
Output Checkstyle XML reports of stylelint results
1 lines • 4.93 kB
Source Map (JSON)
{"version":3,"file":"reporter-with-stdin.mjs","sources":["../src/checkstyle-report.ts","../src/reporter-with-stdin.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 { LintResult } from 'stylelint';\nimport getStdin from 'get-stdin';\nimport { stylelintToCheckstyle } from './formatter';\n\nconst run = async () => {\n let stdinString = '';\n try {\n stdinString = await getStdin();\n } catch {\n console.error('Unable to read from stdin. Did you pass anything?');\n return;\n }\n let stdin: LintResult[];\n try {\n stdin = JSON.parse(stdinString);\n } catch {\n console.error('Unable to parse stdin as JSON. Did you forget to use -f json?');\n return;\n }\n\n console.log(stylelintToCheckstyle(stdin));\n};\n\nvoid run();\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","async","stdin","stdinString","getStdin","console","JSON","parse","log","stylelintResults","_","outputConfig","checkStyleReport","forEach","stylelintResult","source","warnings","warning","column","line","message","text","severity","rule","stylelintToCheckstyle","run"],"mappings":"oEAaaA,EAKT,WAAAC,GAFQC,KAAAC,WAAY,EAGhBD,KAAKE,QAAUC,EAAO,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,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