-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add: Add plugin for spaces in filenames
- Loading branch information
1 parent
33c4021
commit b12552b
Showing
3 changed files
with
50 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
# SPDX-License-Identifier: GPL-3.0-or-later | ||
# SPDX-FileCopyrightText: 2024 Greenbone AG | ||
|
||
from pathlib import Path | ||
|
||
from tests.plugins import PluginTestCase | ||
from troubadix.plugin import LinterError | ||
from troubadix.plugins.spaces_in_filename import CheckSpacesInFilename | ||
|
||
|
||
class TestSpacesInFilename(PluginTestCase): | ||
def test_ok(self): | ||
nasl_file = Path(__file__).parent / "foo.nasl" | ||
fake_context = self.create_file_plugin_context(nasl_file=nasl_file) | ||
plugin = CheckSpacesInFilename(fake_context) | ||
results = list(plugin.run()) | ||
self.assertEqual(len(results), 0) | ||
|
||
def test_fail(self): | ||
nasl_file = Path(__file__).parent / "foo bar.nasl" | ||
fake_context = self.create_file_plugin_context(nasl_file=nasl_file) | ||
plugin = CheckSpacesInFilename(fake_context) | ||
results = list(plugin.run()) | ||
self.assertEqual(len(results), 1) | ||
self.assertIsInstance(results[0], LinterError) | ||
self.assertEqual( | ||
results[0].message, | ||
f"The VT {nasl_file} contains spaces in the filename", | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
# SPDX-License-Identifier: GPL-3.0-or-later | ||
# SPDX-FileCopyrightText: 2024 Greenbone AG | ||
|
||
from typing import Iterator | ||
|
||
from troubadix.plugin import FilePlugin, LinterError, LinterResult | ||
|
||
|
||
class CheckSpacesInFilename(FilePlugin): | ||
name = "check_spaces_in_filename" | ||
|
||
def run(self) -> Iterator[LinterResult]: | ||
if " " in self.context.nasl_file.name: | ||
yield LinterError( | ||
f"The VT {self.context.nasl_file}" | ||
" contains spaces in the filename", | ||
file=self.context.nasl_file, | ||
plugin=self.name, | ||
) |