Skip to content
Closed
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ In the case of a false positive, use the disable command to remove the pylint er


| Pylint checker name | How to fix this | How to disable this rule | Link to python guideline |
|----------------------------------------------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------|---------------------------------------------------------------------| ------------------------------------------------------------------------------------------------------- |
|----------------------------------------------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------|---------------------------------------------------------------------|---------------------------------------------------------------------------------------------------------|
| client-method-should-not-use-static-method | Use module level functions instead. | # pylint:disable=client-method-should-not-use-static-method | [link](https://azure.github.io/azure-sdk/python_implementation.html#method-signatures) |
| missing-client-constructor-parameter-credential | Add a credential parameter to the client constructor. Do not use plural form "credentials". | # pylint:disable=missing-client-constructor-parameter-credential | [link](https://azure.github.io/azure-sdk/python_design.html#client-configuration) |
| missing-client-constructor-parameter-kwargs | Add a \*\*kwargs parameter to the client constructor. | # pylint:disable=missing-client-constructor-parameter-kwargs | [link](https://azure.github.io/azure-sdk/python_design.html#client-configuration) |
Expand Down Expand Up @@ -94,5 +94,10 @@ In the case of a false positive, use the disable command to remove the pylint er
| docstring-type-do-not-use-class | Docstring type is formatted incorrectly. Do not use `:class` in docstring type. | pylint:disable=docstring-type-do-not-use-class | [link](https://sphinx-rtd-tutorial.readthedocs.io/en/latest/docstrings.html) |
| no-typing-import-in-type-check | Do not import typing under TYPE_CHECKING. | pylint:disable=no-typing-import-in-type-check | No Link. |
| do-not-log-raised-errors | Do not log errors at `error` or `warning` level when error is raised in an exception block. | pylint:disable=do-not-log-raised-errors | No Link. |
| do-not-use-legacy-typing | Do not use legacy (<Python 3.8) type hinting comments | pylint:disable=do-not-use-legacy-typing | No Link.
| do-not-import-asyncio | Do not import asyncio directly. | pylint:disable=do-not-import-asyncio | No Link. |
| do-not-use-legacy-typing | Do not use legacy (<Python 3.8) type hinting comments | pylint:disable=do-not-use-legacy-typing | No Link.
| do-not-import-asyncio | Do not import asyncio directly. | pylint:disable=do-not-import-asyncio | No Link. |
| TODO | custom linter check for invalid use of @overload #3229 | | |
| TODO | Custom Linter check for Exception Logging #3227 | | |
| TODO | Address Commented out Pylint Custom Plugin Checkers #3228 | | |
| do-not-hardcode-connection-verify | Do not hardcode a boolean value to connection_verify | pylint:disable=do-not-hardcode-connection-verify | No LInk. |

Original file line number Diff line number Diff line change
Expand Up @@ -2803,6 +2803,12 @@ def visit_import(self, node):
)
except:
pass
# [Pylint] custom linter check for invalid use of @overload #3229
# [Pylint] Custom Linter check for Exception Logging #3227
# [Pylint] Address Commented out Pylint Custom Plugin Checkers #3228
# [Pylint] Add a check for connection_verify hardcoded settings #35355
# [Pylint] Refactor test suite for custom pylint checkers to use files instead of docstrings #3233
# [Pylint] Investigate pylint rule around missing dependency #3231


class DoNotUseLegacyTyping(BaseChecker):
Expand Down Expand Up @@ -2835,7 +2841,6 @@ class DoNotImportAsyncio(BaseChecker):

name = "do-not-import-asyncio"
priority = -1
# TODO Find message number
msgs = {
"C4763": (
"Do not import the asyncio package directly in your library",
Expand Down Expand Up @@ -2867,7 +2872,84 @@ def visit_import(self, node):
# [Pylint] custom linter check for invalid use of @overload #3229
# [Pylint] Custom Linter check for Exception Logging #3227
# [Pylint] Address Commented out Pylint Custom Plugin Checkers #3228
# [Pylint] Add a check for connection_verify hardcoded settings #35355

class DoNotHardcodeConnectionVerify(BaseChecker):

"""Rule to check that developers do not hardcode a boolean to connection_verify."""

name = "do-not-hardcode-connection-verify"
priority = -1
msgs = {
"C4767": (
"Do not hardcode a boolean value to connection_verify",
"do-not-hardcode-connection-verify",
"Do not hardcode a boolean value to connection_verify. It's up to customers who use the code to be able to set it",
),
}


def visit_call(self, node):
"""Visit function calls to ensure it isn't used as a parameter"""
try:
for keyword in node.keywords:
if keyword.arg == "connection_verify":
if type(keyword.value.value) == bool:
self.add_message(
msgid=f"do-not-hardcode-connection-verify",
node=keyword,
confidence=None,
)
except:
pass


def visit_assign(self, node):
"""Visiting variable Assignments"""
try: # Picks up self.connection_verify = True
if node.targets[0].attrname == "connection_verify":
if type(node.value.value) == bool:
self.add_message(
msgid=f"do-not-hardcode-connection-verify",
node=node,
confidence=None,
)
except:
try: # connection_verify = True
if node.targets[0].name == "connection_verify":
if type(node.value.value) == bool:
self.add_message(
msgid=f"do-not-hardcode-connection-verify",
node=node,
confidence=None,
)
except:
pass


def visit_annassign(self, node):
"""Visiting variable annotated assignments"""
try: # self.connection_verify: bool = True
if node.target.attrname == "connection_verify":
if type(node.value.value) == bool:
self.add_message(
msgid=f"do-not-hardcode-connection-verify",
node=node,
confidence=None,
)
except: # Picks up connection_verify: bool = True
try:
if node.target.name == "connection_verify":
if type(node.value.value) == bool:
self.add_message(
msgid=f"do-not-hardcode-connection-verify",
node=node,
confidence=None,
)
except:
pass



# [Pylint] Refactor test suite for custom pylint checkers to use files instead of docstrings #3233
# [Pylint] Investigate pylint rule around missing dependency #3231

Expand Down Expand Up @@ -2907,11 +2989,10 @@ def register(linter):
linter.register_checker(NoImportTypingFromTypeCheck(linter))
linter.register_checker(DoNotUseLegacyTyping(linter))
linter.register_checker(DoNotLogErrorsEndUpRaising(linter))

# [Pylint] custom linter check for invalid use of @overload #3229
# [Pylint] Custom Linter check for Exception Logging #3227
# [Pylint] Address Commented out Pylint Custom Plugin Checkers #3228
# [Pylint] Add a check for connection_verify hardcoded settings #35355
linter.register_checker(DoNotHardcodeConnectionVerify(linter))
# [Pylint] Refactor test suite for custom pylint checkers to use files instead of docstrings #3233
# [Pylint] Investigate pylint rule around missing dependency #3231

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
class InstanceVariableError:
def __init__(self):
self.connection_verify = None
self.self = self


class VariableError:
connection_verify = None


class FunctionArgumentsErrors:
def create(connection_verify):
pass

client = create(connection_verify=None)


class FunctionArgumentsInstanceErrors:
def __init__(self):
client = self.create_client_from_credential(connection_verify=None)


class ReturnErrorFunctionArgument:
def send(connection_verify):
pass

def sampleFunction(self):
return self.send(connection_verify=None)


class ReturnErrorDict:
def returnDict(self):

return dict(
connection_verify=None,
)


class AnnotatedAssignment:
connection_verify: bool = None


class AnnotatedSelfAssignment:
def __init__(self):
self.connection_verify: bool = None







Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
class InstanceVariableError:
def __init__(self):
self.connection_verify = True
self.self = self


class VariableError:
connection_verify = True


class FunctionArgumentsErrors:
def create(connection_verify):
pass

client = create(connection_verify=False)


class FunctionArgumentsInstanceErrors:
def __init__(self):
client = self.create_client_from_credential(connection_verify=False)


class ReturnErrorFunctionArgument:
def send(connection_verify):
pass

def sampleFunction(self):
return self.send(connection_verify=True)


class ReturnErrorDict:
def returnDict(self):

return dict(
connection_verify=False,
)

class AnnotatedAssignment:
connection_verify: bool = True



class AnnotatedSelfAssignment:
def __init__(self):
self.connection_verify: bool = True


Loading