Git Product home page Git Product logo

Comments (2)

ruancomelli avatar ruancomelli commented on June 21, 2024

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.

from sourcery.

stsmrvestas avatar stsmrvestas commented on June 21, 2024

Thanks - that works.
I think I was thrown by a couple of things:

  1. I need to include the '...' aka class body - it is not sufficient to simply do a single line even if I don't care about the body of the class - that's prolly how it has to be, but not 100% intuitive..
  2. the tests also needs to follow the same rule (class body required)
  3. Your suggestion doesn't take into appear to take into account when the classes are like this:
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!

from sourcery.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.