Skip to content

Commit

Permalink
Fix lints
Browse files Browse the repository at this point in the history
  • Loading branch information
schneems committed Jul 10, 2024
1 parent 47a1d24 commit 4c1db4c
Show file tree
Hide file tree
Showing 6 changed files with 48 additions and 53 deletions.
44 changes: 22 additions & 22 deletions lib/rundoc/cli.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,16 @@ module Defaults
attr_reader :execution_context, :after_build_context

def initialize(
source_path:,
io: $stdout,
cli_cmd: $0,
cli_args: $*,
dotenv_path: nil,
on_success_dir: nil,
on_failure_dir: nil,
output_filename: Defaults::OUTPUT_FILENAME,
screenshots_dir: Defaults::SCREENSHOTS_DIR
)
source_path:,
io: $stdout,
cli_cmd: $0,
cli_args: $*,
dotenv_path: nil,
on_success_dir: nil,
on_failure_dir: nil,
output_filename: Defaults::OUTPUT_FILENAME,
screenshots_dir: Defaults::SCREENSHOTS_DIR
)
@io = io
@execution_context = Rundoc::Context::Execution.new(
output_dir: Dir.mktmpdir,
Expand All @@ -34,7 +34,7 @@ def initialize(
@after_build_context = Context::AfterBuild.new(
output_dir: execution_context.output_dir,
screenshots_dir: execution_context.screenshots_dir,
output_markdown_path: @execution_context.output_dir.join(relative_path(output_filename)),
output_markdown_path: @execution_context.output_dir.join(relative_path(output_filename))
)
end

Expand All @@ -51,7 +51,7 @@ def initialize(
raise "Path must be relative but it is not: #{path}"
end

if path.each_filename.any? {|part| part == ".." }
if path.each_filename.any? { |part| part == ".." }
raise "path cannot contain `..` but it does: #{path}"
end
path
Expand All @@ -72,16 +72,16 @@ def load_dotenv
end

def prepend_cli_banner(contents)
<<~HEREDOC
<!-- STOP
This file was generated by a rundoc script, do not modify it.
<<~HEREDOC
<!-- STOP
This file was generated by a rundoc script, do not modify it.
Instead modify the rundoc script and re-run it.
Instead modify the rundoc script and re-run it.
Command: #{cli_cmd} #{cli_args.join(" ")}
STOP -->
#{contents}
HEREDOC
Command: #{cli_cmd} #{cli_args.join(" ")}
STOP -->
#{contents}
HEREDOC
end

def call
Expand All @@ -96,7 +96,7 @@ def call
Dir.chdir(execution_context.output_dir) do
parser = Rundoc::Parser.new(
source_contents,
context: execution_context,
context: execution_context
)
output = begin
parser.to_md
Expand Down Expand Up @@ -163,7 +163,7 @@ def call
io.puts "## RUNdoc is done"
end

def copy_dir_contents(from: , to:)
def copy_dir_contents(from:, to:)
# Cannot use Pathname.join(".")
FileUtils.cp_r(File.join(from, "."), to)
end
Expand Down
2 changes: 1 addition & 1 deletion lib/rundoc/context/after_build.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ module Context
class AfterBuild
attr_reader :output_markdown_path, :screenshots_dir, :output_dir

def initialize(output_markdown_path:, screenshots_dir:, output_dir: )
def initialize(output_markdown_path:, screenshots_dir:, output_dir:)
@output_dir = output_dir
@screenshots_dir = screenshots_dir
@output_markdown_path = output_markdown_path
Expand Down
16 changes: 7 additions & 9 deletions lib/rundoc/context/execution.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,14 @@ module Context
class Execution
# The path to the source file
attr_reader :source_path,
# The directory containing the source file
:source_dir,
# The directory containing the source file
:source_dir,
# The directory we are actively manipulating
:output_dir,
# Directory to store screenshots, relative to output_dir
:screenshots_dir

# The directory we are actively manipulating
:output_dir,

# Directory to store screenshots, relative to output_dir
:screenshots_dir

def initialize(source_path: , output_dir:, screenshots_dir:)
def initialize(source_path:, output_dir:, screenshots_dir:)
@source_path = Pathname(source_path).expand_path
@source_dir = @source_path.parent
@output_dir = Pathname(output_dir).expand_path
Expand Down
8 changes: 4 additions & 4 deletions test/integration/after_build_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@ def test_modifies_directory_structure

io = StringIO.new

Rundoc::CLI::new(
Rundoc::CLI.new(
io: io,
source_path: source_path,
on_success_dir: dir.join("project"),
on_success_dir: dir.join("project")
).call

assert dir.join("project").join("lol").exist?
Expand Down Expand Up @@ -47,10 +47,10 @@ def test_modifies_directory_structure

io = StringIO.new

Rundoc::CLI::new(
Rundoc::CLI.new(
io: io,
source_path: source_path,
on_success_dir: dir.join("project"),
on_success_dir: dir.join("project")
).call

assert dir.join("project").join("rofl.txt").exist?
Expand Down
6 changes: 2 additions & 4 deletions test/integration/require_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ class IntegrationRequireTest < Minitest::Test
def test_require_embeds_results
Dir.mktmpdir do |dir|
Dir.chdir(dir) do

dir = Pathname(dir)
source_path = dir.join("RUNDOC.md")
source_path.write <<~EOF
Expand All @@ -21,7 +20,7 @@ def test_require_embeds_results

parsed = parse_contents(
source_path.read,
source_path: source_path,
source_path: source_path
)
actual = parsed.to_md.gsub(Rundoc::CodeSection::AUTOGEN_WARNING, "")
assert_equal "Hello World!", actual.strip
Expand All @@ -32,7 +31,6 @@ def test_require_embeds_results
def test_require_runs_code_but_embeds_nothing_if_hidden
Dir.mktmpdir do |dir|
Dir.chdir(dir) do

dir = Pathname(dir)
source_path = dir.join("RUNDOC.md")
source_path.write <<~EOF
Expand All @@ -50,7 +48,7 @@ def test_require_runs_code_but_embeds_nothing_if_hidden

parsed = parse_contents(
source_path.read,
source_path: source_path,
source_path: source_path
)
actual = parsed.to_md.gsub(Rundoc::CodeSection::AUTOGEN_WARNING, "")
# Command was run
Expand Down
25 changes: 12 additions & 13 deletions test/test_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,22 +7,21 @@
require "mocha/minitest"
require "tmpdir"


class Minitest::Test
def parse_contents(
contents,
output_dir: Pathname("/dev/null"),
source_path: Pathname("/dev/null"),
screenshots_dir: Pathname("/dev/null")
)
context = Rundoc::Context::Execution.new(
output_dir: output_dir,
source_path: source_path,
screenshots_dir: screenshots_dir
)
Rundoc::Parser.new(
contents,
output_dir: Pathname("/dev/null"),
source_path: Pathname("/dev/null"),
screenshots_dir: Pathname("/dev/null")
context: context
)
context = Rundoc::Context::Execution.new(
output_dir: output_dir,
source_path: source_path,
screenshots_dir: screenshots_dir
)
Rundoc::Parser.new(
contents,
context: context
)
end
end

0 comments on commit 4c1db4c

Please sign in to comment.