mirror of
https://github.com/powerline/powerline.git
synced 2025-07-23 22:05:43 +02:00
adapt linter
This commit is contained in:
parent
a0aef34642
commit
e04be6f5c9
@ -144,19 +144,33 @@ true_color_spec = Spec().re(
|
||||
'^[0-9a-fA-F]{6}$',
|
||||
(lambda value: '"{0}" is not a six-digit hexadecimal unsigned integer written as a string'.format(value))
|
||||
).copy
|
||||
hex_color_spec = Spec().re(
|
||||
'0x[0-9a-fA-F]{6}$',
|
||||
(lambda value: '"{0}" is not a six-digit hexadecimal unsigned integer written as a string'.format(value))
|
||||
).copy
|
||||
hex_color_spec_long = Spec().re(
|
||||
'0x[0-9a-fA-F]{8}$',
|
||||
(lambda value: '"{0}" is not a eight-digit hexadecimal unsigned integer written as a string'.format(value))
|
||||
).copy
|
||||
|
||||
colors_spec = (Spec(
|
||||
colors=Spec().unknown_spec(
|
||||
Spec().ident(),
|
||||
Spec().either(
|
||||
Spec().tuple(term_color_spec(), true_color_spec()),
|
||||
term_color_spec()
|
||||
term_color_spec(),
|
||||
hex_color_spec(),
|
||||
hex_color_spec_long()
|
||||
)
|
||||
).context_message('Error while checking colors (key {key})'),
|
||||
gradients=Spec().unknown_spec(
|
||||
Spec().ident(),
|
||||
Spec().tuple(
|
||||
Spec().len('gt', 1).list(term_color_spec()),
|
||||
Spec().len('gt', 1).list(true_color_spec()).optional(),
|
||||
Spec().either(
|
||||
Spec().tuple(
|
||||
Spec().len('gt', 1).list(term_color_spec()),
|
||||
Spec().len('gt', 1).list(true_color_spec()).optional(),
|
||||
),
|
||||
Spec().len('gt', 1).list(hex_color_spec())
|
||||
)
|
||||
).context_message('Error while checking gradients (key {key})'),
|
||||
).context_message('Error while loading colors configuration'))
|
||||
@ -168,7 +182,8 @@ group_name_spec = Spec().ident().copy
|
||||
group_spec = Spec().either(Spec(
|
||||
fg=color_spec(),
|
||||
bg=color_spec(),
|
||||
attrs=Spec().list(Spec().type(unicode).oneof(set(('bold', 'italic', 'underline')))),
|
||||
attrs=Spec().list(Spec().type(unicode).oneof(set(('bold', 'italic', 'underline', 'overline')))).optional(),
|
||||
click=Spec().optional(),
|
||||
), group_name_spec().func(check_group)).copy
|
||||
groups_spec = Spec().unknown_spec(
|
||||
group_name_spec(),
|
||||
@ -214,19 +229,37 @@ shell_colorscheme_spec = (Spec(
|
||||
mode_translations_value_spec(),
|
||||
).optional().context_message('Error while loading mode translations (key {key})'),
|
||||
).context_message('Error while loading shell colorscheme'))
|
||||
|
||||
ipython_mode_spec = Spec().oneof(set(['vi-navigation', 'vi-insert', 'vi-insert-multiple',
|
||||
'vi-replace'])).copy
|
||||
ipython_colorscheme_spec = (Spec(
|
||||
name=name_spec(),
|
||||
groups=groups_spec(),
|
||||
mode_translations=Spec().unknown_spec(
|
||||
ipython_mode_spec(),
|
||||
mode_translations_value_spec(),
|
||||
).optional().context_message('Error while loading mode translations (key {key})'),
|
||||
).context_message('Error while loading vim colorscheme'))
|
||||
|
||||
args_spec = Spec(
|
||||
pl=Spec().error('pl object must be set by powerline').optional(),
|
||||
segment_info=Spec().error('Segment info dictionary must be set by powerline').optional(),
|
||||
).unknown_spec(Spec(), Spec()).optional().copy
|
||||
segment_module_spec = Spec().type(unicode).func(check_segment_module).optional().copy
|
||||
exinclude_spec = Spec().re(function_name_re).func(check_exinclude_function).copy
|
||||
exinclude_spec = Spec().either(
|
||||
Spec(
|
||||
function=Spec().re(function_name_re).func(check_segment_function),
|
||||
args=Spec().unknown_spec(Spec(), Spec()).func(
|
||||
lambda *args, **kwargs: check_args(get_one_segment_function, *args, **kwargs)
|
||||
)
|
||||
).func(lambda *args, **kwargs: (True, True, False)),
|
||||
Spec().re(function_name_re).func(check_exinclude_function)
|
||||
).copy
|
||||
|
||||
segment_spec_base = Spec(
|
||||
name=Spec().re('^[a-zA-Z_]\w*$').optional(),
|
||||
function=Spec().re(function_name_re).func(check_segment_function).optional(),
|
||||
exclude_modes=Spec().list(vim_mode_spec()).optional(),
|
||||
include_modes=Spec().list(vim_mode_spec()).optional(),
|
||||
exclude_modes=Spec().optional(),
|
||||
include_modes=Spec().optional(),
|
||||
exclude_function=exinclude_spec().optional(),
|
||||
include_function=exinclude_spec().optional(),
|
||||
draw_hard_divider=Spec().type(bool).optional(),
|
||||
@ -263,9 +296,10 @@ segments_spec = Spec().optional().list(segment_spec).copy
|
||||
segdict_spec = Spec(
|
||||
left=segments_spec().context_message('Error while loading segments from left side (key {key})'),
|
||||
right=segments_spec().context_message('Error while loading segments from right side (key {key})'),
|
||||
center=segments_spec().context_message('Error while loading segments from center side (key {key})'),
|
||||
).func(
|
||||
(lambda value, *args: (True, True, not (('left' in value) or ('right' in value)))),
|
||||
(lambda value: 'segments dictionary must contain either left, right or both keys')
|
||||
(lambda value, *args: (True, True, not (('left' in value) or ('right' in value) or ('center' in value)))),
|
||||
(lambda value: 'segments dictionary must contain either left, right, center or all keys')
|
||||
).context_message('Error while loading segments (key {key})').copy
|
||||
divside_spec = Spec(
|
||||
hard=divider_spec(),
|
||||
@ -281,6 +315,7 @@ segment_data_value_spec = Spec(
|
||||
dividers_spec = Spec(
|
||||
left=divside_spec(),
|
||||
right=divside_spec(),
|
||||
center=divside_spec(),
|
||||
).copy
|
||||
spaces_spec = Spec().unsigned().cmp(
|
||||
'le', 2, (lambda value: 'Are you sure you need such a big ({0}) number of spaces?'.format(value))
|
||||
@ -556,8 +591,10 @@ def check(paths=None, debug=False, echoerr=echoerr, require_ext=None):
|
||||
spec = vim_colorscheme_spec
|
||||
elif ext == 'shell':
|
||||
spec = shell_colorscheme_spec
|
||||
elif ext == 'ipython':
|
||||
spec = ipython_colorscheme_spec
|
||||
else:
|
||||
spec = colorscheme_spec
|
||||
spec = top_colorscheme_spec
|
||||
if spec.match(config, context=Context(config), data=data, echoerr=ee)[1]:
|
||||
hadproblem = True
|
||||
|
||||
|
@ -16,7 +16,7 @@ from powerline.lint.context import JStr, list_themes
|
||||
from powerline.lint.imp import WithPath, import_function, import_segment
|
||||
from powerline.lint.spec import Spec
|
||||
from powerline.lint.inspect import getconfigargspec
|
||||
|
||||
from powerline.colorscheme import hex_to_cterm
|
||||
|
||||
list_sep = JStr(', ')
|
||||
|
||||
@ -152,13 +152,18 @@ def check_top_theme(theme, data, context, echoerr):
|
||||
def check_color(color, data, context, echoerr):
|
||||
havemarks(color)
|
||||
if (color not in data['colors_config'].get('colors', {})
|
||||
and color not in data['colors_config'].get('gradients', {})):
|
||||
and color not in data['colors_config'].get('gradients', {})):
|
||||
try:
|
||||
if hex_to_cterm(color) != -1:
|
||||
return True, False, False
|
||||
except Exception:
|
||||
pass
|
||||
echoerr(
|
||||
context='Error while checking highlight group in colorscheme (key {key})'.format(
|
||||
key=context.key),
|
||||
problem='found unexistent color or gradient {0}'.format(color),
|
||||
problem_mark=color.mark
|
||||
)
|
||||
context='Error while checking highlight group in colorscheme (key {key})'.format(
|
||||
key=context.key),
|
||||
problem='found unexistent color or gradient {0}'.format(color),
|
||||
problem_mark=color.mark
|
||||
)
|
||||
return True, False, True
|
||||
return True, False, False
|
||||
|
||||
@ -256,7 +261,7 @@ def check_key_compatibility(segment, data, context, echoerr):
|
||||
hadproblem = False
|
||||
|
||||
keys = set(segment)
|
||||
if not ((keys - generic_keys) < type_keys[segment_type]):
|
||||
if not ((keys - generic_keys) <= type_keys[segment_type]):
|
||||
unknown_keys = keys - generic_keys - type_keys[segment_type]
|
||||
echoerr(
|
||||
context='Error while checking segments (key {key})'.format(key=context.key),
|
||||
@ -570,15 +575,6 @@ def hl_group_in_colorscheme(hl_group, cconfig, allow_gradients, data, context, e
|
||||
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
|
||||
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user