New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
API for reek v3: The first proposal #526
Comments
I like it in general, but I’m unsure about exposing all of the I’d consider wrapping the API calls in thin require 'reek/api'
reporter = Reek::API.reporter(:text)
examiner = Reek::API.examiner_for(source)
reporter.examiners << examiner
puts reporter.show Eventually we should probably consider using core Ruby object types ( report = Reek::API.report(source: source,
reporter: :text,
smells: %i(attribute data_clump nil_check),
config: config) # a path to a YAML file or a Hash
puts report.show |
I like the idea of just exposing a set of methods on Reek or Reek::API to create objects that may change names in the future. We should also determine the set of documented methods on Examiner. Lookin at pronto-reek, I agree that making the configuration injectable can be a next step. |
Good idea! |
I'd rather not have Reek::API but just requiring "reek/api" that sets up an Examiner. |
Ok, but let’s |
Please make it so that source can also be an AST :) |
Good idea @guilhermesimoes ! |
I've always found these options for source a bit confusing, especially how a string is interpreted as code but the array as list of file names. Internally, we only ever pass a single SourceCode object. How about allowing a single piece of source only, which can be:
What do you think? |
Yes, 👍 for that. The array option is confusing. |
Allowing an AST will be for a future, backwards-compatible, update to the API. |
I've considered this kind of setup:
However, I feel this ties together too much at the moment. I prefer exposing just the two pieces: examiner and report. I like @chastell's version with wrapper methods. Perhaps like so:
However, we will still be exposing |
I’m still not sure why the users need to be concerned with the fact that we have reporters and examiners. They want a report for their source – what we use internally shouldn’t leak outside. I don’t mind people providing their own examiners if that’s a use-case we want to support, but as an option with a good default, not a required step of obtaining a report for the given source. The problem is, of course, which parts should be easily tweakable (smells? config?) and how. :) |
Some of our users don't need a report, they just need the smells. |
Good point, and we should expose them – but we should expose them in a way that is as generic as possible, so a |
I think the question is if we're exposing a shrink-wrapped API for external users, or we're just exposing a cleaned-up version of what we use internally. The implementation I made is definitely of the latter kind. The former type of API will require a lot more thought:
Also, such an API requires more maintenance, since we may not be using the API ourselves. For our internal use, I like the split between examiner (finds certain smells in a source) and report (displays found smells in a nice way). I'm not against a more cleaned-up API that exposes less internals, but I think we should first get some experience with how the current classes are used before settling on a design. |
Ok, I agree on the reasoning and step-by-step approach. Let’s go with exposing (and maintaing) our more internal API in |
👍 |
👍 |
Merged, closing this. |
I thought about our future API for reek 3. I believe that this: https://github.com/troessner/reek/blob/develop/docs/API.md is already a good start.
What I had in mind:
[1] Getting started
Set up
This will make available:
Usage
1.) Create a reporter. Can be:
2.) Create an examiner:
where
source
can be a File, a string or an array (so basically like it is right now)3.) Add the examiner to the reporter:
4.) Print the result:
Exposed API methods:
Necessary changes
Spec API
Our spec matchers described here should stay like they are.
[2] Outlook
In the next step I would add a none breaking change that
1.) exposes our AppConfiguration
2.) exposes our SmellRepository
3.) makes the API more convenient to use like this:
This would obviously be a lot harder than [1] since AppConfiguration would be settable on an examiner base. So I'd like to go with [1] to keep things easy and get to a stable version quick and then put out [2] as an add-on.
What do you guys think?
The text was updated successfully, but these errors were encountered: