Correct Kconfigs according to the coding style
This commit is contained in:
@@ -34,116 +34,12 @@ OUTPUT_SUFFIX = '.new'
|
||||
IGNORE_DIRS = (
|
||||
# Kconfigs from submodules need to be ignored:
|
||||
os.path.join('components', 'mqtt', 'esp-mqtt'),
|
||||
# Temporary (incompatibility) list:
|
||||
os.path.join('components', 'app_update'),
|
||||
os.path.join('components', 'aws_iot'),
|
||||
os.path.join('components', 'bootloader'),
|
||||
os.path.join('components', 'bt'),
|
||||
os.path.join('components', 'driver'),
|
||||
os.path.join('components', 'esp32'),
|
||||
os.path.join('components', 'esp_adc_cal'),
|
||||
os.path.join('components', 'esp_event'),
|
||||
os.path.join('components', 'esp_http_client'),
|
||||
os.path.join('components', 'esp_http_server'),
|
||||
os.path.join('components', 'esptool_py'),
|
||||
os.path.join('components', 'fatfs'),
|
||||
os.path.join('components', 'freemodbus'),
|
||||
os.path.join('components', 'freertos'),
|
||||
os.path.join('components', 'heap'),
|
||||
os.path.join('components', 'libsodium'),
|
||||
os.path.join('components', 'log'),
|
||||
os.path.join('components', 'lwip'),
|
||||
os.path.join('components', 'mbedtls'),
|
||||
os.path.join('components', 'mdns'),
|
||||
os.path.join('components', 'mqtt'),
|
||||
os.path.join('components', 'nvs_flash'),
|
||||
os.path.join('components', 'openssl'),
|
||||
os.path.join('components', 'partition_table'),
|
||||
os.path.join('components', 'pthread'),
|
||||
os.path.join('components', 'spi_flash'),
|
||||
os.path.join('components', 'spiffs'),
|
||||
os.path.join('components', 'tcpip_adapter'),
|
||||
os.path.join('components', 'unity'),
|
||||
os.path.join('components', 'vfs'),
|
||||
os.path.join('components', 'wear_levelling'),
|
||||
os.path.join('examples', 'bluetooth', 'a2dp_gatts_coex', 'main'),
|
||||
os.path.join('examples', 'bluetooth', 'a2dp_sink', 'main'),
|
||||
os.path.join('examples', 'bluetooth', 'ble_ibeacon', 'main'),
|
||||
os.path.join('examples', 'bluetooth', 'ble_throughput', 'throughput_client', 'main'),
|
||||
os.path.join('examples', 'bluetooth', 'ble_throughput', 'throughput_server', 'main'),
|
||||
os.path.join('examples', 'bluetooth', 'gatt_server', 'main'),
|
||||
os.path.join('examples', 'get-started', 'blink', 'main'),
|
||||
os.path.join('examples', 'mesh', 'internal_communication', 'main'),
|
||||
os.path.join('examples', 'mesh', 'manual_networking', 'main'),
|
||||
os.path.join('examples', 'peripherals', 'adc2', 'main'),
|
||||
os.path.join('examples', 'peripherals', 'i2c', 'i2c_self_test', 'main'),
|
||||
os.path.join('examples', 'peripherals', 'i2c', 'i2c_tools', 'main'),
|
||||
os.path.join('examples', 'peripherals', 'sdio', 'host', 'main'),
|
||||
os.path.join('examples', 'peripherals', 'sdio', 'slave', 'main'),
|
||||
os.path.join('examples', 'peripherals', 'spi_master', 'main'),
|
||||
os.path.join('examples', 'peripherals', 'uart', 'nmea0183_parser', 'main'),
|
||||
os.path.join('examples', 'protocols', 'asio', 'chat_client', 'main'),
|
||||
os.path.join('examples', 'protocols', 'asio', 'chat_server', 'main'),
|
||||
os.path.join('examples', 'protocols', 'asio', 'tcp_echo_server', 'main'),
|
||||
os.path.join('examples', 'protocols', 'asio', 'udp_echo_server', 'main'),
|
||||
os.path.join('examples', 'protocols', 'aws_iot', 'subscribe_publish', 'main'),
|
||||
os.path.join('examples', 'protocols', 'aws_iot', 'thing_shadow', 'main'),
|
||||
os.path.join('examples', 'protocols', 'coap_client', 'main'),
|
||||
os.path.join('examples', 'protocols', 'coap_server', 'main'),
|
||||
os.path.join('examples', 'protocols', 'esp_http_client', 'main'),
|
||||
os.path.join('examples', 'protocols', 'http2_request', 'main'),
|
||||
os.path.join('examples', 'protocols', 'http_request', 'main'),
|
||||
os.path.join('examples', 'protocols', 'http_server', 'advanced_tests', 'main'),
|
||||
os.path.join('examples', 'protocols', 'http_server', 'persistent_sockets', 'main'),
|
||||
os.path.join('examples', 'protocols', 'http_server', 'simple', 'main'),
|
||||
os.path.join('examples', 'protocols', 'https_mbedtls', 'main'),
|
||||
os.path.join('examples', 'protocols', 'https_request', 'main'),
|
||||
os.path.join('examples', 'protocols', 'https_server', 'main'),
|
||||
os.path.join('examples', 'protocols', 'mdns', 'main'),
|
||||
os.path.join('examples', 'protocols', 'modbus_slave', 'main'),
|
||||
os.path.join('examples', 'protocols', 'mqtt', 'ssl', 'main'),
|
||||
os.path.join('examples', 'protocols', 'mqtt', 'ssl_mutual_auth', 'main'),
|
||||
os.path.join('examples', 'protocols', 'mqtt', 'tcp', 'main'),
|
||||
os.path.join('examples', 'protocols', 'mqtt', 'ws', 'main'),
|
||||
os.path.join('examples', 'protocols', 'mqtt', 'wss', 'main'),
|
||||
os.path.join('examples', 'protocols', 'openssl_client', 'main'),
|
||||
os.path.join('examples', 'protocols', 'openssl_server', 'main'),
|
||||
os.path.join('examples', 'protocols', 'pppos_client', 'main'),
|
||||
os.path.join('examples', 'protocols', 'sntp', 'main'),
|
||||
os.path.join('examples', 'protocols', 'sockets', 'tcp_client', 'main'),
|
||||
os.path.join('examples', 'protocols', 'sockets', 'tcp_server', 'main'),
|
||||
os.path.join('examples', 'protocols', 'sockets', 'udp_client', 'main'),
|
||||
os.path.join('examples', 'protocols', 'sockets', 'udp_multicast', 'main'),
|
||||
os.path.join('examples', 'protocols', 'sockets', 'udp_server', 'main'),
|
||||
os.path.join('examples', 'provisioning', 'ble_prov', 'main'),
|
||||
os.path.join('examples', 'provisioning', 'console_prov', 'main'),
|
||||
os.path.join('examples', 'provisioning', 'custom_config', 'main'),
|
||||
os.path.join('examples', 'provisioning', 'softap_prov', 'main'),
|
||||
os.path.join('examples', 'system', 'app_trace_to_host', 'main'),
|
||||
os.path.join('examples', 'system', 'base_mac_address', 'main'),
|
||||
os.path.join('examples', 'system', 'console', 'main'),
|
||||
os.path.join('examples', 'system', 'deep_sleep', 'main'),
|
||||
os.path.join('examples', 'system', 'gcov', 'main'),
|
||||
os.path.join('examples', 'system', 'ota', 'native_ota_example', 'main'),
|
||||
os.path.join('examples', 'system', 'ota', 'simple_ota_example', 'main'),
|
||||
os.path.join('examples', 'system', 'sysview_tracing', 'main'),
|
||||
os.path.join('examples', 'wifi', 'espnow', 'main'),
|
||||
os.path.join('examples', 'wifi', 'getting_started', 'softAP', 'main'),
|
||||
os.path.join('examples', 'wifi', 'getting_started', 'station', 'main'),
|
||||
os.path.join('examples', 'wifi', 'power_save', 'main'),
|
||||
os.path.join('examples', 'wifi', 'scan', 'main'),
|
||||
os.path.join('examples', 'wifi', 'simple_sniffer', 'main'),
|
||||
os.path.join('examples', 'wifi', 'wpa2_enterprise', 'main'),
|
||||
os.path.join('examples', 'wifi', 'wps', 'main'),
|
||||
os.path.join('tools', 'kconfig'),
|
||||
os.path.join('tools', 'kconfig_new', 'test'),
|
||||
os.path.join('tools', 'ldgen', 'test', 'data'),
|
||||
os.path.join('tools', 'unit-test-app', 'components', 'test_utils'),
|
||||
)
|
||||
|
||||
SPACES_PER_INDENT = 4
|
||||
|
||||
CONFIG_NAME_MAX_LENGTH = 50
|
||||
# TODO decrease the value (after the names have been refactored)
|
||||
CONFIG_NAME_MAX_LENGTH = 60
|
||||
|
||||
# TODO increase prefix length (after the names have been refactored)
|
||||
CONFIG_NAME_MIN_PREFIX_LENGTH = 0
|
||||
@@ -211,6 +107,9 @@ class IndentAndNameChecker(BaseChecker):
|
||||
# stack common prefixes of configs
|
||||
self.prefix_stack = []
|
||||
|
||||
# if the line ends with '\' then we force the indent of the next line
|
||||
self.force_next_indent = 0
|
||||
|
||||
# menu items which increase the indentation of the next line
|
||||
self.re_increase_level = re.compile(r'''^\s*
|
||||
(
|
||||
@@ -287,6 +186,10 @@ class IndentAndNameChecker(BaseChecker):
|
||||
# delete items ("config", "menuconfig", "help") until the appropriate parent
|
||||
self.del_from_level_stack(i)
|
||||
break
|
||||
else:
|
||||
# delete everything when configs are at top level without a parent menu, mainmenu...
|
||||
self.del_from_level_stack(len(self.level_stack))
|
||||
|
||||
self.level_stack.append(new_item)
|
||||
if self.debug:
|
||||
print(self.level_stack)
|
||||
@@ -321,8 +224,10 @@ class IndentAndNameChecker(BaseChecker):
|
||||
raise InputError(self.path_in_idf, line_number,
|
||||
'{} is {} characters long and it should be {} at most'
|
||||
''.format(name, name_length, CONFIG_NAME_MAX_LENGTH),
|
||||
line) # no suggested correction for this
|
||||
if self.prefix_stack[-1] is None:
|
||||
line + '\n') # no suggested correction for this
|
||||
if len(self.prefix_stack) == 0:
|
||||
self.prefix_stack.append(name)
|
||||
elif self.prefix_stack[-1] is None:
|
||||
self.prefix_stack[-1] = name
|
||||
else:
|
||||
# this has nothing common with paths but the algorithm can be used for this also
|
||||
@@ -366,6 +271,7 @@ class IndentAndNameChecker(BaseChecker):
|
||||
def process_line(self, line, line_number):
|
||||
stripped_line = line.strip()
|
||||
if len(stripped_line) == 0:
|
||||
self.force_next_indent = 0
|
||||
return
|
||||
current_level = len(self.level_stack)
|
||||
m = re.search(r'\S', line) # indent found as the first non-space character
|
||||
@@ -377,8 +283,26 @@ class IndentAndNameChecker(BaseChecker):
|
||||
if current_level > 0 and self.level_stack[-1] == 'help':
|
||||
if current_indent >= current_level * SPACES_PER_INDENT:
|
||||
# this line belongs to 'help'
|
||||
self.force_next_indent = 0
|
||||
return
|
||||
|
||||
if self.force_next_indent > 0:
|
||||
if current_indent != self.force_next_indent:
|
||||
raise InputError(self.path_in_idf, line_number,
|
||||
'Indentation consists of {} spaces instead of {}'.format(current_indent,
|
||||
self.force_next_indent),
|
||||
(' ' * self.force_next_indent) + line.lstrip())
|
||||
else:
|
||||
if not stripped_line.endswith('\\'):
|
||||
self.force_next_indent = 0
|
||||
return
|
||||
|
||||
else:
|
||||
if stripped_line.endswith('\\') and stripped_line.startswith(('config', 'menuconfig', 'choice')):
|
||||
raise InputError(self.path_in_idf, line_number,
|
||||
'Line-wrap with backslash is not supported here',
|
||||
line) # no suggestion for this
|
||||
|
||||
self.check_name_and_update_prefix(stripped_line, line_number)
|
||||
|
||||
m = self.re_increase_level.search(line)
|
||||
@@ -395,6 +319,12 @@ class IndentAndNameChecker(BaseChecker):
|
||||
self.check_common_prefix(line, line_number)
|
||||
|
||||
expected_indent = current_level * SPACES_PER_INDENT
|
||||
|
||||
if stripped_line.endswith('\\'):
|
||||
self.force_next_indent = expected_indent + SPACES_PER_INDENT
|
||||
else:
|
||||
self.force_next_indent = 0
|
||||
|
||||
if current_indent != expected_indent:
|
||||
raise InputError(self.path_in_idf, line_number,
|
||||
'Indentation consists of {} spaces instead of {}'.format(current_indent, expected_indent),
|
||||
|
||||
@@ -1,44 +1,44 @@
|
||||
menu "Test config"
|
||||
|
||||
config TEST_BOOL
|
||||
bool "Test boolean"
|
||||
default n
|
||||
config TEST_BOOL
|
||||
bool "Test boolean"
|
||||
default n
|
||||
|
||||
config TEST_CHILD_BOOL
|
||||
bool "Test boolean"
|
||||
depends on TEST_BOOL
|
||||
default y
|
||||
config TEST_CHILD_BOOL
|
||||
bool "Test boolean"
|
||||
depends on TEST_BOOL
|
||||
default y
|
||||
|
||||
config TEST_CHILD_STR
|
||||
string "Test str"
|
||||
depends on TEST_BOOL
|
||||
default "OHAI!"
|
||||
config TEST_CHILD_STR
|
||||
string "Test str"
|
||||
depends on TEST_BOOL
|
||||
default "OHAI!"
|
||||
|
||||
choice TEST_CHOICE
|
||||
prompt "Some choice"
|
||||
default CHOICE_A
|
||||
choice TEST_CHOICE
|
||||
prompt "Some choice"
|
||||
default CHOICE_A
|
||||
|
||||
config CHOICE_A
|
||||
bool "A"
|
||||
config CHOICE_A
|
||||
bool "A"
|
||||
|
||||
config CHOICE_B
|
||||
bool "B"
|
||||
config CHOICE_B
|
||||
bool "B"
|
||||
|
||||
endchoice
|
||||
endchoice
|
||||
|
||||
config DEPENDS_ON_CHOICE
|
||||
string "Depends on choice"
|
||||
default "Depends on A" if CHOICE_A
|
||||
default "Depends on B" if CHOICE_B
|
||||
default "WAT"
|
||||
config DEPENDS_ON_CHOICE
|
||||
string "Depends on choice"
|
||||
default "Depends on A" if CHOICE_A
|
||||
default "Depends on B" if CHOICE_B
|
||||
default "WAT"
|
||||
|
||||
config SOME_UNRELATED_THING
|
||||
bool "Some unrelated thing"
|
||||
config SOME_UNRELATED_THING
|
||||
bool "Some unrelated thing"
|
||||
|
||||
config TEST_CONDITIONAL_RANGES
|
||||
int "Something with a range"
|
||||
range 0 100 if TEST_BOOL
|
||||
range 0 10
|
||||
default 1
|
||||
config TEST_CONDITIONAL_RANGES
|
||||
int "Something with a range"
|
||||
range 0 100 if TEST_BOOL
|
||||
range 0 10
|
||||
default 1
|
||||
|
||||
endmenu
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
menu "Test config"
|
||||
|
||||
config PERFORMANCE_LEVEL
|
||||
int "Performance level"
|
||||
range 0 3
|
||||
config PERFORMANCE_LEVEL
|
||||
int "Performance level"
|
||||
range 0 3
|
||||
|
||||
endmenu
|
||||
|
||||
@@ -18,6 +18,7 @@ import unittest
|
||||
from check_kconfigs import LineRuleChecker
|
||||
from check_kconfigs import InputError
|
||||
from check_kconfigs import IndentAndNameChecker
|
||||
from check_kconfigs import CONFIG_NAME_MAX_LENGTH
|
||||
|
||||
|
||||
class ApplyLine(object):
|
||||
@@ -113,6 +114,7 @@ class TestIndent(TestIndentAndNameChecker):
|
||||
self.expt_success(' menuconfig keyword in the help')
|
||||
self.expt_success(' endmenu keyword in the help')
|
||||
self.expt_success(' endmenu keyword in the help')
|
||||
self.expt_success('') # newline in help
|
||||
self.expt_success(' endmenu keyword in the help')
|
||||
self.expect_error(' menu "real menu with wrong indent"',
|
||||
expect=' menu "real menu with wrong indent"', cleanup=' endmenu')
|
||||
@@ -142,6 +144,24 @@ class TestIndent(TestIndentAndNameChecker):
|
||||
self.expt_success(' config')
|
||||
self.expt_success('endmenu')
|
||||
|
||||
def test_config_without_menu(self):
|
||||
self.expt_success('menuconfig')
|
||||
self.expt_success(' help')
|
||||
self.expt_success(' text')
|
||||
self.expt_success('')
|
||||
self.expt_success(' text')
|
||||
self.expt_success('config')
|
||||
self.expt_success(' help')
|
||||
|
||||
def test_backslashes(self):
|
||||
self.expt_success('default \\')
|
||||
self.expect_error('help', expect=None)
|
||||
self.expt_success(' CONFIG')
|
||||
self.expt_success('default \\')
|
||||
self.expt_success(' LINE1\\')
|
||||
self.expt_success(' LINE2')
|
||||
self.expt_success('help')
|
||||
|
||||
|
||||
class TestName(TestIndentAndNameChecker):
|
||||
def setUp(self):
|
||||
@@ -149,16 +169,23 @@ class TestName(TestIndentAndNameChecker):
|
||||
self.checker.min_prefix_length = 0 # prefixes are ignored in this test case
|
||||
|
||||
def test_name_length(self):
|
||||
max_length = CONFIG_NAME_MAX_LENGTH
|
||||
too_long = max_length + 1
|
||||
self.expt_success('menu "test"')
|
||||
self.expt_success(' config ABC')
|
||||
self.expt_success(' config ' + ('X' * 50))
|
||||
self.expect_error(' config ' + ('X' * 51), expect=None)
|
||||
self.expt_success(' menuconfig ' + ('X' * 50))
|
||||
self.expect_error(' menuconfig ' + ('X' * 51), expect=None)
|
||||
self.expt_success(' choice ' + ('X' * 50))
|
||||
self.expect_error(' choice ' + ('X' * 51), expect=None)
|
||||
self.expt_success(' config ' + ('X' * max_length))
|
||||
self.expect_error(' config ' + ('X' * too_long), expect=None)
|
||||
self.expt_success(' menuconfig ' + ('X' * max_length))
|
||||
self.expect_error(' menuconfig ' + ('X' * too_long), expect=None)
|
||||
self.expt_success(' choice ' + ('X' * max_length))
|
||||
self.expect_error(' choice ' + ('X' * too_long), expect=None)
|
||||
self.expt_success('endmenu')
|
||||
|
||||
def test_config_backslash(self):
|
||||
self.expect_error('config\\', expect=None)
|
||||
self.expect_error('menuconfig\\', expect=None)
|
||||
self.expect_error('choice\\', expect=None)
|
||||
|
||||
|
||||
class TestPrefix(TestIndentAndNameChecker):
|
||||
def test_prefix_len(self):
|
||||
|
||||
@@ -1,15 +1,15 @@
|
||||
menu "IDF unit test"
|
||||
|
||||
config UNITY_FREERTOS_PRIORITY
|
||||
int "Priority of Unity test task"
|
||||
default 5
|
||||
config UNITY_FREERTOS_PRIORITY
|
||||
int "Priority of Unity test task"
|
||||
default 5
|
||||
|
||||
config UNITY_FREERTOS_CPU
|
||||
int "CPU to run Unity test task on"
|
||||
default 0
|
||||
config UNITY_FREERTOS_CPU
|
||||
int "CPU to run Unity test task on"
|
||||
default 0
|
||||
|
||||
config UNITY_FREERTOS_STACK_SIZE
|
||||
int "Stack size of Unity test task, in bytes"
|
||||
default 8192
|
||||
config UNITY_FREERTOS_STACK_SIZE
|
||||
int "Stack size of Unity test task, in bytes"
|
||||
default 8192
|
||||
|
||||
endmenu
|
||||
|
||||
Reference in New Issue
Block a user