rubocop-md 0.1.1 → 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: f5b04c2e0fbc284635fa82174064344fee7bbd71
4
- data.tar.gz: 0abd5499484c03abbdae84b89a82af505a025df8
3
+ metadata.gz: 79797f2e2130aabc8bac1cc72ecefe5acdb367d2
4
+ data.tar.gz: 4094bca4c4e9be29fa8b6630415e70c23a562838
5
5
  SHA512:
6
- metadata.gz: a943e124c09fe2fea37d0199b32568cfe166caa0d4d3745482d7a9992950a19939f70a9a2dee4d117086c9f55d5fc44f7cae30c60af42ec12be9b6f9c46d5ddf
7
- data.tar.gz: 65a2893d0e458f66b94271632060e238cc089ef6bfeeb120df6bc6aeea5838068b62c3ff07742227395a9ab2c30f0420be720d318f42259dc93341b25bd28ba6
6
+ metadata.gz: 60508616bb720460e5f6653aa0fa4ce852ad790858c32a52091e146d182d77cb6ac7d6a3ff0980c0917364aa21c8636e3d4529f0722ab161b821e9cc19320769
7
+ data.tar.gz: aa8cb2cdfd4416790d977f84a53feb031d551f2111ec701b3759a0fcb4ddc2fe8e1806685be0565b437b9ff08c48e282e2e418088d398087319f807f90d04873
data/.gem_release.yml CHANGED
@@ -1,2 +1,3 @@
1
1
  bump:
2
2
  file: lib/rubocop/markdown/version.rb
3
+ skip_ci: true
data/.travis.yml CHANGED
@@ -9,9 +9,20 @@ matrix:
9
9
  gemfile: gemfiles/rubocopmaster.gemfile
10
10
  - rvm: jruby-9.1.0.0
11
11
  gemfile: Gemfile
12
+ - rvm: 2.5.0
13
+ gemfile: gemfiles/rubocopmaster.gemfile
14
+ - rvm: 2.5.0
15
+ gemfile: Gemfile
12
16
  - rvm: 2.4.2
13
17
  gemfile: Gemfile
14
18
  - rvm: 2.3.1
15
19
  gemfile: Gemfile
16
20
  - rvm: 2.2.0
17
21
  gemfile: Gemfile
22
+ allow_failures:
23
+ - rvm: ruby-head
24
+ gemfile: gemfiles/rubocopmaster.gemfile
25
+ - rvm: jruby-9.1.0.0
26
+ gemfile: Gemfile
27
+ - rvm: 2.5.0
28
+ gemfile: gemfiles/rubocopmaster.gemfile
data/README.md CHANGED
@@ -46,22 +46,65 @@ Autocorrect works too:
46
46
  rubocop -r "rubocop-md" -a ./lib
47
47
  ```
48
48
 
49
- ### Configuration file
49
+ ### Configuration
50
50
 
51
- First, add `rubocop-md` to your `.rubocop.yml`:
51
+ Code in the documentation does not make sense to be checked for some style guidelines (eg `Style/FrozenStringLiteralComment`).
52
+
53
+ We described such rules in the [default config](config/default.yml), but if you use the same settings in your project’s `.rubocop.yml` file, `RoboCop` will override them.
54
+
55
+ Fortunately, `RuboCop` supports directory-level configuration and we can do the next trick.
56
+
57
+ At first, add `rubocop-md` to your main `.rubocop.yml`:
52
58
 
53
59
  ```yml
60
+ # .rubocop.yml
61
+
54
62
  require:
55
63
  - "rubocop-md"
56
64
  ```
57
65
 
58
- Additional options:
66
+ *Notice: additional options*
59
67
 
60
68
  ```yml
61
69
  # .rubocop.yml
70
+
62
71
  Markdown:
63
72
  # Whether to run RuboCop against non-valid snippets
64
73
  WarnInvalid: true
74
+ # Whether to lint codeblocks without code attributes
75
+ Autodetect: true
76
+ ```
77
+
78
+ Secondly, create empty `.rubocop.yml` in your docs directory.
79
+
80
+ ```bash
81
+ ├── docs
82
+ │ ├── .rubocop.yml
83
+ │ ├── doc1.md
84
+ │ ├── doc2.md
85
+ │ └── doc3.md
86
+ ├── lib
87
+ ├── .rubocop.yml # main
88
+ └── ...
89
+ ```
90
+
91
+ Third, just run
92
+
93
+ ```bash
94
+ $ rubocop
95
+ ```
96
+
97
+ Also you can add special rules in the second `.rubocop.yml`
98
+
99
+ ```ruby
100
+ # rubocop.yml in docs folder
101
+
102
+ Metrics/LineLength:
103
+ Max: 100
104
+
105
+ Lint/Void:
106
+ Exclude:
107
+ - '*.md'
65
108
  ```
66
109
 
67
110
  ## How it works?
@@ -73,9 +116,11 @@ Markdown:
73
116
  ## Limitations
74
117
 
75
118
  - RuboCop cache is disabled for Markdown files (because cache knows nothing about preprocessing)
76
- - Uses naive Regexp-based approach to extract code blocks from Markdown, support only backticks-style code blocks
119
+ - Uses naive Regexp-based approach to extract code blocks from Markdown, support only backticks-style code blocks\*
77
120
  - No language detection included; if you do not specify language for your code blocks, you'd better turn `WarnInvalid` off (see above)
78
121
 
122
+ \* It should be easy to integrate a _real_ parser (e.g. [Kramdown](https://kramdown.gettalong.org)) and handle all possible syntax. Feel free to open an issue or pull request!
123
+
79
124
  ## Development
80
125
 
81
126
  After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests.
data/config/default.yml CHANGED
@@ -1,5 +1,6 @@
1
1
  Markdown:
2
2
  WarnInvalid: true
3
+ Autodetect: true
3
4
 
4
5
  Layout/CommentIndentation:
5
6
  Exclude:
@@ -10,7 +10,7 @@ module RuboCop
10
10
  # Only recognizes backticks-style code blocks.
11
11
  #
12
12
  # Try it: http://rubular.com/r/iJaKBkSrrT
13
- MD_REGEXP = /^([ \t]*`{3,4})([\w[[:blank:]]]*\n)([\s\S]+?)(^[ \t]*\1[[:blank:]]*\n)/m
13
+ MD_REGEXP = /^([ \t]*`{3,4})([\w[[:blank:]]]*\n)([\s\S]+?)(^[ \t]*\1[[:blank:]]*\n?)/m
14
14
 
15
15
  MARKER = "<--rubocop/md-->".freeze
16
16
 
@@ -72,7 +72,7 @@ module RuboCop
72
72
 
73
73
  parts.each do |part|
74
74
  if walker.code_body?
75
- next walker.next! if maybe_ruby?(@syntax) && valid_syntax?(part)
75
+ next walker.next! if maybe_ruby?(@syntax) && valid_syntax?(@syntax, part)
76
76
  end
77
77
 
78
78
  if walker.code_attr?
@@ -94,19 +94,31 @@ module RuboCop
94
94
  # Check codeblock attribute to prevent from parsing
95
95
  # non-Ruby snippets and avoid false positives
96
96
  def maybe_ruby?(syntax)
97
- syntax.empty? || RUBY_TYPES.include?(syntax)
97
+ (autodetect? && syntax.empty?) || ruby?(syntax)
98
98
  end
99
99
 
100
- # Try to parse with Ripper.
101
- # Invalid Ruby (non-Ruby) code returns `nil`.
102
- def valid_syntax?(src)
103
- return true if warn_invalid?
100
+ # Check codeblack attribute if it's defined and of Ruby type
101
+ def ruby?(syntax)
102
+ RUBY_TYPES.include?(syntax)
103
+ end
104
+
105
+ # Try to parse with Ripper
106
+ # Invalid Ruby code (or non-Ruby) returns `nil`.
107
+ # Return true if it's explicit Ruby and warn_invalid?
108
+ def valid_syntax?(syntax, src)
109
+ return true if ruby?(syntax) && warn_invalid?
104
110
  !Ripper.sexp(src).nil?
105
111
  end
106
112
 
107
- # Where to show warning when snippet is not a valid Ruby
113
+ # Whether to show warning when snippet is not a valid Ruby
108
114
  def warn_invalid?
109
- config["Markdown"] && config["Markdown"].fetch("WarnInvalid", false)
115
+ config["Markdown"] && config["Markdown"].fetch("WarnInvalid", true)
116
+ end
117
+
118
+ # Whether to try to detect Ruby by parsing codeblock.
119
+ # If it's set to false we lint only implicitly specified Ruby blocks.
120
+ def autodetect?
121
+ config["Markdown"] && config["Markdown"].fetch("Autodetect", true)
110
122
  end
111
123
 
112
124
  def comment_lines!(src)
@@ -26,7 +26,7 @@ RuboCop::Markdown.inject!
26
26
 
27
27
  RuboCop::Runner.prepend(Module.new do
28
28
  # Set config store for Markdown
29
- def initialize(*)
29
+ def initialize(*args)
30
30
  super
31
31
  RuboCop::Markdown.config_store = @config_store
32
32
  end
@@ -1,5 +1,5 @@
1
1
  module RuboCop
2
2
  module Markdown
3
- VERSION = "0.1.1".freeze
3
+ VERSION = "0.2.0".freeze
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rubocop-md
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Vladimir Dementyev
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-12-12 00:00:00.000000000 Z
11
+ date: 2018-01-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rubocop