From 29991ae4c896eedc5f5d19c2f278697eb2c776dc Mon Sep 17 00:00:00 2001 From: Manabu Niseki Date: Sat, 28 Aug 2021 15:25:11 +0900 Subject: [PATCH] feat: introduce Standard and Overcommit --- .overcommit.yml | 12 ++++++++++ .standard.yml | 4 ++++ lib/miteru/attachement.rb | 4 ++-- lib/miteru/error.rb | 1 + lib/miteru/feeds.rb | 4 ++-- lib/miteru/http_client.rb | 12 +++++----- lib/miteru/kit.rb | 2 +- miteru.gemspec | 24 ++++++++++--------- spec/cli_spec.rb | 2 +- spec/downloader_spec.rb | 2 +- spec/support/helpers/helpers.rb | 2 ++ .../shared_contexts/http_server_context.rb | 8 +++---- 12 files changed, 49 insertions(+), 28 deletions(-) create mode 100644 .overcommit.yml create mode 100644 .standard.yml diff --git a/.overcommit.yml b/.overcommit.yml new file mode 100644 index 0000000..c5856dd --- /dev/null +++ b/.overcommit.yml @@ -0,0 +1,12 @@ +PreCommit: + BundleCheck: + enabled: true + + RuboCop: + enabled: true + required_executable: bundle + command: ["bundle", "exec", "standardrb"] + on_warn: fail + + YamlSyntax: + enabled: true diff --git a/.standard.yml b/.standard.yml new file mode 100644 index 0000000..8aad730 --- /dev/null +++ b/.standard.yml @@ -0,0 +1,4 @@ +ignore: + - "**/*": + - Layout/SpaceInsideHashLiteralBraces + - Style/RescueStandardError diff --git a/lib/miteru/attachement.rb b/lib/miteru/attachement.rb index fadbebd..463b439 100644 --- a/lib/miteru/attachement.rb +++ b/lib/miteru/attachement.rb @@ -31,7 +31,7 @@ def vt_link { type: "button", text: "Lookup on VirusTotal", - url: _vt_link, + url: _vt_link } end @@ -41,7 +41,7 @@ def urlscan_link { type: "button", text: "Lookup on urlscan.io", - url: _urlscan_link, + url: _urlscan_link } end diff --git a/lib/miteru/error.rb b/lib/miteru/error.rb index 22b29b6..558ac11 100644 --- a/lib/miteru/error.rb +++ b/lib/miteru/error.rb @@ -2,5 +2,6 @@ module Miteru class HTTPResponseError < StandardError; end + class DownloadError < StandardError; end end diff --git a/lib/miteru/feeds.rb b/lib/miteru/feeds.rb index 7ba8fba..1703963 100644 --- a/lib/miteru/feeds.rb +++ b/lib/miteru/feeds.rb @@ -9,7 +9,7 @@ module Miteru class Feeds - IGNORE_EXTENSIONS = %w(.htm .html .php .asp .aspx .exe .txt).freeze + IGNORE_EXTENSIONS = %w[.htm .html .php .asp .aspx .exe .txt].freeze def initialize @feeds = [ @@ -48,7 +48,7 @@ def breakdown(url) segments = uri.path.split("/") return [base] if segments.length.zero? - urls = (0...segments.length).map { |idx| "#{base}#{segments[0..idx].join('/')}" } + urls = (0...segments.length).map { |idx| "#{base}#{segments[0..idx].join("/")}" } urls.reject do |breakdowned_url| # Reject a url which ends with specific extension names diff --git a/lib/miteru/http_client.rb b/lib/miteru/http_client.rb index bc98820..969f3fc 100644 --- a/lib/miteru/http_client.rb +++ b/lib/miteru/http_client.rb @@ -27,18 +27,18 @@ def head(url, options = {}) options = options.merge default_options HTTP.follow - .timeout(3) - .headers(urlscan_url?(url) ? urlscan_headers : default_headers) - .head(url, options) + .timeout(3) + .headers(urlscan_url?(url) ? urlscan_headers : default_headers) + .head(url, options) end def get(url, options = {}) options = options.merge default_options HTTP.follow - .timeout(write: 2, connect: 5, read: 10) - .headers(urlscan_url?(url) ? urlscan_headers : default_headers) - .get(url, options) + .timeout(write: 2, connect: 5, read: 10) + .headers(urlscan_url?(url) ? urlscan_headers : default_headers) + .get(url, options) end def post(url, options = {}) diff --git a/lib/miteru/kit.rb b/lib/miteru/kit.rb index 2aee801..945ef6f 100644 --- a/lib/miteru/kit.rb +++ b/lib/miteru/kit.rb @@ -22,7 +22,7 @@ def initialize(url) @status = nil end - def valid?; + def valid? # make a HEAD request for the validation before_validation diff --git a/miteru.gemspec b/miteru.gemspec index 9521d28..426ff59 100644 --- a/miteru.gemspec +++ b/miteru.gemspec @@ -1,34 +1,36 @@ # frozen_string_literal: true -lib = File.expand_path('lib', __dir__) +lib = File.expand_path("lib", __dir__) $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib) require "miteru/version" Gem::Specification.new do |spec| - spec.name = "miteru" - spec.version = Miteru::VERSION - spec.authors = ["Manabu Niseki"] - spec.email = ["manabu.niseki@gmail.com"] + spec.name = "miteru" + spec.version = Miteru::VERSION + spec.authors = ["Manabu Niseki"] + spec.email = ["manabu.niseki@gmail.com"] - spec.summary = "An experimental phishing kit detector" - spec.description = "An experimental phishing kit detector" - spec.homepage = "https://github.com/ninoseki/miteru" - spec.license = "MIT" + spec.summary = "An experimental phishing kit detector" + spec.description = "An experimental phishing kit detector" + spec.homepage = "https://github.com/ninoseki/miteru" + spec.license = "MIT" # Specify which files should be added to the gem when it is released. # The `git ls-files -z` loads the files in the RubyGem that have been added into git. spec.files = Dir.chdir(File.expand_path(__dir__)) do `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) } end - spec.bindir = "exe" - spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) } + spec.bindir = "exe" + spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) } spec.require_paths = ["lib"] spec.add_development_dependency "bundler", "~> 2.2" spec.add_development_dependency "coveralls_reborn", "~> 0.22" spec.add_development_dependency "glint", "~> 0.1" + spec.add_development_dependency "overcommit", "~> 0.58" spec.add_development_dependency "rake", "~> 13.0" spec.add_development_dependency "rspec", "~> 3.10" + spec.add_development_dependency "standard", "~> 1.3" spec.add_development_dependency "vcr", "~> 6.0" spec.add_development_dependency "webmock", "~> 3.14" spec.add_development_dependency "webrick", "~> 1.7.0" diff --git a/spec/cli_spec.rb b/spec/cli_spec.rb index 17b7e1b..2d57cb7 100644 --- a/spec/cli_spec.rb +++ b/spec/cli_spec.rb @@ -9,7 +9,7 @@ end it "does not raise any error" do - capture(:stdout) { described_class.start %w(execute) } + capture(:stdout) { described_class.start %w[execute] } end end diff --git a/spec/downloader_spec.rb b/spec/downloader_spec.rb index e9fc2ae..ed1ec7b 100644 --- a/spec/downloader_spec.rb +++ b/spec/downloader_spec.rb @@ -44,7 +44,7 @@ it "removes duplicated files" do kits = [ Miteru::Kit.new(url + "/test.zip"), - Miteru::Kit.new( url + "/test.zip") + Miteru::Kit.new(url + "/test.zip") ] expect(Dir.glob("#{base_dir}/*.zip").empty?).to be(true) diff --git a/spec/support/helpers/helpers.rb b/spec/support/helpers/helpers.rb index a3db4b9..6355631 100644 --- a/spec/support/helpers/helpers.rb +++ b/spec/support/helpers/helpers.rb @@ -1,5 +1,6 @@ # frozen_string_literal: true +# rubocop:disable Style/EvalWithLocation, Security/Eval module Spec module Support module Helpers @@ -17,3 +18,4 @@ def capture(stream) end end end +# rubocop:enable Style/EvalWithLocation, Security/Eval diff --git a/spec/support/shared_contexts/http_server_context.rb b/spec/support/shared_contexts/http_server_context.rb index 27529b7..fbd0209 100644 --- a/spec/support/shared_contexts/http_server_context.rb +++ b/spec/support/shared_contexts/http_server_context.rb @@ -22,7 +22,7 @@ def server res.status = status res.content_length = body.size - res.content_type = 'text/plain' + res.content_type = "text/plain" res.body = body end @@ -32,7 +32,7 @@ def server res.status = 200 res.content_length = body.size - res.content_type = 'application/zip' + res.content_type = "application/zip" res.body = body end @@ -42,7 +42,7 @@ def server res.status = 200 res.content_length = body.size - res.content_type = 'application/gzip' + res.content_type = "application/gzip" res.body = body end @@ -53,7 +53,7 @@ def server res.status = status res.content_length = body.size - res.content_type = 'text/plain' + res.content_type = "text/plain" res.body = body end