adapt linter
This commit is contained in:
parent
a0aef34642
commit
e04be6f5c9
|
@ -66,7 +66,7 @@ main_spec = (Spec(
|
|||
default_top_theme=top_theme_spec().optional(),
|
||||
term_truecolor=Spec().type(bool).optional(),
|
||||
term_escape_style=Spec().type(unicode).oneof(set(('auto', 'xterm', 'fbterm'))).optional(),
|
||||
# Python is capable of loading from zip archives. Thus checking path
|
||||
# Python is capable of loading from zip archives. Thus checking path
|
||||
# only for existence of the path, not for it being a directory
|
||||
paths=Spec().list(
|
||||
(lambda value, *args: (True, True, not os.path.exists(os.path.expanduser(value.value)))),
|
||||
|
@ -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))
|
||||
|
@ -396,17 +431,17 @@ def check(paths=None, debug=False, echoerr=echoerr, require_ext=None):
|
|||
:param list paths:
|
||||
Paths from which configuration should be loaded.
|
||||
:param bool debug:
|
||||
Determines whether some information useful for debugging linter should
|
||||
Determines whether some information useful for debugging linter should
|
||||
be output.
|
||||
:param function echoerr:
|
||||
Function that will be used to echo the error(s). Should accept four
|
||||
optional keyword parameters: ``problem`` and ``problem_mark``, and
|
||||
Function that will be used to echo the error(s). Should accept four
|
||||
optional keyword parameters: ``problem`` and ``problem_mark``, and
|
||||
``context`` and ``context_mark``.
|
||||
:param str require_ext:
|
||||
Require configuration for some extension to be present.
|
||||
|
||||
:return:
|
||||
``False`` if user configuration seems to be completely sane and ``True``
|
||||
``False`` if user configuration seems to be completely sane and ``True``
|
||||
if some problems were found.
|
||||
'''
|
||||
hadproblem = False
|
||||
|
@ -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),
|
||||
|
@ -542,7 +547,7 @@ def hl_group_in_colorscheme(hl_group, cconfig, allow_gradients, data, context, e
|
|||
try:
|
||||
group_config = cconfig['groups'][group_config]
|
||||
except KeyError:
|
||||
# No such group. Error was already reported when checking
|
||||
# No such group. Error was already reported when checking
|
||||
# colorschemes.
|
||||
return True
|
||||
havemarks(group_config)
|
||||
|
@ -550,12 +555,12 @@ def hl_group_in_colorscheme(hl_group, cconfig, allow_gradients, data, context, e
|
|||
for ckey in ('fg', 'bg'):
|
||||
color = group_config.get(ckey)
|
||||
if not color:
|
||||
# No color. Error was already reported when checking
|
||||
# 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
|
||||
# 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', {})
|
||||
|
@ -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
|
||||
|
||||
|
||||
|
@ -586,7 +582,7 @@ def hl_exists(hl_group, data, context, echoerr, allow_gradients=False):
|
|||
havemarks(hl_group)
|
||||
ext = data['ext']
|
||||
if ext not in data['colorscheme_configs']:
|
||||
# No colorschemes. Error was already reported, no need to report it
|
||||
# No colorschemes. Error was already reported, no need to report it
|
||||
# twice
|
||||
return []
|
||||
r = []
|
||||
|
@ -805,7 +801,7 @@ def check_exinclude_function(name, data, context, echoerr):
|
|||
def check_log_file_level(this_level, data, context, echoerr):
|
||||
'''Check handler level specified in :ref:`log_file key <config-common-log>`
|
||||
|
||||
This level must be greater or equal to the level in :ref:`log_level key
|
||||
This level must be greater or equal to the level in :ref:`log_level key
|
||||
<config-common-log_level>`.
|
||||
'''
|
||||
havemarks(this_level)
|
||||
|
|
Loading…
Reference in New Issue