Skip to content

Commit

Permalink
determine test_package folder in the lint rule
Browse files Browse the repository at this point in the history
  • Loading branch information
technic committed Jan 4, 2023
1 parent 579ab46 commit 62c83bc
Showing 1 changed file with 15 additions and 2 deletions.
17 changes: 15 additions & 2 deletions linter/check_package_name.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from pylint.checkers import BaseChecker
from pylint.interfaces import IAstroidChecker
from astroid import nodes, Const, AssignName
from pathlib import Path


class PackageName(BaseChecker):
Expand All @@ -21,19 +22,31 @@ class PackageName(BaseChecker):
"Missing name attribute",
"conan-missing-name",
"The member attribute `name` must be declared: `name = 'foobar'`."
)
),
"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:
filename = Path(node.root().file)
is_test = filename.match('test_package/*.py') or filename.match('test_v1_package/*.py')

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):
if is_test:
self.add_message("conan-test-no-name", node=attr, line=attr.lineno)
return
value = children[1].as_string()
if value.lower() != value:
self.add_message("conan-bad-name", node=attr, line=attr.lineno)
return
self.add_message("conan-missing-name", node=node)
if not is_test:
self.add_message("conan-missing-name", node=node)

0 comments on commit 62c83bc

Please sign in to comment.