diff --git a/src/reuse/comment.py b/src/reuse/comment.py index d48e3bc45..56db86691 100644 --- a/src/reuse/comment.py +++ b/src/reuse/comment.py @@ -321,6 +321,14 @@ class BibTexCommentStyle(CommentStyle): SHEBANGS = ["% !BIB", "%!BIB"] +class BladeCommentStyle(CommentStyle): + """Laravel Blade Template comment style.""" + + _shorthand = "blade" + + MULTI_LINE = MultiLineSegments("{{--", "", "--}}") + + class CCommentStyle(CommentStyle): """C comment style.""" @@ -709,7 +717,6 @@ class XQueryCommentStyle(CommentStyle): ".mk": PythonCommentStyle, ".ml": MlCommentStyle, ".mli": MlCommentStyle, - ".nim.cfg": PythonCommentStyle, # Nim-lang build config parameters/settings ".nim": PythonCommentStyle, ".nimble": PythonCommentStyle, # Nim-lang build config ".nimrod": PythonCommentStyle, @@ -837,6 +844,16 @@ class XQueryCommentStyle(CommentStyle): key.lower(): value for key, value in EXTENSION_COMMENT_STYLE_MAP.items() } +#: A map of (common) double file extensions against comment types. +MULTIPLE_EXTENSION_COMMENT_STYLE_MAP = { + ".blade.php": BladeCommentStyle, + ".nim.cfg": PythonCommentStyle, # Nim-lang build config parameters/settings +} + +MULTIPLE_EXTENSION_COMMENT_STYLE_MAP_LOWERCASE = { + k.lower(): v for k, v in MULTIPLE_EXTENSION_COMMENT_STYLE_MAP.items() +} + FILENAME_COMMENT_STYLE_MAP = { ".bashrc": PythonCommentStyle, ".bazelignore": PythonCommentStyle, @@ -930,6 +947,10 @@ def get_comment_style(path: StrPath) -> Optional[Type[CommentStyle]]: """Return value of CommentStyle detected for *path* or None.""" path = Path(path) style = FILENAME_COMMENT_STYLE_MAP_LOWERCASE.get(path.name.lower()) + if style is None: + style = MULTIPLE_EXTENSION_COMMENT_STYLE_MAP_LOWERCASE.get( + "".join(path.suffixes).lower() + ) if style is None: style = cast( Optional[Type[CommentStyle]], diff --git a/tests/test_comment.py b/tests/test_comment.py index 51c1e1247..5c4629611 100644 --- a/tests/test_comment.py +++ b/tests/test_comment.py @@ -13,12 +13,14 @@ import pytest from reuse.comment import ( + BladeCommentStyle, CommentStyle, CppCommentStyle, HtmlCommentStyle, LispCommentStyle, PythonCommentStyle, _all_style_classes, + get_comment_style, ) from reuse.exceptions import CommentCreateError, CommentParseError @@ -688,3 +690,11 @@ def test_parse_comment_lisp(): ) assert LispCommentStyle.parse_comment(text) == expected + + +def test_get_comment_style(): + """Select the right style based on the filename""" + assert get_comment_style("foo.php") == CppCommentStyle + assert get_comment_style("foo.blade.php") == BladeCommentStyle + assert get_comment_style("foo.bar.blade.php") == CppCommentStyle + assert get_comment_style("foo.php.blade") is None