summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Master/texmf-dist/doc/support/hook-pre-commit-pkg/README8
-rw-r--r--Master/texmf-dist/doc/support/hook-pre-commit-pkg/pre-commit-latex100
2 files changed, 53 insertions, 55 deletions
diff --git a/Master/texmf-dist/doc/support/hook-pre-commit-pkg/README b/Master/texmf-dist/doc/support/hook-pre-commit-pkg/README
index ab146317b61..8d8cf08e657 100644
--- a/Master/texmf-dist/doc/support/hook-pre-commit-pkg/README
+++ b/Master/texmf-dist/doc/support/hook-pre-commit-pkg/README
@@ -1,11 +1,11 @@
-Pre-commit hook for LaTeX package developpers
+Pre-commit hook for LaTeX package developers
=== What it is ?
-A pre-commit hook to check basic LaTeX syntaxe for develloper of package.
+A pre-commit hook to check basic LaTeX syntax for developer of package.
==== How to install
-Copy pre-commit in the .git/.hooks file
+Copy pre-commit in the .git/hooks file
Add execution right (chmod +x)
Enjoy !
@@ -29,7 +29,7 @@ Only for new line, these properties are checked:
=== Licence and copyright
Maïeul Rouquette 2014-....
-v 1.1.0
+v 1.1.2
Licence GPl3 https://www.gnu.org/licenses/gpl-3.0.txt
=== Help and github repository
diff --git a/Master/texmf-dist/doc/support/hook-pre-commit-pkg/pre-commit-latex b/Master/texmf-dist/doc/support/hook-pre-commit-pkg/pre-commit-latex
index 70e8b14e80d..2e77321c2a4 100644
--- a/Master/texmf-dist/doc/support/hook-pre-commit-pkg/pre-commit-latex
+++ b/Master/texmf-dist/doc/support/hook-pre-commit-pkg/pre-commit-latex
@@ -1,13 +1,13 @@
#!/usr/bin/python
# -*- coding: utf-8 -*-
-"""Pre-commit hook for LaTeX package developpers
+"""Pre-commit hook for LaTeX package developers
=== What it is ?
-A pre-commit hook to check basic LaTeX syntaxe for develloper of package.
+A pre-commit hook to check basic LaTeX syntax for developer of package.
==== How to install
-Copy pre-commit in the .git/.hooks file
+Copy pre-commit in the .git/hooks file
Add execution right (chmod +x)
Enjoy !
@@ -31,7 +31,7 @@ Only for new line, these properties are checked:
=== Licence and copyright
Maïeul Rouquette 2014-....
-v 1.1.0
+v 1.1.2
Licence GPl3 https://www.gnu.org/licenses/gpl-3.0.txt
=== Help and github repository
@@ -69,28 +69,27 @@ def change_line_number(line_number,line):
line_number = int(line_number[0]) -1
elif not line[0] == "-" and not line[0:1] == "\\":
line_number = line_number + 1
- return line_number
+ return line_number
-lines_results ={}#global, bad, I have to find an other way. Key = filename_linenumber. content : see check_lines
+lines_results ={}#global, bad, I have to find an other way. Key = filename_linenumber. content : see check_lines
def check_lines():
""" Check all modified lines"""
diff = os.popen("git diff --cached")
line_number = 0
file_name = ""
-
for line in diff:
line_number = change_line_number(line_number,line)
# what is the file_name?
if "+++ b/" in line:
file_name = line[6:-1]
extension = os.path.splitext(file_name)[1][1:]
+ lines_results[file_name] ={}
elif "++ /dev/null" in line:
extension = ""
file_name = ""
elif line[0] == "+" and extension in to_be_checked:
check = check_line(line,line_number,file_name)
- lines_results[file_name+"_"+str(line_number)]={
- "line_number":line_number,
+ lines_results[file_name][line_number]={
"content":line,
"results":check,
"file_name":file_name
@@ -124,37 +123,38 @@ def check_macro_env(line,line_number,file_name):
# only for line concerning macro env
errors = []
if begin in line:
-
+
# Check only one space after %
normal_indent = "% \\begin{macro}"
if line[:len(normal_indent)] != normal_indent:
errors.append("indent")
-
+
#Check there is second argument
if line.count("{") != 2 or line.count("}") != 2:
errors.append("#2")
# we think its not paired before anyone paired
errors.append("pairing")
+
if file_name in begin_macro:
- begin_macro[file_name].append(str(line_number))
+ begin_macro[file_name].append(line_number)
else:
- begin_macro[file_name]=[str(line_number)]
+ begin_macro[file_name]=[line_number]
return errors
elif end in line:
-
- #check only
+
+ #check only
normal_indent = "% \end{macro}"
if line[:len(normal_indent)] != normal_indent:
errors.append("indent")
-
+
#correct pairing
try:
begin_pairing = begin_macro[file_name].pop()#get the line of the \begin{macro}
- lines_results[file_name+"_"+begin_pairing]["results"]["macro_env"].remove("pairing")
- if lines_results[file_name+"_"+begin_pairing]["results"]["macro_env"] ==[]:
- del(lines_results[file_name+"_"+begin_pairing]["results"]["macro_env"])
+ lines_results[file_name][begin_pairing]["results"]["macro_env"].remove("pairing")
+ if lines_results[file_name][begin_pairing]["results"]["macro_env"] ==[]:
+ del(lines_results[file_name][begin_pairing]["results"]["macro_env"])
except:
errors.append("pairing")
return errors
@@ -174,7 +174,7 @@ def check_macrocode_env(line,line_number,file_name):
# only for line concerning macrocode env
errors = []
if begin in line:
-
+
# Check only one space after %
normal_indent = "% \\begin{macrocode}"
if line[:len(normal_indent)] != normal_indent:
@@ -183,24 +183,24 @@ def check_macrocode_env(line,line_number,file_name):
# we think its not paired before anyone paired
errors.append("pairing")
if file_name in begin_macrocode:
- begin_macrocode[file_name].append(str(line_number))
+ begin_macrocode[file_name].append(line_number)
else:
- begin_macrocode[file_name]=[str(line_number)]
+ begin_macrocode[file_name]=[line_number]
return errors
elif end in line:
-
- #check only
+
+ #check only
normal_indent = "% \end{macrocode}"
if line[:len(normal_indent)] != normal_indent:
errors.append("indent")
-
+
#correct pairing
try:
begin_pairing = begin_macrocode[file_name].pop()#get the line of the \begin{macrocode}
- lines_results[file_name+"_"+begin_pairing]["results"]["macrocode_env"].remove("pairing")
- if lines_results[file_name+"_"+begin_pairing]["results"]["macrocode_env"] ==[]:
- del(lines_results[file_name+"_"+begin_pairing]["results"]["macrocode_env"])
+ lines_results[file_name][begin_pairing]["results"]["macrocode_env"].remove("pairing")
+ if lines_results[file_name][begin_pairing]["results"]["macrocode_env"] ==[]:
+ del(lines_results[file_name][begin_pairing]["results"]["macrocode_env"])
except:
errors.append("pairing")
return errors
@@ -215,15 +215,15 @@ def check_cs_cmd(line,line_number,file_name):
def check_end_line_percent_signe(line,line_number,file_name):
""""Check line finish by %"""
- line = line.replace("\%","") # Don't look for protected %
-
+ line = line.replace("\%","") # Don't look for protected %
+
if line == "+\n": # Allow empty line
return True
-
+
elif "%" not in line: # If not % -> problem
return False
- elif re.search ("\s+%",line): # Spaces before % -> problem
+ elif re.search ("\s+%",line): # Spaces before % -> problem
return False
else:
return True
@@ -232,25 +232,23 @@ def check_end_line_percent_signe(line,line_number,file_name):
def __main__():
"""Main function: calls the check to bad line, print them if need, and return exit if error"""
lines_results = check_lines()
- exit = 0 #Set to 1 if we have ONE bad line.
- seen_file_names=[]
- for line_result in lines_results:
- line= lines_results[line_result]
- if line["results"]!={}: #there is some error
- exit=1
- if line["file_name"] not in seen_file_names:
- seen_file_names.append(line["file_name"])
- print (line["file_name"])
- print ("\x1b[31m\tl."+ str(line["line_number"]) + ": " + line["content"][:-1])
-
- results = line["results"]
- for error in line["results"]:
- if results[error] == True:
- print ("\t\t " + commands[error])
- else:
- for e in results[error]:
- print ("\t\t " + commands[error][e])
- print("\x1b[0m")
+ exit = 0 #Set to 1 if we have ONE bad line.
+ for file_name in lines_results:
+ print (file_name)
+ for line_number in sorted(lines_results[file_name].keys()):
+ line = lines_results[file_name][line_number]
+ if line["results"]!={}: #there is some error
+ exit=1
+ print ("\x1b[31m\tl."+ str(line_number) + ": " + line["content"][:-1])
+
+ results = line["results"]
+ for error in line["results"]:
+ if results[error] == True:
+ print ("\t\t " + commands[error])
+ else:
+ for e in results[error]:
+ print ("\t\t " + commands[error][e])
+ print("\x1b[0m")
sys.exit(exit)