chusaku 0.6.0 → 0.6.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 46b0340d8c2c5cde79a47703b564be4bec987b2fed0e9561ce658227ac3a2076
4
- data.tar.gz: 8d2384684ad0c72d2f763446177b16d97d76f2c84c95bf4a7b5ff8e08cf32c23
3
+ metadata.gz: 714c60f9b5f8e9ebd4db391daa894dfa96a1ec95b7773900988df7b9a24677da
4
+ data.tar.gz: 1d7adffa9c39bb7dd7cd2f6d6b86fd7844bfbe77a207988eebd1469d5a74d0de
5
5
  SHA512:
6
- metadata.gz: a8e8d607f077c5de894d5fd70989d595fda9f4fab5d5111eeedb4acfa526d4f94cc7cb64abc64b42ac2968ef9e7f16bbf413a4329b46e919f0b46d8e9bc5c527
7
- data.tar.gz: 72a674b922b87067ea2c3276f111603ee377a25bff277862187aa879b11ac83909877749b6b0cd5ff3315429e95b482da211f54b74b460eff129015780734e6c
6
+ metadata.gz: 0bc70bbe88b4cde24d236ac000bf13533fdad892413dc03cf8b8c4eca9f6eb7f21bd8f5a6df382521898a7baddc07f74e1444067ec0f2febd828603c79cfe020
7
+ data.tar.gz: 9a51c9476b1585c1f382f3845a202b6ea4eeed70e30d2cb450de4d01ed59c084ec2d7c1b11930bd6f62a9264129d21b545e0270bf9ea52d2cb92724d520cf924
@@ -1,18 +1,14 @@
1
1
  name: Linting
2
2
  on: [pull_request]
3
3
  jobs:
4
- rubocop:
4
+ standard:
5
5
  runs-on: ubuntu-latest
6
6
  steps:
7
- - uses: actions/checkout@v2
8
- - name: Set up Ruby
9
- uses: ruby/setup-ruby@473e4d8fe5dd94ee328fdfca9f8c9c7afc9dae5e
10
- with:
11
- ruby-version: 3.0.0
12
- bundler-cache: true
13
- - name: Run RuboCop
14
- uses: reviewdog/action-rubocop@v2
15
- with:
16
- rubocop_version: gemfile
17
- github_token: ${{ secrets.github_token }}
18
- reporter: github-pr-review
7
+ - uses: actions/checkout@v2
8
+ - name: Set up Ruby
9
+ uses: ruby/setup-ruby@473e4d8fe5dd94ee328fdfca9f8c9c7afc9dae5e
10
+ with:
11
+ ruby-version: 3.0.0
12
+ bundler-cache: true
13
+ - name: Run Standard
14
+ run: bundle exec standardrb --fail-level A
@@ -5,13 +5,13 @@ jobs:
5
5
  runs-on: ubuntu-latest
6
6
  strategy:
7
7
  matrix:
8
- ruby-version: ['2.6', '2.7', '3.0']
8
+ ruby-version: ["2.6", "2.7", "3.0"]
9
9
  steps:
10
- - uses: actions/checkout@v2
11
- - name: Set up Ruby
12
- uses: ruby/setup-ruby@473e4d8fe5dd94ee328fdfca9f8c9c7afc9dae5e
13
- with:
14
- ruby-version: ${{ matrix.ruby-version }}
15
- bundler-cache: true
16
- - name: Run tests
17
- run: bundle exec rake
10
+ - uses: actions/checkout@v2
11
+ - name: Set up Ruby
12
+ uses: ruby/setup-ruby@473e4d8fe5dd94ee328fdfca9f8c9c7afc9dae5e
13
+ with:
14
+ ruby-version: ${{ matrix.ruby-version }}
15
+ bundler-cache: true
16
+ - name: Run tests
17
+ run: bundle exec rake
data/.rubocop.yml CHANGED
@@ -1,35 +1,7 @@
1
- require:
2
- - rubocop-performance
1
+ require: standard
3
2
 
4
- inherit_mode:
5
- merge:
6
- - Exclude
3
+ inherit_gem:
4
+ standard: config/base.yml
7
5
 
8
6
  AllCops:
9
- NewCops: enable
10
- Exclude:
11
- - 'bin/**/*'
12
- - 'test/mock/app/**/*'
13
- - 'test/mock/examples/**/*'
14
-
15
- Gemspec/RequiredRubyVersion:
16
- Enabled: false
17
-
18
- Layout/LineLength:
19
- Max: 120
20
-
21
- Metrics/AbcSize:
22
- Exclude:
23
- - 'test/**/*'
24
-
25
- Metrics/MethodLength:
26
- Max: 25
27
- Exclude:
28
- - 'test/**/*'
29
-
30
- Metrics/ModuleLength:
31
- Max: 250
32
-
33
- Style/ClassAndModuleChildren:
34
- Exclude:
35
- - 'test/**/*'
7
+ DisabledByDefault: true
data/Gemfile CHANGED
@@ -1,6 +1,4 @@
1
- # frozen_string_literal: true
2
-
3
- source 'https://rubygems.org'
1
+ source "https://rubygems.org"
4
2
 
5
3
  # Specify your gem's dependencies in chusaku.gemspec
6
4
  gemspec
data/README.md CHANGED
@@ -27,7 +27,7 @@ Add this line to your Rails application's Gemfile:
27
27
  ```ruby
28
28
  group :development do
29
29
  # ...
30
- gem 'chusaku', require: false
30
+ gem "chusaku", require: false
31
31
  # ...
32
32
  end
33
33
  ```
data/Rakefile CHANGED
@@ -1,12 +1,10 @@
1
- # frozen_string_literal: true
2
-
3
- require 'bundler/gem_tasks'
4
- require 'rake/testtask'
1
+ require "bundler/gem_tasks"
2
+ require "rake/testtask"
5
3
 
6
4
  Rake::TestTask.new(:test) do |t|
7
- t.libs << 'test'
8
- t.libs << 'lib'
9
- t.test_files = FileList['test/**/*_test.rb']
5
+ t.libs << "test"
6
+ t.libs << "lib"
7
+ t.test_files = FileList["test/**/*_test.rb"]
10
8
  end
11
9
 
12
10
  task default: :test
data/bin/chusaku CHANGED
@@ -1,19 +1,19 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
- require 'rubygems'
3
+ require "rubygems"
4
4
 
5
5
  begin
6
6
  # Use project's bundle.
7
- require 'bundler'
7
+ require "bundler"
8
8
  Bundler.setup
9
9
 
10
10
  # Use project's environment.
11
- require 'rake'
12
- load './Rakefile'
11
+ require "rake"
12
+ load "./Rakefile"
13
13
  Rake::Task[:environment].invoke
14
- rescue StandardError
14
+ rescue
15
15
  end
16
16
 
17
- require 'chusaku/cli'
17
+ require "chusaku/cli"
18
18
 
19
19
  exit Chusaku::CLI.new.call
data/bin/console CHANGED
@@ -1,8 +1,7 @@
1
1
  #!/usr/bin/env ruby
2
- # frozen_string_literal: true
3
2
 
4
- require 'bundler/setup'
5
- require 'chusaku'
3
+ require "bundler/setup"
4
+ require "chusaku"
6
5
 
7
6
  # You can add fixtures and/or initialization code here to make experimenting
8
7
  # with your gem easier. You can also use a different console, if you like.
@@ -11,5 +10,5 @@ require 'chusaku'
11
10
  # require "pry"
12
11
  # Pry.start
13
12
 
14
- require 'irb'
13
+ require "irb"
15
14
  IRB.start(__FILE__)
data/chusaku.gemspec CHANGED
@@ -1,32 +1,30 @@
1
- # frozen_string_literal: true
2
-
3
- lib = File.expand_path('lib', __dir__)
1
+ lib = File.expand_path("lib", __dir__)
4
2
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
5
- require 'chusaku/version'
3
+ require "chusaku/version"
6
4
 
7
5
  Gem::Specification.new do |spec|
8
- spec.name = 'chusaku'
6
+ spec.name = "chusaku"
9
7
  spec.version = Chusaku::VERSION
10
- spec.authors = ['Nishiki Liu']
11
- spec.email = ['nishiki@hey.com']
8
+ spec.authors = ["Nishiki Liu"]
9
+ spec.email = ["hello@nshki.com"]
12
10
 
13
- spec.summary = 'Annotate your Rails controllers with route info.'
14
- spec.description = 'Annotate your Rails controllers with route info.'
15
- spec.homepage = 'https://github.com/nshki/chusaku'
16
- spec.license = 'MIT'
11
+ spec.summary = "Annotate your Rails controllers with route info."
12
+ spec.description = "Annotate your Rails controllers with route info."
13
+ spec.homepage = "https://github.com/nshki/chusaku"
14
+ spec.license = "MIT"
17
15
 
18
16
  # Prevent pushing this gem to RubyGems.org. To allow pushes either set the
19
17
  # 'allowed_push_host' to allow pushing to a single host or delete this section
20
18
  # to allow pushing to any host.
21
19
  if spec.respond_to?(:metadata)
22
- spec.metadata['allowed_push_host'] = 'https://rubygems.org'
20
+ spec.metadata["allowed_push_host"] = "https://rubygems.org"
23
21
 
24
- spec.metadata['homepage_uri'] = spec.homepage
25
- spec.metadata['source_code_uri'] = spec.homepage
26
- spec.metadata['changelog_uri'] = spec.homepage
22
+ spec.metadata["homepage_uri"] = spec.homepage
23
+ spec.metadata["source_code_uri"] = spec.homepage
24
+ spec.metadata["changelog_uri"] = spec.homepage
27
25
  else
28
- raise 'RubyGems 2.0 or newer is required to protect against ' \
29
- 'public gem pushes.'
26
+ raise "RubyGems 2.0 or newer is required to protect against " \
27
+ "public gem pushes."
30
28
  end
31
29
 
32
30
  # Specify which files should be added to the gem when it is released.
@@ -37,15 +35,14 @@ Gem::Specification.new do |spec|
37
35
  f.match(%r{^(test|spec|features)/})
38
36
  end
39
37
  end
40
- spec.bindir = 'bin'
41
- spec.executables = 'chusaku'
42
- spec.require_paths = ['lib']
38
+ spec.bindir = "bin"
39
+ spec.executables = "chusaku"
40
+ spec.require_paths = ["lib"]
43
41
 
44
- spec.add_development_dependency 'bundler', '~> 2.2'
45
- spec.add_development_dependency 'minitest', '~> 5.14'
46
- spec.add_development_dependency 'rake', '~> 13.0'
47
- spec.add_development_dependency 'rubocop', '~> 1.7'
48
- spec.add_development_dependency 'rubocop-performance', '~> 1.9'
42
+ spec.add_development_dependency "bundler", "~> 2.2"
43
+ spec.add_development_dependency "minitest", "~> 5.14"
44
+ spec.add_development_dependency "rake", "~> 13.0"
45
+ spec.add_development_dependency "standardrb", "~> 1.0"
49
46
 
50
- spec.add_dependency 'railties', '>= 3.0'
47
+ spec.add_dependency "railties", ">= 3.0"
51
48
  end
data/lib/chusaku/cli.rb CHANGED
@@ -1,7 +1,5 @@
1
- # frozen_string_literal: true
2
-
3
- require 'optparse'
4
- require 'chusaku'
1
+ require "optparse"
2
+ require "chusaku"
5
3
 
6
4
  module Chusaku
7
5
  # Enables flags for the `chusaku` executable.
@@ -30,7 +28,7 @@ module Chusaku
30
28
  check_for_rails_project
31
29
  Chusaku.call(options)
32
30
  rescue NotARailsProject
33
- warn('Please run chusaku from the root of your project.')
31
+ warn("Please run chusaku from the root of your project.")
34
32
  STATUS_ERROR
35
33
  rescue Finished
36
34
  STATUS_SUCCESS
@@ -43,8 +41,8 @@ module Chusaku
43
41
  # @raise [Chusaku::CLI::NotARailsProject] Exception if not Rails project
44
42
  # @return [void]
45
43
  def check_for_rails_project
46
- has_controllers = File.directory?('./app/controllers')
47
- has_rakefile = File.exist?('./Rakefile')
44
+ has_controllers = File.directory?("./app/controllers")
45
+ has_rakefile = File.exist?("./Rakefile")
48
46
  raise NotARailsProject unless has_controllers && has_rakefile
49
47
  end
50
48
 
@@ -53,7 +51,7 @@ module Chusaku
53
51
  # @return [OptionParser] Preconfigured OptionParser instance
54
52
  def optparser
55
53
  OptionParser.new do |opts|
56
- opts.banner = 'Usage: chusaku [options]'
54
+ opts.banner = "Usage: chusaku [options]"
57
55
  add_dry_run_flag(opts)
58
56
  add_error_on_annotation_flag(opts)
59
57
  add_verbose_flag(opts)
@@ -67,7 +65,7 @@ module Chusaku
67
65
  # @param opts [OptionParser] OptionParser instance
68
66
  # @return [void]
69
67
  def add_dry_run_flag(opts)
70
- opts.on('--dry-run', 'Run without file modifications') do
68
+ opts.on("--dry-run", "Run without file modifications") do
71
69
  @options[:dry] = true
72
70
  end
73
71
  end
@@ -77,7 +75,7 @@ module Chusaku
77
75
  # @param opts [OptionParser] OptionParser instance
78
76
  # @return [void]
79
77
  def add_error_on_annotation_flag(opts)
80
- opts.on('--exit-with-error-on-annotation', 'Fail if any file was annotated') do
78
+ opts.on("--exit-with-error-on-annotation", "Fail if any file was annotated") do
81
79
  @options[:error_on_annotation] = true
82
80
  end
83
81
  end
@@ -87,7 +85,7 @@ module Chusaku
87
85
  # @param opts [OptionParser] OptionParser instance
88
86
  # @return [void]
89
87
  def add_verbose_flag(opts)
90
- opts.on('--verbose', 'Print all annotations') do
88
+ opts.on("--verbose", "Print all annotations") do
91
89
  @options[:verbose] = true
92
90
  end
93
91
  end
@@ -97,7 +95,7 @@ module Chusaku
97
95
  # @param opts [OptionParser] OptionParser instance
98
96
  # @return [void]
99
97
  def add_version_flag(opts)
100
- opts.on('-v', '--version', 'Show Chusaku version number and quit') do
98
+ opts.on("-v", "--version", "Show Chusaku version number and quit") do
101
99
  puts(Chusaku::VERSION)
102
100
  raise Finished
103
101
  end
@@ -108,7 +106,7 @@ module Chusaku
108
106
  # @param opts [OptionParser] OptionParser instance
109
107
  # @return [void]
110
108
  def add_help_flag(opts)
111
- opts.on('-h', '--help', 'Show this help message and quit') do
109
+ opts.on("-h", "--help", "Show this help message and quit") do
112
110
  puts(opts)
113
111
  raise Finished
114
112
  end
@@ -1,5 +1,3 @@
1
- # frozen_string_literal: true
2
-
3
1
  module Chusaku
4
2
  # Handles parsing a file and groups its lines into categories.
5
3
  module Parser
@@ -61,7 +59,7 @@ module Chusaku
61
59
 
62
60
  # Push the last group onto the array and return.
63
61
  groups.push(group)
64
- { content: content, groups: groups }
62
+ {content: content, groups: groups}
65
63
  end
66
64
 
67
65
  # Given a line and actions, returns the line's type.
@@ -85,11 +83,11 @@ module Chusaku
85
83
  def_match = /^\s*def\s+(\w*)\s*\w*.*$/.match(line)
86
84
 
87
85
  if !comment_match.nil?
88
- { type: :comment, body: line, action: nil }
86
+ {type: :comment, body: line, action: nil}
89
87
  elsif !def_match.nil? && actions.include?(def_match[1])
90
- { type: :action, body: line, action: def_match[1] }
88
+ {type: :action, body: line, action: def_match[1]}
91
89
  else
92
- { type: :code, body: line, action: nil }
90
+ {type: :code, body: line, action: nil}
93
91
  end
94
92
  end
95
93
  end
@@ -1,5 +1,3 @@
1
- # frozen_string_literal: true
2
-
3
1
  module Chusaku
4
2
  # Handles extracting information about the Rails project's routes.
5
3
  class Routes
@@ -9,18 +7,18 @@ module Chusaku
9
7
  # Example output:
10
8
  #
11
9
  # {
12
- # 'users' => {
13
- # 'edit' => [
14
- # { verb: 'GET', path: '/users/:id', name: 'edit_user' }
10
+ # "users" => {
11
+ # "edit" => [
12
+ # {verb: "GET", path: "/users/:id", name: "edit_user"}
15
13
  # ],
16
- # 'update' => [
17
- # { verb: 'PATCH', path: '/users', name: 'edit_user' },
18
- # { verb: 'PUT', path: '/users', name: 'edit_user' }
14
+ # "update" => [
15
+ # {verb: "PATCH", path: "/users", name: "edit_user"},
16
+ # {verb: "PUT", path: "/users", name: "edit_user"}
19
17
  # ]
20
18
  # },
21
- # 'empanadas' => {
22
- # 'create' => [
23
- # { verb: 'POST', path: '/empanadas', name: nil }
19
+ # "empanadas" => {
20
+ # "create" => [
21
+ # {verb: "POST", path: "/empanadas", name: nil}
24
22
  # ]
25
23
  # }
26
24
  # }
@@ -86,7 +84,7 @@ module Chusaku
86
84
  def format(route:, verb:, defaults:)
87
85
  {
88
86
  verb: verb,
89
- path: route.path.spec.to_s.gsub('(.:format)', ''),
87
+ path: route.path.spec.to_s.gsub("(.:format)", ""),
90
88
  name: route.name,
91
89
  defaults: defaults
92
90
  }
@@ -1,5 +1,3 @@
1
- # frozen_string_literal: true
2
-
3
1
  module Chusaku
4
- VERSION = '0.6.0'
2
+ VERSION = "0.6.1"
5
3
  end
data/lib/chusaku.rb CHANGED
@@ -1,8 +1,6 @@
1
- # frozen_string_literal: true
2
-
3
- require 'chusaku/version'
4
- require 'chusaku/parser'
5
- require 'chusaku/routes'
1
+ require "chusaku/version"
2
+ require "chusaku/parser"
3
+ require "chusaku/routes"
6
4
 
7
5
  # Handles core functionality of annotating projects.
8
6
  module Chusaku
@@ -21,7 +19,8 @@ module Chusaku
21
19
  @flags = flags
22
20
  @routes = Chusaku::Routes.call
23
21
  @changes = []
24
- controllers_pattern = 'app/controllers/**/*_controller.rb'
22
+ @changed_files = []
23
+ controllers_pattern = "app/controllers/**/*_controller.rb"
25
24
 
26
25
  Dir.glob(Rails.root.join(controllers_pattern)).each do |path|
27
26
  controller = %r{controllers/(.*)_controller\.rb}.match(path)[1]
@@ -92,9 +91,9 @@ module Chusaku
92
91
  def clean_group(group)
93
92
  return unless group[:type] == :comment
94
93
 
95
- group[:body] = group[:body].gsub(/^\s*#\s*@route.*$\n/, '')
94
+ group[:body] = group[:body].gsub(/^\s*#\s*@route.*$\n/, "")
96
95
  group[:body] =
97
- group[:body].gsub(%r{^\s*# (GET|POST|PATCH/PUT|DELETE) /\S+$\n}, '')
96
+ group[:body].gsub(%r{^\s*# (GET|POST|PATCH/PUT|DELETE) /\S+$\n}, "")
98
97
  end
99
98
 
100
99
  # Add an annotation to the given group given by Chusaku::Parser that looks
@@ -125,8 +124,8 @@ module Chusaku
125
124
  if defaults&.any?
126
125
  defaults_str =
127
126
  defaults
128
- .map { |key, value| "#{key}: #{value.inspect}" }
129
- .join(', ')
127
+ .map { |key, value| "#{key}: #{value.inspect}" }
128
+ .join(", ")
130
129
  annotation += " {#{defaults_str}}"
131
130
  end
132
131
  annotation += " (#{name})" unless name.nil?
@@ -143,6 +142,7 @@ module Chusaku
143
142
  return if parsed_file[:content] == new_content
144
143
 
145
144
  !@flags.include?(:dry) && perform_write(path: path, content: new_content)
145
+ @changed_files.push(path)
146
146
  end
147
147
 
148
148
  # Extracts the new file content for the given parsed file.
@@ -174,7 +174,7 @@ module Chusaku
174
174
  #
175
175
  # @return [String] 'r' or 'w'
176
176
  def file_mode
177
- File.instance_methods.include?(:test_write) ? 'r' : 'w'
177
+ File.instance_methods.include?(:test_write) ? "r" : "w"
178
178
  end
179
179
 
180
180
  # Output results to user.
@@ -183,7 +183,7 @@ module Chusaku
183
183
  def output_results
184
184
  puts(output_copy)
185
185
  exit_code = 0
186
- exit_code = 1 if @changes.any? && @flags.include?(:error_on_annotation)
186
+ exit_code = 1 if @changed_files.any? && @flags.include?(:error_on_annotation)
187
187
  exit_code
188
188
  end
189
189
 
@@ -191,7 +191,7 @@ module Chusaku
191
191
  #
192
192
  # @return [String] Copy to be outputted to user
193
193
  def output_copy
194
- return 'Nothing to annotate.' if @changes.empty?
194
+ return "Nothing to annotate." if @changed_files.empty?
195
195
 
196
196
  copy = changes_copy
197
197
  copy += "\nChusaku has finished running."
@@ -204,7 +204,7 @@ module Chusaku
204
204
  #
205
205
  # @return [String] Copy of recorded changes
206
206
  def changes_copy
207
- return '' unless @flags.include?(:verbose)
207
+ return "" unless @flags.include?(:verbose)
208
208
 
209
209
  @changes.map do |change|
210
210
  <<~CHANGE_OUTPUT
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: chusaku
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.0
4
+ version: 0.6.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nishiki Liu
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-10-30 00:00:00.000000000 Z
11
+ date: 2021-11-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -53,33 +53,19 @@ dependencies:
53
53
  - !ruby/object:Gem::Version
54
54
  version: '13.0'
55
55
  - !ruby/object:Gem::Dependency
56
- name: rubocop
56
+ name: standardrb
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
59
  - - "~>"
60
60
  - !ruby/object:Gem::Version
61
- version: '1.7'
61
+ version: '1.0'
62
62
  type: :development
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
66
  - - "~>"
67
67
  - !ruby/object:Gem::Version
68
- version: '1.7'
69
- - !ruby/object:Gem::Dependency
70
- name: rubocop-performance
71
- requirement: !ruby/object:Gem::Requirement
72
- requirements:
73
- - - "~>"
74
- - !ruby/object:Gem::Version
75
- version: '1.9'
76
- type: :development
77
- prerelease: false
78
- version_requirements: !ruby/object:Gem::Requirement
79
- requirements:
80
- - - "~>"
81
- - !ruby/object:Gem::Version
82
- version: '1.9'
68
+ version: '1.0'
83
69
  - !ruby/object:Gem::Dependency
84
70
  name: railties
85
71
  requirement: !ruby/object:Gem::Requirement
@@ -96,7 +82,7 @@ dependencies:
96
82
  version: '3.0'
97
83
  description: Annotate your Rails controllers with route info.
98
84
  email:
99
- - nishiki@hey.com
85
+ - hello@nshki.com
100
86
  executables:
101
87
  - chusaku
102
88
  extensions: []