Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change: replace pylint with ruff #733

Merged
merged 3 commits into from
Aug 8, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
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
468 changes: 0 additions & 468 deletions .pylintrc

This file was deleted.

144 changes: 36 additions & 108 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

29 changes: 12 additions & 17 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ repository = "https://github.com/greenbone/troubadix"
homepage = "https://github.com/greenbone/troubadix"

# Full list: https://pypi.org/pypi?%3Aaction=list_classifiers
classifiers=[
classifiers = [
"Development Status :: 4 - Beta",
"License :: OSI Approved :: GNU General Public License v3 or later (GPLv3+)", # pylint: disable=line-too-long
"License :: OSI Approved :: GNU General Public License v3 or later (GPLv3+)", # pylint: disable=line-too-long
"Environment :: Console",
"Intended Audience :: Developers",
"Programming Language :: Python :: 3.9",
Expand All @@ -21,10 +21,7 @@ classifiers=[
"Topic :: Software Development :: Libraries :: Python Modules",
]

packages = [
{ include = "troubadix"},
{ include = "tests", format = "sdist" },
]
packages = [{ include = "troubadix" }, { include = "tests", format = "sdist" }]

[tool.poetry.dependencies]
python = "^3.9"
Expand All @@ -36,11 +33,11 @@ validators = "0.20.0"
gitpython = "^3.1.31"
charset-normalizer = "^3.2.0"

[tool.poetry.dev-dependencies]
[tool.poetry.group.dev.dependencies]
autohooks = ">=21.7.0"
autohooks-plugin-black = ">=21.12.0"
autohooks-plugin-pylint = ">=21.6.0"
autohooks-plugin-isort = ">=22.3.0"
ruff = "^0.5.6"
autohooks-plugin-ruff = "^24.1.0"

[tool.black]
line-length = 80
Expand All @@ -60,17 +57,15 @@ exclude = '''
)/
'''

[tool.ruff]
line-length = 100
target-version = "py310"
lint.extend-select = ["I", "E", "W"]

[tool.autohooks]
mode = "poetry"
pre-commit = [
'autohooks.plugins.isort',
'autohooks.plugins.black',
'autohooks.plugins.pylint',
]
pre-commit = ['autohooks.plugins.black', 'autohooks.plugins.ruff']

[tool.isort]
profile = "black"
line_length = 80

[tool.pontos.version]
version-module-file = "troubadix/__version__.py"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@

class ChangedPackagesTestCase(TestCase):
def test_get_package(self):
# ruff: noqa: E501
content = """
...some NASL...
if(!isnull(res = isdpkgvuln(pkg:"libwpewebkit-1.0-3", ver:"2.38.3-1~deb11u1", rls:"DEB11"))) {
Expand Down
5 changes: 3 additions & 2 deletions tests/standalone_plugins/test_changed_oid.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,13 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.

import os
import unittest
import tempfile
import unittest
from contextlib import contextmanager
from pathlib import Path
from typing import Generator
from subprocess import SubprocessError
from typing import Generator

from troubadix.standalone_plugins.changed_oid import check_oid, git, parse_args


Expand Down
24 changes: 12 additions & 12 deletions tests/standalone_plugins/test_deprecate_vts.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,17 @@
# pylint: disable=protected-access
import unittest
from pathlib import Path
from tests.plugins import TemporaryDirectory

from tests.plugins import TemporaryDirectory
from troubadix.standalone_plugins.deprecate_vts import (
deprecate,
parse_args,
DeprecatedFile,
_get_summary,
_finalize_content,
update_summary,
get_files_from_path,
_get_summary,
deprecate,
filter_files,
get_files_from_path,
parse_args,
update_summary,
)


Expand Down Expand Up @@ -92,19 +92,19 @@ def test_mandatory_arg_group_neither(self):
'...if(description)\n{\n script_oid("1.3.6.1.4.1.25623.1.0.910673");'
'\n script_version("2024-03-12T14:15:13+0000");'
'\n script_name("RedHat: Security Advisory for gd (RHSA-2020:5443-01)");'
'\n script_family("Red Hat Local Security Checks");\n script_dependencies("gather-package-list.nasl");'
'\n script_family("Red Hat Local Security Checks");\n script_dependencies("gather-package-list.nasl");' # noqa: E501
'\n script_mandatory_keys("ssh/login/rhel", "ssh/login/rpms", re:"ssh/login/release=RHENT_7");'
'\n\n script_xref(name:"RHSA", value:"2020:5443-01");\n script_xref(name:"URL", value:"https://www.redhat.com/archives/rhsa-announce/2020-December/msg00044.html");'
'\n\n script_tag(name:"summary", value:"The remote host is missing an update for the \'gd\'\n package(s) announced via the RHSA-2020:5443-01 advisory.");'
'\n\n exit(0);\n}\n\ninclude("revisions-lib.inc");\ninclude("pkg-lib-rpm.inc");\n\nrelease = rpm_get_ssh_release();\nif(!release)\n exit(0);\n\nres = "";\nreport = "";\n\nif(release == "RHENT_7") {\n\n if(!isnull(res = isrpmvuln(pkg:"gd", rpm:"gd~2.0.35~27.el7_9", rls:"RHENT_7"))) {\n report += res;\n }\n\n if(!isnull(res = isrpmvuln(pkg:"gd-debuginfo", rpm:"gd-debuginfo~2.0.35~27.el7_9", rls:"RHENT_7"))) {\n report += res;\n }\n\n if(report != "") {\n security_message(data:report);\n } else if(__pkg_match) {\n exit(99);\n }\n exit(0);\n}\n\nexit(0);'
'\n\n script_tag(name:"summary", value:"The remote host is missing an update for the \'gd\'\n package(s) announced via the RHSA-2020:5443-01 advisory.");' # noqa: E501
'\n\n exit(0);\n}\n\ninclude("revisions-lib.inc");\ninclude("pkg-lib-rpm.inc");\n\nrelease = rpm_get_ssh_release();\nif(!release)\n exit(0);\n\nres = "";\nreport = "";\n\nif(release == "RHENT_7") {\n\n if(!isnull(res = isrpmvuln(pkg:"gd", rpm:"gd~2.0.35~27.el7_9", rls:"RHENT_7"))) {\n report += res;\n }\n\n if(!isnull(res = isrpmvuln(pkg:"gd-debuginfo", rpm:"gd-debuginfo~2.0.35~27.el7_9", rls:"RHENT_7"))) {\n report += res;\n }\n\n if(report != "") {\n security_message(data:report);\n } else if(__pkg_match) {\n exit(99);\n }\n exit(0);\n}\n\nexit(0);' # noqa: E501
)

NASL_CONTENT_KB = (
'...if(description)\n{\n script_oid("1.3.6.1.4.1.25623.1.0.910673");'
'\n script_mandatory_keys("ssh/login/rhel", "ssh/login/rpms", re:"ssh/login/release=RHENT_7");'
'\n\n set_kb_item(name:"shttp/" + port + "/detected", value:TRUE);"'
'\n\n script_tag(name:"summary", value:"The remote host is missing an update for the \'gd\'\n package(s) announced via the RHSA-2020:5443-01 advisory.");'
'\n\n exit(0);\n}\n\ninclude("revisions-lib.inc");\ninclude("pkg-lib-rpm.inc");\n\nrelease = rpm_get_ssh_release();\nif(!release)\n exit(0);\n\nres = "";\nreport = "";\n\nif(release == "RHENT_7") {\n\n if(!isnull(res = isrpmvuln(pkg:"gd", rpm:"gd~2.0.35~27.el7_9", rls:"RHENT_7"))) {\n report += res;\n }\n\n if(!isnull(res = isrpmvuln(pkg:"gd-debuginfo", rpm:"gd-debuginfo~2.0.35~27.el7_9", rls:"RHENT_7"))) {\n report += res;\n }\n\n if(report != "") {\n security_message(data:report);\n } else if(__pkg_match) {\n exit(99);\n }\n exit(0);\n}\n\nexit(0);'
'\n\n script_tag(name:"summary", value:"The remote host is missing an update for the \'gd\'\n package(s) announced via the RHSA-2020:5443-01 advisory.");' # noqa: E501
'\n\n exit(0);\n}\n\ninclude("revisions-lib.inc");\ninclude("pkg-lib-rpm.inc");\n\nrelease = rpm_get_ssh_release();\nif(!release)\n exit(0);\n\nres = "";\nreport = "";\n\nif(release == "RHENT_7") {\n\n if(!isnull(res = isrpmvuln(pkg:"gd", rpm:"gd~2.0.35~27.el7_9", rls:"RHENT_7"))) {\n report += res;\n }\n\n if(!isnull(res = isrpmvuln(pkg:"gd-debuginfo", rpm:"gd-debuginfo~2.0.35~27.el7_9", rls:"RHENT_7"))) {\n report += res;\n }\n\n if(report != "") {\n security_message(data:report);\n } else if(__pkg_match) {\n exit(99);\n }\n exit(0);\n}\n\nexit(0);' # noqa: E501
)


Expand Down Expand Up @@ -167,7 +167,7 @@ def test_finalize_content(self):
result = _finalize_content(NASL_CONTENT)
expected = (
'...if(description)\n{\n script_oid("1.3.6.1.4.1.25623.1.0.910673");\n '
'script_version("2024-03-12T14:15:13+0000");\n script_name("RedHat: Security Advisory for gd (RHSA-2020:5443-01)");\n script_family("Red Hat Local Security Checks");\n script_dependencies("gather-package-list.nasl");\n script_mandatory_keys("ssh/login/rhel", "ssh/login/rpms", re:"ssh/login/release=RHENT_7");\n\n script_xref(name:"RHSA", value:"2020:5443-01");\n script_xref(name:"URL", value:"https://www.redhat.com/archives/rhsa-announce/2020-December/msg00044.html");\n\n script_tag(name:"summary", value:"The remote host is missing an update for the \'gd\'\n package(s) announced via the RHSA-2020:5443-01 advisory.");\n\n script_tag(name:"deprecated", value:TRUE);\n\nexit(0);\n}\n\nexit(66);\n'
'script_version("2024-03-12T14:15:13+0000");\n script_name("RedHat: Security Advisory for gd (RHSA-2020:5443-01)");\n script_family("Red Hat Local Security Checks");\n script_dependencies("gather-package-list.nasl");\n script_mandatory_keys("ssh/login/rhel", "ssh/login/rpms", re:"ssh/login/release=RHENT_7");\n\n script_xref(name:"RHSA", value:"2020:5443-01");\n script_xref(name:"URL", value:"https://www.redhat.com/archives/rhsa-announce/2020-December/msg00044.html");\n\n script_tag(name:"summary", value:"The remote host is missing an update for the \'gd\'\n package(s) announced via the RHSA-2020:5443-01 advisory.");\n\n script_tag(name:"deprecated", value:TRUE);\n\nexit(0);\n}\n\nexit(66);\n' # noqa: E501
)
self.assertEqual(result, expected)

Expand Down
2 changes: 1 addition & 1 deletion tests/standalone_plugins/test_version_updated.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@
from troubadix.standalone_plugins.version_updated import (
check_version_updated,
git,
parse_args,
)
from troubadix.standalone_plugins.version_updated import main as plugin_main
from troubadix.standalone_plugins.version_updated import parse_args


@contextmanager
Expand Down
2 changes: 1 addition & 1 deletion tests/test_results.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@
import unittest
from pathlib import Path

from troubadix.plugin import LinterError, LinterWarning
from troubadix.results import FileResults
from troubadix.plugin import LinterWarning, LinterError


class TestResults(unittest.TestCase):
Expand Down
12 changes: 12 additions & 0 deletions troubadix/helper/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,15 @@

# js: can we get this to utf-8 in future @scanner @feed?
CURRENT_ENCODING = "latin1" # currently default

__all__ = [
"get_path_from_root",
"get_root",
"is_ignore_file",
"subprocess_cmd",
"ScriptTag",
"SpecialScriptTag",
"get_common_tag_patterns",
"get_script_tag_pattern",
"get_special_script_tag_pattern",
]
NiklasHargarter marked this conversation as resolved.
Show resolved Hide resolved
2 changes: 1 addition & 1 deletion troubadix/plugins/creation_date.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ def check_content(
):
return

if not "creation_date" in file_content:
if "creation_date" not in file_content:
yield LinterError(
"No creation date has been found.",
file=nasl_file,
Expand Down
Loading
Loading