rubocop-md 1.2.1 → 1.2.3
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/CHANGELOG.md +8 -0
- data/README.md +2 -2
- data/config/default.yml +39 -64
- data/lib/rubocop/markdown/preprocess.rb +37 -46
- data/lib/rubocop/markdown/rubocop_ext.rb +24 -16
- data/lib/rubocop/markdown/version.rb +1 -1
- metadata +14 -14
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c7c6dbb228497df06f33f4c2c5f91b9fc719aa1026428b8ca86e596f4658ffcb
|
4
|
+
data.tar.gz: c42e2dea6fe018ec5e0f23dd39caeaff927408729ee69c911f7220446017d1c0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d3a4dd5d3e3eb894db690a40f699303f4350664516cd83475127786e8348086b0e23d8209fb2187aa0df33e287f4a6f72f840efe7b9dc7214b0113180299e59f
|
7
|
+
data.tar.gz: 5cd2b8c3675fd5fa84676c00d75ce2872dbc193ab4f55fc01283450c5bc3ad3774c80156b712332db467585baa8e3913064f5c14095102eb2bb979b572e1e51e
|
data/CHANGELOG.md
CHANGED
@@ -2,6 +2,14 @@
|
|
2
2
|
|
3
3
|
## master (unreleased)
|
4
4
|
|
5
|
+
## 1.2.3 (2024-09-12)
|
6
|
+
|
7
|
+
- Do no try linting `.mdx` files by default.
|
8
|
+
|
9
|
+
## 1.2.2 (2023-12-01) ❄️
|
10
|
+
|
11
|
+
- Fix analyzing code blocks with backticks.
|
12
|
+
|
5
13
|
## 1.2.1 (2023-10-20)
|
6
14
|
|
7
15
|
- Fix incompatibility when loading the plugin from YAML and using other RuboCop options.
|
data/README.md
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
[](http://badge.fury.io/rb/rubocop-md)
|
2
|
-

|
3
3
|
|
4
4
|
# Rubocop Markdown
|
5
5
|
|
@@ -158,7 +158,7 @@ To install this gem onto your local machine, run `bundle exec rake install`.
|
|
158
158
|
|
159
159
|
## Contributing
|
160
160
|
|
161
|
-
Bug reports and pull requests are welcome on GitHub at https://github.com/rubocop
|
161
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/rubocop/rubocop-md.
|
162
162
|
|
163
163
|
## License
|
164
164
|
|
data/config/default.yml
CHANGED
@@ -1,111 +1,86 @@
|
|
1
|
+
inherit_mode:
|
2
|
+
merge:
|
3
|
+
- Include
|
4
|
+
- Exclude
|
5
|
+
|
1
6
|
Markdown:
|
2
7
|
WarnInvalid: true
|
3
8
|
Autodetect: true
|
4
9
|
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
-
|
10
|
+
# Keep in sync with MARKDOWN_EXTENSIONS
|
11
|
+
Layout/CommentIndentation: &markdown_excludes
|
12
|
+
Exclude:
|
13
|
+
- "**/*.md"
|
14
|
+
- "**/*.livemd"
|
15
|
+
- "**/*.markdown"
|
16
|
+
- "**/*.mdown"
|
17
|
+
- "**/*.mdwn"
|
18
|
+
- "**/*.mkd"
|
19
|
+
- "**/*.mkdn"
|
20
|
+
- "**/*.mkdown"
|
21
|
+
- "**/*.ronn"
|
22
|
+
- "**/*.scd"
|
23
|
+
- "**/*.workbook"
|
9
24
|
|
10
25
|
Layout/LeadingCommentSpace:
|
11
|
-
|
12
|
-
- '**/*.md'
|
13
|
-
- '**/*.markdown'
|
26
|
+
<<: *markdown_excludes
|
14
27
|
|
15
28
|
Layout/TrailingBlankLines:
|
16
|
-
|
17
|
-
- '**/*.md'
|
18
|
-
- '**/*.markdown'
|
29
|
+
<<: *markdown_excludes
|
19
30
|
|
20
31
|
Layout/TrailingEmptyLines:
|
21
|
-
|
22
|
-
- '**/*.md'
|
23
|
-
- '**/*.markdown'
|
32
|
+
<<: *markdown_excludes
|
24
33
|
|
25
34
|
Layout/EmptyLineBetweenDefs:
|
26
|
-
|
27
|
-
- '**/*.md'
|
28
|
-
- '**/*.markdown'
|
35
|
+
<<: *markdown_excludes
|
29
36
|
|
30
37
|
Lint/DuplicateRequire:
|
31
|
-
|
32
|
-
- '**/*.md'
|
33
|
-
- '**/*.markdown'
|
38
|
+
<<: *markdown_excludes
|
34
39
|
|
35
40
|
Lint/DuplicateMethods:
|
36
|
-
|
37
|
-
- '**/*.md'
|
38
|
-
- '**/*.markdown'
|
41
|
+
<<: *markdown_excludes
|
39
42
|
|
40
43
|
Lint/RedundantCopDisableDirective:
|
41
|
-
|
42
|
-
- '**/*.md'
|
43
|
-
- '**/*.markdown'
|
44
|
+
<<: *markdown_excludes
|
44
45
|
|
45
46
|
Lint/RedundantCopEnableDirective:
|
46
|
-
|
47
|
-
- '**/*.md'
|
48
|
-
- '**/*.markdown'
|
47
|
+
<<: *markdown_excludes
|
49
48
|
|
50
49
|
Lint/RedundantRequireStatement:
|
51
|
-
|
52
|
-
- '**/*.md'
|
53
|
-
- '**/*.markdown'
|
50
|
+
<<: *markdown_excludes
|
54
51
|
|
55
52
|
Lint/UnusedMethodArgument:
|
56
|
-
|
57
|
-
- '**/*.md'
|
58
|
-
- '**/*.markdown'
|
53
|
+
<<: *markdown_excludes
|
59
54
|
|
60
55
|
Lint/UnusedBlockArgument:
|
61
|
-
|
62
|
-
- '**/*.md'
|
63
|
-
- '**/*.markdown'
|
56
|
+
<<: *markdown_excludes
|
64
57
|
|
65
58
|
Lint/UselessAssignment:
|
66
|
-
|
67
|
-
- '**/*.md'
|
68
|
-
- '**/*.markdown'
|
59
|
+
<<: *markdown_excludes
|
69
60
|
|
70
61
|
Lint/UselessMethodDefinition:
|
71
|
-
|
72
|
-
- '**/*.md'
|
73
|
-
- '**/*.markdown'
|
62
|
+
<<: *markdown_excludes
|
74
63
|
|
75
64
|
Lint/UselessAccessModifier:
|
76
|
-
|
77
|
-
- '**/*.md'
|
78
|
-
- '**/*.markdown'
|
65
|
+
<<: *markdown_excludes
|
79
66
|
|
80
67
|
Lint/Void:
|
81
|
-
|
82
|
-
- '**/*.md'
|
83
|
-
- '**/*.markdown'
|
68
|
+
<<: *markdown_excludes
|
84
69
|
|
85
70
|
Naming/FileName:
|
86
|
-
|
87
|
-
- '**/*.md'
|
88
|
-
- '**/*.markdown'
|
71
|
+
<<: *markdown_excludes
|
89
72
|
|
90
73
|
Style/AsciiComments:
|
91
|
-
|
92
|
-
- '**/*.md'
|
93
|
-
- '**/*.markdown'
|
74
|
+
<<: *markdown_excludes
|
94
75
|
|
95
76
|
Style/Documentation:
|
96
|
-
|
97
|
-
- '**/*.md'
|
98
|
-
- '**/*.markdown'
|
77
|
+
<<: *markdown_excludes
|
99
78
|
|
100
79
|
Style/CommentAnnotation:
|
101
|
-
|
102
|
-
- '**/*.md'
|
103
|
-
- '**/*.markdown'
|
80
|
+
<<: *markdown_excludes
|
104
81
|
|
105
82
|
Style/FrozenStringLiteralComment:
|
106
|
-
|
107
|
-
- '**/*.md'
|
108
|
-
- '**/*.markdown'
|
83
|
+
<<: *markdown_excludes
|
109
84
|
|
110
85
|
Layout/LineLength:
|
111
86
|
IgnoredPatterns:
|
@@ -7,12 +7,18 @@ module RuboCop
|
|
7
7
|
# Transform source Markdown file into valid Ruby file
|
8
8
|
# by commenting out all non-code lines
|
9
9
|
class Preprocess
|
10
|
-
# This is a regexp to
|
10
|
+
# This is a regexp to parse code blocks from .md files.
|
11
11
|
#
|
12
12
|
# Only recognizes backticks-style code blocks.
|
13
13
|
#
|
14
14
|
# Try it: https://rubular.com/r/YMqSWiBuh2TKIJ
|
15
|
-
MD_REGEXP =
|
15
|
+
MD_REGEXP = /
|
16
|
+
^([[:blank:]]*`{3,4}) # Match opening backticks
|
17
|
+
([\w[[:blank:]]+]*)?\n # Match the code block syntax
|
18
|
+
([\s\S]+?) # Match everything inside the code block
|
19
|
+
(^[[:blank:]]*\1[[:blank:]]*\n?) # Match closing backticks
|
20
|
+
|(^.*$) # If we are not in a codeblock, match the whole line
|
21
|
+
/x.freeze
|
16
22
|
|
17
23
|
MARKER = "<--rubocop/md-->"
|
18
24
|
|
@@ -26,26 +32,6 @@ module RuboCop
|
|
26
32
|
rbx
|
27
33
|
].freeze
|
28
34
|
|
29
|
-
class Walker # :nodoc:
|
30
|
-
STEPS = %i[text code_start code_attr code_body code_end].freeze
|
31
|
-
|
32
|
-
STEPS.each do |step|
|
33
|
-
define_method("#{step}?") do
|
34
|
-
STEPS[current_step] == step
|
35
|
-
end
|
36
|
-
end
|
37
|
-
|
38
|
-
attr_accessor :current_step
|
39
|
-
|
40
|
-
def initialize
|
41
|
-
@current_step = 0
|
42
|
-
end
|
43
|
-
|
44
|
-
def next!
|
45
|
-
self.current_step = current_step == (STEPS.size - 1) ? 0 : current_step + 1
|
46
|
-
end
|
47
|
-
end
|
48
|
-
|
49
35
|
class << self
|
50
36
|
# Revert preprocess changes.
|
51
37
|
#
|
@@ -53,11 +39,15 @@ module RuboCop
|
|
53
39
|
# using preproccessed source buffer.
|
54
40
|
#
|
55
41
|
# We have to restore it.
|
56
|
-
def
|
42
|
+
def restore_and_save!(file)
|
57
43
|
contents = File.read(file)
|
58
|
-
|
44
|
+
restore!(contents)
|
59
45
|
File.write(file, contents)
|
60
46
|
end
|
47
|
+
|
48
|
+
def restore!(src)
|
49
|
+
src.gsub!(/^##{MARKER}/m, "")
|
50
|
+
end
|
61
51
|
end
|
62
52
|
|
63
53
|
attr_reader :config
|
@@ -68,31 +58,34 @@ module RuboCop
|
|
68
58
|
|
69
59
|
# rubocop:disable Metrics/MethodLength
|
70
60
|
def call(src)
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
61
|
+
src.gsub(MD_REGEXP) do |full_match|
|
62
|
+
m = Regexp.last_match
|
63
|
+
open_backticks = m[1]
|
64
|
+
syntax = m[2]
|
65
|
+
code = m[3]
|
66
|
+
close_backticks = m[4]
|
67
|
+
markdown = m[5]
|
68
|
+
|
69
|
+
if markdown
|
70
|
+
# We got markdown outside of a codeblock
|
71
|
+
comment_lines(markdown)
|
72
|
+
elsif ruby_codeblock?(syntax, code)
|
73
|
+
# The codeblock we parsed is assumed ruby, keep as is and append markers to backticks
|
74
|
+
"#{comment_lines(open_backticks + syntax)}\n#{code}#{comment_lines(close_backticks)}"
|
75
|
+
else
|
76
|
+
# The codeblock is not relevant, comment it out
|
77
|
+
comment_lines(full_match)
|
78
78
|
end
|
79
|
-
|
80
|
-
if walker.code_attr?
|
81
|
-
@syntax = part.gsub(/(^\s+|\s+$)/, "")
|
82
|
-
next walker.next!
|
83
|
-
end
|
84
|
-
|
85
|
-
comment_lines! part
|
86
|
-
|
87
|
-
walker.next!
|
88
79
|
end
|
89
|
-
|
90
|
-
parts.join
|
91
80
|
end
|
92
81
|
# rubocop:enable Metrics/MethodLength
|
93
82
|
|
94
83
|
private
|
95
84
|
|
85
|
+
def ruby_codeblock?(syntax, src)
|
86
|
+
maybe_ruby?(syntax) && valid_syntax?(syntax, src)
|
87
|
+
end
|
88
|
+
|
96
89
|
# Check codeblock attribute to prevent from parsing
|
97
90
|
# non-Ruby snippets and avoid false positives
|
98
91
|
def maybe_ruby?(syntax)
|
@@ -124,10 +117,8 @@ module RuboCop
|
|
124
117
|
config["Markdown"]&.fetch("Autodetect", true)
|
125
118
|
end
|
126
119
|
|
127
|
-
def comment_lines
|
128
|
-
|
129
|
-
|
130
|
-
src.gsub!(/^(.)/m, "##{MARKER}\\1")
|
120
|
+
def comment_lines(src)
|
121
|
+
src.gsub(/^/, "##{MARKER}")
|
131
122
|
end
|
132
123
|
end
|
133
124
|
end
|
@@ -2,21 +2,25 @@
|
|
2
2
|
|
3
3
|
module RuboCop
|
4
4
|
module Markdown # :nodoc:
|
5
|
-
#
|
6
|
-
#
|
5
|
+
# See https://github.com/github-linguist/linguist/blob/8c380f360ce00b95fa08d14ce0ebccd481af1b33/lib/linguist/languages.yml#L4088-L4098
|
6
|
+
# Keep in sync with config/default.yml
|
7
7
|
MARKDOWN_EXTENSIONS = %w[
|
8
8
|
.md
|
9
|
+
.livemd
|
9
10
|
.markdown
|
10
11
|
.mdown
|
11
12
|
.mdwn
|
12
|
-
.mdx
|
13
13
|
.mkd
|
14
14
|
.mkdn
|
15
15
|
.mkdown
|
16
16
|
.ronn
|
17
|
+
.scd
|
17
18
|
.workbook
|
18
19
|
].freeze
|
19
20
|
|
21
|
+
# A list of cops that could produce offenses in commented lines
|
22
|
+
MARKDOWN_OFFENSE_COPS = %w[Lint/Syntax].freeze
|
23
|
+
|
20
24
|
class << self
|
21
25
|
attr_accessor :config_store
|
22
26
|
|
@@ -56,25 +60,29 @@ RuboCop::Runner.prepend(Module.new do
|
|
56
60
|
super
|
57
61
|
end
|
58
62
|
|
59
|
-
def inspect_file(*args)
|
60
|
-
super.tap do |(offenses, *)|
|
61
|
-
# Skip offenses reported for ignored MD source (trailing whitespaces, etc.)
|
62
|
-
marker_comment = "##{RuboCop::Markdown::Preprocess::MARKER}"
|
63
|
-
offenses.reject! do |offense|
|
64
|
-
offense.location.source_line.start_with?(marker_comment)
|
65
|
-
end
|
66
|
-
end
|
67
|
-
end
|
68
|
-
|
69
63
|
def file_finished(file, offenses)
|
70
64
|
return super unless RuboCop::Markdown.markdown_file?(file)
|
71
65
|
|
72
66
|
# Run Preprocess.restore if file has been autocorrected
|
73
67
|
if @options[:auto_correct] || @options[:autocorrect]
|
74
|
-
RuboCop::Markdown::Preprocess.
|
68
|
+
RuboCop::Markdown::Preprocess.restore_and_save!(file)
|
75
69
|
end
|
76
70
|
|
77
|
-
super
|
71
|
+
super
|
72
|
+
end
|
73
|
+
end)
|
74
|
+
|
75
|
+
RuboCop::Cop::Commissioner::InvestigationReport.prepend(Module.new do
|
76
|
+
# Skip offenses reported for ignored MD source (trailing whitespaces, etc.)
|
77
|
+
def offenses
|
78
|
+
@offenses ||= begin
|
79
|
+
marker_comment = "##{RuboCop::Markdown::Preprocess::MARKER}"
|
80
|
+
offenses_per_cop.flatten(1).reject do |offense|
|
81
|
+
next if RuboCop::Markdown::MARKDOWN_OFFENSE_COPS.include?(offense.cop_name)
|
82
|
+
|
83
|
+
offense.location.source_line.start_with?(marker_comment)
|
84
|
+
end
|
85
|
+
end
|
78
86
|
end
|
79
87
|
end)
|
80
88
|
|
@@ -91,6 +99,6 @@ RuboCop::ProcessedSource.prepend(Module.new do
|
|
91
99
|
# only process Markdown files
|
92
100
|
src = RuboCop::Markdown::Preprocess.new(path).call(src) if
|
93
101
|
path && RuboCop::Markdown.markdown_file?(path)
|
94
|
-
super
|
102
|
+
super
|
95
103
|
end
|
96
104
|
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: 1.2.
|
4
|
+
version: 1.2.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Vladimir Dementyev
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2024-09-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rubocop
|
@@ -16,14 +16,14 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: '1.
|
19
|
+
version: '1.45'
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - ">="
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: '1.
|
26
|
+
version: '1.45'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: bundler
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -83,16 +83,16 @@ files:
|
|
83
83
|
- lib/rubocop/markdown/preprocess.rb
|
84
84
|
- lib/rubocop/markdown/rubocop_ext.rb
|
85
85
|
- lib/rubocop/markdown/version.rb
|
86
|
-
homepage: https://github.com/rubocop
|
86
|
+
homepage: https://github.com/rubocop/rubocop-md
|
87
87
|
licenses:
|
88
88
|
- MIT
|
89
89
|
metadata:
|
90
|
-
bug_tracker_uri: http://github.com/rubocop
|
91
|
-
changelog_uri: https://github.com/rubocop
|
92
|
-
documentation_uri: https://github.com/rubocop
|
93
|
-
homepage_uri: https://github.com/rubocop
|
94
|
-
source_code_uri: http://github.com/rubocop
|
95
|
-
post_install_message:
|
90
|
+
bug_tracker_uri: http://github.com/rubocop/rubocop-md/issues
|
91
|
+
changelog_uri: https://github.com/rubocop/rubocop-md/blob/master/CHANGELOG.md
|
92
|
+
documentation_uri: https://github.com/rubocop/rubocop-md/blob/master/README.md
|
93
|
+
homepage_uri: https://github.com/rubocop/rubocop-md
|
94
|
+
source_code_uri: http://github.com/rubocop/rubocop-md
|
95
|
+
post_install_message:
|
96
96
|
rdoc_options: []
|
97
97
|
require_paths:
|
98
98
|
- lib
|
@@ -107,8 +107,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
107
107
|
- !ruby/object:Gem::Version
|
108
108
|
version: '0'
|
109
109
|
requirements: []
|
110
|
-
rubygems_version: 3.4.
|
111
|
-
signing_key:
|
110
|
+
rubygems_version: 3.4.19
|
111
|
+
signing_key:
|
112
112
|
specification_version: 4
|
113
113
|
summary: Run Rubocop against your Markdown files to make sure that code examples follow
|
114
114
|
style guidelines.
|