Files
conan-center-index/linter/check_no_test_package_name.py
Javier G. Sogo 27d78eb31f (#12023) [linter] Add first rule for test_package files
* [linter] Add first rule for test_package files

* add failing test

* revert failing recipe

* typo
2022-08-03 16:05:25 +02:00

31 lines
1013 B
Python

from pylint.checkers import BaseChecker
from pylint.interfaces import IAstroidChecker
from astroid import nodes, Const, AssignName
class NoPackageName(BaseChecker):
"""
Conanfile used for testing a package should NOT provide a name
"""
__implements__ = IAstroidChecker
name = "conan-test-package-name"
msgs = {
"E9007": (
"No 'name' attribute in test_package conanfile",
"conan-test-no-name",
"No 'name' attribute in test_package conanfile."
)
}
def visit_classdef(self, node: nodes) -> None:
if node.basenames == ['ConanFile']:
for attr in node.body:
children = list(attr.get_children())
if len(children) == 2 and \
isinstance(children[0], AssignName) and \
children[0].name == "name" and \
isinstance(children[1], Const):
self.add_message("conan-test-no-name", node=attr, line=attr.lineno)