Skip to content

RuboCop #65

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
May 6, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 20 additions & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,28 @@ jobs:
ruby-version: ${{ matrix.ruby }}
- name: Test
run: bundle exec rake test

check:
name: Check
runs-on: ubuntu-latest
env:
CI: true
steps:
- uses: actions/checkout@master
- uses: ruby/setup-ruby@v1
with:
bundler-cache: true
ruby-version: '3.1'
- name: Check
run: |
bundle exec rake check
bundle exec rubocop

automerge:
name: AutoMerge
needs: ci
needs:
- ci
- check
runs-on: ubuntu-latest
if: github.event_name == 'pull_request_target' && github.actor == 'dependabot[bot]'
steps:
Expand Down
74 changes: 74 additions & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
inherit_from: config/rubocop.yml

AllCops:
DisplayCopNames: true
DisplayStyleGuide: true
NewCops: enable
SuggestExtensions: false
TargetRubyVersion: 2.7
Exclude:
- '{bin,coverage,pkg,test/fixtures,vendor,tmp}/**/*'
- test.rb

Layout/LineLength:
Max: 80

Lint/DuplicateBranch:
Enabled: false

Lint/InterpolationCheck:
Enabled: false

Lint/MissingSuper:
Enabled: false

Lint/UnusedMethodArgument:
AllowUnusedKeywordArguments: true

Metrics:
Enabled: false

Naming/MethodName:
Enabled: false

Naming/MethodParameterName:
Enabled: false

Naming/RescuedExceptionsVariableName:
PreferredName: error

Style/ExplicitBlockArgument:
Enabled: false

Style/FormatString:
EnforcedStyle: percent

Style/GuardClause:
Enabled: false

Style/IdenticalConditionalBranches:
Enabled: false

Style/IfInsideElse:
Enabled: false

Style/KeywordParametersOrder:
Enabled: false

Style/MutableConstant:
Enabled: false

Style/NegatedIfElseCondition:
Enabled: false

Style/NumericPredicate:
Enabled: false

Style/ParallelAssignment:
Enabled: false

Style/PerlBackrefs:
Enabled: false

Style/SpecialGlobalVars:
Enabled: false
2 changes: 2 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,5 @@
source "https://rubygems.org"

gemspec

gem "rubocop"
21 changes: 21 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,35 @@ PATH
GEM
remote: https://rubygems.org/
specs:
ast (2.4.2)
docile (1.4.0)
minitest (5.15.0)
parallel (1.22.1)
parser (3.1.2.0)
ast (~> 2.4.1)
rainbow (3.1.1)
rake (13.0.6)
regexp_parser (2.3.1)
rexml (3.2.5)
rubocop (1.28.2)
parallel (~> 1.10)
parser (>= 3.1.0.0)
rainbow (>= 2.2.2, < 4.0)
regexp_parser (>= 1.8, < 3.0)
rexml
rubocop-ast (>= 1.17.0, < 2.0)
ruby-progressbar (~> 1.7)
unicode-display_width (>= 1.4.0, < 3.0)
rubocop-ast (1.17.0)
parser (>= 3.1.1.0)
ruby-progressbar (1.11.0)
simplecov (0.21.2)
docile (~> 1.1)
simplecov-html (~> 0.11)
simplecov_json_formatter (~> 0.1)
simplecov-html (0.12.3)
simplecov_json_formatter (0.1.4)
unicode-display_width (2.1.0)

PLATFORMS
arm64-darwin-21
Expand All @@ -27,6 +47,7 @@ DEPENDENCIES
bundler
minitest
rake
rubocop
simplecov
syntax_tree!

Expand Down
24 changes: 24 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ It is built with only standard library dependencies. It additionally ships with
- [ast](#ast)
- [check](#check)
- [format](#format)
- [json](#json)
- [match](#match)
- [write](#write)
- [Library](#library)
- [SyntaxTree.read(filepath)](#syntaxtreereadfilepath)
Expand All @@ -34,6 +36,9 @@ It is built with only standard library dependencies. It additionally ships with
- [textDocument/inlayHints](#textdocumentinlayhints)
- [syntaxTree/visualizing](#syntaxtreevisualizing)
- [Plugins](#plugins)
- [Integration](#integration)
- [RuboCop](#rubocop)
- [VSCode](#vscode)
- [Contributing](#contributing)
- [License](#license)

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

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.

## Integration

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.

### RuboCop

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`:

```yaml
inherit_gem:
syntax_tree: config/rubocop.yml
```

### VSCode

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).

## Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/ruby-syntax-tree/syntax_tree.
Expand Down
32 changes: 27 additions & 5 deletions Rakefile
Original file line number Diff line number Diff line change
@@ -1,12 +1,34 @@
# frozen_string_literal: true

require 'bundler/gem_tasks'
require 'rake/testtask'
require "bundler/gem_tasks"
require "rake/testtask"

Rake::TestTask.new(:test) do |t|
t.libs << 'test'
t.libs << 'lib'
t.test_files = FileList['test/**/*_test.rb']
t.libs << "test"
t.libs << "lib"
t.test_files = FileList["test/**/*_test.rb"]
end

task default: :test

FILEPATHS = %w[
Gemfile
Rakefile
syntax_tree.gemspec
lib/**/*.rb
test/*.rb
].freeze

task :syntax_tree do
$:.unshift File.expand_path("lib", __dir__)
require "syntax_tree"
require "syntax_tree/cli"
end

task check: :syntax_tree do
exit SyntaxTree::CLI.run(["check"] + FILEPATHS)
end

task format: :syntax_tree do
exit SyntaxTree::CLI.run(["write"] + FILEPATHS)
end
64 changes: 64 additions & 0 deletions config/rubocop.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
# Disabling all Layout/* rules, as they're unnecessary when the user is using
# Syntax Tree to handle all of the formatting.
Layout:
Enabled: false

# Re-enable Layout/LineLength because certain cops that most projects use
# (e.g. Style/IfUnlessModifier) require Layout/LineLength to be enabled.
# By leaving it disabled, those rules will mis-fire.
#
# Users can always override these defaults in their own rubocop.yml files.
# https://github.com/prettier/plugin-ruby/issues/825
Layout/LineLength:
Enabled: true

Style/MultilineIfModifier:
Enabled: false

# Syntax Tree will expand empty methods to put the end keyword on the subsequent
# line to reduce git diff noise.
Style/EmptyMethod:
EnforcedStyle: expanded

# lambdas that are constructed with the lambda method call cannot be safely
# turned into lambda literals without removing a method call.
Style/Lambda:
Enabled: false

# When method chains with multiple blocks are chained together, rubocop will let
# them pass if they're using braces but not if they're using do and end
# keywords. Because we will break individual blocks down to using keywords if
# they are multiline, this conflicts with rubocop.
Style/MultilineBlockChain:
Enabled: false

# Syntax Tree by default uses double quotes, so changing the configuration here
# to match that.
Style/StringLiterals:
EnforcedStyle: double_quotes

Style/StringLiteralsInInterpolation:
EnforcedStyle: double_quotes

Style/QuotedSymbols:
EnforcedStyle: double_quotes

# We let users have a little more freedom with symbol and words arrays. If the
# user only has an individual item like ["value"] then we don't bother
# converting it because it ends up being just noise.
Style/SymbolArray:
Enabled: false

Style/WordArray:
Enabled: false

# We don't support trailing commas in Syntax Tree by default, so just turning
# these off for now.
Style/TrailingCommaInArguments:
Enabled: false

Style/TrailingCommaInArrayLiteral:
Enabled: false

Style/TrailingCommaInHashLiteral:
Enabled: false
4 changes: 4 additions & 0 deletions lib/syntax_tree.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@
end
end

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