(#11627) linter - check ConanFile import and cross_building

* linter - check ConanFile import and cross_building

* remove unused code

* Add docs

* improve docs

* example - abseil

* md syntax

* revert uneeded changes

* Update docs/v2_linter.md

Co-authored-by: Daniel <danimanzaneque@gmail.com>

Co-authored-by: Daniel <danimanzaneque@gmail.com>
This commit is contained in:
Javier G. Sogo
2022-07-13 18:30:09 +02:00
committed by GitHub
parent 1f5efc8656
commit 202e85f077
9 changed files with 109 additions and 4 deletions

View File

@@ -0,0 +1,28 @@
from pylint.checkers import BaseChecker
from pylint.interfaces import IAstroidChecker
from astroid import nodes, Const, AssignName
class ImportConanFile(BaseChecker):
"""
Import ConanFile from new 'conan' module
"""
__implements__ = IAstroidChecker
name = "conan-import-conanfile"
msgs = {
"W9006": (
"Import ConanFile from new module: `from conan import ConanFile`. Old import is deprecated in Conan v2.",
"conan-import-conanfile",
"Import ConanFile from new module: `from conan import ConanFile`. Old import is deprecated in Conan v2.",
),
}
def visit_importfrom(self, node: nodes.ImportFrom) -> None:
basename = node.modname
if basename == 'conans':
names = [name for name, _ in node.names]
if 'ConanFile' in names:
self.add_message("conan-import-conanfile", node=node)