Skip to content

Commit

Permalink
lint: Show dynamic description for WarnOnFunction config
Browse files Browse the repository at this point in the history
Fix #1075
  • Loading branch information
danigm committed Oct 18, 2023
1 parent 78f5077 commit dc4f431
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
7 changes: 7 additions & 0 deletions rpmlint/lint.py
Original file line number Diff line number Diff line change
Expand Up @@ -304,8 +304,15 @@ def print_explanation(self, messages, config):
"""
for message in messages:
explanation = self.output.get_description(message, config)
if not explanation:
# check if it's a WarnOnFunction warning configuration
forbidden_functions = config.configuration['WarnOnFunction']
if message in forbidden_functions:
explanation = forbidden_functions[message].get('description')

if not explanation:
explanation = 'Unknown message, please report a bug if the description should be present.\n\n'

print(f'{message}:\n{explanation}')

def load_checks(self):
Expand Down
21 changes: 21 additions & 0 deletions test/test_lint.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,27 @@ def test_explain_known(capsys):
assert not err


@pytest.mark.parametrize('configs', [
# Message defined in configs/Fedora/warn-on-functions.toml
(Path('configs/Fedora/warn-on-functions.toml'), False),
(Path('configs/Fedora/scoring.toml'), True),
])
def test_explain_known_warn_on_function(capsys, configs):
extraconfig, unknown = configs
message = ['crypto-policy-non-compliance-openssl']
additional_options = {
'explain': message,
'config': [extraconfig],
}
options = {**options_preset, **additional_options}
linter = Lint(options)
linter.run()
out, err = capsys.readouterr()

assert ('Unknown message' in out) == unknown
assert not err


def test_explain_with_unknown(capsys):
message = ['infopage-not-compressed', 'blablablabla']
additional_options = {
Expand Down

0 comments on commit dc4f431

Please sign in to comment.