rubocop-md 0.1.1 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: f5b04c2e0fbc284635fa82174064344fee7bbd71
4
- data.tar.gz: 0abd5499484c03abbdae84b89a82af505a025df8
2
+ SHA256:
3
+ metadata.gz: fc562e28add38f2053f69cfedb41bc66d86398191a6eaa55c067b33f738ecfe8
4
+ data.tar.gz: 5b9281774067e963d133b33674395b1cc92ade3d76d0a190f6eb8195464adbb2
5
5
  SHA512:
6
- metadata.gz: a943e124c09fe2fea37d0199b32568cfe166caa0d4d3745482d7a9992950a19939f70a9a2dee4d117086c9f55d5fc44f7cae30c60af42ec12be9b6f9c46d5ddf
7
- data.tar.gz: 65a2893d0e458f66b94271632060e238cc089ef6bfeeb120df6bc6aeea5838068b62c3ff07742227395a9ab2c30f0420be720d318f42259dc93341b25bd28ba6
6
+ metadata.gz: 4ddbf872ef05fb4f9ce11906f186970c9516eb5dfdf8560a369ed26c726b790226b0355510b59ca766d26f4bc6dc5c821b34ed635e8ba9fa30f541c68354d2bc
7
+ data.tar.gz: 54a503aa50566c9fa9f8e86cafe3f207c228c4aead514775f5bebee0d8c2f6e04be5b83d1c45ce0152895dfe4f1ffaf78b6b4137a63d95518e5ad49725301d36
@@ -1,2 +1,3 @@
1
1
  bump:
2
2
  file: lib/rubocop/markdown/version.rb
3
+ skip_ci: true
@@ -1,4 +1,5 @@
1
1
  AllCops:
2
+ NewCops: enable
2
3
  Include:
3
4
  - 'lib/**/*.rb'
4
5
  - 'lib/**/*.rake'
@@ -12,10 +13,7 @@ AllCops:
12
13
  - '*.gemspec'
13
14
  DisplayCopNames: true
14
15
  StyleGuideCopsOnly: false
15
- TargetRubyVersion: 2.2
16
-
17
- Rails:
18
- Enabled: false
16
+ TargetRubyVersion: 2.4
19
17
 
20
18
  Style/Documentation:
21
19
  Exclude:
@@ -31,13 +29,26 @@ Style/ClassAndModuleChildren:
31
29
  Exclude:
32
30
  - 'test/**/*.rb'
33
31
 
32
+ Style/HashEachMethods:
33
+ Enabled: true
34
+
35
+ Style/HashTransformKeys:
36
+ Enabled: true
37
+
38
+ Style/HashTransformValues:
39
+ Enabled: true
40
+
34
41
  Layout/EmptyLinesAroundArguments:
35
42
  Enabled: false
36
43
 
37
44
  Layout/SpaceInsideStringInterpolation:
38
45
  EnforcedStyle: no_space
39
46
 
40
- Metrics/LineLength:
47
+ Naming/FileName:
48
+ Exclude:
49
+ - 'lib/rubocop-md.rb'
50
+
51
+ Layout/LineLength:
41
52
  Max: 100
42
53
  Exclude:
43
54
  - 'test/**/*.rb'
@@ -1,17 +1,33 @@
1
1
  sudo: false
2
2
  language: ruby
3
- before_install: gem install bundler -v 1.15.4
3
+ before_install:
4
+ - gem uninstall -v '>= 2' -i $(rvm gemdir)@global -ax bundler || true
5
+ - gem install bundler -v '< 2'
6
+
7
+ notifications:
8
+ email: false
4
9
 
5
10
  matrix:
6
11
  fast_finish: true
7
12
  include:
8
13
  - rvm: ruby-head
9
14
  gemfile: gemfiles/rubocopmaster.gemfile
10
- - rvm: jruby-9.1.0.0
15
+ - rvm: jruby-9.2.8.0
11
16
  gemfile: Gemfile
12
- - rvm: 2.4.2
17
+ - rvm: 2.7
18
+ gemfile: gemfiles/rubocopmaster.gemfile
19
+ - rvm: 2.7
13
20
  gemfile: Gemfile
14
- - rvm: 2.3.1
21
+ - rvm: 2.6
15
22
  gemfile: Gemfile
16
- - rvm: 2.2.0
23
+ - rvm: 2.5
24
+ gemfile: Gemfile
25
+ - rvm: 2.4.2
17
26
  gemfile: Gemfile
27
+ allow_failures:
28
+ - rvm: ruby-head
29
+ gemfile: gemfiles/rubocopmaster.gemfile
30
+ - rvm: jruby-9.2.8.0
31
+ gemfile: Gemfile
32
+ - rvm: 2.5.0
33
+ gemfile: gemfiles/rubocopmaster.gemfile
@@ -0,0 +1,25 @@
1
+ # Change log
2
+
3
+ ## master (unreleased)
4
+
5
+ ## 0.4.0 (2020-07-03)
6
+
7
+ - [#10](https://github.com/rubocop-hq/rubocop-md/pull/10): **Drop Ruby 2.3 support** ([@dominicsayers][])
8
+
9
+ ## 0.3.2 (2020-03-18)
10
+
11
+ - [#9](https://github.com/rubocop-hq/rubocop-md/pull/9): Add file extensions for Markdown ([@ybiquitous][])
12
+
13
+ ## 0.3.1 (2019-12-25)
14
+
15
+ - Upgrade to RuboCop 0.78 ([@palkan][])
16
+
17
+ Change the default config to use the new cop names for (e.g., `Layout/LineLength`).
18
+
19
+ ## 0.3.0 (2019-05-14)
20
+
21
+ - **Drop Ruby 2.2 support** ([@palkan][])
22
+
23
+ [@palkan]: https://github.com/palkan
24
+ [@ybiquitous]: https://github.com/ybiquitous
25
+ [@dominicsayers]: https://github.com/dominicsayers
@@ -1,6 +1,6 @@
1
1
  The MIT License (MIT)
2
2
 
3
- Copyright (c) 2017 Vladimir Dementyev
3
+ Copyright (c) 2017-2019 Vladimir Dementyev
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  of this software and associated documentation files (the "Software"), to deal
data/README.md CHANGED
@@ -1,5 +1,5 @@
1
1
  [![Gem Version](https://badge.fury.io/rb/rubocop-md.svg)](http://badge.fury.io/rb/rubocop-md)
2
- [![Travis Status](https://travis-ci.org/palkan/rubocop-md.svg?branch=master)](https://travis-ci.org/palkan/rubocop-md)
2
+ [![Travis Status](https://travis-ci.org/rubocop-hq/rubocop-md.svg?branch=master)](https://travis-ci.org/rubocop-hq/rubocop-md)
3
3
 
4
4
  # Rubocop Markdown
5
5
 
@@ -24,7 +24,7 @@ gem 'rubocop-md'
24
24
 
25
25
  And then execute:
26
26
 
27
- $ bundle
27
+ $ bundle install
28
28
 
29
29
  Or install it yourself as:
30
30
 
@@ -46,22 +46,87 @@ 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
- - "rubocop-md"
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'
108
+ ```
109
+
110
+ ### But if I want to use inline disabling some directive like in classic RuboCop?
111
+
112
+ You can use this tricks
113
+
114
+ ```
115
+ # my_post.md
116
+
117
+ ... some markdown ...
118
+
119
+ <span style="display:none;"># rubocop:disable all</span>
120
+
121
+ ```ruby
122
+ def my_poor_method(foo)
123
+ [:a, :b, :c] + ["#{foo}".to_sym]
124
+ end
125
+ ``` end of snippet
126
+
127
+ <span style="display:none;"># rubocop:enable all</span>
128
+
129
+ ... continuation of article ...
65
130
  ```
66
131
 
67
132
  ## How it works?
@@ -73,9 +138,11 @@ Markdown:
73
138
  ## Limitations
74
139
 
75
140
  - 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
141
+ - Uses naive Regexp-based approach to extract code blocks from Markdown, support only backticks-style code blocks\*
77
142
  - No language detection included; if you do not specify language for your code blocks, you'd better turn `WarnInvalid` off (see above)
78
143
 
144
+ \* 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!
145
+
79
146
  ## Development
80
147
 
81
148
  After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests.
@@ -1,5 +1,6 @@
1
1
  Markdown:
2
2
  WarnInvalid: true
3
+ Autodetect: true
3
4
 
4
5
  Layout/CommentIndentation:
5
6
  Exclude:
@@ -16,6 +17,16 @@ Layout/TrailingBlankLines:
16
17
  - '**/*.md'
17
18
  - '**/*.markdown'
18
19
 
20
+ Layout/TrailingEmptyLines:
21
+ Exclude:
22
+ - '**/*.md'
23
+ - '**/*.markdown'
24
+
25
+ Lint/UselessAssignment:
26
+ Exclude:
27
+ - '**/*.md'
28
+ - '**/*.markdown'
29
+
19
30
  Naming/FileName:
20
31
  Exclude:
21
32
  - '**/*.md'
@@ -41,6 +52,6 @@ Style/FrozenStringLiteralComment:
41
52
  - '**/*.md'
42
53
  - '**/*.markdown'
43
54
 
44
- Metrics/LineLength:
55
+ Layout/LineLength:
45
56
  IgnoredPatterns:
46
57
  - !ruby/regexp /^\#/
@@ -1 +1,3 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require "rubocop/markdown"
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require "rubocop/markdown/version"
2
4
  require "pathname"
3
5
 
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require "ripper"
2
4
 
3
5
  module RuboCop
@@ -10,9 +12,9 @@ module RuboCop
10
12
  # Only recognizes backticks-style code blocks.
11
13
  #
12
14
  # Try it: http://rubular.com/r/iJaKBkSrrT
13
- MD_REGEXP = /^([ \t]*`{3,4})([\w[[:blank:]]]*\n)([\s\S]+?)(^[ \t]*\1[[:blank:]]*\n)/m
15
+ MD_REGEXP = /^([ \t]*`{3,4})([\w[[:blank:]]]*\n)([\s\S]+?)(^[ \t]*\1[[:blank:]]*\n?)/m.freeze
14
16
 
15
- MARKER = "<--rubocop/md-->".freeze
17
+ MARKER = "<--rubocop/md-->"
16
18
 
17
19
  # See https://github.com/github/linguist/blob/v5.3.3/lib/linguist/languages.yml#L3925
18
20
  RUBY_TYPES = %w[
@@ -72,7 +74,7 @@ module RuboCop
72
74
 
73
75
  parts.each do |part|
74
76
  if walker.code_body?
75
- next walker.next! if maybe_ruby?(@syntax) && valid_syntax?(part)
77
+ next walker.next! if maybe_ruby?(@syntax) && valid_syntax?(@syntax, part)
76
78
  end
77
79
 
78
80
  if walker.code_attr?
@@ -94,23 +96,37 @@ module RuboCop
94
96
  # Check codeblock attribute to prevent from parsing
95
97
  # non-Ruby snippets and avoid false positives
96
98
  def maybe_ruby?(syntax)
97
- syntax.empty? || RUBY_TYPES.include?(syntax)
99
+ (autodetect? && syntax.empty?) || ruby?(syntax)
100
+ end
101
+
102
+ # Check codeblack attribute if it's defined and of Ruby type
103
+ def ruby?(syntax)
104
+ RUBY_TYPES.include?(syntax)
98
105
  end
99
106
 
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?
107
+ # Try to parse with Ripper
108
+ # Invalid Ruby code (or non-Ruby) returns `nil`.
109
+ # Return true if it's explicit Ruby and warn_invalid?
110
+ def valid_syntax?(syntax, src)
111
+ return true if ruby?(syntax) && warn_invalid?
112
+
104
113
  !Ripper.sexp(src).nil?
105
114
  end
106
115
 
107
- # Where to show warning when snippet is not a valid Ruby
116
+ # Whether to show warning when snippet is not a valid Ruby
108
117
  def warn_invalid?
109
- config["Markdown"] && config["Markdown"].fetch("WarnInvalid", false)
118
+ config["Markdown"]&.fetch("WarnInvalid", true)
119
+ end
120
+
121
+ # Whether to try to detect Ruby by parsing codeblock.
122
+ # If it's set to false we lint only implicitly specified Ruby blocks.
123
+ def autodetect?
124
+ config["Markdown"]&.fetch("Autodetect", true)
110
125
  end
111
126
 
112
127
  def comment_lines!(src)
113
128
  return if src =~ /\A\n\z/
129
+
114
130
  src.gsub!(/^(.)/m, "##{MARKER}\\1")
115
131
  end
116
132
  end
@@ -1,9 +1,25 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module RuboCop
2
4
  module Markdown # :nodoc:
3
- MARKDOWN_EXTENSIONS = %w[.md .markdown].freeze
5
+ # According to Linguist.
6
+ # See https://github.com/github/linguist/blob/96ca71ab99c2f9928d5d69f4c08fd2a51440d045/lib/linguist/languages.yml#L3065-L3083
7
+ MARKDOWN_EXTENSIONS = %w[
8
+ .md
9
+ .markdown
10
+ .mdown
11
+ .mdwn
12
+ .mdx
13
+ .mkd
14
+ .mkdn
15
+ .mkdown
16
+ .ronn
17
+ .workbook
18
+ ].freeze
4
19
 
5
20
  class << self
6
21
  attr_accessor :config_store
22
+
7
23
  # Merge markdown config into default configuration
8
24
  # See https://github.com/backus/rubocop-rspec/blob/master/lib/rubocop/rspec/inject.rb
9
25
  def inject!
@@ -26,7 +42,7 @@ RuboCop::Markdown.inject!
26
42
 
27
43
  RuboCop::Runner.prepend(Module.new do
28
44
  # Set config store for Markdown
29
- def initialize(*)
45
+ def initialize(*args)
30
46
  super
31
47
  RuboCop::Markdown.config_store = @config_store
32
48
  end
@@ -35,6 +51,7 @@ RuboCop::Runner.prepend(Module.new do
35
51
  # NOTE: we should involve preprocessing in RuboCop::CachedData#deserialize_offenses
36
52
  def file_offense_cache(file)
37
53
  return yield if RuboCop::Markdown.markdown_file?(file)
54
+
38
55
  super
39
56
  end
40
57
 
@@ -61,7 +78,7 @@ RuboCop::ProcessedSource.prepend(Module.new do
61
78
  def parse(src, *args)
62
79
  # only process Markdown files
63
80
  src = RuboCop::Markdown::Preprocess.new(path).call(src) if
64
- path.nil? || RuboCop::Markdown.markdown_file?(path)
81
+ path && RuboCop::Markdown.markdown_file?(path)
65
82
  super(src, *args)
66
83
  end
67
84
  end)
@@ -1,5 +1,7 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module RuboCop
2
4
  module Markdown
3
- VERSION = "0.1.1".freeze
5
+ VERSION = "0.4.0"
4
6
  end
5
7
  end
@@ -17,11 +17,21 @@ Gem::Specification.new do |spec|
17
17
  f.match(%r{^(test|spec|features)/})
18
18
  end
19
19
 
20
+ spec.metadata = {
21
+ "bug_tracker_uri" => "http://github.com/rubocop-hq/rubocop-md/issues",
22
+ "changelog_uri" => "https://github.com/rubocop-hq/rubocop-md/blob/master/CHANGELOG.md",
23
+ "documentation_uri" => "https://github.com/rubocop-hq/rubocop-md/blob/master/README.md",
24
+ "homepage_uri" => "https://github.com/rubocop-hq/rubocop-md",
25
+ "source_code_uri" => "http://github.com/rubocop-hq/rubocop-md"
26
+ }
27
+
28
+ spec.required_ruby_version = ">= 2.4.0"
29
+
20
30
  spec.require_paths = ["lib"]
21
31
 
22
- spec.add_runtime_dependency "rubocop", "~> 0.50"
32
+ spec.add_runtime_dependency "rubocop", "~> 0.60"
23
33
 
24
- spec.add_development_dependency "bundler", "~> 1.15"
25
- spec.add_development_dependency "rake", "~> 10.0"
34
+ spec.add_development_dependency "bundler", ">= 1.15"
35
+ spec.add_development_dependency "rake", "~> 13.0"
26
36
  spec.add_development_dependency "minitest", "~> 5.0"
27
37
  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.4.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: 2020-07-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rubocop
@@ -16,26 +16,26 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: '0.50'
19
+ version: '0.60'
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: '0.50'
26
+ version: '0.60'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: bundler
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - "~>"
31
+ - - ">="
32
32
  - !ruby/object:Gem::Version
33
33
  version: '1.15'
34
34
  type: :development
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - "~>"
38
+ - - ">="
39
39
  - !ruby/object:Gem::Version
40
40
  version: '1.15'
41
41
  - !ruby/object:Gem::Dependency
@@ -44,14 +44,14 @@ dependencies:
44
44
  requirements:
45
45
  - - "~>"
46
46
  - !ruby/object:Gem::Version
47
- version: '10.0'
47
+ version: '13.0'
48
48
  type: :development
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
52
  - - "~>"
53
53
  - !ruby/object:Gem::Version
54
- version: '10.0'
54
+ version: '13.0'
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: minitest
57
57
  requirement: !ruby/object:Gem::Requirement
@@ -78,6 +78,7 @@ files:
78
78
  - ".gitignore"
79
79
  - ".rubocop.yml"
80
80
  - ".travis.yml"
81
+ - CHANGELOG.md
81
82
  - Gemfile
82
83
  - LICENSE.txt
83
84
  - README.md
@@ -94,7 +95,12 @@ files:
94
95
  homepage: https://github.com/palkan/rubocop-md
95
96
  licenses:
96
97
  - MIT
97
- metadata: {}
98
+ metadata:
99
+ bug_tracker_uri: http://github.com/rubocop-hq/rubocop-md/issues
100
+ changelog_uri: https://github.com/rubocop-hq/rubocop-md/blob/master/CHANGELOG.md
101
+ documentation_uri: https://github.com/rubocop-hq/rubocop-md/blob/master/README.md
102
+ homepage_uri: https://github.com/rubocop-hq/rubocop-md
103
+ source_code_uri: http://github.com/rubocop-hq/rubocop-md
98
104
  post_install_message:
99
105
  rdoc_options: []
100
106
  require_paths:
@@ -103,15 +109,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
103
109
  requirements:
104
110
  - - ">="
105
111
  - !ruby/object:Gem::Version
106
- version: '0'
112
+ version: 2.4.0
107
113
  required_rubygems_version: !ruby/object:Gem::Requirement
108
114
  requirements:
109
115
  - - ">="
110
116
  - !ruby/object:Gem::Version
111
117
  version: '0'
112
118
  requirements: []
113
- rubyforge_project:
114
- rubygems_version: 2.6.13
119
+ rubygems_version: 3.0.6
115
120
  signing_key:
116
121
  specification_version: 4
117
122
  summary: Run Rubocop against your Markdown files to make sure that code examples follow