rubocop-rspec-documentation 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 6835013f9bdd9b919825c399180848fd02c1c5b66ea32a6a16d4558759e1deb9
4
+ data.tar.gz: 5d3e7ab0db9bbd8dfa22f689126cd254b5d56ee56d9a63377ebbbee0a5ed311a
5
+ SHA512:
6
+ metadata.gz: cf760e3954900da9d30b32a9884151f8bf85f3d2b91d30d6331d996dbfa590f3c1185cd288aff0e16ca0839fc0462d535e9043161891a8ee204dc2f0a83c4027
7
+ data.tar.gz: 9f1f527b654bfdcddb6a961830b5f5dcddca00eb4d458c08dd53ca012d2b4e8c9f81972c2eed9af99a4f6434808c6a2437aa981c50b3c84fd1a5d185689bab6c
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
data/.ruby-version ADDED
@@ -0,0 +1 @@
1
+ 2.7.8
data/Gemfile ADDED
@@ -0,0 +1,10 @@
1
+ # frozen_string_literal: true
2
+
3
+ source 'https://rubygems.org'
4
+
5
+ gemspec
6
+
7
+ gem 'devpack', '~> 0.4.1'
8
+ gem 'rake', '~> 13.0'
9
+ gem 'rspec', '~> 3.0'
10
+ gem 'strong_versions', '~> 0.4.5'
data/Gemfile.lock ADDED
@@ -0,0 +1,89 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ rubocop-rspec-documentation (0.0.1)
5
+ rspec-documentation (~> 0.0.7)
6
+ rubocop (~> 1.52)
7
+
8
+ GEM
9
+ remote: https://rubygems.org/
10
+ specs:
11
+ ast (2.4.2)
12
+ concurrent-ruby (1.2.2)
13
+ devpack (0.4.1)
14
+ diff-lcs (1.5.0)
15
+ htmlbeautifier (1.4.2)
16
+ i18n (1.14.1)
17
+ concurrent-ruby (~> 1.0)
18
+ json (2.6.3)
19
+ kramdown (2.4.0)
20
+ rexml
21
+ kramdown-parser-gfm (1.1.0)
22
+ kramdown (~> 2.0)
23
+ nokogiri (1.15.2-x86_64-linux)
24
+ racc (~> 1.4)
25
+ paint (2.3.0)
26
+ paintbrush (0.1.3)
27
+ parallel (1.23.0)
28
+ parser (3.2.2.3)
29
+ ast (~> 2.4.1)
30
+ racc
31
+ racc (1.7.0)
32
+ rainbow (3.1.1)
33
+ rake (13.0.6)
34
+ redcarpet (3.6.0)
35
+ regexp_parser (2.8.1)
36
+ rexml (3.2.5)
37
+ rouge (4.1.2)
38
+ rspec (3.12.0)
39
+ rspec-core (~> 3.12.0)
40
+ rspec-expectations (~> 3.12.0)
41
+ rspec-mocks (~> 3.12.0)
42
+ rspec-core (3.12.2)
43
+ rspec-support (~> 3.12.0)
44
+ rspec-documentation (0.0.7)
45
+ htmlbeautifier (~> 1.4)
46
+ kramdown (~> 2.4)
47
+ kramdown-parser-gfm (~> 1.1)
48
+ nokogiri (~> 1.15)
49
+ paintbrush (~> 0.1.3)
50
+ redcarpet (~> 3.6)
51
+ rouge (~> 4.1)
52
+ rspec (~> 3.12)
53
+ rspec-expectations (3.12.3)
54
+ diff-lcs (>= 1.2.0, < 2.0)
55
+ rspec-support (~> 3.12.0)
56
+ rspec-mocks (3.12.5)
57
+ diff-lcs (>= 1.2.0, < 2.0)
58
+ rspec-support (~> 3.12.0)
59
+ rspec-support (3.12.0)
60
+ rubocop (1.52.0)
61
+ json (~> 2.3)
62
+ parallel (~> 1.10)
63
+ parser (>= 3.2.0.0)
64
+ rainbow (>= 2.2.2, < 4.0)
65
+ regexp_parser (>= 1.8, < 3.0)
66
+ rexml (>= 3.2.5, < 4.0)
67
+ rubocop-ast (>= 1.28.0, < 2.0)
68
+ ruby-progressbar (~> 1.7)
69
+ unicode-display_width (>= 2.4.0, < 3.0)
70
+ rubocop-ast (1.29.0)
71
+ parser (>= 3.2.1.0)
72
+ ruby-progressbar (1.13.0)
73
+ strong_versions (0.4.5)
74
+ i18n (>= 0.5)
75
+ paint (~> 2.0)
76
+ unicode-display_width (2.4.2)
77
+
78
+ PLATFORMS
79
+ x86_64-linux
80
+
81
+ DEPENDENCIES
82
+ devpack (~> 0.4.1)
83
+ rake (~> 13.0)
84
+ rspec (~> 3.0)
85
+ rubocop-rspec-documentation!
86
+ strong_versions (~> 0.4.5)
87
+
88
+ BUNDLED WITH
89
+ 2.4.13
data/LICENSE ADDED
@@ -0,0 +1,7 @@
1
+ Copyright 2023 Robert Farrell
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
4
+
5
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
6
+
7
+ THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,21 @@
1
+ # Rubocop::Rspec::Documentation
2
+
3
+ _Rubocop_ extension for [RSpec::Documentation](https://github.com/bobf/rspec-documentation).
4
+
5
+ See [Rubocop](https://docs.bob.frl/rspec-documentation/rubocop.html) overview in _RSpec::Documentation_ documentation for usage instructions.
6
+
7
+ ## Installation
8
+
9
+ TODO: Replace `UPDATE_WITH_YOUR_GEM_NAME_PRIOR_TO_RELEASE_TO_RUBYGEMS_ORG` with your gem name right after releasing it to RubyGems.org. Please do not do it earlier due to security reasons. Alternatively, replace this section with instructions to install your gem from git if you don't plan to release to RubyGems.org.
10
+
11
+ Install the gem and add to the application's Gemfile by executing:
12
+
13
+ $ bundle add UPDATE_WITH_YOUR_GEM_NAME_PRIOR_TO_RELEASE_TO_RUBYGEMS_ORG
14
+
15
+ If bundler is not being used to manage dependencies, install the gem by executing:
16
+
17
+ $ gem install UPDATE_WITH_YOUR_GEM_NAME_PRIOR_TO_RELEASE_TO_RUBYGEMS_ORG
18
+
19
+ ## License
20
+
21
+ [MIT](LICENSE)
data/Rakefile ADDED
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'bundler/gem_tasks'
4
+ require 'rspec/core/rake_task'
5
+
6
+ RSpec::Core::RakeTask.new(:spec)
7
+
8
+ task default: :spec
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
@@ -0,0 +1,35 @@
1
+ ---
2
+ AllCops:
3
+ inherit_mode:
4
+ merge:
5
+ - Include
6
+ Include:
7
+ - 'rspec-documentation/pages/**/*.md'
8
+
9
+ RSpec:
10
+ inherit_mode:
11
+ merge:
12
+ - Include
13
+ Include:
14
+ - 'rspec-documentation/pages/**/*.md'
15
+
16
+ Naming/FileName:
17
+ inherit_mode:
18
+ merge:
19
+ - Exclude
20
+ Exclude:
21
+ - 'rspec-documentation/pages/**/*.md'
22
+
23
+ Gemspec/RequiredRubyVersion:
24
+ inherit_mode:
25
+ merge:
26
+ - Exclude
27
+ Exclude:
28
+ - 'rspec-documentation/pages/**/*.md'
29
+
30
+ Style/FrozenStringLiteralComment:
31
+ inherit_mode:
32
+ merge:
33
+ - Exclude
34
+ Exclude:
35
+ - 'rspec-documentation/pages/**/*.md'
@@ -0,0 +1,42 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'rubocop'
4
+
5
+ module RuboCop
6
+ module RSpecDocumentation
7
+ # Extracts Ruby code from Markdown documentation files and generates an output compatible
8
+ # with RuboCop's code extraction mechanism:
9
+ # https://docs.rubocop.org/rubocop/extensions.html#configuring-an-extension
10
+ class RubyExtractor
11
+ def call(processed_source)
12
+ return nil unless relevant?(processed_source.path)
13
+
14
+ specs.select { |spec| spec.path.expand_path.to_s == processed_source.path }
15
+ .map { |spec| extracted_spec(spec, processed_source) }
16
+ end
17
+
18
+ private
19
+
20
+ def specs
21
+ @specs ||= ::RSpecDocumentation::Documentation.new.page_collection.documents.map(&:specs).flatten
22
+ end
23
+
24
+ def relevant?(path)
25
+ path.start_with?(::RSpecDocumentation::Util.base_dir.to_s) && Pathname.new(path).extname == '.md'
26
+ end
27
+
28
+ def rspec_documentation_processed_source(spec, processed_source)
29
+ RuboCop::ProcessedSource.new(spec.source, RUBY_VERSION.to_f, processed_source.path)
30
+ end
31
+
32
+ def extracted_spec(spec, processed_source)
33
+ {
34
+ offset: spec.path.readlines[...spec.location - 2].sum(&:size),
35
+ processed_source: rspec_documentation_processed_source(spec, processed_source)
36
+ }
37
+ end
38
+ end
39
+ end
40
+ end
41
+
42
+ RuboCop::Runner.ruby_extractors.unshift(RuboCop::RSpecDocumentation::RubyExtractor.new)
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RuboCop
4
+ module RSpec
5
+ module Documentation
6
+ VERSION = '0.0.1'
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,35 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'rspec/documentation'
4
+ require_relative 'documentation/ruby_extractor'
5
+
6
+ # XXX: This is the "official" way to create a Rubocop plugin, all code below this comment is
7
+ # taken directly from here:
8
+ # https://github.com/rubocop/rubocop-extension-generator/blob/master/lib/rubocop/extension/generator/generator.rb
9
+
10
+ # The original code is from https://github.com/rubocop/rubocop-rspec/blob/master/lib/rubocop/rspec/inject.rb
11
+ # See https://github.com/rubocop/rubocop-rspec/blob/master/MIT-LICENSE.md
12
+ module RuboCop
13
+ # RuboCop extension for RSpec::Documentation
14
+ module RSpecDocumentation
15
+ PROJECT_ROOT = Pathname.new(__dir__).parent.parent.expand_path.freeze
16
+ CONFIG_DEFAULT = PROJECT_ROOT.join('rubocop/rspec/documentation/default.yml').freeze
17
+ CONFIG = YAML.safe_load(CONFIG_DEFAULT.read).freeze
18
+
19
+ private_constant(:CONFIG_DEFAULT, :PROJECT_ROOT)
20
+
21
+ # Because RuboCop doesn't yet support plugins, we have to monkey patch in a bit of our configuration.
22
+ module Inject
23
+ def self.defaults!
24
+ path = CONFIG_DEFAULT.to_s
25
+ hash = ConfigLoader.send(:load_yaml_configuration, path)
26
+ config = Config.new(hash, path).tap(&:make_excludes_absolute)
27
+ puts "configuration from \#{path}" if ConfigLoader.debug?
28
+ config = ConfigLoader.merge_with_default(config, path)
29
+ ConfigLoader.instance_variable_set(:@default_configuration, config)
30
+ end
31
+ end
32
+ end
33
+ end
34
+
35
+ RuboCop::RSpecDocumentation::Inject.defaults!
@@ -0,0 +1,32 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'lib/rubocop/rspec/documentation/version'
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = 'rubocop-rspec-documentation'
7
+ spec.version = RuboCop::RSpec::Documentation::VERSION
8
+ spec.authors = ['Bob Farrell']
9
+ spec.email = ['git@bob.frl']
10
+ spec.licenses = ['MIT']
11
+
12
+ spec.summary = 'Rubocop integration with rspec-documentation'
13
+ spec.description = 'Lint RSpec examples embedded in Markdown files'
14
+ spec.homepage = 'https://github.com/bobf/rubocop-rspec-documentation'
15
+ spec.required_ruby_version = '>= 2.7.0'
16
+
17
+ spec.metadata['homepage_uri'] = spec.homepage
18
+ spec.metadata['source_code_uri'] = spec.homepage
19
+ spec.metadata['changelog_uri'] = spec.homepage
20
+
21
+ spec.files = Dir.chdir(__dir__) do
22
+ `git ls-files -z`.split("\x0").reject do |f|
23
+ (File.expand_path(f) == __FILE__) || f.start_with?(*%w[bin/ test/ spec/ features/ .git .circleci appveyor])
24
+ end
25
+ end
26
+
27
+ spec.bindir = 'exe'
28
+ spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
29
+ spec.require_paths = ['lib']
30
+ spec.add_runtime_dependency 'rspec-documentation', '~> 0.0.7'
31
+ spec.add_runtime_dependency 'rubocop', '~> 1.52'
32
+ end
metadata ADDED
@@ -0,0 +1,88 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rubocop-rspec-documentation
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Bob Farrell
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2023-06-13 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rspec-documentation
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: 0.0.7
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: 0.0.7
27
+ - !ruby/object:Gem::Dependency
28
+ name: rubocop
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.52'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.52'
41
+ description: Lint RSpec examples embedded in Markdown files
42
+ email:
43
+ - git@bob.frl
44
+ executables:
45
+ - rubocop-rspec-documentation
46
+ extensions: []
47
+ extra_rdoc_files: []
48
+ files:
49
+ - ".rspec"
50
+ - ".ruby-version"
51
+ - Gemfile
52
+ - Gemfile.lock
53
+ - LICENSE
54
+ - README.md
55
+ - Rakefile
56
+ - exe/rubocop-rspec-documentation
57
+ - lib/rubocop/rspec/documentation.rb
58
+ - lib/rubocop/rspec/documentation/default.yml
59
+ - lib/rubocop/rspec/documentation/ruby_extractor.rb
60
+ - lib/rubocop/rspec/documentation/version.rb
61
+ - rubocop-rspec-documentation.gemspec
62
+ homepage: https://github.com/bobf/rubocop-rspec-documentation
63
+ licenses:
64
+ - MIT
65
+ metadata:
66
+ homepage_uri: https://github.com/bobf/rubocop-rspec-documentation
67
+ source_code_uri: https://github.com/bobf/rubocop-rspec-documentation
68
+ changelog_uri: https://github.com/bobf/rubocop-rspec-documentation
69
+ post_install_message:
70
+ rdoc_options: []
71
+ require_paths:
72
+ - lib
73
+ required_ruby_version: !ruby/object:Gem::Requirement
74
+ requirements:
75
+ - - ">="
76
+ - !ruby/object:Gem::Version
77
+ version: 2.7.0
78
+ required_rubygems_version: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ requirements: []
84
+ rubygems_version: 3.1.6
85
+ signing_key:
86
+ specification_version: 4
87
+ summary: Rubocop integration with rspec-documentation
88
+ test_files: []