Skip to content

Commit

Permalink
Merge pull request #381 from dodona-edu/fix/javascript-errors
Browse files Browse the repository at this point in the history
Enable strict mode in JavaScript
  • Loading branch information
niknetniko committed Jun 16, 2023
2 parents f5e4b00 + a523dc7 commit f20ac55
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 2 deletions.
8 changes: 8 additions & 0 deletions tested/languages/javascript/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ def map_type_restrictions(self) -> Optional[Set[ExpressionTypes]]:
return {BasicStringTypes.TEXT}

def set_type_restrictions(self) -> Optional[Set[ExpressionTypes]]:
# noinspection PyTypeChecker
return {
"integer",
"real",
Expand Down Expand Up @@ -131,6 +132,13 @@ def modify_solution(self, solution: Path):
except TimeoutError:
pass

# Add strict mode to the script.
with open(solution, "r") as file:
non_strict = file.read()
with open(solution, "w") as file:
file.write('"use strict";\n\n' + non_strict)
self.config.dodona.source_offset += 2

def linter(self, remaining: float) -> Tuple[List[Message], List[AnnotateCode]]:
# Import locally to prevent errors.
from tested.languages.javascript import linter
Expand Down
4 changes: 2 additions & 2 deletions tested/languages/kotlin/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ def linter(self, remaining: float) -> Tuple[List[Message], List[AnnotateCode]]:
return linter.run_ktlint(self.config.dodona, remaining)

def find_main_file(
self, files: List[str], name: str, precompilation_messages: List[str]
self, files: List[Path], name: str, precompilation_messages: List[str]
) -> Tuple[Optional[str], List[Message], Status, List[AnnotateCode]]:
logger.debug("Finding %s in %s", name, files)
main, msgs, status, ants = Language.find_main_file(
Expand All @@ -188,7 +188,7 @@ def find_main_file(
else:
return Language.find_main_file(self, files, name, precompilation_messages)

def filter_dependencies(self, files: List[Path], context_name: str) -> List[str]:
def filter_dependencies(self, files: List[Path], context_name: str) -> List[Path]:
def filter_function(file: Path) -> bool:
# We don't want files for contexts that are not the one we use.
prefix = conventionalize_namespace(self, EXECUTION_PREFIX)
Expand Down
1 change: 1 addition & 0 deletions tested/languages/python/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ def datatype_support(self) -> Mapping[AllTypes, TypeSupport]:
}

def map_type_restrictions(self) -> Optional[Set[ExpressionTypes]]:
# noinspection PyTypeChecker
return {
"integer",
"real",
Expand Down

0 comments on commit f20ac55

Please sign in to comment.