Skip to content

Commit cdc668f

Browse files
committed
chore: adopt StandardRB for lib/ + auto-fix 953 violations
- Add 'standard' gem + .standard.yml (lib/ only; spec/bin/exe ignored) - Auto-fix 953 -> 23 remaining violations (mostly regexp_converter.rb and visualize/*.rb; need manual review) - Add StandardRB job to rake.yml CI
1 parent e3f8cef commit cdc668f

48 files changed

Lines changed: 721 additions & 653 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.github/workflows/rake.yml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,3 +44,14 @@ jobs:
4444
- name: RSpec
4545
working-directory: ruby
4646
run: bundle exec rspec
47+
48+
standard:
49+
name: StandardRB
50+
runs-on: ubuntu-latest
51+
steps:
52+
- uses: actions/checkout@v7
53+
- uses: ruby/setup-ruby@v1
54+
with:
55+
ruby-version: "3.4"
56+
bundler-cache: true
57+
- run: bundle exec standardrb

.standard.yml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# StandardRB config — enforce Ruby style on lib/, leave specs/bin/exe flexible for now.
2+
# Existing violations in lib/ were auto-fixed in this PR; remaining violations are
3+
# tracked in TODO.complete/06-standardrb-ruby-gems.md.
4+
ignore:
5+
- "bin/**/*"
6+
- "exe/**/*"
7+
- "spec/**/*"
8+
- "docs/**/*"
9+
- "reference-docs/**/*"
10+
- "pkg/**/*"
11+
- "vendor/**/*"

Gemfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,3 +38,4 @@ gem "iso-639-data"
3838
gem "iso-15924"
3939

4040
gem "simplecov", require: false, group: :test
41+
gem "standard", group: :development, require: false

Rakefile

Lines changed: 18 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -25,15 +25,15 @@ task :compile, [:compiler, :target] do |t, args|
2525

2626
maps = Interscript.maps
2727
maps = Interscript.exclude_maps(maps, compiler: compiler, platform: false)
28-
28+
2929
maps.each do |map|
30-
code = compiler.(map).code
30+
code = compiler.call(map).code
3131
File.write(args[:target] + "/" + map + "." + ext, code)
3232
maplist[map] = nil
3333
end
3434

3535
Interscript.maps(libraries: true).each do |map|
36-
code = compiler.(map).code
36+
code = compiler.call(map).code
3737
File.write(args[:target] + "/" + map + "." + ext, code)
3838
end
3939

@@ -45,12 +45,12 @@ task :generate_visualization_html do
4545
require "interscript"
4646
require "interscript/visualize"
4747

48-
FileUtils.rm_rf(dir = __dir__+"/visualizations/")
48+
FileUtils.rm_rf(dir = __dir__ + "/visualizations/")
4949
FileUtils.mkdir_p(dir)
5050

5151
Interscript.maps.each do |map|
52-
html = Interscript::Visualize.(map)
53-
File.write(dir+map+".html", html)
52+
html = Interscript::Visualize.call(map)
53+
File.write(dir + map + ".html", html)
5454
end
5555
end
5656

@@ -60,16 +60,15 @@ task :generate_metadata_json do
6060
require "interscript"
6161
require "interscript/compiler/javascript"
6262

63-
FileUtils.rm_rf(file = __dir__+"/metadata.json")
63+
FileUtils.rm_rf(file = __dir__ + "/metadata.json")
6464

6565
hash = Interscript.maps.map do |map|
6666
parsed_map = Interscript.parse(map)
6767
md = parsed_map.metadata.to_hash
6868
md["test"] = parsed_map.tests&.data&.first
6969
md["skip_js"] = Interscript.exclude_maps([map],
70-
compiler: Interscript::Compiler::Javascript,
71-
platform: false,
72-
).empty?
70+
compiler: Interscript::Compiler::Javascript,
71+
platform: false).empty?
7372
[map, md]
7473
end.to_h
7574

@@ -81,12 +80,12 @@ task :generate_json do
8180
require "json"
8281
require "interscript"
8382

84-
FileUtils.rm_rf(dir = __dir__+"/json/")
83+
FileUtils.rm_rf(dir = __dir__ + "/json/")
8584
FileUtils.mkdir_p(dir)
8685

8786
(Interscript.maps + Interscript.maps(libraries: true)).each do |map|
8887
json = JSON.pretty_generate(Interscript.parse(map).to_hash)
89-
File.write(dir+map+".json", json)
88+
File.write(dir + map + ".json", json)
9089
end
9190
end
9291

@@ -96,14 +95,14 @@ task :generate_visualization_json do
9695
require "json"
9796
require "interscript/visualize"
9897

99-
FileUtils.rm_rf(dir = __dir__+"/vis_json/")
98+
FileUtils.rm_rf(dir = __dir__ + "/vis_json/")
10099
FileUtils.mkdir_p(dir)
101100

102101
(Interscript.maps + Interscript.maps(libraries: true)).each do |map_name|
103102
map = Interscript.parse(map_name)
104103
map.stages.each do |stage_name, stage|
105104
json = JSON.pretty_generate(stage.to_visualization_array(map))
106-
File.write(dir+map_name+"_#{stage_name}.json", json)
105+
File.write(dir + map_name + "_#{stage_name}.json", json)
107106
end
108107
end
109108
end
@@ -113,7 +112,7 @@ task :generate_authority_json do
113112
require "json"
114113
require "iso-639-data"
115114

116-
FileUtils.rm_rf(dir = __dir__+"/auth_json/")
115+
FileUtils.rm_rf(dir = __dir__ + "/auth_json/")
117116
FileUtils.mkdir_p(dir)
118117

119118
%w[iso icao din].each do |auth|
@@ -122,10 +121,10 @@ task :generate_authority_json do
122121
end.sort.map do |map_name|
123122
map = Interscript.parse(map_name)
124123
tests = map.tests&.data&.first(2)&.transpose || []
125-
std, lang = map.metadata.data[:language].split(':')
124+
std, lang = map.metadata.data[:language].split(":")
126125

127126
{
128-
lang: std.end_with?("-3") ? Iso639Data.iso_639_3[lang]['Ref_Name'] : Iso639Data.iso_639_2[lang]['eng'],
127+
lang: std.end_with?("-3") ? Iso639Data.iso_639_3[lang]["Ref_Name"] : Iso639Data.iso_639_2[lang]["eng"],
129128
isoName: map.metadata.data[:name],
130129
systemName: map_name,
131130
samples: tests[0] || [],
@@ -135,8 +134,8 @@ task :generate_authority_json do
135134
end
136135

137136
json = JSON.pretty_generate(out)
138-
File.write(dir+auth+".json", json)
137+
File.write(dir + auth + ".json", json)
139138
end
140139
end
141140

142-
task :default => :spec
141+
task default: :spec

interscript.gemspec

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,21 @@
11
require_relative "lib/interscript/version"
22

33
Gem::Specification.new do |spec|
4-
spec.name = "interscript"
5-
spec.version = Interscript::VERSION
6-
spec.summary = "Interoperable script conversion systems"
7-
spec.description = "Interoperable script conversion systems."
8-
spec.authors = ["Ribose Inc."]
9-
spec.email = ["open.source@ribose.com"]
4+
spec.name = "interscript"
5+
spec.version = Interscript::VERSION
6+
spec.summary = "Interoperable script conversion systems"
7+
spec.description = "Interoperable script conversion systems."
8+
spec.authors = ["Ribose Inc."]
9+
spec.email = ["open.source@ribose.com"]
1010

11-
spec.homepage = "https://www.interscript.com"
12-
spec.license = "BSD-2-Clause"
11+
spec.homepage = "https://www.interscript.com"
12+
spec.license = "BSD-2-Clause"
1313
spec.required_ruby_version = ">= 3.3.0"
1414

15-
spec.metadata["homepage_uri"] = spec.homepage
16-
spec.metadata["source_code_uri"] = "https://github.com/interscript/interscript-ruby"
17-
spec.metadata["changelog_uri"] = "https://github.com/interscript/interscript-ruby/releases"
18-
spec.metadata["bug_tracker_uri"] = "https://github.com/interscript/interscript-ruby/issues"
15+
spec.metadata["homepage_uri"] = spec.homepage
16+
spec.metadata["source_code_uri"] = "https://github.com/interscript/interscript-ruby"
17+
spec.metadata["changelog_uri"] = "https://github.com/interscript/interscript-ruby/releases"
18+
spec.metadata["bug_tracker_uri"] = "https://github.com/interscript/interscript-ruby/issues"
1919
spec.metadata["rubygems_mfa_required"] = "true"
2020

2121
spec.files = Dir.chdir(__dir__) do
@@ -28,11 +28,11 @@ Gem::Specification.new do |spec|
2828
"*.gemspec"
2929
].select { |f| File.file?(f) }
3030
end
31-
spec.bindir = "exe"
32-
spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
31+
spec.bindir = "exe"
32+
spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
3333
spec.require_paths = ["lib"]
3434

3535
spec.add_dependency "thor"
36-
spec.add_dependency "interscript-maps", "~> #{Interscript::VERSION.split('.')[0, 2].join(".")}.0a"
36+
spec.add_dependency "interscript-maps", "~> #{Interscript::VERSION.split(".")[0, 2].join(".")}.0a"
3737
spec.add_dependency "text"
3838
end

lib/interscript.rb

Lines changed: 27 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ class MapLogicError < StandardError; end
1313

1414
class << self
1515
def load_path
16-
@load_path ||= ['.', *Interscript.map_locations]
16+
@load_path ||= [".", *Interscript.map_locations]
1717
end
1818

1919
def locate map_name
@@ -33,26 +33,26 @@ def parse(map_name)
3333
Interscript::DSL.parse(map_name)
3434
end
3535

36-
def load(system_code, maps={}, compiler: Interscript::Interpreter)
37-
maps[[system_code, compiler.name]] ||= compiler.(system_code)
36+
def load(system_code, maps = {}, compiler: Interscript::Interpreter)
37+
maps[[system_code, compiler.name]] ||= compiler.call(system_code)
3838
end
3939

4040
# Transliterates the string.
41-
def transliterate(system_code, string, maps={}, compiler: Interscript::Interpreter)
41+
def transliterate(system_code, string, maps = {}, compiler: Interscript::Interpreter)
4242
# The current best implementation is Interpreter
43-
load(system_code, maps, compiler: compiler).(string)
43+
load(system_code, maps, compiler: compiler).call(string)
4444
end
4545

4646
# Gives each possible value of the transliteration.
47-
def transliterate_each(system_code, string, maps={}, &block)
48-
load(system_code, maps).(string, each: true, &block)
47+
def transliterate_each(system_code, string, maps = {}, &block)
48+
load(system_code, maps).call(string, each: true, &block)
4949
end
5050

51-
def transliterate_file(system_code, input_file, output_file, maps={}, compiler: Interscript::Interpreter)
51+
def transliterate_file(system_code, input_file, output_file, maps = {}, compiler: Interscript::Interpreter)
5252
input = File.read(input_file)
5353
output = transliterate(system_code, input, maps, compiler: compiler)
5454

55-
File.open(output_file, 'w') do |f|
55+
File.open(output_file, "w") do |f|
5656
f.puts(output)
5757
end
5858

@@ -67,17 +67,17 @@ def transliterate_file(system_code, input_file, output_file, maps={}, compiler:
6767
def detect(source, destination, **kwargs)
6868
detector = Detector.new
6969
detector.set_from_kwargs(**kwargs)
70-
detector.(source, destination)
70+
detector.call(source, destination)
7171
end
7272

7373
def map_gems
74-
@map_gems ||= Gem.find_latest_files('interscript-maps.yaml').map do |i|
74+
@map_gems ||= Gem.find_latest_files("interscript-maps.yaml").map do |i|
7575
[i, YAML.load_file(i)]
7676
end.to_h
7777
end
7878

7979
def map_locations
80-
@map_locations ||= map_gems.map do |i,v|
80+
@map_locations ||= map_gems.map do |i, v|
8181
paths = v["paths"].dup
8282
paths += v["staging"] if ENV["INTERSCRIPT_STAGING"] && v["staging"]
8383

@@ -88,24 +88,24 @@ def map_locations
8888
end
8989

9090
def secryst_index_locations
91-
@secryst_index_locations ||= map_gems.map do |i,v|
91+
@secryst_index_locations ||= map_gems.map do |i, v|
9292
v["secryst-models"]
9393
end.compact.flatten
9494
end
9595

9696
def rababa_configs
97-
@rababa_configs ||= map_gems.map do |i,v|
97+
@rababa_configs ||= map_gems.map do |i, v|
9898
v["rababa-configs"]
99-
end.compact.inject({}) do |a,b|
99+
end.compact.inject({}) do |a, b|
100100
a.merge(b)
101101
end
102102
end
103103

104104
# This code is borrowed from Secryst and should end up in Rababa, but for now,
105105
# let's keep it here.
106106
def rababa_provision(model_name, model_uri)
107-
require 'fileutils'
108-
require 'open-uri'
107+
require "fileutils"
108+
require "open-uri"
109109

110110
# We provision the environment in the following way:
111111
# First, we try the RABABA_DATA environment variable. If that's available,
@@ -129,26 +129,26 @@ def rababa_provision(model_name, model_uri)
129129
break
130130
rescue
131131
end
132-
132+
133133
raise ExternalUtilError, "Can't find a writable path for Rababa. Consider setting a RABABA_DATA environment variable" unless write_path
134134

135135
model_path = "#{write_path}/model-#{model_name}.onnx"
136136

137137
# Redownload every hour
138138
if File.exist?(model_path) && File.mtime(model_path) + 3600 >= Time.now
139-
return model_path
139+
model_path
140140
else
141141
data = URI.open(model_uri, encoding: "BINARY").read
142142
File.binwrite(model_path, data)
143-
return model_path
143+
model_path
144144
end
145145
end
146146

147147
def map_aliases
148148
return @map_aliases if @map_aliases
149149

150150
@map_aliases = {}
151-
map_gems.each do |i,v|
151+
map_gems.each do |i, v|
152152
(v["aliases"] || {}).each do |code, value|
153153
value.each do |al, map|
154154
@map_aliases[al] = map["alias_to"]
@@ -172,9 +172,9 @@ def maps(basename: true, load_path: false, select: "*", libraries: false)
172172
# To be used by tests
173173
# and builders. It uses the `skip` directive in interscript-maps.yaml
174174
def exclude_maps(maps, compiler:, platform: true)
175-
map_gems.each do |i,v|
175+
map_gems.each do |i, v|
176176
[compiler.name, (Gem::Platform.local.os if platform)].compact.each do |name|
177-
skips = v.dig('skip', name) || []
177+
skips = v.dig("skip", name) || []
178178
skips.each do |skip|
179179
skip_re = /#{Regexp.escape(skip).gsub("\\*", ".*?")}/
180180
maps = maps.grep_v(skip_re)
@@ -186,12 +186,12 @@ def exclude_maps(maps, compiler:, platform: true)
186186
end
187187
end
188188

189-
require 'interscript/stdlib'
189+
require "interscript/stdlib"
190190

191191
require "interscript/compiler"
192192
require "interscript/interpreter"
193193

194-
require 'interscript/dsl'
195-
require 'interscript/node'
194+
require "interscript/dsl"
195+
require "interscript/node"
196196

197-
require 'interscript/detector'
197+
require "interscript/detector"

0 commit comments

Comments
 (0)