Added Rubocop and initial config

This commit is contained in:
2025-07-10 15:30:00 +03:00
parent 864769e70a
commit 42d45853ff
8 changed files with 140 additions and 35 deletions
+37
View File
@@ -0,0 +1,37 @@
# The behavior of RuboCop can be controlled via the .rubocop.yml
# configuration file. It makes it possible to enable/disable
# certain cops (checks) and to alter their behavior if they accept
# any parameters. The file can be placed either in your home
# directory or in some project directory.
#
# RuboCop will start looking for the configuration file in the directory
# where the inspected file is and continue its way up to the root directory.
#
# See https://docs.rubocop.org/rubocop/configuration
plugins:
- rubocop-rails
AllCops:
NewCops: enable
Style/StringLiterals:
Exclude:
- Gemfile # Mostly because of auto-generated files
Bundler/OrderedGems:
Enabled: false
Style/Documentation:
Enabled: false
Rails/ActionOrder:
Enabled: false
Metrics/AbcSize:
Exclude:
- db/migrate/*.rb
Metrics/MethodLength:
Exclude:
- db/migrate/*.rb
+5
View File
@@ -1,3 +1,5 @@
# frozen_string_literal: true
source "https://rubygems.org"
# Bundle edge Rails instead: gem "rails", github: "rails/rails", branch: "main"
@@ -50,4 +52,7 @@ end
group :development do
# Use console on exceptions pages [https://github.com/rails/web-console]
gem "web-console"
gem 'rubocop', require: false
gem 'rubocop-rails', require: false
end
+37
View File
@@ -72,6 +72,7 @@ GEM
securerandom (>= 0.3)
tzinfo (~> 2.0, >= 2.0.5)
uri (>= 0.13.1)
ast (2.4.3)
base64 (0.3.0)
bcrypt (3.1.20)
benchmark (0.4.1)
@@ -124,6 +125,9 @@ GEM
jbuilder (2.13.0)
actionview (>= 5.0.0)
activesupport (>= 5.0.0)
json (2.12.2)
language_server-protocol (3.17.0.5)
lint_roller (1.1.0)
logger (1.7.0)
loofah (2.24.1)
crass (~> 1.0.2)
@@ -166,9 +170,14 @@ GEM
racc (~> 1.4)
nokogiri (1.18.8-x86_64-linux-musl)
racc (~> 1.4)
parallel (1.27.0)
parser (3.3.8.0)
ast (~> 2.4.1)
racc
pp (0.6.2)
prettyprint
prettyprint (0.2.0)
prism (1.4.0)
propshaft (1.1.0)
actionpack (>= 7.0.0)
activesupport (>= 7.0.0)
@@ -218,12 +227,35 @@ GEM
rake (>= 12.2)
thor (~> 1.0, >= 1.2.2)
zeitwerk (~> 2.6)
rainbow (3.1.1)
rake (13.3.0)
rdoc (6.14.1)
erb
psych (>= 4.0.0)
regexp_parser (2.10.0)
reline (0.6.1)
io-console (~> 0.5)
rubocop (1.78.0)
json (~> 2.3)
language_server-protocol (~> 3.17.0.2)
lint_roller (~> 1.1.0)
parallel (~> 1.10)
parser (>= 3.3.0.2)
rainbow (>= 2.2.2, < 4.0)
regexp_parser (>= 2.9.3, < 3.0)
rubocop-ast (>= 1.45.1, < 2.0)
ruby-progressbar (~> 1.7)
unicode-display_width (>= 2.4.0, < 4.0)
rubocop-ast (1.45.1)
parser (>= 3.3.7.2)
prism (~> 1.4)
rubocop-rails (2.32.0)
activesupport (>= 4.2.0)
lint_roller (~> 1.1)
rack (>= 1.1)
rubocop (>= 1.75.0, < 2.0)
rubocop-ast (>= 1.44.0, < 2.0)
ruby-progressbar (1.13.0)
ruby-vips (2.2.4)
ffi (~> 1.12)
logger
@@ -265,6 +297,9 @@ GEM
railties (>= 7.1.0)
tzinfo (2.0.6)
concurrent-ruby (~> 1.0)
unicode-display_width (3.1.4)
unicode-emoji (~> 4.0, >= 4.0.4)
unicode-emoji (4.0.4)
uri (1.0.3)
useragent (0.16.11)
web-console (4.2.1)
@@ -300,6 +335,8 @@ DEPENDENCIES
propshaft
puma (>= 5.0)
rails (~> 8.0.2)
rubocop
rubocop-rails
slim
solid_cable
solid_cache
+8 -6
View File
@@ -1,16 +1,17 @@
# frozen_string_literal: true
class PasswordsController < ApplicationController
allow_unauthenticated_access
before_action :set_user_by_token, only: %i[edit update]
def new
end
def new; end
def create
if user = User.find_by(email_address: params[:email_address])
PasswordsMailer.reset(user).deliver_later
end
redirect_to new_session_path, notice: "Password reset instructions sent (if user with that email address exists)."
redirect_to new_session_path, notice: 'Password reset instructions sent (if user with that email address exists).'
end
def edit
@@ -18,16 +19,17 @@ class PasswordsController < ApplicationController
def update
if @user.update(params.permit(:password, :password_confirmation))
redirect_to new_session_path, notice: "Password has been reset."
redirect_to new_session_path, notice: 'Password has been reset.'
else
redirect_to edit_password_path(params[:token]), alert: "Passwords did not match."
redirect_to edit_password_path(params[:token]), alert: 'Passwords did not match.'
end
end
private
def set_user_by_token
@user = User.find_by_password_reset_token!(params[:token])
rescue ActiveSupport::MessageVerifier::InvalidSignature
redirect_to new_password_path, alert: "Password reset link is invalid or has expired."
redirect_to new_password_path, alert: 'Password reset link is invalid or has expired.'
end
end
+5 -6
View File
@@ -1,3 +1,5 @@
# frozen_string_literal: true
class ProjectsController < ApplicationController
before_action :fetch_project!, only: %w[show edit update destroy]
@@ -5,8 +7,7 @@ class ProjectsController < ApplicationController
@projects = Project.all
end
def show
end
def show; end
def new
@project = Project.new
@@ -21,8 +22,7 @@ class ProjectsController < ApplicationController
end
end
def edit
end
def edit; end
def update
if @project.update(project_params)
@@ -32,8 +32,7 @@ class ProjectsController < ApplicationController
end
end
def destroy
end
def destroy; end
private
+7 -4
View File
@@ -1,16 +1,19 @@
# frozen_string_literal: true
class SessionsController < ApplicationController
allow_unauthenticated_access only: %i[new create]
rate_limit to: 10, within: 3.minutes, only: :create, with: -> { redirect_to new_session_url, alert: "Try again later." }
rate_limit to: 10, within: 3.minutes, only: :create, with: lambda {
redirect_to new_session_url, alert: 'Try again later.'
}
def new
end
def new; end
def create
if user = User.authenticate_by(params.permit(:email_address, :password))
start_new_session_for user
redirect_to after_authentication_url
else
redirect_to new_session_path, alert: "Try another email address or password."
redirect_to new_session_path, alert: 'Try another email address or password.'
end
end
+5 -10
View File
@@ -1,23 +1,18 @@
# frozen_string_literal: true
class Project < ApplicationRecord
validates :name, :code, presence: true
validates :code, exclusion: { in: %w[new] }, uniqueness: true
has_many :tasks
has_many :tasks, dependent: :restrict_with_exception
has_rich_text :description
before_validation :lowercase_code
normalizes :code, with: ->(code) { code.strip.downcase }
def to_param
return unless id
code
end
private
def lowercase_code
return if code.blank?
self.code = self.code.downcase
end
end
Executable
+27
View File
@@ -0,0 +1,27 @@
#!/usr/bin/env ruby
# frozen_string_literal: true
#
# This file was generated by Bundler.
#
# The application 'rubocop' is installed as part of a gem, and
# this file is here to facilitate running it.
#
ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../Gemfile", __dir__)
bundle_binstub = File.expand_path("bundle", __dir__)
if File.file?(bundle_binstub)
if File.read(bundle_binstub, 300).include?("This file was generated by Bundler")
load(bundle_binstub)
else
abort("Your `bin/bundle` was not generated by Bundler, so this binstub cannot run.
Replace `bin/bundle` by running `bundle binstubs bundler --force`, then run this command again.")
end
end
require "rubygems"
require "bundler/setup"
load Gem.bin_path("rubocop", "rubocop")