Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: renew rubocop & rspec #1091

Merged
merged 1 commit into from
Jun 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/ruby.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ jobs:
bundler: latest
bundler-cache: true
- name: Lint
run: bundle exec standardrb
run: bundle exec rake rubocop
test:
runs-on: ubuntu-latest
strategy:
Expand Down
30 changes: 27 additions & 3 deletions .rubocop.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
Style/StringLiterals:
EnforcedStyle: double_quotes
AllCops:
TargetRubyVersion: 3.2
NewCops: enable
Metrics/BlockLength:
Max: 150
Exclude:
Expand All @@ -12,13 +13,36 @@ Metrics/MethodLength:
Metrics/AbcSize:
Max: 50
RSpec/MultipleMemoizedHelpers:
Max: 10
Max: 15
RSpec/ExampleLength:
Max: 20
RSpec/FilePath:
SpecSuffixOnly: true
RSpec/NestedGroups:
Max: 5
RSpec/RepeatedExampleGroupDescription:
Enabled: false
RSpec/ReceiveMessages:
Enabled: false
RSpec/MultipleExpectations:
Enabled: false
RSpec/SpecFilePathFormat:
Enabled: false
RSpecRails:
Enabled: false
FactoryBot/SyntaxMethods:
Enabled: false
require:
- rubocop-capybara
- rubocop-factory_bot
- rubocop-performance
- rubocop-rake
- rubocop-rspec
- rubocop-yard
- standard
- standard-custom
- standard-performance
inherit_gem:
standard: config/base.yml
standard-custom: config/base.yml
standard-performance: config/base.yml
4 changes: 3 additions & 1 deletion Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@
require "time"

require "rspec/core/rake_task"
require "standard/rake"
require "rubocop/rake_task"

RuboCop::RakeTask.new
RSpec::Core::RakeTask.new(:spec)

task default: :spec
Expand Down Expand Up @@ -67,6 +68,7 @@ namespace :build do
end
end

desc "Build including Swagger doc and frontend assets"
task :build do
Rake::Task["build:swagger"].invoke
Rake::Task["build:frontend"].invoke
Expand Down
4 changes: 2 additions & 2 deletions lefthook.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
pre-commit:
commands:
standard:
rubocop:
glob: "*.rb"
run: bundle exec standardrb --fix {staged_files}
run: bundle exec rubocop --fix {staged_files}
stage_fixed: true
eslint:
root: "frontend/"
Expand Down
73 changes: 37 additions & 36 deletions mihari.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -36,76 +36,77 @@ Gem::Specification.new do |spec|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
spec.require_paths = ["lib"]

spec.add_development_dependency "better_errors", "~> 2.10"
spec.add_development_dependency "binding_of_caller", "~> 1.0"
spec.add_development_dependency "better_errors", "~> 2.10.1"
spec.add_development_dependency "binding_of_caller", "~> 1.0.1"
spec.add_development_dependency "bundler", "~> 2.5"
spec.add_development_dependency "capybara", "~> 3.40"
spec.add_development_dependency "coveralls_reborn", "~> 0.28"
spec.add_development_dependency "factory_bot", "~> 6.4"
spec.add_development_dependency "factory_bot", "~> 6.4.6"
spec.add_development_dependency "fakefs", "~> 2.5"
spec.add_development_dependency "faker", "~> 3.3"
spec.add_development_dependency "fuubar", "~> 2.5"
spec.add_development_dependency "mysql2", "~> 0.5"
spec.add_development_dependency "pg", "~> 1.5"
spec.add_development_dependency "faker", "~> 3.4.1"
spec.add_development_dependency "fuubar", "~> 2.5.1"
spec.add_development_dependency "mysql2", "~> 0.5.6"
spec.add_development_dependency "pg", "~> 1.5.6"
spec.add_development_dependency "rack-test", "~> 2.1"
spec.add_development_dependency "rake", "~> 13.2"
spec.add_development_dependency "rb-fsevent", "~> 0.11"
spec.add_development_dependency "rake", "~> 13.2.1"
spec.add_development_dependency "rb-fsevent", "~> 0.11.2"
spec.add_development_dependency "rerun", "~> 0.14"
spec.add_development_dependency "rspec-httpbin", "~> 0.1.0"
spec.add_development_dependency "rspec-parameterized", "~> 1.0.2"
spec.add_development_dependency "rspec", "~> 3.13"
spec.add_development_dependency "rspec-parameterized", "~> 1.0"
spec.add_development_dependency "rubocop-factory_bot", "~> 2.25"
spec.add_development_dependency "rubocop-factory_bot", "~> 2.26.0"
spec.add_development_dependency "rubocop-rake", "~> 0.6"
spec.add_development_dependency "rubocop-rspec", "~> 2.29"
spec.add_development_dependency "rubocop-yard", "~> 0.9"
spec.add_development_dependency "rubocop-rspec", "~> 2.31.0"
spec.add_development_dependency "rubocop-yard", "~> 0.9.3"
spec.add_development_dependency "simplecov-lcov", "~> 0.8"
spec.add_development_dependency "standard", "~> 1.35"
spec.add_development_dependency "test-prof", "~> 1.3"
spec.add_development_dependency "timecop", "~> 0.9"
spec.add_development_dependency "standard", "~> 1.36.0"
spec.add_development_dependency "test-prof", "~> 1.3.3"
spec.add_development_dependency "timecop", "~> 0.9.9"
spec.add_development_dependency "vcr", "~> 6.2"
spec.add_development_dependency "webmock", "~> 3.23"
spec.add_development_dependency "webmock", "~> 3.23.1"

unless ci_env?
spec.add_development_dependency "lefthook", "~> 1.6"
spec.add_development_dependency "ruby-lsp-rspec", "~> 0.1"
spec.add_development_dependency "lefthook", "~> 1.6.15"
spec.add_development_dependency "ruby-lsp-rspec", "~> 0.1.12"
spec.add_development_dependency "solargraph", "~> 0.50"
end

spec.add_dependency "activerecord", "7.1.3.2"
spec.add_dependency "activerecord", "7.1.3.4"
spec.add_dependency "addressable", "~> 2.8"
spec.add_dependency "anyway_config", "2.6.3"
spec.add_dependency "awrence", "2.0.1"
spec.add_dependency "anyway_config", "2.6.4"
spec.add_dependency "awrence", "3.0.0"
spec.add_dependency "csv", "~> 3.3"
spec.add_dependency "dotenv", "3.1.0"
spec.add_dependency "dotenv", "3.1.2"
spec.add_dependency "dry-container", "0.11.0"
spec.add_dependency "dry-files", "1.1.0"
spec.add_dependency "dry-monads", "1.6.0"
spec.add_dependency "dry-schema", "1.13.3"
spec.add_dependency "dry-schema", "1.13.4"
spec.add_dependency "dry-struct", "1.6.0"
spec.add_dependency "dry-validation", "1.10.0"
spec.add_dependency "email_address", "0.2.4"
spec.add_dependency "grape", "2.0.0"
spec.add_dependency "grape-entity", "1.0.1"
spec.add_dependency "grape-swagger", "2.0.2"
spec.add_dependency "grape-swagger-entity", "0.5.3"
spec.add_dependency "grape-swagger", "2.1.0"
spec.add_dependency "grape-swagger-entity", "0.5.4"
spec.add_dependency "http", "5.2.0"
spec.add_dependency "jbuilder", "2.11.5"
spec.add_dependency "jbuilder", "2.12.0"
spec.add_dependency "jr-cli", "0.6.0"
spec.add_dependency "launchy", "3.0.0"
spec.add_dependency "memo_wise", "1.8.0"
spec.add_dependency "launchy", "3.0.1"
spec.add_dependency "memo_wise", "1.9.0"
spec.add_dependency "normalize_country", "0.3.2"
spec.add_dependency "parallel", "1.24.0"
spec.add_dependency "plissken", "2.0.1"
spec.add_dependency "parallel", "1.25.1"
spec.add_dependency "plissken", "3.0.0"
spec.add_dependency "public_suffix", "5.0.5"
spec.add_dependency "puma", "6.4.2"
spec.add_dependency "rack", "3.0.10"
spec.add_dependency "rack", "3.0.11"
spec.add_dependency "rack-cors", "2.0.2"
spec.add_dependency "rack-session", "2.0.0"
spec.add_dependency "rackup", "2.1.0"
spec.add_dependency "search_cop", "1.3.0"
spec.add_dependency "search_cop", "1.4.0"
spec.add_dependency "semantic_logger", "4.15.0"
spec.add_dependency "sentry-ruby", "~> 5.17"
spec.add_dependency "sentry-sidekiq", "~> 5.17"
spec.add_dependency "sidekiq", "7.2.2"
spec.add_dependency "sentry-ruby", "~> 5.17.3"
spec.add_dependency "sentry-sidekiq", "~> 5.17.3"
spec.add_dependency "sidekiq", "7.2.4"
spec.add_dependency "slack-notifier", "2.4.0"
spec.add_dependency "sqlite3", "~> 1.7"
spec.add_dependency "thor", "1.3.1"
Expand Down
2 changes: 2 additions & 0 deletions spec/analyzers/dnstwister_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@

describe "#artifacts" do
before do
# rubocop:disable RSpec/SubjectStub
allow(analyzer).to receive(:resolvable?).and_return(true)
# rubocop:enable RSpec/SubjectStub
end

it do
Expand Down
8 changes: 4 additions & 4 deletions spec/analyzers/otx_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

describe "#artifacts" do
it do
expect(subject.artifacts).to be_an(Array)
expect(analyzer.artifacts).to be_an(Array)
end
end
end
Expand All @@ -18,7 +18,7 @@

describe "#artifacts" do
it do
expect(subject.artifacts).to be_an(Array)
expect(analyzer.artifacts).to be_an(Array)
end
end
end
Expand All @@ -28,7 +28,7 @@

describe "#artifacts" do
it do
expect { subject.artifacts }.to raise_error(Mihari::ValueError)
expect { analyzer.artifacts }.to raise_error(Mihari::ValueError)
end
end
end
Expand All @@ -41,7 +41,7 @@
end

it do
expect { subject.artifacts }.to raise_error(ArgumentError)
expect { analyzer.artifacts }.to raise_error(ArgumentError)
end
end
end
2 changes: 1 addition & 1 deletion spec/analyzers/securitytrails_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
end

context "without API credentials" do
let!(:query) { "1.1.1.1" }
let(:query) { "1.1.1.1" }

before do
allow(Mihari.config).to receive(:securitytrails_api_key).and_return(nil)
Expand Down
15 changes: 8 additions & 7 deletions spec/cli/alert_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,18 +27,19 @@
end

describe "#create" do
before do
@file = Tempfile.new("dummy")
@file.write(YAML.dump({rule_id: rule.id, artifacts: %w[1.1.1.1]}))
@file.rewind
end
let(:file) {
file = Tempfile.new("dummy")
file.write(YAML.dump({rule_id: rule.id, artifacts: %w[1.1.1.1]}))
file.rewind
file
}

after do
@file.unlink
file.unlink
end

it do
expect { described_class.new.invoke(:create, [@file.path]) }.to output(include(rule.id)).to_stdout
expect { described_class.new.invoke(:create, [file.path]) }.to output(include(rule.id)).to_stdout
end
end
end
2 changes: 1 addition & 1 deletion spec/cli/rule_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
it do
expect do
described_class.new.invoke(:init, [path])
end.to output("").to_stdout
end.not_to output.to_stdout
end
end

Expand Down
4 changes: 2 additions & 2 deletions spec/concerns/autonomous_system_normalizable_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ class AutonomousSystemTest
end

RSpec.describe Mihari::Concerns::AutonomousSystemNormalizable do
subject(:subject) { AutonomousSystemTest.new }
subject(:test) { AutonomousSystemTest.new }

describe "#normalize_asn" do
where(:value, :expected) do
Expand All @@ -18,7 +18,7 @@ class AutonomousSystemTest

with_them do
it do
expect(subject.normalize_asn(value)).to eq(expected)
expect(test.normalize_asn(value)).to eq(expected)
end
end
end
Expand Down
14 changes: 7 additions & 7 deletions spec/concerns/error_unwrappable_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,28 +21,28 @@ def raise_error
end

RSpec.describe Mihari::Concerns::ErrorUnwrappable do
subject(:subject) { ErrorTest.new }
subject(:test) { ErrorTest.new }

describe "#unwrap_error" do
it do
subject.raise_try_error
test.raise_try_error
rescue => e
expect(e).not_to be_a ZeroDivisionError
expect(subject.unwrap_error(e)).to be_a ZeroDivisionError
expect(test.unwrap_error(e)).to be_a ZeroDivisionError
end

it do
subject.raise_result_error
test.raise_result_error
rescue => e
expect(e).not_to be_a ZeroDivisionError
expect(subject.unwrap_error(e)).to be_a ZeroDivisionError
expect(test.unwrap_error(e)).to be_a ZeroDivisionError
end

it do
subject.raise_error
test.raise_error
rescue => e
expect(e).to be_a ZeroDivisionError
expect(subject.unwrap_error(e)).to be_a ZeroDivisionError
expect(test.unwrap_error(e)).to be_a ZeroDivisionError
end
end
end
6 changes: 3 additions & 3 deletions spec/concerns/falsepositive_validatable_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ class FalsePositiveTest
end

RSpec.describe Mihari::Concerns::FalsePositiveValidatable do
subject(:subject) { FalsePositiveTest.new }
subject(:test) { FalsePositiveTest.new }

describe "#normalize_falsepositive" do
where(:value, :expected) do
Expand All @@ -19,7 +19,7 @@ class FalsePositiveTest

with_them do
it do
expect(subject.normalize_falsepositive(value)).to eq(expected)
expect(test.normalize_falsepositive(value)).to eq(expected)
end
end
end
Expand All @@ -36,7 +36,7 @@ class FalsePositiveTest

with_them do
it do
expect(subject.valid_falsepositive?(value)).to be expected
expect(test.valid_falsepositive?(value)).to be expected
end
end
end
Expand Down
4 changes: 2 additions & 2 deletions spec/concerns/refangable_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ class RefangTest

RSpec.describe Mihari::Concerns::Refangable do
describe "#refang" do
subject(:subject) { RefangTest.new }
subject(:test) { RefangTest.new }

where(:value, :expected) do
[
Expand All @@ -18,7 +18,7 @@ class RefangTest

with_them do
it do
expect(subject.refang(value)).to eq(expected)
expect(test.refang(value)).to eq(expected)
end
end
end
Expand Down
Loading