本文整理汇总了Python中pylint.lint.PyLinter方法的典型用法代码示例。如果您正苦于以下问题:Python lint.PyLinter方法的具体用法?Python lint.PyLinter怎么用?Python lint.PyLinter使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pylint.lint
的用法示例。
在下文中一共展示了lint.PyLinter方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
# 需要导入模块: from pylint import lint [as 别名]
# 或者: from pylint.lint import PyLinter [as 别名]
def __init__(self, test_file):
test_reporter = FunctionalTestReporter()
self._linter = lint.PyLinter()
google_styleguide.register_checkers(self._linter)
shopify_styleguide.register_checkers(self._linter)
self._linter.set_reporter(test_reporter)
self._linter.config.persistent = 0
checkers.initialize(self._linter)
self._linter.disable('I')
try:
self._linter.read_config_file(test_file.option_file)
self._linter.load_config_file()
except NoFileError:
pass
self._test_file = test_file
示例2: linter
# 需要导入模块: from pylint import lint [as 别名]
# 或者: from pylint.lint import PyLinter [as 别名]
def linter(checker, register, enable, disable, reporter):
_linter = PyLinter()
_linter.set_reporter(reporter())
checkers.initialize(_linter)
if register:
register(_linter)
if checker:
_linter.register_checker(checker(_linter))
if disable:
for msg in disable:
_linter.disable(msg)
if enable:
for msg in enable:
_linter.enable(msg)
os.environ.pop("PYLINTRC", None)
return _linter
示例3: test_parseable_output_regression
# 需要导入模块: from pylint import lint [as 别名]
# 或者: from pylint.lint import PyLinter [as 别名]
def test_parseable_output_regression():
output = StringIO()
with warnings.catch_warnings(record=True):
linter = PyLinter(reporter=ParseableTextReporter())
checkers.initialize(linter)
linter.config.persistent = 0
linter.reporter.set_output(output)
linter.set_option("output-format", "parseable")
linter.open()
linter.set_current_module("0123")
linter.add_message("line-too-long", line=1, args=(1, 2))
assert (
output.getvalue() == "************* Module 0123\n"
"0123:1: [C0301(line-too-long), ] "
"Line too long (1/2)\n"
)
示例4: register
# 需要导入模块: from pylint import lint [as 别名]
# 或者: from pylint.lint import PyLinter [as 别名]
def register(linter): # type: (lint.PyLinter) -> None
google_styleguide.register_checkers(linter)
shopify_styleguide.register_checkers(linter)
示例5: register
# 需要导入模块: from pylint import lint [as 别名]
# 或者: from pylint.lint import PyLinter [as 别名]
def register(linter: PyLinter) -> None:
"""Required method to auto register this checker.
Args:
linter: Main interface object for Pylint plugins.
"""
linter.register_checker(MonolithChecker(linter))
linter.register_checker(TranslationStringConstantsChecker(linter))
linter.register_checker(AsyncAwaitChecker(linter))
示例6: register_checkers
# 需要导入模块: from pylint import lint [as 别名]
# 或者: from pylint.lint import PyLinter [as 别名]
def register_checkers(linter: PyLinter) -> None:
"""Register checkers."""
linter.register_checker(TranslationStringConstantsChecker(linter))
示例7: __init__
# 需要导入模块: from pylint import lint [as 别名]
# 或者: from pylint.lint import PyLinter [as 别名]
def __init__(self, linter: Optional[PyLinter] = None) -> None:
BaseChecker.__init__(self, linter)
self.isort_obj = isort.SortImports(
file_contents='',
)
示例8: test_disable_global_option_end_of_line
# 需要导入模块: from pylint import lint [as 别名]
# 或者: from pylint.lint import PyLinter [as 别名]
def test_disable_global_option_end_of_line():
"""
Test for issue with disabling tokenizer messages
that extend beyond the scope of the ast tokens
"""
file_ = tempfile.NamedTemporaryFile("w", delete=False)
with file_:
file_.write(
"""
mylist = [
None
]
"""
)
try:
linter = lint.PyLinter()
checker = FormatChecker(linter)
linter.register_checker(checker)
args = linter.load_command_line_configuration(
[file_.name, "-d", "bad-continuation"]
)
myreporter = reporters.CollectingReporter()
linter.set_reporter(myreporter)
linter.check(args)
assert not myreporter.messages
finally:
os.remove(file_.name)
示例9: linter
# 需要导入模块: from pylint import lint [as 别名]
# 或者: from pylint.lint import PyLinter [as 别名]
def linter():
l = PyLinter(reporter=testutils.TestReporter())
initialize(l)
return l
示例10: setUpClass
# 需要导入模块: from pylint import lint [as 别名]
# 或者: from pylint.lint import PyLinter [as 别名]
def setUpClass(cls):
cls._linter = PyLinter()
cls._linter.set_reporter(CompareToZeroTestReporter())
checkers.initialize(cls._linter)
cls._linter.register_checker(CompareToZeroChecker(cls._linter))
cls._linter.disable('I')
示例11: test_custom_should_analyze_file
# 需要导入模块: from pylint import lint [as 别名]
# 或者: from pylint.lint import PyLinter [as 别名]
def test_custom_should_analyze_file():
"""Check that we can write custom should_analyze_file that work
even for arguments.
"""
class CustomPyLinter(PyLinter):
def should_analyze_file(self, modname, path, is_argument=False):
if os.path.basename(path) == "wrong.py":
return False
return super(CustomPyLinter, self).should_analyze_file(
modname, path, is_argument=is_argument
)
package_dir = os.path.join(HERE, "regrtest_data", "bad_package")
wrong_file = os.path.join(package_dir, "wrong.py")
for jobs in [1, 2]:
reporter = testutils.TestReporter()
linter = CustomPyLinter()
linter.config.jobs = jobs
linter.config.persistent = 0
linter.open()
linter.set_reporter(reporter)
try:
sys.path.append(os.path.dirname(package_dir))
linter.check([package_dir, wrong_file])
finally:
sys.path.pop()
messages = reporter.messages
assert len(messages) == 1
assert "invalid syntax" in messages[0]
示例12: test_simple_json_output
# 需要导入模块: from pylint import lint [as 别名]
# 或者: from pylint.lint import PyLinter [as 别名]
def test_simple_json_output():
output = StringIO()
reporter = JSONReporter()
linter = PyLinter(reporter=reporter)
checkers.initialize(linter)
linter.config.persistent = 0
linter.reporter.set_output(output)
linter.open()
linter.set_current_module("0123")
linter.add_message("line-too-long", line=1, args=(1, 2))
# we call this method because we didn't actually run the checkers
reporter.display_messages(None)
expected_result = [
[
("column", 0),
("line", 1),
("message", "Line too long (1/2)"),
("message-id", "C0301"),
("module", "0123"),
("obj", ""),
("path", "0123"),
("symbol", "line-too-long"),
("type", "convention"),
]
]
report_result = json.loads(output.getvalue())
report_result = [sorted(report_result[0].items(), key=lambda item: item[0])]
assert report_result == expected_result
示例13: __init__
# 需要导入模块: from pylint import lint [as 别名]
# 或者: from pylint.lint import PyLinter [as 别名]
def __init__(self, test_file):
test_reporter = FunctionalTestReporter()
self._linter = lint.PyLinter()
self._linter.set_reporter(test_reporter)
self._linter.config.persistent = 0
checkers.initialize(self._linter)
self._linter.disable('I')
try:
self._linter.read_config_file(test_file.option_file)
self._linter.load_config_file()
except NoFileError:
pass
self._test_file = test_file
示例14: register
# 需要导入模块: from pylint import lint [as 别名]
# 或者: from pylint.lint import PyLinter [as 别名]
def register(linter: PyLinter):
linter.register_checker(DoNotUseAssertsChecker(linter))