rubocop-schema-gen 0.1.2 → 0.1.6

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
  SHA256:
3
- metadata.gz: ad2887f7e9c6ed387de3ea9c44a785c2c846c351681226752d334bad5e42ac42
4
- data.tar.gz: dd3787e2db023d2dfc5a391bbc628e9796dc63d4578e604d2bd0eb2f9fb86ca6
3
+ metadata.gz: d98e35c60ef286f1d5c9df9233a47697e6902709cf821e35bab4e1fbbdc3bc3c
4
+ data.tar.gz: e510ba95ef1cebccef9309ac5645c5beb2b4cf62c37a7263545eedacc9420e03
5
5
  SHA512:
6
- metadata.gz: 0cb67d04acc4d37ba1c8d4e05fb269b6f22be79b0928666c5e1639cb0d7840caacc3140c0320cead6fe311fe9aae3fd6cf9ff6474854f65ff3f07d28849204ab
7
- data.tar.gz: 9f663797d40199ab878106996f4d6272c57c67f698ab9bb55fb222330c047330f49985eedd66cbcbd15acc0330e8da47dba38463f6039332d12d6fae2bc8514c
6
+ metadata.gz: 366bb50398f6bb733cd8ee2cd83294b0db503bf8c1580533c9498131d00a4b680f016211d8927ef320fc3228baad0ef7aa5f8508e716ef05a7bcac8cccb68cce
7
+ data.tar.gz: b68e8aa28af5a18e9f2efadce1cc32e8feb67274434b0ceaac1e9192945e0376dd91594c3279b7db61d950d7fff386bcf24630a29f74034fa28abb00ffa7ef92
@@ -24,8 +24,9 @@ module RuboCop
24
24
 
25
25
  def link_text(str)
26
26
  # The Asciidoctor API doesn't provide access to the raw title, or parts of it.
27
- # If performance becomes an issue, this could become a regexp or similarly crude solution.
28
- Nokogiri::HTML(str).at_css('a')&.text
27
+ return unless (text = str[%r{<a\s.+?>(.+?)</a>}, 1])
28
+
29
+ strip_html text
29
30
  end
30
31
 
31
32
  # @param [Asciidoctor::Table] table
@@ -1,6 +1,5 @@
1
1
  require 'pathname'
2
2
  require 'uri'
3
- require 'net/http'
4
3
 
5
4
  require 'rubocop/schema/helpers'
6
5
 
@@ -19,13 +19,15 @@ module RuboCop
19
19
  # @param [Hash] defaults
20
20
  def initialize(defaults)
21
21
  @cops = defaults.map do |cop_name, attributes|
22
+ next unless attributes.is_a? Hash
23
+
22
24
  CopInfo.new(
23
25
  name: cop_name,
24
26
  description: attributes['Description'],
25
27
  enabled_by_default: attributes['Enabled'] == true,
26
28
  attributes: transform_attributes(attributes)
27
29
  )
28
- end
30
+ end.compact
29
31
  end
30
32
 
31
33
  private
@@ -1,4 +1,5 @@
1
1
  require 'asciidoctor'
2
+ require 'yaml'
2
3
 
3
4
  module RuboCop
4
5
  module Schema
@@ -25,7 +26,7 @@ module RuboCop
25
26
  # @param [Spec] spec
26
27
  def defaults(spec)
27
28
  @defaults[spec] ||=
28
- YAML.safe_load @http_client.get(url_for_defaults(spec)), [Regexp, Symbol]
29
+ YAML.safe_load @http_client.get(url_for_defaults(spec)), [Regexp, Symbol], [], true
29
30
  end
30
31
 
31
32
  # @param [Spec] spec
@@ -1,5 +1,7 @@
1
- require 'nokogiri'
2
1
  require 'uri'
2
+ require 'yaml'
3
+ require 'net/http'
4
+ require 'cgi'
3
5
 
4
6
  module RuboCop
5
7
  module Schema
@@ -45,9 +47,8 @@ module RuboCop
45
47
 
46
48
  # Used for stripping HTML from Asciidoctor output, where raw output is not available, or not
47
49
  # appropriate to use.
48
- # TODO: look into the Asciidoctor for a way to do a non-HTML conversion
49
50
  def strip_html(str)
50
- Nokogiri::HTML(str).text
51
+ CGI.unescapeHTML str.gsub(/<.*?>/, '').gsub(/\s+/, ' ')
51
52
  end
52
53
 
53
54
  def http_get(url)
@@ -2,13 +2,18 @@ require 'json'
2
2
 
3
3
  require 'rubocop/schema/helpers'
4
4
  require 'rubocop/schema/diff'
5
+ require 'rubocop/schema/extension_spec'
6
+ require 'rubocop/schema/value_objects'
5
7
 
6
8
  module RuboCop
7
9
  module Schema
8
10
  class Repo
9
11
  include Helpers
10
12
 
11
- TAGS_URL_TEMPLATE = -'https://api.github.com/repos/rubocop/%s/tags'
13
+ # GitHub public APIs have a rate limit of 60/hour when making unauthenticated requests. 100 items
14
+ # per page is the maximum allowed, which we'll use to keep the number of requests to a minimum.
15
+ TAGS_PER_PAGE = 100
16
+ TAGS_URL_TEMPLATE = -"https://api.github.com/repos/rubocop/%s/tags?page=%d&per_page=#{TAGS_PER_PAGE}"
12
17
 
13
18
  def initialize(dir, loader, &event_handler)
14
19
  @dir = Pathname(dir)
@@ -69,10 +74,17 @@ module RuboCop
69
74
  end
70
75
 
71
76
  def versions_of(name)
72
- json = http_get(format(TAGS_URL_TEMPLATE, name))
73
- raise "No tags available for #{name}" if json == ''
77
+ tags = []
78
+ loop do
79
+ json = http_get(format(TAGS_URL_TEMPLATE, name, (tags.length / TAGS_PER_PAGE) + 1))
80
+ raise "No tags available for #{name}" if json == ''
74
81
 
75
- JSON.parse(json).reverse.map { |obj| obj['name'].to_s[/(?<=\Av)\d.+/] }.compact
82
+ parsed = JSON.parse(json)
83
+ tags += parsed
84
+ break unless parsed.length == TAGS_PER_PAGE
85
+ end
86
+
87
+ tags.reverse.map { |obj| obj['name'].to_s[/(?<=\Av)\d.+/] }.compact
76
88
  end
77
89
  end
78
90
  end
@@ -1,5 +1,5 @@
1
1
  module RuboCop
2
2
  module Schema
3
- VERSION = -'0.1.2'
3
+ VERSION = -'0.1.6'
4
4
  end
5
5
  end
@@ -1,5 +1,4 @@
1
1
  require 'pathname'
2
- require 'rubocop'
3
2
 
4
3
  require 'rubocop/schema/version'
5
4
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rubocop-schema-gen
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.1.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Neil E. Pearson
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2021-05-07 00:00:00.000000000 Z
11
+ date: 2021-11-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: asciidoctor
@@ -24,34 +24,6 @@ dependencies:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
26
  version: 2.0.14
27
- - !ruby/object:Gem::Dependency
28
- name: bundler
29
- requirement: !ruby/object:Gem::Requirement
30
- requirements:
31
- - - ">="
32
- - !ruby/object:Gem::Version
33
- version: '1.17'
34
- type: :runtime
35
- prerelease: false
36
- version_requirements: !ruby/object:Gem::Requirement
37
- requirements:
38
- - - ">="
39
- - !ruby/object:Gem::Version
40
- version: '1.17'
41
- - !ruby/object:Gem::Dependency
42
- name: nokogiri
43
- requirement: !ruby/object:Gem::Requirement
44
- requirements:
45
- - - "~>"
46
- - !ruby/object:Gem::Version
47
- version: '1'
48
- type: :runtime
49
- prerelease: false
50
- version_requirements: !ruby/object:Gem::Requirement
51
- requirements:
52
- - - "~>"
53
- - !ruby/object:Gem::Version
54
- version: '1'
55
27
  description: Generate JSON schemas for IDE integration with RuboCop
56
28
  email:
57
29
  - neil@helium.net.au
@@ -106,7 +78,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
106
78
  - !ruby/object:Gem::Version
107
79
  version: '0'
108
80
  requirements: []
109
- rubygems_version: 3.0.8
81
+ rubygems_version: 3.0.9
110
82
  signing_key:
111
83
  specification_version: 4
112
84
  summary: Generate JSON schemas for IDE integration with RuboCop