irbs 0.1.0 → 0.2.0

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: 6c8b175c641b45064dcf880ee4c21133ba9a6240f55c7237e8ef859bc3e51156
4
- data.tar.gz: ad4a5fbf12afc99fee4ad48bd11c348acdb4c2cdf94e120656eeb8d50a2a3cf2
3
+ metadata.gz: 9913638753b516454d942c3ac25e0a00a81e955c0d66535dab01afbb19a63d37
4
+ data.tar.gz: afb1d1f24bd72d41d5a7b6df29285e9dcb040809390b4d4ace4bbddd0b646bf4
5
5
  SHA512:
6
- metadata.gz: 1af6c2167935bad83840c1fba0497f3bda725c65d4521cdbf245e0d02aaa8cf93539bc9da5d010e12b8d3f5b0c284aa35459831c85fc3c9f172b8fbed3f5a392
7
- data.tar.gz: d1682623eb9e908ad5b1e79ee9fb23824a57ed7ce216560de37678f4a934c9eb2cd378fcf1b1e71d17dd2effcceba8f93fd821a501466ad132366c72493a2b0e
6
+ metadata.gz: fde271cafa4b35f8d9c35874b82bbe4c4b16dfd01540f57f50277bb615f68c4b61f1e57d974e3b309b2157dd1f348cc59b550f38633062e534525887c458bcd7
7
+ data.tar.gz: 583a39520e37c9eff50c327a6aaf5c6c534329ef7425505ae1647b19bd6c3d12ddc7c46287aaa5f8c10fdd3131cf89f78c20bfbccabab98b2ff3249c2053c8e0
data/.rubocop.yml CHANGED
@@ -25,6 +25,10 @@ Style/EmptyMethod:
25
25
  Style/BlockDelimiters:
26
26
  EnforcedStyle: semantic
27
27
 
28
+ # ↑と相性が悪い
29
+ Style/NumberedParameters:
30
+ Enabled: false
31
+
28
32
  # 内容は名前で示したい
29
33
  Style/Documentation:
30
34
  Enabled: false
data/README.md CHANGED
@@ -26,6 +26,8 @@ module App
26
26
  arg.to_s
27
27
  end
28
28
 
29
+ private
30
+
29
31
  # @sig (String) -> Integer
30
32
  def some_private_method(arg)
31
33
  arg.to_i
@@ -48,7 +50,7 @@ end
48
50
  See example task in [`Rakefile`](https://github.com/diaphragm/irbs/tree/master/Rakefile) and [`exmaple/`](https://github.com/diaphragm/irbs/tree/master/example) for more examples.
49
51
 
50
52
  This library uses itself for type checking.
51
- See typecheck task in [`Rakefile`](https://github.com/diaphragm/irbs/tree/master/Rakefile) and [`isig/irbs.rbs`](https://github.com/diaphragm/irbs/tree/master/isig/irbs.rbs)
53
+ See typecheck task in [`Rakefile`](https://github.com/diaphragm/irbs/tree/master/Rakefile) and [`isig/irbs.rbs`](https://github.com/diaphragm/irbs/tree/master/sig/isig.rbs)
52
54
 
53
55
  ## Development
54
56
 
data/Rakefile CHANGED
@@ -22,15 +22,15 @@ end
22
22
 
23
23
  desc 'typecheck'
24
24
  task :typecheck do
25
- sh 'mkdir -p isig'
25
+ sh 'mkdir -p sig'
26
26
 
27
- sh 'exe/irbs "lib/**/*.rb" -o isig/irbs.rbs'
27
+ sh 'exe/irbs "lib/**/*.rb" -o sig/isig.rbs'
28
28
  sh 'steep check lib'
29
29
  end
30
30
 
31
31
  desc 'Example of usage with TypeProf and Steep'
32
32
  task :example do
33
- sh 'exe/irbs example/app.rb -o example/irbs.rbs --ignore-constant'
34
- sh 'typeprof example/app.rb example/irbs.rbs -o example/typeprof.rbs'
33
+ sh 'exe/irbs example/app.rb -o example/isig.rbs --ignore-constant'
34
+ sh 'typeprof example/app.rb example/isig.rbs -o example/typeprof.rbs'
35
35
  sh 'steep check example'
36
36
  end
data/Steepfile CHANGED
@@ -29,7 +29,7 @@
29
29
  # end
30
30
 
31
31
  target :lib do
32
- signature 'isig'
32
+ signature 'sig'
33
33
 
34
34
  check 'lib'
35
35
  end
data/example/app.rb CHANGED
@@ -5,6 +5,10 @@ module Submodule
5
5
  end
6
6
  end
7
7
 
8
+ module PrependModule
9
+ prepend Submodule
10
+ end
11
+
8
12
  module Example
9
13
  # @rbs type key = String | Symbol
10
14
  class App
@@ -3,6 +3,10 @@
3
3
  module ::Submodule
4
4
  end
5
5
 
6
+ module ::PrependModule
7
+ prepend ::Submodule
8
+ end
9
+
6
10
  module ::Example
7
11
  end
8
12
 
data/example/typeprof.rbs CHANGED
@@ -5,6 +5,10 @@ module Submodule
5
5
  def submethod: -> nil
6
6
  end
7
7
 
8
+ module PrependModule
9
+ prepend Submodule
10
+ end
11
+
8
12
  module Example
9
13
  class App
10
14
  HOGE: String
data/lib/irbs/cli.rb CHANGED
@@ -5,17 +5,18 @@ require 'optparse'
5
5
  module Irbs
6
6
  class CLI
7
7
  # @sig String
8
- NO_CONSTANT_HELP_MESSAGE = 'Generate no constant signatures. ' \
8
+ IGNORE_CONSTANT_HELP_MESSAGE = 'Generate no constant signatures. ' \
9
9
  'For using TypeProf. ' \
10
10
  '(TypeProf genarate duplicate constant signature even if already exists.)'
11
- private_constant :NO_CONSTANT_HELP_MESSAGE
11
+ private_constant :IGNORE_CONSTANT_HELP_MESSAGE
12
12
 
13
13
  class << self
14
14
  # @sig (Array[String]) -> void
15
15
  def run(argv)
16
16
  config = parse_opt(argv)
17
17
  Core.new(config).generate
18
- config.stdout.close
18
+ ensure
19
+ config&.stdout&.close
19
20
  end
20
21
 
21
22
  private
@@ -25,10 +26,10 @@ module Irbs
25
26
  config = Irbs::Config.new
26
27
  opt = OptionParser.new
27
28
 
28
- opt.on('-o output', 'default: stdout') do
29
+ opt.on('-o output', 'Output filename. (Default: stdout)') do
29
30
  config.stdout = File.open(_1, 'w')
30
31
  end
31
- opt.on('--ignore-constant', NO_CONSTANT_HELP_MESSAGE) do
32
+ opt.on('--ignore-constant', IGNORE_CONSTANT_HELP_MESSAGE) do
32
33
  config.ingore_constant = _1
33
34
  end
34
35
  config.paths = opt.parse(argv)
data/lib/irbs/core.rb CHANGED
@@ -11,9 +11,15 @@ module Irbs
11
11
  def initialize(config)
12
12
  @config = config
13
13
 
14
+ # YARD::Parser::SourceParser.after_parse_file do |parser|
15
+ # next unless parser.file == 'example/app.rb'
16
+ # $parser = parser.instance_variable_get(:@parser)
17
+ # end
18
+
14
19
  YARD::Tags::Library.define_tag('Signature', :sig)
15
20
  YARD::Tags::Library.define_tag('Raw rbs code', :rbs)
16
- YARD.parse(config.paths)
21
+
22
+ YARD::Parser::SourceParser.parse(config.paths)
17
23
  YARD::Registry.load_all
18
24
  end
19
25
 
@@ -0,0 +1,20 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Irbs
4
+ # @rbs def statement: () -> untyped
5
+ module MonkeyPatch
6
+ protected
7
+
8
+ def process_mixin(mixin)
9
+ super.tap do
10
+ i = statement.method_name(true) == :include ? 0 : -1
11
+ ident = statement[0].source
12
+ _1[i].instance_variable_set(:@__ident, ident)
13
+ end
14
+ end
15
+ end
16
+ end
17
+
18
+ class YARD::Handlers::Ruby::MixinHandler # rubocop:disable Style/ClassAndModuleChildren
19
+ prepend ::Irbs::MonkeyPatch
20
+ end
@@ -45,10 +45,10 @@ module Irbs
45
45
  end
46
46
 
47
47
  # @sig () -> String
48
- def to_rbs # rubocop:todo Metrics/AbcSize, Metrics/CyclomaticComplexity
48
+ def to_rbs # rubocop:todo Metrics/AbcSize
49
49
  [
50
50
  namespace_definition,
51
- raw_rbss.map{ Template.rbs(_1) },
51
+ raw_rbses.map{ Template.rbs(_1) },
52
52
  class_mixins.map{ Template.extend(_1) },
53
53
  instance_mixins.map{ Template.include(_1) },
54
54
  config.ingore_constant ? nil : constants.map{ Template.constant(_1) },
@@ -64,7 +64,7 @@ module Irbs
64
64
  end
65
65
 
66
66
  # @sig () -> Array[YARD::Tags::Tag]
67
- def raw_rbss
67
+ def raw_rbses
68
68
  obj.tags(:rbs)
69
69
  end
70
70
 
data/lib/irbs/template.rb CHANGED
@@ -24,7 +24,9 @@ module Irbs
24
24
 
25
25
  # @sig (YARD::CodeObjects::ModuleObject) -> String
26
26
  def include(mod)
27
- " include ::#{mod.path}"
27
+ ident = mod.instance_variable_get(:@__ident)
28
+
29
+ " #{ident} ::#{mod.path}"
28
30
  end
29
31
 
30
32
  # @sig (YARD::CodeObjects::ModuleObject) -> String
data/lib/irbs/version.rb CHANGED
@@ -2,5 +2,5 @@
2
2
 
3
3
  module Irbs
4
4
  # @sig String
5
- VERSION = '0.1.0'
5
+ VERSION = '0.2.0'
6
6
  end
data/lib/irbs.rb CHANGED
@@ -4,6 +4,7 @@ require_relative 'irbs/attribute_wrapper'
4
4
  require_relative 'irbs/cli'
5
5
  require_relative 'irbs/config'
6
6
  require_relative 'irbs/core'
7
+ require_relative 'irbs/monkey_patch'
7
8
  require_relative 'irbs/rbs_generator'
8
9
  require_relative 'irbs/template'
9
10
  require_relative 'irbs/version'
@@ -5,7 +5,7 @@ module ::Irbs
5
5
  end
6
6
 
7
7
  class ::Irbs::CLI
8
- NO_CONSTANT_HELP_MESSAGE: String
8
+ IGNORE_CONSTANT_HELP_MESSAGE: String
9
9
  public def self.run: (Array[String]) -> void
10
10
  private def self.parse_opt: (Array[String]) -> Irbs::Config
11
11
  end
@@ -32,6 +32,10 @@ module ::Irbs::Template
32
32
  public def self.rbs: (YARD::Tags::Tag) -> String
33
33
  end
34
34
 
35
+ module ::Irbs::MonkeyPatch
36
+ def statement: () -> untyped
37
+ end
38
+
35
39
  class ::Irbs::RbsGenerator
36
40
  extend ::Forwardable
37
41
  private attr_reader obj: YARD::CodeObjects::NamespaceObject
@@ -44,7 +48,7 @@ class ::Irbs::RbsGenerator
44
48
  private def writeout: () -> void
45
49
  private def to_rbs: () -> String
46
50
  private def namespace_definition: () -> String
47
- private def raw_rbss: () -> Array[YARD::Tags::Tag]
51
+ private def raw_rbses: () -> Array[YARD::Tags::Tag]
48
52
  private def child_namespaces: () -> Array[YARD::CodeObjects::NamespaceObject]
49
53
  private def constants: () -> Array[YARD::CodeObjects::ConstantObject]
50
54
  private def meths: () -> Array[YARD::CodeObjects::MethodObject]
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: irbs
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - diaphragm
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2022-11-20 00:00:00.000000000 Z
11
+ date: 2022-11-21 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description:
14
14
  email:
@@ -26,21 +26,22 @@ files:
26
26
  - Rakefile
27
27
  - Steepfile
28
28
  - example/app.rb
29
- - example/irbs.rbs
29
+ - example/isig.rbs
30
30
  - example/typeprof.rbs
31
31
  - exe/irbs
32
32
  - irbs.gemspec
33
- - isig/irbs.rbs
34
33
  - lib/irbs.rb
35
34
  - lib/irbs/attribute_wrapper.rb
36
35
  - lib/irbs/cli.rb
37
36
  - lib/irbs/config.rb
38
37
  - lib/irbs/core.rb
38
+ - lib/irbs/monkey_patch.rb
39
39
  - lib/irbs/rbs_generator.rb
40
40
  - lib/irbs/template.rb
41
41
  - lib/irbs/version.rb
42
42
  - rbs_collection.lock.yaml
43
43
  - rbs_collection.yaml
44
+ - sig/isig.rbs
44
45
  homepage: https://github.com/diaphragm/irbs
45
46
  licenses:
46
47
  - MIT