rubocop-schema-gen 0.1.0 → 0.1.5
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/LICENSE +13 -0
- data/README.md +20 -25
- data/assets/templates/cop_schema.yml +1 -3
- data/assets/templates/schema.yml +4 -0
- data/exe/rubocop-schema-gen +4 -2
- data/lib/rubocop/schema.rb +0 -4
- data/lib/rubocop/schema/ascii_doc/base.rb +52 -0
- data/lib/rubocop/schema/ascii_doc/cop.rb +93 -0
- data/lib/rubocop/schema/ascii_doc/department.rb +21 -0
- data/lib/rubocop/schema/ascii_doc/index.rb +20 -0
- data/lib/rubocop/schema/ascii_doc/stringifier.rb +49 -0
- data/lib/rubocop/schema/{cache.rb → cached_http_client.rb} +9 -12
- data/lib/rubocop/schema/cli.rb +94 -26
- data/lib/rubocop/schema/cop_info_merger.rb +54 -0
- data/lib/rubocop/schema/cop_schema.rb +69 -26
- data/lib/rubocop/schema/defaults_ripper.rb +48 -0
- data/lib/rubocop/schema/diff.rb +67 -0
- data/lib/rubocop/schema/document_loader.rb +55 -0
- data/lib/rubocop/schema/extension_spec.rb +67 -0
- data/lib/rubocop/schema/generator.rb +91 -0
- data/lib/rubocop/schema/helpers.rb +62 -0
- data/lib/rubocop/schema/repo.rb +91 -0
- data/lib/rubocop/schema/value_objects.rb +29 -3
- data/lib/rubocop/schema/version.rb +1 -1
- metadata +20 -36
- data/.gitignore +0 -19
- data/.rspec +0 -3
- data/.rubocop.yml +0 -38
- data/.ruby-version +0 -1
- data/.travis.yml +0 -6
- data/CODE_OF_CONDUCT.md +0 -74
- data/Gemfile +0 -10
- data/LICENSE.txt +0 -21
- data/Rakefile +0 -6
- data/bin/console +0 -14
- data/bin/setup +0 -8
- data/lib/rubocop/schema/lockfile_inspector.rb +0 -51
- data/lib/rubocop/schema/scraper.rb +0 -183
- data/lib/rubocop/schema/templates.rb +0 -8
- data/rubocop-schema.gemspec +0 -31
- data/rubocop-schema.json +0 -21110
@@ -0,0 +1,62 @@
|
|
1
|
+
require 'uri'
|
2
|
+
require 'yaml'
|
3
|
+
require 'net/http'
|
4
|
+
require 'cgi'
|
5
|
+
|
6
|
+
module RuboCop
|
7
|
+
module Schema
|
8
|
+
module Helpers
|
9
|
+
def self.templates
|
10
|
+
@templates ||= {}
|
11
|
+
end
|
12
|
+
|
13
|
+
def deep_dup(obj)
|
14
|
+
case obj
|
15
|
+
when String
|
16
|
+
obj.dup
|
17
|
+
when Hash
|
18
|
+
obj.transform_values &method(:deep_dup)
|
19
|
+
when Array
|
20
|
+
obj.map &method(:deep_dup)
|
21
|
+
else
|
22
|
+
obj
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
def deep_merge(old, new, &block)
|
27
|
+
return old if old.class != new.class
|
28
|
+
|
29
|
+
case old
|
30
|
+
when Hash
|
31
|
+
old.merge(new.map { |k, v| [k, old.key?(k) ? deep_merge(old[k], v, &block) : v] }.to_h)
|
32
|
+
.tap { |merged| yield merged if block_given? }
|
33
|
+
when Array
|
34
|
+
old | new
|
35
|
+
else
|
36
|
+
old
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
def boolean
|
41
|
+
{ 'type' => 'boolean' }
|
42
|
+
end
|
43
|
+
|
44
|
+
def template(name)
|
45
|
+
deep_dup(Helpers.templates[name] ||= YAML.load_file(ROOT.join('assets', 'templates', "#{name}.yml")).freeze)
|
46
|
+
end
|
47
|
+
|
48
|
+
# Used for stripping HTML from Asciidoctor output, where raw output is not available, or not
|
49
|
+
# appropriate to use.
|
50
|
+
def strip_html(str)
|
51
|
+
CGI.unescapeHTML str.gsub(/<.*?>/, '').gsub(/\s+/, ' ')
|
52
|
+
end
|
53
|
+
|
54
|
+
def http_get(url)
|
55
|
+
url = URI(url)
|
56
|
+
res = Net::HTTP.get_response(url)
|
57
|
+
res.body = '' unless res.is_a? Net::HTTPOK
|
58
|
+
res.body.force_encoding Encoding::UTF_8
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
@@ -0,0 +1,91 @@
|
|
1
|
+
require 'json'
|
2
|
+
|
3
|
+
require 'rubocop/schema/helpers'
|
4
|
+
require 'rubocop/schema/diff'
|
5
|
+
require 'rubocop/schema/extension_spec'
|
6
|
+
require 'rubocop/schema/value_objects'
|
7
|
+
|
8
|
+
module RuboCop
|
9
|
+
module Schema
|
10
|
+
class Repo
|
11
|
+
include Helpers
|
12
|
+
|
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}"
|
17
|
+
|
18
|
+
def initialize(dir, loader, &event_handler)
|
19
|
+
@dir = Pathname(dir)
|
20
|
+
@loader = loader
|
21
|
+
@event_handler = event_handler
|
22
|
+
@dir.mkpath
|
23
|
+
end
|
24
|
+
|
25
|
+
def build
|
26
|
+
ExtensionSpec::KNOWN_GEMS.each &method(:build_for_gem)
|
27
|
+
Event.dispatch message: "Repo updated: #{@dir}", &@event_handler
|
28
|
+
end
|
29
|
+
|
30
|
+
private
|
31
|
+
|
32
|
+
def build_for_gem(name)
|
33
|
+
existing = read(name).map { |h| [h['version'], h['diff']] }.to_h
|
34
|
+
previous = nil
|
35
|
+
body = versions_of(name).map do |version|
|
36
|
+
previous, diff = fetch_for_spec(Spec.new(name: name, version: version), existing, previous)
|
37
|
+
{
|
38
|
+
'version' => version,
|
39
|
+
'diff' => diff
|
40
|
+
}
|
41
|
+
end
|
42
|
+
write name, body.compact
|
43
|
+
end
|
44
|
+
|
45
|
+
def fetch_for_spec(spec, existing, previous)
|
46
|
+
if existing.key? spec.version
|
47
|
+
diff = existing[spec.version]
|
48
|
+
schema = Diff.apply(previous, diff)
|
49
|
+
else
|
50
|
+
schema = build_for_spec(spec)
|
51
|
+
diff = Diff.diff(previous, schema)
|
52
|
+
end
|
53
|
+
[schema, diff]
|
54
|
+
end
|
55
|
+
|
56
|
+
def build_for_spec(spec)
|
57
|
+
Event.dispatch message: "Generating: #{spec}", &@event_handler
|
58
|
+
Generator.new([spec], @loader).schema
|
59
|
+
end
|
60
|
+
|
61
|
+
def write(name, body)
|
62
|
+
path_for(name).binwrite JSON.pretty_generate body
|
63
|
+
end
|
64
|
+
|
65
|
+
def read(name)
|
66
|
+
path = path_for(name)
|
67
|
+
return [] unless path.exist?
|
68
|
+
|
69
|
+
JSON.parse path.read
|
70
|
+
end
|
71
|
+
|
72
|
+
def path_for(name)
|
73
|
+
@dir.join("#{name}.json")
|
74
|
+
end
|
75
|
+
|
76
|
+
def versions_of(name)
|
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 == ''
|
81
|
+
|
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
|
88
|
+
end
|
89
|
+
end
|
90
|
+
end
|
91
|
+
end
|
@@ -1,7 +1,33 @@
|
|
1
1
|
module RuboCop
|
2
2
|
module Schema
|
3
|
-
CopInfo = Struct.new(:name, :description, :attributes, :supports_autocorrect,
|
4
|
-
Attribute = Struct.new(:name, :type, :default
|
5
|
-
|
3
|
+
CopInfo = Struct.new(:name, :description, :attributes, :supports_autocorrect, :enabled_by_default)
|
4
|
+
Attribute = Struct.new(:name, :type, :default)
|
5
|
+
|
6
|
+
Event = Struct.new(:type, :message) do
|
7
|
+
def self.dispatch(**kwargs)
|
8
|
+
yield new(**kwargs) if block_given?
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
Spec = Struct.new(:name, :version) do
|
13
|
+
def short_name
|
14
|
+
return nil if name == 'rubocop'
|
15
|
+
|
16
|
+
name[8..-1]
|
17
|
+
end
|
18
|
+
|
19
|
+
def to_s
|
20
|
+
"#{short_name || name}-#{version}"
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
# Support for Ruby 2.4
|
25
|
+
module KeywordInitPatch
|
26
|
+
def initialize(**attrs)
|
27
|
+
super *self.class.members.map { |k| attrs[k] }
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
[CopInfo, Attribute, Event, Spec].each { |klass| klass.include KeywordInitPatch }
|
6
32
|
end
|
7
33
|
end
|
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.
|
4
|
+
version: 0.1.5
|
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-
|
11
|
+
date: 2021-06-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: asciidoctor
|
@@ -24,21 +24,7 @@ dependencies:
|
|
24
24
|
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: 2.0.14
|
27
|
-
|
28
|
-
name: nokogiri
|
29
|
-
requirement: !ruby/object:Gem::Requirement
|
30
|
-
requirements:
|
31
|
-
- - "~>"
|
32
|
-
- !ruby/object:Gem::Version
|
33
|
-
version: '1.11'
|
34
|
-
type: :runtime
|
35
|
-
prerelease: false
|
36
|
-
version_requirements: !ruby/object:Gem::Requirement
|
37
|
-
requirements:
|
38
|
-
- - "~>"
|
39
|
-
- !ruby/object:Gem::Version
|
40
|
-
version: '1.11'
|
41
|
-
description: Generate JSON schemas for IDE integration with Rubocop
|
27
|
+
description: Generate JSON schemas for IDE integration with RuboCop
|
42
28
|
email:
|
43
29
|
- neil@helium.net.au
|
44
30
|
executables:
|
@@ -46,32 +32,30 @@ executables:
|
|
46
32
|
extensions: []
|
47
33
|
extra_rdoc_files: []
|
48
34
|
files:
|
49
|
-
-
|
50
|
-
- ".rspec"
|
51
|
-
- ".rubocop.yml"
|
52
|
-
- ".ruby-version"
|
53
|
-
- ".travis.yml"
|
54
|
-
- CODE_OF_CONDUCT.md
|
55
|
-
- Gemfile
|
56
|
-
- LICENSE.txt
|
35
|
+
- LICENSE
|
57
36
|
- README.md
|
58
|
-
- Rakefile
|
59
37
|
- assets/templates/cop_schema.yml
|
60
38
|
- assets/templates/schema.yml
|
61
|
-
- bin/console
|
62
|
-
- bin/setup
|
63
39
|
- exe/rubocop-schema-gen
|
64
40
|
- lib/rubocop/schema.rb
|
65
|
-
- lib/rubocop/schema/
|
41
|
+
- lib/rubocop/schema/ascii_doc/base.rb
|
42
|
+
- lib/rubocop/schema/ascii_doc/cop.rb
|
43
|
+
- lib/rubocop/schema/ascii_doc/department.rb
|
44
|
+
- lib/rubocop/schema/ascii_doc/index.rb
|
45
|
+
- lib/rubocop/schema/ascii_doc/stringifier.rb
|
46
|
+
- lib/rubocop/schema/cached_http_client.rb
|
66
47
|
- lib/rubocop/schema/cli.rb
|
48
|
+
- lib/rubocop/schema/cop_info_merger.rb
|
67
49
|
- lib/rubocop/schema/cop_schema.rb
|
68
|
-
- lib/rubocop/schema/
|
69
|
-
- lib/rubocop/schema/
|
70
|
-
- lib/rubocop/schema/
|
50
|
+
- lib/rubocop/schema/defaults_ripper.rb
|
51
|
+
- lib/rubocop/schema/diff.rb
|
52
|
+
- lib/rubocop/schema/document_loader.rb
|
53
|
+
- lib/rubocop/schema/extension_spec.rb
|
54
|
+
- lib/rubocop/schema/generator.rb
|
55
|
+
- lib/rubocop/schema/helpers.rb
|
56
|
+
- lib/rubocop/schema/repo.rb
|
71
57
|
- lib/rubocop/schema/value_objects.rb
|
72
58
|
- lib/rubocop/schema/version.rb
|
73
|
-
- rubocop-schema.gemspec
|
74
|
-
- rubocop-schema.json
|
75
59
|
homepage: https://github.com/hx/rubocop-schema
|
76
60
|
licenses:
|
77
61
|
- MIT
|
@@ -87,7 +71,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
87
71
|
requirements:
|
88
72
|
- - ">="
|
89
73
|
- !ruby/object:Gem::Version
|
90
|
-
version:
|
74
|
+
version: 2.4.0
|
91
75
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
92
76
|
requirements:
|
93
77
|
- - ">="
|
@@ -97,5 +81,5 @@ requirements: []
|
|
97
81
|
rubygems_version: 3.2.3
|
98
82
|
signing_key:
|
99
83
|
specification_version: 4
|
100
|
-
summary: Generate JSON schemas for IDE integration with
|
84
|
+
summary: Generate JSON schemas for IDE integration with RuboCop
|
101
85
|
test_files: []
|
data/.gitignore
DELETED
data/.rspec
DELETED
data/.rubocop.yml
DELETED
@@ -1,38 +0,0 @@
|
|
1
|
-
# The behavior of RuboCop can be controlled via the .rubocop.yml
|
2
|
-
# configuration file. It makes it possible to enable/disable
|
3
|
-
# certain cops (checks) and to alter their behavior if they accept
|
4
|
-
# any parameters. The file can be placed either in your home
|
5
|
-
# directory or in some project directory.
|
6
|
-
#
|
7
|
-
# RuboCop will start looking for the configuration file in the directory
|
8
|
-
# where the inspected file is and continue its way up to the root directory.
|
9
|
-
#
|
10
|
-
# See https://docs.rubocop.org/rubocop/configuration
|
11
|
-
|
12
|
-
require:
|
13
|
-
- rubocop-rspec
|
14
|
-
- rubocop-rake
|
15
|
-
|
16
|
-
AllCops:
|
17
|
-
SuggestExtensions: false
|
18
|
-
NewCops: enable
|
19
|
-
TargetRubyVersion: 3.0
|
20
|
-
|
21
|
-
Layout/HashAlignment:
|
22
|
-
EnforcedColonStyle: table
|
23
|
-
EnforcedHashRocketStyle: table
|
24
|
-
|
25
|
-
Layout/MultilineMethodCallIndentation:
|
26
|
-
EnforcedStyle: indented
|
27
|
-
|
28
|
-
Style/FrozenStringLiteralComment:
|
29
|
-
EnforcedStyle: never
|
30
|
-
|
31
|
-
Style/Documentation:
|
32
|
-
Enabled: false
|
33
|
-
|
34
|
-
Style/StringConcatenation:
|
35
|
-
Enabled: false
|
36
|
-
|
37
|
-
Style/StderrPuts:
|
38
|
-
Enabled: false
|
data/.ruby-version
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
3.0.0
|
data/.travis.yml
DELETED
data/CODE_OF_CONDUCT.md
DELETED
@@ -1,74 +0,0 @@
|
|
1
|
-
# Contributor Covenant Code of Conduct
|
2
|
-
|
3
|
-
## Our Pledge
|
4
|
-
|
5
|
-
In the interest of fostering an open and welcoming environment, we as
|
6
|
-
contributors and maintainers pledge to making participation in our project and
|
7
|
-
our community a harassment-free experience for everyone, regardless of age, body
|
8
|
-
size, disability, ethnicity, gender identity and expression, level of experience,
|
9
|
-
nationality, personal appearance, race, religion, or sexual identity and
|
10
|
-
orientation.
|
11
|
-
|
12
|
-
## Our Standards
|
13
|
-
|
14
|
-
Examples of behavior that contributes to creating a positive environment
|
15
|
-
include:
|
16
|
-
|
17
|
-
* Using welcoming and inclusive language
|
18
|
-
* Being respectful of differing viewpoints and experiences
|
19
|
-
* Gracefully accepting constructive criticism
|
20
|
-
* Focusing on what is best for the community
|
21
|
-
* Showing empathy towards other community members
|
22
|
-
|
23
|
-
Examples of unacceptable behavior by participants include:
|
24
|
-
|
25
|
-
* The use of sexualized language or imagery and unwelcome sexual attention or
|
26
|
-
advances
|
27
|
-
* Trolling, insulting/derogatory comments, and personal or political attacks
|
28
|
-
* Public or private harassment
|
29
|
-
* Publishing others' private information, such as a physical or electronic
|
30
|
-
address, without explicit permission
|
31
|
-
* Other conduct which could reasonably be considered inappropriate in a
|
32
|
-
professional setting
|
33
|
-
|
34
|
-
## Our Responsibilities
|
35
|
-
|
36
|
-
Project maintainers are responsible for clarifying the standards of acceptable
|
37
|
-
behavior and are expected to take appropriate and fair corrective action in
|
38
|
-
response to any instances of unacceptable behavior.
|
39
|
-
|
40
|
-
Project maintainers have the right and responsibility to remove, edit, or
|
41
|
-
reject comments, commits, code, wiki edits, issues, and other contributions
|
42
|
-
that are not aligned to this Code of Conduct, or to ban temporarily or
|
43
|
-
permanently any contributor for other behaviors that they deem inappropriate,
|
44
|
-
threatening, offensive, or harmful.
|
45
|
-
|
46
|
-
## Scope
|
47
|
-
|
48
|
-
This Code of Conduct applies both within project spaces and in public spaces
|
49
|
-
when an individual is representing the project or its community. Examples of
|
50
|
-
representing a project or community include using an official project e-mail
|
51
|
-
address, posting via an official social media account, or acting as an appointed
|
52
|
-
representative at an online or offline event. Representation of a project may be
|
53
|
-
further defined and clarified by project maintainers.
|
54
|
-
|
55
|
-
## Enforcement
|
56
|
-
|
57
|
-
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
58
|
-
reported by contacting the project team at neil.pearson@bigcommerce.com. All
|
59
|
-
complaints will be reviewed and investigated and will result in a response that
|
60
|
-
is deemed necessary and appropriate to the circumstances. The project team is
|
61
|
-
obligated to maintain confidentiality with regard to the reporter of an incident.
|
62
|
-
Further details of specific enforcement policies may be posted separately.
|
63
|
-
|
64
|
-
Project maintainers who do not follow or enforce the Code of Conduct in good
|
65
|
-
faith may face temporary or permanent repercussions as determined by other
|
66
|
-
members of the project's leadership.
|
67
|
-
|
68
|
-
## Attribution
|
69
|
-
|
70
|
-
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
|
71
|
-
available at [https://contributor-covenant.org/version/1/4][version]
|
72
|
-
|
73
|
-
[homepage]: https://contributor-covenant.org
|
74
|
-
[version]: https://contributor-covenant.org/version/1/4/
|