mirror of
https://github.com/esphome/esphome.git
synced 2025-04-15 07:10:33 +01:00
removes comments from lambda (#998)
* removes comments from lambda * include comments in lambda test * pylint no else return
This commit is contained in:
parent
3b7a47fb90
commit
43cf3063e0
@ -230,10 +230,23 @@ class Lambda:
|
|||||||
self._parts = None
|
self._parts = None
|
||||||
self._requires_ids = 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
|
@property
|
||||||
def parts(self):
|
def parts(self):
|
||||||
if self._parts is None:
|
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
|
return self._parts
|
||||||
|
|
||||||
@property
|
@property
|
||||||
|
@ -211,6 +211,10 @@ class TestTimePeriod:
|
|||||||
SAMPLE_LAMBDA = """
|
SAMPLE_LAMBDA = """
|
||||||
it.strftime(64, 0, id(my_font), TextAlign::TOP_CENTER, "%H:%M:%S", id(esptime).now());
|
it.strftime(64, 0, id(my_font), TextAlign::TOP_CENTER, "%H:%M:%S", id(esptime).now());
|
||||||
it.printf(64, 16, id(my_font2), TextAlign::TOP_CENTER, "%.1f°C (%.1f%%)", id( office_tmp ).state, id(office_hmd).state);
|
it.printf(64, 16, id(my_font2), TextAlign::TOP_CENTER, "%.1f°C (%.1f%%)", id( office_tmp ).state, id(office_hmd).state);
|
||||||
|
//id(my_commented_id)
|
||||||
|
int x = 4;/* id(my_commented_id2)
|
||||||
|
id(my_commented_id3)
|
||||||
|
*/
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
|
||||||
@ -246,7 +250,7 @@ class TestLambda:
|
|||||||
"state, ",
|
"state, ",
|
||||||
"office_hmd",
|
"office_hmd",
|
||||||
".",
|
".",
|
||||||
"state);"
|
"state);\n \nint x = 4; "
|
||||||
]
|
]
|
||||||
|
|
||||||
def test_requires_ids(self):
|
def test_requires_ids(self):
|
||||||
|
Loading…
x
Reference in New Issue
Block a user