rails-tc 0.1.0

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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: cd4de7e0ef2d8cbd984d8f7a39bd4485b5ea8b7175febb6b7e6598499b5943e8
4
+ data.tar.gz: 555d73a67397784495b845ccf3a6ddc28c99f6e0f3aaaf568215f2438f266f09
5
+ SHA512:
6
+ metadata.gz: beddf0019850cc3dcff8dd0704bce524712ad90c816db5b2fae450ada4cccb3422e6fc9fb3a88134efb2edff999feeab76f2a68608893dd0730debd0501357bc
7
+ data.tar.gz: 51ed684438b851e66c18ffba0b14924a4e1fa5f24595850a86c407cc216cbcf279643a67ead893ce0836fe4af1de9199dda37afcf8a2de83c7c07dbbc774f00a
data/.gitignore ADDED
@@ -0,0 +1,11 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+
10
+ # rspec failure tracking
11
+ .rspec_status
data/.gitlab-ci.yml ADDED
@@ -0,0 +1,9 @@
1
+ image: ruby:3.0.2
2
+
3
+ before_script:
4
+ - gem install bundler -v 2.2.25
5
+ - bundle install
6
+
7
+ example_job:
8
+ script:
9
+ - bundle exec rake
@@ -0,0 +1,87 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <project version="4">
3
+ <component name="ChangeListManager">
4
+ <list default="true" id="70f1023d-93df-464d-ae60-42cd1388a1e4" name="Changes" comment="">
5
+ <change afterPath="$PROJECT_DIR$/.gitignore" afterDir="false" />
6
+ <change afterPath="$PROJECT_DIR$/.gitlab-ci.yml" afterDir="false" />
7
+ <change afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
8
+ <change afterPath="$PROJECT_DIR$/.rspec" afterDir="false" />
9
+ <change afterPath="$PROJECT_DIR$/.rubocop.yml" afterDir="false" />
10
+ <change afterPath="$PROJECT_DIR$/CHANGELOG.md" afterDir="false" />
11
+ <change afterPath="$PROJECT_DIR$/Gemfile" afterDir="false" />
12
+ <change afterPath="$PROJECT_DIR$/LICENSE.txt" afterDir="false" />
13
+ <change afterPath="$PROJECT_DIR$/README.md" afterDir="false" />
14
+ <change afterPath="$PROJECT_DIR$/Rakefile" afterDir="false" />
15
+ <change afterPath="$PROJECT_DIR$/bin/console" afterDir="false" />
16
+ <change afterPath="$PROJECT_DIR$/bin/setup" afterDir="false" />
17
+ <change afterPath="$PROJECT_DIR$/lib/rails/tc.rb" afterDir="false" />
18
+ <change afterPath="$PROJECT_DIR$/lib/rails/tc/command_runner.rb" afterDir="false" />
19
+ <change afterPath="$PROJECT_DIR$/lib/rails/tc/railtie.rb" afterDir="false" />
20
+ <change afterPath="$PROJECT_DIR$/lib/rails/tc/rubocop.rb" afterDir="false" />
21
+ <change afterPath="$PROJECT_DIR$/lib/rails/tc/tasks/tc.rake" afterDir="false" />
22
+ <change afterPath="$PROJECT_DIR$/lib/rails/tc/type_checker.rb" afterDir="false" />
23
+ <change afterPath="$PROJECT_DIR$/lib/rails/tc/type_checker_error.rb" afterDir="false" />
24
+ <change afterPath="$PROJECT_DIR$/lib/rails/tc/version.rb" afterDir="false" />
25
+ <change afterPath="$PROJECT_DIR$/rails-tc.gemspec" afterDir="false" />
26
+ <change afterPath="$PROJECT_DIR$/spec/rails/tc_spec.rb" afterDir="false" />
27
+ <change afterPath="$PROJECT_DIR$/spec/spec_helper.rb" afterDir="false" />
28
+ </list>
29
+ <option name="SHOW_DIALOG" value="false" />
30
+ <option name="HIGHLIGHT_CONFLICTS" value="true" />
31
+ <option name="HIGHLIGHT_NON_ACTIVE_CHANGELIST" value="false" />
32
+ <option name="LAST_RESOLUTION" value="IGNORE" />
33
+ </component>
34
+ <component name="FileTemplateManagerImpl">
35
+ <option name="RECENT_TEMPLATES">
36
+ <list>
37
+ <option value="Ruby File" />
38
+ </list>
39
+ </option>
40
+ </component>
41
+ <component name="Git.Settings">
42
+ <option name="RECENT_GIT_ROOT_PATH" value="$PROJECT_DIR$" />
43
+ </component>
44
+ <component name="GitSEFilterConfiguration">
45
+ <file-type-list>
46
+ <filtered-out-file-type name="LOCAL_BRANCH" />
47
+ <filtered-out-file-type name="REMOTE_BRANCH" />
48
+ <filtered-out-file-type name="TAG" />
49
+ <filtered-out-file-type name="COMMIT_BY_MESSAGE" />
50
+ </file-type-list>
51
+ </component>
52
+ <component name="MarkdownSettingsMigration">
53
+ <option name="stateVersion" value="1" />
54
+ </component>
55
+ <component name="ProjectId" id="22oxrhkAKjljfVppUYbrdhBm39d" />
56
+ <component name="ProjectLevelVcsManager" settingsEditedManually="true" />
57
+ <component name="ProjectViewState">
58
+ <option name="hideEmptyMiddlePackages" value="true" />
59
+ <option name="showLibraryContents" value="true" />
60
+ </component>
61
+ <component name="PropertiesComponent">
62
+ <property name="RunOnceActivity.OpenProjectViewOnStart" value="true" />
63
+ <property name="RunOnceActivity.ShowReadmeOnStart" value="true" />
64
+ <property name="WebServerToolWindowFactoryState" value="false" />
65
+ <property name="last.edited.regexp" value=" * def (0.9)" />
66
+ <property name="last_opened_file_path" value="$PROJECT_DIR$/../fa-x" />
67
+ <property name="nodejs_interpreter_path.stuck_in_default_project" value="undefined stuck path" />
68
+ <property name="nodejs_npm_path_reset_for_default_project" value="true" />
69
+ <property name="vue.rearranger.settings.migration" value="true" />
70
+ </component>
71
+ <component name="SpellCheckerSettings" RuntimeDictionaries="0" Folders="0" CustomDictionaries="0" DefaultDictionary="application-level" UseSingleDictionary="true" transferred="true" />
72
+ <component name="SpringUtil" SPRING_PRE_LOADER_OPTION="true" RAKE_SPRING_PRE_LOADER_OPTION="true" RAILS_SPRING_PRE_LOADER_OPTION="true" />
73
+ <component name="TaskManager">
74
+ <task active="true" id="Default" summary="Default task">
75
+ <changelist id="70f1023d-93df-464d-ae60-42cd1388a1e4" name="Changes" comment="" />
76
+ <created>1640517942267</created>
77
+ <option name="number" value="Default" />
78
+ <option name="presentableId" value="Default" />
79
+ <updated>1640517942267</updated>
80
+ <workItem from="1640517945803" duration="6297000" />
81
+ </task>
82
+ <servers />
83
+ </component>
84
+ <component name="TypeScriptGeneratedFilesManager">
85
+ <option name="version" value="3" />
86
+ </component>
87
+ </project>
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
data/.rubocop.yml ADDED
@@ -0,0 +1,16 @@
1
+ AllCops:
2
+ TargetRubyVersion: 2.6
3
+
4
+ Style/StringLiterals:
5
+ Enabled: true
6
+ EnforcedStyle: double_quotes
7
+
8
+ Style/StringLiteralsInInterpolation:
9
+ Enabled: true
10
+ EnforcedStyle: double_quotes
11
+
12
+ Layout/LineLength:
13
+ Max: 120
14
+
15
+ Style/AccessorGrouping:
16
+ Enabled: false
data/CHANGELOG.md ADDED
@@ -0,0 +1,5 @@
1
+ ## [Unreleased]
2
+
3
+ ## [0.1.0] - 2021-12-26
4
+
5
+ - Initial release
data/Gemfile ADDED
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ source "https://rubygems.org"
4
+
5
+ # Specify your gem's dependencies in rails-tc.gemspec
6
+ gemspec
7
+
8
+ gem "rake", "~> 13.0"
9
+
10
+ gem "rspec", "~> 3.0"
11
+
12
+ gem "rubocop", "~> 1.7"
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2021 Oskar Kirmis
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,39 @@
1
+ # Rails::Tc
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/rails/tc`. 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 'rails-tc'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle install
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install rails-tc
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 the created tag, 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]/rails-tc.
36
+
37
+ ## License
38
+
39
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
data/Rakefile ADDED
@@ -0,0 +1,12 @@
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
+ require "rubocop/rake_task"
9
+
10
+ RuboCop::RakeTask.new
11
+
12
+ task default: %i[spec rubocop]
data/bin/console ADDED
@@ -0,0 +1,15 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ require "bundler/setup"
5
+ require "rails/tc"
6
+
7
+ # You can add fixtures and/or initialization code here to make experimenting
8
+ # with your gem easier. You can also use a different console, if you like.
9
+
10
+ # (If you use this, don't forget to add pry to your Gemfile!)
11
+ # require "pry"
12
+ # Pry.start
13
+
14
+ require "irb"
15
+ 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,32 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Rails
4
+ module Tc
5
+ module CommandRunner
6
+ def self.init
7
+ `bundle exec srb init 2>&1`
8
+ end
9
+
10
+ def self.generate
11
+ system "bundle exec tapioca gem"
12
+ system "bundle exec tapioca dsl"
13
+ end
14
+
15
+ def self.type_check
16
+ `bundle exec srb tc 2>&1`
17
+ end
18
+
19
+ def self.add_development_gem(gem)
20
+ system "bundle add #{gem} --group development" unless gem_installed?(gem)
21
+ end
22
+
23
+ def self.add_runtime_gem(gem)
24
+ system "bundle add #{gem}" unless gem_installed?(gem)
25
+ end
26
+
27
+ def self.gem_installed?(gem)
28
+ `bundle show`.scan(/^\s*\*\s*([^\s]+).*/).map(&:first).include? gem
29
+ end
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,14 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Rails
4
+ module Tc
5
+ class Railtie < Rails::Railtie
6
+ railtie_name :tc
7
+
8
+ rake_tasks do
9
+ path = File.expand_path(__dir__)
10
+ Dir.glob("#{path}/tasks/**/*.rake").each { |f| load f }
11
+ end
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,36 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Rails
4
+ module Tc
5
+ module Rubocop
6
+ class InvalidConfigError < StandardError; end
7
+
8
+ ACCESSOR_GROUPING_PATH = "Style/AccessorGrouping"
9
+
10
+ def self.patch_configuration
11
+ rubocop_path = Rails.root.join(".rubocop.yml").to_s
12
+
13
+ return unless File.exist?(rubocop_path)
14
+
15
+ config = YAML.safe_load(File.read(rubocop_path))
16
+ raise InvalidConfigError.new("Invalid rubocop config") unless config.is_a?(Hash)
17
+
18
+ modified = false
19
+
20
+ if config.fetch(ACCESSOR_GROUPING_PATH, {}).fetch("Enabled", true)
21
+ config[ACCESSOR_GROUPING_PATH] = { "Enabled" => false }
22
+ modified = true
23
+ end
24
+
25
+ if modified
26
+ File.open(rubocop_path, "w") { |f| f.write YAML.dump(config) }
27
+ puts "Rubocop configuration patched"
28
+ else
29
+ puts "Rubocop configuration unchanged"
30
+ end
31
+ rescue
32
+ puts "Unable to patch Rubocop configuration"
33
+ end
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,31 @@
1
+ # frozen_string_literal: true
2
+
3
+ namespace :tc do
4
+ desc "Setup type checking for the project"
5
+ task install: :environment do
6
+ Rails::Tc::CommandRunner.add_development_gem "sorbet"
7
+ Rails::Tc::CommandRunner.add_development_gem "tapioca"
8
+ Rails::Tc::CommandRunner.add_runtime_gem "sorbet-runtime"
9
+
10
+ Rails::Tc::CommandRunner.init unless Rails::Tc::TypeChecker.set_up?
11
+ Rails::Tc::CommandRunner.generate
12
+ Rails::Tc::Rubocop.patch_configuration
13
+ end
14
+
15
+ desc "Check types in the project"
16
+ task check: :environment do
17
+ checker = Rails::Tc::TypeChecker.new([], ["*/**/*.rbi"])
18
+
19
+ if checker.errors.empty?
20
+ puts "Good job, no errors"
21
+ else
22
+ checker.errors.each do |error|
23
+ puts error.to_s
24
+ puts "\n\n"
25
+ end
26
+
27
+ puts "Found #{checker.errors.size} errors"
28
+ Kernel.exit(-1)
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,54 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "./type_checker_error"
4
+ require_relative "./command_runner"
5
+
6
+ module Rails
7
+ module Tc
8
+ class TypeChecker
9
+ ERROR_LINE_REGEX = %r{^([^:]+):([0-9]+): (.*) https://srb\.help/([0-9]+)$}.freeze
10
+
11
+ def self.set_up?
12
+ File.exist?(Rails.root.join("sorbet/config"))
13
+ end
14
+
15
+ def initialize(ignored_errors = [], ignored_patterns = [])
16
+ @ignored_errors = ignored_errors
17
+ @ignored_patterns = ignored_patterns
18
+ end
19
+
20
+ def errors
21
+ @errors ||= run
22
+ end
23
+
24
+ protected
25
+
26
+ def run
27
+ errors = []
28
+ current = T.let(nil, T.nilable(TypeCheckerError))
29
+
30
+ CommandRunner.type_check.split("\n", -1).each do |line|
31
+ result = line.scan ERROR_LINE_REGEX
32
+
33
+ if result.any?
34
+ current = TypeCheckerError.new(
35
+ result.first[0],
36
+ result.first[1].to_i,
37
+ result.first[3].to_i,
38
+ result.first[2]
39
+ )
40
+
41
+ errors.push current
42
+ elsif result.empty? && !current.nil? && line.start_with?(" ")
43
+ current.notes.push line
44
+ end
45
+ end
46
+
47
+ errors.reject do |error|
48
+ @ignored_errors.include?(error.code) ||
49
+ @ignored_patterns.any? { |pattern| File.fnmatch?(pattern, error.filename) }
50
+ end
51
+ end
52
+ end
53
+ end
54
+ end
@@ -0,0 +1,21 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Rails
4
+ module Tc
5
+ class TypeCheckerError
6
+ attr_reader :filename, :message, :line, :code, :notes
7
+
8
+ def initialize(filename, line, code, message)
9
+ @filename = filename
10
+ @line = line
11
+ @code = code
12
+ @message = message
13
+ @notes = []
14
+ end
15
+
16
+ def to_s
17
+ "#{filename}:#{line}: #{message} https://srb.help/#{code}\n#{notes.join("\n")}"
18
+ end
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Rails
4
+ module Tc
5
+ VERSION = "0.1.0"
6
+ end
7
+ end
data/lib/rails/tc.rb ADDED
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "tc/version"
4
+ require_relative "tc/type_checker"
5
+ require_relative "tc/type_checker_error"
6
+ require_relative "tc/command_runner"
7
+ require_relative "tc/rubocop"
8
+ require_relative "tc/railtie"
data/rails-tc.gemspec ADDED
@@ -0,0 +1,29 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "lib/rails/tc/version"
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = "rails-tc"
7
+ spec.version = Rails::Tc::VERSION
8
+ spec.authors = ["Oskar Kirmis"]
9
+ spec.email = ["oskar.kirmis@posteo.de"]
10
+
11
+ spec.summary = "Type checking package for Rails using sorbet, tapioca and some magic to hide external errors."
12
+ spec.description = "rails-tc bundles everything required to properly setup type checking with sorbet in rails projects"
13
+ spec.homepage = "https://git.iftrue.de/okirmis/rails-tc"
14
+ spec.license = "MIT"
15
+ spec.required_ruby_version = ">= 2.6.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
+ # Specify which files should be added to the gem when it is released.
22
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
23
+ spec.files = Dir.chdir(File.expand_path(__dir__)) do
24
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{\A(?:test|spec|features)/}) }
25
+ end
26
+ spec.bindir = "exe"
27
+ spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
28
+ spec.require_paths = ["lib"]
29
+ end
metadata ADDED
@@ -0,0 +1,69 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rails-tc
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Oskar Kirmis
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2021-12-26 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: rails-tc bundles everything required to properly setup type checking
14
+ with sorbet in rails projects
15
+ email:
16
+ - oskar.kirmis@posteo.de
17
+ executables: []
18
+ extensions: []
19
+ extra_rdoc_files: []
20
+ files:
21
+ - ".gitignore"
22
+ - ".gitlab-ci.yml"
23
+ - ".idea/workspace.xml"
24
+ - ".rspec"
25
+ - ".rubocop.yml"
26
+ - CHANGELOG.md
27
+ - Gemfile
28
+ - LICENSE.txt
29
+ - README.md
30
+ - Rakefile
31
+ - bin/console
32
+ - bin/setup
33
+ - lib/rails/tc.rb
34
+ - lib/rails/tc/command_runner.rb
35
+ - lib/rails/tc/railtie.rb
36
+ - lib/rails/tc/rubocop.rb
37
+ - lib/rails/tc/tasks/tc.rake
38
+ - lib/rails/tc/type_checker.rb
39
+ - lib/rails/tc/type_checker_error.rb
40
+ - lib/rails/tc/version.rb
41
+ - rails-tc.gemspec
42
+ homepage: https://git.iftrue.de/okirmis/rails-tc
43
+ licenses:
44
+ - MIT
45
+ metadata:
46
+ homepage_uri: https://git.iftrue.de/okirmis/rails-tc
47
+ source_code_uri: https://git.iftrue.de/okirmis/rails-tc
48
+ changelog_uri: https://git.iftrue.de/okirmis/rails-tc
49
+ post_install_message:
50
+ rdoc_options: []
51
+ require_paths:
52
+ - lib
53
+ required_ruby_version: !ruby/object:Gem::Requirement
54
+ requirements:
55
+ - - ">="
56
+ - !ruby/object:Gem::Version
57
+ version: 2.6.0
58
+ required_rubygems_version: !ruby/object:Gem::Requirement
59
+ requirements:
60
+ - - ">="
61
+ - !ruby/object:Gem::Version
62
+ version: '0'
63
+ requirements: []
64
+ rubygems_version: 3.2.22
65
+ signing_key:
66
+ specification_version: 4
67
+ summary: Type checking package for Rails using sorbet, tapioca and some magic to hide
68
+ external errors.
69
+ test_files: []