troubadix 24.9.4__py3-none-any.whl → 24.10.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
troubadix/__version__.py CHANGED
@@ -2,4 +2,4 @@
2
2
 
3
3
  # THIS IS AN AUTOGENERATED FILE. DO NOT TOUCH!
4
4
 
5
- __version__ = "24.9.4"
5
+ __version__ = "24.10.0"
@@ -18,6 +18,7 @@
18
18
  from typing import Iterable, List
19
19
 
20
20
  from troubadix.plugin import FilePlugin, FilesPlugin, Plugin
21
+ from troubadix.plugins.spaces_before_dots import CheckSpacesBeforeDots
21
22
 
22
23
  from .badwords import CheckBadwords
23
24
  from .copyright_text import CheckCopyrightText
@@ -140,6 +141,7 @@ _FILE_PLUGINS = [
140
141
  CheckVTFilePermissions,
141
142
  CheckVTPlacement,
142
143
  CheckWrongSetGetKBCalls,
144
+ CheckSpacesBeforeDots,
143
145
  ]
144
146
 
145
147
  # plugins checking all files
@@ -0,0 +1,130 @@
1
+ # SPDX-License-Identifier: GPL-3.0-or-later
2
+ # SPDX-FileCopyrightText: 2024 Greenbone AG
3
+ import re
4
+ from collections.abc import Iterator
5
+ from pathlib import Path
6
+
7
+ from troubadix.helper import CURRENT_ENCODING
8
+ from troubadix.helper.helper import is_ignore_file
9
+ from troubadix.helper.patterns import (
10
+ ScriptTag,
11
+ get_script_tag_pattern,
12
+ )
13
+ from troubadix.plugin import (
14
+ FileContentPlugin,
15
+ LinterFix,
16
+ LinterResult,
17
+ LinterWarning,
18
+ )
19
+
20
+ TAGS = [
21
+ ScriptTag.SUMMARY,
22
+ ScriptTag.VULDETECT,
23
+ ScriptTag.INSIGHT,
24
+ ScriptTag.IMPACT,
25
+ ScriptTag.AFFECTED,
26
+ ScriptTag.SOLUTION,
27
+ ]
28
+
29
+ # Regex pattern to match:
30
+ # 1. A dot preceded and/or followed by any whitespace character (floating between words)
31
+ # 2. A dot preceded by any whitespace character at the end of the string
32
+ PATTERN = re.compile(r"\s+\.(\s|$)")
33
+ IGNORE = [
34
+ # 21.04 and 22.04 are generated and should not be touched manually
35
+ "21.04/",
36
+ "22.04/",
37
+ # uses dots for beginning of entry in enumeration
38
+ "common/2008/debian/deb_246.nasl",
39
+ "common/2008/debian/deb_266.nasl",
40
+ "common/2008/freebsd/freebsd_5e92e8a2.nasl",
41
+ "common/2008/freebsd/freebsdsa_cpio.nasl",
42
+ "common/2008/freebsd/freebsdsa_cvs2.nasl",
43
+ "common/2009/osc_photoGallery_sql_injection.nasl",
44
+ "common/2009/secpod_novell_edir_mult_vuln_jul09_lin.nasl",
45
+ "common/2009/secpod_novell_edir_mult_vuln_jul09_win.nasl",
46
+ "common/2010/freebsd/freebsd_3a7c5fc4.nasl",
47
+ "common/2012/freebsd/freebsd_a4a809d8.nasl",
48
+ "common/2015/amazon/alas-2014-455.nasl",
49
+ "common/2015/gb_mozilla_firefox_mult_vuln01_mar15_macosx.nasl",
50
+ "common/2015/gb_mozilla_firefox_mult_vuln01_mar15_win.nasl",
51
+ "common/2015/oracle/ELSA-2009-1619.nasl",
52
+ "common/2015/oracle/ELSA-2011-0586.nasl",
53
+ "common/2016/gb_perl_privilege_escalation_vuln_win.nasl",
54
+ "common/2021/dropbear/gb_dropbear_ssh_filename_vuln_may20.nasl",
55
+ "common/2021/eclipse/gb_jetty_GHSA-v7ff-8wcx-gmc5_lin.nasl",
56
+ "common/2021/eclipse/gb_jetty_GHSA-v7ff-8wcx-gmc5_win.nasl",
57
+ "common/gsf/2009/mandriva/gb_mandriva_MDVSA_2008_140.nasl",
58
+ "common/gsf/2009/mandriva/gb_mandriva_MDVSA_2008_141.nasl",
59
+ "common/gsf/2010/mandriva/gb_mandriva_MDVA_2010_173.nasl",
60
+ "common/gsf/2010/mandriva/gb_mandriva_MDVSA_2010_155.nasl",
61
+ "common/gsf/2010/mandriva/gb_mandriva_MDVSA_2010_155_1.nasl",
62
+ "common/gsf/2010/mandriva/gb_mandriva_MDVSA_2010_167.nasl",
63
+ "common/gsf/2020/f5/gb_f5_big_ip_K11315080.nasl",
64
+ "common/gsf/2020/f5/gb_f5_big_iq_K11315080.nasl",
65
+ "common/2022/opensuse/gb_opensuse_2022_1548_1.nasl",
66
+ "common/2024/opensuse/gb_opensuse_2023_3247_1.nasl",
67
+ "common/attic/debian/deb_232_1.nasl",
68
+ ]
69
+
70
+
71
+ class CheckSpacesBeforeDots(FileContentPlugin):
72
+ name = "check_spaces_before_dots"
73
+
74
+ def check_content(
75
+ self, nasl_file: Path, file_content: str
76
+ ) -> Iterator[LinterResult]:
77
+ """
78
+ This plugin checks for excess whitespace before a dot
79
+ in script_tags that have full sentence values
80
+ """
81
+ self.matches = []
82
+ if nasl_file.suffix == ".inc" or is_ignore_file(nasl_file, IGNORE):
83
+ return
84
+ for tag in TAGS:
85
+ pattern = get_script_tag_pattern(tag)
86
+ match = pattern.search(file_content)
87
+ if not match:
88
+ continue
89
+
90
+ value = match.group("value")
91
+ value_start = match.start("value")
92
+
93
+ for excess_match in PATTERN.finditer(value):
94
+ whitespace_pos = excess_match.start() + value_start
95
+ self.matches.append((whitespace_pos, excess_match.group()))
96
+ fullmatch = match.group()
97
+ yield LinterWarning(
98
+ f"value of script_tag {match.group('name')} has at least"
99
+ " one occurence of excess whitespace before a dot:"
100
+ f"\n '{fullmatch}'",
101
+ file=nasl_file,
102
+ plugin=self.name,
103
+ )
104
+
105
+ def fix(self) -> Iterator[LinterResult]:
106
+
107
+ if not self.matches:
108
+ return
109
+
110
+ # Sort matches by position, descending order to avoid messing up indices during replacement
111
+ self.matches.sort(reverse=True)
112
+
113
+ file_content = self.context.file_content
114
+ for pos, match_str in self.matches:
115
+ # Replace the match by removing the excess whitespace before the dot
116
+ fixed_str = re.sub(r"\s+\.", ".", match_str)
117
+ file_content = (
118
+ file_content[:pos]
119
+ + fixed_str
120
+ + file_content[pos + len(match_str) :]
121
+ )
122
+
123
+ with open(self.context.nasl_file, "w", encoding=CURRENT_ENCODING) as f:
124
+ f.write(file_content)
125
+
126
+ yield LinterFix(
127
+ "Excess spaces were removed",
128
+ file=self.context.nasl_file,
129
+ plugin=self.name,
130
+ )
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: troubadix
3
- Version: 24.9.4
3
+ Version: 24.10.0
4
4
  Summary: A linting and QA check tool for NASL files
5
5
  Home-page: https://github.com/greenbone/troubadix
6
6
  License: GPL-3.0-or-later
@@ -1,5 +1,5 @@
1
1
  troubadix/__init__.py,sha256=K7sIXXDrC7YRb7BvIpdQ6ZfG_QkT0qUH_wAlHROVRfM,716
2
- troubadix/__version__.py,sha256=fCgh5yBoJNHBzdwMZ24n51N50H4g6MWpbLRDcZoIaZw,103
2
+ troubadix/__version__.py,sha256=8b1wMGC6uMDMfZhzI8Kjts-f3LbyZAKp11yRbn2eB-k,104
3
3
  troubadix/argparser.py,sha256=YAo8cGJt0k2GMICXrDj3Z124GrM8oRwgNm2Bn3J_gYI,7001
4
4
  troubadix/codespell/codespell.additions,sha256=OaHe66OE0Yx4VTkhIeITZqB7_ERiv0fsDnpikGUgZ-Q,488
5
5
  troubadix/codespell/codespell.exclude,sha256=6HEOtHrMBBdm4E4794W4g1H9nmGLlYbgZpQiJzKio-A,139033
@@ -9,7 +9,7 @@ troubadix/helper/helper.py,sha256=GXapYLii2rLKwkX2ok31YoAdUSizBnyPjWz-aPP6HM8,31
9
9
  troubadix/helper/linguistic_exception_handler.py,sha256=Bq7ULjDdWTKUpFNTUX6XMPdD4s4v8eIjZPyqBe8VLws,6811
10
10
  troubadix/helper/patterns.py,sha256=_ifRnwHsPee9B0yRYSCsyFms4StWVWJq7I9YnQwToa8,9174
11
11
  troubadix/plugin.py,sha256=3fQPj3Qe_hgwHerlYE4hbdzYMzRU557NxJ-UwtE9mOI,3525
12
- troubadix/plugins/__init__.py,sha256=McIt4ZDPLmFxr0WMi8FmRoV-bDLXxSP-6JbrYKR1RHc,7413
12
+ troubadix/plugins/__init__.py,sha256=V5fHMg2qVWIYKVZJqHKpzgrQ5x87Pz5u-h-CxOx7Dls,7511
13
13
  troubadix/plugins/badwords.py,sha256=C5Vuq6rzyeQkbEsg4t9ui9K05nQAh3Xy93sqV9K7aNw,4603
14
14
  troubadix/plugins/copyright_text.py,sha256=jYsLWmTbT_A78XQQxQFK-5kMMHkh3xdvlh7mEF2dZGU,3583
15
15
  troubadix/plugins/copyright_year.py,sha256=XzM9MHVzOXwNLwHpfuaWj8PUOmswr56SBVOLBdvxjd4,5478
@@ -57,6 +57,7 @@ troubadix/plugins/security_messages.py,sha256=EPu3-YB0iP5_hfbQjrfvvTrQRiPgDjC85G
57
57
  troubadix/plugins/set_get_kb_calls.py,sha256=WGu1CKLjn3VhbDo33IJ4TtWQ-kz9gInkJskTqOSMM6k,3415
58
58
  troubadix/plugins/solution_text.py,sha256=4Gs84Qsyg-1iTDP7Y7o8Bo5AH4hKlwGPW0NfwMpx2fU,5852
59
59
  troubadix/plugins/solution_type.py,sha256=6wq7lj0bCL6tTaZ-d_aGKq6a_jVlCD73GltHJsJhmm8,2602
60
+ troubadix/plugins/spaces_before_dots.py,sha256=83bVH4dxJPsNyd53kEX8fnDEge9R6kjAHdOnrDB7L9w,4852
60
61
  troubadix/plugins/spaces_in_filename.py,sha256=v8OqzzZSeI4_iXATHYzkf-HoAMxc_xb2Nj0HPAVevpk,611
61
62
  troubadix/plugins/spelling.py,sha256=3AW5sNtLL67OthKLaCH_y2HCVJ5YH_eyF9xjTJMIDG4,9593
62
63
  troubadix/plugins/tabs.py,sha256=7zXaTZe4cZoZvrLyqntVfTeNN_W3D8dfQl67QevXxtc,1319
@@ -92,8 +93,8 @@ troubadix/standalone_plugins/last_modification.py,sha256=oYzQq7xV3YzSvi6ZtuHuupX
92
93
  troubadix/standalone_plugins/no_solution.py,sha256=81r20kP8otRob2NTaCea-sgVRIM6ARvhddFdibsG6Ao,8877
93
94
  troubadix/standalone_plugins/version_updated.py,sha256=RlzVuXgFOvcjrRTOhiTYlmzV4vvcn7ntCz0lDTjePMU,4316
94
95
  troubadix/troubadix.py,sha256=foA7Loi67cCKieN3ea4s3QOfOWOkgwQVR1H-pNXtXn0,6041
95
- troubadix-24.9.4.dist-info/LICENSE,sha256=OXLcl0T2SZ8Pmy2_dmlvKuetivmyPd5m1q-Gyd-zaYY,35149
96
- troubadix-24.9.4.dist-info/METADATA,sha256=cy8Uc-BwHeiZuQABZkS1O_OmFEvFlSg7OG5pvAbvgLk,4357
97
- troubadix-24.9.4.dist-info/WHEEL,sha256=sP946D7jFCHeNz5Iq4fL4Lu-PrWrFsgfLXbbkciIZwg,88
98
- troubadix-24.9.4.dist-info/entry_points.txt,sha256=LplOk4nzKrS4B8Jz0SPkQLPlIDesdraCO8Vp_eoycpc,737
99
- troubadix-24.9.4.dist-info/RECORD,,
96
+ troubadix-24.10.0.dist-info/LICENSE,sha256=OXLcl0T2SZ8Pmy2_dmlvKuetivmyPd5m1q-Gyd-zaYY,35149
97
+ troubadix-24.10.0.dist-info/METADATA,sha256=ESGsxnzuTpGa1qOgnPV3mcwQUTpFmZiEWb-ph2H3CN0,4358
98
+ troubadix-24.10.0.dist-info/WHEEL,sha256=sP946D7jFCHeNz5Iq4fL4Lu-PrWrFsgfLXbbkciIZwg,88
99
+ troubadix-24.10.0.dist-info/entry_points.txt,sha256=LplOk4nzKrS4B8Jz0SPkQLPlIDesdraCO8Vp_eoycpc,737
100
+ troubadix-24.10.0.dist-info/RECORD,,