diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index ecd5d28..f3cffbe 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -9,6 +9,19 @@ env: BUNDLE_WITHOUT: development:release jobs: + rubocop: + env: + BUNDLE_WITHOUT: release + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - name: Install Ruby ${{ matrix.ruby }} + uses: ruby/setup-ruby@v1 + with: + ruby-version: "3.1" + bundler-cache: true + - name: Run Rubocop + run: bundle exec rake rubocop test: runs-on: ubuntu-latest strategy: diff --git a/.rubocop.yml b/.rubocop.yml new file mode 100644 index 0000000..bfc47d3 --- /dev/null +++ b/.rubocop.yml @@ -0,0 +1,22 @@ +--- +inherit_from: .rubocop_todo.yml + +require: +- rubocop-performance +- rubocop-rake +- rubocop-rspec + +AllCops: + NewCops: enable + TargetRubyVersion: '2.4' + Exclude: + - vendor/**/* + +Metrics: + Enabled: false + +Style: + Enabled: false + +Layout: + Enabled: false diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml new file mode 100644 index 0000000..5433c4f --- /dev/null +++ b/.rubocop_todo.yml @@ -0,0 +1,177 @@ +# This configuration was generated by +# `rubocop --auto-gen-config` +# on 2023-03-15 20:57:21 UTC using RuboCop version 1.12.1. +# The point is for the user to remove these configuration records +# one by one as the offenses are removed from the code base. +# Note that changes in the inspected code, or installation of new +# versions of RuboCop, may require this file to be generated again. + +# Offense count: 1 +# Cop supports --auto-correct. +# Configuration parameters: TreatCommentsAsGroupSeparators, ConsiderPunctuation, Include. +# Include: **/*.gemspec +Gemspec/OrderedDependencies: + Exclude: + - 'puppet-syntax.gemspec' + +# Offense count: 1 +# Configuration parameters: IgnoreLiteralBranches, IgnoreConstantBranches. +Lint/DuplicateBranch: + Exclude: + - 'lib/puppet-syntax/templates.rb' + +# Offense count: 1 +Lint/MissingSuper: + Exclude: + - 'lib/puppet-syntax/tasks/puppet-syntax.rb' + +# Offense count: 1 +# Cop supports --auto-correct. +Lint/ParenthesesAsGroupedExpression: + Exclude: + - 'spec/puppet-syntax/manifests_spec.rb' + +# Offense count: 1 +Lint/RescueException: + Exclude: + - 'lib/puppet-syntax/hiera.rb' + +# Offense count: 1 +# Configuration parameters: AllowComments, AllowNil. +Lint/SuppressedException: + Exclude: + - 'Rakefile' + +# Offense count: 1 +# Cop supports --auto-correct. +# Configuration parameters: IgnoreEmptyBlocks, AllowUnusedKeywordArguments. +Lint/UnusedBlockArgument: + Exclude: + - 'lib/puppet-syntax/templates.rb' + +# Offense count: 1 +# Cop supports --auto-correct. +# Configuration parameters: AllowUnusedKeywordArguments, IgnoreEmptyMethods, IgnoreNotImplementedMethods. +Lint/UnusedMethodArgument: + Exclude: + - 'lib/puppet-syntax/tasks/puppet-syntax.rb' + +# Offense count: 1 +Lint/UselessAssignment: + Exclude: + - 'lib/puppet-syntax/templates.rb' + +# Offense count: 4 +# Configuration parameters: ExpectMatchingDefinition, CheckDefinitionPathHierarchy, Regex, IgnoreExecutableScripts, AllowedAcronyms. +# AllowedAcronyms: CLI, DSL, ACL, API, ASCII, CPU, CSS, DNS, EOF, GUID, HTML, HTTP, HTTPS, ID, IP, JSON, LHS, QPS, RAM, RHS, RPC, SLA, SMTP, SQL, SSH, TCP, TLS, TTL, UDP, UI, UID, UUID, URI, URL, UTF8, VM, XML, XMPP, XSRF, XSS +Naming/FileName: + Exclude: + - 'lib/puppet-syntax.rb' + - 'lib/puppet-syntax/tasks/puppet-syntax.rb' + - 'spec/puppet-syntax/tasks/puppet-syntax_spec.rb' + - 'spec/puppet-syntax_spec.rb' + +# Offense count: 6 +# Cop supports --auto-correct. +# Configuration parameters: PreferredName. +Naming/RescuedExceptionsVariableName: + Exclude: + - 'lib/puppet-syntax/hiera.rb' + - 'lib/puppet-syntax/manifests.rb' + - 'lib/puppet-syntax/templates.rb' + +# Offense count: 1 +# Cop supports --auto-correct. +Performance/RedundantSplitRegexpArgument: + Exclude: + - 'lib/puppet-syntax/hiera.rb' + +# Offense count: 7 +# Cop supports --auto-correct. +Performance/RegexpMatch: + Exclude: + - 'Rakefile' + - 'lib/puppet-syntax/hiera.rb' + - 'spec/puppet-syntax/hiera_spec.rb' + +# Offense count: 1 +# Configuration parameters: Prefixes. +# Prefixes: when, with, without +RSpec/ContextWording: + Exclude: + - 'spec/puppet-syntax/hiera_spec.rb' + +# Offense count: 1 +# Configuration parameters: IgnoredMetadata. +RSpec/DescribeClass: + Exclude: + - 'spec/puppet-syntax/tasks/puppet-syntax_spec.rb' + +# Offense count: 19 +# Cop supports --auto-correct. +# Configuration parameters: SkipBlocks, EnforcedStyle. +# SupportedStyles: described_class, explicit +RSpec/DescribedClass: + Exclude: + - 'spec/puppet-syntax/hiera_spec.rb' + - 'spec/puppet-syntax/manifests_spec.rb' + - 'spec/puppet-syntax/templates_spec.rb' + - 'spec/puppet-syntax_spec.rb' + +# Offense count: 8 +# Configuration parameters: CountAsOne. +RSpec/ExampleLength: + Max: 14 + +# Offense count: 40 +# Cop supports --auto-correct. +# Configuration parameters: CustomTransform, IgnoredWords. +RSpec/ExampleWording: + Exclude: + - 'spec/puppet-syntax/hiera_spec.rb' + - 'spec/puppet-syntax/manifests_spec.rb' + - 'spec/puppet-syntax/tasks/puppet-syntax_spec.rb' + - 'spec/puppet-syntax/templates_spec.rb' + - 'spec/puppet-syntax_spec.rb' + +# Offense count: 4 +# Configuration parameters: Include, CustomTransform, IgnoreMethods, SpecSuffixOnly. +# Include: **/*_spec*rb*, **/spec/**/* +RSpec/FilePath: + Exclude: + - 'spec/puppet-syntax/hiera_spec.rb' + - 'spec/puppet-syntax/manifests_spec.rb' + - 'spec/puppet-syntax/templates_spec.rb' + - 'spec/puppet-syntax_spec.rb' + +# Offense count: 2 +# Cop supports --auto-correct. +# Configuration parameters: EnforcedStyle. +# SupportedStyles: implicit, each, example +RSpec/HookArgument: + Exclude: + - 'spec/puppet-syntax/hiera_spec.rb' + - 'spec/puppet-syntax/templates_spec.rb' + +# Offense count: 29 +RSpec/MultipleExpectations: + Max: 8 + +# Offense count: 30 +# Configuration parameters: IgnoreSharedExamples. +RSpec/NamedSubject: + Exclude: + - 'spec/puppet-syntax/hiera_spec.rb' + - 'spec/puppet-syntax/manifests_spec.rb' + - 'spec/puppet-syntax/templates_spec.rb' + +# Offense count: 8 +RSpec/RepeatedDescription: + Exclude: + - 'spec/puppet-syntax/templates_spec.rb' + +# Offense count: 1 +# Cop supports --auto-correct. +Rake/Desc: + Exclude: + - 'Rakefile' diff --git a/Rakefile b/Rakefile index 2bfa8f2..fe86167 100644 --- a/Rakefile +++ b/Rakefile @@ -21,3 +21,14 @@ begin end rescue LoadError end + +begin + require 'rubocop/rake_task' +rescue LoadError + # RuboCop is an optional group +else + RuboCop::RakeTask.new(:rubocop) do |task| + # These make the rubocop experience maybe slightly less terrible + task.options = ['--display-cop-names', '--display-style-guide', '--extra-details'] + end +end diff --git a/puppet-syntax.gemspec b/puppet-syntax.gemspec index 9599ca7..760f2e6 100644 --- a/puppet-syntax.gemspec +++ b/puppet-syntax.gemspec @@ -25,4 +25,9 @@ Gem::Specification.new do |spec| spec.add_development_dependency "pry" spec.add_development_dependency "rb-readline" + + spec.add_development_dependency 'rubocop', '~> 1.12.0' + spec.add_development_dependency 'rubocop-performance', '~> 1.10' + spec.add_development_dependency 'rubocop-rake', '~> 0.2' + spec.add_development_dependency 'rubocop-rspec', '>= 1.44' end