mirror of
https://github.com/esphome/esphome.git
synced 2025-10-30 14:43:51 +00:00
removes comments from lambda (#998)
* removes comments from lambda * include comments in lambda test * pylint no else return
This commit is contained in:
committed by
GitHub
parent
3b7a47fb90
commit
43cf3063e0
@@ -230,10 +230,23 @@ class Lambda:
|
||||
self._parts = None
|
||||
self._requires_ids = None
|
||||
|
||||
# https://stackoverflow.com/a/241506/229052
|
||||
def comment_remover(self, text):
|
||||
def replacer(match):
|
||||
s = match.group(0)
|
||||
if s.startswith('/'):
|
||||
return " " # note: a space and not an empty string
|
||||
return s
|
||||
pattern = re.compile(
|
||||
r'//.*?$|/\*.*?\*/|\'(?:\\.|[^\\\'])*\'|"(?:\\.|[^\\"])*"',
|
||||
re.DOTALL | re.MULTILINE
|
||||
)
|
||||
return re.sub(pattern, replacer, text)
|
||||
|
||||
@property
|
||||
def parts(self):
|
||||
if self._parts is None:
|
||||
self._parts = re.split(LAMBDA_PROG, self._value)
|
||||
self._parts = re.split(LAMBDA_PROG, self.comment_remover(self._value))
|
||||
return self._parts
|
||||
|
||||
@property
|
||||
|
||||
Reference in New Issue
Block a user