Skip to content

Commit

Permalink
chore: setup rubocop properly
Browse files Browse the repository at this point in the history
  • Loading branch information
crazyoptimist committed Oct 29, 2023
1 parent 4d54b58 commit 92c099c
Show file tree
Hide file tree
Showing 9 changed files with 230 additions and 68 deletions.
1 change: 1 addition & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
inherit_from: .rubocop_todo.yml
165 changes: 165 additions & 0 deletions .rubocop_todo.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,165 @@
# This configuration was generated by
# `rubocop --auto-gen-config`
# on 2023-10-29 21:02:33 UTC using RuboCop version 1.31.2.
# The point is for the user to remove these configuration records
# one by one as the offenses are removed from the code base.
# Note that changes in the inspected code, or installation of new
# versions of RuboCop, may require this file to be generated again.

# Offense count: 6
# This cop supports safe autocorrection (--autocorrect).
Layout/EmptyLineAfterGuardClause:
Exclude:
- 'bin/bundle'

# Offense count: 1
# This cop supports safe autocorrection (--autocorrect).
Layout/EmptyLines:
Exclude:
- 'config/environments/development.rb'

# Offense count: 1
# This cop supports safe autocorrection (--autocorrect).
# Configuration parameters: AllowForAlignment, AllowBeforeTrailingComments, ForceEqualSignAlignment.
Layout/ExtraSpacing:
Exclude:
- 'config/environments/production.rb'

# Offense count: 1
# This cop supports safe autocorrection (--autocorrect).
# Configuration parameters: EnforcedStyle, IndentationWidth.
# SupportedStyles: aligned, indented
Layout/MultilineOperationIndentation:
Exclude:
- 'bin/bundle'

# Offense count: 1
# This cop supports safe autocorrection (--autocorrect).
# Configuration parameters: AllowForAlignment, EnforcedStyleForExponentOperator.
# SupportedStylesForExponentOperator: space, no_space
Layout/SpaceAroundOperators:
Exclude:
- 'config/environments/production.rb'

# Offense count: 2
# This cop supports safe autocorrection (--autocorrect).
# Configuration parameters: EnforcedStyle, EnforcedStyleForEmptyBrackets.
# SupportedStyles: space, no_space, compact
# SupportedStylesForEmptyBrackets: space, no_space
Layout/SpaceInsideArrayLiteralBrackets:
Exclude:
- 'config/environments/production.rb'

# Offense count: 2
Lint/UselessAssignment:
Exclude:
- 'bot/actions/modal.rb'

# Offense count: 1
# Configuration parameters: IgnoredMethods.
Metrics/CyclomaticComplexity:
Max: 9

# Offense count: 3
# Configuration parameters: CountComments, CountAsOne, ExcludedMethods, IgnoredMethods.
Metrics/MethodLength:
Max: 62

# Offense count: 1
# Configuration parameters: IgnoredMethods.
Metrics/PerceivedComplexity:
Max: 9

# Offense count: 1
# This cop supports unsafe autocorrection (--autocorrect-all).
Style/CaseLikeIf:
Exclude:
- 'bot/actions/quiz.rb'

# Offense count: 2
# Configuration parameters: AllowedConstants.
Style/Documentation:
Exclude:
- 'spec/**/*'
- 'test/**/*'
- 'app/models/application_record.rb'
- 'config/application.rb'

# Offense count: 1
# This cop supports safe autocorrection (--autocorrect).
Style/ExpandPathArguments:
Exclude:
- 'bin/bundle'

# Offense count: 44
# This cop supports unsafe autocorrection (--autocorrect-all).
# Configuration parameters: EnforcedStyle.
# SupportedStyles: always, always_true, never
Style/FrozenStringLiteralComment:
Enabled: false

# Offense count: 1
# This cop supports unsafe autocorrection (--autocorrect-all).
Style/GlobalStdStream:
Exclude:
- 'config/environments/production.rb'

# Offense count: 2
# This cop supports safe autocorrection (--autocorrect).
Style/IfUnlessModifier:
Exclude:
- 'bin/bundle'

# Offense count: 1
# This cop supports safe autocorrection (--autocorrect).
Style/PerlBackrefs:
Exclude:
- 'bin/bundle'

# Offense count: 2
# This cop supports unsafe autocorrection (--autocorrect-all).
# Configuration parameters: SafeForConstants.
Style/RedundantFetchBlock:
Exclude:
- 'config/puma.rb'

# Offense count: 1
# This cop supports unsafe autocorrection (--autocorrect-all).
# Configuration parameters: RequireEnglish.
# SupportedStyles: use_perl_names, use_english_names, use_builtin_english_names
Style/SpecialGlobalVars:
EnforcedStyle: use_perl_names

# Offense count: 61
# This cop supports safe autocorrection (--autocorrect).
# Configuration parameters: EnforcedStyle, ConsistentQuotesInMultiline.
# SupportedStyles: single_quotes, double_quotes
Style/StringLiterals:
Exclude:
- 'bin/bundle'
- 'bin/rails'
- 'bin/rake'
- 'bin/setup'
- 'config/application.rb'
- 'config/boot.rb'
- 'config/environment.rb'
- 'config/environments/development.rb'
- 'config/environments/production.rb'
- 'config/environments/test.rb'
- 'config/puma.rb'
- 'config/spring.rb'

# Offense count: 1
# This cop supports safe autocorrection (--autocorrect).
# Configuration parameters: .
# SupportedStyles: percent, brackets
Style/SymbolArray:
EnforcedStyle: percent
MinSize: 10

# Offense count: 2
# This cop supports safe autocorrection (--autocorrect).
# Configuration parameters: AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives, AllowedPatterns, IgnoredPatterns.
# URISchemes: http, https
Layout/LineLength:
Max: 198
6 changes: 3 additions & 3 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,15 @@ gem 'bootsnap', '>= 1.15.0', require: false

gem 'activerecord', '~> 7.0.4', require: 'active_record'
gem 'otr-activerecord'
gem 'pg'
gem 'pagy_cursor'
gem 'pg'

gem 'slack-ruby-bot-server-events'

group :development, :test do
# Call 'byebug' anywhere in the code to stop execution and get a debugger console
gem 'byebug', platforms: [:mri, :mingw, :x64_mingw]
gem 'byebug', platforms: %i[mri mingw x64_mingw]
gem 'rubocop', '1.31.2', require: false
end

group :development do
Expand All @@ -43,4 +44,3 @@ end

# Windows does not include zoneinfo files, so bundle the tzinfo-data gem
# gem 'tzinfo-data', platforms: [:mingw, :mswin, :x64_mingw, :jruby]
gem 'rubocop', require: false
15 changes: 6 additions & 9 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,6 @@ GEM
kaminari-grape (1.0.1)
grape
kaminari-core (~> 1.0)
language_server-protocol (3.17.0.3)
listen (3.8.0)
rb-fsevent (~> 0.10, >= 0.10.3)
rb-inotify (~> 0.9, >= 0.9.10)
Expand Down Expand Up @@ -247,19 +246,17 @@ GEM
rexml (3.2.6)
roar (1.1.1)
representable (~> 3.0)
rubocop (1.57.1)
base64 (~> 0.1.1)
rubocop (1.31.2)
json (~> 2.3)
language_server-protocol (>= 3.17.0)
parallel (~> 1.10)
parser (>= 3.2.2.4)
parser (>= 3.1.0.0)
rainbow (>= 2.2.2, < 4.0)
regexp_parser (>= 1.8, < 3.0)
rexml (>= 3.2.5, < 4.0)
rubocop-ast (>= 1.28.1, < 2.0)
rubocop-ast (>= 1.18.0, < 2.0)
ruby-progressbar (~> 1.7)
unicode-display_width (>= 2.4.0, < 3.0)
rubocop-ast (1.29.0)
unicode-display_width (>= 1.4.0, < 3.0)
rubocop-ast (1.30.0)
parser (>= 3.2.1.0)
ruby-progressbar (1.13.0)
ruby2_keywords (0.0.5)
Expand Down Expand Up @@ -314,7 +311,7 @@ DEPENDENCIES
pg
puma (~> 6.0.1)
rails (~> 7.0.5)
rubocop
rubocop (= 1.31.2)
slack-ruby-bot-server-events
spring
spring-watcher-listen (~> 2.0.0)
Expand Down
10 changes: 5 additions & 5 deletions bot/actions/modal.rb
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
SlackRubyBotServer::Events.configure do |config|
config.on :action, 'view_submission' do |action|
payload = action[:payload]
team_id = payload["team"]["id"]
username = payload["user"]["username"]
trigger_id = payload["trigger_id"]
team_id = payload['team']['id']
username = payload['user']['username']
trigger_id = payload['trigger_id']
action.logger.info "User #{username} has submitted a demo modal form"
team = Team.find_by(team_id: team_id)
team = Team.find_by(team_id:)
slack_client = Slack::Web::Client.new(token: team.token)
form_values = payload["view"]["state"]["values"]
form_values = payload['view']['state']['values']
p form_values
nil
end
Expand Down
12 changes: 6 additions & 6 deletions bot/actions/quiz.rb
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
SlackRubyBotServer::Events.configure do |config|
config.on :action, 'block_actions' do |action|
payload = action[:payload]
action_id = payload["actions"][0]["action_id"]
channel_id = payload["channel"]["id"]
team_id = payload["team"]["id"]
action_id = payload['actions'][0]['action_id']
channel_id = payload['channel']['id']
team_id = payload['team']['id']
action.logger.info "Action #{action_id} has been processed in channel #{channel_id}"
team = Team.find_by(team_id: team_id)
team = Team.find_by(team_id:)
slack_client = Slack::Web::Client.new(token: team.token)
if action_id == 'reply_yes'
slack_client.chat_postMessage(channel: channel_id, text: "Great! I also think so! :thumbsup:")
slack_client.chat_postMessage(channel: channel_id, text: 'Great! I also think so! :thumbsup:')
elsif action_id == 'reply_no'
slack_client.chat_postMessage(channel: channel_id, text: "Oops! Try to google it... :thumbsdown:")
slack_client.chat_postMessage(channel: channel_id, text: 'Oops! Try to google it... :thumbsdown:')
end
# Do not send text message any more
nil
Expand Down
1 change: 0 additions & 1 deletion bot/events/default.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

SlackRubyBotServer::Events.configure do |config|
config.on :event do |event|
event.logger.info "Received #{event[:type]}, #{event[:event][:type]}."
Expand Down
56 changes: 28 additions & 28 deletions bot/slash_commands/modal.rb
Original file line number Diff line number Diff line change
@@ -1,61 +1,61 @@
def modal_payload(trigger_id)
{
trigger_id: trigger_id,
trigger_id:,
view: {
type: "modal",
type: 'modal',
title: {
type: "plain_text",
text: "Demo Modal Form",
type: 'plain_text',
text: 'Demo Modal Form',
emoji: true
},
submit: {
type: "plain_text",
text: "Submit",
type: 'plain_text',
text: 'Submit',
emoji: true
},
close: {
type: "plain_text",
text: "Cancel",
type: 'plain_text',
text: 'Cancel',
emoji: true
},
blocks: [
{
type: "input",
type: 'input',
element: {
type: "plain_text_input",
action_id: "sl_input",
type: 'plain_text_input',
action_id: 'sl_input',
placeholder: {
type: "plain_text",
text: "Placeholder text for single-line input"
type: 'plain_text',
text: 'Placeholder text for single-line input'
}
},
label: {
type: "plain_text",
text: "Subject"
type: 'plain_text',
text: 'Subject'
},
hint: {
type: "plain_text",
text: "Short description or subject line"
type: 'plain_text',
text: 'Short description or subject line'
}
},
{
type: "input",
type: 'input',
element: {
type: "plain_text_input",
action_id: "ml_input",
type: 'plain_text_input',
action_id: 'ml_input',
multiline: true,
placeholder: {
type: "plain_text",
text: "Placeholder text for multi-line input"
type: 'plain_text',
text: 'Placeholder text for multi-line input'
}
},
label: {
type: "plain_text",
text: "Details"
type: 'plain_text',
text: 'Details'
},
hint: {
type: "plain_text",
text: "Long description"
type: 'plain_text',
text: 'Long description'
}
}
]
Expand All @@ -69,9 +69,9 @@ def modal_payload(trigger_id)
team_id = command[:team_id]
trigger_id = command[:trigger_id]
command.logger.info "Opening a modal with trigger_id: #{trigger_id}."
team = Team.find_by(team_id: team_id)
team = Team.find_by(team_id:)
slack_client = Slack::Web::Client.new(token: team.token)
slack_client.views_open(modal_payload trigger_id)
slack_client.views_open(modal_payload(trigger_id))
nil
end
end
Loading

0 comments on commit 92c099c

Please sign in to comment.