Skip to content

Commit

Permalink
Update build
Browse files Browse the repository at this point in the history
  • Loading branch information
robotdana committed Jan 25, 2025
1 parent b9456b8 commit f5be681
Show file tree
Hide file tree
Showing 23 changed files with 215 additions and 199 deletions.
42 changes: 12 additions & 30 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,38 +7,21 @@ jobs:
strategy:
fail-fast: false
matrix:
ruby: [2.5, 2.6, 2.7, '3.0', 3.1, 3.2, 3.3, ruby-head]
ruby: [2.5, 2.6, 2.7, '3.0', 3.1, 3.2, 3.3, 3.4, ruby-head]
continue-on-error: ${{ endsWith(matrix.ruby, 'head') }}
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- uses: ruby/setup-ruby@v1
with:
ruby-version: ${{ matrix.ruby }}
bundler-cache: true
- run: gem install did_you_mean; bundle exec rspec

rspec_no_did_you_mean:
strategy:
fail-fast: false
matrix:
ruby: [2.5, 2.6]
continue-on-error: ${{ endsWith(matrix.ruby, 'head') }}
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: ruby/setup-ruby@v1
with:
ruby-version: ${{ matrix.ruby }}
bundler-cache: true
- run: bundle exec rspec --tag ~did_you_mean
env:
DID_YOU_MEAN: '0'
- run: bundle exec rspec

coverage:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- uses: ruby/setup-ruby@v1
with:
ruby-version: 3.3
Expand All @@ -55,40 +38,39 @@ jobs:
rubocop:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- uses: ruby/setup-ruby@v1
with:
ruby-version: 3.3
ruby-version: 3.4
bundler-cache: true
- run: bundle exec rubocop

spellr:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- uses: ruby/setup-ruby@v1
with:
ruby-version: 3.3
ruby-version: 3.4
bundler-cache: true
- run: bundle exec spellr

leftovers:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- uses: ruby/setup-ruby@v1
with:
ruby-version: 3.3
ruby-version: 3.4
bundler-cache: true
- run: bundle exec leftovers

build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- uses: ruby/setup-ruby@v1
with:
ruby-version: 3.3
ruby-version: 3.4
bundler-cache: true
- run: bundle exec rake build

3 changes: 3 additions & 0 deletions .spellr_wordlists/english.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
abc
addable
alexdeng
alnum
arg
arglist
Expand Down Expand Up @@ -122,6 +123,7 @@ punycode
pwd
rakefile
rdoc
readline
readme
redisplay
regexps
Expand All @@ -142,6 +144,7 @@ stdin
stdlib
stdout
str
stringio
stringscanner
strscan
struct
Expand Down
1 change: 1 addition & 0 deletions .spellr_wordlists/ruby.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
cov
damerau
kwarg
matchdata
nocov
Expand Down
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
# v0.12.0

- Require stringio (thanks @alexdeng-mp)
- Remove implicit did_you_mean dependency, inline and specialize what of did_you_mean this was using.
- Update rubies this is tested with
- Replace readline dependency with reline

# v0.11.0
- Remove explicit did_you_mean dependency
(if you want the suggestions in ruby 2.5 & 2.6, you'll need to add did_you_mean to your Gemfile directly).
Expand Down
20 changes: 10 additions & 10 deletions bin/generate/ruby
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,15 @@ class RubyWords
}.freeze

STDLIBS = %w{
abbrev base64 benchmark bigdecimal cgi cmath coverage csv date delegate digest
drb/drb e2mmap English erb etc expect fcntl fiddle fileutils find forwardable
getoptlong io/console io/nonblock io/wait ipaddr irb json logger matrix mkmf
monitor mutex_m net/ftp net/http net/imap net/pop net/smtp net/telnet nkf mathn
objspace observer open-uri open3 openssl optionparser optparse ostruct pathname
pp prettyprint prime pstore psych pty racc/parser readline resolv ripper rss scanf
sdbm securerandom set shell shellwords singleton socket stringio strscan sync syslog
tempfile thwait time timeout tmpdir tracer tsort uri weakref webrick yaml zlib
bundler dbm gdbm racc rake rdoc resolv-replace rexml/document rinda/ring rubygems
base64 bigdecimal cgi cmath coverage date delegate digest
e2mmap English erb etc expect fcntl fileutils find forwardable
io/console io/nonblock io/wait ipaddr json mkmf
monitor net/http net/telnet mathn
objspace open-uri open3 openssl optionparser optparse pathname
pp prettyprint psych pty racc/parser resolv ripper scanf
sdbm securerandom set shell shellwords singleton socket stringio strscan sync
tempfile thwait time timeout tmpdir tracer tsort uri weakref yaml zlib
bundler dbm gdbm racc rake rexml/document rubygems
}.freeze

# spellr:disable
Expand Down Expand Up @@ -117,7 +117,7 @@ class RubyWords
def require_stdlibs
STDLIBS.each do |lib|
require lib
rescue LoadError
rescue LoadError, TypeError
puts "can't load #{lib}"
end
end
Expand Down
1 change: 1 addition & 0 deletions bin/generate/util/write.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# frozen_string_literal: true

require 'pathname'
require 'stringio'
require_relative '../../../lib/spellr/wordlist'

module Write
Expand Down
2 changes: 1 addition & 1 deletion lib/spellr/autocorrect_reporter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ def total
end

def handle_replace(token)
replacement = ::Spellr::Suggester.suggestions(token).first
replacement = ::Spellr::Suggester.suggestions(token, 1).first
return increment(:total_unfixed) unless replacement

token.replace(replacement)
Expand Down
4 changes: 2 additions & 2 deletions lib/spellr/interactive.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ def call(token, only_prompt: false)

super(token) unless only_prompt

suggestions = ::Spellr::Suggester.fast_suggestions(token)
suggestions = ::Spellr::Suggester.fast_suggestions(token, 5)
print_suggestions(suggestions) unless only_prompt

prompt(token, suggestions)
Expand Down Expand Up @@ -107,7 +107,7 @@ def clear_line(lines = 1)
print "\r\e[K"
(lines - 1).times do
sleep 0.01
print "\r\e[1T\e[2K"
print "\r\e[0m\e[1T\e[2K"
end
end

Expand Down
22 changes: 9 additions & 13 deletions lib/spellr/interactive_replacement.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# frozen_string_literal: true

require 'readline'
require 'reline'
require_relative 'string_format'

module Spellr
Expand All @@ -15,8 +15,8 @@ def initialize(token, reporter)
@token = token
@token_highlight = red(token)
@reporter = reporter
Readline.input = reporter.output.stdin
Readline.output = reporter.output.stdout
Reline.input = reporter.output.stdin
Reline.output = reporter.output.stdout
end

def global_replace
Expand Down Expand Up @@ -44,9 +44,9 @@ def ask_replacement
end

def prompt_replacement
Readline.pre_input_hook = -> { pre_input_hook(token) }
prompt = " Replace #{'all ' if global?}#{token_highlight} with: \e[32m"
Readline.readline(prompt)
Reline.pre_input_hook = -> { pre_input_hook(token) }
prompt = " Replace #{'all ' if global?}#{token_highlight} with: "
Reline.readline(prompt)
rescue Interrupt
handle_ctrl_c
end
Expand All @@ -70,19 +70,15 @@ def replace

def handle_ctrl_c
print "\e[0m"
reporter.clear_line(4)
reporter.clear_line(5)
reporter.call(token, only_prompt: true)
end

private

def pre_input_hook(value)
Readline.refresh_line
Readline.insert_text value.to_s
Readline.redisplay

# Remove the hook right away.
Readline.pre_input_hook = nil
Reline.insert_text value.to_s
Reline.pre_input_hook = nil
end

def puts(str)
Expand Down
12 changes: 3 additions & 9 deletions lib/spellr/null_suggester.rb
Original file line number Diff line number Diff line change
@@ -1,25 +1,19 @@
# frozen_string_literal: true

module Spellr
class NullSuggester
module NullSuggester
class << self
def suggestions(_token)
def suggestions(_token, _limit = 0)
[]
end

def fast_suggestions(_token)
def fast_suggestions(_token, _limit = 0)
[]
end

def slow?
true
end
end

def initialize(_wordlist); end

def suggestions(_term)
[]
end
end
end
1 change: 1 addition & 0 deletions lib/spellr/output_stubbed.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# frozen_string_literal: true

require 'stringio'
require_relative 'output'

module Spellr
Expand Down
Loading

0 comments on commit f5be681

Please sign in to comment.