mirror of
https://github.com/esphome/esphome.git
synced 2024-12-25 06:54:52 +01:00
Add lint check for integer constants (#775)
This commit is contained in:
parent
4fa11dfa68
commit
b59cf6572b
3 changed files with 21 additions and 7 deletions
|
@ -4,11 +4,11 @@
|
|||
#include "esphome/components/uart/uart.h"
|
||||
#include "esphome/core/automation.h"
|
||||
|
||||
#define SIM800L_READ_BUFFER_LENGTH 255
|
||||
|
||||
namespace esphome {
|
||||
namespace sim800l {
|
||||
|
||||
const uint8_t SIM800L_READ_BUFFER_LENGTH = 255;
|
||||
|
||||
enum State {
|
||||
STATE_IDLE = 0,
|
||||
STATE_INIT,
|
||||
|
|
|
@ -54,15 +54,15 @@ bool ESPPreferenceObject::save_() {
|
|||
|
||||
#ifdef ARDUINO_ARCH_ESP8266
|
||||
|
||||
#define ESP_RTC_USER_MEM_START 0x60001200
|
||||
static const uint32_t ESP_RTC_USER_MEM_START = 0x60001200;
|
||||
#define ESP_RTC_USER_MEM ((uint32_t *) ESP_RTC_USER_MEM_START)
|
||||
#define ESP_RTC_USER_MEM_SIZE_WORDS 128
|
||||
#define ESP_RTC_USER_MEM_SIZE_BYTES ESP_RTC_USER_MEM_SIZE_WORDS * 4
|
||||
static const uint32_t ESP_RTC_USER_MEM_SIZE_WORDS = 128;
|
||||
static const uint32_t ESP_RTC_USER_MEM_SIZE_BYTES = ESP_RTC_USER_MEM_SIZE_WORDS * 4;
|
||||
|
||||
#ifdef USE_ESP8266_PREFERENCES_FLASH
|
||||
#define ESP8266_FLASH_STORAGE_SIZE 128
|
||||
static const uint32_t ESP8266_FLASH_STORAGE_SIZE = 128;
|
||||
#else
|
||||
#define ESP8266_FLASH_STORAGE_SIZE 64
|
||||
static const uint32_t ESP8266_FLASH_STORAGE_SIZE = 64;
|
||||
#endif
|
||||
|
||||
static inline bool esp_rtc_user_mem_read(uint32_t index, uint32_t *dest) {
|
||||
|
|
|
@ -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]
|
||||
|
|
Loading…
Reference in a new issue