Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 18 additions & 4 deletions src/main/kotlin/app/extractors/Heuristics.kt
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,9 @@ val Perl6Regex = Regex(
val PhpRegex = Regex(
"^<\\?(?:php)?"
)
val PhpIlluminateRegex = Regex(
"(Auth|Bootstrap|Bus|Console|Events|Exceptions|Http|Providers" +
"|Support|Testing|Validation)")
val PicoLispRegex = Regex(
"^\\((de|class|rel|code|data|must)\\s",
RegexOption.MULTILINE
Expand Down Expand Up @@ -235,6 +238,11 @@ val k8sExp = { buf: String ->
&& buf.contains("metadata")
}

val bootstrapWebpackExp = { buf: String ->
// Handling php projects with bootstrap Webpack.
buf.contains("/******/ (function(modules) { // webpackBootstrap")
}

/**
* Heuristics to detect a programming language by file extension and content.
* Inspired by GitHub Liguist heuristics (https://github.com/github/linguist).
Expand Down Expand Up @@ -638,8 +646,11 @@ val HeuristicsMap = mapOf<String, (String, String) -> ExtractorInterface?>(
"jl" to { _, _ ->
CommonExtractor(Lang.JULIA)
},
"js" to { _, _ ->
JavascriptExtractor()
"js" to { buf, _ ->
if (bootstrapWebpackExp(buf)) {
null
}
else JavascriptExtractor()
},
"jsx" to { _, _ ->
JavascriptExtractor()
Expand Down Expand Up @@ -793,10 +804,13 @@ val HeuristicsMap = mapOf<String, (String, String) -> ExtractorInterface?>(
"pde" to { _, _ ->
CommonExtractor(Lang.PROCESSING)
},
"php" to { buf, _ ->
"php" to { buf, path ->
if (buf.contains("<?hh")) {
CommonExtractor(Lang.HACK)
} else {
} else if (PhpIlluminateRegex.containsMatchIn(path)) {
null
}
else {
PhpExtractor()
}
},
Expand Down