gpt4 book ai didi

python - pylint 可以检查所有文档顶部的静态注释/版权声明吗?

转载 作者:行者123 更新时间:2023-12-02 03:30:54 29 4
gpt4 key购买 nike

是否可以将 pylint 配置为检查特定的静态文本,例如每个文件顶部的版权声明?

例如验证以下两行是否开始每个文件:

# Copyright Spacely Sprockets, 2018-2062
#

最佳答案

您可以编写自己的检查器:

from pylint.interfaces import IRawChecker
from pylint.checkers import BaseChecker

class CopyrightChecker(BaseChecker):
""" Check the first line for copyright notice
"""

__implements__ = IRawChecker

name = 'custom_copy'
msgs = {'W9902': ('Include copyright in file',
'file-no-copyright',
('Your file has no copyright')),
}
options = ()

def process_module(self, node):
"""process a module
the module's content is accessible via node.stream() function
"""
with node.stream() as stream:
for (lineno, line) in enumerate(stream):
if lineno == 1:
# Check for copyright notice
# if it fails add an error message
self.add_message('file-no-copyright',
line=lineno)


def register(linter):
"""required method to auto register this checker"""
linter.register_checker(CopyrightChecker(linter))

查看有关自定义检查器的更多信息 in the pylint documentation .还有 this excellent post about the subject .

关于python - pylint 可以检查所有文档顶部的静态注释/版权声明吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51886592/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com