Skip to content

Commit

Permalink
Replace outdated rubocop with stnadardrb
Browse files Browse the repository at this point in the history
  • Loading branch information
bkeepers committed Jul 26, 2022
1 parent a28205d commit 8167f3b
Show file tree
Hide file tree
Showing 14 changed files with 70 additions and 97 deletions.
20 changes: 0 additions & 20 deletions .rubocop.yml

This file was deleted.

2 changes: 1 addition & 1 deletion Guardfile
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@ end
guard "rspec", cmd: "bundle exec rspec" do
watch(%r{^spec/.+_spec\.rb$})
watch(%r{^spec/spec_helper.rb$}) { "spec" }
watch(%r{^lib/(.+)\.rb$}) { |m| "spec/#{m[1]}_spec.rb" }
watch(%r{^lib/(.+)\.rb$}) { |m| "spec/#{m[1]}_spec.rb" }
end
19 changes: 11 additions & 8 deletions Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,17 @@ namespace "dotenv" do
Bundler::GemHelper.install_tasks name: "dotenv"
end

namespace "dotenv-rails" do
class DotenvRailsGemHelper < Bundler::GemHelper
def guard_already_tagged; end # noop
class DotenvRailsGemHelper < Bundler::GemHelper
def guard_already_tagged
# noop
end

def tag_version; end # noop
def tag_version
# noop
end
end

namespace "dotenv-rails" do
DotenvRailsGemHelper.install_tasks name: "dotenv-rails"
end

Expand All @@ -24,11 +28,10 @@ require "rspec/core/rake_task"

desc "Run all specs"
RSpec::Core::RakeTask.new(:spec) do |t|
t.rspec_opts = %w(--color)
t.rspec_opts = %w[--color]
t.verbose = false
end

require "rubocop/rake_task"
RuboCop::RakeTask.new
require "standard/rake"

task default: [:spec, :rubocop]
task default: [:spec, :standard]
12 changes: 6 additions & 6 deletions dotenv-rails.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@ require File.expand_path("../lib/dotenv/version", __FILE__)
require "English"

Gem::Specification.new "dotenv-rails", Dotenv::VERSION do |gem|
gem.authors = ["Brandon Keepers"]
gem.email = ["brandon@opensoul.org"]
gem.description = gem.summary = "Autoload dotenv in Rails."
gem.homepage = "https://github.com/bkeepers/dotenv"
gem.license = "MIT"
gem.files = `git ls-files lib | grep rails`.split(
gem.authors = ["Brandon Keepers"]
gem.email = ["brandon@opensoul.org"]
gem.description = gem.summary = "Autoload dotenv in Rails."
gem.homepage = "https://github.com/bkeepers/dotenv"
gem.license = "MIT"
gem.files = `git ls-files lib | grep rails`.split(
$OUTPUT_RECORD_SEPARATOR
) + ["README.md", "LICENSE"]

Expand Down
16 changes: 8 additions & 8 deletions dotenv.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,17 @@ require File.expand_path("../lib/dotenv/version", __FILE__)
require "English"

Gem::Specification.new "dotenv", Dotenv::VERSION do |gem|
gem.authors = ["Brandon Keepers"]
gem.email = ["brandon@opensoul.org"]
gem.description = gem.summary = "Loads environment variables from `.env`."
gem.homepage = "https://github.com/bkeepers/dotenv"
gem.license = "MIT"
gem.authors = ["Brandon Keepers"]
gem.email = ["brandon@opensoul.org"]
gem.description = gem.summary = "Loads environment variables from `.env`."
gem.homepage = "https://github.com/bkeepers/dotenv"
gem.license = "MIT"

gem_files = `git ls-files README.md LICENSE lib bin | grep -v rails`
gem.files = gem_files.split($OUTPUT_RECORD_SEPARATOR)
gem_files = `git ls-files README.md LICENSE lib bin | grep -v rails`
gem.files = gem_files.split($OUTPUT_RECORD_SEPARATOR)
gem.executables = gem.files.grep(%r{^bin/}).map { |f| File.basename(f) }

gem.add_development_dependency "rake"
gem.add_development_dependency "rspec"
gem.add_development_dependency "rubocop", "~>0.40.0"
gem.add_development_dependency "standard"
end
2 changes: 1 addition & 1 deletion lib/dotenv/missing_keys.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ class Error < StandardError; end

class MissingKeys < Error # :nodoc:
def initialize(keys)
key_word = "key#{keys.size > 1 ? 's' : ''}"
key_word = "key#{keys.size > 1 ? "s" : ""}"
super("Missing required configuration #{key_word}: #{keys.inspect}")
end
end
Expand Down
7 changes: 3 additions & 4 deletions lib/dotenv/parser.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class Parser
(?:^|\A) # beginning of line
\s* # leading whitespace
(?:export\s+)? # optional export
([\w\.]+) # key
([\w.]+) # key
(?:\s*=\s*?|:\s+?) # separator
( # optional value begin
\s*'(?:\\'|[^'])*' # single quoted value
Expand Down Expand Up @@ -72,8 +72,7 @@ def parse_value(value)
value = value.strip.sub(/\A(['"])(.*)\1\z/m, '\2')
maybe_quote = Regexp.last_match(1)
value = unescape_value(value, maybe_quote)
value = perform_substitutions(value, maybe_quote)
value
perform_substitutions(value, maybe_quote)
end

def unescape_characters(value)
Expand All @@ -85,7 +84,7 @@ def expand_newlines(value)
end

def variable_not_set?(line)
!line.split[1..-1].all? { |var| @hash.member?(var) }
!line.split[1..].all? { |var| @hash.member?(var) }
end

def unescape_value(value, maybe_quote)
Expand Down
4 changes: 2 additions & 2 deletions lib/dotenv/substitutions/command.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class << self
\$ # literal $
(?<cmd> # collect command content for eval
\( # require opening paren
([^()]|\g<cmd>)+ # allow any number of non-parens, or balanced
(?:[^()]|\g<cmd>)+ # allow any number of non-parens, or balanced
# parens (by nesting the <cmd> expression
# recursively)
\) # require closing paren
Expand All @@ -28,7 +28,7 @@ def call(value, _env, _is_load)

if $LAST_MATCH_INFO[:backslash]
# Command is escaped, don't replace it.
$LAST_MATCH_INFO[0][1..-1]
$LAST_MATCH_INFO[0][1..]
else
# Execute the command and return the value
`#{command}`.chomp
Expand Down
10 changes: 3 additions & 7 deletions lib/dotenv/substitutions/variable.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,7 @@ class << self
/xi

def call(value, env, is_load)
combined_env = if is_load
env.merge(ENV)
else
ENV.to_h.merge(env)
end
combined_env = is_load ? env.merge(ENV) : ENV.to_h.merge(env)
value.gsub(VARIABLE) do |variable|
match = $LAST_MATCH_INFO
substitute(match, variable, combined_env)
Expand All @@ -33,8 +29,8 @@ def call(value, env, is_load)
private

def substitute(match, variable, env)
if match[1] == '\\'
variable[1..-1]
if match[1] == "\\"
variable[1..]
elsif match[3]
env.fetch(match[3], "")
else
Expand Down
1 change: 0 additions & 1 deletion spec/dotenv/cli_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,6 @@ def run(*args)
end
it "templates variables" do
@input = StringIO.new("FOO=BAR\nFOO2=BAR2")
# rubocop:disable LineLength
allow(File).to receive(:open).with(@origin_filename, "r").and_yield(@input)
allow(File).to receive(:open).with(@template_filename, "w").and_yield(@buffer)
# call the function that writes to the file
Expand Down
8 changes: 3 additions & 5 deletions spec/dotenv/parser_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -113,13 +113,11 @@ def env(string)
export OPTION_A')).to eql("OPTION_A" => "2")
end

it "allows export line if you want to do it that way and checks for unset"\
" variables" do
it "allows export line if you want to do it that way and checks for unset variables" do
expect do
env('OPTION_A=2
export OH_NO_NOT_SET')
end.to raise_error(Dotenv::FormatError, 'Line "export OH_NO_NOT_SET"'\
" has an unset variable")
end.to raise_error(Dotenv::FormatError, 'Line "export OH_NO_NOT_SET" has an unset variable')
end

it "expands newlines in quoted strings" do
Expand Down Expand Up @@ -276,7 +274,7 @@ def env(string)

# This functionality is not supported on JRuby or Rubinius
if (!defined?(RUBY_ENGINE) || RUBY_ENGINE != "jruby") &&
!defined?(Rubinius)
!defined?(Rubinius)
it "substitutes shell variables within interpolated shell commands" do
expect(env(%(VAR1=var1\ninterp=$(echo "VAR1 is $VAR1")))["interp"])
.to eql("VAR1 is var1")
Expand Down
20 changes: 10 additions & 10 deletions spec/dotenv/rails_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,20 @@
require "rails"
require "dotenv/rails"

describe Dotenv::Railtie do
# Fake watcher for Spring
class SpecWatcher
attr_reader :items
# Fake watcher for Spring
class SpecWatcher
attr_reader :items

def initialize
@items = []
end
def initialize
@items = []
end

def add(*items)
@items |= items
end
def add(*items)
@items |= items
end
end

describe Dotenv::Railtie do
before do
Rails.env = "test"
allow(Rails).to receive(:root)
Expand Down
44 changes: 21 additions & 23 deletions spec/dotenv_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@
let(:env_files) { [] }

it "defaults to .env" do
expect(Dotenv::Environment).to receive(:new).with(expand(".env"),
anything)
expect(Dotenv::Environment).to receive(:new).with(expand(".env"), anything)
.and_return(double(apply: {}, apply!: {}))
subject
end
Expand All @@ -33,13 +32,13 @@
let(:env_files) { [".env", fixture_path("plain.env")] }

let(:expected) do
{ "OPTION_A" => "1",
"OPTION_B" => "2",
"OPTION_C" => "3",
"OPTION_D" => "4",
"OPTION_E" => "5",
"PLAIN" => "true",
"DOTENV" => "true" }
{"OPTION_A" => "1",
"OPTION_B" => "2",
"OPTION_C" => "3",
"OPTION_D" => "4",
"OPTION_E" => "5",
"PLAIN" => "true",
"DOTENV" => "true"}
end

it "loads all files" do
Expand Down Expand Up @@ -189,11 +188,10 @@
before { Dotenv.load(*env_files) }

it "raises exception with not defined mandatory ENV keys" do
expect { Dotenv.require_keys("BOM", "TEST") }.to \
raise_error(
Dotenv::MissingKeys,
'Missing required configuration key: ["TEST"]'
)
expect { Dotenv.require_keys("BOM", "TEST") }.to raise_error(
Dotenv::MissingKeys,
'Missing required configuration key: ["TEST"]'
)
end
end

Expand All @@ -206,7 +204,7 @@

it "defaults to .env" do
expect(Dotenv::Environment).to receive(:new).with(expand(".env"),
anything)
anything)
subject
end
end
Expand All @@ -226,13 +224,13 @@
let(:env_files) { [".env", fixture_path("plain.env")] }

let(:expected) do
{ "OPTION_A" => "1",
"OPTION_B" => "2",
"OPTION_C" => "3",
"OPTION_D" => "4",
"OPTION_E" => "5",
"PLAIN" => "true",
"DOTENV" => "true" }
{"OPTION_A" => "1",
"OPTION_B" => "2",
"OPTION_C" => "3",
"OPTION_D" => "4",
"OPTION_E" => "5",
"PLAIN" => "true",
"DOTENV" => "true"}
end

it "does not modify ENV" do
Expand Down Expand Up @@ -270,7 +268,7 @@
end

it "fixture file has UTF-8 BOM" do
contents = File.open(subject, "rb", &:read).force_encoding("UTF-8")
contents = File.binread(subject).force_encoding("UTF-8")
expect(contents).to start_with("\xEF\xBB\xBF".force_encoding("UTF-8"))
end
end
Expand Down
2 changes: 1 addition & 1 deletion spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
RSpec.configure do |config|
# Restore the state of ENV after each spec
config.before { @env_keys = ENV.keys }
config.after { ENV.delete_if { |k, _v| !@env_keys.include?(k) } }
config.after { ENV.delete_if { |k, _v| !@env_keys.include?(k) } }
end

def fixture_path(name)
Expand Down

0 comments on commit 8167f3b

Please sign in to comment.