mirror of
https://github.com/powerline/powerline.git
synced 2025-07-26 15:25:06 +02:00
Fix linting of highlight groups
Currently checks for highlight group existence do not work. With this commit tests will fail due to #1136.
This commit is contained in:
parent
b22562b028
commit
3b56cf748b
@ -233,6 +233,7 @@ segment_spec = Spec(
|
|||||||
segments=sub_segments_spec,
|
segments=sub_segments_spec,
|
||||||
).func(check_full_segment_data)
|
).func(check_full_segment_data)
|
||||||
sub_segments_spec.optional().list(segment_spec)
|
sub_segments_spec.optional().list(segment_spec)
|
||||||
|
del sub_segments_spec
|
||||||
segments_spec = Spec().optional().list(segment_spec).copy
|
segments_spec = Spec().optional().list(segment_spec).copy
|
||||||
segdict_spec = Spec(
|
segdict_spec = Spec(
|
||||||
left=segments_spec().context_message('Error while loading segments from left side (key {key})'),
|
left=segments_spec().context_message('Error while loading segments from left side (key {key})'),
|
||||||
@ -546,6 +547,8 @@ def check(paths=None, debug=False, echoerr=echoerr, require_ext=None):
|
|||||||
econfigs.get('__main__'),
|
econfigs.get('__main__'),
|
||||||
ecconfigs,
|
ecconfigs,
|
||||||
)
|
)
|
||||||
|
if not (mconfigs[0] or mconfigs[2]):
|
||||||
|
continue
|
||||||
config = None
|
config = None
|
||||||
for mconfig in mconfigs:
|
for mconfig in mconfigs:
|
||||||
if not mconfig:
|
if not mconfig:
|
||||||
@ -554,7 +557,7 @@ def check(paths=None, debug=False, echoerr=echoerr, require_ext=None):
|
|||||||
config = mergedicts_copy(config, mconfig)
|
config = mergedicts_copy(config, mconfig)
|
||||||
else:
|
else:
|
||||||
config = mconfig
|
config = mconfig
|
||||||
colorscheme_configs[colorscheme] = config
|
colorscheme_configs[ext][colorscheme] = config
|
||||||
|
|
||||||
theme_configs = dict2(loaded_configs['themes'])
|
theme_configs = dict2(loaded_configs['themes'])
|
||||||
top_theme_configs = dict(loaded_configs['top_themes'])
|
top_theme_configs = dict(loaded_configs['top_themes'])
|
||||||
|
@ -499,6 +499,56 @@ def check_segment_function(function_name, data, context, echoerr):
|
|||||||
return True, False, False
|
return True, False, False
|
||||||
|
|
||||||
|
|
||||||
|
def hl_group_in_colorscheme(hl_group, cconfig, allow_gradients, data, context, echoerr):
|
||||||
|
havemarks(hl_group, cconfig)
|
||||||
|
if hl_group not in cconfig.get('groups', {}):
|
||||||
|
return False
|
||||||
|
elif not allow_gradients or allow_gradients == 'force':
|
||||||
|
group_config = cconfig['groups'][hl_group]
|
||||||
|
while isinstance(group_config, unicode):
|
||||||
|
try:
|
||||||
|
group_config = cconfig['groups'][group_config]
|
||||||
|
except KeyError:
|
||||||
|
# No such group. Error was already reported when checking
|
||||||
|
# colorschemes.
|
||||||
|
return True
|
||||||
|
havemarks(group_config)
|
||||||
|
hadgradient = False
|
||||||
|
for ckey in ('fg', 'bg'):
|
||||||
|
color = group_config.get(ckey)
|
||||||
|
if not color:
|
||||||
|
# No color. Error was already reported when checking
|
||||||
|
# colorschemes.
|
||||||
|
return True
|
||||||
|
havemarks(color)
|
||||||
|
# Gradients are only allowed for function segments. Note that
|
||||||
|
# whether *either* color or gradient exists should have been
|
||||||
|
# already checked
|
||||||
|
hascolor = color in data['colors_config'].get('colors', {})
|
||||||
|
hasgradient = color in data['colors_config'].get('gradients', {})
|
||||||
|
if hasgradient:
|
||||||
|
hadgradient = True
|
||||||
|
if allow_gradients is False and not hascolor and hasgradient:
|
||||||
|
echoerr(
|
||||||
|
context='Error while checking highlight group in theme (key {key})'.format(
|
||||||
|
key=context.key),
|
||||||
|
context_mark=hl_group.mark,
|
||||||
|
problem='group {0} is using gradient {1} instead of a color'.format(hl_group, color),
|
||||||
|
problem_mark=color.mark
|
||||||
|
)
|
||||||
|
return False
|
||||||
|
if allow_gradients == 'force' and not hadgradient:
|
||||||
|
echoerr(
|
||||||
|
context='Error while checking highlight group in theme (key {key})'.format(
|
||||||
|
key=context.key),
|
||||||
|
context_mark=hl_group.mark,
|
||||||
|
problem='group {0} should have at least one gradient color, but it has no'.format(hl_group),
|
||||||
|
problem_mark=group_config.mark
|
||||||
|
)
|
||||||
|
return False
|
||||||
|
return True
|
||||||
|
|
||||||
|
|
||||||
def hl_exists(hl_group, data, context, echoerr, allow_gradients=False):
|
def hl_exists(hl_group, data, context, echoerr, allow_gradients=False):
|
||||||
havemarks(hl_group)
|
havemarks(hl_group)
|
||||||
ext = data['ext']
|
ext = data['ext']
|
||||||
@ -507,45 +557,14 @@ def hl_exists(hl_group, data, context, echoerr, allow_gradients=False):
|
|||||||
# twice
|
# twice
|
||||||
return []
|
return []
|
||||||
r = []
|
r = []
|
||||||
|
found = False
|
||||||
for colorscheme, cconfig in data['colorscheme_configs'][ext].items():
|
for colorscheme, cconfig in data['colorscheme_configs'][ext].items():
|
||||||
if hl_group not in cconfig.get('groups', {}):
|
if hl_group_in_colorscheme(hl_group, cconfig, allow_gradients, data, context, echoerr):
|
||||||
|
found = True
|
||||||
|
else:
|
||||||
r.append(colorscheme)
|
r.append(colorscheme)
|
||||||
elif not allow_gradients or allow_gradients == 'force':
|
if not found:
|
||||||
group_config = cconfig['groups'][hl_group]
|
pass
|
||||||
havemarks(group_config)
|
|
||||||
hadgradient = False
|
|
||||||
for ckey in ('fg', 'bg'):
|
|
||||||
color = group_config.get(ckey)
|
|
||||||
if not color:
|
|
||||||
# No color. Error was already reported.
|
|
||||||
continue
|
|
||||||
havemarks(color)
|
|
||||||
# Gradients are only allowed for function segments. Note that
|
|
||||||
# whether *either* color or gradient exists should have been
|
|
||||||
# already checked
|
|
||||||
hascolor = color in data['colors_config'].get('colors', {})
|
|
||||||
hasgradient = color in data['colors_config'].get('gradients', {})
|
|
||||||
if hasgradient:
|
|
||||||
hadgradient = True
|
|
||||||
if allow_gradients is False and not hascolor and hasgradient:
|
|
||||||
echoerr(
|
|
||||||
context='Error while checking highlight group in theme (key {key})'.format(
|
|
||||||
key=context.key),
|
|
||||||
context_mark=hl_group.mark,
|
|
||||||
problem='group {0} is using gradient {1} instead of a color'.format(hl_group, color),
|
|
||||||
problem_mark=color.mark
|
|
||||||
)
|
|
||||||
r.append(colorscheme)
|
|
||||||
continue
|
|
||||||
if allow_gradients == 'force' and not hadgradient:
|
|
||||||
echoerr(
|
|
||||||
context='Error while checking highlight group in theme (key {key})'.format(
|
|
||||||
key=context.key),
|
|
||||||
context_mark=hl_group.mark,
|
|
||||||
problem='group {0} should have at least one gradient color, but it has no'.format(hl_group),
|
|
||||||
problem_mark=group_config.mark
|
|
||||||
)
|
|
||||||
r.append(colorscheme)
|
|
||||||
return r
|
return r
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user