-
Notifications
You must be signed in to change notification settings - Fork 285
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add support for pylint config files #673
base: develop
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
# Copyright 2019 Palantir Technologies, Inc. | ||
import logging | ||
import os | ||
from pyls._utils import find_parents | ||
from .source import ConfigSource, _get_opt, _set_opt | ||
|
||
log = logging.getLogger(__name__) | ||
|
||
PROJECT_CONFIGS = ['.pylintrc', 'pylintrc'] | ||
|
||
CONFIG_KEYS = { # 'option': 'section key' | ||
'disable': 'MESSAGES CONTROL', | ||
'ignore': 'MASTER', | ||
'max-line-length': 'FORMAT', | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
|
||
OPTIONS = [ | ||
('disable', 'plugins.pylint.disable', list), | ||
('ignore', 'plugins.pylint.ignore', list), | ||
('max-line-length', 'plugins.pylint.maxLineLength', int), | ||
] | ||
|
||
|
||
class PylintConfig(ConfigSource): | ||
"""Parse pylint configurations.""" | ||
|
||
def user_config(self): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Would be nice to add a docstring with some explanation. Also maybe saying what the returned object is. |
||
config_file = self._user_config_file() | ||
config = self.read_config_from_files([config_file]) | ||
return self.parse_config_multi_keys(config, CONFIG_KEYS, OPTIONS) | ||
|
||
def _user_config_file(self): | ||
if self.is_windows: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do we really need to make this special case for windows? I was expecting this |
||
return os.path.expanduser('~\\.pylintrc') | ||
return os.path.expanduser('~/.pylintrc') | ||
|
||
def project_config(self, document_path): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Would be nice to add a docstring with some explanation. Also maybe saying what the returned object is. |
||
files = find_parents(self.root_path, document_path, PROJECT_CONFIGS) | ||
config = self.read_config_from_files(files) | ||
return self.parse_config_multi_keys(config, CONFIG_KEYS, OPTIONS) | ||
|
||
@staticmethod | ||
def parse_config_multi_keys(config, keys, options): | ||
"""Parse the config with the given options. | ||
This method use multiple keys depending on the value we want to get. | ||
""" | ||
conf = {} | ||
for source, destination, opt_type in options: | ||
key = keys[source] | ||
opt_value = _get_opt(config, key, source, opt_type) | ||
if opt_value is not None: | ||
_set_opt(conf, destination, opt_value) | ||
return conf |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So we are only using the first 2 options?
https://docs.pylint.org/en/1.6.0/run.html