From dae8afe0c5c7ee93cb89475d9e55401653b8f695 Mon Sep 17 00:00:00 2001 From: Arnout Engelen Date: Sat, 20 Aug 2022 10:40:04 +0200 Subject: [PATCH] Add style for php 'blade' templates --- src/reuse/_comment.py | 16 ++++++++++++++++ src/reuse/header.py | 3 +++ 2 files changed, 19 insertions(+) diff --git a/src/reuse/_comment.py b/src/reuse/_comment.py index 1a034499e..e12f27b71 100644 --- a/src/reuse/_comment.py +++ b/src/reuse/_comment.py @@ -272,6 +272,13 @@ class BibTexCommentStyle(CommentStyle): MULTI_LINE = ("@Comment{", "", "}") +class BladeCommentStyle(CommentStyle): + """Laravel Blade Template comment style.""" + + _shorthand = "blade" + + MULTI_LINE = ("{{--", "", "--}}") + NEWLINE_AFTER = False class CCommentStyle(CommentStyle): """C comment style.""" @@ -646,6 +653,15 @@ class VimCommentStyle(CommentStyle): k.lower(): v for k, v in EXTENSION_COMMENT_STYLE_MAP.items() } +#: A map of (common) double file extensions against comment types. +EXTENSIONS_COMMENT_STYLE_MAP = { + ".blade.php": BladeCommentStyle, +} + +EXTENSIONS_COMMENT_STYLE_MAP_LOWERCASE = { + k.lower(): v for k, v in EXTENSIONS_COMMENT_STYLE_MAP.items() +} + FILENAME_COMMENT_STYLE_MAP = { ".bashrc": PythonCommentStyle, ".coveragerc": PythonCommentStyle, diff --git a/src/reuse/header.py b/src/reuse/header.py index 78e463d40..5c95d6716 100644 --- a/src/reuse/header.py +++ b/src/reuse/header.py @@ -35,6 +35,7 @@ from . import SpdxInfo from ._comment import ( EXTENSION_COMMENT_STYLE_MAP_LOWERCASE, + EXTENSIONS_COMMENT_STYLE_MAP_LOWERCASE, FILENAME_COMMENT_STYLE_MAP_LOWERCASE, NAME_STYLE_MAP, CCommentStyle, @@ -330,6 +331,8 @@ def find_and_replace_header( def _get_comment_style(path: Path) -> Optional[CommentStyle]: """Return value of CommentStyle detected for *path* or None.""" style = FILENAME_COMMENT_STYLE_MAP_LOWERCASE.get(path.name.lower()) + if style is None: + style = EXTENSIONS_COMMENT_STYLE_MAP_LOWERCASE.get(''.join(path.suffixes).lower()) if style is None: style = EXTENSION_COMMENT_STYLE_MAP_LOWERCASE.get(path.suffix.lower()) return style