Closed stsmrvestas closed 5 months ago
Hello, @stsmrvestas! Thanks for reaching out!
The error message you are seeing here actually comes from our YAML parser. Because of the YAML syntax, our parser (correctly) interprets the line pattern: class ${klass}:
as if you were building a nested dictionary {"pattern": {"class ${klass}": ""}}
. Strange, right?
To fix this, you can use a multiline YAML string:
rules:
- id: service-class-naming
description: Service class naming convention
pattern: |
class ${klass}(...):
...
condition: not klass.ends_with("Service")
explanation: 'Service classes must be postfixed with "Service" - if you have additional classes in the same file, please move them to a separate file'
I have also fixed the Sourcery pattern syntax for you by using the universal matcher ...
and simplified the matching condition by using the ends_with
conditional, which (I think?) is what your rule is about.
Please let me know if this does (or does not) work for you.
Thanks - that works. I think I was thrown by a couple of things:
class SomeClass: # no parenthesis
...
but even with your proposal, the above example actually works and detects that SomeClass does not end with Service even though it doesn't strictly match the 'class ${klass}(...):' pattern which has the parenthesis. This last thing is what I want, but it is not clear why it actually works, and I would never have guess this?
Anyways thanks for the assistance!
Checklist
Description
I'm new, so apologies if this is a user error, however I'm getting this error from a pattern, which looks almost identical to what you have in your docs afaict. It is complaining when attempting review from CLI:
Code snippet that reproduces issue
Debug Information
IDE Version: PyCharm 2023.3.1 (Professional Edition)
Sourcery Version: sourcery, version 1.15.0
Operating system and Version: OSX Sonoma 14.2.1 (23C71)