mirror of
https://github.com/esphome/esphome.git
synced 2025-06-22 16:25:48 +01:00
Add lint check for integer constants (#775)
This commit is contained in:
@ -5,6 +5,7 @@ import codecs
|
||||
import collections
|
||||
import fnmatch
|
||||
import os.path
|
||||
import re
|
||||
import subprocess
|
||||
import sys
|
||||
|
||||
@ -143,6 +144,19 @@ def lint_end_newline(fname, content):
|
||||
return None
|
||||
|
||||
|
||||
@lint_content_check(include=['*.cpp', '*.h', '*.tcc'],
|
||||
exclude=['esphome/core/log.h'])
|
||||
def lint_no_defines(fname, content):
|
||||
errors = []
|
||||
for match in re.finditer(r'#define\s+([a-zA-Z0-9_]+)\s+([0-9bx]+)', content, re.MULTILINE):
|
||||
errors.append(
|
||||
"#define macros for integer constants are not allowed, please use "
|
||||
"`static const uint8_t {} = {};` style instead (replace uint8_t with the appropriate "
|
||||
"datatype). See also Google styleguide.".format(match.group(1), match.group(2))
|
||||
)
|
||||
return errors
|
||||
|
||||
|
||||
def relative_cpp_search_text(fname, content):
|
||||
parts = fname.split('/')
|
||||
integration = parts[2]
|
||||
|
Reference in New Issue
Block a user