Skip to content

Commit 91192f9

Browse files
authored
Add Vaimo Parser (#301)
1 parent cf98a30 commit 91192f9

File tree

10 files changed

+95
-0
lines changed

10 files changed

+95
-0
lines changed

doc-generator/src/main/scala/codacy/codesniffer/docsgen/Generator.scala

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ class Generator() {
2929
new PHPCSSecurityAuditDocsParser(),
3030
new SlevomatCSDocsParser(),
3131
new SymfonyDocsParser(),
32+
new VaimoUKParser(),
3233
new VipWordPressDocsParser(),
3334
new WordPressCSDocsParser()
3435
)

doc-generator/src/main/scala/codacy/codesniffer/docsgen/VersionsHelper.scala

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,4 +22,5 @@ object VersionsHelper {
2222
lazy val slevomatCS = properties("slevomat/coding-standard").str.replace("^","")
2323
lazy val codesniffer = properties("squizlabs/php_codesniffer").str.replace("^","")
2424
lazy val wordpress = properties("wp-coding-standards/wpcs").str.replace("^","")
25+
lazy val vaimoUK = properties("vaimo/uk-phpcs-standards").str.replace("^","")
2526
}

doc-generator/src/main/scala/codacy/codesniffer/docsgen/parsers/DocsParser.scala

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ trait DocsParser {
8787

8888
private[this] def withRepo[A](repositoryURL: String, checkoutCommit: String)(f: File => A): Either[Throwable, A] = {
8989
val dir = Files.createTempDirectory("")
90+
println(s"Cloning $repositoryURL into $dir")
9091
for {
9192
_ <- Right(
9293
CommandRunner
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
package codacy.codesniffer.docsgen.parsers
2+
3+
import codacy.codesniffer.docsgen.VersionsHelper
4+
import scala.util.matching.Regex
5+
6+
import better.files.File
7+
import com.codacy.plugins.api.results.Pattern
8+
9+
import scala.annotation.nowarn
10+
11+
class VaimoUKParser extends DocsParser {
12+
13+
override val repositoryURL = "https://bitbucket.org/vaimo/uk-phpcs-standards.git"
14+
15+
override val checkoutCommit: String = VersionsHelper.vaimoUK
16+
17+
18+
override val sniffRegex: Regex = """.*(Vaimo)\/Sniffs\/(.*?)\/(.*?)Sniff.php""".r
19+
20+
@nowarn("msg=match may not be exhaustive")
21+
override def patternIdPartsFor(relativizedFilePath: String): PatternIdParts = {
22+
val sniffRegex(vaimoVersion, sniffType, patternName) = relativizedFilePath
23+
PatternIdParts(vaimoVersion, sniffType, patternName)
24+
}
25+
26+
override def descriptionWithDocs(rootDir: File,
27+
patternIdParts: PatternIdParts,
28+
patternFile: File
29+
): (Pattern.Description, Option[String]) = {
30+
(description(patternIdParts, rootDir),
31+
this.parseExtendedDescription("Vaimo\\Sniffs\\Custom", "Vaimo", patternIdParts, rootDir)
32+
)
33+
}
34+
35+
private[this] def description(patternIdParts: PatternIdParts, rootDir: File): Pattern.Description = {
36+
val caseRegexPattern = """((?<=\p{Ll})\p{Lu}|\p{Lu}(?=\p{Ll}))""".r
37+
val patternName = caseRegexPattern.replaceAllIn(patternIdParts.patternName, " $1").trim
38+
val sniffName = caseRegexPattern.replaceAllIn(patternIdParts.sniffType, " $1").trim
39+
val title = Pattern.Title(s"$sniffName: $patternName")
40+
val extended = this.parseDescription("Vaimo\\Sniffs\\Custom", "Vaimo", patternIdParts, rootDir)
41+
Pattern.Description(patternIdParts.patternId, title, extended, None, Set.empty)
42+
}
43+
}
44+
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Custom: Array Access
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Custom: Fix Multiline If
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Custom: Legacy Docblock Tags
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Custom: No Php Cs Disable

docs/description/description.json

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4103,6 +4103,22 @@
41034103
"patternId" : "Symfony_Whitespace_DiscourageFitzinator",
41044104
"title" : "Whitespace: Discourage Fitzinator",
41054105
"parameters" : [ ]
4106+
}, {
4107+
"patternId" : "Vaimo_Custom_ArrayAccess",
4108+
"title" : "Custom: Array Access",
4109+
"parameters" : [ ]
4110+
}, {
4111+
"patternId" : "Vaimo_Custom_FixMultilineIf",
4112+
"title" : "Custom: Fix Multiline If",
4113+
"parameters" : [ ]
4114+
}, {
4115+
"patternId" : "Vaimo_Custom_LegacyDocblockTags",
4116+
"title" : "Custom: Legacy Docblock Tags",
4117+
"parameters" : [ ]
4118+
}, {
4119+
"patternId" : "Vaimo_Custom_NoPhpCsDisable",
4120+
"title" : "Custom: No Php Cs Disable",
4121+
"parameters" : [ ]
41064122
}, {
41074123
"patternId" : "WordPressVIPMinimum_Classes_DeclarationCompatibility",
41084124
"title" : "Classes: Declaration Compatibility",

docs/patterns.json

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6374,6 +6374,34 @@
63746374
"parameters" : [ ],
63756375
"languages" : [ ],
63766376
"enabled" : false
6377+
}, {
6378+
"patternId" : "Vaimo_Custom_ArrayAccess",
6379+
"level" : "Info",
6380+
"category" : "CodeStyle",
6381+
"parameters" : [ ],
6382+
"languages" : [ ],
6383+
"enabled" : false
6384+
}, {
6385+
"patternId" : "Vaimo_Custom_FixMultilineIf",
6386+
"level" : "Info",
6387+
"category" : "CodeStyle",
6388+
"parameters" : [ ],
6389+
"languages" : [ ],
6390+
"enabled" : false
6391+
}, {
6392+
"patternId" : "Vaimo_Custom_LegacyDocblockTags",
6393+
"level" : "Info",
6394+
"category" : "CodeStyle",
6395+
"parameters" : [ ],
6396+
"languages" : [ ],
6397+
"enabled" : false
6398+
}, {
6399+
"patternId" : "Vaimo_Custom_NoPhpCsDisable",
6400+
"level" : "Info",
6401+
"category" : "CodeStyle",
6402+
"parameters" : [ ],
6403+
"languages" : [ ],
6404+
"enabled" : false
63776405
}, {
63786406
"patternId" : "WordPressVIPMinimum_Classes_DeclarationCompatibility",
63796407
"level" : "Info",

0 commit comments

Comments
 (0)