Skip to content

Commit

Permalink
Add basic ruby linter (#15168)
Browse files Browse the repository at this point in the history
Adds rubocop as a linter for ruby.:
 - Adds .rubocop.yml which defines specific config on top of default
 - Adds Gradle task 'lint' task
 - Adds 'lint:report' rake task to report Lint Cops.
 - Adds 'lint:format' rake task to automatically format the code.
  • Loading branch information
roaksoax authored Jul 13, 2023
1 parent 07b6635 commit 6154a69
Show file tree
Hide file tree
Showing 5 changed files with 269 additions and 0 deletions.
220 changes: 220 additions & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,220 @@
AllCops:
RubyInterpreters:
- ruby
- rake
- jruby
Include:
- '**/*.rb'
- '**/*.gemfile'
- '**/*.gemspec'
- '**/*.rake'
- '**/Gemfile'
- '**/Rakefile'
Exclude:
- 'node_modules/**/*'
- 'tmp/**/*'
- 'vendor/**/*'
- '.git/**/*'
- 'build/**/*'
- 'config/**/*'
DisplayCopNames: true
UseCache: false
#################### Layout ###########################
Layout/AccessModifierIndentation:
Enabled: false
Layout/ArgumentAlignment:
Enabled: false
Layout/ArrayAlignment:
Enabled: false
Layout/AssignmentIndentation:
Enabled: false
Layout/BeginEndAlignment:
Enabled: false
Layout/BlockAlignment:
Enabled: false
Layout/BlockEndNewline:
Enabled: false
Layout/CaseIndentation:
Enabled: false
Layout/ClassStructure:
Enabled: false
Layout/ClosingHeredocIndentation:
Enabled: false
Layout/ClosingParenthesisIndentation:
Enabled: false
Layout/CommentIndentation:
Enabled: false
Layout/ConditionPosition:
Enabled: false
Layout/DefEndAlignment:
Enabled: false
Layout/DotPosition:
Enabled: false
Layout/ElseAlignment:
Enabled: false
Layout/EmptyComment:
Enabled: false
Layout/EmptyLineAfterGuardClause:
Enabled: false
Layout/EmptyLineAfterMagicComment:
Enabled: false
Layout/EmptyLineAfterMultilineCondition:
Enabled: false
Layout/EmptyLineBetweenDefs:
Enabled: false
Layout/EmptyLines:
Enabled: false
Layout/EmptyLinesAroundAccessModifier:
Enabled: false
Layout/EmptyLinesAroundArguments:
Enabled: false
Layout/EmptyLinesAroundAttributeAccessor:
Enabled: false
Layout/EmptyLinesAroundBeginBody:
Enabled: false
Layout/EmptyLinesAroundBlockBody:
Enabled: false
Layout/EmptyLinesAroundClassBody:
Enabled: false
Layout/EmptyLinesAroundExceptionHandlingKeywords:
Enabled: false
Layout/EmptyLinesAroundMethodBody:
Enabled: false
Layout/EmptyLinesAroundModuleBody:
Enabled: false
Layout/EndAlignment:
Enabled: false
Layout/EndOfLine:
Enabled: false
Layout/ExtraSpacing:
Enabled: false
Layout/FirstArgumentIndentation:
Enabled: false
Layout/FirstArrayElementIndentation:
Enabled: false
Layout/FirstArrayElementLineBreak:
Enabled: false
Layout/FirstHashElementIndentation:
Enabled: false
Layout/FirstHashElementLineBreak:
Enabled: false
Layout/FirstMethodArgumentLineBreak:
Enabled: false
Layout/FirstMethodParameterLineBreak:
Enabled: false
Layout/FirstParameterIndentation:
Enabled: false
Layout/HashAlignment:
Enabled: false
Layout/HeredocArgumentClosingParenthesis:
Enabled: false
Layout/HeredocIndentation:
Enabled: false
Layout/IndentationConsistency:
Enabled: false
Layout/IndentationStyle:
Enabled: false
Layout/IndentationWidth:
Enabled: false
Layout/InitialIndentation:
Enabled: false
Layout/LeadingCommentSpace:
Enabled: false
Layout/LeadingEmptyLines:
Enabled: false
Layout/LineContinuationLeadingSpace:
Enabled: false
Layout/LineContinuationSpacing:
Enabled: false
Layout/LineEndStringConcatenationIndentation:
Enabled: false
Layout/LineLength:
Enabled: false
Layout/MultilineArrayBraceLayout:
Enabled: false
Layout/MultilineArrayLineBreaks:
Enabled: false
Layout/MultilineAssignmentLayout:
Enabled: false
Layout/MultilineBlockLayout:
Enabled: false
Layout/MultilineHashBraceLayout:
Enabled: false
Layout/MultilineHashKeyLineBreaks:
Enabled: false
Layout/MultilineMethodArgumentLineBreaks:
Enabled: false
Layout/MultilineMethodCallBraceLayout:
Enabled: false
Layout/MultilineMethodCallIndentation:
Enabled: false
Layout/MultilineMethodDefinitionBraceLayout:
Enabled: false
Layout/MultilineMethodParameterLineBreaks:
Enabled: false
Layout/MultilineOperationIndentation:
Enabled: false
Layout/ParameterAlignment:
Enabled: false
Layout/RedundantLineBreak:
Enabled: false
Layout/RescueEnsureAlignment:
Enabled: false
Layout/SingleLineBlockChain:
Enabled: false
Layout/SpaceAfterColon:
Enabled: false
Layout/SpaceAfterComma:
Enabled: false
Layout/SpaceAfterMethodName:
Enabled: false
Layout/SpaceAfterNot:
Enabled: false
Layout/SpaceAfterSemicolon:
Enabled: false
Layout/SpaceAroundBlockParameters:
Enabled: false
Layout/SpaceAroundEqualsInParameterDefault:
Enabled: false
Layout/SpaceAroundKeyword:
Enabled: false
Layout/SpaceAroundMethodCallOperator:
Enabled: false
Layout/SpaceAroundOperators:
Enabled: false
Layout/SpaceBeforeBlockBraces:
Enabled: false
Layout/SpaceBeforeBrackets:
Enabled: false
Layout/SpaceBeforeComma:
Enabled: false
Layout/SpaceBeforeComment:
Enabled: false
Layout/SpaceBeforeFirstArg:
Enabled: false
Layout/SpaceBeforeSemicolon:
Enabled: false
Layout/SpaceInLambdaLiteral:
Enabled: false
Layout/SpaceInsideArrayLiteralBrackets:
Enabled: false
Layout/SpaceInsideArrayPercentLiteral:
Enabled: false
Layout/SpaceInsideBlockBraces:
Enabled: false
Layout/SpaceInsideHashLiteralBraces:
Enabled: false
Layout/SpaceInsideParens:
Enabled: false
Layout/SpaceInsidePercentLiteralDelimiters:
Enabled: false
Layout/SpaceInsideRangeLiteral:
Enabled: false
Layout/SpaceInsideReferenceBrackets:
Enabled: false
Layout/SpaceInsideStringInterpolation:
Enabled: false
Layout/TrailingEmptyLines:
Enabled: false
Layout/TrailingWhitespace:
Enabled: false
1 change: 1 addition & 0 deletions Gemfile.template
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ gem "octokit", "~> 4.25", :group => :build
gem "rubyzip", "~> 1", :group => :build
gem "stud", "~> 0.0.22", :group => :build

gem "rubocop", :group => :development
gem "belzebuth", :group => :development
gem "benchmark-ips", :group => :development
gem "ci_reporter_rspec", "~> 1", :group => :development
Expand Down
2 changes: 2 additions & 0 deletions Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -34,5 +34,7 @@ Developing?
`rake test:install-core` installs any dependencies for testing Logstash core
`rake test:core` to run Logstash core tests
`rake vendor:clean` clean vendored dependencies used for Logstash development
`rake lint:report` to run the Rubocop linter
`rake lint:format` to automatically format the code
HELP
end
8 changes: 8 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -739,6 +739,14 @@ class JDKDetails {
}
}

tasks.register("lint") {
// Calls rake's 'lint' task
dependsOn installDevelopmentGems
doLast {
rake(projectDir, buildDir, 'lint:report')
}
}

tasks.register("downloadJdk", Download) {
// CLI project properties: -Pjdk_bundle_os=[windows|linux|darwin] -Pjdk_arch=[arm64|x86_64]

Expand Down
38 changes: 38 additions & 0 deletions rakelib/lint.rake
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# Licensed to Elasticsearch B.V. under one or more contributor
# license agreements. See the NOTICE file distributed with
# this work for additional information regarding copyright
# ownership. Elasticsearch B.V. licenses this file to you under
# the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.

namespace "lint" do

module RuboCLI
def self.run!(*args)
require "rubocop"
cli = RuboCop::CLI.new
result = cli.run(["--force-exclusion", *args])
raise "Linting failed." if result.nonzero?
end
end

# task that runs lint report
task "report" do
RuboCLI.run!("--lint")
end

# task that automatically fixes code formatting
task "format" do
RuboCLI.run!("--fix-layout")
end
end

0 comments on commit 6154a69

Please sign in to comment.