rubocop-schema-gen 0.1.0

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: 9896f77d8a3c4c39bd31f21878bffdb2d8979dee897b5fe38b3ef090bd11043d
4
+ data.tar.gz: bfa9fe9b715b977f1dc973f48e80eafe59a448545bbef559247055bd98cfc5bd
5
+ SHA512:
6
+ metadata.gz: 074f101c7a87e0ce7e1de730a82b6bc83682bf0068d60519c1b042ca6bbcc7d3ca574e5ed47f3fec0f2cb63ce3639b98ab2915b90644b1e349aa4c589c3d6cab
7
+ data.tar.gz: aeafc3e4661bed171c7d182ffbf6c752ded81d002623984bd0e146072c70fca9609d79410a8f5c23fe031c49caf15755d8ad5a3fe120955e7f23b9ddbd813398
data/.gitignore ADDED
@@ -0,0 +1,19 @@
1
+ # Actual stuff
2
+
3
+ /cache
4
+ /.cache
5
+ /Gemfile.lock
6
+
7
+ # Generated by `bundle gem`
8
+
9
+ /.bundle/
10
+ /.yardoc
11
+ /_yardoc/
12
+ /coverage/
13
+ /doc/
14
+ /pkg/
15
+ /spec/reports/
16
+ /tmp/
17
+
18
+ # rspec failure tracking
19
+ .rspec_status
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
data/.rubocop.yml ADDED
@@ -0,0 +1,38 @@
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 ADDED
@@ -0,0 +1 @@
1
+ 3.0.0
data/.travis.yml ADDED
@@ -0,0 +1,6 @@
1
+ ---
2
+ language: ruby
3
+ cache: bundler
4
+ rvm:
5
+ - 3.0.0
6
+ before_install: gem install bundler -v 2.1.4
@@ -0,0 +1,74 @@
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/
data/Gemfile ADDED
@@ -0,0 +1,10 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in rubocop-schema.gemspec
4
+ gemspec
5
+
6
+ gem 'rake', '~> 12.0'
7
+ gem 'rspec', '~> 3.0'
8
+ gem 'rubocop', '~> 1.13.0', require: false
9
+ gem 'rubocop-rake', require: false
10
+ gem 'rubocop-rspec', require: false
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2021 Neil E. Pearson
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,44 @@
1
+ # Rubocop::Schema
2
+
3
+ Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/rubocop/schema`. To experiment with that code, run `bin/console` for an interactive prompt.
4
+
5
+ TODO: Delete this and the text above, and describe your gem
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'rubocop-schema'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle install
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install rubocop-schema
22
+
23
+ ## Usage
24
+
25
+ TODO: Write usage instructions here
26
+
27
+ ## Development
28
+
29
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
30
+
31
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
32
+
33
+ ## Contributing
34
+
35
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/rubocop-schema. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/[USERNAME]/rubocop-schema/blob/master/CODE_OF_CONDUCT.md).
36
+
37
+
38
+ ## License
39
+
40
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
41
+
42
+ ## Code of Conduct
43
+
44
+ Everyone interacting in the Rubocop::Schema project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/rubocop-schema/blob/master/CODE_OF_CONDUCT.md).
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require 'bundler/gem_tasks'
2
+ require 'rspec/core/rake_task'
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task default: :spec
@@ -0,0 +1,15 @@
1
+ type: object
2
+ additionalProperties: true
3
+
4
+ propertyNames:
5
+ type: string
6
+ pattern: '^[A-Z][A-Za-z]*$'
7
+
8
+ properties:
9
+ Enabled: { type: boolean }
10
+ Exclude: { $ref: '#/definitions/listOfFiles' }
11
+ Include: { $ref: '#/definitions/listOfFiles' }
12
+ Severity: { $ref: '#/definitions/severity' }
13
+ Details: { type: string }
14
+ StyleGuideBaseURL: { type: string }
15
+ StyleGuide: { type: string }
@@ -0,0 +1,67 @@
1
+ $schema: http://json-schema.org/draft-07/schema
2
+
3
+ title: RuboCop configuration schema
4
+ description: >-
5
+ Schema for RuboCop configuration files (e.g. .rubocop.yml), intended for
6
+ helping IDEs provide autocompletion and validation.
7
+
8
+ type: object
9
+ additionalProperties: false
10
+
11
+ definitions:
12
+ inherit_mode:
13
+ type: object
14
+ minProperties: 1
15
+ propertyNames:
16
+ enum:
17
+ - merge
18
+ - override
19
+ additionalProperties:
20
+ type: array
21
+ minItems: 1
22
+ items: { type: string }
23
+
24
+ listOfFiles:
25
+ type: array
26
+ items: { type: string }
27
+
28
+ severity:
29
+ type: string
30
+ enum:
31
+ - info
32
+ - refactor
33
+ - convention
34
+ - warning
35
+ - error
36
+ - fatal
37
+
38
+ stringOrStrings:
39
+ oneOf:
40
+ - type: string
41
+ - type: array
42
+ items: { type: string }
43
+
44
+ properties:
45
+ inherit_from: { type: string }
46
+
47
+ inherit_gem:
48
+ type: object
49
+ additionalProperties: { $ref: '#/definitions/stringOrStrings' }
50
+
51
+ require: { $ref: '#/definitions/stringOrStrings' }
52
+
53
+ inherit_mode: { $ref: '#/definitions/inherit_mode' }
54
+
55
+ AllCops:
56
+ type: object
57
+ additionalProperties: false
58
+ properties:
59
+ Exclude: { $ref: '#/definitions/listOfFiles' }
60
+ Include: { $ref: '#/definitions/listOfFiles' }
61
+ NewCops: { enum: [ enable, disable ] }
62
+ EnabledByDefault: { type: boolean }
63
+ DisabledByDefault: { type: boolean }
64
+ SuggestExtensions: { type: boolean }
65
+ TargetRubyVersion: { type: number }
66
+ StyleGuideBaseURL: { type: string }
67
+ StyleGuide: { type: string }
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'bundler/setup'
4
+ require 'rubocop/schema'
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require 'irb'
14
+ IRB.start(__FILE__)
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'bundler/setup'
4
+ require 'rubocop/schema'
5
+ require 'rubocop/schema/cli'
6
+ require 'json'
7
+
8
+ RuboCop::Schema::CLI.new(Dir.pwd, ENV, ARGV).run
@@ -0,0 +1,16 @@
1
+ require 'pathname'
2
+ require 'rubocop'
3
+
4
+ require 'rubocop/schema/version'
5
+ require 'rubocop/schema/cache'
6
+ require 'rubocop/schema/scraper'
7
+ require 'rubocop/schema/lockfile_inspector'
8
+
9
+ module RuboCop
10
+ module Schema
11
+ ROOT =
12
+ Pathname(__dir__) # rubocop/
13
+ .parent # lib/
14
+ .parent # /
15
+ end
16
+ end
@@ -0,0 +1,47 @@
1
+ require 'pathname'
2
+ require 'uri'
3
+ require 'net/http'
4
+
5
+ module RuboCop
6
+ module Schema
7
+ class Cache
8
+ # @return [URI]
9
+ attr_reader :base_url
10
+
11
+ def initialize(cache_dir, base_url: nil, &event_handler)
12
+ @cache_dir = Pathname(cache_dir)
13
+ @base_url = validate_url(base_url)
14
+ @event_handler = event_handler
15
+ end
16
+
17
+ def get(url)
18
+ url = URI(url)
19
+ url = @base_url + url if @base_url && url.relative?
20
+ validate_url url
21
+
22
+ path = path_for_url(url)
23
+ return path.read if path.readable?
24
+
25
+ path.parent.mkpath
26
+ @event_handler&.call Event.new(type: :request)
27
+ Net::HTTP.get(url).force_encoding(Encoding::UTF_8).tap(&path.method(:write))
28
+ end
29
+
30
+ private
31
+
32
+ def validate_url(url)
33
+ return if url.nil?
34
+
35
+ raise ArgumentError, 'Expected an absolute URL' unless url.absolute?
36
+ raise ArgumentError, 'Expected an HTTP URL' unless url.is_a? URI::HTTP
37
+
38
+ url
39
+ end
40
+
41
+ # @param [URI::HTTP] url
42
+ def path_for_url(url)
43
+ @cache_dir + url.scheme + url.hostname + url.path[1..]
44
+ end
45
+ end
46
+ end
47
+ end
@@ -0,0 +1,68 @@
1
+ require 'pathname'
2
+ require 'json'
3
+
4
+ module RuboCop
5
+ module Schema
6
+ class CLI
7
+ # @param [Pathname] working_dir
8
+ # @param [Hash] env
9
+ # @param [Array<String>] args
10
+ def initialize(working_dir, env, args)
11
+ @working_dir = Pathname(working_dir)
12
+ @env = env
13
+ @args = args
14
+ end
15
+
16
+ def run
17
+ fail "Cannot read #{lockfile_path}" unless lockfile_path.readable?
18
+ fail 'RuboCop is not part of this project' unless lockfile.specs.any?
19
+
20
+ schema = report_duration { Scraper.new(lockfile, cache).schema }
21
+ puts JSON.pretty_generate schema
22
+ end
23
+
24
+ private
25
+
26
+ def report_duration
27
+ started = Time.now
28
+ yield
29
+ ensure
30
+ finished = Time.now
31
+ handle_event Event.new(message: "Complete in #{(finished - started).round 1}s")
32
+ end
33
+
34
+ def handle_event(event)
35
+ case event.type
36
+ when :request
37
+ $stderr << '.'
38
+ @line_dirty = true
39
+ else
40
+ $stderr.puts '' if @line_dirty
41
+ @line_dirty = false
42
+ $stderr.puts event.message.to_s
43
+ end
44
+ end
45
+
46
+ def fail(msg)
47
+ $stderr.puts msg.to_s
48
+ exit 1
49
+ end
50
+
51
+ def lockfile
52
+ @lockfile ||= LockfileInspector.new(lockfile_path)
53
+ end
54
+
55
+ def lockfile_path
56
+ @lockfile_path ||= @working_dir + 'Gemfile.lock'
57
+ end
58
+
59
+ def cache
60
+ @cache ||= Cache.new(cache_dir, &method(:handle_event))
61
+ end
62
+
63
+ def cache_dir
64
+ @cache_dir ||= Pathname(Dir.home) + '.rubocop-schema-cache'
65
+ end
66
+ end
67
+ end
68
+ end