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 +4 -4
- data/.gem_release.yml +1 -0
- data/.travis.yml +11 -0
- data/README.md +49 -4
- data/config/default.yml +1 -0
- data/lib/rubocop/markdown/preprocess.rb +21 -9
- data/lib/rubocop/markdown/rubocop_ext.rb +1 -1
- data/lib/rubocop/markdown/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 79797f2e2130aabc8bac1cc72ecefe5acdb367d2
|
4
|
+
data.tar.gz: 4094bca4c4e9be29fa8b6630415e70c23a562838
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 60508616bb720460e5f6653aa0fa4ce852ad790858c32a52091e146d182d77cb6ac7d6a3ff0980c0917364aa21c8636e3d4529f0722ab161b821e9cc19320769
|
7
|
+
data.tar.gz: aa8cb2cdfd4416790d977f84a53feb031d551f2111ec701b3759a0fcb4ddc2fe8e1806685be0565b437b9ff08c48e282e2e418088d398087319f807f90d04873
|
data/.gem_release.yml
CHANGED
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
|
49
|
+
### Configuration
|
50
50
|
|
51
|
-
|
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
|
-
|
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
@@ -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? ||
|
97
|
+
(autodetect? && syntax.empty?) || ruby?(syntax)
|
98
98
|
end
|
99
99
|
|
100
|
-
#
|
101
|
-
|
102
|
-
|
103
|
-
|
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
|
-
#
|
113
|
+
# Whether to show warning when snippet is not a valid Ruby
|
108
114
|
def warn_invalid?
|
109
|
-
config["Markdown"] && config["Markdown"].fetch("WarnInvalid",
|
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)
|
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.
|
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:
|
11
|
+
date: 2018-01-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rubocop
|