Skip to content

Commit 85b4524

Browse files
committed
chore: adopt StandardRB + autofix violations
1 parent e446960 commit 85b4524

9 files changed

Lines changed: 102 additions & 98 deletions

File tree

.github/workflows/test.yml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,3 +21,13 @@ jobs:
2121
ruby-version: ${{ matrix.ruby }}
2222
bundler-cache: true
2323
- run: bundle exec rspec
24+
25+
standard:
26+
runs-on: ubuntu-latest
27+
steps:
28+
- uses: actions/checkout@v7
29+
- uses: ruby/setup-ruby@v1
30+
with:
31+
ruby-version: "3.4"
32+
bundler-cache: true
33+
- run: bundle exec standardrb

.standard.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
ignore:
2+
- "vendor/**/*"
3+
- "tmp/**/*"

Gemfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,5 @@ gem "rababa", "~> 0.1.1"
1515
group :development, :test do
1616
gem "rake"
1717
gem "rspec", "~> 3.13"
18+
gem "standard", require: false
1819
end

Rakefile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
require "bundler/setup"
2-
require 'rspec/core/rake_task'
2+
require "rspec/core/rake_task"
33

44
RSpec::Core::RakeTask.new(:spec)
55

6-
task :default => :spec
6+
task default: :spec

lib/interscript-api/graphql/types/query_type.rb

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
require "interscript"
55
require "interscript/compiler/ruby"
66

7-
require 'pathname' unless ENV["AWS_EXECUTION_ENV"].nil?
7+
require "pathname" unless ENV["AWS_EXECUTION_ENV"].nil?
88

99
class DetectionResultType < GraphQL::Schema::Object
1010
field :map_name, String, null: false
@@ -37,43 +37,40 @@ def transliterate(system_code:, input:)
3737
raise StandardError.new("{input} string too long")
3838
end
3939

40-
rs = Interscript.transliterate(
40+
Interscript.transliterate(
4141
system_code,
4242
input.dup,
4343
@cache ||= {},
4444
compiler: Interscript::Compiler::Ruby
4545
)
46-
rs
4746
end
4847

4948
field :detect, [DetectionResultType], null: true do
5049
description "Detect which transliteration system was used for #input to generate #output"
5150
argument :input, String, required: true
5251
argument :output, String, required: true
5352

54-
argument :map_pattern, String, required: false, default_value: '*'
53+
argument :map_pattern, String, required: false, default_value: "*"
5554
end
5655

5756
def detect(input:, output:, map_pattern: "*")
58-
rs = Interscript.detect(
57+
Interscript.detect(
5958
input,
6059
output,
6160
compiler: Interscript::Compiler::Ruby,
6261
multiple: true,
6362
cache: @cache ||= {},
6463
map_pattern: map_pattern
6564
).map do |map_name, distance|
66-
{ map_name: map_name, distance: distance }
65+
{map_name: map_name, distance: distance}
6766
end
68-
69-
rs
7067
end
7168

7269
def info
7370
JSON.generate({
74-
version: InterscriptApi::VERSION,
75-
interscript_version: Interscript::VERSION,
76-
})
71+
version: InterscriptApi::VERSION,
72+
interscript_version: Interscript::VERSION
73+
})
7774
end
7875

7976
# def limits
@@ -84,5 +81,3 @@ def system_codes
8481
Interscript.maps
8582
end
8683
end
87-
88-

lib/interscript-api/lambda_function.rb

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -4,50 +4,50 @@
44

55
def handler(event:, context: {})
66
cors_origin = ENV["DEFAULT_ORIGIN"]
7-
input_origin = event.fetch('headers', {}).fetch('origin', "")
7+
input_origin = event.fetch("headers", {}).fetch("origin", "")
88

9-
if /#{ENV["CORS_ORIGIN_REGEX"]}/ =~ input_origin
10-
puts 'match origin'
9+
if /#{ENV["CORS_ORIGIN_REGEX"]}/.match?(input_origin)
10+
puts "match origin"
1111
cors_origin = input_origin
1212
end
1313

1414
headers = {
1515
"Access-Control-Allow-Origin" => cors_origin,
16-
"Access-Control-Allow-Headers"=> 'Content-Type,X-Amz-Date,Authorization,X-Api-Key,X-Amz-Security-Token',
17-
"Access-Control-Allow-Methods"=> "POST, OPTIONS"
16+
"Access-Control-Allow-Headers" => "Content-Type,X-Amz-Date,Authorization,X-Api-Key,X-Amz-Security-Token",
17+
"Access-Control-Allow-Methods" => "POST, OPTIONS"
1818
}
1919

20-
body = event['body']
21-
if "OPTIONS".casecmp?(event['httpMethod']) || body.nil? || body.empty?
20+
body = event["body"]
21+
if "OPTIONS".casecmp?(event["httpMethod"]) || body.nil? || body.empty?
2222
return {
2323
statusCode: 200,
24-
headers: headers,
24+
headers: headers
2525
}
2626
end
2727

2828
query = begin
29-
JSON.parse(body)["query"]
30-
rescue JSON::ParserError
31-
body
32-
end
29+
JSON.parse(body)["query"]
30+
rescue JSON::ParserError
31+
body
32+
end
3333

3434
status_code = begin
35-
result = InterscriptApi::Schema.execute(query).to_json
36-
200
37-
rescue StandardError => e
38-
result = e.message
39-
puts result
40-
400
41-
rescue => e
42-
puts e
43-
puts "Catch Error"
44-
end
35+
result = InterscriptApi::Schema.execute(query).to_json
36+
200
37+
rescue => e
38+
result = e.message
39+
puts result
40+
400
41+
rescue => e
42+
puts e
43+
puts "Catch Error"
44+
end
4545

4646
begin
4747
result_json = JSON.parse result
4848
status_code = 400 if result_json.key?("errors")
4949
rescue JSON::ParserError
50-
#ignore
50+
# ignore
5151
end
5252

5353
{

lib/limits.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ module InterscriptApi
22
LIMITS = {
33
# timeout_millis: 10,
44

5-
#1k input length
6-
input_max_size: 1_000_000,
5+
# 1k input length
6+
input_max_size: 1_000_000
77
}.freeze
88
end

spec/interscript-api/lambda_function_spec.rb

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,7 @@
22
require "json"
33

44
describe InterscriptApi do
5-
65
context "With valid input" do
7-
86
it "should return valid data when transliterate is called" do
97
event = {
108
"body" => '{transliterate(systemCode: "odni-rus-Cyrl-Latn-2015", input: "Михаил Тимофеевич Калашников")}'
@@ -34,9 +32,9 @@
3432
end
3533

3634
it "should print system_codes" do
37-
ENV['INTERSCRIPT_STAGING'] = '1'
35+
ENV["INTERSCRIPT_STAGING"] = "1"
3836
event = {
39-
"body" => '{systemCodes}'
37+
"body" => "{systemCodes}"
4038
}
4139
rs = handler(event: event)
4240
rs = JSON.parse(rs[:body])["data"].to_h
@@ -59,7 +57,6 @@
5957

6058
rs = /#{cors_origin}/ =~ "https://localhost:3001"
6159
expect(rs).to be_truthy
62-
6360
end
6461
end
6562
end

spec/spec_helper.rb

Lines changed: 51 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -44,57 +44,55 @@
4444
# triggering implicit auto-inclusion in groups with matching metadata.
4545
config.shared_context_metadata_behavior = :apply_to_host_groups
4646

47-
# The settings below are suggested to provide a good initial experience
48-
# with RSpec, but feel free to customize to your heart's content.
49-
=begin
50-
# This allows you to limit a spec run to individual examples or groups
51-
# you care about by tagging them with `:focus` metadata. When nothing
52-
# is tagged with `:focus`, all examples get run. RSpec also provides
53-
# aliases for `it`, `describe`, and `context` that include `:focus`
54-
# metadata: `fit`, `fdescribe` and `fcontext`, respectively.
55-
config.filter_run_when_matching :focus
56-
57-
# Allows RSpec to persist some state between runs in order to support
58-
# the `--only-failures` and `--next-failure` CLI options. We recommend
59-
# you configure your source control system to ignore this file.
60-
config.example_status_persistence_file_path = "spec/examples.txt"
61-
62-
# Limits the available syntax to the non-monkey patched syntax that is
63-
# recommended. For more details, see:
64-
# - http://rspec.info/blog/2012/06/rspecs-new-expectation-syntax/
65-
# - http://www.teaisaweso.me/blog/2013/05/27/rspecs-new-message-expectation-syntax/
66-
# - http://rspec.info/blog/2014/05/notable-changes-in-rspec-3/#zero-monkey-patching-mode
67-
config.disable_monkey_patching!
68-
69-
# This setting enables warnings. It's recommended, but in some cases may
70-
# be too noisy due to issues in dependencies.
71-
config.warnings = true
72-
73-
# Many RSpec users commonly either run the entire suite or an individual
74-
# file, and it's useful to allow more verbose output when running an
75-
# individual spec file.
76-
if config.files_to_run.one?
77-
# Use the documentation formatter for detailed output,
78-
# unless a formatter has already been configured
79-
# (e.g. via a command-line flag).
80-
config.default_formatter = "doc"
81-
end
82-
83-
# Print the 10 slowest examples and example groups at the
84-
# end of the spec run, to help surface which specs are running
85-
# particularly slow.
86-
config.profile_examples = 10
87-
88-
# Run specs in random order to surface order dependencies. If you find an
89-
# order dependency and want to debug it, you can fix the order by providing
90-
# the seed, which is printed after each run.
91-
# --seed 1234
92-
config.order = :random
93-
94-
# Seed global randomization in this process using the `--seed` CLI option.
95-
# Setting this allows you to use `--seed` to deterministically reproduce
96-
# test failures related to randomization by passing the same `--seed` value
97-
# as the one that triggered the failure.
98-
Kernel.srand config.seed
99-
=end
47+
# The settings below are suggested to provide a good initial experience
48+
# with RSpec, but feel free to customize to your heart's content.
49+
# # This allows you to limit a spec run to individual examples or groups
50+
# # you care about by tagging them with `:focus` metadata. When nothing
51+
# # is tagged with `:focus`, all examples get run. RSpec also provides
52+
# # aliases for `it`, `describe`, and `context` that include `:focus`
53+
# # metadata: `fit`, `fdescribe` and `fcontext`, respectively.
54+
# config.filter_run_when_matching :focus
55+
#
56+
# # Allows RSpec to persist some state between runs in order to support
57+
# # the `--only-failures` and `--next-failure` CLI options. We recommend
58+
# # you configure your source control system to ignore this file.
59+
# config.example_status_persistence_file_path = "spec/examples.txt"
60+
#
61+
# # Limits the available syntax to the non-monkey patched syntax that is
62+
# # recommended. For more details, see:
63+
# # - http://rspec.info/blog/2012/06/rspecs-new-expectation-syntax/
64+
# # - http://www.teaisaweso.me/blog/2013/05/27/rspecs-new-message-expectation-syntax/
65+
# # - http://rspec.info/blog/2014/05/notable-changes-in-rspec-3/#zero-monkey-patching-mode
66+
# config.disable_monkey_patching!
67+
#
68+
# # This setting enables warnings. It's recommended, but in some cases may
69+
# # be too noisy due to issues in dependencies.
70+
# config.warnings = true
71+
#
72+
# # Many RSpec users commonly either run the entire suite or an individual
73+
# # file, and it's useful to allow more verbose output when running an
74+
# # individual spec file.
75+
# if config.files_to_run.one?
76+
# # Use the documentation formatter for detailed output,
77+
# # unless a formatter has already been configured
78+
# # (e.g. via a command-line flag).
79+
# config.default_formatter = "doc"
80+
# end
81+
#
82+
# # Print the 10 slowest examples and example groups at the
83+
# # end of the spec run, to help surface which specs are running
84+
# # particularly slow.
85+
# config.profile_examples = 10
86+
#
87+
# # Run specs in random order to surface order dependencies. If you find an
88+
# # order dependency and want to debug it, you can fix the order by providing
89+
# # the seed, which is printed after each run.
90+
# # --seed 1234
91+
# config.order = :random
92+
#
93+
# # Seed global randomization in this process using the `--seed` CLI option.
94+
# # Setting this allows you to use `--seed` to deterministically reproduce
95+
# # test failures related to randomization by passing the same `--seed` value
96+
# # as the one that triggered the failure.
97+
# Kernel.srand config.seed
10098
end

0 commit comments

Comments
 (0)