Skip to content

Commit fce4cae

Browse files
committed
Enable missing rules and more documentation
1 parent d67cb70 commit fce4cae

File tree

14 files changed

+304
-213
lines changed

14 files changed

+304
-213
lines changed

Diff for: .github/workflows/main.yml

+3-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,9 @@ jobs:
3737
bundler-cache: true
3838
ruby-version: '3.1'
3939
- name: Check
40-
run: bundle exec rake check
40+
run: |
41+
bundle exec rake check
42+
bundle exec rubocop
4143
4244
automerge:
4345
name: AutoMerge

Diff for: .rubocop.yml

+3-17
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,6 @@ AllCops:
1212

1313
Layout/LineLength:
1414
Max: 80
15-
AllowedPatterns:
16-
- '^\s*in '
17-
- '^\s*location: Location'
1815

1916
Lint/DuplicateBranch:
2017
Enabled: false
@@ -25,6 +22,9 @@ Lint/InterpolationCheck:
2522
Lint/MissingSuper:
2623
Enabled: false
2724

25+
Lint/UnusedMethodArgument:
26+
AllowUnusedKeywordArguments: true
27+
2828
Metrics:
2929
Enabled: false
3030

@@ -72,17 +72,3 @@ Style/PerlBackrefs:
7272

7373
Style/SpecialGlobalVars:
7474
Enabled: false
75-
76-
###
77-
78-
Lint/AssignmentInCondition:
79-
Enabled: false
80-
81-
Lint/UnusedMethodArgument:
82-
Enabled: false
83-
84-
Style/Documentation:
85-
Enabled: false
86-
87-
Style/StringLiterals:
88-
Enabled: false

Diff for: README.md

+24
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ It is built with only standard library dependencies. It additionally ships with
1616
- [ast](#ast)
1717
- [check](#check)
1818
- [format](#format)
19+
- [json](#json)
20+
- [match](#match)
1921
- [write](#write)
2022
- [Library](#library)
2123
- [SyntaxTree.read(filepath)](#syntaxtreereadfilepath)
@@ -34,6 +36,9 @@ It is built with only standard library dependencies. It additionally ships with
3436
- [textDocument/inlayHints](#textdocumentinlayhints)
3537
- [syntaxTree/visualizing](#syntaxtreevisualizing)
3638
- [Plugins](#plugins)
39+
- [Integration](#integration)
40+
- [RuboCop](#rubocop)
41+
- [VSCode](#vscode)
3742
- [Contributing](#contributing)
3843
- [License](#license)
3944

@@ -395,6 +400,25 @@ Below are listed all of the "official" plugins hosted under the same GitHub orga
395400
* [SyntaxTree::JSON](https://github.com/ruby-syntax-tree/syntax_tree-json) for JSON.
396401
* [SyntaxTree::RBS](https://github.com/ruby-syntax-tree/syntax_tree-rbs) for the [RBS type language](https://github.com/ruby/rbs).
397402

403+
When invoking the CLI, you pass through the list of plugins with the `--plugins` options to the commands that accept them. They should be a comma-delimited list. When the CLI first starts, it will require the files corresponding to those names.
404+
405+
## Integration
406+
407+
Syntax Tree's goal is to seemlessly integrate into your workflow. To this end, it provides a couple of additional tools beyond the CLI and the Ruby library.
408+
409+
### RuboCop
410+
411+
RuboCop and Syntax Tree serve different purposes, but there is overlap with some of RuboCop's functionality. Syntax Tree provides a RuboCop configuration file to disable rules that are redundant with Syntax Tree. To use this configuration file, add the following snippet to the top of your project's `.rubocop.yml`:
412+
413+
```yaml
414+
inherit_gem:
415+
syntax_tree: config/rubocop.yml
416+
```
417+
418+
### VSCode
419+
420+
To integrate Syntax Tree into VSCode, you should use the official VSCode extension [ruby-syntax-tree/vscode-syntax-tree](https://github.com/ruby-syntax-tree/vscode-syntax-tree).
421+
398422
## Contributing
399423
400424
Bug reports and pull requests are welcome on GitHub at https://github.com/ruby-syntax-tree/syntax_tree.

Diff for: config/rubocop.yml

-5
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,8 @@ Layout:
99
#
1010
# Users can always override these defaults in their own rubocop.yml files.
1111
# https://github.com/prettier/plugin-ruby/issues/825
12-
#
13-
# We're also explicitly allowing pattern matching to extend beyond the maximum
14-
# line length, since SyntaxTree prefers putting patterns on a single line.
1512
Layout/LineLength:
1613
Enabled: true
17-
AllowedPatterns:
18-
- '^\s*in '
1914

2015
Style/MultilineIfModifier:
2116
Enabled: false

Diff for: lib/syntax_tree.rb

+4
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,10 @@
3030
end
3131
end
3232

33+
# Syntax Tree is a suite of tools built on top of the internal CRuby parser. It
34+
# provides the ability to generate a syntax tree from source, as well as the
35+
# tools necessary to inspect and manipulate that syntax tree. It can be used to
36+
# build formatters, linters, language servers, and more.
3337
module SyntaxTree
3438
# This holds references to objects that respond to both #parse and #format
3539
# so that we can use them in the CLI.

Diff for: lib/syntax_tree/cli.rb

+8-6
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
# frozen_string_literal: true
22

33
module SyntaxTree
4+
# Syntax Tree ships with the `stree` CLI, which can be used to inspect and
5+
# manipulate Ruby code. This module is responsible for powering that CLI.
46
module CLI
57
# A utility wrapper around colored strings in the output.
68
class Color
@@ -46,7 +48,7 @@ def failure
4648

4749
# An action of the CLI that prints out the AST for the given source.
4850
class AST < Action
49-
def run(handler, filepath, source)
51+
def run(handler, _filepath, source)
5052
pp handler.parse(source)
5153
end
5254
end
@@ -100,7 +102,7 @@ def failure
100102

101103
# An action of the CLI that prints out the doc tree IR for the given source.
102104
class Doc < Action
103-
def run(handler, filepath, source)
105+
def run(handler, _filepath, source)
104106
formatter = Formatter.new(source, [])
105107
handler.parse(source).format(formatter)
106108
pp formatter.groups.first
@@ -109,15 +111,15 @@ def run(handler, filepath, source)
109111

110112
# An action of the CLI that formats the input source and prints it out.
111113
class Format < Action
112-
def run(handler, filepath, source)
114+
def run(handler, _filepath, source)
113115
puts handler.format(source)
114116
end
115117
end
116118

117119
# An action of the CLI that converts the source into its equivalent JSON
118120
# representation.
119121
class Json < Action
120-
def run(handler, filepath, source)
122+
def run(handler, _filepath, source)
121123
object = Visitor::JSONVisitor.new.visit(handler.parse(source))
122124
puts JSON.pretty_generate(object)
123125
end
@@ -126,7 +128,7 @@ def run(handler, filepath, source)
126128
# An action of the CLI that outputs a pattern-matching Ruby expression that
127129
# would match the input given.
128130
class Match < Action
129-
def run(handler, filepath, source)
131+
def run(handler, _filepath, source)
130132
formatter = Formatter.new(source, [])
131133
Visitor::MatchVisitor.new(formatter).visit(handler.parse(source))
132134
formatter.flush
@@ -296,7 +298,7 @@ def run(argv)
296298
private
297299

298300
def each_file(arguments)
299-
if $stdin.tty?
301+
if $stdin.tty? || arguments.any?
300302
arguments.each do |pattern|
301303
Dir
302304
.glob(pattern)

Diff for: lib/syntax_tree/language_server.rb

+6-1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,11 @@
77
require_relative "language_server/inlay_hints"
88

99
module SyntaxTree
10+
# Syntax Tree additionally ships with a language server conforming to the
11+
# language server protocol. It can be invoked through the CLI by running:
12+
#
13+
# stree lsp
14+
#
1015
class LanguageServer
1116
attr_reader :input, :output
1217

@@ -21,7 +26,7 @@ def run
2126
hash[uri] = File.binread(CGI.unescape(URI.parse(uri).path))
2227
end
2328

24-
while headers = input.gets("\r\n\r\n")
29+
while (headers = input.gets("\r\n\r\n"))
2530
source = input.read(headers[/Content-Length: (\d+)/i, 1].to_i)
2631
request = JSON.parse(source, symbolize_names: true)
2732

Diff for: lib/syntax_tree/language_server/inlay_hints.rb

+7
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,13 @@
22

33
module SyntaxTree
44
class LanguageServer
5+
# This class provides inlay hints for the language server. It is loosely
6+
# designed around the LSP spec, but existed before the spec was finalized so
7+
# is a little different for now.
8+
#
9+
# For more information, see the spec here:
10+
# https://github.com/microsoft/language-server-protocol/issues/956.
11+
#
512
class InlayHints < Visitor
613
attr_reader :stack, :before, :after
714

0 commit comments

Comments
 (0)