|
| 1 | + |
| 2 | +package codacy.codesniffer.docsgen.parsers |
| 3 | + |
| 4 | +import codacy.codesniffer.docsgen.VersionsHelper |
| 5 | +import scala.util.matching.Regex |
| 6 | + |
| 7 | +import better.files.File |
| 8 | +import com.codacy.plugins.api.results.Pattern |
| 9 | + |
| 10 | +import scala.annotation.nowarn |
| 11 | + |
| 12 | +class VaimoParser extends DocsParser { |
| 13 | + |
| 14 | + override val repositoryURL = "https://bitbucket.org/vaimo/phpcs-rulesets" |
| 15 | + |
| 16 | + override val checkoutCommit: String = VersionsHelper.vaimo |
| 17 | + |
| 18 | + |
| 19 | + override val sniffRegex: Regex = """.*(Vaimo)\/Sniffs\/(.*?)\/(.*?)Sniff.php""".r |
| 20 | + |
| 21 | + @nowarn("msg=match may not be exhaustive") |
| 22 | + override def patternIdPartsFor(relativizedFilePath: String): PatternIdParts = { |
| 23 | + val sniffRegex(vaimoVersion, sniffType, patternName) = relativizedFilePath |
| 24 | + PatternIdParts(vaimoVersion, sniffType, patternName) |
| 25 | + } |
| 26 | + |
| 27 | +override def descriptionWithDocs(rootDir: File, |
| 28 | + patternIdParts: PatternIdParts, |
| 29 | + patternFile: File |
| 30 | + ): (Pattern.Description, Option[String]) = { |
| 31 | + (description(patternIdParts, rootDir), |
| 32 | + this.parseExtendedDescription("Vaimo\\Sniffs\\Custom", "Vaimo", patternIdParts, rootDir) |
| 33 | + ) |
| 34 | + } |
| 35 | + |
| 36 | + private[this] def description(patternIdParts: PatternIdParts, rootDir: File): Pattern.Description = { |
| 37 | + val caseRegexPattern = """((?<=\p{Ll})\p{Lu}|\p{Lu}(?=\p{Ll}))""".r |
| 38 | + val patternName = caseRegexPattern.replaceAllIn(patternIdParts.patternName, " $1").trim |
| 39 | + val sniffName = caseRegexPattern.replaceAllIn(patternIdParts.sniffType, " $1").trim |
| 40 | + val title = Pattern.Title(s"$sniffName: $patternName") |
| 41 | + val extended = this.parseDescription("Vaimo\\Sniffs\\Custom", "Vaimo", patternIdParts, rootDir) |
| 42 | + Pattern.Description(patternIdParts.patternId, title, extended, None, Set.empty) |
| 43 | + } |
| 44 | +} |
| 45 | + |
0 commit comments