Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
51 commits
Select commit Hold shift + click to select a range
9f84ad7
add placeholders
MJoshuaB Aug 11, 2024
c81ff56
add new placeholder comments
MJoshuaB Aug 20, 2024
18762be
exploring AST unfinished - minor emergency had to leave
Aug 21, 2024
2238161
identifying some mismatched functions
Aug 28, 2024
95fe015
refactor checker and tests
MJoshuaB Aug 28, 2024
e2e664f
fix error with non-builtins decorators
MJoshuaB Aug 28, 2024
46053e6
fine tuning and testing required
Aug 29, 2024
b402a5d
add pylint report
MJoshuaB Aug 29, 2024
3d051d7
add ranked listing of reports
MJoshuaB Aug 29, 2024
fdf6db7
format report as table
MJoshuaB Aug 29, 2024
fb160d5
add new verbs
MJoshuaB Sep 1, 2024
f06c915
update report
MJoshuaB Sep 2, 2024
db697b2
update reportcounts.md
MJoshuaB Sep 2, 2024
ae66d2c
fix formatting for reportcounts.md
MJoshuaB Sep 2, 2024
233f536
update reportcounts.md
MJoshuaB Sep 2, 2024
27edb80
minimal tests added
Sep 3, 2024
112173d
Merge pull request #2 from Azure/main
JessicaBell00 Sep 8, 2024
c5ffb91
Merge branch 'Azure:main' into main
JessicaBell00 Sep 10, 2024
7dc03ca
Merge branch 'working-main' into main
JessicaBell00 Sep 12, 2024
18f09e9
Merge pull request #5 from MJoshuaB/main
JessicaBell00 Sep 12, 2024
af098f7
Merge branch 'Azure:main' into working-main
JessicaBell00 Sep 12, 2024
6e53b16
Final Refactor
Sep 17, 2024
80657b4
not running multiple times picking up on different function types
Sep 19, 2024
5b69e7e
Merge branch 'main' into invalid-use-of-@overload
16234397 Sep 19, 2024
b10a3cd
add TODOs
MJoshuaB Sep 21, 2024
a0e5c18
removed code not reached
Sep 24, 2024
bf6936c
Merge remote-tracking branch 'origin/invalid-use-of-@overload' into i…
Sep 24, 2024
3ed8120
Checks at a class level
Sep 24, 2024
ac9921a
Merge branch 'main' into invalid-use-of-@overload
16234397 Sep 24, 2024
4c638df
Looking into different connection_verify assignments
Sep 25, 2024
ab62179
Placeholders added back
16234397 Sep 26, 2024
795c861
Checker base done
Sep 26, 2024
35094ba
exclue private namespaces and classes
MJoshuaB Sep 26, 2024
ed5e211
update reports
MJoshuaB Sep 27, 2024
a835da4
Checker, Tests, & Readme done
Sep 29, 2024
ae88cee
add new prefixes
MJoshuaB Oct 1, 2024
efe6ddc
Merge branch 'main' into working-main
MJoshuaB Oct 1, 2024
0bf7340
Merge branch 'working-main' into approved_prefix
MJoshuaB Oct 2, 2024
cfaa891
update unit tests
MJoshuaB Oct 2, 2024
a6f341a
remove reports
MJoshuaB Oct 2, 2024
5947f31
remove commented code
MJoshuaB Oct 2, 2024
65e431f
add checker to README
MJoshuaB Oct 2, 2024
c50a082
Merge branch 'working-main' into do-not-hardcode-boolean-connection_v…
16234397 Oct 5, 2024
24e9647
Merge pull request #10 from MJoshuaB/do-not-hardcode-boolean-connecti…
16234397 Oct 5, 2024
1f78550
Merge branch 'working-main' into invalid-use-of-@overload
16234397 Oct 5, 2024
56176ca
Merge pull request #11 from MJoshuaB/invalid-use-of-@overload
16234397 Oct 5, 2024
8cdce20
Tidy Up
Oct 5, 2024
6d262e3
Merge branch 'working-main' into approved_prefix
MJoshuaB Oct 6, 2024
9217630
Revert "Merge branch 'working-main' into approved_prefix"
MJoshuaB Oct 7, 2024
d64d347
remove duplicate tests
MJoshuaB Oct 8, 2024
bb867c7
Merge branch 'main' into approved_prefix
MJoshuaB Oct 11, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Revert "Merge branch 'working-main' into approved_prefix"
This reverts commit 6d262e3, reversing
changes made to 65e431f.
  • Loading branch information
MJoshuaB committed Oct 7, 2024
commit 921763005dc34a35f6ea39b5f3b813748c9ab68a
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 @@ -93,12 +93,11 @@ In the case of a false positive, use the disable command to remove the pylint er
| docstring-keyword-should-match-keyword-only | Docstring keyword arguments and keyword-only method arguments should match. | pylint:disable=docstring-keyword-should-match-keyword-only | [link](https://azure.github.io/azure-sdk/python_documentation.html#docstrings) |
| 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. |
| invalid-use-of-overload | Do not mix async and synchronous overloads | pylint:disable=invalid-use-of-overload | 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. |
| TODO | custom linter check for invalid use of @overload #3229 | | |
| TODO | Custom Linter check for Exception Logging #3227 | | |
| unapproved-client-method-name-prefix | Clients should use preferred verbs for method names | pylint:disable=unapproved-client-method-name-prefix | [link](https://azure.github.io/azure-sdk/python_design.html#naming) |
| do-not-hardcode-connection-verify | Do not hardcode a boolean value to connection_verify | pylint:disable=do-not-hardcode-connection-verify | No LInk. |
| TODO | Add a check for connection_verify hardcoded settings #35355 | | |
| TODO | Address Commented out Pylint Custom Plugin Checkers #3228 | | |
Original file line number Diff line number Diff line change
Expand Up @@ -2817,75 +2817,12 @@ def visit_import(self, node):
)
except:
pass


class InvalidUseOfOverload(BaseChecker):
"""Rule to check that use of the @overload decorator matches the async/sync nature of the underlying function"""

name = "invalid-use-of-overload"
priority = -1
msgs = {
"C4765": (
"Do not mix async and synchronous overloads",
"invalid-use-of-overload",
"Functions and their overloads must be either all async or all synchronous.",
),
}

def visit_classdef(self, node):
"""Check that use of the @overload decorator matches the async/sync nature of the underlying function"""

# Obtain a list of all functions and function names
functions = []
try:
node.body
for item in node.body:
if hasattr(item, 'name'):
functions.append(item)

# Dictionary of lists of all functions by name
overloadedfunctions = {}
for item in functions:
if item.name in overloadedfunctions:
overloadedfunctions[item.name].append(item)
else:
overloadedfunctions[item.name] = [item]


# Loop through the overloaded functions and check they are the same type
for funct in overloadedfunctions.values():
if len(funct) > 1: # only need to check if there is more than 1 function with the same name
function_is_async = None

for item in funct:
if function_is_async is None:
function_is_async = self.is_function_async(item)

else:
if function_is_async != self.is_function_async(item):
self.add_message(
msgid=f"invalid-use-of-overload",
node=item,
confidence=None,
)
except:
pass


def is_function_async(self, node):
try:
str(node.__class__).index("Async")
return True
except:
if node.returns is None:
return False
try:
if node.returns.value.name == "Awaitable":
return True
else:
return False
except:
return False
# [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 @@ -2918,6 +2855,7 @@ 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 @@ -2946,83 +2884,12 @@ 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

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] 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


# if a linter is registered in this function then it will be checked with pylint
Expand Down Expand Up @@ -3058,12 +2925,15 @@ def register(linter):
linter.register_checker(DoNotImportAsyncio(linter))
linter.register_checker(NoLegacyAzureCoreHttpResponseImport(linter))
linter.register_checker(NoImportTypingFromTypeCheck(linter))
linter.register_checker(InvalidUseOfOverload(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
linter.register_checker(DoNotHardcodeConnectionVerify(linter))
# [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

# disabled by default, use pylint --enable=check-docstrings if you want to use it
linter.register_checker(CheckDocstringParameters(linter))
Expand Down

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

Loading