timezone_default.rb 813 B

12345678910111213141516171819202122232425262728293031
  1. # Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
  2. module RuboCop
  3. module Cop
  4. module Zammad
  5. class TimezoneDefault < Base
  6. def on_str(node)
  7. return if !matching_string?(node)
  8. return if !matching_node?(node)
  9. add_offense(node.parent, message: <<~TEXT.chomp)
  10. Setting.get('timezone_default_sanitized') is removed.
  11. Please use Setting.get('timezone_default') directly.
  12. TEXT
  13. end
  14. def matching_string?(node)
  15. node.source == "'timezone_default_sanitized'"
  16. end
  17. def matching_node?(node)
  18. parent = node.parent
  19. return false if !parent
  20. parent.receiver&.const_name == 'Setting' && parent.method_name == :get
  21. end
  22. end
  23. end
  24. end
  25. end