Use .pylintrc files (#654)

* switched pylint to a .pylintrc based config

Signed-off-by: Mark Cohen <markcoh@amazon.com>

* added invalid-name pylint disable instruction because the framework requires camel case instead of snake case

Signed-off-by: Mark Cohen <markcoh@amazon.com>

---------

Signed-off-by: Mark Cohen <markcoh@amazon.com>
This commit is contained in:
Mark Cohen
2024-01-19 16:17:32 -05:00
committed by GitHub
parent 0ddbf8cafa
commit 7c66e8cf3d
5 changed files with 29 additions and 59 deletions
+7
View File
@@ -0,0 +1,7 @@
[MESSAGES CONTROL]
disable=all
enable=line-too-long,invalid-name,pointless-statement,unspecified-encoding,
missing-function-docstring,missing-param-doc,differing-param-doc
max-line-length=240
good-names-rgxs=^[_a-z][_a-z0-9]?$
+6 -58
View File
@@ -25,7 +25,7 @@
# under the License.
from typing import Any, List
from typing import Any
import nox
@@ -102,7 +102,11 @@ def lint(session: Any) -> None:
session.run("black", "--check", *SOURCE_FILES)
session.run("flake8", *SOURCE_FILES)
lint_per_folder(session)
pylint_overrides = ["opensearchpy/", "test_opensearchpy/"]
pylint_defaults = [file for file in SOURCE_FILES if file not in pylint_overrides]
for file in pylint_overrides:
session.run("pylint", "--rcfile", f"{file}.pylintrc", f"{file}")
session.run("pylint", "--rcfile", ".pylintrc", *pylint_defaults)
session.run("python", "utils/license_headers.py", "check", *SOURCE_FILES)
@@ -122,62 +126,6 @@ def lint(session: Any) -> None:
session.run("mypy", "--strict", "test_opensearchpy/test_types/sync_types.py")
def lint_per_folder(session: Any) -> None:
"""
allows configuration of pylint rules per folder and runs a pylint command for each folder
:param session: the current nox session
"""
# any paths that should not be run through pylint
exclude_path_from_linting: List[str] = []
# all paths not referenced in override_enable will run these lints
default_enable = [
"line-too-long",
"invalid-name",
"pointless-statement",
"unspecified-encoding",
"missing-function-docstring",
"missing-param-doc",
"differing-param-doc",
]
override_enable = {
"test_opensearchpy/": [
"line-too-long",
# "invalid-name", lots of short functions with one or two character names
"pointless-statement",
"unspecified-encoding",
"missing-param-doc",
"differing-param-doc",
# "missing-function-docstring", test names usually are, self describing
],
"opensearchpy/": [
"line-too-long",
"invalid-name",
"pointless-statement",
"unspecified-encoding",
],
}
for source_file in SOURCE_FILES:
if source_file in exclude_path_from_linting:
continue
args = [
"--disable=all",
"--max-line-length=240",
"--good-names-rgxs=^[_a-z][_a-z0-9]?$",
"--load-plugins",
"pylint.extensions.docparams",
]
if source_file in override_enable:
args.append(f"--enable={','.join(override_enable[source_file])}")
else:
args.append(f"--enable={','.join(default_enable)}")
args.append(source_file)
session.run("pylint", *args)
@nox.session() # type: ignore
def docs(session: Any) -> None:
"""
+5
View File
@@ -0,0 +1,5 @@
[MESSAGES CONTROL]
disable=all
enable=line-too-long,invalid-name,pointless-statement,unspecified-encoding
max-line-length=240
good-names-rgxs=^[_a-z][_a-z0-9]?$
+10
View File
@@ -0,0 +1,10 @@
[MESSAGES CONTROL]
disable=all
enable=line-too-long,
invalid-name,
pointless-statement,
unspecified-encoding,
missing-param-doc,
differing-param-doc
max-line-length=240
good-names-rgxs=^[_a-z][_a-z0-9]?$
@@ -48,7 +48,7 @@ class TestSecurityPlugin(IsolatedAsyncioTestCase): # type: ignore
await add_connection("default", self.client)
async def asyncTearDown(self) -> None:
# pylint disable=invalid-name
# pylint: disable=invalid-name
if self.client:
await self.client.close()