mdl 0.1.0 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (36) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +78 -0
  3. data/docs/RULES.md +197 -7
  4. data/docs/configuration.md +7 -3
  5. data/docs/rolling_a_release.md +23 -0
  6. data/lib/mdl.rb +13 -4
  7. data/lib/mdl/cli.rb +13 -2
  8. data/lib/mdl/doc.rb +29 -2
  9. data/lib/mdl/rules.rb +89 -1
  10. data/lib/mdl/styles/cirosantilli.rb +5 -0
  11. data/lib/mdl/styles/default.rb +2 -0
  12. data/lib/mdl/styles/relaxed.rb +3 -0
  13. data/lib/mdl/version.rb +1 -1
  14. data/mdl.gemspec +1 -1
  15. data/test/rule_tests/code_block_dollar.md +1 -1
  16. data/test/rule_tests/emphasis_instead_of_headers.md +35 -0
  17. data/test/rule_tests/fenced_code_blocks.md +6 -0
  18. data/test/rule_tests/fenced_code_without_blank_lines_style.rb +2 -0
  19. data/test/rule_tests/hr_style_dashes.md +22 -0
  20. data/test/rule_tests/hr_style_dashes_style.rb +2 -0
  21. data/test/rule_tests/hr_style_inconsistent.md +22 -0
  22. data/test/rule_tests/hr_style_long.md +22 -0
  23. data/test/rule_tests/hr_style_long_style.rb +2 -0
  24. data/test/rule_tests/hr_style_stars.md +22 -0
  25. data/test/rule_tests/hr_style_stars_style.rb +2 -0
  26. data/test/rule_tests/inline_html.md +13 -0
  27. data/test/rule_tests/links.md +9 -0
  28. data/test/rule_tests/reversed_link.md +1 -1
  29. data/test/rule_tests/spaces_inside_codespan_elements.md +7 -0
  30. data/test/rule_tests/spaces_inside_emphasis_markers.md +31 -0
  31. data/test/rule_tests/spaces_inside_link_text.md +7 -0
  32. data/test/rule_tests/trailing_spaces_br.md +4 -0
  33. data/test/rule_tests/trailing_spaces_br_style.rb +2 -0
  34. data/test/rule_tests/{whitespace issues.md → whitespace_issues.md} +0 -0
  35. data/test/test_ruledocs.rb +1 -1
  36. metadata +39 -5
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 9b4aab66e36530dc982328a64e931370dcd484c9
4
- data.tar.gz: 69c11c9027df69c408e9f854341a6e54412d2c1c
3
+ metadata.gz: 754ba4fcea65ab367c6851469bb744fbf4339800
4
+ data.tar.gz: 22488dfa5f78f22cbf15ea204eadd437854515da
5
5
  SHA512:
6
- metadata.gz: 47a151052b1220aedefc36019406ec451a6f03c919c91e500780dcb696637bf2e315204ae08d468937d93536eaca078d2295b5ef013adecc4bb21155c9d8956e
7
- data.tar.gz: 36228402d91b627ee1d35e2447dba6fa65457f971fc55a8dbdc94fd262032c7f541a43c7ea69441d987b0591bcf293ace021aa0ec13baf6882ef56ef3265d5e0
6
+ metadata.gz: 9129f6ab9f1dc20326f2171eb70fd0d620becbc825f7b2d913a679b26a1f536643550f6db309590349ad1a7fcda3ae5cebed97e73bce5e1840ffb973348b2ec0
7
+ data.tar.gz: 554f83c5d7f92e0ae15442acab0d9d18a7b2052fafc3c61037e15140354c2db6c6fca38f4d9a8bfbce95a817d6975d911016735b040414ad825186e85b276d72
@@ -0,0 +1,78 @@
1
+ # Change Log
2
+
3
+ ## [v0.2.0](https://github.com/mivok/markdownlint/tree/v0.2.0) (2015-04-13)
4
+
5
+ [Full Changelog](https://github.com/mivok/markdownlint/compare/v0.1.0...v0.2.0)
6
+
7
+ ### Rules added
8
+
9
+ * MD033 - Inline HTML
10
+ * MD034 - Bare URL used
11
+ * MD035 - Horizontal rule style
12
+ * MD036 - Emphasis used instead of a header
13
+ * MD037 - Spaces inside emphasis markers
14
+ * MD038 - Spaces inside code span elements
15
+ * MD039 - Spaces inside link text
16
+ * MD040 - Fenced code blocks should have a language specified
17
+
18
+ ## Enhancements implemented
19
+
20
+ * Trailing spaces rule should allow an excemption for deliberate <br/\>
21
+ insertion.
22
+ * Rules can be excluded in .mdlrc and on the command line by specifying a rule
23
+ as ~MD000.
24
+
25
+ ### Merged pull requests
26
+
27
+ * [Add parameter (value and default) information to rule documentation. - David Anson](https://github.com/mivok/markdownlint/pull/76)
28
+
29
+ ## [v0.1.0](https://github.com/mivok/markdownlint/tree/v0.1.0) (2015-02-22)
30
+
31
+ [Full Changelog](https://github.com/mivok/markdownlint/compare/v0.0.1...v0.1.0)
32
+
33
+ ### Rules added
34
+
35
+ * MD031 - Fenced code blocks should be surrounded by blank lines
36
+ * MD032 - Lists should be surrounded by blank lines
37
+
38
+ ### Bugs fixed
39
+
40
+ * MD014 triggers when it shouldn't
41
+
42
+ ### Merged pull requests
43
+
44
+ * [MD032 - Lists should be surrounded by blank lines - David Anson](https://github.com/mivok/markdownlint/pull/70)
45
+ * [MD031 - Fenced code blocks should be surrounded by blank lines - David Anson](https://github.com/mivok/markdownlint/pull/68)
46
+ * [Clarify how to specify your own style - mjankowski](https://github.com/mivok/markdownlint/pull/65)
47
+ * [Use single quotes to prevent early escaping - highb](https://github.com/mivok/markdownlint/pull/64)
48
+
49
+ ## [v0.0.1](https://github.com/mivok/markdownlint/tree/v0.0.1) (2014-09-07)
50
+
51
+ ### Rules added
52
+
53
+ * MD001 - Header levels should only increment by one level at a time
54
+ * MD002 - First header should be a h1 header
55
+ * MD003 - Header style
56
+ * MD004 - Unordered list style
57
+ * MD005 - Inconsistent indentation for list items at the same level
58
+ * MD006 - Consider starting bulleted lists at the beginning of the line
59
+ * MD007 - Unordered list indentation
60
+ * MD009 - Trailing spaces
61
+ * MD010 - Hard tabs
62
+ * MD011 - Reversed link syntax
63
+ * MD012 - Multiple consecutive blank lines
64
+ * MD013 - Line length
65
+ * MD014 - Dollar signs used before commands without showing output
66
+ * MD018 - No space after hash on atx style header
67
+ * MD019 - Multiple spaces after hash on atx style header
68
+ * MD020 - No space inside hashes on closed atx style header
69
+ * MD021 - Multiple spaces inside hashes on closed atx style header
70
+ * MD022 - Headers should be surrounded by blank lines
71
+ * MD023 - Headers must start at the beginning of the line
72
+ * MD024 - Multiple headers with the same content
73
+ * MD025 - Multiple top level headers in the same document
74
+ * MD026 - Trailing punctuation in header
75
+ * MD027 - Multiple spaces after blockquote symbol
76
+ * MD028 - Blank line inside blockquote
77
+ * MD029 - Ordered list item prefix
78
+ * MD030 - Spaces after list markers
@@ -53,7 +53,7 @@ The first header in the document should be a h1 header:
53
53
 
54
54
  Tags: headers
55
55
 
56
- Parameters: style
56
+ Parameters: style ("consistent", "atx", "atx_closed", "setext"; default "consistent")
57
57
 
58
58
  This rule is triggered when different header styles (atx, setext, and 'closed'
59
59
  atx) are used in the same document:
@@ -79,7 +79,7 @@ document.
79
79
 
80
80
  Tags: bullet, ul
81
81
 
82
- Parameters: style
82
+ Parameters: style ("consistent", "asterisk", "plus", "dash"; default "consistent")
83
83
 
84
84
  This rule is triggered when the symbols used in the document for unordered
85
85
  list items do not match the configured unordered list style:
@@ -149,7 +149,7 @@ characters if you use 4 space tabs, or 1 character if you use 2 space tabs).
149
149
 
150
150
  Tags: bullet, ul, indentation
151
151
 
152
- Parameters: indent
152
+ Parameters: indent (number; default 2)
153
153
 
154
154
  This rule is triggered when list items are not indented by the configured
155
155
  number of spaces (default: 2).
@@ -182,9 +182,20 @@ for a description of the problem.
182
182
 
183
183
  Tags: whitespace
184
184
 
185
+ Parameters: br_spaces (number; default: 0)
186
+
185
187
  This rule is triggered on any lines that end with whitespace. To fix this,
186
188
  find the line that is triggered and remove any trailing spaces from the end.
187
189
 
190
+ The br_spaces parameter allows an exception to this rule for a specific amount
191
+ of trailing spaces used to insert an explicit line break/br element. For
192
+ example, set br_spaces to 2 to allow exactly 2 spaces at the end of a line.
193
+
194
+ Note: you have to set br_spaces to 2 or higher for this exception to take
195
+ effect - you can't insert a br element with just a single trailing space, so
196
+ if you set br_spaces to 1, the exception will be disabled, just as if it was
197
+ set to the default of 0.
198
+
188
199
  ## MD010 - Hard tabs
189
200
 
190
201
  Tags: whitespace, hard_tab
@@ -244,7 +255,7 @@ lines inside code blocks.
244
255
 
245
256
  Tags: line_length
246
257
 
247
- Parameters: line_length
258
+ Parameters: line_length (number; default 80)
248
259
 
249
260
  This rule is triggered when there are lines that are longer than the
250
261
  configured line length (default: 80 characters). To fix this, split the line
@@ -463,7 +474,7 @@ should be contained within this header.
463
474
 
464
475
  Tags: headers
465
476
 
466
- Parameters: punctuation
477
+ Parameters: punctuation (string; default ".,;:!?")
467
478
 
468
479
  This rule is triggered on any header that has a punctuation character as the
469
480
  last character in the line:
@@ -531,7 +542,7 @@ separate blockquotes.
531
542
 
532
543
  Tags: ol
533
544
 
534
- Parameters: style
545
+ Parameters: style ("one", "ordered"; default "one")
535
546
 
536
547
  This rule is triggered on ordered lists that do not either start with '1.' or
537
548
  do not have a prefix that increases in numerical order (depending on the
@@ -553,7 +564,7 @@ Example valid list if the style is configured as 'ordered':
553
564
 
554
565
  Tags: ol, ul, whitespace
555
566
 
556
- Parameters: ul_single, ol_single, ul_multi, ol_multi
567
+ Parameters: ul_single, ol_single, ul_multi, ol_multi (number, default 1)
557
568
 
558
569
  This rule checks for the number of spaces between a list marker (e.g. '`-`',
559
570
  '`*`', '`+`' or '`1.`') and the text of the list item.
@@ -682,3 +693,182 @@ items with hanging indents are okay:
682
693
 
683
694
  * This is
684
695
  okay
696
+
697
+ ## MD033 - Inline HTML
698
+
699
+ Tags: html
700
+
701
+ This rule is triggered whenever raw HTML is used in a markdown document:
702
+
703
+ <h1>Inline HTML header</h1>
704
+
705
+ To fix this, use 'pure' markdown instead of including raw HTML:
706
+
707
+ # Markdown header
708
+
709
+ Rationale: Raw HTML is allowed in markdown, but this rule is included for
710
+ those who want their documents to only include "pure" markdown, or for those
711
+ who are rendering markdown documents in something other than HTML.
712
+
713
+ ## MD034 - Bare URL used
714
+
715
+ Tags: links, url
716
+
717
+ This rule is triggered whenever a URL is given that isn't surrounded by angle
718
+ brackets:
719
+
720
+ For more information, see http://www.example.com/.
721
+
722
+ To fix this, add angle brackets around the URL:
723
+
724
+ For more information, see <http://www.example.com/>.
725
+
726
+ Rationale: Without angle brackets, the URL isn't converted into a link in many
727
+ markdown parsers.
728
+
729
+ Note: if you do want a bare URL without it being converted into a link,
730
+ enclose it in a code block, otherwise in some markdown parsers it _will_ be
731
+ converted:
732
+
733
+ `http://www.example.com`
734
+
735
+ ## MD035 - Horizontal rule style
736
+
737
+ Tags: hr
738
+
739
+ Parameters: style ("consistent", "---", "***", or other string specifying the
740
+ horizontal rule; default "consistent")
741
+
742
+ This rule is triggered when inconsistent styles of horizontal rules used in
743
+ the document:
744
+
745
+ ---
746
+
747
+ - - -
748
+
749
+ ***
750
+
751
+ * * *
752
+
753
+ ****
754
+
755
+ To fix this, ensure any horizontal rules used in the document are consistent,
756
+ or match the given style if the rule is so configured:
757
+
758
+ ---
759
+
760
+ ---
761
+
762
+ Note: by default, this rule is configured to just require that all horizontal
763
+ rules in the document are the same, and will trigger if any of the horizontal
764
+ rules are different than the first one encountered in the document. If you
765
+ want to configure the rule to match a specific style, the parameter given to
766
+ the 'style' option is a string containing the exact horizontal rule text that
767
+ is allowed.
768
+
769
+ ## MD036 - Emphasis used instead of a header
770
+
771
+ Tags: headers, emphasis
772
+
773
+ This check looks for instances where emphasized (i.e. bold or italic) text is
774
+ used to separate sections, where a header should be used instead:
775
+
776
+ **My document**
777
+
778
+ Lorem ipsum dolor sit amet...
779
+
780
+ _Another section_
781
+
782
+ Consectetur adipiscing elit, sed do eiusmod.
783
+
784
+ To fix this, use markdown headers instead of emphasized text to denote
785
+ sections:
786
+
787
+ # My document
788
+
789
+ Lorem ipsum dolor sit amet...
790
+
791
+ ## Another section
792
+
793
+ Consectetur adipiscing elit, sed do eiusmod.
794
+
795
+ Note: this rule looks for paragraphs that consist entirely of emphasized text.
796
+ It won't fire on emphasis used within regular text.
797
+
798
+ ## MD037 - Spaces inside emphasis markers
799
+
800
+ Tags: whitespace, emphasis
801
+
802
+ This rule is triggered when emphasis markers (bold, italic) are used, but they
803
+ have spaces between the markers and the text:
804
+
805
+ Here is some ** bold ** text.
806
+
807
+ Here is some * italic * text.
808
+
809
+ Here is some more __ bold __ text.
810
+
811
+ Here is some more _ italic _ text.
812
+
813
+ To fix this, remove the spaces around the emphasis markers:
814
+
815
+ Here is some **bold** text.
816
+
817
+ Here is some *italic* text.
818
+
819
+ Here is some more __bold__ text.
820
+
821
+ Here is some more _italic_ text.
822
+
823
+ Rationale: Emphasis is only parsed as such when the asterisks/underscores
824
+ aren't completely surrounded by spaces. This rule attempts to detect where
825
+ they were surrounded by spaces, but it appears that emphasized text was
826
+ intended by the author.
827
+
828
+ ## MD038 - Spaces inside code span elements
829
+
830
+ Tags: whitespace, code
831
+
832
+ This rule is triggered on code span elements that have spaces right inside the
833
+ backticks:
834
+
835
+ ` some text `
836
+
837
+ `some text `
838
+
839
+ ` some text`
840
+
841
+ To fix this, remove the spaces inside the codespan markers:
842
+
843
+ `some text`
844
+
845
+ ## MD039 - Spaces inside link text
846
+
847
+ Tags: whitespace, links
848
+
849
+ This rule is triggered on links that have spaces surrounding the link text:
850
+
851
+ [ a link ](http://www.example.com/)
852
+
853
+ To fix this, remove the spaces surrounding the link text:
854
+
855
+ [a link](http://www.example.com/)
856
+
857
+ ## MD040 - Fenced code blocks should have a language specified
858
+
859
+ Tags: code, language
860
+
861
+ This rule is triggered when fenced code blocks are used, but a language isn't
862
+ specified:
863
+
864
+ ```
865
+ #!/bin/bash
866
+ echo Hello world
867
+ ```
868
+
869
+ To fix this, add a language specifier to the code block:
870
+
871
+ ```bash
872
+ #!/bin/bash
873
+ echo Hello world
874
+ ```
@@ -42,19 +42,23 @@ instead, and ignore any files git doesn't know about.
42
42
 
43
43
  Tags - Limit the rules mdl enables to those containing the provided tags.
44
44
 
45
- * Command line: `-t tag1,tag2`, `--tags tag1,tag2`
45
+ * Command line: `-t tag1,tag2`, `--tags tag1,tag2`, `-t ~tag1,~tag2`
46
46
  * Config file: `tags "tag1", "tag2"`
47
47
  * Default: process all rules (no tag limit)
48
48
 
49
49
  Rules - Limit the rules mdl enables to those provided in this option.
50
50
 
51
- * Command line: `-r MD001,MD002`, `--rules MD001,MD002`
51
+ * Command line: `-r MD001,MD002`, `--rules MD001,MD002`, `-r ~MD001,~MD002`
52
52
  * Config file: `rules "MD001", "MD002"`
53
53
  * Default: process all rules (no rule limit)
54
54
 
55
+ If a rule or tag ID is preceded by a tilde (`~`), then it _disables_ the
56
+ matching rules instead of enabling them, starting with all rules being enabled.
57
+
55
58
  Note: if both `--rules` and `--tags` are provided, then a given rule has to
56
59
  both be in the list of enabled rules, as well as be tagged with one of the
57
- tags provided with the `--tags` option.
60
+ tags provided with the `--tags` option. Use the `-l/--list-rules` option to
61
+ test this behavior.
58
62
 
59
63
  Style - Select which style mdl uses. A 'style' is a file containing a list of
60
64
  enabled/disable rules, as well as options for some rules that take them. For
@@ -12,6 +12,29 @@ Bump the version. Markdownlint uses semantic versioning. From
12
12
  To bump the version, edit `lib/mdl/version.rb` and commit to the master
13
13
  branch.
14
14
 
15
+ Update the changelog:
16
+
17
+ * Add a new header and 'full changelog' link for the new release:
18
+
19
+ ## [v0.2.0](https://github.com/mivok/markdownlint/tree/v0.2.0) (2015-04-13)
20
+
21
+ [Full Changelog](https://github.com/mivok/markdownlint/compare/v0.1.0...v0.2.0)
22
+
23
+ * Add an 'Rules added' section, listing every new rule added for this version.
24
+ * Use `git diff v0.1.0..v0.2.0 docs/RULES.md | grep '## MD'` to discover
25
+ what these are.
26
+ * Search for closed issues:
27
+ * Go to <https://github.com/mivok/markdownlint/issues>
28
+ * Search for `is:closed closed:>1900-01-01`, changing the date to the date
29
+ of the last release.
30
+ * From this list of issues, make sections for:
31
+ * Enhancements implemented
32
+ * Bugs fixed
33
+ * Search for merged pull requests:
34
+ * Search for `is:pull-request merged:>1900-01-01`
35
+ * Add an entry for each merged pull request:
36
+ * `[Title - author](https://github.com/mivok/markdownlint/pull/NN)`
37
+
15
38
  Next, run `rake release`. This will:
16
39
 
17
40
  * Tag vX.Y.Z in git and push it.
data/lib/mdl.rb CHANGED
@@ -13,11 +13,21 @@ module MarkdownLint
13
13
  cli = MarkdownLint::CLI.new
14
14
  cli.run
15
15
  rules = RuleSet.load_default
16
- style = Style.load(Config[:style], rules)
16
+ Style.load(Config[:style], rules)
17
17
  # Rule option filter
18
- rules.select! {|r| Config[:rules].include?(r) } if Config[:rules]
18
+ if Config[:rules]
19
+ rules.select! {|r| Config[:rules][:include].include?(r) } \
20
+ unless Config[:rules][:include].empty?
21
+ rules.select! {|r| not Config[:rules][:exclude].include?(r) } \
22
+ unless Config[:rules][:exclude].empty?
23
+ end
19
24
  # Tag option filter
20
- rules.select! {|r, v| not (v.tags & Config[:tags]).empty? } if Config[:tags]
25
+ if Config[:tags]
26
+ rules.select! {|r, v| not (v.tags & Config[:tags][:include]).empty? } \
27
+ unless Config[:tags][:include].empty?
28
+ rules.select! {|r, v| (v.tags & Config[:tags][:exclude]).empty? } \
29
+ unless Config[:tags][:exclude].empty?
30
+ end
21
31
 
22
32
  if Config[:list_rules]
23
33
  puts "Enabled rules:"
@@ -34,7 +44,6 @@ module MarkdownLint
34
44
  # Recurse into directories
35
45
  cli.cli_arguments.each_with_index do |filename, i|
36
46
  if Dir.exist?(filename)
37
- pattern = "#{filename}/**/*.md" # This works for both Dir and ls-files
38
47
  if Config[:git_recurse]
39
48
  Dir.chdir(filename) do
40
49
  cli.cli_arguments[i] = %x(git ls-files '*.md').split("\n")
@@ -28,13 +28,13 @@ module MarkdownLint
28
28
  :short => '-t',
29
29
  :long => '--tags TAG1,TAG2',
30
30
  :description => 'Only process rules with these tags',
31
- :proc => Proc.new { |v| v.split(',').map { |t| t.to_sym } }
31
+ :proc => Proc.new { |v| toggle_list(v, true) }
32
32
 
33
33
  option :rules,
34
34
  :short => '-r',
35
35
  :long => '--rules RULE1,RULE2',
36
36
  :description => 'Only process these rules',
37
- :proc => Proc.new { |v| v.split(',') }
37
+ :proc => Proc.new { |v| toggle_list(v) }
38
38
 
39
39
  option :style,
40
40
  :short => '-s',
@@ -85,5 +85,16 @@ module MarkdownLint
85
85
  cli_arguments << "-"
86
86
  end
87
87
  end
88
+
89
+ def self.toggle_list(s, to_sym=false)
90
+ parts = s.split(',')
91
+ inc = parts.select{|p| not p.start_with?('~')}
92
+ exc = parts.select{|p| p.start_with?('~')}.map{|p| p[1..-1]}
93
+ if to_sym
94
+ inc.map!{|p| p.to_sym}
95
+ exc.map!{|p| p.to_sym}
96
+ end
97
+ {:include => inc, :exclude => exc}
98
+ end
88
99
  end
89
100
  end
@@ -84,6 +84,33 @@ module MarkdownLint
84
84
  results
85
85
  end
86
86
 
87
+ ##
88
+ # A variation on find_type_elements that allows you to skip drilling down
89
+ # into children of specific element types.
90
+ #
91
+ # Instead of a single type, a list of types can be provided instead to
92
+ # find all types.
93
+ #
94
+ # Unlike find_type_elements, this method will always search for nested
95
+ # elements, and skip the element types given to nested_except.
96
+
97
+ def find_type_elements_except(type, nested_except=[], elements=@elements)
98
+ results = []
99
+ if type.class == Symbol
100
+ type = [type]
101
+ end
102
+ if nested_except.class == Symbol
103
+ nested_except = [nested_except]
104
+ end
105
+ elements.each do |e|
106
+ results.push(e) if type.include?(e.type)
107
+ unless nested_except.include?(e.type) or e.children.empty?
108
+ results.concat(find_type_elements_except(type, nested_except, e.children))
109
+ end
110
+ end
111
+ results
112
+ end
113
+
87
114
  ##
88
115
  # Returns the line number a given element is located on in the source
89
116
  # file. You can pass in either an element object or an options hash here.
@@ -186,9 +213,9 @@ module MarkdownLint
186
213
  # Returns line numbers for lines that match the given regular expression.
187
214
  # Only considers text inside of 'text' elements (i.e. regular markdown
188
215
  # text and not code/links or other elements).
189
- def matching_text_element_lines(re)
216
+ def matching_text_element_lines(re, exclude_nested=[:a])
190
217
  matches = []
191
- find_type_elements(:text).each do |e|
218
+ find_type_elements_except(:text, exclude_nested).each do |e|
192
219
  first_line = e.options[:location]
193
220
  lines = e.value.split("\n")
194
221
  lines.each_with_index do |l, i|
@@ -115,8 +115,13 @@ end
115
115
 
116
116
  rule "MD009", "Trailing spaces" do
117
117
  tags :whitespace
118
+ params :br_spaces => 0
118
119
  check do |doc|
119
- doc.matching_lines(/\s$/)
120
+ errors = doc.matching_lines(/\s$/)
121
+ if params[:br_spaces] > 1
122
+ errors -= doc.matching_lines(/\S\s{#{params[:br_spaces]}}$/)
123
+ end
124
+ errors
120
125
  end
121
126
  end
122
127
 
@@ -442,3 +447,86 @@ rule "MD032", "Lists should be surrounded by blank lines" do
442
447
  errors.uniq
443
448
  end
444
449
  end
450
+
451
+ rule "MD033", "Inline HTML" do
452
+ tags :html
453
+ check do |doc|
454
+ doc.element_linenumbers(doc.find_type(:html_element))
455
+ end
456
+ end
457
+
458
+ rule "MD034", "Bare URL used" do
459
+ tags :links, :url
460
+ check do |doc|
461
+ doc.matching_text_element_lines(/https?:\/\//)
462
+ end
463
+ end
464
+
465
+ rule "MD035", "Horizontal rule style" do
466
+ tags :hr
467
+ params :style => :consistent
468
+ check do |doc|
469
+ hrs = doc.find_type(:hr)
470
+ if hrs.empty?
471
+ []
472
+ else
473
+ if params[:style] == :consistent
474
+ doc_style = doc.element_line(hrs[0])
475
+ else
476
+ doc_style = params[:style]
477
+ end
478
+ doc.element_linenumbers(hrs.select{|e| doc.element_line(e) != doc_style})
479
+ end
480
+ end
481
+ end
482
+
483
+ rule "MD036", "Emphasis used instead of a header" do
484
+ tags :headers, :emphasis
485
+ check do |doc|
486
+ # We are looking for a paragraph consisting entirely of emphasized
487
+ # (italic/bold) text.
488
+ doc.element_linenumbers(doc.find_type_elements(:p, false).select{|p|
489
+ p.children.length == 1 && [:em, :strong].include?(p.children[0].type)})
490
+ end
491
+ end
492
+
493
+ rule "MD037", "Spaces inside emphasis markers" do
494
+ tags :whitespace, :emphasis
495
+ check do |doc|
496
+ # Kramdown doesn't parse emphasis with spaces, which means we can just
497
+ # look for emphasis patterns inside regular text with spaces just inside
498
+ # them.
499
+ (doc.matching_text_element_lines(/(\*\*?|__?)\s.+\1/) | \
500
+ doc.matching_text_element_lines(/(\*\*?|__?).+\s\1/)).sort
501
+ end
502
+ end
503
+
504
+ rule "MD038", "Spaces inside code span elements" do
505
+ tags :whitespace, :code
506
+ check do |doc|
507
+ # We only want to check single line codespan elements and not fenced code
508
+ # block that happen to be parsed as code spans.
509
+ doc.element_linenumbers(doc.find_type_elements(:codespan).select{
510
+ |i| i.value.match(/(^\s|\s$)/) and not i.value.include?("\n")})
511
+ end
512
+ end
513
+
514
+ rule "MD039", "Spaces inside link text" do
515
+ tags :whitespace, :links
516
+ check do |doc|
517
+ doc.element_linenumbers(doc.find_type_elements(:a).select{|e|
518
+ e.children[0].value.start_with?(" ") or
519
+ e.children[0].value.end_with?(" ")})
520
+ end
521
+ end
522
+
523
+ rule "MD040", "Fenced code blocks should have a language specified" do
524
+ tags :code, :language
525
+ check do |doc|
526
+ # Kramdown parses code blocks with language settings as code blocks with
527
+ # the class attribute set to language-languagename.
528
+ doc.element_linenumbers(doc.find_type_elements(:codeblock).select{|i|
529
+ not i.attr['class'].to_s.start_with?("language-") and
530
+ not doc.element_line(i).start_with?(" ")})
531
+ end
532
+ end
@@ -4,3 +4,8 @@ rule 'MD003', :style => :atx
4
4
  rule 'MD004', :style => :dash
5
5
  rule 'MD007', :indent => 4
6
6
  rule 'MD030', :ul_multi => 3, :ol_multi => 2
7
+ rule 'MD035', :style => "---"
8
+
9
+ # Inline HTML - this isn't forbidden by the style guide, and raw HTML use is
10
+ # explicitly mentioned in the 'email automatic links' section.
11
+ exclude_rule 'MD033'
@@ -1 +1,3 @@
1
1
  all
2
+
3
+ exclude_rule 'MD040' # Fenced code blocks should have a language specified
@@ -4,3 +4,6 @@ exclude_tag :line_length
4
4
 
5
5
  exclude_rule 'MD006' # Lists at beginning of line
6
6
  exclude_rule 'MD007' # List indentation
7
+ exclude_rule 'MD033' # Inline HTML
8
+ exclude_rule 'MD034' # Bare URL used
9
+ exclude_rule 'MD040' # Fenced code blocks should have a language specified
@@ -1,3 +1,3 @@
1
1
  module MarkdownLint
2
- VERSION = "0.1.0"
2
+ VERSION = "0.2.0"
3
3
  end
@@ -10,7 +10,7 @@ Gem::Specification.new do |spec|
10
10
  spec.email = ["mark@mivok.net"]
11
11
  spec.summary = %q{Markdown lint tool}
12
12
  spec.description = %q{Style checker/lint tool for markdown files}
13
- spec.homepage = "http://github.com/mivok/mdl"
13
+ spec.homepage = "http://github.com/mivok/markdownlint"
14
14
  spec.license = "MIT"
15
15
 
16
16
  spec.files = `git ls-files -z`.split("\x0")
@@ -29,5 +29,5 @@ The following code block doesn't have any dollar signs, and shouldn't fire:
29
29
  The following (fenced) code block doesn't have any content at all, and
30
30
  shouldn't fire:
31
31
 
32
- ```
32
+ ```bash
33
33
  ```
@@ -0,0 +1,35 @@
1
+ **Section 1: the first section {MD036}**
2
+
3
+ Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor
4
+ incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis
5
+ nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.
6
+ Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore
7
+ eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt
8
+ in culpa qui officia deserunt mollit anim id est laborum.
9
+
10
+ __Section 1.1: another section {MD036}__
11
+
12
+ Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor
13
+ incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis
14
+ nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.
15
+ Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore
16
+ eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt
17
+ in culpa qui officia deserunt mollit anim id est laborum.
18
+
19
+ *Section 2: yet more sections {MD036}*
20
+
21
+ Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor
22
+ incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis
23
+ nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.
24
+ Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore
25
+ eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt
26
+ in culpa qui officia deserunt mollit anim id est laborum.
27
+
28
+ _Section 3: oh no more sections {MD036}_
29
+
30
+ This is a normal paragraph
31
+ **that just happens to have emphasized text in**
32
+ even though the emphasized text is on its own line.
33
+
34
+ This is another **normal** paragraph with some text in it. This also should
35
+ not trigger the rule.
@@ -19,3 +19,9 @@ echo "World"
19
19
  ~~~
20
20
 
21
21
  None of the above should trigger any heading related rules.
22
+
23
+ ```
24
+ Code block without a language specifier
25
+ ```
26
+
27
+ {MD040:23}
@@ -0,0 +1,2 @@
1
+ all
2
+ exclude_rule "MD040"
@@ -0,0 +1,22 @@
1
+ ***
2
+
3
+ * * *
4
+
5
+ *****
6
+
7
+ ---
8
+
9
+ - - -
10
+
11
+ -----
12
+
13
+ ___
14
+
15
+ _ _ _
16
+
17
+ _____
18
+
19
+ ***
20
+
21
+ {MD035:1} {MD035:3} {MD035:5} {MD035:9} {MD035:11} {MD035:13} {MD035:15}
22
+ {MD035:17} {MD035:19}
@@ -0,0 +1,2 @@
1
+ all
2
+ rule "MD035", :style => "---"
@@ -0,0 +1,22 @@
1
+ ***
2
+
3
+ * * *
4
+
5
+ *****
6
+
7
+ ---
8
+
9
+ - - -
10
+
11
+ -----
12
+
13
+ ___
14
+
15
+ _ _ _
16
+
17
+ _____
18
+
19
+ ***
20
+
21
+ {MD035:3} {MD035:5} {MD035:7} {MD035:9} {MD035:11} {MD035:13} {MD035:15}
22
+ {MD035:17}
@@ -0,0 +1,22 @@
1
+ ***
2
+
3
+ * * *
4
+
5
+ *****
6
+
7
+ ---
8
+
9
+ - - -
10
+
11
+ -----
12
+
13
+ ___
14
+
15
+ _ _ _
16
+
17
+ _____
18
+
19
+ ***
20
+
21
+ {MD035:1} {MD035:3} {MD035:5} {MD035:7} {MD035:9} {MD035:11} {MD035:13}
22
+ {MD035:15} {MD035:19}
@@ -0,0 +1,2 @@
1
+ all
2
+ rule "MD035", :style => "_____"
@@ -0,0 +1,22 @@
1
+ ***
2
+
3
+ * * *
4
+
5
+ *****
6
+
7
+ ---
8
+
9
+ - - -
10
+
11
+ -----
12
+
13
+ ___
14
+
15
+ _ _ _
16
+
17
+ _____
18
+
19
+ ***
20
+
21
+ {MD035:3} {MD035:5} {MD035:7} {MD035:9} {MD035:11} {MD035:13} {MD035:15}
22
+ {MD035:17}
@@ -0,0 +1,2 @@
1
+ all
2
+ rule "MD035", :style => "***"
@@ -0,0 +1,13 @@
1
+ # Regular header
2
+
3
+ <h1>Inline HTML Header {MD033}</h1>
4
+
5
+ <p>More inline HTML {MD033}
6
+ but this time on multiple lines
7
+ </p>
8
+
9
+ <h1>This shouldn't trigger as it's inside a code block</h1>
10
+
11
+ ```text
12
+ <p>Neither should this as it's also in a code block</p>
13
+ ```
@@ -0,0 +1,9 @@
1
+ # Link test
2
+
3
+ For more information, please see the
4
+ following page: http://www.example.com/ {MD034}
5
+ which will tell you all you want to know.
6
+
7
+ http://www.google.com/ {MD034}
8
+
9
+ This link should be fine: <http://www.google.com/>
@@ -1,4 +1,4 @@
1
- Go to (this website)[http://www.example.com] {MD011}
1
+ Go to (this website)[http://www.example.com] {MD011} {MD034}
2
2
 
3
3
  However, this shouldn't trigger inside code blocks:
4
4
 
@@ -0,0 +1,7 @@
1
+ `normal codespan element`
2
+
3
+ ` codespan element with space inside left` {MD038}
4
+
5
+ `codespan element with space inside right ` {MD038}
6
+
7
+ ` codespan element with spaces inside ` {MD038}
@@ -0,0 +1,31 @@
1
+ Line with *Normal emphasis*
2
+
3
+ Line with **Normal strong**
4
+
5
+ Line with _Normal emphasis_
6
+
7
+ Line with __Normal strong__
8
+
9
+ Broken * emphasis * with spaces in {MD037}
10
+
11
+ Broken ** strong ** with spaces in {MD037}
12
+
13
+ Broken _ emphasis _ with spaces in {MD037}
14
+
15
+ Broken __ strong __ with spaces in {MD037}
16
+
17
+ Mixed *ok emphasis* and * broken emphasis * {MD037}
18
+
19
+ Mixed **ok strong** and ** broken strong ** {MD037}
20
+
21
+ Mixed _ok emphasis_ and _ broken emphasis _ {MD037}
22
+
23
+ Mixed __ok strong__ and __ broken strong __ {MD037}
24
+
25
+ Mixed *ok emphasis* **ok strong** * broken emphasis * {MD037}
26
+
27
+ Multiple * broken emphasis * _ broken emphasis _ {MD037}
28
+
29
+ One-sided *broken emphasis * {MD037}
30
+
31
+ One-sided * broken emphasis* {MD037}
@@ -0,0 +1,7 @@
1
+ [foo](http://bar/)
2
+
3
+ [foo ](http://bar/) {MD039}
4
+
5
+ [ foo](http://bar/) {MD039}
6
+
7
+ [ foo ](http://bar/) {MD039}
@@ -0,0 +1,4 @@
1
+ This line has a single trailing space {MD009}
2
+ This line has two trailing spaces and should be allowed
3
+ This line has three trailing spaces {MD009}
4
+ This line has four trailing spaces {MD009}
@@ -0,0 +1,2 @@
1
+ all
2
+ rule 'MD009', :br_spaces => 2
@@ -19,7 +19,7 @@ class TestRuledocs < Minitest::Test
19
19
  curr_rule = $1
20
20
  elsif l.match(/^Tags: (.*)$/)
21
21
  rules[curr_rule][:tags] = $1.split(',').map{|i| i.strip.to_sym}
22
- elsif l.match(/^Parameters: (.*)$/)
22
+ elsif l.match(/^Parameters: (.*)(\(.*\)?)$/)
23
23
  rules[curr_rule][:params] = $1.split(',').map{|i| i.strip.to_sym}
24
24
  end
25
25
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mdl
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
  - Mark Harrison
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-02-22 00:00:00.000000000 Z
11
+ date: 2015-04-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: kramdown
@@ -136,6 +136,7 @@ extra_rdoc_files: []
136
136
  files:
137
137
  - ".gitignore"
138
138
  - ".travis.yml"
139
+ - CHANGELOG.md
139
140
  - Gemfile
140
141
  - LICENSE.txt
141
142
  - README.md
@@ -174,9 +175,11 @@ files:
174
175
  - test/rule_tests/consistent_bullet_styles_asterisk.md
175
176
  - test/rule_tests/consistent_bullet_styles_dash.md
176
177
  - test/rule_tests/consistent_bullet_styles_plus.md
178
+ - test/rule_tests/emphasis_instead_of_headers.md
177
179
  - test/rule_tests/empty_doc.md
178
180
  - test/rule_tests/fenced_code_blocks.md
179
181
  - test/rule_tests/fenced_code_without_blank_lines.md
182
+ - test/rule_tests/fenced_code_without_blank_lines_style.rb
180
183
  - test/rule_tests/first_header_bad_atx.md
181
184
  - test/rule_tests/first_header_bad_setext.md
182
185
  - test/rule_tests/first_header_good_atx.md
@@ -192,6 +195,13 @@ files:
192
195
  - test/rule_tests/headers_surrounding_space_atx.md
193
196
  - test/rule_tests/headers_surrounding_space_setext.md
194
197
  - test/rule_tests/headers_with_spaces_at_the_beginning.md
198
+ - test/rule_tests/hr_style_dashes.md
199
+ - test/rule_tests/hr_style_dashes_style.rb
200
+ - test/rule_tests/hr_style_inconsistent.md
201
+ - test/rule_tests/hr_style_long.md
202
+ - test/rule_tests/hr_style_long_style.rb
203
+ - test/rule_tests/hr_style_stars.md
204
+ - test/rule_tests/hr_style_stars_style.rb
195
205
  - test/rule_tests/inconsistent_bullet_indent_same_level.md
196
206
  - test/rule_tests/inconsistent_bullet_styles_asterisk.md
197
207
  - test/rule_tests/inconsistent_bullet_styles_dash.md
@@ -208,6 +218,8 @@ files:
208
218
  - test/rule_tests/incorrect_header_atx_style.rb
209
219
  - test/rule_tests/incorrect_header_setext.md
210
220
  - test/rule_tests/incorrect_header_setext_style.rb
221
+ - test/rule_tests/inline_html.md
222
+ - test/rule_tests/links.md
211
223
  - test/rule_tests/lists_without_blank_lines.md
212
224
  - test/rule_tests/long_lines.md
213
225
  - test/rule_tests/long_lines_100.md
@@ -221,14 +233,19 @@ files:
221
233
  - test/rule_tests/reversed_link.md
222
234
  - test/rule_tests/spaces_after_list_marker.md
223
235
  - test/rule_tests/spaces_after_list_marker_style.rb
224
- - test/rule_tests/whitespace issues.md
236
+ - test/rule_tests/spaces_inside_codespan_elements.md
237
+ - test/rule_tests/spaces_inside_emphasis_markers.md
238
+ - test/rule_tests/spaces_inside_link_text.md
239
+ - test/rule_tests/trailing_spaces_br.md
240
+ - test/rule_tests/trailing_spaces_br_style.rb
241
+ - test/rule_tests/whitespace_issues.md
225
242
  - test/setup_tests.rb
226
243
  - test/test_ruledocs.rb
227
244
  - test/test_rules.rb
228
245
  - tools/README.md
229
246
  - tools/test_location.rb
230
247
  - tools/view_markdown.rb
231
- homepage: http://github.com/mivok/mdl
248
+ homepage: http://github.com/mivok/markdownlint
232
249
  licenses:
233
250
  - MIT
234
251
  metadata: {}
@@ -266,9 +283,11 @@ test_files:
266
283
  - test/rule_tests/consistent_bullet_styles_asterisk.md
267
284
  - test/rule_tests/consistent_bullet_styles_dash.md
268
285
  - test/rule_tests/consistent_bullet_styles_plus.md
286
+ - test/rule_tests/emphasis_instead_of_headers.md
269
287
  - test/rule_tests/empty_doc.md
270
288
  - test/rule_tests/fenced_code_blocks.md
271
289
  - test/rule_tests/fenced_code_without_blank_lines.md
290
+ - test/rule_tests/fenced_code_without_blank_lines_style.rb
272
291
  - test/rule_tests/first_header_bad_atx.md
273
292
  - test/rule_tests/first_header_bad_setext.md
274
293
  - test/rule_tests/first_header_good_atx.md
@@ -284,6 +303,13 @@ test_files:
284
303
  - test/rule_tests/headers_surrounding_space_atx.md
285
304
  - test/rule_tests/headers_surrounding_space_setext.md
286
305
  - test/rule_tests/headers_with_spaces_at_the_beginning.md
306
+ - test/rule_tests/hr_style_dashes.md
307
+ - test/rule_tests/hr_style_dashes_style.rb
308
+ - test/rule_tests/hr_style_inconsistent.md
309
+ - test/rule_tests/hr_style_long.md
310
+ - test/rule_tests/hr_style_long_style.rb
311
+ - test/rule_tests/hr_style_stars.md
312
+ - test/rule_tests/hr_style_stars_style.rb
287
313
  - test/rule_tests/inconsistent_bullet_indent_same_level.md
288
314
  - test/rule_tests/inconsistent_bullet_styles_asterisk.md
289
315
  - test/rule_tests/inconsistent_bullet_styles_dash.md
@@ -300,6 +326,8 @@ test_files:
300
326
  - test/rule_tests/incorrect_header_atx_style.rb
301
327
  - test/rule_tests/incorrect_header_setext.md
302
328
  - test/rule_tests/incorrect_header_setext_style.rb
329
+ - test/rule_tests/inline_html.md
330
+ - test/rule_tests/links.md
303
331
  - test/rule_tests/lists_without_blank_lines.md
304
332
  - test/rule_tests/long_lines.md
305
333
  - test/rule_tests/long_lines_100.md
@@ -313,7 +341,13 @@ test_files:
313
341
  - test/rule_tests/reversed_link.md
314
342
  - test/rule_tests/spaces_after_list_marker.md
315
343
  - test/rule_tests/spaces_after_list_marker_style.rb
316
- - test/rule_tests/whitespace issues.md
344
+ - test/rule_tests/spaces_inside_codespan_elements.md
345
+ - test/rule_tests/spaces_inside_emphasis_markers.md
346
+ - test/rule_tests/spaces_inside_link_text.md
347
+ - test/rule_tests/trailing_spaces_br.md
348
+ - test/rule_tests/trailing_spaces_br_style.rb
349
+ - test/rule_tests/whitespace_issues.md
317
350
  - test/setup_tests.rb
318
351
  - test/test_ruledocs.rb
319
352
  - test/test_rules.rb
353
+ has_rdoc: