From 99d71862c11f83c4b25d9940c5d6819234f06f78 Mon Sep 17 00:00:00 2001 From: Joakim Antman Date: Mon, 14 Dec 2020 21:15:53 +0200 Subject: [PATCH] Enable rubocop locally and on ci --- .github/workflows/test.yml | 13 +++ .rubocop.yml | 27 +++--- .rubocop_todo.yml | 194 +++++++++++++++++++++++++++++++++++++ Gemfile | 2 + lib/jwt/jwk/rsa.rb | 2 +- lib/jwt/version.rb | 1 - spec/jwt/verify_spec.rb | 2 +- 7 files changed, 224 insertions(+), 17 deletions(-) create mode 100644 .rubocop_todo.yml diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 8cb569ee..f37d21ab 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -8,6 +8,19 @@ on: branches: - "*" jobs: + lint: + name: RuboCop + timeout-minutes: 30 + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - name: Set up Ruby + uses: ruby/setup-ruby@v1 + with: + ruby-version: "2.4" + bundler-cache: true + - name: Run RuboCop + run: bundle exec rubocop test: strategy: fail-fast: false diff --git a/.rubocop.yml b/.rubocop.yml index 854661cf..dbd8a04b 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -1,20 +1,15 @@ -AllCops: - Exclude: - - 'bin/**/*' - - 'db/**/*' - - 'config/**/*' - - 'script/**/*' +inherit_from: .rubocop_todo.yml -Style/AlignParameters: +Layout/AlignParameters: EnforcedStyle: with_fixed_indentation -Style/CaseIndentation: +Layout/CaseIndentation: EnforcedStyle: end Style/AsciiComments: Enabled: false -Style/IndentHash: +Layout/IndentHash: Enabled: false Style/CollectionMethods: @@ -39,7 +34,7 @@ Style/GuardClause: Style/IfUnlessModifier: Enabled: false -Style/SpaceInsideHashLiteralBraces: +Layout/SpaceInsideHashLiteralBraces: Enabled: false Style/Lambda: @@ -55,7 +50,7 @@ Metrics/AbcSize: Max: 20 Metrics/ClassLength: - Max: 100 + Max: 101 Metrics/ModuleLength: Max: 100 @@ -63,6 +58,10 @@ Metrics/ModuleLength: Metrics/LineLength: Enabled: false +Metrics/BlockLength: + Exclude: + - spec/**/*_spec.rb + Metrics/MethodLength: Max: 15 @@ -75,10 +74,10 @@ Lint/EndAlignment: Style/FormatString: Enabled: false -Style/MultilineMethodCallIndentation: +Layout/MultilineMethodCallIndentation: EnforcedStyle: indented -Style/MultilineOperationIndentation: +Layout/MultilineOperationIndentation: EnforcedStyle: indented Style/WordArray: @@ -87,7 +86,7 @@ Style/WordArray: Style/RedundantSelf: Enabled: false -Style/AlignHash: +Layout/AlignHash: Enabled: true EnforcedLastArgumentHashStyle: always_ignore diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml new file mode 100644 index 00000000..89ffe48d --- /dev/null +++ b/.rubocop_todo.yml @@ -0,0 +1,194 @@ +# This configuration was generated by +# `rubocop --auto-gen-config` +# on 2020-12-14 21:03:32 +0200 using RuboCop version 0.52.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: 2 +# Cop supports --auto-correct. +# Configuration parameters: Include, TreatCommentsAsGroupSeparators. +# Include: **/*.gemspec +Gemspec/OrderedDependencies: + Exclude: + - 'ruby-jwt.gemspec' + +# Offense count: 1 +# Cop supports --auto-correct. +Layout/EmptyLines: + Exclude: + - 'spec/integration/readme_examples_spec.rb' + +# Offense count: 1 +# Cop supports --auto-correct. +# Configuration parameters: EnforcedStyle. +# SupportedStyles: empty_lines, no_empty_lines +Layout/EmptyLinesAroundBlockBody: + Exclude: + - 'spec/jwt_spec.rb' + +# Offense count: 1 +# Cop supports --auto-correct. +# Configuration parameters: AllowForAlignment, ForceEqualSignAlignment. +Layout/ExtraSpacing: + Exclude: + - 'spec/jwk_spec.rb' + +# Offense count: 2 +# Cop supports --auto-correct. +# Configuration parameters: EnforcedStyle. +# SupportedStyles: normal, rails +Layout/IndentationConsistency: + Exclude: + - 'spec/jwt_spec.rb' + +# Offense count: 1 +# Cop supports --auto-correct. +# Configuration parameters: Width, IgnoredPatterns. +Layout/IndentationWidth: + Exclude: + - 'spec/jwt_spec.rb' + +# Offense count: 3 +# Cop supports --auto-correct. +Layout/SpaceAfterComma: + Exclude: + - 'spec/jwt_spec.rb' + +# Offense count: 2 +# Cop supports --auto-correct. +# Configuration parameters: EnforcedStyle, EnforcedStyleForEmptyBraces. +# SupportedStyles: space, no_space +# SupportedStylesForEmptyBraces: space, no_space +Layout/SpaceBeforeBlockBraces: + Exclude: + - 'spec/jwk/ec_spec.rb' + - 'spec/jwt/verify_spec.rb' + +# Offense count: 1 +# Cop supports --auto-correct. +# Configuration parameters: EnforcedStyle, EnforcedStyleForEmptyBraces, SpaceBeforeBlockParameters. +# SupportedStyles: space, no_space +# SupportedStylesForEmptyBraces: space, no_space +Layout/SpaceInsideBlockBraces: + Exclude: + - 'spec/jwt/verify_spec.rb' + +# Offense count: 1 +# Cop supports --auto-correct. +# Configuration parameters: EnforcedStyle. +# SupportedStyles: final_newline, final_blank_line +Layout/TrailingBlankLines: + Exclude: + - 'bin/console.rb' + +# Offense count: 3 +# Cop supports --auto-correct. +# Configuration parameters: IgnoreEmptyBlocks, AllowUnusedKeywordArguments. +Lint/UnusedBlockArgument: + Exclude: + - 'spec/jwk/decode_with_jwk_spec.rb' + - 'spec/jwk/ec_spec.rb' + - 'spec/jwt/verify_spec.rb' + +# Offense count: 1 +# Configuration parameters: CountComments. +Metrics/ClassLength: + Max: 101 + +# Offense count: 1 +Metrics/CyclomaticComplexity: + Max: 7 + +# Offense count: 1 +# Configuration parameters: CountComments. +Metrics/ModuleLength: + Max: 180 + +# Offense count: 1 +Metrics/PerceivedComplexity: + Max: 8 + +# Offense count: 1 +# Cop supports --auto-correct. +# Configuration parameters: MaxKeyValuePairs. +Performance/RedundantMerge: + Exclude: + - 'spec/jwt_spec.rb' + +# Offense count: 1 +# Cop supports --auto-correct. +# Configuration parameters: InverseMethods, InverseBlocks. +Style/InverseMethods: + Exclude: + - 'spec/jwk/ec_spec.rb' + +# Offense count: 2 +# Cop supports --auto-correct. +Style/MethodCallWithoutArgsParentheses: + Exclude: + - 'spec/jwt_spec.rb' + +# Offense count: 1 +# Configuration parameters: EnforcedStyle. +# SupportedStyles: module_function, extend_self +Style/ModuleFunction: + Exclude: + - 'lib/jwt/signature.rb' + +# Offense count: 1 +# Cop supports --auto-correct. +Style/MultilineIfModifier: + Exclude: + - 'spec/integration/readme_examples_spec.rb' + +# Offense count: 1 +# Cop supports --auto-correct. +Style/MutableConstant: + Exclude: + - 'lib/jwt/version.rb' + +# Offense count: 1 +# Cop supports --auto-correct. +# Configuration parameters: Strict. +Style/NumericLiterals: + MinDigits: 6 + +# Offense count: 1 +# Cop supports --auto-correct. +Style/ParallelAssignment: + Exclude: + - 'spec/integration/readme_examples_spec.rb' + +# Offense count: 11 +# Cop supports --auto-correct. +# Configuration parameters: EnforcedStyle, ConsistentQuotesInMultiline. +# SupportedStyles: single_quotes, double_quotes +Style/StringLiterals: + Exclude: + - 'bin/console.rb' + - 'spec/jwk/ec_spec.rb' + - 'spec/jwk/rsa_spec.rb' + - 'spec/jwk_spec.rb' + - 'spec/jwt_spec.rb' + +# Offense count: 1 +# Cop supports --auto-correct. +# Configuration parameters: EnforcedStyleForMultiline. +# SupportedStylesForMultiline: comma, consistent_comma, no_comma +Style/TrailingCommaInArguments: + Exclude: + - 'spec/jwt_spec.rb' + +# Offense count: 1 +# Cop supports --auto-correct. +Style/UnlessElse: + Exclude: + - 'spec/jwt_spec.rb' + +# Offense count: 163 +# Configuration parameters: AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives, IgnoredPatterns. +# URISchemes: http, https +Metrics/LineLength: + Max: 420 diff --git a/Gemfile b/Gemfile index fa75df15..438636bb 100644 --- a/Gemfile +++ b/Gemfile @@ -1,3 +1,5 @@ source 'https://rubygems.org' gemspec + +gem 'rubocop', '~> 0.52.0' # Same as codeclimate default diff --git a/lib/jwt/jwk/rsa.rb b/lib/jwt/jwk/rsa.rb index bd66d509..f6d0ab1f 100644 --- a/lib/jwt/jwk/rsa.rb +++ b/lib/jwt/jwk/rsa.rb @@ -90,7 +90,7 @@ def populate_key(rsa_key, rsa_parameters) rsa_key end else - def populate_key(rsa_key, rsa_parameters) # rubocop:disable Metrics/CyclomaticComplexity + def populate_key(rsa_key, rsa_parameters) rsa_key.n = rsa_parameters[:n] rsa_key.e = rsa_parameters[:e] rsa_key.d = rsa_parameters[:d] if rsa_parameters[:d] diff --git a/lib/jwt/version.rb b/lib/jwt/version.rb index d6856190..9c8061fe 100644 --- a/lib/jwt/version.rb +++ b/lib/jwt/version.rb @@ -1,4 +1,3 @@ -# encoding: utf-8 # frozen_string_literal: true # Moments version builder module diff --git a/spec/jwt/verify_spec.rb b/spec/jwt/verify_spec.rb index ef8e3cf9..960fdcd2 100644 --- a/spec/jwt/verify_spec.rb +++ b/spec/jwt/verify_spec.rb @@ -3,7 +3,7 @@ require 'spec_helper' require 'jwt/verify' -module JWT +module JWT # rubocop:disable Metrics/ModuleLength RSpec.describe Verify do let(:base_payload) { { 'user_id' => 'some@user.tld' } } let(:options) { { leeway: 0 } }