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

Adds support to print info for multiple files. #83

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

mateusdeap
Copy link
Member

Description

This is a bit of a 2 for 1:

  1. It adds a new option, --path, so that we can provide a custom path to our deprecation files.
  2. With this option we can also give the deprecations command a file glob. That way it will print out information on the deprecation warnings present in all the files that match that glob.

And that's basically it.

Motivation and Context

The motivation is given on the issue it fixes. Fixes #3.

How Has This Been Tested?

Manually on the command line since the info command is entirely contained in the exe/deprecations script.

I will abide by the code of conduct

@mateusdeap mateusdeap requested a review from a team as a code owner February 10, 2023 19:53
@mateusdeap mateusdeap requested review from ashwinisukale, KostiantynPopovych, arielj and etagwerker and removed request for a team and KostiantynPopovych February 10, 2023 19:53
Comment on lines +86 to +88
opts.on("--path PATH_OR_FILE_GLOB", "Path to deprecation shitlist or glob for multiple files") do |path|
options[:path] = path
end
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think we should put the use of this option in Readme as well.

Copy link
Member

Choose a reason for hiding this comment

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

+1

Comment on lines +114 to +115
deprecation_warnings = file_paths.map { |path| extract_deprecations(path, pattern) }
.inject(:merge)
Copy link
Collaborator

Choose a reason for hiding this comment

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

the inject(:merge) logic does not work well with more than 2 files.
I did this:

  1. created a folder dep_test and added 3 files dep1.json, dep2.json, and dep3.json.

dep1.json

{
  "./spec/controllers/contacts_controller_spec.rb": [
    "DEPRECATION WARNING: dep1",
    "DEPRECATION WARNING: dep1"
  ],
  "./spec/controllers/search_controller_spec.rb": [
    "DEPRECATION WARNING: dep2",
    "DEPRECATION WARNING: dep2",
    "DEPRECATION WARNING: dep2"
  ]
}

dep2.json

{
  "./spec/controllers/search_controller_spec.rb": [ 
    "DEPRECATION WARNING: dep3",
    "DEPRECATION WARNING: dep3"
  ]
}

dep3.json

{
  "./spec/controllers/contacts_controller_spec.rb": [
    "DEPRECATION WARNING: dep4"
  ],
  "./spec/controllers/search_controller_spec.rb": [
    "DEPRECATION WARNING: dep3",
    "DEPRECATION WARNING: dep2",
    "DEPRECATION WARNING: dep2"
  ]
}

Now I run this command

exe/deprecations info --path "/home/rishi/projects/next_rails/dep_test/*"

I get this output

Ten most common deprecation warnings:
Occurrences: 3
DEPRECATION WARNING: dep2
----------
Occurrences: 2
DEPRECATION WARNING: dep1
----------

You can see it ignored the deprecation warning dep4 and dep3 completely.

I tried to debug this and figured out that the inject is not working as expected.
I did something like this (it could be made better for sure):

extracted_deprecation_warnings = file_paths.map { |path| extract_deprecations(path, pattern) }

  deprecation_warnings = {}
  extracted_deprecation_warnings.each do |a|
    a.keys.each do |h|
      if deprecation_warnings[h]
        deprecation_warnings[h] << a[h].flatten
        deprecation_warnings[h].flatten!
      else
        deprecation_warnings[h] = a[h].flatten
      end
    end
  end

  deprecation_warnings

and this returns

rishi@rishi:~/projects/next_rails$ exe/deprecations info --path "/home/rishi/projects/next_rails/dep_test/*"
Ten most common deprecation warnings:
Occurrences: 5
DEPRECATION WARNING: dep2
----------
Occurrences: 3
DEPRECATION WARNING: dep3
----------
Occurrences: 2
DEPRECATION WARNING: dep1
----------
Occurrences: 1
DEPRECATION WARNING: dep4
----------

Copy link
Collaborator

Choose a reason for hiding this comment

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

I have not tested my suggested code with all possible scenario. I was just trying to suggest an example for you to play with if it seems correct to you.

Copy link
Member

Choose a reason for hiding this comment

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

This would be an interesting test case to be added to the test suite.

@rishijain
Copy link
Collaborator

@mateusdeap
While I think issue #3 was asking for a way to merge multiple shitlist json files, I think this is a good step in that direction.
Since we have the deprecations from all the json files in one place now, we can certainly create a new merge mode which will create a new json file with results merged from shitlist files.

Let me know if I am understanding this all a bit differently.

Copy link
Member

@etagwerker etagwerker left a comment

Choose a reason for hiding this comment

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

@mateusdeap Thanks for taking the time to submit this! ❤️

I agree with the comments by @rishijain.

Additionally, I would like to see most of this code moved to a file/s under the lib directory.

Considering you are adding behavior, we need to have a test case to verify that it does what it is supposed to be doing. This will save us time in the long run.

I know that it's a little beyond the scope of this PR, but I think we should not have all that code in the exe/deprecations file as it makes it hard to test with our test suite.

Comment on lines +114 to +115
deprecation_warnings = file_paths.map { |path| extract_deprecations(path, pattern) }
.inject(:merge)
Copy link
Member

Choose a reason for hiding this comment

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

This would be an interesting test case to be added to the test suite.

Comment on lines +86 to +88
opts.on("--path PATH_OR_FILE_GLOB", "Path to deprecation shitlist or glob for multiple files") do |path|
options[:path] = path
end
Copy link
Member

Choose a reason for hiding this comment

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

+1

@mateusdeap
Copy link
Member Author

@etagwerker @rishijain Sorry for the late response. I'll later try to address all of these comments

@etagwerker
Copy link
Member

@mateusdeap Sounds good, thank you!

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.

Merge multiple shitlist.json files into one?
3 participants