appium_doc_lint 0.0.1

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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: e81bae7396d3274bda69140ee465c9c581afe2cb
4
+ data.tar.gz: 522aa1992b52fb5763cc98217f3bd1e8d352d4f1
5
+ SHA512:
6
+ metadata.gz: 6bc03d6856b7a710dcf8398341ce5af44511866cfa92b8a5919fdd7543f4b24d005bbdf5c1769645cad7223aca722312a642b467be74edf0dfa783e9298eeed6
7
+ data.tar.gz: b1abb318bfe3c668a01c947b618a601a2b000dd05ce3ac44d65f37b6b9a2e6280e473e0213d18990e3aa91f998d5f71e3e8a6e0b7fc7ba01e5f9db6bcd97e760
data/.gitignore ADDED
@@ -0,0 +1,36 @@
1
+ .*
2
+ *.lock
3
+ *.gem
4
+ *.rbc
5
+ /.config
6
+ /coverage/
7
+ /InstalledFiles
8
+ /pkg/
9
+ /spec/reports/
10
+ /test/tmp/
11
+ /test/version_tmp/
12
+ /tmp/
13
+
14
+ ## Specific to RubyMotion:
15
+ .dat*
16
+ .repl_history
17
+ build/
18
+
19
+ ## Documentation cache and generated files:
20
+ /.yardoc/
21
+ /_yardoc/
22
+ /doc/
23
+ /rdoc/
24
+
25
+ ## Environment normalisation:
26
+ /.bundle/
27
+ /lib/bundler/man/
28
+
29
+ # for a library or gem, you might want to ignore these files since the code is
30
+ # intended to run in multiple environments; otherwise, check them in:
31
+ # Gemfile.lock
32
+ # .ruby-version
33
+ # .ruby-gemset
34
+
35
+ # unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
36
+ .rvmrc
data/.travis.yml ADDED
@@ -0,0 +1,3 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.1.1
data/Gemfile ADDED
@@ -0,0 +1,2 @@
1
+ source 'https://rubygems.org'
2
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,201 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "{}"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright {yyyy} {name of copyright owner}
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
data/README.md ADDED
@@ -0,0 +1,4 @@
1
+ appium_doc_lint [![Build Status](https://travis-ci.org/appium/appium_doc_lint.svg?branch=master)](https://travis-ci.org/appium/appium_doc_lint)
2
+ ===============
3
+
4
+ lint tool to check for common issues in the appium docs before publishing with Slate
data/Rakefile ADDED
@@ -0,0 +1,167 @@
1
+ # encoding: utf-8
2
+ # ruby_console Rakefile
3
+ require 'rubygems'
4
+ require 'rake'
5
+ require 'date'
6
+ require 'posix/spawn'
7
+
8
+ # rspec
9
+ require 'rspec'
10
+ require 'rspec/core/rake_task'
11
+ RSpec::Core::RakeTask.new :spec
12
+ task :default => :spec
13
+
14
+ # Defines gem name.
15
+ def repo_name; 'appium_doc_lint'; end # the rubygem name
16
+ def gh_name; 'appium_doc_lint'; end # the name as used on github.com
17
+ def version_file; File.expand_path Dir.glob("lib/#{repo_name}/**/version.rb").first; end
18
+ def version_rgx; /VERSION = '([^']+)'/m; end
19
+
20
+ def version
21
+ @version = @version || File.read(version_file).match(version_rgx)[1]
22
+ end
23
+
24
+ def bump
25
+ data = File.read version_file
26
+
27
+ v_line = data.match version_rgx
28
+ d_line = data.match /DATE\s*=\s*'([^']+)'/m
29
+
30
+ old_v = v_line[0]
31
+ old_d = d_line[0]
32
+
33
+ old_num = v_line[1]
34
+ new_num = old_num.split('.')
35
+ new_num[-1] = new_num[-1].to_i + 1
36
+ new_num = new_num.join '.'
37
+
38
+ new_v = old_v.sub old_num, new_num
39
+ puts "#{old_num} -> #{new_num}"
40
+
41
+ old_date = d_line[1]
42
+ new_date = Date.today.to_s
43
+ new_d = old_d.sub old_date, new_date
44
+ puts "#{old_date} -> #{new_date}" unless old_date == new_date
45
+
46
+ data.sub! old_v, new_v
47
+ data.sub! old_d, new_d
48
+
49
+ File.write version_file, data
50
+ end
51
+
52
+ desc 'Bump the version number and update the date.'
53
+ task :bump do
54
+ bump
55
+ end
56
+
57
+ def tag_exists tag_name
58
+ cmd = %Q(git branch -a --contains "#{tag_name}")
59
+ POSIX::Spawn::Child.new(cmd).out.include? '* master'
60
+ end
61
+
62
+ # Inspired by Gollum's Rakefile
63
+ desc 'Build and release a new gem to rubygems.org'
64
+ task :release => :gem do
65
+ unless `git branch`.include? '* master'
66
+ puts 'Master branch required to release.'
67
+ exit!
68
+ end
69
+
70
+ # Commit then pull before pushing.
71
+ tag_name = "v#{version}"
72
+ raise 'Tag already exists!' if tag_exists tag_name
73
+
74
+ # Commit then pull before pushing.
75
+ sh "git commit --allow-empty -am 'Release #{version}'"
76
+ sh 'git pull'
77
+ sh "git tag #{tag_name}"
78
+ # update notes now that there's a new tag
79
+ Rake::Task['notes'].execute
80
+ sh "git commit --allow-empty -am 'Update release notes'"
81
+ sh 'git push origin master'
82
+ sh "git push origin #{tag_name}"
83
+ sh "gem push #{repo_name}-#{version}.gem"
84
+ end
85
+
86
+ desc 'Build and release a new gem to rubygems.org (same as release)'
87
+ task :publish => :release do
88
+ end
89
+
90
+ desc 'Build a new gem'
91
+ task :gem do
92
+ `chmod 0600 ~/.gem/credentials`
93
+ sh "gem build #{repo_name}.gemspec"
94
+ end
95
+
96
+ desc 'Build a new gem (same as gem task)'
97
+ task :build => :gem do
98
+ end
99
+
100
+ desc 'Uninstall gem'
101
+ task :uninstall do
102
+ cmd = "gem uninstall -aIx #{repo_name}"
103
+ # rescue on gem not installed error.
104
+ begin; sh "#{cmd}"; rescue; end
105
+ end
106
+
107
+ desc 'Install gem'
108
+ task :install => [ :gem, :uninstall ] do
109
+ sh "gem install --no-rdoc --no-ri --local #{repo_name}-#{version}.gem"
110
+ end
111
+
112
+ desc 'Update release notes'
113
+ task :notes do
114
+ tag_sort = ->(tag1,tag2) do
115
+ begin
116
+ tag1_numbers = tag1.match(/\.?v(\d+\.\d+\.\d+)$/)[1].split('.').map! { |n| n.to_i }
117
+ tag2_numbers = tag2.match(/\.?v(\d+\.\d+\.\d+)$/)[1].split('.').map! { |n| n.to_i }
118
+ tag1_numbers <=> tag2_numbers
119
+ rescue
120
+ raise "Match failed on\n'#{tag1}'\n'#{tag2}'"
121
+ end
122
+ end
123
+
124
+ tags = `git tag`.split "\n"
125
+ tags.sort! &tag_sort
126
+ pairs = []
127
+ tags.each_index { |a| pairs.push tags[a] + '..' + tags[a+1] unless tags[a+1].nil? }
128
+
129
+ notes = ''
130
+
131
+ dates = `git log --tags --simplify-by-decoration --pretty="format:%d %ad" --date=short`.split "\n"
132
+ # " (tag: v0.0.21) 2013-03-22"
133
+ dates.reject! { |d| ! d.match /\(tag: v\d+\.\d+\.\d+\) \d+-\d+-\d+/ }
134
+
135
+ pairs.sort! &tag_sort
136
+ pairs.reverse! # pairs are in reverse order.
137
+
138
+ tag_date = []
139
+ pairs.each do |pair|
140
+ tag = pair.split('..').last
141
+ dates.each do |line|
142
+ # regular tag, or tag on master.
143
+ if line.include?(tag + ')') || line.include?(tag + ',')
144
+ tag_date.push tag + ' ' + line.match(/\d{4}-\d{2}-\d{2}/)[0]
145
+ break
146
+ end
147
+ end
148
+ end
149
+
150
+ pairs.each_index do |a|
151
+ data =`git log --pretty=oneline #{pairs[a]}`
152
+ new_data = ''
153
+ data.split("\n").each do |line|
154
+ hex = line.match(/[a-zA-Z0-9]+/)[0]
155
+ # use first 7 chars to match GitHub
156
+ comment = line.gsub(hex, '').strip
157
+ next if comment == 'Update release notes'
158
+ new_data += "- [#{hex[0...7]}](https://github.com/appium/#{gh_name}/commit/#{hex}) #{comment}\n"
159
+ end
160
+ data = new_data + "\n"
161
+
162
+ # last pair is the released version.
163
+ notes += "#### #{tag_date[a]}\n\n" + data + "\n"
164
+ end
165
+
166
+ File.open('release_notes.md', 'w') { |f| f.write notes.to_s.strip }
167
+ end
@@ -0,0 +1,23 @@
1
+ require_relative 'lib/appium_doc_lint'
2
+
3
+ Gem::Specification.new do |s|
4
+ # 1.8.x is not supported
5
+ s.required_ruby_version = '>= 1.9.3'
6
+
7
+ s.name = 'appium_doc_lint'
8
+ s.version = Appium::Lint::VERSION
9
+ s.date = Appium::Lint::DATE
10
+ s.license = 'http://www.apache.org/licenses/LICENSE-2.0.txt'
11
+ s.description = s.summary = 'Appium Doc Lint'
12
+ s.description += '.' # avoid identical warning
13
+ s.authors = s.email = [ 'code@bootstraponline.com' ]
14
+ s.homepage = 'https://github.com/appium/appium_doc_lint' # published as appium_doc_lint
15
+ s.require_paths = [ 'lib' ]
16
+
17
+ s.add_development_dependency 'rake', '~> 10.3.1'
18
+ s.add_development_dependency 'rspec', '~> 2.14.1'
19
+ s.add_development_dependency 'posix-spawn', '~> 0.3.8'
20
+
21
+ s.executables = [ 'appium_doc_lint' ]
22
+ s.files = `git ls-files`.split "\n"
23
+ end
@@ -0,0 +1,13 @@
1
+ #!/usr/bin/env ruby
2
+ require 'rubygems'
3
+ require_relative '../lib/appium_doc_lint'
4
+
5
+ def run_glob
6
+ lint = Appium::Lint.new
7
+ dir = File.join(Dir.pwd, '**', '*.md')
8
+
9
+ lint.report lint.glob dir
10
+ end
11
+
12
+ result = run_glob
13
+ puts result if result
@@ -0,0 +1,32 @@
1
+ module Appium
2
+ class Lint
3
+ # noinspection RubyArgCount
4
+ class Base
5
+ attr_reader :input, :warnings
6
+ # Appium::Lint::Base.new file: '/path/to/file'
7
+ #
8
+ # Appium::Lint::Base.new data: 'some **markdown**'
9
+ def initialize opts
10
+ @input = opts.is_a?(OpenStruct) ? opts : Appium::Lint.new_input(opts)
11
+ @warnings = Hash.new []
12
+ end
13
+
14
+ # Record a warning on a zero indexed line number
15
+ #
16
+ # @param line_number [int] line number to warn on
17
+ # @return [warnings]
18
+ def warn line_number
19
+ warnings[line_number + 1] += [fail]
20
+ warnings
21
+ end
22
+
23
+ def fail
24
+ raise NotImplementedError
25
+ end
26
+
27
+ def call
28
+ raise NotImplementedError
29
+ end
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,36 @@
1
+ module Appium
2
+ class Lint
3
+ ###
4
+ # h1 must use the `#` syntax and not the `===` underline syntax.
5
+ # check for three = to reduce false positives
6
+ class H1Invalid < Base
7
+ def call
8
+ # === is always a h1 regardless of previous line
9
+ input.lines.each_with_index do |line, index|
10
+ h1_invalid = !!line.match(/^===+\s*$/)
11
+ warn index if h1_invalid
12
+ end
13
+
14
+ warnings
15
+ end
16
+
17
+ FAIL = 'h1 must not use === underline syntax. Use # instead'
18
+
19
+ def fail
20
+ FAIL
21
+ end
22
+ end
23
+ end
24
+ end
25
+
26
+ =begin
27
+ md = Redcarpet::Markdown.new(Redcarpet::Render::HTML, autolink: true, tables: true)
28
+ > md.render("hi\n=")
29
+ => "<h1>hi</h1>\n"
30
+ > md.render("hi\n =")
31
+ => "<p>hi\n =</p>\n"
32
+ > md.render("hi\n= ")
33
+ => "<h1>hi</h1>\n"
34
+ > md.render("\n\n======")
35
+ => "<h1></h1>\n"
36
+ =end
@@ -0,0 +1,25 @@
1
+ module Appium
2
+ class Lint
3
+ ###
4
+ # Each file must have a h1
5
+ # This forms the title for the document and is used to anchor the
6
+ # #filename.md link.
7
+ #
8
+ # The file should start with the h1. This rule will fail if the document
9
+ # doesn't contain at least one h1
10
+ class H1Missing < Base
11
+ def call
12
+ # either the doc has a h1 or it doesn't
13
+ # attach warning to line 0
14
+ h1_missing = !input.data.match(/^#[^#]/m)
15
+ h1_missing ? warn(0) : warnings
16
+ end
17
+
18
+ FAIL = 'h1 is missing'
19
+
20
+ def fail
21
+ FAIL
22
+ end
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,39 @@
1
+ module Appium
2
+ class Lint
3
+ ###
4
+ # h2 must use the `##` syntax and not the `---` underline syntax.
5
+ # check for three - to reduce false positives
6
+ class H2Invalid < Base
7
+ def call
8
+ previous_line = ''
9
+
10
+ input.lines.each_with_index do |line, index|
11
+ # If the previous line is empty then --- triggers a line break
12
+ previous_line_not_empty = !previous_line.match(/^\s*$/)
13
+ h2_invalid = previous_line_not_empty && line.match(/^---+\s*$/)
14
+ warn index if h2_invalid
15
+
16
+ previous_line = line
17
+ end
18
+
19
+ warnings
20
+ end
21
+
22
+ FAIL = 'h2 must not use --- underline syntax. Use ## instead'
23
+
24
+ def fail
25
+ FAIL
26
+ end
27
+ end
28
+ end
29
+ end
30
+
31
+ =begin
32
+ md = Redcarpet::Markdown.new(Redcarpet::Render::HTML, autolink: true, tables: true)
33
+ > md.render("hi\n--")
34
+ => "<h2>hi</h2>\n"
35
+ > md.render("hi\n -")
36
+ => "<p>hi\n -</p>\n"
37
+ > md.render("hi\n- ")
38
+ => "<h2>hi</h2>\n"
39
+ =end
@@ -0,0 +1,29 @@
1
+ module Appium
2
+ class Lint
3
+ ###
4
+ # h4, h5, and h6 should not be used.
5
+ # Slate works best with h1, h2, or h3
6
+ class H456Invalid < Base
7
+ def call
8
+ input.lines.each_with_index do |line, index|
9
+ h456_invalid = !!line.match(/^\#{4,6}[^#]/)
10
+ warn index if h456_invalid
11
+ end
12
+
13
+ warnings
14
+ end
15
+
16
+ FAIL = 'h4, h5, h6 should not be used. Use h1, h2 or h3.'
17
+
18
+ def fail
19
+ FAIL
20
+ end
21
+ end
22
+ end
23
+ end
24
+ =begin
25
+ > md.render("##### ok")
26
+ => "<h5>ok</h5>\n"
27
+ > md.render(" ##### ok")
28
+ => "<p>##### ok</p>\n"
29
+ =end
@@ -0,0 +1,41 @@
1
+ module Appium
2
+ class Lint
3
+ ###
4
+ # line breaks such as `--` and `---` shouldn't be used
5
+ # on Slate. They will cause problems such as null divs
6
+ class LineBreakInvalid < Base
7
+ def call
8
+ previous_line = ''
9
+ input.lines.each_with_index do |line, index|
10
+ # If the previous line isn't empty then --- createa a h2 not a line break.
11
+ previous_line_empty = previous_line.match(/^\s*$/)
12
+ line_break_invalid = previous_line_empty && line.match(/^--+\s*$/)
13
+ warn index if line_break_invalid
14
+
15
+ previous_line = line
16
+ end
17
+
18
+ warnings
19
+ end
20
+
21
+ FAIL = '`--` and `---` line breaks must not be used. Delete them.'
22
+
23
+ def fail
24
+ FAIL
25
+ end
26
+ end
27
+ end
28
+ end
29
+
30
+ =begin
31
+ > md.render(" -- ")
32
+ => "<p>-- </p>\n"
33
+ > md.render("-- ")
34
+ => "<h2></h2>\n"
35
+ > md.render("--- ")
36
+ => "<hr>\n"
37
+ > md.render("--- ok")
38
+ => "<p>--- ok</p>\n
39
+ > md.render "hi\n--"
40
+ => "<h2>hi</h2>\n"
41
+ =end
@@ -0,0 +1,92 @@
1
+ require 'ostruct'
2
+
3
+ module Appium
4
+ class Lint
5
+ require_relative 'lint/base'
6
+ require_relative 'lint/h1_invalid'
7
+ require_relative 'lint/h1_missing'
8
+ require_relative 'lint/h2_invalid'
9
+ require_relative 'lint/h456_invalid'
10
+ require_relative 'lint/line_break_invalid'
11
+
12
+ # OpenStruct.new data: '', lines: '', file: ''
13
+ attr_reader :input
14
+
15
+ def initialize
16
+ @rules = [H1Invalid, H1Missing, H2Invalid, H456Invalid, LineBreakInvalid]
17
+ end
18
+
19
+ def self.init_data opts={}, input
20
+ raise 'Input must exist' unless input
21
+ data = opts[:data]
22
+ if data
23
+ input.data = data.freeze
24
+ input.lines = data.split(/\r?\n/).freeze
25
+ input.file = nil
26
+ else
27
+ file = opts[:file]
28
+ raise 'File path must be provided' unless file
29
+ raise "File must exist and be readable #{file}" unless File.exist?(file) && File.readable?(file)
30
+ file = File.expand_path(file)
31
+
32
+ input.data = File.read(file).freeze
33
+ input.lines = input.data.split(/\r?\n/).freeze
34
+ input.file = file.freeze
35
+ end
36
+
37
+ input
38
+ end
39
+
40
+ def self.new_input opts
41
+ input = OpenStruct.new(data: '', lines: '', file: '')
42
+ self.init_data opts, input
43
+ end
44
+
45
+ def call opts={}
46
+ @input = self.class.new_input opts
47
+
48
+ all_warnings = {}
49
+ @rules.each do |rule|
50
+ warnings = rule.new(@input).call
51
+ unless warnings.empty?
52
+ all_warnings.merge!(warnings) do |key, old_val, new_val|
53
+ # flatten to prevent { :a => [[1, 2], 2]}
54
+ [old_val, new_val].flatten
55
+ end
56
+ end
57
+ end
58
+
59
+ return {} if all_warnings.empty?
60
+
61
+ # sort by line number
62
+ all_warnings = all_warnings.sort.to_h
63
+
64
+ # wrap with file path if available
65
+ input.file ? { input.file => all_warnings } : all_warnings
66
+ end
67
+
68
+ def glob dir_glob
69
+ results = {}
70
+ Dir.glob dir_glob do |markdown|
71
+ markdown = File.expand_path markdown
72
+ results.merge!(self.call(file: markdown))
73
+ end
74
+ results
75
+ end
76
+
77
+ # Format data into a report
78
+ def report data
79
+ return nil if data.nil? || data.empty?
80
+ result = ''
81
+ data.each do |file_name, analysis|
82
+ result += "\n#{File.basename(file_name)}\n"
83
+ analysis.each do |line_number, warning|
84
+ result += " #{line_number}: #{warning.join(',')}\n"
85
+ end
86
+ end
87
+ result.strip!
88
+
89
+ result.empty? ? nil : result
90
+ end
91
+ end
92
+ end
@@ -0,0 +1,6 @@
1
+ module Appium
2
+ class Lint
3
+ VERSION = '0.0.1' unless defined? ::Appium::Lint::VERSION
4
+ DATE = '2014-04-18' unless defined? ::Appium::Lint::DATE
5
+ end
6
+ end
@@ -0,0 +1,2 @@
1
+ require_relative 'appium_doc_lint/version'
2
+ require_relative 'appium_doc_lint/lint'
data/spec/data/0.md ADDED
@@ -0,0 +1,5 @@
1
+ h1
2
+ ====
3
+
4
+ h2
5
+ ----
data/spec/data/1.md ADDED
@@ -0,0 +1,3 @@
1
+ # h1
2
+
3
+ ## h2
@@ -0,0 +1,7 @@
1
+ # h1
2
+
3
+ --
4
+
5
+ hi
6
+
7
+ ---
data/spec/helper.rb ADDED
@@ -0,0 +1,9 @@
1
+ require 'rubygems'
2
+ require 'rspec'
3
+ require_relative '../lib/appium_doc_lint/lint'
4
+ require_relative '../lib/appium_doc_lint/lint/base'
5
+ require_relative '../lib/appium_doc_lint/lint/h1_missing'
6
+ require_relative '../lib/appium_doc_lint/lint/h1_invalid'
7
+ require_relative '../lib/appium_doc_lint/lint/h2_invalid'
8
+ require_relative '../lib/appium_doc_lint/lint/h456_invalid'
9
+ require_relative '../lib/appium_doc_lint/lint/line_break_invalid'
data/spec/lint_spec.rb ADDED
@@ -0,0 +1,260 @@
1
+ require_relative 'helper'
2
+
3
+ class Appium::Lint
4
+ describe 'Lint' do
5
+ it 'processes globbed files' do
6
+ lint = Appium::Lint.new
7
+ dir = File.join(Dir.pwd, 'spec', 'data', '**', '*.md')
8
+
9
+ actual = lint.glob dir
10
+
11
+ # 1.md has no problems so it doesn't show up in expected failures
12
+ expected = { '0.md' => { 1 => [H1Missing::FAIL],
13
+ 2 => [H1Invalid::FAIL],
14
+ 5 => [H2Invalid::FAIL] },
15
+ '3.md' => { 3 => [LineBreakInvalid::FAIL],
16
+ 7 => [LineBreakInvalid::FAIL] } }
17
+
18
+ # convert path/to/0.md to 0.md
19
+ actual.keys.each do |key|
20
+ new_key = File.basename key
21
+ actual[new_key] = actual[key]
22
+ actual.delete key
23
+ end
24
+
25
+ expect(actual).to eq(expected)
26
+ end
27
+
28
+ it 'reports globbed files' do
29
+ lint = Appium::Lint.new
30
+ dir = File.join(Dir.pwd, 'spec', 'data', '**', '*.md')
31
+
32
+ actual = lint.report lint.glob dir
33
+ expected = (<<REPORT).strip
34
+ 0.md
35
+ 1: #{H1Missing::FAIL}
36
+ 2: #{H1Invalid::FAIL}
37
+ 5: #{H2Invalid::FAIL}
38
+
39
+ 3.md
40
+ 3: #{LineBreakInvalid::FAIL}
41
+ 7: #{LineBreakInvalid::FAIL}
42
+ REPORT
43
+
44
+ expect(actual).to eq(expected)
45
+ end
46
+
47
+ it 'empty report is falsey' do
48
+ lint = Appium::Lint.new
49
+ actual = !! lint.report({})
50
+ expect(actual).to eq(false)
51
+ end
52
+
53
+ it 'processes all rules without raising an exception' do
54
+ lint = Appium::Lint.new
55
+
56
+ markdown = <<MARKDOWN
57
+ hi
58
+ ====
59
+
60
+ hi 2
61
+ =====
62
+
63
+ there
64
+ ------
65
+
66
+ there 2
67
+ --------
68
+
69
+ --
70
+
71
+ ---
72
+
73
+ #### h4
74
+ ##### h5
75
+ ###### h6
76
+ MARKDOWN
77
+
78
+ expected = { 1 => [H1Missing::FAIL],
79
+ 2 => [H1Invalid::FAIL],
80
+ 5 => [H1Invalid::FAIL],
81
+ 8 => [H2Invalid::FAIL],
82
+ 11 => [H2Invalid::FAIL],
83
+ 13 => [LineBreakInvalid::FAIL],
84
+ 15 => [LineBreakInvalid::FAIL],
85
+ 17 => [H456Invalid::FAIL],
86
+ 18 => [H456Invalid::FAIL],
87
+ 19 => [H456Invalid::FAIL] }
88
+
89
+ actual = lint.call data: markdown
90
+
91
+ expect(actual).to eq(expected)
92
+ end
93
+ end
94
+
95
+ describe H1Missing do
96
+ it 'detects missing h1' do
97
+ rule = H1Missing.new data: '## hi'
98
+ expected = { 1 => [rule.fail] }
99
+ actual = rule.call
100
+
101
+ expect(actual).to eq(expected)
102
+ end
103
+
104
+ it 'detects h1 missing' do
105
+ rule = H1Missing.new data: '# hi'
106
+ expected = {}
107
+ actual = rule.call
108
+
109
+ expect(actual).to eq(expected)
110
+ end
111
+ end
112
+
113
+ describe H1Invalid do
114
+ it 'detects invalid h1' do
115
+ rule = H1Invalid.new data: "hi\n==="
116
+ expected = { 2 => [rule.fail] }
117
+ actual = rule.call
118
+
119
+ expect(actual).to eq(expected)
120
+ end
121
+
122
+ it 'detects multiple invalid h1' do
123
+ rule = H1Invalid.new data: "hi\n===\nbye\n======\n\n===="
124
+ expected = { 2 => [rule.fail],
125
+ 4 => [rule.fail],
126
+ 6 => [rule.fail] }
127
+ actual = rule.call
128
+
129
+ expect(actual).to eq(expected)
130
+ end
131
+
132
+ it 'detects valid h1' do
133
+ rule = H1Invalid.new data: '# hi'
134
+ expected = {}
135
+ actual = rule.call
136
+
137
+ expect(actual).to eq(expected)
138
+ end
139
+ end
140
+
141
+ describe H2Invalid do
142
+ it 'detects invalid h2' do
143
+ rule = H2Invalid.new data: "hi\n---"
144
+ expected = { 2 => [rule.fail] }
145
+ actual = rule.call
146
+
147
+ expect(actual).to eq(expected)
148
+ end
149
+
150
+ it 'detects multiple invalid h2' do
151
+ rule = H2Invalid.new data: "hi\n---\nbye\n-------"
152
+ expected = { 2 => [rule.fail],
153
+ 4 => [rule.fail] }
154
+ actual = rule.call
155
+
156
+ expect(actual).to eq(expected)
157
+ end
158
+
159
+ it 'detects valid h2' do
160
+ rule = H2Invalid.new data: '## hi'
161
+ expected = {}
162
+ actual = rule.call
163
+
164
+ expect(actual).to eq(expected)
165
+ end
166
+ end
167
+
168
+ describe H456Invalid do
169
+ it 'detects invalid h4, h5, h6' do
170
+ ['#### h4', '##### h5', '###### h6'].each do |data|
171
+ rule = H456Invalid.new data: data
172
+ expected = { 1 => [rule.fail] }
173
+ actual = rule.call
174
+
175
+ expect(actual).to eq(expected)
176
+ end
177
+ end
178
+
179
+ it 'detects multiple invalid h4, h5, h6' do
180
+ data = <<-MARKDOWN
181
+ # h1
182
+ ## h2
183
+ ### h3
184
+ #### h4
185
+ ##### h5
186
+ ###### h6
187
+ #### not actually a h4 due to leading space
188
+ MARKDOWN
189
+
190
+ rule = H456Invalid.new data: data
191
+ expected = { 4 => [rule.fail],
192
+ 5 => [rule.fail],
193
+ 6 => [rule.fail] }
194
+ actual = rule.call
195
+
196
+ expect(actual).to eq(expected)
197
+ end
198
+
199
+ it 'does not error on h1, h2, h3' do
200
+ data = <<-MARKDOWN
201
+ # h1
202
+ # h2
203
+ # h3
204
+ MARKDOWN
205
+ rule = H456Invalid.new data: data
206
+ expected = {}
207
+ actual = rule.call
208
+
209
+ expect(actual).to eq(expected)
210
+ end
211
+ end
212
+
213
+ describe LineBreakInvalid do
214
+ it 'detects invalid line breaks' do
215
+ %w(-- --- ----).each do |data|
216
+ rule = LineBreakInvalid.new data: data
217
+ expected = { 1 => [rule.fail] }
218
+ actual = rule.call
219
+
220
+ expect(actual).to eq(expected)
221
+ end
222
+ end
223
+
224
+ it 'detects multiple invalid line breaks' do
225
+ data = <<-MARKDOWN
226
+ -- not a break
227
+ ------
228
+ -- still not
229
+
230
+ --
231
+
232
+ ---
233
+
234
+ -----
235
+ MARKDOWN
236
+
237
+ rule = LineBreakInvalid.new data: data
238
+ expected = { 5 => [rule.fail],
239
+ 7 => [rule.fail],
240
+ 9 => [rule.fail] }
241
+ actual = rule.call
242
+
243
+ expect(actual).to eq(expected)
244
+ end
245
+
246
+ it 'does not error on valid data' do
247
+ data = <<-MARKDOWN
248
+ some --
249
+ ------
250
+ markdown--
251
+ -- examples
252
+ MARKDOWN
253
+ rule = LineBreakInvalid.new data: data
254
+ expected = {}
255
+ actual = rule.call
256
+
257
+ expect(actual).to eq(expected)
258
+ end
259
+ end
260
+ end
metadata ADDED
@@ -0,0 +1,109 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: appium_doc_lint
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - code@bootstraponline.com
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-04-18 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rake
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: 10.3.1
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: 10.3.1
27
+ - !ruby/object:Gem::Dependency
28
+ name: rspec
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: 2.14.1
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: 2.14.1
41
+ - !ruby/object:Gem::Dependency
42
+ name: posix-spawn
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: 0.3.8
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: 0.3.8
55
+ description: Appium Doc Lint.
56
+ email:
57
+ - code@bootstraponline.com
58
+ executables:
59
+ - appium_doc_lint
60
+ extensions: []
61
+ extra_rdoc_files: []
62
+ files:
63
+ - ".gitignore"
64
+ - ".travis.yml"
65
+ - Gemfile
66
+ - LICENSE
67
+ - README.md
68
+ - Rakefile
69
+ - appium_doc_lint.gemspec
70
+ - bin/appium_doc_lint
71
+ - lib/appium_doc_lint.rb
72
+ - lib/appium_doc_lint/lint.rb
73
+ - lib/appium_doc_lint/lint/base.rb
74
+ - lib/appium_doc_lint/lint/h1_invalid.rb
75
+ - lib/appium_doc_lint/lint/h1_missing.rb
76
+ - lib/appium_doc_lint/lint/h2_invalid.rb
77
+ - lib/appium_doc_lint/lint/h456_invalid.rb
78
+ - lib/appium_doc_lint/lint/line_break_invalid.rb
79
+ - lib/appium_doc_lint/version.rb
80
+ - spec/data/0.md
81
+ - spec/data/1.md
82
+ - spec/data/sub/3.md
83
+ - spec/helper.rb
84
+ - spec/lint_spec.rb
85
+ homepage: https://github.com/appium/appium_doc_lint
86
+ licenses:
87
+ - http://www.apache.org/licenses/LICENSE-2.0.txt
88
+ metadata: {}
89
+ post_install_message:
90
+ rdoc_options: []
91
+ require_paths:
92
+ - lib
93
+ required_ruby_version: !ruby/object:Gem::Requirement
94
+ requirements:
95
+ - - ">="
96
+ - !ruby/object:Gem::Version
97
+ version: 1.9.3
98
+ required_rubygems_version: !ruby/object:Gem::Requirement
99
+ requirements:
100
+ - - ">="
101
+ - !ruby/object:Gem::Version
102
+ version: '0'
103
+ requirements: []
104
+ rubyforge_project:
105
+ rubygems_version: 2.2.2
106
+ signing_key:
107
+ specification_version: 4
108
+ summary: Appium Doc Lint
109
+ test_files: []