-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #23 from sue445/fix_meaning_less_error
Fix `comparison of Integer with nil failed` in `YARD/MeaninglessTag`
- Loading branch information
Showing
4 changed files
with
67 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
{ | ||
"metadata": { | ||
"rubocop_version": "1.57.2", | ||
"ruby_engine": "ruby", | ||
"ruby_version": "3.2.2", | ||
"ruby_patchlevel": "53", | ||
"ruby_platform": "arm64-darwin22" | ||
}, | ||
"files": [ | ||
{ | ||
"path": "smoke/meaningless_tag_n_plus_one_query.rb", | ||
"offenses": [] | ||
} | ||
], | ||
"summary": { | ||
"offense_count": 0, | ||
"target_file_count": 1, | ||
"inspected_file_count": 1 | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
# Checks that there’s no N+1 query | ||
# | ||
# @note If `Database` isn't configured, auto-correct will not be available. (Only offense detection can be used) | ||
# | ||
# @note For the number of N+1 queries that can be detected by this cop, there are too few that can be corrected automatically | ||
# | ||
# @example | ||
# # bad | ||
# reservations = db.xquery('SELECT * FROM `reservations` WHERE `schedule_id` = ?', schedule_id).map do |reservation| | ||
# reservation[:user] = db.xquery('SELECT * FROM `users` WHERE `id` = ? LIMIT 1', id).first | ||
# reservation | ||
# end | ||
# | ||
# # good | ||
# rows = db.xquery(<<~SQL, schedule_id) | ||
# SELECT | ||
# r.id AS reservation_id, | ||
# r.schedule_id AS reservation_schedule_id, | ||
# r.user_id AS reservation_user_id, | ||
# r.created_at AS reservation_created_at, | ||
# u.id AS user_id, | ||
# u.email AS user_email, | ||
# u.nickname AS user_nickname, | ||
# u.staff AS user_staff, | ||
# u.created_at AS user_created_at | ||
# FROM `reservations` AS r | ||
# INNER JOIN users u ON u.id = r.user_id | ||
# WHERE r.schedule_id = ? | ||
# SQL | ||
# | ||
# # bad | ||
# courses.map do |course| | ||
# teacher = db.xquery('SELECT * FROM `users` WHERE `id` = ?', course[:teacher_id]).first | ||
# end | ||
# | ||
# # good | ||
# # This is similar to ActiveRecord's preload | ||
# # c.f. https://guides.rubyonrails.org/active_record_querying.html#preload | ||
# courses.map do |course| | ||
# @users_by_id ||= db.xquery('SELECT * FROM `users` WHERE `id` IN (?)', courses.map { |course| course[:teacher_id] }).each_with_object({}) { |v, hash| hash[v[:id]] = v } | ||
# teacher = @users_by_id[course[:teacher_id]] | ||
# end | ||
class NPlusOneQuery < Base | ||
end |