Просмотр исходного кода

Merge pull request #299 from sharelatex/roll-out-chktex

Roll out chktex
Brian Gough 10 лет назад
Родитель
Сommit
f26ed03e7d

+ 15 - 1
services/web/public/coffee/ide/human-readable-logs/HumanReadableLogs.coffee

@@ -11,6 +11,8 @@ define [
 		_getRule = (logMessage) ->
 			return rule for rule in ruleset when rule.regexToMatch.test logMessage
 
+		seenErrorTypes = {} # keep track of types of errors seen
+
 		for entry in parsedLogEntries.all
 			ruleDetails = _getRule entry.message
 
@@ -21,8 +23,20 @@ define [
 					entry.ruleId = 'hint_' + ruleDetails.regexToMatch.toString().replace(/\s/g, '_').slice(1, -1)
 				if ruleDetails.newMessage?
 					entry.message = entry.message.replace ruleDetails.regexToMatch, ruleDetails.newMessage
+				# suppress any entries that are known to cascade from previous error types
+				if ruleDetails.cascadesFrom?
+					for type in ruleDetails.cascadesFrom
+						entry.suppressed = true if seenErrorTypes[type]
+				# record the types of errors seen
+				if ruleDetails.types?
+					for type in ruleDetails.types
+						seenErrorTypes[type] = true
 				
 				entry.humanReadableHint = ruleDetails.humanReadableHint if ruleDetails.humanReadableHint?
 				entry.extraInfoURL = ruleDetails.extraInfoURL if ruleDetails.extraInfoURL?
-	
+
+		# filter out the suppressed errors (from the array entries in parsedLogEntries)
+		for key, errors of parsedLogEntries when typeof errors is 'object' and errors.length > 0
+			parsedLogEntries[key] = (err for err in errors when not err.suppressed)
+
 		return parsedLogEntries

+ 27 - 1
services/web/public/coffee/ide/human-readable-logs/HumanReadableLogsRules.coffee

@@ -90,6 +90,7 @@ define -> [
 		"""
 	,
 		ruleId: "hint_mismatched_environment"
+		types: ['environment']
 		regexToMatch: /Error: `([^']{2,})' expected, found `([^']{2,})'.*/
 		newMessage: "Error: environment does not match \\begin{$1} ... \\end{$2}"
 		humanReadableHint: """
@@ -97,10 +98,35 @@ define -> [
 		"""
 	,
 		ruleId: "hint_mismatched_brackets"
+		types: ['environment']
 		regexToMatch: /Error: `([^a-zA-Z0-9])' expected, found `([^a-zA-Z0-9])'.*/
 		newMessage: "Error: brackets do not match, found '$2' instead of '$1'"
 		humanReadableHint: """
 			You have used an open bracket without a corresponding close bracket.
 		"""
-
+	,
+		ruleId: "hint_mismatched_environment2"
+		types: ['environment']
+		regexToMatch: /Error: `\\end\{([^\}]+)\}' expected but found `\\end\{([^\}]+)\}'.*/
+		newMessage: "Error: environments do not match: \\begin{$1} ... \\end{$2}"
+		humanReadableHint: """
+			You have used \\begin{} without a corresponding \\end{}.
+		"""
+	,
+		ruleId: "hint_mismatched_environment3"
+		types: ['environment']
+		regexToMatch: /Warning: No matching \\end found for `\\begin\{([^\}]+)\}'.*/
+		newMessage: "Warning: No matching \\end found for \\begin{$1}"
+		humanReadableHint: """
+			You have used \\begin{} without a corresponding \\end{}.
+		"""
+	,
+		ruleId: "hint_mismatched_environment4"
+		types: ['environment']
+		cascadesFrom: ['environment']
+		regexToMatch: /Error: Found `\\end\{([^\}]+)\}' without corresponding \\begin.*/
+		newMessage: "Error: found \\end{$1} without a corresponding \\begin{$1}"
+		humanReadableHint: """
+			You have used \\begin{} without a corresponding \\end{}.
+		"""
 ]