syntax_tree 2.3.0 → 2.4.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,6 +1,9 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module SyntaxTree
4
+ # Visitor is a parent class that provides the ability to walk down the tree
5
+ # and handle a subset of nodes. By defining your own subclass, you can
6
+ # explicitly handle a node type by defining a visit_* method.
4
7
  class Visitor
5
8
  # This is raised when you use the Visitor.visit_method method and it fails.
6
9
  # It is correctable to through DidYouMean.
@@ -24,7 +27,9 @@ module SyntaxTree
24
27
 
25
28
  def corrections
26
29
  @corrections ||=
27
- DidYouMean::SpellChecker.new(dictionary: Visitor.visit_methods).correct(visit_method)
30
+ DidYouMean::SpellChecker.new(
31
+ dictionary: Visitor.visit_methods
32
+ ).correct(visit_method)
28
33
  end
29
34
 
30
35
  DidYouMean.correct_error(VisitMethodError, self)
data/lib/syntax_tree.rb CHANGED
@@ -11,7 +11,9 @@ require_relative "syntax_tree/node"
11
11
  require_relative "syntax_tree/parser"
12
12
  require_relative "syntax_tree/version"
13
13
  require_relative "syntax_tree/visitor"
14
+ require_relative "syntax_tree/visitor/field_visitor"
14
15
  require_relative "syntax_tree/visitor/json_visitor"
16
+ require_relative "syntax_tree/visitor/match_visitor"
15
17
  require_relative "syntax_tree/visitor/pretty_print_visitor"
16
18
 
17
19
  # If PrettyPrint::Align isn't defined, then we haven't gotten the updated
@@ -28,6 +30,20 @@ unless PrettyPrint.const_defined?(:Align)
28
30
  end
29
31
  end
30
32
 
33
+ # When PP is running, it expects that everything that interacts with it is going
34
+ # to flow through PP.pp, since that's the main entry into the module from the
35
+ # perspective of its uses in core Ruby. In doing so, it calls guard_inspect_key
36
+ # at the top of the PP.pp method, which establishes some thread-local hashes to
37
+ # check for cycles in the pretty printed tree. This means that if you want to
38
+ # manually call pp on some object _before_ you have established these hashes,
39
+ # you're going to break everything. So this call ensures that those hashes have
40
+ # been set up before anything uses pp manually.
41
+ PP.new(+"", 0).guard_inspect_key {}
42
+
43
+ # Syntax Tree is a suite of tools built on top of the internal CRuby parser. It
44
+ # provides the ability to generate a syntax tree from source, as well as the
45
+ # tools necessary to inspect and manipulate that syntax tree. It can be used to
46
+ # build formatters, linters, language servers, and more.
31
47
  module SyntaxTree
32
48
  # This holds references to objects that respond to both #parse and #format
33
49
  # so that we can use them in the CLI.
@@ -61,8 +77,10 @@ module SyntaxTree
61
77
  def self.read(filepath)
62
78
  encoding =
63
79
  File.open(filepath, "r") do |file|
80
+ break Encoding.default_external if file.eof?
81
+
64
82
  header = file.readline
65
- header += file.readline if header.start_with?("#!")
83
+ header += file.readline if !file.eof? && header.start_with?("#!")
66
84
  Ripper.new(header).tap(&:parse).encoding
67
85
  end
68
86
 
data/syntax_tree.gemspec CHANGED
@@ -1,30 +1,32 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require_relative 'lib/syntax_tree/version'
3
+ require_relative "lib/syntax_tree/version"
4
4
 
5
5
  Gem::Specification.new do |spec|
6
- spec.name = 'syntax_tree'
7
- spec.version = SyntaxTree::VERSION
8
- spec.authors = ['Kevin Newton']
9
- spec.email = ['kddnewton@gmail.com']
6
+ spec.name = "syntax_tree"
7
+ spec.version = SyntaxTree::VERSION
8
+ spec.authors = ["Kevin Newton"]
9
+ spec.email = ["kddnewton@gmail.com"]
10
10
 
11
- spec.summary = 'A parser based on ripper'
12
- spec.homepage = 'https://github.com/kddnewton/syntax_tree'
13
- spec.license = 'MIT'
14
- spec.metadata = { 'rubygems_mfa_required' => 'true' }
11
+ spec.summary = "A parser based on ripper"
12
+ spec.homepage = "https://github.com/kddnewton/syntax_tree"
13
+ spec.license = "MIT"
14
+ spec.metadata = { "rubygems_mfa_required" => "true" }
15
15
 
16
- spec.files = Dir.chdir(__dir__) do
17
- `git ls-files -z`.split("\x0").reject do |f|
18
- f.match(%r{^(test|spec|features)/})
16
+ spec.files =
17
+ Dir.chdir(__dir__) do
18
+ `git ls-files -z`.split("\x0")
19
+ .reject { |f| f.match(%r{^(test|spec|features)/}) }
19
20
  end
20
- end
21
21
 
22
- spec.bindir = 'exe'
23
- spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
22
+ spec.required_ruby_version = ">= 2.7.3"
23
+
24
+ spec.bindir = "exe"
25
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
24
26
  spec.require_paths = %w[lib]
25
27
 
26
- spec.add_development_dependency 'bundler'
27
- spec.add_development_dependency 'minitest'
28
- spec.add_development_dependency 'rake'
29
- spec.add_development_dependency 'simplecov'
28
+ spec.add_development_dependency "bundler"
29
+ spec.add_development_dependency "minitest"
30
+ spec.add_development_dependency "rake"
31
+ spec.add_development_dependency "simplecov"
30
32
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: syntax_tree
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.3.0
4
+ version: 2.4.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kevin Newton
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2022-04-22 00:00:00.000000000 Z
11
+ date: 2022-05-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -78,6 +78,7 @@ files:
78
78
  - ".github/workflows/gh-pages.yml"
79
79
  - ".github/workflows/main.yml"
80
80
  - ".gitignore"
81
+ - ".rubocop.yml"
81
82
  - CHANGELOG.md
82
83
  - CODE_OF_CONDUCT.md
83
84
  - Gemfile
@@ -88,19 +89,24 @@ files:
88
89
  - bin/bench
89
90
  - bin/console
90
91
  - bin/profile
92
+ - config/rubocop.yml
91
93
  - doc/logo.svg
92
94
  - exe/stree
93
95
  - lib/syntax_tree.rb
94
96
  - lib/syntax_tree/cli.rb
95
97
  - lib/syntax_tree/formatter.rb
98
+ - lib/syntax_tree/formatter/single_quotes.rb
96
99
  - lib/syntax_tree/language_server.rb
97
100
  - lib/syntax_tree/language_server/inlay_hints.rb
98
101
  - lib/syntax_tree/node.rb
99
102
  - lib/syntax_tree/parser.rb
103
+ - lib/syntax_tree/plugin/single_quotes.rb
100
104
  - lib/syntax_tree/prettyprint.rb
101
105
  - lib/syntax_tree/version.rb
102
106
  - lib/syntax_tree/visitor.rb
107
+ - lib/syntax_tree/visitor/field_visitor.rb
103
108
  - lib/syntax_tree/visitor/json_visitor.rb
109
+ - lib/syntax_tree/visitor/match_visitor.rb
104
110
  - lib/syntax_tree/visitor/pretty_print_visitor.rb
105
111
  - syntax_tree.gemspec
106
112
  homepage: https://github.com/kddnewton/syntax_tree
@@ -116,14 +122,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
116
122
  requirements:
117
123
  - - ">="
118
124
  - !ruby/object:Gem::Version
119
- version: '0'
125
+ version: 2.7.3
120
126
  required_rubygems_version: !ruby/object:Gem::Requirement
121
127
  requirements:
122
128
  - - ">="
123
129
  - !ruby/object:Gem::Version
124
130
  version: '0'
125
131
  requirements: []
126
- rubygems_version: 3.3.3
132
+ rubygems_version: 3.4.0.dev
127
133
  signing_key:
128
134
  specification_version: 4
129
135
  summary: A parser based on ripper