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
+7 -2
View File
@@ -1,3 +1,5 @@
# frozen_string_literal: true
source "https://rubygems.org" source "https://rubygems.org"
# Bundle edge Rails instead: gem "rails", github: "rails/rails", branch: "main" # Bundle edge Rails instead: gem "rails", github: "rails/rails", branch: "main"
@@ -21,7 +23,7 @@ gem "jbuilder"
gem "bcrypt", "~> 3.1.7" gem "bcrypt", "~> 3.1.7"
# Windows does not include zoneinfo files, so bundle the tzinfo-data gem # Windows does not include zoneinfo files, so bundle the tzinfo-data gem
gem "tzinfo-data", platforms: %i[ windows jruby ] gem "tzinfo-data", platforms: %i[windows jruby]
# Use the database-backed adapters for Rails.cache, Active Job, and Action Cable # Use the database-backed adapters for Rails.cache, Active Job, and Action Cable
gem "solid_cache" gem "solid_cache"
@@ -41,7 +43,7 @@ gem 'slim'
group :development, :test do group :development, :test do
# See https://guides.rubyonrails.org/debugging_rails_applications.html#debugging-with-the-debug-gem # See https://guides.rubyonrails.org/debugging_rails_applications.html#debugging-with-the-debug-gem
gem "debug", platforms: %i[ mri windows ], require: "debug/prelude" gem "debug", platforms: %i[mri windows], require: "debug/prelude"
# Static analysis for security vulnerabilities [https://brakemanscanner.org/] # Static analysis for security vulnerabilities [https://brakemanscanner.org/]
gem "brakeman", require: false gem "brakeman", require: false
@@ -50,4 +52,7 @@ end
group :development do group :development do
# Use console on exceptions pages [https://github.com/rails/web-console] # Use console on exceptions pages [https://github.com/rails/web-console]
gem "web-console" gem "web-console"
gem 'rubocop', require: false
gem 'rubocop-rails', require: false
end end
+37
View File
@@ -72,6 +72,7 @@ GEM
securerandom (>= 0.3) securerandom (>= 0.3)
tzinfo (~> 2.0, >= 2.0.5) tzinfo (~> 2.0, >= 2.0.5)
uri (>= 0.13.1) uri (>= 0.13.1)
ast (2.4.3)
base64 (0.3.0) base64 (0.3.0)
bcrypt (3.1.20) bcrypt (3.1.20)
benchmark (0.4.1) benchmark (0.4.1)
@@ -124,6 +125,9 @@ GEM
jbuilder (2.13.0) jbuilder (2.13.0)
actionview (>= 5.0.0) actionview (>= 5.0.0)
activesupport (>= 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) logger (1.7.0)
loofah (2.24.1) loofah (2.24.1)
crass (~> 1.0.2) crass (~> 1.0.2)
@@ -166,9 +170,14 @@ GEM
racc (~> 1.4) racc (~> 1.4)
nokogiri (1.18.8-x86_64-linux-musl) nokogiri (1.18.8-x86_64-linux-musl)
racc (~> 1.4) racc (~> 1.4)
parallel (1.27.0)
parser (3.3.8.0)
ast (~> 2.4.1)
racc
pp (0.6.2) pp (0.6.2)
prettyprint prettyprint
prettyprint (0.2.0) prettyprint (0.2.0)
prism (1.4.0)
propshaft (1.1.0) propshaft (1.1.0)
actionpack (>= 7.0.0) actionpack (>= 7.0.0)
activesupport (>= 7.0.0) activesupport (>= 7.0.0)
@@ -218,12 +227,35 @@ GEM
rake (>= 12.2) rake (>= 12.2)
thor (~> 1.0, >= 1.2.2) thor (~> 1.0, >= 1.2.2)
zeitwerk (~> 2.6) zeitwerk (~> 2.6)
rainbow (3.1.1)
rake (13.3.0) rake (13.3.0)
rdoc (6.14.1) rdoc (6.14.1)
erb erb
psych (>= 4.0.0) psych (>= 4.0.0)
regexp_parser (2.10.0)
reline (0.6.1) reline (0.6.1)
io-console (~> 0.5) 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) ruby-vips (2.2.4)
ffi (~> 1.12) ffi (~> 1.12)
logger logger
@@ -265,6 +297,9 @@ GEM
railties (>= 7.1.0) railties (>= 7.1.0)
tzinfo (2.0.6) tzinfo (2.0.6)
concurrent-ruby (~> 1.0) 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) uri (1.0.3)
useragent (0.16.11) useragent (0.16.11)
web-console (4.2.1) web-console (4.2.1)
@@ -300,6 +335,8 @@ DEPENDENCIES
propshaft propshaft
puma (>= 5.0) puma (>= 5.0)
rails (~> 8.0.2) rails (~> 8.0.2)
rubocop
rubocop-rails
slim slim
solid_cable solid_cable
solid_cache solid_cache
+9 -7
View File
@@ -1,16 +1,17 @@
# frozen_string_literal: true
class PasswordsController < ApplicationController class PasswordsController < ApplicationController
allow_unauthenticated_access allow_unauthenticated_access
before_action :set_user_by_token, only: %i[ edit update ] before_action :set_user_by_token, only: %i[edit update]
def new def new; end
end
def create def create
if user = User.find_by(email_address: params[:email_address]) if user = User.find_by(email_address: params[:email_address])
PasswordsMailer.reset(user).deliver_later PasswordsMailer.reset(user).deliver_later
end 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 end
def edit def edit
@@ -18,16 +19,17 @@ class PasswordsController < ApplicationController
def update def update
if @user.update(params.permit(:password, :password_confirmation)) 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 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
end end
private private
def set_user_by_token def set_user_by_token
@user = User.find_by_password_reset_token!(params[:token]) @user = User.find_by_password_reset_token!(params[:token])
rescue ActiveSupport::MessageVerifier::InvalidSignature 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
end end
+5 -6
View File
@@ -1,3 +1,5 @@
# frozen_string_literal: true
class ProjectsController < ApplicationController class ProjectsController < ApplicationController
before_action :fetch_project!, only: %w[show edit update destroy] before_action :fetch_project!, only: %w[show edit update destroy]
@@ -5,8 +7,7 @@ class ProjectsController < ApplicationController
@projects = Project.all @projects = Project.all
end end
def show def show; end
end
def new def new
@project = Project.new @project = Project.new
@@ -21,8 +22,7 @@ class ProjectsController < ApplicationController
end end
end end
def edit def edit; end
end
def update def update
if @project.update(project_params) if @project.update(project_params)
@@ -32,8 +32,7 @@ class ProjectsController < ApplicationController
end end
end end
def destroy def destroy; end
end
private private
+9 -6
View File
@@ -1,16 +1,19 @@
class SessionsController < ApplicationController # frozen_string_literal: true
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." }
def new class SessionsController < ApplicationController
end allow_unauthenticated_access only: %i[new create]
rate_limit to: 10, within: 3.minutes, only: :create, with: lambda {
redirect_to new_session_url, alert: 'Try again later.'
}
def new; end
def create def create
if user = User.authenticate_by(params.permit(:email_address, :password)) if user = User.authenticate_by(params.permit(:email_address, :password))
start_new_session_for user start_new_session_for user
redirect_to after_authentication_url redirect_to after_authentication_url
else 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
end end
+5 -10
View File
@@ -1,23 +1,18 @@
# frozen_string_literal: true
class Project < ApplicationRecord class Project < ApplicationRecord
validates :name, :code, presence: true validates :name, :code, presence: true
validates :code, exclusion: { in: %w[new] }, uniqueness: true validates :code, exclusion: { in: %w[new] }, uniqueness: true
has_many :tasks has_many :tasks, dependent: :restrict_with_exception
has_rich_text :description has_rich_text :description
before_validation :lowercase_code normalizes :code, with: ->(code) { code.strip.downcase }
def to_param def to_param
return unless id return unless id
code code
end end
private
def lowercase_code
return if code.blank?
self.code = self.code.downcase
end
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")