Skip to content

Commit

Permalink
linting
Browse files Browse the repository at this point in the history
  • Loading branch information
dorianmariecom committed Apr 3, 2024
1 parent facf8d3 commit 4882739
Show file tree
Hide file tree
Showing 8 changed files with 46 additions and 27 deletions.
24 changes: 12 additions & 12 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
---
version: 2
updates:
- directory: "/"
package-ecosystem: github-actions
schedule:
interval: daily
- directory: "/"
package-ecosystem: npm
schedule:
interval: daily
- directory: "/"
package-ecosystem: bundler
schedule:
interval: daily
- directory: "/"
package-ecosystem: github-actions
schedule:
interval: daily
- directory: "/"
package-ecosystem: npm
schedule:
interval: daily
- directory: "/"
package-ecosystem: bundler
schedule:
interval: daily
8 changes: 8 additions & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
inherit_gem:
rubocop-rails-omakase: rubocop.yml

Layout/SpaceInsideArrayLiteralBrackets:
Enabled: false

Performance/UnfreezeString:
Enabled: false
1 change: 1 addition & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@ gemspec
ruby "3.3.0"

gem "rspec"
gem "rubocop-rails-omakase"
19 changes: 8 additions & 11 deletions bin/anonymize-json
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,18 @@
require "json"

def anonymize_json(data)
if data.is_a?(Array)
case data
when Array
data.map { |element| anonymize_json(element) }
elsif data.is_a?(Hash)
when Hash
data.transform_values { |value| anonymize_json(value) }
elsif data.is_a?(String)
when String
data.gsub(/[0-9]/, "0").gsub(/[a-z]/, "a").gsub(/[A-Z]/, "A")
elsif data.is_a?(Integer)
when Integer
0
elsif data.is_a?(Float)
when Float
0.0
elsif data.is_a?(TrueClass) || data.is_a?(FalseClass)
when TrueClass, FalseClass
false
else
raise NotImplementedError, data.class.name
Expand All @@ -33,11 +34,7 @@ if inputs.empty?
inputs = $stdin.each_line.to_a

inputs =
if File.exist?(inputs.first.strip)
inputs.map(&:strip)
else
[inputs.join]
end
(File.exist?(inputs.first.strip) ? inputs.map(&:strip) : [inputs.join])
end

inputs.each do |input|
Expand Down
10 changes: 7 additions & 3 deletions bin/rspec
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,15 @@ 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")
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.")
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

Expand Down
3 changes: 3 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"license": "MIT"
}
6 changes: 5 additions & 1 deletion spec/anonymize_json_spec.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
# frozen_string_literal: true

require "spec_helper"

RSpec.describe "anonymize-json" do
it "works" do
expect(`bin/anonymize-json '{"a":"Secret123"}'`).to eq(%({\n "a": "Aaaaaa000"\n}\n))
expect(`bin/anonymize-json '{"a":"Secret123"}'`).to eq(
%({\n "a": "Aaaaaa000"\n}\n)
)
end
end
2 changes: 2 additions & 0 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
# frozen_string_literal: true

require "rspec"

0 comments on commit 4882739

Please sign in to comment.