File tree 4 files changed +148
-0
lines changed
4 files changed +148
-0
lines changed Original file line number Diff line number Diff line change
1
+ # frozen_string_literal: true
2
+
3
+ require "rake"
4
+ require "rake/tasklib"
5
+
6
+ module SyntaxTree
7
+ module Rake
8
+ # A Rake task that runs check on a set of source files.
9
+ #
10
+ # Example:
11
+ #
12
+ # require 'syntax_tree/rake/check_task'
13
+ #
14
+ # SyntaxTree::Rake::CheckTask.new do |t|
15
+ # t.source_files = '{app,config,lib}/**/*.rb'
16
+ # end
17
+ #
18
+ # This will create task that can be run with:
19
+ #
20
+ # rake stree_check
21
+ #
22
+ class CheckTask < ::Rake ::TaskLib
23
+ # Name of the task.
24
+ # Defaults to :stree_check.
25
+ attr_accessor :name
26
+
27
+ # Glob pattern to match source files.
28
+ # Defaults to 'lib/**/*.rb'.
29
+ attr_accessor :source_files
30
+
31
+ def initialize ( name = :stree_check )
32
+ @name = name
33
+ @source_files = "lib/**/*.rb"
34
+
35
+ yield self if block_given?
36
+ define_task
37
+ end
38
+
39
+ private
40
+
41
+ def define_task
42
+ desc "Runs `stree check` over source files"
43
+ task ( name ) { run_task }
44
+ end
45
+
46
+ def run_task
47
+ SyntaxTree ::CLI . run ( [ "check" , source_files ] . compact )
48
+ end
49
+ end
50
+ end
51
+ end
Original file line number Diff line number Diff line change
1
+ # frozen_string_literal: true
2
+
3
+ require "rake"
4
+ require "rake/tasklib"
5
+
6
+ module SyntaxTree
7
+ module Rake
8
+ # A Rake task that runs format on a set of source files.
9
+ #
10
+ # Example:
11
+ #
12
+ # require 'syntax_tree/rake/write_task'
13
+ #
14
+ # SyntaxTree::Rake::WriteTask.new do |t|
15
+ # t.source_files = '{app,config,lib}/**/*.rb'
16
+ # end
17
+ #
18
+ # This will create task that can be run with:
19
+ #
20
+ # rake stree_write
21
+ #
22
+ class WriteTask < ::Rake ::TaskLib
23
+ # Name of the task.
24
+ # Defaults to :stree_write.
25
+ attr_accessor :name
26
+
27
+ # Glob pattern to match source files.
28
+ # Defaults to 'lib/**/*.rb'.
29
+ attr_accessor :source_files
30
+
31
+ def initialize ( name = :stree_write )
32
+ @name = name
33
+ @source_files = "lib/**/*.rb"
34
+
35
+ yield self if block_given?
36
+ define_task
37
+ end
38
+
39
+ private
40
+
41
+ def define_task
42
+ desc "Runs `stree write` over source files"
43
+ task ( name ) { run_task }
44
+ end
45
+
46
+ def run_task
47
+ SyntaxTree ::CLI . run ( [ "write" , source_files ] . compact )
48
+ end
49
+ end
50
+ end
51
+ end
Original file line number Diff line number Diff line change
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "test_helper"
4
+ require "syntax_tree/rake/check_task"
5
+
6
+ module SyntaxTree
7
+ class CheckTaskTest < Minitest ::Test
8
+ Invoke = Struct . new ( :args )
9
+
10
+ def test_task
11
+ source_files = "{app,config,lib}/**/*.rb"
12
+
13
+ SyntaxTree ::Rake ::CheckTask . new { |t | t . source_files = source_files }
14
+
15
+ invoke = nil
16
+ SyntaxTree ::CLI . stub ( :run , -> ( args ) { invoke = Invoke . new ( args ) } ) do
17
+ ::Rake ::Task [ "stree_check" ] . invoke
18
+ end
19
+
20
+ assert_equal ( [ "check" , source_files ] , invoke . args )
21
+ end
22
+ end
23
+ end
Original file line number Diff line number Diff line change
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "test_helper"
4
+ require "syntax_tree/rake/write_task"
5
+
6
+ module SyntaxTree
7
+ class WriteTaskTest < Minitest ::Test
8
+ Invoke = Struct . new ( :args )
9
+
10
+ def test_task
11
+ source_files = "{app,config,lib}/**/*.rb"
12
+
13
+ SyntaxTree ::Rake ::WriteTask . new { |t | t . source_files = source_files }
14
+
15
+ invoke = nil
16
+ SyntaxTree ::CLI . stub ( :run , -> ( args ) { invoke = Invoke . new ( args ) } ) do
17
+ ::Rake ::Task [ "stree_write" ] . invoke
18
+ end
19
+
20
+ assert_equal ( [ "write" , source_files ] , invoke . args )
21
+ end
22
+ end
23
+ end
You can’t perform that action at this time.
0 commit comments