Welcome to mirror list, hosted at ThFree Co, Russian Federation.

ModifiedFilesAuditor.scala « auditing « rorschach « getbootstrap « com « scala « main « src - github.com/twbs/rorschach.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 67f3f3cbe7608d2ffa014cd18fca8c2be401ca75 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
package com.getbootstrap.rorschach.auditing

object ModifiedFilesAuditor {
  private implicit class PathString(filepath: String) {
    def isDist: Boolean = filepath.startsWith("dist/")
    def isNonMinifiedCss: Boolean = filepath.endsWith(".css") && !filepath.endsWith(".min.css")
    def isSourceLess: Boolean = filepath.startsWith("less/") && filepath.endsWith(".less")
    def isNonMinifiedJs: Boolean = filepath.endsWith(".js") && !filepath.endsWith(".min.js")
    def isDistCss: Boolean = filepath.isDist && filepath.isNonMinifiedCss
    def isDistJs: Boolean = filepath.isDist && filepath.isNonMinifiedJs
    def isSourceJs: Boolean = filepath.startsWith("js/") && filepath.isNonMinifiedJs
  }

  def audit(filepaths: Set[String]): Seq[String] = {
    Seq(auditCname(filepaths), auditCss(filepaths), auditJs(filepaths)).flatten
  }

  /**
   * If dist/bootstrap.css etc. is modified, then less/<*>.less must also have been modified.
   */
  private def auditCss(filepaths: Set[String]): Option[String] = {
    val cssModified = filepaths.exists{ _.isDistCss }
    val lessModified = filepaths.exists{ _.isSourceLess }
    if (cssModified && !lessModified) {
      Some("Changes must be made to the original Less source code file(s), not just the compiled CSS file(s).")
    }
    else {
      None
    }
  }

  /**
   * If dist/js/bootstrap.js etc. is modified, then js/<*>.js must also have been modified.
   */
  private def auditJs(filepaths: Set[String]): Option[String] = {
    val distJsModified = filepaths.exists{ _.isDistJs }
    val sourceJsModified = filepaths.exists{ _.isSourceJs }
    if (distJsModified && !sourceJsModified) {
      Some("Changes must be made to the original JS source code file(s), not just the generated concatenated JS file(s).")
    }
    else {
      None
    }
  }

  private def auditCname(filepaths: Set[String]): Option[String] = {
    if (filepaths.contains("CNAME")) {
      Some("The `CNAME` file should never be modified (except in extremely unlikely circumstances).")
    }
    else {
      None
    }
  }
}