Skip to content

Commit

Permalink
Merge pull request #438 from dodona-edu/fix/js-line-number
Browse files Browse the repository at this point in the history
Fix line numbers in JavaScript
  • Loading branch information
niknetniko authored Sep 20, 2023
2 parents 5bc31ff + dd5538e commit e43c084
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion tested/languages/javascript/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ def modify_solution(self, solution: Path):
non_strict = file.read()
with open(solution, "w") as file:
file.write('"use strict";\n\n' + non_strict)
self.config.dodona.source_offset += 2
self.config.dodona.source_offset -= 2

def linter(self, remaining: float) -> tuple[list[Message], list[AnnotateCode]]:
# Import locally to prevent errors.
Expand All @@ -165,6 +165,11 @@ def cleanup_stacktrace(self, traceback: str) -> str:
compilation_submission_location = str(submission_location.resolve())
execution_location_regex = f"{self.config.dodona.workdir}/{EXECUTION_PREFIX}[_0-9]+/{EXECUTION_PREFIX}[_0-9]+.js"
submission_namespace = f"{submission_name(self)}."
location_pattern = r"(\d+):(\d+)"

def update_line_number(match: re.Match) -> str:
assert self.config
return f"{int(match.group(1)) + self.config.dodona.source_offset}:{match.group(2)}"

resulting_lines = ""
for line in traceback.splitlines(keepends=True):
Expand All @@ -177,6 +182,10 @@ def cleanup_stacktrace(self, traceback: str) -> str:
line = line.replace(compilation_submission_location, "<code>")
# Remove any references of the form "submission.SOMETHING"
line = line.replace(submission_namespace, "")

# Adjust line numbers
line = re.sub(location_pattern, update_line_number, line)

resulting_lines += line

return resulting_lines
Expand Down

0 comments on commit e43c084

Please sign in to comment.