Skip to content
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

Allow ignore offences using .isolator_todo.yml #13

Merged
merged 1 commit into from
Jun 15, 2018
Merged

Allow ignore offences using .isolator_todo.yml #13

merged 1 commit into from
Jun 15, 2018

Conversation

DmitryTsepelev
Copy link
Contributor

@DmitryTsepelev DmitryTsepelev commented Mar 19, 2018

I'm trying to use Isolator on my current project and found the place where Sidekiq job is initiated from the after_save. I'm planning to fix it a bit later, so I'd like to silence the offence caused by the exact line, for instance: Isolator.adapters.sidekiq.ignore_at("app/models/user.rb:48")

@palkan
Copy link
Owner

palkan commented Mar 20, 2018

Thanks for contribution!

I got the idea, that make sense. But I'm not sure the implementation is flexible enough and easy to use.
What about having a separate .isolator.yml to keep all this ignores? Just like .rubocop.yml.

Thus it would be easy to keep a TODO list for Isolator; and do not touch the codebase.

I mean something like that:

# .isolator_todo.yml
# name of the adapter
sidekiq:
  - app/models/user.rb:48
  # masks support too
  - app/models/**/*.rb

That would require a more complex ignore_if handler than caller.join.include?(path), but from the other hand that would be more flexible.

What do you think?

@DmitryTsepelev
Copy link
Contributor Author

That was my plan for the next PR :) Will come up with solution in a couple of days

@DmitryTsepelev DmitryTsepelev changed the title Add ignore_at modifier Allow ignore offences using .isolator_todo.yml May 24, 2018
@DmitryTsepelev
Copy link
Contributor Author

It took a bit longer then I've expected, but I think I'm done with the very basic implementation. It seems to pass specs, but there are some space for improvements:

  • I'm not sure if the way I define ignore_if rules is covering all the possible cases
  • also, is isolate.rb a right place to define such things?
  • there are no any checks for the rules in the file (e.g. it's possible to specify the mask AND the line number)
  • the spec is a bit brittle, because I had to hardcode ignored lines

@palkan could you please review and let me know if I'm thinking in the right direction? Thanks

Copy link
Owner

@palkan palkan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great work!

Let's refactor it a little bit and make Rails-free, and we're done.


def ignore_in_files(adapter, ignored_files)
adapter.ignore_if do
caller_paths = caller.map { |row| row.split(":in").first }
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about using Regex here (build from ignore pattern) to avoid splitting?

Then we could build the same ignore_if block for both exact lines and masks.

def isolate(id, **options)
raise "Adapter already registered: #{id}" if Isolator.adapters.key?(id.to_s)
adapter = AdapterBuilder.call(options)
register_todos(id.to_s, adapter) if isolator_todos
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about extracting all the ignoring logic into a separate module? And then:

Ignorer.configure(adapter)

end

def ignore_line(adapter, line)
full_line = Rails.root.join(line).to_s
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We cannot use Rails here, Isolator is not Rails-specific.

Looks like we need a way to specify the path to the configuration somehow, e.g. Isolator.load_ingore_config "./.isolator_blabla.yml".

That also means that we cannot apply ignores within isolate method, since it's called when gem is loading.

So, we should configure all the ignores in a separate step (we can access existing adapters through Isolator.adapters).

To make it easier to use with Rails we can add a Railtie with an initializer to load configuration form Rails.root.join(TODO_CONFIG_PATH).

@DmitryTsepelev
Copy link
Contributor Author

Thanks for the review! I think I've addressed all the issues, please let me know if I'm using the proper place to load the config for Rails app

@DmitryTsepelev
Copy link
Contributor Author

@palkan pinging again, probably there were no notification since I haven't mentioned you in the previous comment :)

Copy link
Owner

@palkan palkan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good!

Thanks!

Let's add a changelog entry and update the docs, and we're done!

README.md Outdated
@@ -145,6 +145,17 @@ Isolator.adapters.sidekiq.ignore_if { Thread.current[:sidekiq_postpone] }

You can add as many _ignores_ as you want, the offense is registered iff all of them return false.

### Using with legacy codebases
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's split the instructions into two parts: "Using with Rails" and "Using with Ruby".

We need an example on how to use ignore config in non-Rails apps too.

README.md Outdated

```
sidekiq:
- app/models/user.rb:20
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's add a wildcard example too (i.e. app/models/somthing/**/*.rb)

@DmitryTsepelev
Copy link
Contributor Author

@palkan I think I'm done

@palkan palkan merged commit d3a27ff into palkan:master Jun 15, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants