Skip to content

Commit ca16c0a

Browse files
committed
Lint before syncing
I'm not proud of the code here, but cli ui sucks and makes outputting stuff a pain in the ass. What this does is effectively just run the linter on the changed file before we sync it, most of the changes are just making the canvas gem not output so that we can manage in the context of the new spin group or something?
1 parent c2ff50d commit ca16c0a

File tree

2 files changed

+20
-8
lines changed

2 files changed

+20
-8
lines changed

lib/canvas/dev_server/syncer.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@ def sync_file(path)
88
return if path.nil?
99
relative_path = Pathname.new(path).relative_path_from(Dir.getwd)
1010
CLI::UI::Spinner.spin("Syncing #{relative_path}") {
11+
error_checks = Canvas::Lint.new.run([relative_path.to_s], nil)
12+
13+
raise "Failed Linting #{relative_path}" if error_checks.any?
14+
1115
Canvas::Client.new.post(
1216
"/test_site_sync",
1317
body: {

lib/canvas/lint.rb

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,29 +5,37 @@
55
module Canvas
66
#:documented:
77
class Lint
8-
def run(scoped_files)
9-
output_context = CLI::UI::SpinGroup.new(auto_debrief: false)
10-
8+
def run(scoped_files, output_context = CLI::UI::SpinGroup.new(auto_debrief: false))
119
@checks = Checks.registered.map(&:new)
1210

1311
@checks.each do |check|
1412
run_check(check, output_context, scoped_files)
1513
end
1614

17-
output_context.wait
15+
if output_context
16+
output_context.wait
17+
end
1818

1919
if @checks.any?(&:failed?)
20-
puts debrief_message
21-
exit 1
20+
if output_context
21+
puts debrief_message
22+
exit 1
23+
else
24+
return @checks.filter(&:failed?)
25+
end
2226
end
2327
end
2428

2529
private
2630

2731
def run_check(check, output_context, scoped_files)
28-
output_context.add(check.class.name) do
32+
if output_context
33+
output_context.add(check.class.name) do
34+
check.run(scoped_files)
35+
raise if check.offenses.any?
36+
end
37+
else
2938
check.run(scoped_files)
30-
raise if check.offenses.any?
3139
end
3240
end
3341

0 commit comments

Comments
 (0)