Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 601b7b5

Browse files
authored
Merge pull request #65 from ruby-syntax-tree/rubocop
RuboCop
2 parents 8e2e0c8 + fce4cae commit 601b7b5

27 files changed

+1377
-599
lines changed

.github/workflows/main.yml

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,28 @@ jobs:
2424
ruby-version: ${{ matrix.ruby }}
2525
- name: Test
2626
run: bundle exec rake test
27+
28+
check:
29+
name: Check
30+
runs-on: ubuntu-latest
31+
env:
32+
CI: true
33+
steps:
34+
- uses: actions/checkout@master
35+
- uses: ruby/setup-ruby@v1
36+
with:
37+
bundler-cache: true
38+
ruby-version: '3.1'
39+
- name: Check
40+
run: |
41+
bundle exec rake check
42+
bundle exec rubocop
43+
2744
automerge:
2845
name: AutoMerge
29-
needs: ci
46+
needs:
47+
- ci
48+
- check
3049
runs-on: ubuntu-latest
3150
if: github.event_name == 'pull_request_target' && github.actor == 'dependabot[bot]'
3251
steps:

.rubocop.yml

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
inherit_from: config/rubocop.yml
2+
3+
AllCops:
4+
DisplayCopNames: true
5+
DisplayStyleGuide: true
6+
NewCops: enable
7+
SuggestExtensions: false
8+
TargetRubyVersion: 2.7
9+
Exclude:
10+
- '{bin,coverage,pkg,test/fixtures,vendor,tmp}/**/*'
11+
- test.rb
12+
13+
Layout/LineLength:
14+
Max: 80
15+
16+
Lint/DuplicateBranch:
17+
Enabled: false
18+
19+
Lint/InterpolationCheck:
20+
Enabled: false
21+
22+
Lint/MissingSuper:
23+
Enabled: false
24+
25+
Lint/UnusedMethodArgument:
26+
AllowUnusedKeywordArguments: true
27+
28+
Metrics:
29+
Enabled: false
30+
31+
Naming/MethodName:
32+
Enabled: false
33+
34+
Naming/MethodParameterName:
35+
Enabled: false
36+
37+
Naming/RescuedExceptionsVariableName:
38+
PreferredName: error
39+
40+
Style/ExplicitBlockArgument:
41+
Enabled: false
42+
43+
Style/FormatString:
44+
EnforcedStyle: percent
45+
46+
Style/GuardClause:
47+
Enabled: false
48+
49+
Style/IdenticalConditionalBranches:
50+
Enabled: false
51+
52+
Style/IfInsideElse:
53+
Enabled: false
54+
55+
Style/KeywordParametersOrder:
56+
Enabled: false
57+
58+
Style/MutableConstant:
59+
Enabled: false
60+
61+
Style/NegatedIfElseCondition:
62+
Enabled: false
63+
64+
Style/NumericPredicate:
65+
Enabled: false
66+
67+
Style/ParallelAssignment:
68+
Enabled: false
69+
70+
Style/PerlBackrefs:
71+
Enabled: false
72+
73+
Style/SpecialGlobalVars:
74+
Enabled: false

Gemfile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,5 @@
33
source "https://rubygems.org"
44

55
gemspec
6+
7+
gem "rubocop"

Gemfile.lock

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,35 @@ PATH
66
GEM
77
remote: https://rubygems.org/
88
specs:
9+
ast (2.4.2)
910
docile (1.4.0)
1011
minitest (5.15.0)
12+
parallel (1.22.1)
13+
parser (3.1.2.0)
14+
ast (~> 2.4.1)
15+
rainbow (3.1.1)
1116
rake (13.0.6)
17+
regexp_parser (2.3.1)
18+
rexml (3.2.5)
19+
rubocop (1.28.2)
20+
parallel (~> 1.10)
21+
parser (>= 3.1.0.0)
22+
rainbow (>= 2.2.2, < 4.0)
23+
regexp_parser (>= 1.8, < 3.0)
24+
rexml
25+
rubocop-ast (>= 1.17.0, < 2.0)
26+
ruby-progressbar (~> 1.7)
27+
unicode-display_width (>= 1.4.0, < 3.0)
28+
rubocop-ast (1.17.0)
29+
parser (>= 3.1.1.0)
30+
ruby-progressbar (1.11.0)
1231
simplecov (0.21.2)
1332
docile (~> 1.1)
1433
simplecov-html (~> 0.11)
1534
simplecov_json_formatter (~> 0.1)
1635
simplecov-html (0.12.3)
1736
simplecov_json_formatter (0.1.4)
37+
unicode-display_width (2.1.0)
1838

1939
PLATFORMS
2040
arm64-darwin-21
@@ -27,6 +47,7 @@ DEPENDENCIES
2747
bundler
2848
minitest
2949
rake
50+
rubocop
3051
simplecov
3152
syntax_tree!
3253

README.md

Lines changed: 24 additions & 0 deletions
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.

Rakefile

Lines changed: 27 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,34 @@
11
# frozen_string_literal: true
22

3-
require 'bundler/gem_tasks'
4-
require 'rake/testtask'
3+
require "bundler/gem_tasks"
4+
require "rake/testtask"
55

66
Rake::TestTask.new(:test) do |t|
7-
t.libs << 'test'
8-
t.libs << 'lib'
9-
t.test_files = FileList['test/**/*_test.rb']
7+
t.libs << "test"
8+
t.libs << "lib"
9+
t.test_files = FileList["test/**/*_test.rb"]
1010
end
1111

1212
task default: :test
13+
14+
FILEPATHS = %w[
15+
Gemfile
16+
Rakefile
17+
syntax_tree.gemspec
18+
lib/**/*.rb
19+
test/*.rb
20+
].freeze
21+
22+
task :syntax_tree do
23+
$:.unshift File.expand_path("lib", __dir__)
24+
require "syntax_tree"
25+
require "syntax_tree/cli"
26+
end
27+
28+
task check: :syntax_tree do
29+
exit SyntaxTree::CLI.run(["check"] + FILEPATHS)
30+
end
31+
32+
task format: :syntax_tree do
33+
exit SyntaxTree::CLI.run(["write"] + FILEPATHS)
34+
end

config/rubocop.yml

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
# Disabling all Layout/* rules, as they're unnecessary when the user is using
2+
# Syntax Tree to handle all of the formatting.
3+
Layout:
4+
Enabled: false
5+
6+
# Re-enable Layout/LineLength because certain cops that most projects use
7+
# (e.g. Style/IfUnlessModifier) require Layout/LineLength to be enabled.
8+
# By leaving it disabled, those rules will mis-fire.
9+
#
10+
# Users can always override these defaults in their own rubocop.yml files.
11+
# https://github.com/prettier/plugin-ruby/issues/825
12+
Layout/LineLength:
13+
Enabled: true
14+
15+
Style/MultilineIfModifier:
16+
Enabled: false
17+
18+
# Syntax Tree will expand empty methods to put the end keyword on the subsequent
19+
# line to reduce git diff noise.
20+
Style/EmptyMethod:
21+
EnforcedStyle: expanded
22+
23+
# lambdas that are constructed with the lambda method call cannot be safely
24+
# turned into lambda literals without removing a method call.
25+
Style/Lambda:
26+
Enabled: false
27+
28+
# When method chains with multiple blocks are chained together, rubocop will let
29+
# them pass if they're using braces but not if they're using do and end
30+
# keywords. Because we will break individual blocks down to using keywords if
31+
# they are multiline, this conflicts with rubocop.
32+
Style/MultilineBlockChain:
33+
Enabled: false
34+
35+
# Syntax Tree by default uses double quotes, so changing the configuration here
36+
# to match that.
37+
Style/StringLiterals:
38+
EnforcedStyle: double_quotes
39+
40+
Style/StringLiteralsInInterpolation:
41+
EnforcedStyle: double_quotes
42+
43+
Style/QuotedSymbols:
44+
EnforcedStyle: double_quotes
45+
46+
# We let users have a little more freedom with symbol and words arrays. If the
47+
# user only has an individual item like ["value"] then we don't bother
48+
# converting it because it ends up being just noise.
49+
Style/SymbolArray:
50+
Enabled: false
51+
52+
Style/WordArray:
53+
Enabled: false
54+
55+
# We don't support trailing commas in Syntax Tree by default, so just turning
56+
# these off for now.
57+
Style/TrailingCommaInArguments:
58+
Enabled: false
59+
60+
Style/TrailingCommaInArrayLiteral:
61+
Enabled: false
62+
63+
Style/TrailingCommaInHashLiteral:
64+
Enabled: false

lib/syntax_tree.rb

Lines changed: 4 additions & 0 deletions
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.

0 commit comments

Comments
 (0)