ci-syntax-tool 0.1.0 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 12e0cbc5efe12dc146a5ede4094ea62f0137915d
4
- data.tar.gz: 480b4eff820df5aac1ad736330918492f5a9324b
3
+ metadata.gz: 48c6b5c42852bbebba0adf68bac910ef045c904a
4
+ data.tar.gz: 71fe5ab362375d55db9a71229e4d25c9d580a04a
5
5
  SHA512:
6
- metadata.gz: c77c377d030d48e67134ef124633a1d2307288cbe0f6f00cc5fdc9bd4636c966b530ad65bf2971b0ba2cdac55d055f9ec32da99c193fb661cf59fc2aed49b555
7
- data.tar.gz: 55f16c7324455770784844f16243c2038b2371e1cd1a95602658c3d122c815204458bd6507d2d0944850b91f3bcba8ef52fecee80009cf99a28baf4303eda837
6
+ metadata.gz: b25922cd44c509c9df3104439b67b783a907a7cfcbbf3c50523f0de06c137576e91bf89fe8784e409b2fbfe32d7dfc21d43025cdf2efa1d37cd9e7d52f4c124d
7
+ data.tar.gz: f1a026f1c4fe68acc04c2663acb75d7581cf82a01dbf955fab681f494321f854d1eaf5de0f54da8725fa6ebeb0c21214bfeba08a1f9dfd80f93300e1d91ed399
data/README.md CHANGED
@@ -64,6 +64,24 @@ This might be good enough for a commit hook.
64
64
 
65
65
  If a file doesn't have an extension that would match the usual glob, you can specify one or more filenames, bypassing the globbing mechanism. Use --lang to keep it restricted to only the language you know you want. Again, the default Progress format sends a report to STDOUT.
66
66
 
67
+ ## Rake Support
68
+
69
+ The gem includes a Rake Task, which you can use in your rakefiles.
70
+
71
+ require 'ci-syntax-tool/rake_task'
72
+
73
+ # Gives you a 'syntax' task, just like running CLI with defaults:
74
+ # all languages, Progress format to STDOUT
75
+ CI::Syntax::Tool::RakeTask.new()
76
+
77
+ # Bells and whistles - I like this for CI
78
+ CI::Syntax::Tool::RakeTask.new('myname') do |taskdef|
79
+ taskdef.formats = [ 'Progress', 'JUnit' ]
80
+ taskdef.outputs = [ '-', 'test/reports/syntax.xml' ]
81
+ taskdef.languages = [ 'YAML', 'Ruby' ] # Default all - only specify to restrict
82
+ taskdef.options = [ '--anything', '--else']
83
+ end
84
+
67
85
  ## Language Syntax Plugins
68
86
 
69
87
  So far, we support:
@@ -0,0 +1,74 @@
1
+
2
+ require 'rake'
3
+ require 'rake/tasklib'
4
+
5
+ module CI
6
+ module Syntax
7
+ module Tool
8
+
9
+ # Provides a custom rake task.
10
+ #
11
+ # require 'ci-syntax-tool/rake_task'
12
+ # CI::Syntax::Tool::RakeTask.new
13
+ class RakeTask < Rake::TaskLib
14
+ attr_accessor :name
15
+ attr_accessor :fail_on_error
16
+ attr_accessor :verbose
17
+ attr_accessor :languages
18
+ attr_accessor :outputs
19
+ attr_accessor :formats
20
+ attr_accessor :options
21
+
22
+ def initialize(*args, &task_block)
23
+ setup_ivars(args)
24
+
25
+ desc 'Run syntax checks' unless ::Rake.application.last_comment
26
+
27
+ task(name, *args) do |_, task_args|
28
+ RakeFileUtils.send(:verbose, verbose) do
29
+ if task_block
30
+ task_block.call(*[self, task_args].slice(0, task_block.arity))
31
+ end
32
+ run_main_task(verbose)
33
+ end
34
+ end
35
+ end
36
+
37
+ def run_main_task(verbose)
38
+ run_cli(verbose, full_options)
39
+ end
40
+
41
+ private
42
+
43
+ def run_cli(verbose, options)
44
+ require 'ci-syntax-tool'
45
+
46
+ cli_opts = CommandLine.new(options)
47
+ puts 'Running ci-syntax-tool...' if verbose
48
+ result = Checker.new(cli_opts).run
49
+ abort('Syntax checks failed!') if result != 0 && fail_on_error
50
+ end
51
+
52
+ def full_options
53
+ [].tap do |result|
54
+ result.concat(formats.map { |f| ['--format', f] }.flatten)
55
+ result.concat(outputs.map { |o| ['--output', o] }.flatten)
56
+ result.concat(languages.map { |l| ['--output', l] }.flatten)
57
+ result.concat(options)
58
+ end
59
+ end
60
+
61
+ def setup_ivars(args)
62
+ @name = args.shift || :syntax
63
+ @verbose = true
64
+ @fail_on_error = true
65
+ @languages = []
66
+ @formats = []
67
+ @options = []
68
+ @outputs = []
69
+ end
70
+
71
+ end
72
+ end
73
+ end
74
+ end
@@ -4,7 +4,7 @@ module CI
4
4
  # Simple container for namespacing the project. Here, just the
5
5
  # version string.
6
6
  module Tool
7
- VERSION = '0.1.0'
7
+ VERSION = '0.2.0'
8
8
  end
9
9
  end
10
10
  end
@@ -0,0 +1,16 @@
1
+ require 'ci-syntax-tool/rake_task'
2
+
3
+ # All defaults - should be 'syntax'
4
+ CI::Syntax::Tool::RakeTask.new
5
+
6
+
7
+ CI::Syntax::Tool::RakeTask.new('renamed')
8
+
9
+ desc 'Alt description'
10
+ CI::Syntax::Tool::RakeTask.new('altdesc')
11
+
12
+ CI::Syntax::Tool::RakeTask.new('prog-junit') do |t|
13
+ t.formats = [ 'Progress', 'JUnit' ]
14
+ t.outputs = [ '-', 'test/tmp/rake-out-1.out' ]
15
+ end
16
+
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ci-syntax-tool
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Clinton Wolfe
@@ -105,6 +105,7 @@ files:
105
105
  - lib/ci-syntax-tool/language/base.rb
106
106
  - lib/ci-syntax-tool/language/yaml.rb
107
107
  - lib/ci-syntax-tool/language_factory.rb
108
+ - lib/ci-syntax-tool/rake_task.rb
108
109
  - lib/ci-syntax-tool/result.rb
109
110
  - lib/ci-syntax-tool/version.rb
110
111
  - rubocop.yml
@@ -130,6 +131,7 @@ files:
130
131
  - test/fixtures/files/error/missing-array-element.yaml
131
132
  - test/fixtures/files/error/unquoted-jinja-template.yaml
132
133
  - test/fixtures/files/error/very-high-yaml-version.yaml
134
+ - test/fixtures/rakefiles/Rakefile
133
135
  - test/fixtures/require/invalid.rb
134
136
  - test/fixtures/require/mock_format.rb
135
137
  - test/fixtures/require/second.rb
@@ -188,6 +190,7 @@ test_files:
188
190
  - test/fixtures/files/error/missing-array-element.yaml
189
191
  - test/fixtures/files/error/unquoted-jinja-template.yaml
190
192
  - test/fixtures/files/error/very-high-yaml-version.yaml
193
+ - test/fixtures/rakefiles/Rakefile
191
194
  - test/fixtures/require/invalid.rb
192
195
  - test/fixtures/require/mock_format.rb
193
196
  - test/fixtures/require/second.rb