From 760a2707ea9ea3f86ed8004f62c3ad420ced9b79 Mon Sep 17 00:00:00 2001 From: Tim Meusel Date: Fri, 17 Feb 2023 08:41:18 +0100 Subject: [PATCH 1/3] Enable RuboCop in CI --- .github/workflows/test.yml | 3 +- .rubocop.yml | 10 + .rubocop_todo.yml | 1054 ++++++++++++++++++++++++++++++++++++ Gemfile | 8 +- Rakefile | 12 + test/test-suite | 2 +- 6 files changed, 1083 insertions(+), 6 deletions(-) create mode 100644 .rubocop.yml create mode 100644 .rubocop_todo.yml diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 90b0fb0f..58b9857c 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -17,6 +17,7 @@ jobs: - ruby: truffleruby+graalvm - ruby: jruby - ruby: "2.5" + rake_task: "rubocop test" - ruby: "2.6" - ruby: "2.7" - ruby: "3.0" @@ -32,6 +33,6 @@ jobs: ruby-version: ${{ matrix.ruby }} bundler-cache: true - name: Run tests - run: bundle exec rake + run: bundle exec rake ${{ matrix.rake_task }} - name: Build gem run: gem build *.gemspec diff --git a/.rubocop.yml b/.rubocop.yml new file mode 100644 index 00000000..e5ddcbef --- /dev/null +++ b/.rubocop.yml @@ -0,0 +1,10 @@ +--- +inherit_from: .rubocop_todo.yml + +require: + - rubocop-rake + - rubocop-rspec + - rubocop-performance +AllCops: + TargetRubyVersion: 2.5 + NewCops: enable diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml new file mode 100644 index 00000000..16c6288a --- /dev/null +++ b/.rubocop_todo.yml @@ -0,0 +1,1054 @@ +# This configuration was generated by +# `rubocop --auto-gen-config` +# on 2023-02-17 07:55:34 UTC using RuboCop version 1.11.0. +# 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: 3 +# Cop supports --auto-correct. +# Configuration parameters: TreatCommentsAsGroupSeparators, ConsiderPunctuation, Include. +# Include: **/*.gemfile, **/Gemfile, **/gems.rb +Bundler/OrderedGems: + Exclude: + - 'Gemfile' + +# Offense count: 2 +# Cop supports --auto-correct. +# Configuration parameters: TreatCommentsAsGroupSeparators, ConsiderPunctuation, Include. +# Include: **/*.gemspec +Gemspec/OrderedDependencies: + Exclude: + - 'json-schema.gemspec' + +# Offense count: 2 +# Cop supports --auto-correct. +# Configuration parameters: EnforcedStyle, IndentationWidth. +# SupportedStyles: with_first_argument, with_fixed_indentation +Layout/ArgumentAlignment: + Exclude: + - 'test/common_test_suite_test.rb' + +# Offense count: 2 +# Cop supports --auto-correct. +Layout/CommentIndentation: + Exclude: + - 'lib/json-schema/util/uuid.rb' + +# Offense count: 2 +# Cop supports --auto-correct. +# Configuration parameters: EnforcedStyle. +# SupportedStyles: leading, trailing +Layout/DotPosition: + Exclude: + - 'test/common_test_suite_test.rb' + - 'test/schema_reader_test.rb' + +# Offense count: 18 +# Cop supports --auto-correct. +Layout/EmptyLineAfterGuardClause: + Exclude: + - 'lib/json-schema/attributes/additionalitems.rb' + - 'lib/json-schema/attributes/dependencies.rb' + - 'lib/json-schema/attributes/disallow.rb' + - 'lib/json-schema/attributes/format.rb' + - 'lib/json-schema/attributes/formats/date.rb' + - 'lib/json-schema/attributes/formats/date_time.rb' + - 'lib/json-schema/attributes/formats/date_time_v4.rb' + - 'lib/json-schema/attributes/formats/uri.rb' + - 'lib/json-schema/attributes/items.rb' + - 'lib/json-schema/attributes/patternproperties.rb' + - 'lib/json-schema/attributes/required.rb' + - 'lib/json-schema/attributes/type.rb' + - 'lib/json-schema/util/uuid.rb' + - 'lib/json-schema/validator.rb' + +# Offense count: 5 +# Cop supports --auto-correct. +Layout/EmptyLineAfterMagicComment: + Exclude: + - 'test/custom_format_test.rb' + - 'test/draft3_test.rb' + - 'test/draft4_test.rb' + - 'test/draft6_test.rb' + - 'test/uri_parsing_test.rb' + +# Offense count: 9 +# Cop supports --auto-correct. +# Configuration parameters: EmptyLineBetweenMethodDefs, EmptyLineBetweenClassDefs, EmptyLineBetweenModuleDefs, AllowAdjacentOneLineDefs, NumberOfEmptyLines. +Layout/EmptyLineBetweenDefs: + Exclude: + - 'test/draft1_test.rb' + - 'test/draft3_test.rb' + - 'test/draft4_test.rb' + - 'test/full_validation_test.rb' + - 'test/schema_validation_test.rb' + +# Offense count: 28 +# Cop supports --auto-correct. +Layout/EmptyLines: + Exclude: + - 'lib/json-schema/attributes/oneof.rb' + - 'lib/json-schema/util/uuid.rb' + - 'lib/json-schema/validator.rb' + - 'test/bad_schema_ref_test.rb' + - 'test/draft1_test.rb' + - 'test/draft2_test.rb' + - 'test/draft3_test.rb' + - 'test/draft4_test.rb' + - 'test/full_validation_test.rb' + - 'test/schema_validation_test.rb' + - 'test/support/enum_validation.rb' + +# Offense count: 2 +# Cop supports --auto-correct. +# Configuration parameters: EnforcedStyle. +# SupportedStyles: around, only_before +Layout/EmptyLinesAroundAccessModifier: + Exclude: + - 'lib/json-schema/schema/reader.rb' + +# Offense count: 30 +# Cop supports --auto-correct. +# Configuration parameters: EnforcedStyle. +# SupportedStyles: empty_lines, empty_lines_except_namespace, empty_lines_special, no_empty_lines, beginning_only, ending_only +Layout/EmptyLinesAroundClassBody: + Enabled: false + +# Offense count: 6 +# Cop supports --auto-correct. +Layout/EmptyLinesAroundMethodBody: + Exclude: + - 'lib/json-schema/validator.rb' + - 'test/draft1_test.rb' + - 'test/draft3_test.rb' + - 'test/draft4_test.rb' + - 'test/one_of_test.rb' + +# Offense count: 2 +# Cop supports --auto-correct. +# Configuration parameters: EnforcedStyle. +# SupportedStyles: empty_lines, empty_lines_except_namespace, empty_lines_special, no_empty_lines +Layout/EmptyLinesAroundModuleBody: + Exclude: + - 'lib/json-schema/validator.rb' + - 'test/support/strict_validation.rb' + +# Offense count: 2 +# Cop supports --auto-correct. +# Configuration parameters: AllowForAlignment, AllowBeforeTrailingComments, ForceEqualSignAlignment. +Layout/ExtraSpacing: + Exclude: + - 'lib/json-schema/util/uuid.rb' + +# Offense count: 1 +# Cop supports --auto-correct. +# Configuration parameters: EnforcedStyle, IndentationWidth. +# SupportedStyles: consistent, consistent_relative_to_receiver, special_for_inner_method_call, special_for_inner_method_call_in_parentheses +Layout/FirstArgumentIndentation: + Exclude: + - 'test/load_ref_schema_test.rb' + +# Offense count: 3 +# Cop supports --auto-correct. +# Configuration parameters: EnforcedStyle, IndentationWidth. +# SupportedStyles: special_inside_parentheses, consistent, align_brackets +Layout/FirstArrayElementIndentation: + Exclude: + - 'lib/json-schema/util/uuid.rb' + - 'test/draft4_test.rb' + +# Offense count: 1 +# Cop supports --auto-correct. +# Configuration parameters: EnforcedStyle, IndentationWidth. +# SupportedStyles: special_inside_parentheses, consistent, align_braces +Layout/FirstHashElementIndentation: + Exclude: + - 'test/draft3_test.rb' + +# Offense count: 28 +# Cop supports --auto-correct. +# Configuration parameters: AllowMultipleStyles, EnforcedHashRocketStyle, EnforcedColonStyle, EnforcedLastArgumentHashStyle. +# SupportedHashRocketStyles: key, separator, table +# SupportedColonStyles: key, separator, table +# SupportedLastArgumentHashStyles: always_inspect, always_ignore, ignore_implicit, ignore_explicit +Layout/HashAlignment: + Exclude: + - 'test/draft4_test.rb' + - 'test/support/string_validation.rb' + - 'test/support/type_validation.rb' + - 'test/uri_parsing_test.rb' + +# Offense count: 218 +# Cop supports --auto-correct. +# Configuration parameters: IndentationWidth, EnforcedStyle. +# SupportedStyles: spaces, tabs +Layout/IndentationStyle: + Exclude: + - 'lib/json-schema/util/uuid.rb' + +# Offense count: 65 +# Cop supports --auto-correct. +# Configuration parameters: Width, IgnoredPatterns. +Layout/IndentationWidth: + Exclude: + - 'lib/json-schema/util/uuid.rb' + +# Offense count: 1 +# Cop supports --auto-correct. +# Configuration parameters: EnforcedStyle. +# SupportedStyles: symmetrical, new_line, same_line +Layout/MultilineHashBraceLayout: + Exclude: + - 'test/draft4_test.rb' + +# Offense count: 1 +# Cop supports --auto-correct. +# Configuration parameters: EnforcedStyle. +# SupportedStyles: symmetrical, new_line, same_line +Layout/MultilineMethodCallBraceLayout: + Exclude: + - 'test/common_test_suite_test.rb' + +# Offense count: 3 +# Cop supports --auto-correct. +# Configuration parameters: EnforcedStyle, IndentationWidth. +# SupportedStyles: aligned, indented +Layout/MultilineOperationIndentation: + Exclude: + - 'lib/json-schema/attributes/properties.rb' + +# Offense count: 276 +# Cop supports --auto-correct. +Layout/SpaceAfterComma: + Enabled: false + +# Offense count: 18 +# Cop supports --auto-correct. +# Configuration parameters: EnforcedStyle. +# SupportedStyles: space, no_space +Layout/SpaceAroundEqualsInParameterDefault: + Exclude: + - 'lib/json-schema/schema.rb' + - 'lib/json-schema/util/uuid.rb' + - 'lib/json-schema/validator.rb' + +# Offense count: 48 +# Cop supports --auto-correct. +# Configuration parameters: AllowForAlignment, EnforcedStyleForExponentOperator. +# SupportedStylesForExponentOperator: space, no_space +Layout/SpaceAroundOperators: + Exclude: + - 'Gemfile' + - 'lib/json-schema/util/uuid.rb' + - 'test/common_test_suite_test.rb' + - 'test/draft4_test.rb' + - 'test/full_validation_test.rb' + - 'test/uri_parsing_test.rb' + +# Offense count: 11 +# Cop supports --auto-correct. +# Configuration parameters: EnforcedStyle, EnforcedStyleForEmptyBraces. +# SupportedStyles: space, no_space +# SupportedStylesForEmptyBraces: space, no_space +Layout/SpaceBeforeBlockBraces: + Exclude: + - 'lib/json-schema/errors/validation_error.rb' + - 'lib/json-schema/validator.rb' + +# Offense count: 13 +# Cop supports --auto-correct. +# Configuration parameters: EnforcedStyle, EnforcedStyleForEmptyBraces, SpaceBeforeBlockParameters. +# SupportedStyles: space, no_space +# SupportedStylesForEmptyBraces: space, no_space +Layout/SpaceInsideBlockBraces: + Exclude: + - 'lib/json-schema.rb' + - 'lib/json-schema/errors/validation_error.rb' + - 'lib/json-schema/validator.rb' + +# Offense count: 1103 +# Cop supports --auto-correct. +# Configuration parameters: EnforcedStyle, EnforcedStyleForEmptyBraces. +# SupportedStyles: space, no_space, compact +# SupportedStylesForEmptyBraces: space, no_space +Layout/SpaceInsideHashLiteralBraces: + Enabled: false + +# Offense count: 2 +# Cop supports --auto-correct. +# Configuration parameters: EnforcedStyle, EnforcedStyleForEmptyBrackets. +# SupportedStyles: space, no_space +# SupportedStylesForEmptyBrackets: space, no_space +Layout/SpaceInsideReferenceBrackets: + Exclude: + - 'json-schema.gemspec' + +# Offense count: 1 +# Cop supports --auto-correct. +# Configuration parameters: EnforcedStyle. +# SupportedStyles: final_newline, final_blank_line +Layout/TrailingEmptyLines: + Exclude: + - 'lib/json-schema/util/uuid.rb' + +# Offense count: 2 +# Cop supports --auto-correct. +# Configuration parameters: AllowInHeredoc. +Layout/TrailingWhitespace: + Exclude: + - 'lib/json-schema/util/uuid.rb' + +# Offense count: 1 +Lint/AmbiguousBlockAssociation: + Exclude: + - 'lib/json-schema/errors/validation_error.rb' + +# Offense count: 4 +# Configuration parameters: AllowSafeAssignment. +Lint/AssignmentInCondition: + Exclude: + - 'lib/json-schema/attributes/additionalproperties.rb' + - 'lib/json-schema/attributes/disallow.rb' + - 'lib/json-schema/validator.rb' + +# Offense count: 2 +Lint/FloatComparison: + Exclude: + - 'lib/json-schema/attributes/divisibleby.rb' + +# Offense count: 6 +Lint/ImplicitStringConcatenation: + Exclude: + - 'test/all_of_ref_schema_test.rb' + - 'test/any_of_ref_schema_test.rb' + - 'test/one_of_test.rb' + +# Offense count: 1 +Lint/MissingSuper: + Exclude: + - 'lib/json-schema/attributes/formats/custom.rb' + +# Offense count: 2 +# Cop supports --auto-correct. +Lint/NonDeterministicRequireOrder: + Exclude: + - 'lib/json-schema.rb' + - 'test/support/test_helper.rb' + +# Offense count: 1 +# Cop supports --auto-correct. +Lint/RedundantRequireStatement: + Exclude: + - 'lib/json-schema/validator.rb' + +# Offense count: 3 +# Cop supports --auto-correct. +Lint/RedundantStringCoercion: + Exclude: + - 'lib/json-schema/attributes/extends.rb' + - 'lib/json-schema/attributes/ref.rb' + +# Offense count: 1 +# Cop supports --auto-correct. +Lint/ScriptPermission: + Exclude: + - 'lib/json-schema/util/uuid.rb' + +# Offense count: 2 +# Configuration parameters: AllowComments. +Lint/SuppressedException: + Exclude: + - 'Rakefile' + - 'lib/json-schema/validator.rb' + +# Offense count: 3 +# Cop supports --auto-correct. +Lint/TripleQuotes: + Exclude: + - 'test/all_of_ref_schema_test.rb' + - 'test/any_of_ref_schema_test.rb' + - 'test/one_of_test.rb' + +# Offense count: 10 +# Cop supports --auto-correct. +# Configuration parameters: IgnoreEmptyBlocks, AllowUnusedKeywordArguments. +Lint/UnusedBlockArgument: + Exclude: + - 'lib/json-schema/attributes/patternproperties.rb' + - 'lib/json-schema/attributes/properties.rb' + - 'lib/json-schema/attributes/required.rb' + - 'lib/json-schema/schema.rb' + - 'lib/json-schema/schema/validator.rb' + - 'lib/json-schema/validator.rb' + +# Offense count: 24 +# Cop supports --auto-correct. +# Configuration parameters: AllowUnusedKeywordArguments, IgnoreEmptyMethods, IgnoreNotImplementedMethods. +Lint/UnusedMethodArgument: + Enabled: false + +# Offense count: 52 +# Configuration parameters: IgnoredMethods, CountRepeatedAttributes. +Metrics/AbcSize: + Max: 60 + +# Offense count: 2 +# Configuration parameters: CountComments, CountAsOne, ExcludedMethods, IgnoredMethods. +# IgnoredMethods: refine +Metrics/BlockLength: + Max: 37 + +# Offense count: 6 +# Configuration parameters: CountBlocks. +Metrics/BlockNesting: + Max: 4 + +# Offense count: 9 +# Configuration parameters: CountComments, CountAsOne. +Metrics/ClassLength: + Max: 561 + +# Offense count: 17 +# Configuration parameters: IgnoredMethods. +Metrics/CyclomaticComplexity: + Max: 21 + +# Offense count: 145 +# Configuration parameters: CountComments, CountAsOne, ExcludedMethods, IgnoredMethods. +Metrics/MethodLength: + Max: 73 + +# Offense count: 38 +# Configuration parameters: CountKeywordArgs, MaxOptionalParameters. +Metrics/ParameterLists: + Max: 8 + +# Offense count: 15 +# Configuration parameters: IgnoredMethods. +Metrics/PerceivedComplexity: + Max: 20 + +# Offense count: 1 +Naming/AccessorMethodName: + Exclude: + - 'test/caching_test.rb' + +# Offense count: 2 +# Configuration parameters: AllowedNames. +# AllowedNames: module_parent +Naming/ClassAndModuleCamelCase: + Exclude: + - 'test/support/enum_validation.rb' + +# Offense count: 6 +# 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/json-schema.rb' + - 'lib/json-schema/validators/hyper-draft1.rb' + - 'lib/json-schema/validators/hyper-draft2.rb' + - 'lib/json-schema/validators/hyper-draft3.rb' + - 'lib/json-schema/validators/hyper-draft4.rb' + - 'lib/json-schema/validators/hyper-draft6.rb' + +# Offense count: 18 +# Configuration parameters: MinNameLength, AllowNamesEndingInNumbers, AllowedNames, ForbiddenNames. +# AllowedNames: at, by, db, id, in, io, ip, of, on, os, pp, to +Naming/MethodParameterName: + Exclude: + - 'lib/json-schema/attributes/extends.rb' + - 'lib/json-schema/attributes/ref.rb' + - 'lib/json-schema/util/uuid.rb' + - 'lib/json-schema/validator.rb' + +# Offense count: 18 +# Configuration parameters: EnforcedStyle, CheckMethodNames, CheckSymbols, AllowedIdentifiers. +# SupportedStyles: snake_case, normalcase, non_integer +# AllowedIdentifiers: capture3, iso8601, rfc1123_date, rfc822, rfc2822, rfc3339 +Naming/VariableNumber: + Exclude: + - 'test/all_of_ref_schema_test.rb' + - 'test/any_of_ref_schema_test.rb' + - 'test/custom_format_test.rb' + - 'test/one_of_test.rb' + +# Offense count: 1 +# Cop supports --auto-correct. +# Configuration parameters: SafeMultiline. +Performance/DeletePrefix: + Exclude: + - 'lib/json-schema/util/uuid.rb' + +# Offense count: 1 +# Cop supports --auto-correct. +Performance/RangeInclude: + Exclude: + - 'lib/json-schema/util/uuid.rb' + +# Offense count: 1 +# Cop supports --auto-correct. +# Configuration parameters: AutoCorrect. +Performance/StringInclude: + Exclude: + - 'test/min_items_test.rb' + +# Offense count: 1 +# Cop supports --auto-correct. +Performance/UnfreezeString: + Exclude: + - 'test/type_attribute_test.rb' + +# Offense count: 1 +Rake/Desc: + Exclude: + - 'Rakefile' + +# Offense count: 1 +Security/MarshalLoad: + Exclude: + - 'lib/json-schema/util/uuid.rb' + +# Offense count: 4 +Security/Open: + Exclude: + - 'lib/json-schema/schema/reader.rb' + - 'lib/json-schema/util/uuid.rb' + - 'lib/json-schema/validator.rb' + +# Offense count: 1 +# Cop supports --auto-correct. +Security/YAMLLoad: + Exclude: + - 'json-schema.gemspec' + +# Offense count: 4 +# Cop supports --auto-correct. +# Configuration parameters: EnforcedStyle. +# SupportedStyles: prefer_alias, prefer_alias_method +Style/Alias: + Exclude: + - 'lib/json-schema/util/uuid.rb' + +# Offense count: 4 +# Cop supports --auto-correct. +# Configuration parameters: EnforcedStyle. +# SupportedStyles: percent_q, bare_percent +Style/BarePercentLiterals: + Exclude: + - 'test/files_test.rb' + +# Offense count: 3 +# Cop supports --auto-correct. +# Configuration parameters: EnforcedStyle, ProceduralMethods, FunctionalMethods, IgnoredMethods, AllowBracesOnProceduralOneLiners, BracesRequiredMethods. +# SupportedStyles: line_count_based, semantic, braces_for_chaining, always_braces +# ProceduralMethods: benchmark, bm, bmbm, create, each_with_object, measure, new, realtime, tap, with_object +# FunctionalMethods: let, let!, subject, watch +# IgnoredMethods: lambda, proc, it +Style/BlockDelimiters: + Exclude: + - 'lib/json-schema/attribute.rb' + - 'lib/json-schema/attributes/enum.rb' + +# Offense count: 2 +# Cop supports --auto-correct. +Style/CaseLikeIf: + Exclude: + - 'lib/json-schema/validator.rb' + +# Offense count: 1 +# Cop supports --auto-correct. +# Configuration parameters: EnforcedStyle. +# SupportedStyles: nested, compact +Style/ClassAndModuleChildren: + Exclude: + - 'test/support/test_helper.rb' + +# Offense count: 2 +# Cop supports --auto-correct. +# Configuration parameters: EnforcedStyle. +# SupportedStyles: is_a?, kind_of? +Style/ClassCheck: + Exclude: + - 'lib/json-schema/attribute.rb' + - 'lib/json-schema/schema.rb' + +# Offense count: 23 +Style/ClassVars: + Exclude: + - 'lib/json-schema/validator.rb' + +# Offense count: 4 +# Cop supports --auto-correct. +Style/ColonMethodCall: + Exclude: + - 'lib/json-schema.rb' + - 'lib/json-schema/validator.rb' + +# Offense count: 2 +# Cop supports --auto-correct. +Style/CommentedKeyword: + Exclude: + - 'lib/json-schema/util/uuid.rb' + +# Offense count: 5 +# Cop supports --auto-correct. +# Configuration parameters: EnforcedStyle, SingleLineConditionsOnly, IncludeTernaryExpressions. +# SupportedStyles: assign_to_condition, assign_inside_condition +Style/ConditionalAssignment: + Exclude: + - 'lib/json-schema/attributes/oneof.rb' + - 'lib/json-schema/attributes/ref.rb' + - 'lib/json-schema/attributes/type.rb' + - 'lib/json-schema/schema.rb' + - 'lib/json-schema/validator.rb' + +# Offense count: 1 +# Cop supports --auto-correct. +Style/DefWithParentheses: + Exclude: + - 'lib/json-schema/schema/validator.rb' + +# Offense count: 70 +Style/Documentation: + Enabled: false + +# Offense count: 1 +# Cop supports --auto-correct. +Style/EachWithObject: + Exclude: + - 'lib/json-schema/errors/validation_error.rb' + +# Offense count: 2 +# Cop supports --auto-correct. +Style/EmptyLiteral: + Exclude: + - 'test/type_attribute_test.rb' + +# Offense count: 1 +# Cop supports --auto-correct. +# Configuration parameters: EnforcedStyle. +# SupportedStyles: compact, expanded +Style/EmptyMethod: + Exclude: + - 'lib/json-schema/attribute.rb' + +# Offense count: 5 +# Cop supports --auto-correct. +Style/Encoding: + Exclude: + - 'test/custom_format_test.rb' + - 'test/draft3_test.rb' + - 'test/draft4_test.rb' + - 'test/draft6_test.rb' + - 'test/uri_parsing_test.rb' + +# Offense count: 40 +# Cop supports --auto-correct. +Style/ExpandPathArguments: + Enabled: false + +# Offense count: 2 +# Cop supports --auto-correct. +# Configuration parameters: EnforcedStyle. +# SupportedStyles: format, sprintf, percent +Style/FormatString: + Exclude: + - 'lib/json-schema/util/uuid.rb' + +# Offense count: 21 +# Configuration parameters: MaxUnannotatedPlaceholdersAllowed, IgnoredMethods. +# SupportedStyles: annotated, template, unannotated +Style/FormatStringToken: + EnforcedStyle: unannotated + +# Offense count: 118 +# Cop supports --auto-correct. +# Configuration parameters: EnforcedStyle. +# SupportedStyles: always, always_true, never +Style/FrozenStringLiteralComment: + Enabled: false + +# Offense count: 2 +# Cop supports --auto-correct. +Style/GlobalStdStream: + Exclude: + - 'Rakefile' + +# Offense count: 26 +# Configuration parameters: MinBodyLength. +Style/GuardClause: + Enabled: false + +# Offense count: 1 +# Cop supports --auto-correct. +# Configuration parameters: AllowSplatArgument. +Style/HashConversion: + Exclude: + - 'lib/json-schema/schema.rb' + +# Offense count: 1 +# Cop supports --auto-correct. +Style/HashEachMethods: + Exclude: + - 'test/support/type_validation.rb' + +# Offense count: 333 +# Cop supports --auto-correct. +# Configuration parameters: UseHashRocketsWithSymbolValues, PreferHashRocketsForNonAlnumEndingSymbols. +# SupportedStyles: ruby19, hash_rockets, no_mixed_keys, ruby19_no_mixed_keys +Style/HashSyntax: + EnforcedStyle: hash_rockets + +# Offense count: 19 +# Cop supports --auto-correct. +Style/IfUnlessModifier: + Exclude: + - 'Rakefile' + - 'lib/json-schema/attributes/additionalproperties.rb' + - 'lib/json-schema/attributes/not.rb' + - 'lib/json-schema/attributes/ref.rb' + - 'lib/json-schema/schema.rb' + - 'lib/json-schema/schema/validator.rb' + - 'lib/json-schema/validator.rb' + +# Offense count: 1 +# Cop supports --auto-correct. +# Configuration parameters: AllowedMethods. +# AllowedMethods: nonzero? +Style/IfWithBooleanLiteralBranches: + Exclude: + - 'lib/json-schema/validator.rb' + +# Offense count: 6 +# Cop supports --auto-correct. +# Configuration parameters: EnforcedStyle. +# SupportedStyles: line_count_dependent, lambda, literal +Style/Lambda: + Exclude: + - 'lib/json-schema/validator.rb' + - 'test/custom_format_test.rb' + +# Offense count: 14 +# Cop supports --auto-correct. +# Configuration parameters: EnforcedStyle. +# SupportedStyles: require_parentheses, require_no_parentheses, require_no_parentheses_except_multiline +Style/MethodDefParentheses: + Exclude: + - 'lib/json-schema/util/uuid.rb' + - 'lib/json-schema/validator.rb' + +# Offense count: 1 +Style/MultilineBlockChain: + Exclude: + - 'lib/json-schema/attribute.rb' + +# Offense count: 2 +# Cop supports --auto-correct. +Style/MultilineIfThen: + Exclude: + - 'lib/json-schema/util/uuid.rb' + +# Offense count: 3 +# Cop supports --auto-correct. +Style/MultilineWhenThen: + Exclude: + - 'lib/json-schema/schema.rb' + +# Offense count: 11 +# Cop supports --auto-correct. +# Configuration parameters: EnforcedStyle. +# SupportedStyles: literals, strict +Style/MutableConstant: + Exclude: + - 'lib/json-schema/attribute.rb' + - 'lib/json-schema/attributes/formats/date.rb' + - 'lib/json-schema/attributes/formats/date_time.rb' + - 'lib/json-schema/attributes/formats/time.rb' + - 'lib/json-schema/errors/validation_error.rb' + - 'lib/json-schema/util/uri.rb' + - 'lib/json-schema/util/uuid.rb' + - 'test/extends_nested_test.rb' + - 'test/schema_reader_test.rb' + - 'test/support/type_validation.rb' + +# Offense count: 11 +# Cop supports --auto-correct. +# Configuration parameters: EnforcedStyle. +# SupportedStyles: both, prefix, postfix +Style/NegatedIf: + Exclude: + - 'lib/json-schema/attributes/anyof.rb' + - 'lib/json-schema/attributes/extends.rb' + - 'lib/json-schema/attributes/oneof.rb' + - 'lib/json-schema/attributes/required.rb' + - 'lib/json-schema/attributes/type.rb' + - 'lib/json-schema/attributes/type_v4.rb' + - 'lib/json-schema/errors/validation_error.rb' + - 'lib/json-schema/util/array_set.rb' + - 'lib/json-schema/util/uri.rb' + - 'lib/json-schema/validator.rb' + +# Offense count: 1 +# Cop supports --auto-correct. +Style/NegatedIfElseCondition: + Exclude: + - 'lib/json-schema/validator.rb' + +# Offense count: 2 +# Cop supports --auto-correct. +# Configuration parameters: EnforcedStyle, MinBodyLength. +# SupportedStyles: skip_modifier_ifs, always +Style/Next: + Exclude: + - 'lib/json-schema/attributes/ref.rb' + - 'lib/json-schema/validator.rb' + +# Offense count: 3 +# Cop supports --auto-correct. +# Configuration parameters: Strict. +Style/NumericLiterals: + MinDigits: 23 + +# Offense count: 11 +# Cop supports --auto-correct. +# Configuration parameters: EnforcedStyle, IgnoredMethods. +# SupportedStyles: predicate, comparison +Style/NumericPredicate: + Exclude: + - 'spec/**/*' + - 'lib/json-schema/attributes/allof.rb' + - 'lib/json-schema/attributes/anyof.rb' + - 'lib/json-schema/attributes/divisibleby.rb' + - 'lib/json-schema/attributes/oneof.rb' + - 'lib/json-schema/attributes/properties.rb' + - 'lib/json-schema/attributes/type.rb' + - 'lib/json-schema/errors/validation_error.rb' + - 'test/extended_schema_test.rb' + +# Offense count: 2 +# Configuration parameters: AllowedMethods. +# AllowedMethods: respond_to_missing? +Style/OptionalBooleanParameter: + Exclude: + - 'lib/json-schema/validator.rb' + +# Offense count: 3 +# Cop supports --auto-correct. +Style/ParallelAssignment: + Exclude: + - 'lib/json-schema/attributes/extends.rb' + - 'lib/json-schema/attributes/ref.rb' + +# Offense count: 4 +# Cop supports --auto-correct. +# Configuration parameters: PreferredDelimiters. +Style/PercentLiteralDelimiters: + Exclude: + - 'Rakefile' + - 'lib/json-schema/util/uri.rb' + - 'lib/json-schema/util/uuid.rb' + +# Offense count: 4 +# Cop supports --auto-correct. +# Configuration parameters: EnforcedStyle. +# SupportedStyles: lower_case_q, upper_case_q +Style/PercentQLiterals: + Exclude: + - 'test/files_test.rb' + +# Offense count: 10 +# Cop supports --auto-correct. +# Configuration parameters: EnforcedStyle. +# SupportedStyles: short, verbose +Style/PreferredHashMethods: + Exclude: + - 'lib/json-schema/attributes/dependencies.rb' + - 'lib/json-schema/attributes/properties.rb' + - 'lib/json-schema/attributes/properties_optional.rb' + - 'lib/json-schema/attributes/required.rb' + - 'lib/json-schema/schema/validator.rb' + +# Offense count: 13 +# Cop supports --auto-correct. +# Configuration parameters: EnforcedStyle, AllowedCompactTypes. +# SupportedStyles: compact, exploded +Style/RaiseArgs: + Exclude: + - 'lib/json-schema/attributes/ref.rb' + - 'lib/json-schema/util/uri.rb' + - 'lib/json-schema/validator.rb' + - 'test/custom_format_test.rb' + +# Offense count: 2 +# Cop supports --auto-correct. +Style/RedundantBegin: + Exclude: + - 'lib/json-schema/attributes/formats/custom.rb' + - 'lib/json-schema/validator.rb' + +# Offense count: 1 +# Cop supports --auto-correct. +Style/RedundantConditional: + Exclude: + - 'lib/json-schema/validator.rb' + +# Offense count: 4 +# Cop supports --auto-correct. +Style/RedundantPercentQ: + Exclude: + - 'test/files_test.rb' + +# Offense count: 1 +# Cop supports --auto-correct. +Style/RedundantRegexpEscape: + Exclude: + - 'lib/json-schema/attributes/formats/date_time.rb' + +# Offense count: 5 +# Cop supports --auto-correct. +# Configuration parameters: AllowMultipleReturnValues. +Style/RedundantReturn: + Exclude: + - 'lib/json-schema/util/uri.rb' + - 'lib/json-schema/util/uuid.rb' + - 'lib/json-schema/validator.rb' + +# Offense count: 15 +# Cop supports --auto-correct. +Style/RedundantSelf: + Exclude: + - 'lib/json-schema/util/array_set.rb' + - 'lib/json-schema/util/uuid.rb' + - 'lib/json-schema/validators/draft1.rb' + - 'lib/json-schema/validators/draft2.rb' + - 'lib/json-schema/validators/draft3.rb' + - 'lib/json-schema/validators/draft4.rb' + - 'lib/json-schema/validators/draft6.rb' + - 'lib/json-schema/validators/hyper-draft1.rb' + - 'lib/json-schema/validators/hyper-draft2.rb' + - 'lib/json-schema/validators/hyper-draft3.rb' + - 'lib/json-schema/validators/hyper-draft4.rb' + - 'lib/json-schema/validators/hyper-draft6.rb' + +# Offense count: 10 +# Cop supports --auto-correct. +# Configuration parameters: EnforcedStyle, AllowInnerSlashes. +# SupportedStyles: slashes, percent_r, mixed +Style/RegexpLiteral: + Exclude: + - 'lib/json-schema/util/uuid.rb' + - 'test/all_of_ref_schema_test.rb' + - 'test/any_of_ref_schema_test.rb' + - 'test/custom_format_test.rb' + - 'test/one_of_test.rb' + +# Offense count: 3 +# Cop supports --auto-correct. +# Configuration parameters: ConvertCodeThatCanStartToReturnNil, AllowedMethods. +# AllowedMethods: present?, blank?, presence, try, try! +Style/SafeNavigation: + Exclude: + - 'lib/json-schema/attributes/additionalproperties.rb' + - 'lib/json-schema/attributes/format.rb' + - 'lib/json-schema/schema.rb' + +# Offense count: 10 +# Cop supports --auto-correct. +Style/SelfAssignment: + Exclude: + - 'lib/json-schema/attributes/additionalproperties.rb' + - 'lib/json-schema/attributes/allof.rb' + - 'lib/json-schema/attributes/anyof.rb' + - 'lib/json-schema/attributes/oneof.rb' + - 'lib/json-schema/attributes/ref.rb' + - 'lib/json-schema/attributes/type.rb' + - 'lib/json-schema/util/uuid.rb' + +# Offense count: 2 +# Cop supports --auto-correct. +Style/StderrPuts: + Exclude: + - 'Rakefile' + +# Offense count: 4 +# Cop supports --auto-correct. +Style/StringConcatenation: + Exclude: + - 'lib/json-schema/attributes/ref.rb' + - 'lib/json-schema/util/uuid.rb' + - 'test/schema_reader_test.rb' + +# Offense count: 2208 +# Cop supports --auto-correct. +# Configuration parameters: EnforcedStyle, ConsistentQuotesInMultiline. +# SupportedStyles: single_quotes, double_quotes +Style/StringLiterals: + Enabled: false + +# Offense count: 7 +# Cop supports --auto-correct. +# Configuration parameters: MinSize. +# SupportedStyles: percent, brackets +Style/SymbolArray: + EnforcedStyle: brackets + +# Offense count: 3 +# Cop supports --auto-correct. +# Configuration parameters: AllowMethodsWithArguments, IgnoredMethods. +# IgnoredMethods: respond_to, define_method +Style/SymbolProc: + Exclude: + - 'lib/json-schema/errors/validation_error.rb' + - 'lib/json-schema/validator.rb' + +# Offense count: 3 +# Cop supports --auto-correct. +# Configuration parameters: EnforcedStyleForMultiline. +# SupportedStylesForMultiline: comma, consistent_comma, no_comma +Style/TrailingCommaInArrayLiteral: + Exclude: + - 'lib/json-schema/util/uuid.rb' + - 'test/support/test_helper.rb' + - 'test/uri_parsing_test.rb' + +# Offense count: 15 +# Cop supports --auto-correct. +# Configuration parameters: EnforcedStyleForMultiline. +# SupportedStylesForMultiline: comma, consistent_comma, no_comma +Style/TrailingCommaInHashLiteral: + Exclude: + - 'test/custom_format_test.rb' + - 'test/draft6_test.rb' + - 'test/full_validation_test.rb' + - 'test/one_of_test.rb' + +# Offense count: 1 +# Cop supports --auto-correct. +# Configuration parameters: AllowNamedUnderscoreVariables. +Style/TrailingUnderscoreVariable: + Exclude: + - 'lib/json-schema/attribute.rb' + +# Offense count: 25 +# Cop supports --auto-correct. +# Configuration parameters: WordRegex. +# SupportedStyles: percent, brackets +Style/WordArray: + EnforcedStyle: percent + MinSize: 3 + +# Offense count: 1 +# Cop supports --auto-correct. +Style/ZeroLengthPredicate: + Exclude: + - 'lib/json-schema/attributes/properties.rb' + +# Offense count: 74 +# Cop supports --auto-correct. +# Configuration parameters: AutoCorrect, AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives, IgnoredPatterns. +# URISchemes: http, https +Layout/LineLength: + Max: 235 diff --git a/Gemfile b/Gemfile index 81222954..4951d199 100644 --- a/Gemfile +++ b/Gemfile @@ -12,8 +12,8 @@ group :coverage, optional: ENV['COVERAGE']!='yes' do end group :tests do - gem 'rubocop', '~> 1.11.0' - gem 'rubocop-rspec', '~> 2.2.0' - gem 'rubocop-rake', '~> 0.5.1' - gem 'rubocop-performance', '~> 1.10.2' + gem 'rubocop', '~> 1.12.0' # newer version require Ruby 2.6 + gem 'rubocop-rspec', '~> 2.4.0' # newer version require Ruby 2.6 or rubocop 1.19 + gem 'rubocop-rake', '~> 0.6.0' # latest + gem 'rubocop-performance', '~> 1.13.0' # newer version requires Ruby 2.6 end diff --git a/Rakefile b/Rakefile index 26ede98f..a906a721 100644 --- a/Rakefile +++ b/Rakefile @@ -65,6 +65,18 @@ end task update: [:update_common_tests, :update_meta_schemas] +require 'rubocop/rake_task' +RuboCop::RakeTask.new(:rubocop) do |task| + # These make the rubocop experience maybe slightly less terrible + task.options = ['-D', '-S', '-E'] + + # Use Rubocop's Github Actions formatter if possible + if ENV['GITHUB_ACTIONS'] == 'true' + rubocop_spec = Gem::Specification.find_by_name('rubocop') + task.formatters << 'github' if Gem::Version.new(rubocop_spec.version) >= Gem::Version.new('1.2') + end +end + task :default => :test begin diff --git a/test/test-suite b/test/test-suite index 15ba997f..637f0ac3 160000 --- a/test/test-suite +++ b/test/test-suite @@ -1 +1 @@ -Subproject commit 15ba997f9b937150a0ab88244d1d0fbf58526c48 +Subproject commit 637f0ac3ebdd110065ab846918c03b364d9ee253 From 27e679d12e75e7b7dda1e8c8f34b1498f585b92e Mon Sep 17 00:00:00 2001 From: Tim Meusel Date: Fri, 17 Feb 2023 09:02:39 +0100 Subject: [PATCH 2/3] Add rubocop-minitest --- Gemfile | 1 + 1 file changed, 1 insertion(+) diff --git a/Gemfile b/Gemfile index 4951d199..b1535e08 100644 --- a/Gemfile +++ b/Gemfile @@ -16,4 +16,5 @@ group :tests do gem 'rubocop-rspec', '~> 2.4.0' # newer version require Ruby 2.6 or rubocop 1.19 gem 'rubocop-rake', '~> 0.6.0' # latest gem 'rubocop-performance', '~> 1.13.0' # newer version requires Ruby 2.6 + gem 'rubocop-minitest', '~> 0.19.0' # newer version requires Ruby 2.6 end From 1a3ed33147d0961763285b2ae5500069b925f4d1 Mon Sep 17 00:00:00 2001 From: Tim Meusel Date: Fri, 17 Feb 2023 09:03:14 +0100 Subject: [PATCH 3/3] rubocop: Fix Style/HashSyntax --- Gemfile | 4 ++-- Rakefile | 2 +- test/full_validation_test.rb | 4 ++-- test/list_option_test.rb | 2 +- test/uri_util_test.rb | 46 ++++++++++++++++++------------------ 5 files changed, 29 insertions(+), 29 deletions(-) diff --git a/Gemfile b/Gemfile index b1535e08..66c5e11b 100644 --- a/Gemfile +++ b/Gemfile @@ -3,10 +3,10 @@ source 'https://rubygems.org' gemspec group :release do - gem 'github_changelog_generator', require: false + gem 'github_changelog_generator', :require => false end -group :coverage, optional: ENV['COVERAGE']!='yes' do +group :coverage, :optional => ENV['COVERAGE']!='yes' do gem 'simplecov-console', :require => false gem 'codecov', :require => false end diff --git a/Rakefile b/Rakefile index a906a721..f9fafbbe 100644 --- a/Rakefile +++ b/Rakefile @@ -63,7 +63,7 @@ Rake::TestTask.new do |t| t.test_files = FileList.new('test/*_test.rb') end -task update: [:update_common_tests, :update_meta_schemas] +task :update => [:update_common_tests, :update_meta_schemas] require 'rubocop/rake_task' RuboCop::RakeTask.new(:rubocop) do |task| diff --git a/test/full_validation_test.rb b/test/full_validation_test.rb index 3eca142c..16efe4c3 100644 --- a/test/full_validation_test.rb +++ b/test/full_validation_test.rb @@ -44,7 +44,7 @@ def test_full_validation_with_instantiated_validator } } - validator = JSON::Validator.new(schema, { record_errors: true }) + validator = JSON::Validator.new(schema, { :record_errors => true }) assert(validator.validate(data).empty?) assert(validator.validate(data).empty?) assert(validator.validate(data).empty?) @@ -62,7 +62,7 @@ def test_full_validation_with_instantiated_validator } } - validator = JSON::Validator.new(schema, { record_errors: true }) + validator = JSON::Validator.new(schema, { :record_errors => true }) assert(validator.validate(data).length == 2) assert(validator.validate(data).length == 2) assert(validator.validate(data).length == 2) diff --git a/test/list_option_test.rb b/test/list_option_test.rb index 2626159b..fc6e5aa7 100644 --- a/test/list_option_test.rb +++ b/test/list_option_test.rb @@ -13,7 +13,7 @@ def test_list_option_reusing_schemas JSON::Validator.add_schema(schema) data = {"a" => 1} - assert_valid uri.to_s, data, clear_cache: false + assert_valid uri.to_s, data, :clear_cache => false data = [{"a" => 1}] assert_valid uri.to_s, data, :list => true diff --git a/test/uri_util_test.rb b/test/uri_util_test.rb index bf63c045..50ebc13e 100644 --- a/test/uri_util_test.rb +++ b/test/uri_util_test.rb @@ -13,59 +13,59 @@ def teardown def test_normalized_uri str = "https://www.google.com/search" - uri = Addressable::URI.new(scheme: 'https', - host: 'www.google.com', - path: 'search') + uri = Addressable::URI.new(:scheme => 'https', + :host => 'www.google.com', + :path => 'search') assert_equal uri, JSON::Util::URI.normalized_uri(str, '/home') end def test_normalized_uri_with_empty_fragment str = "https://www.google.com/search#" - uri = Addressable::URI.new(scheme: 'https', - host: 'www.google.com', - path: 'search', - fragment: nil) + uri = Addressable::URI.new(:scheme => 'https', + :host => 'www.google.com', + :path => 'search', + :fragment => nil) assert_equal uri, JSON::Util::URI.normalized_uri(str, '/home') end def test_normalized_uri_with_fragment str = "https://www.google.com/search#foo" - uri = Addressable::URI.new(scheme: 'https', - host: 'www.google.com', - path: 'search', - fragment: 'foo') + uri = Addressable::URI.new(:scheme => 'https', + :host => 'www.google.com', + :path => 'search', + :fragment => 'foo') assert_equal uri, JSON::Util::URI.normalized_uri(str, '/home') end def test_normalized_uri_for_absolute_path str = "/foo/bar.json" - uri = Addressable::URI.new(scheme: 'file', - host: '', - path: '/foo/bar.json') + uri = Addressable::URI.new(:scheme => 'file', + :host => '', + :path => '/foo/bar.json') assert_equal uri, JSON::Util::URI.normalized_uri(str, '/home') end def test_normalized_uri_for_relative_path str = "foo/bar.json" - uri = Addressable::URI.new(scheme: 'file', - host: '', - path: '/home/foo/bar.json') + uri = Addressable::URI.new(:scheme => 'file', + :host => '', + :path => '/home/foo/bar.json') assert_equal uri, JSON::Util::URI.normalized_uri(str, '/home') end def test_normalized_uri_for_file_path_with_host str = "file://localhost/foo/bar.json" - uri = Addressable::URI.new(scheme: 'file', - host: 'localhost', - path: '/foo/bar.json') + uri = Addressable::URI.new(:scheme => 'file', + :host => 'localhost', + :path => '/foo/bar.json') assert_equal uri, JSON::Util::URI.normalized_uri(str, '/home') end def test_uri_parse str = "https://www.google.com/search" - uri = Addressable::URI.new(scheme: 'https', - host: 'www.google.com', - path: 'search') + uri = Addressable::URI.new(:scheme => 'https', + :host => 'www.google.com', + :path => 'search') assert_equal uri, JSON::Util::URI.parse(str) end