Commits

Anonymous committed a9dac2e

add detection of missing copyright headers

git-svn-id: http://caml.inria.fr/svn/ocaml/trunk@12805f963ae5c-01c2-4b8c-9fe0-0dff7051ff02

Comments (0)

Files changed (1)

 # - absence of white lines at end of file (white-at-eof)
 # - presence of a LF character at the end of the file (missing-lf)
 # - maximum line length of 80 characters (long-line)
+# - presence of a copyright header (missing-header)
 
 # Exceptions are handled with a SVN property: "ocaml:typo".
 # Its value for a given file is a comma-separated list of rule names,
 #   is automatically exempt from all the rules.
 # - Any file whose name begins with "Makefile" is automatically exempt
 #   from the "tabs" rule.
+# - Any file whose name matches one of the following patterns is
+#   automatically exempt from the "missing-header" rule.
+#     */.depend
+#     */.ignore
+#     *.mlpack
+#     *.mllib
+#     *.odocl
+#     *.clib
+#     */unmaintained/*
+#     */experimental/*
+#     *.reference
 
 # ASCII characters are bytes from 0 to 127.  Any other byte is
 # flagged as a non-ASCII character.
     fi
     rules="$userrules"
     case "$f" in
-      Makefile*) rules="tab,$rules";;
-      */Makefile*) rules="tab,$rules";;
+      Makefile*|*/Makefile*) rules="tab,$rules";;
+    esac
+    h(){ rules="missing-header,$rules"; }
+    case "$f" in
+      */.depend|*/.ignore) h;;
+      *.mlpack|*.mllib|*.odocl|*.itarget|*.clib) h;;
+      */unmaintained/*|*/experimental/*) h;;
+      *.reference) h;;
     esac
 
     (cat "$f"; echo) \
 
         length($0) > 80 {
           RSTART = 81;
-          RLENGTH = length($0) - 81;
+          RLENGTH = 0;
           err("long-line", "line is over 80 characters");
         }
 
+        3 <= NR && NR <= 8 \
+        && (/ OCaml / || / ocamlbuild / || / OCamldoc /) {
+          header_ocaml = 1;
+        }
+
+        7 <= NR && NR <= 12 && / Copyright / && header_ocaml {
+          header_copyright = 1;
+        }
+
         {
           prev_line = last_line;
           last_line = $0;
           if (!empty_file && match(prev_line, /^[ \t]*$/)){
             err("white-at-eof", "white line(s) at EOF");
           }
+          NR = 1;
+          RSTART = 1;
+          RLENGTH = 0;
+          if (!(header_ocaml && header_copyright)){
+            err("missing-header", "missing copyright header");
+          }
           split(svnrules, r, ",");
           for (i in r){
             name = r[i];
             if (name != "" && !counts[name]){
-              printf ("%s, line 1, char 1: unused rule exception [%s]\n",
-                      file, name);
+              err("unused-prop", sprintf("unused [%s] in ocaml:typo", name));
             }
           }
         }
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.