From 39b1287cc2b20794156d6ba740ab7d3c1ba6e3b6 Mon Sep 17 00:00:00 2001 From: Benjamin Quorning Date: Fri, 17 Nov 2023 23:51:55 +0100 Subject: [PATCH 1/5] Replace rubocop with standard --- .github/workflows/actions.yml | 2 +- .rubocop.yml | 115 ---------- .standard.yml | 1 + .standard_todo.yml | 234 ++++++++++++++++++++ Gemfile.lock | 28 ++- Rakefile | 8 +- gemfiles/rails5.0.gemfile.lock | 43 +++- gemfiles/rails5.1.gemfile.lock | 43 +++- gemfiles/rails5.2.gemfile.lock | 43 +++- gemfiles/rails6.0.gemfile.lock | 43 +++- gemfiles/rails6.1.gemfile.lock | 43 +++- gemfiles/rails7.0.gemfile.lock | 43 +++- gemfiles/rails7.1.gemfile.lock | 28 ++- stronger_parameters.gemspec | 2 +- test/stronger_parameters/parameters_test.rb | 2 +- 15 files changed, 470 insertions(+), 208 deletions(-) delete mode 100644 .rubocop.yml create mode 100644 .standard.yml create mode 100644 .standard_todo.yml diff --git a/.github/workflows/actions.yml b/.github/workflows/actions.yml index 1d96522..a3df2a1 100644 --- a/.github/workflows/actions.yml +++ b/.github/workflows/actions.yml @@ -35,7 +35,7 @@ jobs: with: bundler-cache: true - name: linter - run: bundle exec rake rubocop + run: bundle exec rake standard # This wrapper is used in the main branch protection rules as a required check. # This way, we don’t need to update those rules when we add or remove a version in the test matrix. diff --git a/.rubocop.yml b/.rubocop.yml deleted file mode 100644 index e808fea..0000000 --- a/.rubocop.yml +++ /dev/null @@ -1,115 +0,0 @@ -AllCops: - SuggestExtensions: false - NewCops: enable - TargetRubyVersion: 2.7 # lowest supported version - Exclude: - - vendor/**/* - - gemfiles/vendor/**/* - -Gemspec/DevelopmentDependencies: - EnforcedStyle: gemspec - -Layout/LineLength: - Max: 120 - -Layout/CommentIndentation: - Enabled: false - -Style/StringLiterals: - Enabled: false - -Style/SignalException: - Enabled: false - -Layout/SpaceInsideHashLiteralBraces: - Enabled: false - -Style/PerlBackrefs: - Enabled: false - -Lint/AmbiguousOperator: - Enabled: false - -Style/Lambda: - Enabled: false - -Style/SpecialGlobalVars: - Enabled: false - -Style/WordArray: - Enabled: false - -Layout/EndAlignment: - EnforcedStyleAlignWith: variable - -Style/StringLiteralsInInterpolation: - Enabled: false - -Style/NumericLiterals: - Enabled: false - -Layout/FirstArgumentIndentation: - Enabled: false - -Layout/FirstHashElementIndentation: - Enabled: false - -Layout/ParameterAlignment: - Enabled: false - -Layout/MultilineOperationIndentation: - Enabled: false - -Metrics: - Enabled: false - -Style/DoubleNegation: - Enabled: false - -Style/Documentation: - Enabled: false - -Layout/MultilineMethodCallIndentation: - Enabled: false - -Lint/AssignmentInCondition: - Enabled: false - -Layout/DotPosition: - EnforcedStyle: trailing - -Layout/EmptyLineAfterMagicComment: - Enabled: false - -Style/SymbolArray: - Enabled: false - -Bundler/OrderedGems: - Enabled: false - -Style/GuardClause: - Enabled: false - -Style/ClassAndModuleChildren: - Enabled: false - -Style/NumericPredicate: - Enabled: false - -Naming/MethodParameterName: - Enabled: false - -Gemspec/OrderedDependencies: - Enabled: false - -Style/IfUnlessModifier: - Enabled: false - -Lint/MissingSuper: - Enabled: false - -Style/FetchEnvVar: - Enabled: false - -Lint/ParenthesesAsGroupedExpression: - Enabled: false diff --git a/.standard.yml b/.standard.yml new file mode 100644 index 0000000..c19ce03 --- /dev/null +++ b/.standard.yml @@ -0,0 +1 @@ +ruby_version: 2.7 diff --git a/.standard_todo.yml b/.standard_todo.yml new file mode 100644 index 0000000..dbef762 --- /dev/null +++ b/.standard_todo.yml @@ -0,0 +1,234 @@ +# Auto generated files with errors to ignore. +# Remove from this list as you refactor files. +--- +ignore: +- Gemfile: + - Layout/EmptyLineAfterMagicComment + - Style/StringLiterals +- Rakefile: + - Layout/EmptyLineAfterMagicComment + - Style/StringLiterals +- gemfiles/common.rb: + - Layout/EmptyLineAfterMagicComment + - Style/StringLiterals +- gemfiles/rails5.0.gemfile: + - Layout/EmptyLineAfterMagicComment + - Style/StringLiterals +- gemfiles/rails5.1.gemfile: + - Layout/EmptyLineAfterMagicComment + - Style/StringLiterals +- gemfiles/rails5.2.gemfile: + - Layout/EmptyLineAfterMagicComment + - Style/StringLiterals +- gemfiles/rails6.0.gemfile: + - Layout/EmptyLineAfterMagicComment + - Style/StringLiterals +- gemfiles/rails6.1.gemfile: + - Layout/EmptyLineAfterMagicComment + - Style/StringLiterals +- gemfiles/rails7.0.gemfile: + - Layout/EmptyLineAfterMagicComment + - Style/StringLiterals +- gemfiles/rails7.1.gemfile: + - Layout/EmptyLineAfterMagicComment + - Style/StringLiterals +- lib/stronger_parameters.rb: + - Layout/EmptyLineAfterMagicComment + - Style/StringLiterals +- lib/stronger_parameters/constraint.rb: + - Layout/EmptyLineAfterMagicComment + - Style/StringLiterals +- lib/stronger_parameters/constraints.rb: + - Layout/EmptyLineAfterMagicComment + - Style/StringLiterals +- lib/stronger_parameters/constraints/array_constraint.rb: + - Layout/EmptyLineAfterMagicComment + - Style/StringLiterals +- lib/stronger_parameters/constraints/boolean_constraint.rb: + - Layout/EmptyLineAfterMagicComment + - Style/StringLiterals + - Layout/ExtraSpacing +- lib/stronger_parameters/constraints/comparison_constraints.rb: + - Layout/EmptyLineAfterMagicComment + - Style/StringLiterals +- lib/stronger_parameters/constraints/date_constraint.rb: + - Layout/EmptyLineAfterMagicComment + - Style/StringLiterals +- lib/stronger_parameters/constraints/date_iso8601_constraint.rb: + - Layout/EmptyLineAfterMagicComment + - Style/StringLiterals +- lib/stronger_parameters/constraints/date_time_constraint.rb: + - Layout/EmptyLineAfterMagicComment + - Style/StringLiterals +- lib/stronger_parameters/constraints/date_time_iso8601_constraint.rb: + - Layout/EmptyLineAfterMagicComment + - Style/StringLiterals +- lib/stronger_parameters/constraints/decimal_constraint.rb: + - Layout/EmptyLineAfterMagicComment + - Style/StringLiterals + - Performance/RegexpMatch +- lib/stronger_parameters/constraints/enumeration_constraint.rb: + - Layout/EmptyLineAfterMagicComment + - Style/StringLiterals +- lib/stronger_parameters/constraints/file_constraint.rb: + - Layout/EmptyLineAfterMagicComment + - Style/StringLiterals +- lib/stronger_parameters/constraints/float_constraint.rb: + - Layout/EmptyLineAfterMagicComment + - Style/StringLiterals +- lib/stronger_parameters/constraints/hash_constraint.rb: + - Layout/EmptyLineAfterMagicComment + - Style/StringLiterals +- lib/stronger_parameters/constraints/hex_constraint.rb: + - Layout/EmptyLineAfterMagicComment + - Style/StringLiterals +- lib/stronger_parameters/constraints/integer_constraint.rb: + - Layout/EmptyLineAfterMagicComment + - Style/StringLiterals +- lib/stronger_parameters/constraints/nil_constraint.rb: + - Layout/EmptyLineAfterMagicComment + - Style/StringLiterals +- lib/stronger_parameters/constraints/nil_string_constraint.rb: + - Layout/EmptyLineAfterMagicComment + - Style/StringLiterals +- lib/stronger_parameters/constraints/regexp_constraint.rb: + - Layout/EmptyLineAfterMagicComment + - Style/StringLiterals + - Performance/RegexpMatch +- lib/stronger_parameters/constraints/string_constraint.rb: + - Layout/EmptyLineAfterMagicComment + - Style/StringLiterals +- lib/stronger_parameters/constraints/time_constraint.rb: + - Layout/EmptyLineAfterMagicComment + - Style/StringLiterals +- lib/stronger_parameters/constraints/time_iso8601_constraint.rb: + - Layout/EmptyLineAfterMagicComment + - Style/StringLiterals +- lib/stronger_parameters/constraints/ulid_constraint.rb: + - Layout/EmptyLineAfterMagicComment + - Style/StringLiterals + - Performance/RegexpMatch +- lib/stronger_parameters/controller_support/permitted_parameters.rb: + - Layout/EmptyLineAfterMagicComment + - Style/StringLiterals + - Lint/AssignmentInCondition +- lib/stronger_parameters/errors.rb: + - Layout/EmptyLineAfterMagicComment +- lib/stronger_parameters/parameters.rb: + - Layout/EmptyLineAfterMagicComment + - Style/StringLiterals + - Style/Alias + - Layout/ExtraSpacing + - Layout/SpaceInsideHashLiteralBraces +- lib/stronger_parameters/version.rb: + - Layout/EmptyLineAfterMagicComment + - Style/StringLiterals +- stronger_parameters.gemspec: + - Layout/EmptyLineAfterMagicComment + - Style/StringLiterals + - Layout/ExtraSpacing +- test/benchmark.rb: + - Layout/EmptyLineAfterMagicComment + - Style/StringLiterals +- test/controller_test.rb: + - Layout/EmptyLineAfterMagicComment + - Style/StringLiterals + - Layout/SpaceInsideHashLiteralBraces +- test/coverage_test.rb: + - Layout/EmptyLineAfterMagicComment + - Style/StringLiterals +- test/stronger_parameters/constraint_test.rb: + - Layout/EmptyLineAfterMagicComment + - Style/StringLiterals + - Layout/MultilineOperationIndentation +- test/stronger_parameters/constraints/array_constraint_test.rb: + - Layout/EmptyLineAfterMagicComment + - Style/StringLiterals +- test/stronger_parameters/constraints/boolean_constraint_test.rb: + - Layout/EmptyLineAfterMagicComment + - Style/StringLiterals + - Layout/ExtraSpacing +- test/stronger_parameters/constraints/comparison_constraints_test.rb: + - Layout/EmptyLineAfterMagicComment + - Style/StringLiterals +- test/stronger_parameters/constraints/date_constraint_test.rb: + - Layout/EmptyLineAfterMagicComment + - Style/StringLiterals +- test/stronger_parameters/constraints/date_iso8601_constraint_test.rb: + - Layout/EmptyLineAfterMagicComment + - Style/StringLiterals +- test/stronger_parameters/constraints/date_time_constraint_test.rb: + - Layout/EmptyLineAfterMagicComment + - Style/StringLiterals +- test/stronger_parameters/constraints/date_time_iso8601_constraint_test.rb: + - Layout/EmptyLineAfterMagicComment + - Style/StringLiterals +- test/stronger_parameters/constraints/decimal_constraint_test.rb: + - Layout/EmptyLineAfterMagicComment + - Style/StringLiterals +- test/stronger_parameters/constraints/enumeration_constraint_test.rb: + - Layout/EmptyLineAfterMagicComment + - Style/StringLiterals +- test/stronger_parameters/constraints/file_constraint_test.rb: + - Layout/EmptyLineAfterMagicComment + - Style/StringLiterals +- test/stronger_parameters/constraints/float_constraint_test.rb: + - Layout/EmptyLineAfterMagicComment + - Style/StringLiterals +- test/stronger_parameters/constraints/hash_constraint_test.rb: + - Layout/EmptyLineAfterMagicComment + - Style/StringLiterals + - Layout/DotPosition +- test/stronger_parameters/constraints/hex_constraint_test.rb: + - Layout/EmptyLineAfterMagicComment + - Style/StringLiterals +- test/stronger_parameters/constraints/integer_constraint_test.rb: + - Layout/EmptyLineAfterMagicComment + - Style/StringLiterals +- test/stronger_parameters/constraints/nil_constraint_test.rb: + - Layout/EmptyLineAfterMagicComment + - Style/StringLiterals +- test/stronger_parameters/constraints/nil_string_constraint_test.rb: + - Layout/EmptyLineAfterMagicComment + - Style/StringLiterals +- test/stronger_parameters/constraints/regexp_constraint_test.rb: + - Layout/EmptyLineAfterMagicComment + - Style/StringLiterals +- test/stronger_parameters/constraints/string_constraint_test.rb: + - Layout/EmptyLineAfterMagicComment + - Style/StringLiterals + - Performance/UnfreezeString +- test/stronger_parameters/constraints/time_constraint_test.rb: + - Layout/EmptyLineAfterMagicComment + - Style/StringLiterals +- test/stronger_parameters/constraints/time_iso8601_constraint_test.rb: + - Layout/EmptyLineAfterMagicComment + - Style/StringLiterals +- test/stronger_parameters/constraints/ulid_constraint_test.rb: + - Layout/EmptyLineAfterMagicComment + - Style/StringLiterals +- test/stronger_parameters/constraints_test.rb: + - Layout/EmptyLineAfterMagicComment + - Style/StringLiterals +- test/stronger_parameters/controller_support/permitted_parameters_test.rb: + - Layout/EmptyLineAfterMagicComment + - Style/StringLiterals + - Layout/SpaceInsideHashLiteralBraces + - Layout/DotPosition + - Performance/UnfreezeString +- test/stronger_parameters/errors_test.rb: + - Layout/EmptyLineAfterMagicComment + - Style/StringLiterals +- test/stronger_parameters/parameters_test.rb: + - Layout/EmptyLineAfterMagicComment + - Style/StringLiterals + - Layout/DotPosition +- test/stronger_parameters/version_test.rb: + - Layout/EmptyLineAfterMagicComment + - Style/StringLiterals +- test/stronger_parameters_test.rb: + - Layout/EmptyLineAfterMagicComment + - Style/StringLiterals +- test/test_helper.rb: + - Layout/EmptyLineAfterMagicComment + - Style/StringLiterals diff --git a/Gemfile.lock b/Gemfile.lock index 841f3a8..43bd0e1 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -102,8 +102,9 @@ GEM irb (1.8.3) rdoc reline (>= 0.3.8) - json (2.6.3) + json (2.7.1) language_server-protocol (3.17.0.3) + lint_roller (1.1.0) loofah (2.21.4) crass (~> 1.0.2) nokogiri (>= 1.12.0) @@ -138,7 +139,7 @@ GEM parallel (1.23.0) parallel_tests (4.3.0) parallel - parser (3.2.2.4) + parser (3.3.0.5) ast (~> 2.4.1) racc psych (5.1.1.1) @@ -185,11 +186,11 @@ GEM rake (13.1.0) rdoc (6.5.0) psych (>= 4.0.0) - regexp_parser (2.8.2) + regexp_parser (2.9.0) reline (0.3.9) io-console (~> 0.5) rexml (3.2.6) - rubocop (1.57.2) + rubocop (1.59.0) json (~> 2.3) language_server-protocol (>= 3.17.0) parallel (~> 1.10) @@ -197,14 +198,29 @@ GEM rainbow (>= 2.2.2, < 4.0) regexp_parser (>= 1.8, < 3.0) rexml (>= 3.2.5, < 4.0) - rubocop-ast (>= 1.28.1, < 2.0) + rubocop-ast (>= 1.30.0, < 2.0) ruby-progressbar (~> 1.7) unicode-display_width (>= 2.4.0, < 3.0) rubocop-ast (1.30.0) parser (>= 3.2.1.0) + rubocop-performance (1.20.2) + rubocop (>= 1.48.1, < 2.0) + rubocop-ast (>= 1.30.0, < 2.0) ruby-progressbar (1.13.0) ruby2_keywords (0.0.5) single_cov (1.11.0) + standard (1.33.0) + language_server-protocol (~> 3.17.0.2) + lint_roller (~> 1.0) + rubocop (~> 1.59.0) + standard-custom (~> 1.0.0) + standard-performance (~> 1.3) + standard-custom (1.0.2) + lint_roller (~> 1.0) + rubocop (~> 1.50) + standard-performance (1.3.1) + lint_roller (~> 1.1) + rubocop-performance (~> 1.20.2) stringio (3.0.8) thor (1.3.0) timeout (0.4.0) @@ -230,8 +246,8 @@ DEPENDENCIES minitest-rails (~> 7.1) rails (~> 7.1.0) rake - rubocop single_cov + standard stronger_parameters! BUNDLED WITH diff --git a/Rakefile b/Rakefile index c2b6c01..5e4709b 100644 --- a/Rakefile +++ b/Rakefile @@ -1,22 +1,18 @@ # frozen_string_literal: true require 'bundler/setup' +require 'standard/rake' require 'bump/tasks' # Pushing to rubygems is handled by a github workflow require 'bundler/gem_tasks' ENV['gem_push'] = 'false' -task default: [:test, :rubocop] +task default: [:test, :standard] task :test do sh "forking-test-runner test --merge-coverage --quiet" end -desc "Run rubocop" -task :rubocop do - sh "rubocop -a --fail-level A" -end - desc "Bundle all gemfiles [CMD=]" task :bundle_all do cmd = ENV["CMD"] diff --git a/gemfiles/rails5.0.gemfile.lock b/gemfiles/rails5.0.gemfile.lock index 20c5ad7..6e1a595 100644 --- a/gemfiles/rails5.0.gemfile.lock +++ b/gemfiles/rails5.0.gemfile.lock @@ -58,7 +58,9 @@ GEM activesupport (>= 5.0) i18n (1.12.0) concurrent-ruby (~> 1.0) - json (2.6.3) + json (2.7.1) + language_server-protocol (3.17.0.3) + lint_roller (1.1.0) loofah (2.19.1) crass (~> 1.0.2) nokogiri (>= 1.5.9) @@ -94,8 +96,9 @@ GEM parallel (1.22.1) parallel_tests (4.1.0) parallel - parser (3.2.0.0) + parser (3.3.0.5) ast (~> 2.4.1) + racc racc (1.6.2) rack (2.2.6.2) rack-test (0.6.3) @@ -125,21 +128,25 @@ GEM thor (>= 0.18.1, < 2.0) rainbow (3.1.1) rake (13.0.6) - regexp_parser (2.6.2) - rexml (3.2.5) - rubocop (1.44.1) + regexp_parser (2.9.0) + rexml (3.2.6) + rubocop (1.59.0) json (~> 2.3) + language_server-protocol (>= 3.17.0) parallel (~> 1.10) - parser (>= 3.2.0.0) + parser (>= 3.2.2.4) rainbow (>= 2.2.2, < 4.0) regexp_parser (>= 1.8, < 3.0) rexml (>= 3.2.5, < 4.0) - rubocop-ast (>= 1.24.1, < 2.0) + rubocop-ast (>= 1.30.0, < 2.0) ruby-progressbar (~> 1.7) unicode-display_width (>= 2.4.0, < 3.0) - rubocop-ast (1.24.1) - parser (>= 3.1.1.0) - ruby-progressbar (1.11.0) + rubocop-ast (1.30.0) + parser (>= 3.2.1.0) + rubocop-performance (1.20.2) + rubocop (>= 1.48.1, < 2.0) + rubocop-ast (>= 1.30.0, < 2.0) + ruby-progressbar (1.13.0) single_cov (1.8.0) sprockets (4.2.0) concurrent-ruby (~> 1.0) @@ -148,12 +155,24 @@ GEM actionpack (>= 4.0) activesupport (>= 4.0) sprockets (>= 3.0.0) + standard (1.33.0) + language_server-protocol (~> 3.17.0.2) + lint_roller (~> 1.0) + rubocop (~> 1.59.0) + standard-custom (~> 1.0.0) + standard-performance (~> 1.3) + standard-custom (1.0.2) + lint_roller (~> 1.0) + rubocop (~> 1.50) + standard-performance (1.3.1) + lint_roller (~> 1.1) + rubocop-performance (~> 1.20.2) thor (1.2.1) thread_safe (0.3.6) timeout (0.3.1) tzinfo (1.2.11) thread_safe (~> 0.1) - unicode-display_width (2.4.2) + unicode-display_width (2.5.0) websocket-driver (0.6.5) websocket-extensions (>= 0.1.0) websocket-extensions (0.1.5) @@ -170,8 +189,8 @@ DEPENDENCIES minitest-rails rails (~> 5.0.0) rake - rubocop single_cov + standard stronger_parameters! BUNDLED WITH diff --git a/gemfiles/rails5.1.gemfile.lock b/gemfiles/rails5.1.gemfile.lock index 572f3d7..8808d72 100644 --- a/gemfiles/rails5.1.gemfile.lock +++ b/gemfiles/rails5.1.gemfile.lock @@ -58,7 +58,9 @@ GEM activesupport (>= 5.0) i18n (1.12.0) concurrent-ruby (~> 1.0) - json (2.6.3) + json (2.7.1) + language_server-protocol (3.17.0.3) + lint_roller (1.1.0) loofah (2.19.1) crass (~> 1.0.2) nokogiri (>= 1.5.9) @@ -94,8 +96,9 @@ GEM parallel (1.22.1) parallel_tests (4.1.0) parallel - parser (3.2.0.0) + parser (3.3.0.5) ast (~> 2.4.1) + racc racc (1.6.2) rack (2.2.6.2) rack-test (2.0.2) @@ -125,21 +128,25 @@ GEM thor (>= 0.18.1, < 2.0) rainbow (3.1.1) rake (13.0.6) - regexp_parser (2.6.2) - rexml (3.2.5) - rubocop (1.44.1) + regexp_parser (2.9.0) + rexml (3.2.6) + rubocop (1.59.0) json (~> 2.3) + language_server-protocol (>= 3.17.0) parallel (~> 1.10) - parser (>= 3.2.0.0) + parser (>= 3.2.2.4) rainbow (>= 2.2.2, < 4.0) regexp_parser (>= 1.8, < 3.0) rexml (>= 3.2.5, < 4.0) - rubocop-ast (>= 1.24.1, < 2.0) + rubocop-ast (>= 1.30.0, < 2.0) ruby-progressbar (~> 1.7) unicode-display_width (>= 2.4.0, < 3.0) - rubocop-ast (1.24.1) - parser (>= 3.1.1.0) - ruby-progressbar (1.11.0) + rubocop-ast (1.30.0) + parser (>= 3.2.1.0) + rubocop-performance (1.20.2) + rubocop (>= 1.48.1, < 2.0) + rubocop-ast (>= 1.30.0, < 2.0) + ruby-progressbar (1.13.0) single_cov (1.8.0) sprockets (4.2.0) concurrent-ruby (~> 1.0) @@ -148,12 +155,24 @@ GEM actionpack (>= 4.0) activesupport (>= 4.0) sprockets (>= 3.0.0) + standard (1.33.0) + language_server-protocol (~> 3.17.0.2) + lint_roller (~> 1.0) + rubocop (~> 1.59.0) + standard-custom (~> 1.0.0) + standard-performance (~> 1.3) + standard-custom (1.0.2) + lint_roller (~> 1.0) + rubocop (~> 1.50) + standard-performance (1.3.1) + lint_roller (~> 1.1) + rubocop-performance (~> 1.20.2) thor (1.2.1) thread_safe (0.3.6) timeout (0.3.1) tzinfo (1.2.11) thread_safe (~> 0.1) - unicode-display_width (2.4.2) + unicode-display_width (2.5.0) websocket-driver (0.6.5) websocket-extensions (>= 0.1.0) websocket-extensions (0.1.5) @@ -170,8 +189,8 @@ DEPENDENCIES minitest-rails rails (~> 5.1.0) rake - rubocop single_cov + standard stronger_parameters! BUNDLED WITH diff --git a/gemfiles/rails5.2.gemfile.lock b/gemfiles/rails5.2.gemfile.lock index ed411e2..55c5003 100644 --- a/gemfiles/rails5.2.gemfile.lock +++ b/gemfiles/rails5.2.gemfile.lock @@ -62,7 +62,9 @@ GEM activesupport (>= 5.0) i18n (1.12.0) concurrent-ruby (~> 1.0) - json (2.6.3) + json (2.7.1) + language_server-protocol (3.17.0.3) + lint_roller (1.1.0) loofah (2.19.1) crass (~> 1.0.2) nokogiri (>= 1.5.9) @@ -99,8 +101,9 @@ GEM parallel (1.22.1) parallel_tests (4.1.0) parallel - parser (3.2.0.0) + parser (3.3.0.5) ast (~> 2.4.1) + racc racc (1.6.2) rack (2.2.6.2) rack-test (2.0.2) @@ -131,21 +134,25 @@ GEM thor (>= 0.19.0, < 2.0) rainbow (3.1.1) rake (13.0.6) - regexp_parser (2.6.2) - rexml (3.2.5) - rubocop (1.44.1) + regexp_parser (2.9.0) + rexml (3.2.6) + rubocop (1.59.0) json (~> 2.3) + language_server-protocol (>= 3.17.0) parallel (~> 1.10) - parser (>= 3.2.0.0) + parser (>= 3.2.2.4) rainbow (>= 2.2.2, < 4.0) regexp_parser (>= 1.8, < 3.0) rexml (>= 3.2.5, < 4.0) - rubocop-ast (>= 1.24.1, < 2.0) + rubocop-ast (>= 1.30.0, < 2.0) ruby-progressbar (~> 1.7) unicode-display_width (>= 2.4.0, < 3.0) - rubocop-ast (1.24.1) - parser (>= 3.1.1.0) - ruby-progressbar (1.11.0) + rubocop-ast (1.30.0) + parser (>= 3.2.1.0) + rubocop-performance (1.20.2) + rubocop (>= 1.48.1, < 2.0) + rubocop-ast (>= 1.30.0, < 2.0) + ruby-progressbar (1.13.0) single_cov (1.8.0) sprockets (4.2.0) concurrent-ruby (~> 1.0) @@ -154,12 +161,24 @@ GEM actionpack (>= 5.2) activesupport (>= 5.2) sprockets (>= 3.0.0) + standard (1.33.0) + language_server-protocol (~> 3.17.0.2) + lint_roller (~> 1.0) + rubocop (~> 1.59.0) + standard-custom (~> 1.0.0) + standard-performance (~> 1.3) + standard-custom (1.0.2) + lint_roller (~> 1.0) + rubocop (~> 1.50) + standard-performance (1.3.1) + lint_roller (~> 1.1) + rubocop-performance (~> 1.20.2) thor (1.2.1) thread_safe (0.3.6) timeout (0.3.1) tzinfo (1.2.11) thread_safe (~> 0.1) - unicode-display_width (2.4.2) + unicode-display_width (2.5.0) websocket-driver (0.7.5) websocket-extensions (>= 0.1.0) websocket-extensions (0.1.5) @@ -176,8 +195,8 @@ DEPENDENCIES minitest-rails rails (~> 5.2.0) rake - rubocop single_cov + standard stronger_parameters! BUNDLED WITH diff --git a/gemfiles/rails6.0.gemfile.lock b/gemfiles/rails6.0.gemfile.lock index 41b9b3a..5f5268c 100644 --- a/gemfiles/rails6.0.gemfile.lock +++ b/gemfiles/rails6.0.gemfile.lock @@ -75,7 +75,9 @@ GEM activesupport (>= 5.0) i18n (1.12.0) concurrent-ruby (~> 1.0) - json (2.6.3) + json (2.7.1) + language_server-protocol (3.17.0.3) + lint_roller (1.1.0) loofah (2.19.1) crass (~> 1.0.2) nokogiri (>= 1.5.9) @@ -112,8 +114,9 @@ GEM parallel (1.22.1) parallel_tests (4.1.0) parallel - parser (3.2.0.0) + parser (3.3.0.5) ast (~> 2.4.1) + racc racc (1.6.2) rack (2.2.6.2) rack-test (2.0.2) @@ -146,21 +149,25 @@ GEM thor (>= 0.20.3, < 2.0) rainbow (3.1.1) rake (13.0.6) - regexp_parser (2.6.2) - rexml (3.2.5) - rubocop (1.44.1) + regexp_parser (2.9.0) + rexml (3.2.6) + rubocop (1.59.0) json (~> 2.3) + language_server-protocol (>= 3.17.0) parallel (~> 1.10) - parser (>= 3.2.0.0) + parser (>= 3.2.2.4) rainbow (>= 2.2.2, < 4.0) regexp_parser (>= 1.8, < 3.0) rexml (>= 3.2.5, < 4.0) - rubocop-ast (>= 1.24.1, < 2.0) + rubocop-ast (>= 1.30.0, < 2.0) ruby-progressbar (~> 1.7) unicode-display_width (>= 2.4.0, < 3.0) - rubocop-ast (1.24.1) - parser (>= 3.1.1.0) - ruby-progressbar (1.11.0) + rubocop-ast (1.30.0) + parser (>= 3.2.1.0) + rubocop-performance (1.20.2) + rubocop (>= 1.48.1, < 2.0) + rubocop-ast (>= 1.30.0, < 2.0) + ruby-progressbar (1.13.0) single_cov (1.8.0) sprockets (4.2.0) concurrent-ruby (~> 1.0) @@ -169,12 +176,24 @@ GEM actionpack (>= 5.2) activesupport (>= 5.2) sprockets (>= 3.0.0) + standard (1.33.0) + language_server-protocol (~> 3.17.0.2) + lint_roller (~> 1.0) + rubocop (~> 1.59.0) + standard-custom (~> 1.0.0) + standard-performance (~> 1.3) + standard-custom (1.0.2) + lint_roller (~> 1.0) + rubocop (~> 1.50) + standard-performance (1.3.1) + lint_roller (~> 1.1) + rubocop-performance (~> 1.20.2) thor (1.2.1) thread_safe (0.3.6) timeout (0.3.1) tzinfo (1.2.11) thread_safe (~> 0.1) - unicode-display_width (2.4.2) + unicode-display_width (2.5.0) websocket-driver (0.7.5) websocket-extensions (>= 0.1.0) websocket-extensions (0.1.5) @@ -192,8 +211,8 @@ DEPENDENCIES minitest-rails rails (~> 6.0.0) rake - rubocop single_cov + standard stronger_parameters! BUNDLED WITH diff --git a/gemfiles/rails6.1.gemfile.lock b/gemfiles/rails6.1.gemfile.lock index f9b072c..89f4970 100644 --- a/gemfiles/rails6.1.gemfile.lock +++ b/gemfiles/rails6.1.gemfile.lock @@ -79,7 +79,9 @@ GEM activesupport (>= 5.0) i18n (1.12.0) concurrent-ruby (~> 1.0) - json (2.6.3) + json (2.7.1) + language_server-protocol (3.17.0.3) + lint_roller (1.1.0) loofah (2.19.1) crass (~> 1.0.2) nokogiri (>= 1.5.9) @@ -116,8 +118,9 @@ GEM parallel (1.22.1) parallel_tests (4.1.0) parallel - parser (3.2.0.0) + parser (3.3.0.5) ast (~> 2.4.1) + racc racc (1.6.2) rack (2.2.6.2) rack-test (2.0.2) @@ -150,21 +153,25 @@ GEM thor (~> 1.0) rainbow (3.1.1) rake (13.0.6) - regexp_parser (2.6.2) - rexml (3.2.5) - rubocop (1.44.1) + regexp_parser (2.9.0) + rexml (3.2.6) + rubocop (1.59.0) json (~> 2.3) + language_server-protocol (>= 3.17.0) parallel (~> 1.10) - parser (>= 3.2.0.0) + parser (>= 3.2.2.4) rainbow (>= 2.2.2, < 4.0) regexp_parser (>= 1.8, < 3.0) rexml (>= 3.2.5, < 4.0) - rubocop-ast (>= 1.24.1, < 2.0) + rubocop-ast (>= 1.30.0, < 2.0) ruby-progressbar (~> 1.7) unicode-display_width (>= 2.4.0, < 3.0) - rubocop-ast (1.24.1) - parser (>= 3.1.1.0) - ruby-progressbar (1.11.0) + rubocop-ast (1.30.0) + parser (>= 3.2.1.0) + rubocop-performance (1.20.2) + rubocop (>= 1.48.1, < 2.0) + rubocop-ast (>= 1.30.0, < 2.0) + ruby-progressbar (1.13.0) single_cov (1.8.0) sprockets (4.2.0) concurrent-ruby (~> 1.0) @@ -173,11 +180,23 @@ GEM actionpack (>= 5.2) activesupport (>= 5.2) sprockets (>= 3.0.0) + standard (1.33.0) + language_server-protocol (~> 3.17.0.2) + lint_roller (~> 1.0) + rubocop (~> 1.59.0) + standard-custom (~> 1.0.0) + standard-performance (~> 1.3) + standard-custom (1.0.2) + lint_roller (~> 1.0) + rubocop (~> 1.50) + standard-performance (1.3.1) + lint_roller (~> 1.1) + rubocop-performance (~> 1.20.2) thor (1.2.1) timeout (0.3.1) tzinfo (2.0.6) concurrent-ruby (~> 1.0) - unicode-display_width (2.4.2) + unicode-display_width (2.5.0) websocket-driver (0.7.5) websocket-extensions (>= 0.1.0) websocket-extensions (0.1.5) @@ -195,8 +214,8 @@ DEPENDENCIES minitest-rails rails (~> 6.1.0) rake - rubocop single_cov + standard stronger_parameters! BUNDLED WITH diff --git a/gemfiles/rails7.0.gemfile.lock b/gemfiles/rails7.0.gemfile.lock index 5c63cdb..d2f4ca0 100644 --- a/gemfiles/rails7.0.gemfile.lock +++ b/gemfiles/rails7.0.gemfile.lock @@ -85,7 +85,9 @@ GEM activesupport (>= 5.0) i18n (1.12.0) concurrent-ruby (~> 1.0) - json (2.6.3) + json (2.7.1) + language_server-protocol (3.17.0.3) + lint_roller (1.1.0) loofah (2.19.1) crass (~> 1.0.2) nokogiri (>= 1.5.9) @@ -122,8 +124,9 @@ GEM parallel (1.22.1) parallel_tests (4.1.0) parallel - parser (3.2.0.0) + parser (3.3.0.5) ast (~> 2.4.1) + racc racc (1.6.2) rack (2.2.6.2) rack-test (2.0.2) @@ -156,27 +159,43 @@ GEM zeitwerk (~> 2.5) rainbow (3.1.1) rake (13.0.6) - regexp_parser (2.6.2) - rexml (3.2.5) - rubocop (1.44.1) + regexp_parser (2.9.0) + rexml (3.2.6) + rubocop (1.59.0) json (~> 2.3) + language_server-protocol (>= 3.17.0) parallel (~> 1.10) - parser (>= 3.2.0.0) + parser (>= 3.2.2.4) rainbow (>= 2.2.2, < 4.0) regexp_parser (>= 1.8, < 3.0) rexml (>= 3.2.5, < 4.0) - rubocop-ast (>= 1.24.1, < 2.0) + rubocop-ast (>= 1.30.0, < 2.0) ruby-progressbar (~> 1.7) unicode-display_width (>= 2.4.0, < 3.0) - rubocop-ast (1.24.1) - parser (>= 3.1.1.0) - ruby-progressbar (1.11.0) + rubocop-ast (1.30.0) + parser (>= 3.2.1.0) + rubocop-performance (1.20.2) + rubocop (>= 1.48.1, < 2.0) + rubocop-ast (>= 1.30.0, < 2.0) + ruby-progressbar (1.13.0) single_cov (1.8.0) + standard (1.33.0) + language_server-protocol (~> 3.17.0.2) + lint_roller (~> 1.0) + rubocop (~> 1.59.0) + standard-custom (~> 1.0.0) + standard-performance (~> 1.3) + standard-custom (1.0.2) + lint_roller (~> 1.0) + rubocop (~> 1.50) + standard-performance (1.3.1) + lint_roller (~> 1.1) + rubocop-performance (~> 1.20.2) thor (1.2.1) timeout (0.3.1) tzinfo (2.0.6) concurrent-ruby (~> 1.0) - unicode-display_width (2.4.2) + unicode-display_width (2.5.0) websocket-driver (0.7.5) websocket-extensions (>= 0.1.0) websocket-extensions (0.1.5) @@ -194,8 +213,8 @@ DEPENDENCIES minitest-rails rails (~> 7.0.0) rake - rubocop single_cov + standard stronger_parameters! BUNDLED WITH diff --git a/gemfiles/rails7.1.gemfile.lock b/gemfiles/rails7.1.gemfile.lock index 7182e52..0590f9e 100644 --- a/gemfiles/rails7.1.gemfile.lock +++ b/gemfiles/rails7.1.gemfile.lock @@ -102,8 +102,9 @@ GEM irb (1.8.3) rdoc reline (>= 0.3.8) - json (2.6.3) + json (2.7.1) language_server-protocol (3.17.0.3) + lint_roller (1.1.0) loofah (2.21.4) crass (~> 1.0.2) nokogiri (>= 1.12.0) @@ -138,7 +139,7 @@ GEM parallel (1.23.0) parallel_tests (4.3.0) parallel - parser (3.2.2.4) + parser (3.3.0.5) ast (~> 2.4.1) racc psych (5.1.1.1) @@ -185,11 +186,11 @@ GEM rake (13.1.0) rdoc (6.5.0) psych (>= 4.0.0) - regexp_parser (2.8.2) + regexp_parser (2.9.0) reline (0.3.9) io-console (~> 0.5) rexml (3.2.6) - rubocop (1.57.2) + rubocop (1.59.0) json (~> 2.3) language_server-protocol (>= 3.17.0) parallel (~> 1.10) @@ -197,14 +198,29 @@ GEM rainbow (>= 2.2.2, < 4.0) regexp_parser (>= 1.8, < 3.0) rexml (>= 3.2.5, < 4.0) - rubocop-ast (>= 1.28.1, < 2.0) + rubocop-ast (>= 1.30.0, < 2.0) ruby-progressbar (~> 1.7) unicode-display_width (>= 2.4.0, < 3.0) rubocop-ast (1.30.0) parser (>= 3.2.1.0) + rubocop-performance (1.20.2) + rubocop (>= 1.48.1, < 2.0) + rubocop-ast (>= 1.30.0, < 2.0) ruby-progressbar (1.13.0) ruby2_keywords (0.0.5) single_cov (1.11.0) + standard (1.33.0) + language_server-protocol (~> 3.17.0.2) + lint_roller (~> 1.0) + rubocop (~> 1.59.0) + standard-custom (~> 1.0.0) + standard-performance (~> 1.3) + standard-custom (1.0.2) + lint_roller (~> 1.0) + rubocop (~> 1.50) + standard-performance (1.3.1) + lint_roller (~> 1.1) + rubocop-performance (~> 1.20.2) stringio (3.0.8) thor (1.3.0) timeout (0.4.0) @@ -229,8 +245,8 @@ DEPENDENCIES minitest-rails rails (~> 7.1.0) rake - rubocop single_cov + standard stronger_parameters! BUNDLED WITH diff --git a/stronger_parameters.gemspec b/stronger_parameters.gemspec index b8b005b..743d954 100644 --- a/stronger_parameters.gemspec +++ b/stronger_parameters.gemspec @@ -18,7 +18,7 @@ Gem::Specification.new do |spec| spec.add_development_dependency 'maxitest' spec.add_development_dependency 'bump' spec.add_development_dependency 'single_cov' - spec.add_development_dependency 'rubocop' + spec.add_development_dependency 'standard' spec.add_development_dependency 'forking_test_runner' spec.add_runtime_dependency 'actionpack', '>= 5.0', '< 7.2' diff --git a/test/stronger_parameters/parameters_test.rb b/test/stronger_parameters/parameters_test.rb index fcf80da..5a8b2a7 100644 --- a/test/stronger_parameters/parameters_test.rb +++ b/test/stronger_parameters/parameters_test.rb @@ -327,7 +327,7 @@ def pass_nil_as_constrain params(value: nil).permit(value: ActionController::Parameters.integer32) end - def with_allow_nil_for_everything(value = true) # rubocop:disable Style/OptionalBooleanParameter + def with_allow_nil_for_everything(value = true) old = ActionController::Parameters.allow_nil_for_everything ActionController::Parameters.allow_nil_for_everything = value yield From eee1a5f87757938eb85bdca0a77df4ab81dadd87 Mon Sep 17 00:00:00 2001 From: Benjamin Quorning Date: Fri, 17 Nov 2023 23:52:48 +0100 Subject: [PATCH 2/5] Standard: Fix Style/StringLiterals offenses --- .standard_todo.yml | 70 ------------------ Gemfile | 4 +- Rakefile | 10 +-- gemfiles/common.rb | 2 +- gemfiles/rails5.0.gemfile | 2 +- gemfiles/rails5.1.gemfile | 2 +- gemfiles/rails5.2.gemfile | 2 +- gemfiles/rails6.0.gemfile | 2 +- gemfiles/rails6.1.gemfile | 2 +- gemfiles/rails7.0.gemfile | 2 +- gemfiles/rails7.1.gemfile | 2 +- lib/stronger_parameters.rb | 10 +-- lib/stronger_parameters/constraint.rb | 2 +- lib/stronger_parameters/constraints.rb | 44 ++++++------ .../constraints/array_constraint.rb | 2 +- .../constraints/boolean_constraint.rb | 6 +- .../constraints/comparison_constraints.rb | 2 +- .../constraints/date_constraint.rb | 2 +- .../constraints/date_iso8601_constraint.rb | 2 +- .../constraints/date_time_constraint.rb | 2 +- .../date_time_iso8601_constraint.rb | 2 +- .../constraints/decimal_constraint.rb | 2 +- .../constraints/enumeration_constraint.rb | 2 +- .../constraints/file_constraint.rb | 2 +- .../constraints/float_constraint.rb | 2 +- .../constraints/hash_constraint.rb | 2 +- .../constraints/hex_constraint.rb | 4 +- .../constraints/integer_constraint.rb | 4 +- .../constraints/nil_constraint.rb | 4 +- .../constraints/nil_string_constraint.rb | 4 +- .../constraints/regexp_constraint.rb | 2 +- .../constraints/string_constraint.rb | 6 +- .../constraints/time_constraint.rb | 2 +- .../constraints/time_iso8601_constraint.rb | 2 +- .../constraints/ulid_constraint.rb | 2 +- .../permitted_parameters.rb | 4 +- lib/stronger_parameters/parameters.rb | 16 ++--- lib/stronger_parameters/version.rb | 2 +- stronger_parameters.gemspec | 38 +++++----- test/benchmark.rb | 4 +- test/controller_test.rb | 36 +++++----- test/coverage_test.rb | 2 +- test/stronger_parameters/constraint_test.rb | 20 +++--- .../constraints/array_constraint_test.rb | 10 +-- .../constraints/boolean_constraint_test.rb | 20 +++--- .../comparison_constraints_test.rb | 2 +- .../constraints/date_constraint_test.rb | 4 +- .../date_iso8601_constraint_test.rb | 4 +- .../constraints/date_time_constraint_test.rb | 4 +- .../date_time_iso8601_constraint_test.rb | 4 +- .../constraints/decimal_constraint_test.rb | 72 +++++++++---------- .../enumeration_constraint_test.rb | 14 ++-- .../constraints/file_constraint_test.rb | 12 ++-- .../constraints/float_constraint_test.rb | 16 ++--- .../constraints/hash_constraint_test.rb | 32 ++++----- .../constraints/hex_constraint_test.rb | 12 ++-- .../constraints/integer_constraint_test.rb | 14 ++-- .../constraints/nil_constraint_test.rb | 6 +- .../constraints/nil_string_constraint_test.rb | 10 +-- .../constraints/regexp_constraint_test.rb | 10 +-- .../constraints/string_constraint_test.rb | 14 ++-- .../constraints/time_constraint_test.rb | 4 +- .../time_iso8601_constraint_test.rb | 4 +- .../constraints/ulid_constraint_test.rb | 18 ++--- test/stronger_parameters/constraints_test.rb | 2 +- .../permitted_parameters_test.rb | 64 ++++++++--------- test/stronger_parameters/errors_test.rb | 2 +- test/stronger_parameters/parameters_test.rb | 28 ++++---- test/stronger_parameters/version_test.rb | 2 +- test/stronger_parameters_test.rb | 2 +- test/test_helper.rb | 22 +++--- 71 files changed, 337 insertions(+), 407 deletions(-) diff --git a/.standard_todo.yml b/.standard_todo.yml index dbef762..fb607b9 100644 --- a/.standard_todo.yml +++ b/.standard_todo.yml @@ -4,231 +4,161 @@ ignore: - Gemfile: - Layout/EmptyLineAfterMagicComment - - Style/StringLiterals - Rakefile: - Layout/EmptyLineAfterMagicComment - - Style/StringLiterals - gemfiles/common.rb: - Layout/EmptyLineAfterMagicComment - - Style/StringLiterals - gemfiles/rails5.0.gemfile: - Layout/EmptyLineAfterMagicComment - - Style/StringLiterals - gemfiles/rails5.1.gemfile: - Layout/EmptyLineAfterMagicComment - - Style/StringLiterals - gemfiles/rails5.2.gemfile: - Layout/EmptyLineAfterMagicComment - - Style/StringLiterals - gemfiles/rails6.0.gemfile: - Layout/EmptyLineAfterMagicComment - - Style/StringLiterals - gemfiles/rails6.1.gemfile: - Layout/EmptyLineAfterMagicComment - - Style/StringLiterals - gemfiles/rails7.0.gemfile: - Layout/EmptyLineAfterMagicComment - - Style/StringLiterals - gemfiles/rails7.1.gemfile: - Layout/EmptyLineAfterMagicComment - - Style/StringLiterals - lib/stronger_parameters.rb: - Layout/EmptyLineAfterMagicComment - - Style/StringLiterals - lib/stronger_parameters/constraint.rb: - Layout/EmptyLineAfterMagicComment - - Style/StringLiterals - lib/stronger_parameters/constraints.rb: - Layout/EmptyLineAfterMagicComment - - Style/StringLiterals - lib/stronger_parameters/constraints/array_constraint.rb: - Layout/EmptyLineAfterMagicComment - - Style/StringLiterals - lib/stronger_parameters/constraints/boolean_constraint.rb: - Layout/EmptyLineAfterMagicComment - - Style/StringLiterals - Layout/ExtraSpacing - lib/stronger_parameters/constraints/comparison_constraints.rb: - Layout/EmptyLineAfterMagicComment - - Style/StringLiterals - lib/stronger_parameters/constraints/date_constraint.rb: - Layout/EmptyLineAfterMagicComment - - Style/StringLiterals - lib/stronger_parameters/constraints/date_iso8601_constraint.rb: - Layout/EmptyLineAfterMagicComment - - Style/StringLiterals - lib/stronger_parameters/constraints/date_time_constraint.rb: - Layout/EmptyLineAfterMagicComment - - Style/StringLiterals - lib/stronger_parameters/constraints/date_time_iso8601_constraint.rb: - Layout/EmptyLineAfterMagicComment - - Style/StringLiterals - lib/stronger_parameters/constraints/decimal_constraint.rb: - Layout/EmptyLineAfterMagicComment - - Style/StringLiterals - Performance/RegexpMatch - lib/stronger_parameters/constraints/enumeration_constraint.rb: - Layout/EmptyLineAfterMagicComment - - Style/StringLiterals - lib/stronger_parameters/constraints/file_constraint.rb: - Layout/EmptyLineAfterMagicComment - - Style/StringLiterals - lib/stronger_parameters/constraints/float_constraint.rb: - Layout/EmptyLineAfterMagicComment - - Style/StringLiterals - lib/stronger_parameters/constraints/hash_constraint.rb: - Layout/EmptyLineAfterMagicComment - - Style/StringLiterals - lib/stronger_parameters/constraints/hex_constraint.rb: - Layout/EmptyLineAfterMagicComment - - Style/StringLiterals - lib/stronger_parameters/constraints/integer_constraint.rb: - Layout/EmptyLineAfterMagicComment - - Style/StringLiterals - lib/stronger_parameters/constraints/nil_constraint.rb: - Layout/EmptyLineAfterMagicComment - - Style/StringLiterals - lib/stronger_parameters/constraints/nil_string_constraint.rb: - Layout/EmptyLineAfterMagicComment - - Style/StringLiterals - lib/stronger_parameters/constraints/regexp_constraint.rb: - Layout/EmptyLineAfterMagicComment - - Style/StringLiterals - Performance/RegexpMatch - lib/stronger_parameters/constraints/string_constraint.rb: - Layout/EmptyLineAfterMagicComment - - Style/StringLiterals - lib/stronger_parameters/constraints/time_constraint.rb: - Layout/EmptyLineAfterMagicComment - - Style/StringLiterals - lib/stronger_parameters/constraints/time_iso8601_constraint.rb: - Layout/EmptyLineAfterMagicComment - - Style/StringLiterals - lib/stronger_parameters/constraints/ulid_constraint.rb: - Layout/EmptyLineAfterMagicComment - - Style/StringLiterals - Performance/RegexpMatch - lib/stronger_parameters/controller_support/permitted_parameters.rb: - Layout/EmptyLineAfterMagicComment - - Style/StringLiterals - Lint/AssignmentInCondition - lib/stronger_parameters/errors.rb: - Layout/EmptyLineAfterMagicComment - lib/stronger_parameters/parameters.rb: - Layout/EmptyLineAfterMagicComment - - Style/StringLiterals - Style/Alias - Layout/ExtraSpacing - Layout/SpaceInsideHashLiteralBraces - lib/stronger_parameters/version.rb: - Layout/EmptyLineAfterMagicComment - - Style/StringLiterals - stronger_parameters.gemspec: - Layout/EmptyLineAfterMagicComment - - Style/StringLiterals - Layout/ExtraSpacing - test/benchmark.rb: - Layout/EmptyLineAfterMagicComment - - Style/StringLiterals - test/controller_test.rb: - Layout/EmptyLineAfterMagicComment - - Style/StringLiterals - Layout/SpaceInsideHashLiteralBraces - test/coverage_test.rb: - Layout/EmptyLineAfterMagicComment - - Style/StringLiterals - test/stronger_parameters/constraint_test.rb: - Layout/EmptyLineAfterMagicComment - - Style/StringLiterals - Layout/MultilineOperationIndentation - test/stronger_parameters/constraints/array_constraint_test.rb: - Layout/EmptyLineAfterMagicComment - - Style/StringLiterals - test/stronger_parameters/constraints/boolean_constraint_test.rb: - Layout/EmptyLineAfterMagicComment - - Style/StringLiterals - Layout/ExtraSpacing - test/stronger_parameters/constraints/comparison_constraints_test.rb: - Layout/EmptyLineAfterMagicComment - - Style/StringLiterals - test/stronger_parameters/constraints/date_constraint_test.rb: - Layout/EmptyLineAfterMagicComment - - Style/StringLiterals - test/stronger_parameters/constraints/date_iso8601_constraint_test.rb: - Layout/EmptyLineAfterMagicComment - - Style/StringLiterals - test/stronger_parameters/constraints/date_time_constraint_test.rb: - Layout/EmptyLineAfterMagicComment - - Style/StringLiterals - test/stronger_parameters/constraints/date_time_iso8601_constraint_test.rb: - Layout/EmptyLineAfterMagicComment - - Style/StringLiterals - test/stronger_parameters/constraints/decimal_constraint_test.rb: - Layout/EmptyLineAfterMagicComment - - Style/StringLiterals - test/stronger_parameters/constraints/enumeration_constraint_test.rb: - Layout/EmptyLineAfterMagicComment - - Style/StringLiterals - test/stronger_parameters/constraints/file_constraint_test.rb: - Layout/EmptyLineAfterMagicComment - - Style/StringLiterals - test/stronger_parameters/constraints/float_constraint_test.rb: - Layout/EmptyLineAfterMagicComment - - Style/StringLiterals - test/stronger_parameters/constraints/hash_constraint_test.rb: - Layout/EmptyLineAfterMagicComment - - Style/StringLiterals - Layout/DotPosition - test/stronger_parameters/constraints/hex_constraint_test.rb: - Layout/EmptyLineAfterMagicComment - - Style/StringLiterals - test/stronger_parameters/constraints/integer_constraint_test.rb: - Layout/EmptyLineAfterMagicComment - - Style/StringLiterals - test/stronger_parameters/constraints/nil_constraint_test.rb: - Layout/EmptyLineAfterMagicComment - - Style/StringLiterals - test/stronger_parameters/constraints/nil_string_constraint_test.rb: - Layout/EmptyLineAfterMagicComment - - Style/StringLiterals - test/stronger_parameters/constraints/regexp_constraint_test.rb: - Layout/EmptyLineAfterMagicComment - - Style/StringLiterals - test/stronger_parameters/constraints/string_constraint_test.rb: - Layout/EmptyLineAfterMagicComment - - Style/StringLiterals - Performance/UnfreezeString - test/stronger_parameters/constraints/time_constraint_test.rb: - Layout/EmptyLineAfterMagicComment - - Style/StringLiterals - test/stronger_parameters/constraints/time_iso8601_constraint_test.rb: - Layout/EmptyLineAfterMagicComment - - Style/StringLiterals - test/stronger_parameters/constraints/ulid_constraint_test.rb: - Layout/EmptyLineAfterMagicComment - - Style/StringLiterals - test/stronger_parameters/constraints_test.rb: - Layout/EmptyLineAfterMagicComment - - Style/StringLiterals - test/stronger_parameters/controller_support/permitted_parameters_test.rb: - Layout/EmptyLineAfterMagicComment - - Style/StringLiterals - Layout/SpaceInsideHashLiteralBraces - Layout/DotPosition - Performance/UnfreezeString - test/stronger_parameters/errors_test.rb: - Layout/EmptyLineAfterMagicComment - - Style/StringLiterals - test/stronger_parameters/parameters_test.rb: - Layout/EmptyLineAfterMagicComment - - Style/StringLiterals - Layout/DotPosition - test/stronger_parameters/version_test.rb: - Layout/EmptyLineAfterMagicComment - - Style/StringLiterals - test/stronger_parameters_test.rb: - Layout/EmptyLineAfterMagicComment - - Style/StringLiterals - test/test_helper.rb: - Layout/EmptyLineAfterMagicComment - - Style/StringLiterals diff --git a/Gemfile b/Gemfile index 22f2382..2efe8f4 100644 --- a/Gemfile +++ b/Gemfile @@ -1,4 +1,4 @@ # frozen_string_literal: true eval_gemfile Dir["gemfiles/*.gemfile"].max -gem 'minitest-rails', '~> 7.1' -gem 'minitest', '~> 5.20' +gem "minitest-rails", "~> 7.1" +gem "minitest", "~> 5.20" diff --git a/Rakefile b/Rakefile index 5e4709b..95094d3 100644 --- a/Rakefile +++ b/Rakefile @@ -1,11 +1,11 @@ # frozen_string_literal: true -require 'bundler/setup' -require 'standard/rake' -require 'bump/tasks' +require "bundler/setup" +require "standard/rake" +require "bump/tasks" # Pushing to rubygems is handled by a github workflow -require 'bundler/gem_tasks' -ENV['gem_push'] = 'false' +require "bundler/gem_tasks" +ENV["gem_push"] = "false" task default: [:test, :standard] diff --git a/gemfiles/common.rb b/gemfiles/common.rb index 43ee679..651cba4 100644 --- a/gemfiles/common.rb +++ b/gemfiles/common.rb @@ -1,4 +1,4 @@ # frozen_string_literal: true source "https://rubygems.org" -gemspec path: '..' +gemspec path: ".." diff --git a/gemfiles/rails5.0.gemfile b/gemfiles/rails5.0.gemfile index 6ed6ca4..53dd0ca 100644 --- a/gemfiles/rails5.0.gemfile +++ b/gemfiles/rails5.0.gemfile @@ -1,4 +1,4 @@ # frozen_string_literal: true gem "rails", "~> 5.0.0" -eval_gemfile 'common.rb' +eval_gemfile "common.rb" diff --git a/gemfiles/rails5.1.gemfile b/gemfiles/rails5.1.gemfile index 87f6cb6..b46b927 100644 --- a/gemfiles/rails5.1.gemfile +++ b/gemfiles/rails5.1.gemfile @@ -1,4 +1,4 @@ # frozen_string_literal: true gem "rails", "~> 5.1.0" -eval_gemfile 'common.rb' +eval_gemfile "common.rb" diff --git a/gemfiles/rails5.2.gemfile b/gemfiles/rails5.2.gemfile index e4d350f..b048bc1 100644 --- a/gemfiles/rails5.2.gemfile +++ b/gemfiles/rails5.2.gemfile @@ -1,4 +1,4 @@ # frozen_string_literal: true gem "rails", "~> 5.2.0" -eval_gemfile 'common.rb' +eval_gemfile "common.rb" diff --git a/gemfiles/rails6.0.gemfile b/gemfiles/rails6.0.gemfile index 11bf725..57817aa 100644 --- a/gemfiles/rails6.0.gemfile +++ b/gemfiles/rails6.0.gemfile @@ -1,4 +1,4 @@ # frozen_string_literal: true gem "rails", "~> 6.0.0" -eval_gemfile 'common.rb' +eval_gemfile "common.rb" diff --git a/gemfiles/rails6.1.gemfile b/gemfiles/rails6.1.gemfile index 48d05bc..35fef85 100644 --- a/gemfiles/rails6.1.gemfile +++ b/gemfiles/rails6.1.gemfile @@ -1,4 +1,4 @@ # frozen_string_literal: true gem "rails", "~> 6.1.0" -eval_gemfile 'common.rb' +eval_gemfile "common.rb" diff --git a/gemfiles/rails7.0.gemfile b/gemfiles/rails7.0.gemfile index b47ccc8..5da5010 100644 --- a/gemfiles/rails7.0.gemfile +++ b/gemfiles/rails7.0.gemfile @@ -1,4 +1,4 @@ # frozen_string_literal: true gem "rails", "~> 7.0.0" -eval_gemfile 'common.rb' +eval_gemfile "common.rb" diff --git a/gemfiles/rails7.1.gemfile b/gemfiles/rails7.1.gemfile index 1c97b1c..a6e7f39 100644 --- a/gemfiles/rails7.1.gemfile +++ b/gemfiles/rails7.1.gemfile @@ -1,4 +1,4 @@ # frozen_string_literal: true gem "rails", "~> 7.1.0" -eval_gemfile 'common.rb' +eval_gemfile "common.rb" diff --git a/lib/stronger_parameters.rb b/lib/stronger_parameters.rb index d41dcf3..3f1cf16 100644 --- a/lib/stronger_parameters.rb +++ b/lib/stronger_parameters.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -require 'stronger_parameters/version' -require 'action_pack' -require 'stronger_parameters/parameters' -require 'stronger_parameters/constraints' -require 'stronger_parameters/controller_support/permitted_parameters' +require "stronger_parameters/version" +require "action_pack" +require "stronger_parameters/parameters" +require "stronger_parameters/constraints" +require "stronger_parameters/controller_support/permitted_parameters" diff --git a/lib/stronger_parameters/constraint.rb b/lib/stronger_parameters/constraint.rb index a59de39..cce1893 100644 --- a/lib/stronger_parameters/constraint.rb +++ b/lib/stronger_parameters/constraint.rb @@ -1,5 +1,5 @@ # frozen_string_literal: true -require 'stronger_parameters/errors' +require "stronger_parameters/errors" module StrongerParameters class Constraint diff --git a/lib/stronger_parameters/constraints.rb b/lib/stronger_parameters/constraints.rb index 17aa9bb..77675d2 100644 --- a/lib/stronger_parameters/constraints.rb +++ b/lib/stronger_parameters/constraints.rb @@ -1,23 +1,23 @@ # frozen_string_literal: true -require 'stronger_parameters/constraint' -require 'stronger_parameters/constraints/string_constraint' -require 'stronger_parameters/constraints/float_constraint' -require 'stronger_parameters/constraints/date_constraint' -require 'stronger_parameters/constraints/date_iso8601_constraint' -require 'stronger_parameters/constraints/time_constraint' -require 'stronger_parameters/constraints/time_iso8601_constraint' -require 'stronger_parameters/constraints/date_time_constraint' -require 'stronger_parameters/constraints/date_time_iso8601_constraint' -require 'stronger_parameters/constraints/regexp_constraint' -require 'stronger_parameters/constraints/integer_constraint' -require 'stronger_parameters/constraints/nil_constraint' -require 'stronger_parameters/constraints/boolean_constraint' -require 'stronger_parameters/constraints/array_constraint' -require 'stronger_parameters/constraints/hash_constraint' -require 'stronger_parameters/constraints/enumeration_constraint' -require 'stronger_parameters/constraints/comparison_constraints' -require 'stronger_parameters/constraints/nil_string_constraint' -require 'stronger_parameters/constraints/file_constraint' -require 'stronger_parameters/constraints/decimal_constraint' -require 'stronger_parameters/constraints/hex_constraint' -require 'stronger_parameters/constraints/ulid_constraint' +require "stronger_parameters/constraint" +require "stronger_parameters/constraints/string_constraint" +require "stronger_parameters/constraints/float_constraint" +require "stronger_parameters/constraints/date_constraint" +require "stronger_parameters/constraints/date_iso8601_constraint" +require "stronger_parameters/constraints/time_constraint" +require "stronger_parameters/constraints/time_iso8601_constraint" +require "stronger_parameters/constraints/date_time_constraint" +require "stronger_parameters/constraints/date_time_iso8601_constraint" +require "stronger_parameters/constraints/regexp_constraint" +require "stronger_parameters/constraints/integer_constraint" +require "stronger_parameters/constraints/nil_constraint" +require "stronger_parameters/constraints/boolean_constraint" +require "stronger_parameters/constraints/array_constraint" +require "stronger_parameters/constraints/hash_constraint" +require "stronger_parameters/constraints/enumeration_constraint" +require "stronger_parameters/constraints/comparison_constraints" +require "stronger_parameters/constraints/nil_string_constraint" +require "stronger_parameters/constraints/file_constraint" +require "stronger_parameters/constraints/decimal_constraint" +require "stronger_parameters/constraints/hex_constraint" +require "stronger_parameters/constraints/ulid_constraint" diff --git a/lib/stronger_parameters/constraints/array_constraint.rb b/lib/stronger_parameters/constraints/array_constraint.rb index 3739845..9a9a651 100644 --- a/lib/stronger_parameters/constraints/array_constraint.rb +++ b/lib/stronger_parameters/constraints/array_constraint.rb @@ -1,5 +1,5 @@ # frozen_string_literal: true -require 'stronger_parameters/constraint' +require "stronger_parameters/constraint" module StrongerParameters class ArrayConstraint < Constraint diff --git a/lib/stronger_parameters/constraints/boolean_constraint.rb b/lib/stronger_parameters/constraints/boolean_constraint.rb index c6ce6d1..497bc84 100644 --- a/lib/stronger_parameters/constraints/boolean_constraint.rb +++ b/lib/stronger_parameters/constraints/boolean_constraint.rb @@ -1,10 +1,10 @@ # frozen_string_literal: true -require 'stronger_parameters/constraint' +require "stronger_parameters/constraint" module StrongerParameters class BooleanConstraint < Constraint - TRUE_VALUES = [true, 'true', '1', 1, 'on'].freeze - FALSE_VALUES = [false, 'false', '0', 0].freeze + TRUE_VALUES = [true, "true", "1", 1, "on"].freeze + FALSE_VALUES = [false, "false", "0", 0].freeze def value(v) v = v.downcase if v.is_a? String diff --git a/lib/stronger_parameters/constraints/comparison_constraints.rb b/lib/stronger_parameters/constraints/comparison_constraints.rb index 6d1f845..cf7aff1 100644 --- a/lib/stronger_parameters/constraints/comparison_constraints.rb +++ b/lib/stronger_parameters/constraints/comparison_constraints.rb @@ -1,5 +1,5 @@ # frozen_string_literal: true -require 'stronger_parameters/constraint' +require "stronger_parameters/constraint" module StrongerParameters class ComparisonConstraints < Constraint diff --git a/lib/stronger_parameters/constraints/date_constraint.rb b/lib/stronger_parameters/constraints/date_constraint.rb index 8cad206..fd10e36 100644 --- a/lib/stronger_parameters/constraints/date_constraint.rb +++ b/lib/stronger_parameters/constraints/date_constraint.rb @@ -1,5 +1,5 @@ # frozen_string_literal: true -require 'stronger_parameters/constraint' +require "stronger_parameters/constraint" module StrongerParameters class DateConstraint < Constraint diff --git a/lib/stronger_parameters/constraints/date_iso8601_constraint.rb b/lib/stronger_parameters/constraints/date_iso8601_constraint.rb index 5dd8e89..4010a4c 100644 --- a/lib/stronger_parameters/constraints/date_iso8601_constraint.rb +++ b/lib/stronger_parameters/constraints/date_iso8601_constraint.rb @@ -1,5 +1,5 @@ # frozen_string_literal: true -require 'stronger_parameters/constraint' +require "stronger_parameters/constraint" module StrongerParameters class DateIso8601Constraint < Constraint diff --git a/lib/stronger_parameters/constraints/date_time_constraint.rb b/lib/stronger_parameters/constraints/date_time_constraint.rb index c842129..faa55ec 100644 --- a/lib/stronger_parameters/constraints/date_time_constraint.rb +++ b/lib/stronger_parameters/constraints/date_time_constraint.rb @@ -1,5 +1,5 @@ # frozen_string_literal: true -require 'stronger_parameters/constraint' +require "stronger_parameters/constraint" module StrongerParameters class DateTimeConstraint < Constraint diff --git a/lib/stronger_parameters/constraints/date_time_iso8601_constraint.rb b/lib/stronger_parameters/constraints/date_time_iso8601_constraint.rb index 805c085..de5fd5f 100644 --- a/lib/stronger_parameters/constraints/date_time_iso8601_constraint.rb +++ b/lib/stronger_parameters/constraints/date_time_iso8601_constraint.rb @@ -1,5 +1,5 @@ # frozen_string_literal: true -require 'stronger_parameters/constraint' +require "stronger_parameters/constraint" module StrongerParameters class DateTimeIso8601Constraint < Constraint diff --git a/lib/stronger_parameters/constraints/decimal_constraint.rb b/lib/stronger_parameters/constraints/decimal_constraint.rb index 5d67145..4ac42de 100644 --- a/lib/stronger_parameters/constraints/decimal_constraint.rb +++ b/lib/stronger_parameters/constraints/decimal_constraint.rb @@ -1,5 +1,5 @@ # frozen_string_literal: true -require 'stronger_parameters/constraint' +require "stronger_parameters/constraint" module StrongerParameters class DecimalConstraint < Constraint diff --git a/lib/stronger_parameters/constraints/enumeration_constraint.rb b/lib/stronger_parameters/constraints/enumeration_constraint.rb index 1eae0db..d54a9f9 100644 --- a/lib/stronger_parameters/constraints/enumeration_constraint.rb +++ b/lib/stronger_parameters/constraints/enumeration_constraint.rb @@ -1,5 +1,5 @@ # frozen_string_literal: true -require 'stronger_parameters/constraint' +require "stronger_parameters/constraint" module StrongerParameters class EnumerationConstraint < Constraint diff --git a/lib/stronger_parameters/constraints/file_constraint.rb b/lib/stronger_parameters/constraints/file_constraint.rb index 0f5f0a7..8b69221 100644 --- a/lib/stronger_parameters/constraints/file_constraint.rb +++ b/lib/stronger_parameters/constraints/file_constraint.rb @@ -1,5 +1,5 @@ # frozen_string_literal: true -require 'stronger_parameters/constraint' +require "stronger_parameters/constraint" module StrongerParameters class FileConstraint < Constraint diff --git a/lib/stronger_parameters/constraints/float_constraint.rb b/lib/stronger_parameters/constraints/float_constraint.rb index 7d76596..453b078 100644 --- a/lib/stronger_parameters/constraints/float_constraint.rb +++ b/lib/stronger_parameters/constraints/float_constraint.rb @@ -1,5 +1,5 @@ # frozen_string_literal: true -require 'stronger_parameters/constraint' +require "stronger_parameters/constraint" module StrongerParameters class FloatConstraint < Constraint diff --git a/lib/stronger_parameters/constraints/hash_constraint.rb b/lib/stronger_parameters/constraints/hash_constraint.rb index 047e2d4..2a55232 100644 --- a/lib/stronger_parameters/constraints/hash_constraint.rb +++ b/lib/stronger_parameters/constraints/hash_constraint.rb @@ -1,5 +1,5 @@ # frozen_string_literal: true -require 'stronger_parameters/constraint' +require "stronger_parameters/constraint" module StrongerParameters class HashConstraint < Constraint diff --git a/lib/stronger_parameters/constraints/hex_constraint.rb b/lib/stronger_parameters/constraints/hex_constraint.rb index df317e5..74d08b2 100644 --- a/lib/stronger_parameters/constraints/hex_constraint.rb +++ b/lib/stronger_parameters/constraints/hex_constraint.rb @@ -1,12 +1,12 @@ # frozen_string_literal: true -require 'stronger_parameters/constraint' +require "stronger_parameters/constraint" module StrongerParameters class HexConstraint < Constraint def value(v) return v if v.is_a?(String) && v.match?(/\A[a-f0-9]+\z/i) - InvalidValue.new(v, 'must be a hexadecimal string') + InvalidValue.new(v, "must be a hexadecimal string") end end end diff --git a/lib/stronger_parameters/constraints/integer_constraint.rb b/lib/stronger_parameters/constraints/integer_constraint.rb index cd4085a..4b18b24 100644 --- a/lib/stronger_parameters/constraints/integer_constraint.rb +++ b/lib/stronger_parameters/constraints/integer_constraint.rb @@ -1,5 +1,5 @@ # frozen_string_literal: true -require 'stronger_parameters/constraint' +require "stronger_parameters/constraint" module StrongerParameters class IntegerConstraint < Constraint @@ -10,7 +10,7 @@ def value(v) return v.to_i end - InvalidValue.new(v, 'must be an integer') + InvalidValue.new(v, "must be an integer") end end end diff --git a/lib/stronger_parameters/constraints/nil_constraint.rb b/lib/stronger_parameters/constraints/nil_constraint.rb index e7f6da7..f1abd13 100644 --- a/lib/stronger_parameters/constraints/nil_constraint.rb +++ b/lib/stronger_parameters/constraints/nil_constraint.rb @@ -1,12 +1,12 @@ # frozen_string_literal: true -require 'stronger_parameters/constraint' +require "stronger_parameters/constraint" module StrongerParameters class NilConstraint < Constraint def value(v) return v if v.nil? - InvalidValue.new(v, 'must be an nil') + InvalidValue.new(v, "must be an nil") end end end diff --git a/lib/stronger_parameters/constraints/nil_string_constraint.rb b/lib/stronger_parameters/constraints/nil_string_constraint.rb index f71eb59..b43749e 100644 --- a/lib/stronger_parameters/constraints/nil_string_constraint.rb +++ b/lib/stronger_parameters/constraints/nil_string_constraint.rb @@ -1,9 +1,9 @@ # frozen_string_literal: true -require 'stronger_parameters/constraint' +require "stronger_parameters/constraint" module StrongerParameters class NilStringConstraint < Constraint - NULL_VALUES = [nil, '', 'undefined'].freeze + NULL_VALUES = [nil, "", "undefined"].freeze def value(v) if NULL_VALUES.include?(v) diff --git a/lib/stronger_parameters/constraints/regexp_constraint.rb b/lib/stronger_parameters/constraints/regexp_constraint.rb index 0b2a853..d529860 100644 --- a/lib/stronger_parameters/constraints/regexp_constraint.rb +++ b/lib/stronger_parameters/constraints/regexp_constraint.rb @@ -1,5 +1,5 @@ # frozen_string_literal: true -require 'stronger_parameters/constraint' +require "stronger_parameters/constraint" module StrongerParameters class RegexpConstraint < Constraint diff --git a/lib/stronger_parameters/constraints/string_constraint.rb b/lib/stronger_parameters/constraints/string_constraint.rb index 09ce059..8350b0e 100644 --- a/lib/stronger_parameters/constraints/string_constraint.rb +++ b/lib/stronger_parameters/constraints/string_constraint.rb @@ -1,5 +1,5 @@ # frozen_string_literal: true -require 'stronger_parameters/constraint' +require "stronger_parameters/constraint" module StrongerParameters class StringConstraint < Constraint @@ -17,13 +17,13 @@ def value(v) elsif minimum_length && v.bytesize < minimum_length return InvalidValue.new(v, "can not be shorter than #{minimum_length} bytes") elsif !v.valid_encoding? - return InvalidValue.new(v, 'must have valid encoding') + return InvalidValue.new(v, "must have valid encoding") end return v end - InvalidValue.new(v, 'must be a string') + InvalidValue.new(v, "must be a string") end def ==(other) diff --git a/lib/stronger_parameters/constraints/time_constraint.rb b/lib/stronger_parameters/constraints/time_constraint.rb index 9369409..b5b9900 100644 --- a/lib/stronger_parameters/constraints/time_constraint.rb +++ b/lib/stronger_parameters/constraints/time_constraint.rb @@ -1,5 +1,5 @@ # frozen_string_literal: true -require 'stronger_parameters/constraint' +require "stronger_parameters/constraint" module StrongerParameters class TimeConstraint < Constraint diff --git a/lib/stronger_parameters/constraints/time_iso8601_constraint.rb b/lib/stronger_parameters/constraints/time_iso8601_constraint.rb index 9419b66..6a43790 100644 --- a/lib/stronger_parameters/constraints/time_iso8601_constraint.rb +++ b/lib/stronger_parameters/constraints/time_iso8601_constraint.rb @@ -1,5 +1,5 @@ # frozen_string_literal: true -require 'stronger_parameters/constraint' +require "stronger_parameters/constraint" module StrongerParameters class TimeIso8601Constraint < Constraint diff --git a/lib/stronger_parameters/constraints/ulid_constraint.rb b/lib/stronger_parameters/constraints/ulid_constraint.rb index f459080..651e243 100644 --- a/lib/stronger_parameters/constraints/ulid_constraint.rb +++ b/lib/stronger_parameters/constraints/ulid_constraint.rb @@ -1,5 +1,5 @@ # frozen_string_literal: true -require 'stronger_parameters/constraint' +require "stronger_parameters/constraint" module StrongerParameters class UlidConstraint < Constraint diff --git a/lib/stronger_parameters/controller_support/permitted_parameters.rb b/lib/stronger_parameters/controller_support/permitted_parameters.rb index 48371ee..8e012e2 100644 --- a/lib/stronger_parameters/controller_support/permitted_parameters.rb +++ b/lib/stronger_parameters/controller_support/permitted_parameters.rb @@ -1,5 +1,5 @@ # frozen_string_literal: true -require 'stronger_parameters/constraints' +require "stronger_parameters/constraints" module StrongerParameters module ControllerSupport @@ -101,7 +101,7 @@ def permit_parameters def show_unpermitted_keys(unpermitted_keys, log_unpermitted) return if unpermitted_keys.empty? - log_prefix = (log_unpermitted ? 'Found' : 'Removed') + log_prefix = (log_unpermitted ? "Found" : "Removed") message = "#{log_prefix} restricted keys #{unpermitted_keys.inspect} from parameters according to permitted list" diff --git a/lib/stronger_parameters/parameters.rb b/lib/stronger_parameters/parameters.rb index 92ca851..e09ffc9 100644 --- a/lib/stronger_parameters/parameters.rb +++ b/lib/stronger_parameters/parameters.rb @@ -1,12 +1,12 @@ # frozen_string_literal: true -require 'action_pack' +require "action_pack" -require 'action_controller/base' -require 'action_controller/api' -require 'action_controller/metal/strong_parameters' +require "action_controller/base" +require "action_controller/api" +require "action_controller/metal/strong_parameters" -require 'stronger_parameters/constraints' -require 'stronger_parameters/errors' +require "stronger_parameters/constraints" +require "stronger_parameters/errors" module StrongerParameters module Parameters @@ -173,7 +173,7 @@ def hash_filter_with_stronger_parameters(params, filter) if key?(key) result = constraint.value(value) elsif constraint.required? - result = InvalidValue.new(nil, 'must be present') + result = InvalidValue.new(nil, "must be present") else next # uncovered end @@ -211,7 +211,7 @@ module ControllerSupport # TODO: this is not consistent with the behavior of raising ActionController::UnpermittedParameters # should have the same render vs raise behavior in test/dev ... see permitted_parameters_test.rb rescue_from(StrongerParameters::InvalidParameter) do |e| - if request.format.to_s.include?('json') + if request.format.to_s.include?("json") render json: { error: e.message }, status: :bad_request else render plain: e.message, status: :bad_request diff --git a/lib/stronger_parameters/version.rb b/lib/stronger_parameters/version.rb index 49b79a6..370b088 100644 --- a/lib/stronger_parameters/version.rb +++ b/lib/stronger_parameters/version.rb @@ -1,4 +1,4 @@ # frozen_string_literal: true module StrongerParameters - VERSION = '2.22.0' + VERSION = "2.22.0" end diff --git a/stronger_parameters.gemspec b/stronger_parameters.gemspec index 743d954..101313f 100644 --- a/stronger_parameters.gemspec +++ b/stronger_parameters.gemspec @@ -1,27 +1,27 @@ # frozen_string_literal: true -require './lib/stronger_parameters/version' +require "./lib/stronger_parameters/version" Gem::Specification.new do |spec| - spec.name = 'stronger_parameters' + spec.name = "stronger_parameters" spec.version = StrongerParameters::VERSION - spec.authors = ['Mick Staugaard'] - spec.email = ['mick@zendesk.com'] - spec.summary = 'Type checking and type casting of parameters for Action Pack' - spec.homepage = 'https://github.com/zendesk/stronger_parameters' - spec.license = 'Apache License Version 2.0' + spec.authors = ["Mick Staugaard"] + spec.email = ["mick@zendesk.com"] + spec.summary = "Type checking and type casting of parameters for Action Pack" + spec.homepage = "https://github.com/zendesk/stronger_parameters" + spec.license = "Apache License Version 2.0" - spec.files = Dir.glob('lib/**/*') + %w[README.md] + spec.files = Dir.glob("lib/**/*") + %w[README.md] - spec.add_development_dependency 'bundler', '<= 3' - spec.add_development_dependency 'rake' - spec.add_development_dependency 'minitest-rails' - spec.add_development_dependency 'maxitest' - spec.add_development_dependency 'bump' - spec.add_development_dependency 'single_cov' - spec.add_development_dependency 'standard' - spec.add_development_dependency 'forking_test_runner' - spec.add_runtime_dependency 'actionpack', '>= 5.0', '< 7.2' + spec.add_development_dependency "bundler", "<= 3" + spec.add_development_dependency "rake" + spec.add_development_dependency "minitest-rails" + spec.add_development_dependency "maxitest" + spec.add_development_dependency "bump" + spec.add_development_dependency "single_cov" + spec.add_development_dependency "standard" + spec.add_development_dependency "forking_test_runner" + spec.add_runtime_dependency "actionpack", ">= 5.0", "< 7.2" - spec.required_ruby_version = '>= 2.7.0' - spec.metadata['rubygems_mfa_required'] = 'true' + spec.required_ruby_version = ">= 2.7.0" + spec.metadata["rubygems_mfa_required"] = "true" end diff --git a/test/benchmark.rb b/test/benchmark.rb index 9b4113d..ad51116 100644 --- a/test/benchmark.rb +++ b/test/benchmark.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -require_relative 'test_helper' -require 'benchmark' +require_relative "test_helper" +require "benchmark" def build_stack(count, &block) if count.zero? diff --git a/test/controller_test.rb b/test/controller_test.rb index 1a05962..b73ff32 100644 --- a/test/controller_test.rb +++ b/test/controller_test.rb @@ -1,5 +1,5 @@ # frozen_string_literal: true -require_relative 'test_helper' +require_relative "test_helper" SingleCov.not_covered! @@ -9,7 +9,7 @@ class BooksController < ActionController::Base include ROUTES.url_helpers rescue_from(ActionController::ParameterMissing) do |e| - if request.format.to_s.include?('json') + if request.format.to_s.include?("json") render json: { error: "Required parameter missing: #{e.param}" }, status: :bad_request else render plain: "Required parameter missing: #{e.param}", status: :bad_request @@ -26,36 +26,36 @@ def create describe BooksController do before { @routes = BooksController::ROUTES } - context 'for text format' do - it 'rejects invalid params' do - post :create, params: {magazine: {name: 'Mjallo!'}} + context "for text format" do + it "rejects invalid params" do + post :create, params: {magazine: {name: "Mjallo!"}} assert_response :bad_request - response.body.must_equal 'Required parameter missing: book' + response.body.must_equal "Required parameter missing: book" - post :create, params: {book: {id: 'Mjallo!'}} + post :create, params: {book: {id: "Mjallo!"}} assert_response :bad_request - response.body.must_equal 'Invalid parameter: id must be an integer' + response.body.must_equal "Invalid parameter: id must be an integer" end - it 'permits valid params' do - post :create, params: {book: {id: '123'}} + it "permits valid params" do + post :create, params: {book: {id: "123"}} assert_response :ok end end - context 'for json format' do - it 'rejects invalid params' do - post :create, params: {magazine: {name: 'Mjallo!'}}, format: :json + context "for json format" do + it "rejects invalid params" do + post :create, params: {magazine: {name: "Mjallo!"}}, format: :json assert_response :bad_request - (JSON.parse(response.body)["error"]).must_equal 'Required parameter missing: book' + (JSON.parse(response.body)["error"]).must_equal "Required parameter missing: book" - post :create, params: {book: {id: 'Mjallo!'}}, format: :json + post :create, params: {book: {id: "Mjallo!"}}, format: :json assert_response :bad_request - (JSON.parse(response.body)["error"]).must_equal 'Invalid parameter: id must be an integer' + (JSON.parse(response.body)["error"]).must_equal "Invalid parameter: id must be an integer" end - it 'permits valid params' do - post :create, params: {book: {id: '123'}}, format: :json + it "permits valid params" do + post :create, params: {book: {id: "123"}}, format: :json assert_response :ok end end diff --git a/test/coverage_test.rb b/test/coverage_test.rb index 5fa966d..37f032f 100644 --- a/test/coverage_test.rb +++ b/test/coverage_test.rb @@ -1,5 +1,5 @@ # frozen_string_literal: true -require_relative 'test_helper' +require_relative "test_helper" SingleCov.not_covered! # not testing any code in lib/ diff --git a/test/stronger_parameters/constraint_test.rb b/test/stronger_parameters/constraint_test.rb index 894a592..4816c3f 100644 --- a/test/stronger_parameters/constraint_test.rb +++ b/test/stronger_parameters/constraint_test.rb @@ -1,5 +1,5 @@ # frozen_string_literal: true -require_relative '../test_helper' +require_relative "../test_helper" SingleCov.covered! @@ -7,7 +7,7 @@ subject { StrongerParameters::Constraint.new } describe "#value" do - permits 'abc' + permits "abc" end describe "#==" do @@ -34,8 +34,8 @@ describe StrongerParameters::OrConstraint do subject { ActionController::Parameters.integer | ActionController::Parameters.string } - permits 'abc' - permits '123', as: 123 + permits "abc" + permits "123", as: 123 rejects Date.today rejects Time.now @@ -48,7 +48,7 @@ ActionController::Parameters.boolean end - permits 'abc' + permits "abc" permits true rejects Date.today @@ -88,10 +88,10 @@ describe StrongerParameters::AndConstraint do subject { ActionController::Parameters.string & ActionController::Parameters.integer } - permits '123', as: 123 + permits "123", as: 123 rejects 123 - rejects 'abc' + rejects "abc" rejects nil describe "multi-chain" do @@ -101,9 +101,9 @@ ActionController::Parameters.lt(5) end - permits '4', as: 4 + permits "4", as: 4 - rejects '5' + rejects "5" end describe "#==" do @@ -141,5 +141,5 @@ subject { ActionController::Parameters.string.required } rejects nil - permits '123' + permits "123" end diff --git a/test/stronger_parameters/constraints/array_constraint_test.rb b/test/stronger_parameters/constraints/array_constraint_test.rb index 2344546..c3c46a6 100644 --- a/test/stronger_parameters/constraints/array_constraint_test.rb +++ b/test/stronger_parameters/constraints/array_constraint_test.rb @@ -1,21 +1,21 @@ # frozen_string_literal: true -require_relative '../../test_helper' +require_relative "../../test_helper" SingleCov.covered! describe StrongerParameters::ArrayConstraint do subject { ActionController::Parameters.array(ActionController::Parameters.string) } - permits ['a', 'b'] + permits ["a", "b"] - rejects 'abc' + rejects "abc" rejects 123 rejects [123, 456] - rejects ['abc', 123] + rejects ["abc", 123] rejects nil rejects [nil] - describe '#==' do + describe "#==" do it "is the same with same constraints" do subject.must_equal ActionController::Parameters.array(ActionController::Parameters.string) end diff --git a/test/stronger_parameters/constraints/boolean_constraint_test.rb b/test/stronger_parameters/constraints/boolean_constraint_test.rb index 26d0820..1888238 100644 --- a/test/stronger_parameters/constraints/boolean_constraint_test.rb +++ b/test/stronger_parameters/constraints/boolean_constraint_test.rb @@ -1,24 +1,24 @@ # frozen_string_literal: true -require_relative '../../test_helper' +require_relative "../../test_helper" SingleCov.covered! -describe 'boolean parameter constraints' do +describe "boolean parameter constraints" do subject { ActionController::Parameters.boolean } permits true, as: true - permits 'true', as: true - permits 'True', as: true + permits "true", as: true + permits "True", as: true permits 1, as: true - permits '1', as: true - permits 'on', as: true + permits "1", as: true + permits "on", as: true permits false, as: false - permits 'false', as: false - permits 'FALSE', as: false + permits "false", as: false + permits "FALSE", as: false permits 0, as: false - permits '0', as: false + permits "0", as: false - rejects 'foo' + rejects "foo" rejects nil end diff --git a/test/stronger_parameters/constraints/comparison_constraints_test.rb b/test/stronger_parameters/constraints/comparison_constraints_test.rb index 9002ad1..69ab2b9 100644 --- a/test/stronger_parameters/constraints/comparison_constraints_test.rb +++ b/test/stronger_parameters/constraints/comparison_constraints_test.rb @@ -1,5 +1,5 @@ # frozen_string_literal: true -require_relative '../../test_helper' +require_relative "../../test_helper" SingleCov.covered! diff --git a/test/stronger_parameters/constraints/date_constraint_test.rb b/test/stronger_parameters/constraints/date_constraint_test.rb index ce4056a..4a31a55 100644 --- a/test/stronger_parameters/constraints/date_constraint_test.rb +++ b/test/stronger_parameters/constraints/date_constraint_test.rb @@ -1,9 +1,9 @@ # frozen_string_literal: true -require_relative '../../test_helper' +require_relative "../../test_helper" SingleCov.covered! -describe 'date parameter constraints' do +describe "date parameter constraints" do subject { ActionController::Parameters.date } permits Date.parse("2015-03-21"), as: Date.parse("2015-03-21") diff --git a/test/stronger_parameters/constraints/date_iso8601_constraint_test.rb b/test/stronger_parameters/constraints/date_iso8601_constraint_test.rb index e177aa3..871e79d 100644 --- a/test/stronger_parameters/constraints/date_iso8601_constraint_test.rb +++ b/test/stronger_parameters/constraints/date_iso8601_constraint_test.rb @@ -1,9 +1,9 @@ # frozen_string_literal: true -require_relative '../../test_helper' +require_relative "../../test_helper" SingleCov.covered! -describe 'date_iso8601 parameter constraints' do +describe "date_iso8601 parameter constraints" do subject { ActionController::Parameters.date_iso8601 } permits "2018-04-12", as: Date.iso8601("2018-04-12") diff --git a/test/stronger_parameters/constraints/date_time_constraint_test.rb b/test/stronger_parameters/constraints/date_time_constraint_test.rb index 9e1391c..0a5e426 100644 --- a/test/stronger_parameters/constraints/date_time_constraint_test.rb +++ b/test/stronger_parameters/constraints/date_time_constraint_test.rb @@ -1,9 +1,9 @@ # frozen_string_literal: true -require_relative '../../test_helper' +require_relative "../../test_helper" SingleCov.covered! -describe 'datetime parameter constraints' do +describe "datetime parameter constraints" do subject { ActionController::Parameters.datetime } permits DateTime.parse("2015-03-31"), as: DateTime.parse("2015-03-31") diff --git a/test/stronger_parameters/constraints/date_time_iso8601_constraint_test.rb b/test/stronger_parameters/constraints/date_time_iso8601_constraint_test.rb index 0a02c67..5a43ca0 100644 --- a/test/stronger_parameters/constraints/date_time_iso8601_constraint_test.rb +++ b/test/stronger_parameters/constraints/date_time_iso8601_constraint_test.rb @@ -1,9 +1,9 @@ # frozen_string_literal: true -require_relative '../../test_helper' +require_relative "../../test_helper" SingleCov.covered! -describe 'datetime_iso8601 parameter constraints' do +describe "datetime_iso8601 parameter constraints" do subject { ActionController::Parameters.datetime_iso8601 } permits "2018-04-12", as: DateTime.iso8601("2018-04-12") diff --git a/test/stronger_parameters/constraints/decimal_constraint_test.rb b/test/stronger_parameters/constraints/decimal_constraint_test.rb index 169fc8c..9855b02 100644 --- a/test/stronger_parameters/constraints/decimal_constraint_test.rb +++ b/test/stronger_parameters/constraints/decimal_constraint_test.rb @@ -1,86 +1,86 @@ # frozen_string_literal: true -require_relative '../../test_helper' +require_relative "../../test_helper" SingleCov.covered! -describe 'decimal parameter constraints' do - describe 'with 2 scale and 4 precision' do +describe "decimal parameter constraints" do + describe "with 2 scale and 4 precision" do subject { ActionController::Parameters.decimal(4, 2) } - permits '1.23', as: 1.23 - permits '-1.23', as: -1.23 + permits "1.23", as: 1.23 + permits "-1.23", as: -1.23 permits 1.23 permits(-1.23) - permits '12.34', as: 12.34 - permits '-12.34', as: -12.34 + permits "12.34", as: 12.34 + permits "-12.34", as: -12.34 permits 12.34 permits(-12.34) permits 1 permits(-1) - permits '1', as: 1 - permits '-1', as: -1 + permits "1", as: 1 + permits "-1", as: -1 - permits '1.2', as: 1.2 - permits '-1.2', as: -1.2 + permits "1.2", as: 1.2 + permits "-1.2", as: -1.2 permits 1.2 permits(-1.2) - rejects '123', as: 123 - rejects '-123', as: -123 + rejects "123", as: 123 + rejects "-123", as: -123 rejects 123 rejects(-123) - rejects 'abc' - rejects '1.2.3' - rejects '.3' - rejects '3.' + rejects "abc" + rejects "1.2.3" + rejects ".3" + rejects "3." rejects true - rejects '1234', as: 1234 - rejects '-1234', as: -1234 + rejects "1234", as: 1234 + rejects "-1234", as: -1234 rejects 1234 rejects(-1234) - rejects '1.234', as: 1.234 - rejects '-1.234', as: -1.234 + rejects "1.234", as: 1.234 + rejects "-1.234", as: -1.234 rejects 1.234 rejects(-1.234) - rejects '123.45', as: 123.45 - rejects '-123.45', as: 123.45 + rejects "123.45", as: 123.45 + rejects "-123.45", as: 123.45 rejects 123.45 rejects(-123.45) end - describe 'with 0 scale and 5 precision' do + describe "with 0 scale and 5 precision" do subject { ActionController::Parameters.decimal(5, 0) } permits 1 - permits '1', as: 1 + permits "1", as: 1 permits(-1) - permits '-1', as: -1 + permits "-1", as: -1 permits 12345 - permits '12345', as: 12345 + permits "12345", as: 12345 permits(-12345) - permits '-12345', as: -12345 + permits "-12345", as: -12345 - rejects 'abc' - rejects '1.2.3' - rejects '.3' - rejects '3.' + rejects "abc" + rejects "1.2.3" + rejects ".3" + rejects "3." rejects true - rejects '1.23', as: 1.23 - rejects '-1.23', as: -1.23 + rejects "1.23", as: 1.23 + rejects "-1.23", as: -1.23 rejects 1.23 rejects(-1.23) rejects 123456 - rejects '123456', as: 123456 + rejects "123456", as: 123456 rejects(-123456) - rejects '-123456', as: -123456 + rejects "-123456", as: -123456 end end diff --git a/test/stronger_parameters/constraints/enumeration_constraint_test.rb b/test/stronger_parameters/constraints/enumeration_constraint_test.rb index 601ab28..4d5a86d 100644 --- a/test/stronger_parameters/constraints/enumeration_constraint_test.rb +++ b/test/stronger_parameters/constraints/enumeration_constraint_test.rb @@ -1,22 +1,22 @@ # frozen_string_literal: true -require_relative '../../test_helper' +require_relative "../../test_helper" SingleCov.covered! -describe 'enum parameter constraints' do - subject { ActionController::Parameters.enumeration('abc', 123) } +describe "enum parameter constraints" do + subject { ActionController::Parameters.enumeration("abc", 123) } - permits 'abc' + permits "abc" permits 123 - rejects 'abcd' - rejects '123' + rejects "abcd" + rejects "123" rejects 1234 rejects nil describe "#==" do it "is the same with same limit" do - subject.must_equal StrongerParameters::EnumerationConstraint.new('abc', 123) + subject.must_equal StrongerParameters::EnumerationConstraint.new("abc", 123) end it "is not the same with different limit" do diff --git a/test/stronger_parameters/constraints/file_constraint_test.rb b/test/stronger_parameters/constraints/file_constraint_test.rb index db9dc59..26289fa 100644 --- a/test/stronger_parameters/constraints/file_constraint_test.rb +++ b/test/stronger_parameters/constraints/file_constraint_test.rb @@ -1,15 +1,15 @@ # frozen_string_literal: true -require_relative '../../test_helper' +require_relative "../../test_helper" SingleCov.covered! -describe 'io parameter constraints' do +describe "io parameter constraints" do subject { ActionController::Parameters.file } - permits StringIO.new('test') - permits File.new('.') - permits Rack::Test::UploadedFile.new('./README.md') - permits ActionDispatch::Http::UploadedFile.new(tempfile: Tempfile.new('test')) + permits StringIO.new("test") + permits File.new(".") + permits Rack::Test::UploadedFile.new("./README.md") + permits ActionDispatch::Http::UploadedFile.new(tempfile: Tempfile.new("test")) rejects 123 rejects Date.today diff --git a/test/stronger_parameters/constraints/float_constraint_test.rb b/test/stronger_parameters/constraints/float_constraint_test.rb index c4fbbee..a88b408 100644 --- a/test/stronger_parameters/constraints/float_constraint_test.rb +++ b/test/stronger_parameters/constraints/float_constraint_test.rb @@ -1,9 +1,9 @@ # frozen_string_literal: true -require_relative '../../test_helper' +require_relative "../../test_helper" SingleCov.covered! -describe 'float parameter constraints' do +describe "float parameter constraints" do subject { ActionController::Parameters.float } permits "1.2", as: 1.2 @@ -12,11 +12,11 @@ permits(-1.2) rejects 1 - rejects '1' - rejects '-1' - rejects 'abc' - rejects '1.2.3' - rejects '.3' - rejects '3.' + rejects "1" + rejects "-1" + rejects "abc" + rejects "1.2.3" + rejects ".3" + rejects "3." rejects true end diff --git a/test/stronger_parameters/constraints/hash_constraint_test.rb b/test/stronger_parameters/constraints/hash_constraint_test.rb index bba5edd..7983efe 100644 --- a/test/stronger_parameters/constraints/hash_constraint_test.rb +++ b/test/stronger_parameters/constraints/hash_constraint_test.rb @@ -1,5 +1,5 @@ # frozen_string_literal: true -require_relative '../../test_helper' +require_relative "../../test_helper" SingleCov.covered! @@ -26,39 +26,39 @@ def self.permits(value, options = {}) constraint.value(foo: "bar").must_equal(expected) end - describe 'map parameter constraints' do - permits(id: 1, name: 'Mick') - permits({id: '1', name: 'Mick'}, as: {id: 1, name: 'Mick'}) + describe "map parameter constraints" do + permits(id: 1, name: "Mick") + permits({id: "1", name: "Mick"}, as: {id: 1, name: "Mick"}) permits(id: 1) - permits({id: '1'}, as: {id: 1}) - permits(name: 'Mick') + permits({id: "1"}, as: {id: 1}) + permits(name: "Mick") rejects({id: 1, name: 123}, key: :name) - rejects({id: 'Mick', name: 'Mick'}, key: :id) + rejects({id: "Mick", name: "Mick"}, key: :id) rejects(123) - rejects('abc') + rejects("abc") rejects nil end - describe 'open-ended map parameter constraints' do + describe "open-ended map parameter constraints" do subject { ActionController::Parameters.map } - permits(id: 1, name: 'Mick') - permits("id" => 1, "name" => 'Mick') + permits(id: 1, name: "Mick") + permits("id" => 1, "name" => "Mick") rejects("a string") rejects(123) rejects nil end - describe 'merged constraints' do + describe "merged constraints" do describe "hash" do subject do ActionController::Parameters.map(id: ActionController::Parameters.integer). merge(ActionController::Parameters.map(name: ActionController::Parameters.string)) end - permits(id: 1, name: 'Mick') - rejects({id: 'Mick', foo: 'Mick'}, key: :id) # TODO: key: :id is wrong + permits(id: 1, name: "Mick") + rejects({id: "Mick", foo: "Mick"}, key: :id) # TODO: key: :id is wrong end describe "other" do @@ -67,8 +67,8 @@ def self.permits(value, options = {}) merge(name: ActionController::Parameters.string) end - permits(id: 1, name: 'Mick') - rejects({id: 'Mick', foo: 'Mick'}, key: :id) # TODO: key: :id is wrong + permits(id: 1, name: "Mick") + rejects({id: "Mick", foo: "Mick"}, key: :id) # TODO: key: :id is wrong end end diff --git a/test/stronger_parameters/constraints/hex_constraint_test.rb b/test/stronger_parameters/constraints/hex_constraint_test.rb index b9666e2..a4b7e66 100644 --- a/test/stronger_parameters/constraints/hex_constraint_test.rb +++ b/test/stronger_parameters/constraints/hex_constraint_test.rb @@ -1,16 +1,16 @@ # frozen_string_literal: true -require_relative '../../test_helper' +require_relative "../../test_helper" SingleCov.covered! -describe 'hexadecimal parameter constraints' do +describe "hexadecimal parameter constraints" do subject { ActionController::Parameters.hex } - permits 'DEADbeef' - permits 'abcdef0123456789' + permits "DEADbeef" + permits "abcdef0123456789" - rejects 'abcxyz' - rejects '' + rejects "abcxyz" + rejects "" rejects 123 rejects false rejects [1] diff --git a/test/stronger_parameters/constraints/integer_constraint_test.rb b/test/stronger_parameters/constraints/integer_constraint_test.rb index 9356fda..1bc24a4 100644 --- a/test/stronger_parameters/constraints/integer_constraint_test.rb +++ b/test/stronger_parameters/constraints/integer_constraint_test.rb @@ -1,20 +1,20 @@ # frozen_string_literal: true -require_relative '../../test_helper' +require_relative "../../test_helper" SingleCov.covered! -describe 'integer parameter constraints' do +describe "integer parameter constraints" do subject { ActionController::Parameters.integer } permits 123 permits 2**64 - permits '123', as: 123 - permits '-123', as: -123 - permits ' 123', as: 123 + permits "123", as: 123 + permits "-123", as: -123 + permits " 123", as: 123 - rejects 'abc' + rejects "abc" rejects Date.today rejects Time.now rejects nil - rejects ' ' + rejects " " end diff --git a/test/stronger_parameters/constraints/nil_constraint_test.rb b/test/stronger_parameters/constraints/nil_constraint_test.rb index 073d5cc..69c9eb6 100644 --- a/test/stronger_parameters/constraints/nil_constraint_test.rb +++ b/test/stronger_parameters/constraints/nil_constraint_test.rb @@ -1,14 +1,14 @@ # frozen_string_literal: true -require_relative '../../test_helper' +require_relative "../../test_helper" SingleCov.covered! -describe 'nil parameter constraints' do +describe "nil parameter constraints" do subject { ActionController::Parameters.nil } permits nil - rejects 'abc' + rejects "abc" rejects 1 rejects false end diff --git a/test/stronger_parameters/constraints/nil_string_constraint_test.rb b/test/stronger_parameters/constraints/nil_string_constraint_test.rb index 30eca6a..62daa98 100644 --- a/test/stronger_parameters/constraints/nil_string_constraint_test.rb +++ b/test/stronger_parameters/constraints/nil_string_constraint_test.rb @@ -1,14 +1,14 @@ # frozen_string_literal: true -require_relative '../../test_helper' +require_relative "../../test_helper" SingleCov.covered! -describe 'nil_string parameter constraints' do +describe "nil_string parameter constraints" do subject { ActionController::Parameters.nil_string } - permits '', as: nil - permits 'undefined', as: nil + permits "", as: nil + permits "undefined", as: nil permits nil - rejects 'foo' + rejects "foo" end diff --git a/test/stronger_parameters/constraints/regexp_constraint_test.rb b/test/stronger_parameters/constraints/regexp_constraint_test.rb index 98d901f..f59b0b4 100644 --- a/test/stronger_parameters/constraints/regexp_constraint_test.rb +++ b/test/stronger_parameters/constraints/regexp_constraint_test.rb @@ -1,17 +1,17 @@ # frozen_string_literal: true -require_relative '../../test_helper' +require_relative "../../test_helper" SingleCov.covered! -describe 'regexp parameter constraints' do +describe "regexp parameter constraints" do subject { ActionController::Parameters.regexp(/\Aab?c\Z/) } - permits 'abc' - permits 'ac' + permits "abc" + permits "ac" rejects 123 rejects nil - rejects 'abbc' + rejects "abbc" it "rejects non-strings with string constraint" do subject.value(123).message.must_equal "must be a string" diff --git a/test/stronger_parameters/constraints/string_constraint_test.rb b/test/stronger_parameters/constraints/string_constraint_test.rb index d479c73..9f2e4de 100644 --- a/test/stronger_parameters/constraints/string_constraint_test.rb +++ b/test/stronger_parameters/constraints/string_constraint_test.rb @@ -1,25 +1,25 @@ # frozen_string_literal: true -require_relative '../../test_helper' +require_relative "../../test_helper" SingleCov.covered! describe StrongerParameters::StringConstraint do subject { ActionController::Parameters.string } - permits 'abc' + permits "abc" rejects 123 rejects Date.today rejects Time.now rejects nil - rejects "\xA1".dup.force_encoding('UTF-8') + rejects "\xA1".dup.force_encoding("UTF-8") - it 'rejects strings that are too long' do - assert_rejects(:value) { params(value: '123').permit(value: ActionController::Parameters.string(max_length: 2)) } + it "rejects strings that are too long" do + assert_rejects(:value) { params(value: "123").permit(value: ActionController::Parameters.string(max_length: 2)) } end - it 'rejects strings that are too short' do - assert_rejects(:value) { params(value: '1234').permit(value: ActionController::Parameters.string(min_length: 5)) } + it "rejects strings that are too short" do + assert_rejects(:value) { params(value: "1234").permit(value: ActionController::Parameters.string(min_length: 5)) } end describe "#==" do diff --git a/test/stronger_parameters/constraints/time_constraint_test.rb b/test/stronger_parameters/constraints/time_constraint_test.rb index f8804dc..2ae4967 100644 --- a/test/stronger_parameters/constraints/time_constraint_test.rb +++ b/test/stronger_parameters/constraints/time_constraint_test.rb @@ -1,9 +1,9 @@ # frozen_string_literal: true -require_relative '../../test_helper' +require_relative "../../test_helper" SingleCov.covered! -describe 'time parameter constraints' do +describe "time parameter constraints" do subject { ActionController::Parameters.time } permits Time.parse("2015-03-31"), as: Time.parse("2015-03-31") diff --git a/test/stronger_parameters/constraints/time_iso8601_constraint_test.rb b/test/stronger_parameters/constraints/time_iso8601_constraint_test.rb index c08f64c..64549f1 100644 --- a/test/stronger_parameters/constraints/time_iso8601_constraint_test.rb +++ b/test/stronger_parameters/constraints/time_iso8601_constraint_test.rb @@ -1,9 +1,9 @@ # frozen_string_literal: true -require_relative '../../test_helper' +require_relative "../../test_helper" SingleCov.covered! -describe 'date parameter constraints' do +describe "date parameter constraints" do subject { ActionController::Parameters.time_iso8601 } permits "2018-04-12T08:53:18+00:00", as: Time.iso8601("2018-04-12T08:53:18+00:00") diff --git a/test/stronger_parameters/constraints/ulid_constraint_test.rb b/test/stronger_parameters/constraints/ulid_constraint_test.rb index 3927760..35c9cbb 100644 --- a/test/stronger_parameters/constraints/ulid_constraint_test.rb +++ b/test/stronger_parameters/constraints/ulid_constraint_test.rb @@ -1,5 +1,5 @@ # frozen_string_literal: true -require_relative '../../test_helper' +require_relative "../../test_helper" SingleCov.covered! @@ -9,13 +9,13 @@ rejects Date.today rejects Time.now rejects nil - rejects '01GTJ6C0NF1MQX0KFZMS1RHTY' # short - rejects '01GTJ6C0NF1MQX0KFZMS1RHT-!' # special char - rejects '0IGTJ6C0NF1MQX0KFZMS1RHTYF' # i - rejects '0LGTJ6C0NF1MQX0KFZMS1RHTYF' # l - rejects 'O1GTJ6C0NF1MQX0KFZMS1RHTYF' # o - rejects '01GTJ6C0NF1MQX0KFZMS1RHTYU' # u + rejects "01GTJ6C0NF1MQX0KFZMS1RHTY" # short + rejects "01GTJ6C0NF1MQX0KFZMS1RHT-!" # special char + rejects "0IGTJ6C0NF1MQX0KFZMS1RHTYF" # i + rejects "0LGTJ6C0NF1MQX0KFZMS1RHTYF" # l + rejects "O1GTJ6C0NF1MQX0KFZMS1RHTYF" # o + rejects "01GTJ6C0NF1MQX0KFZMS1RHTYU" # u - permits '01GTJ6C0NF1MQX0KFZMS1RHTYF' - permits '01GTJ6C0NF1MQX0KFZMS1RHTYF'.downcase + permits "01GTJ6C0NF1MQX0KFZMS1RHTYF" + permits "01GTJ6C0NF1MQX0KFZMS1RHTYF".downcase end diff --git a/test/stronger_parameters/constraints_test.rb b/test/stronger_parameters/constraints_test.rb index dd30cde..794320a 100644 --- a/test/stronger_parameters/constraints_test.rb +++ b/test/stronger_parameters/constraints_test.rb @@ -1,4 +1,4 @@ # frozen_string_literal: true -require_relative '../test_helper' +require_relative "../test_helper" SingleCov.covered! diff --git a/test/stronger_parameters/controller_support/permitted_parameters_test.rb b/test/stronger_parameters/controller_support/permitted_parameters_test.rb index 9a7a113..be6b696 100644 --- a/test/stronger_parameters/controller_support/permitted_parameters_test.rb +++ b/test/stronger_parameters/controller_support/permitted_parameters_test.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -require_relative '../../test_helper' -require 'stronger_parameters/controller_support/permitted_parameters' +require_relative "../../test_helper" +require "stronger_parameters/controller_support/permitted_parameters" SingleCov.covered! @@ -43,23 +43,23 @@ def show WhitelistsController.log_unpermitted_parameters = false end - describe '.sugar' do - it 'turns Array into Parameters.array' do + describe ".sugar" do + it "turns Array into Parameters.array" do WhitelistsController.permitted_parameters :foo, ticket: [ActionController::Parameters.integer] constraint = WhitelistsController.permitted_parameters_for(:foo)[:ticket] assert_instance_of StrongerParameters::ArrayConstraint, constraint assert_equal ActionController::Parameters.integer, constraint.item_constraint end - it 'turns Hash into Parameters.map' do + it "turns Hash into Parameters.map" do WhitelistsController.permitted_parameters :foo, ticket: { id: ActionController::Parameters.integer } constraint = WhitelistsController.permitted_parameters_for(:foo)[:ticket] assert_instance_of StrongerParameters::HashConstraint, constraint - assert_equal({ 'id' => ActionController::Parameters.integer }, constraint.constraints) + assert_equal({ "id" => ActionController::Parameters.integer }, constraint.constraints) end end - describe '.permitted_parameters' do + describe ".permitted_parameters" do before do WhitelistsController.permitted_parameters :all, user_id: ActionController::Parameters.integer WhitelistsController.permitted_parameters :foo, ticket_id: ActionController::Parameters.integer @@ -68,12 +68,12 @@ def show WhitelistsController.permitted_parameters :bar, nested: {b: ActionController::Parameters.integer} end - it 'allows general whitelisting' do + it "allows general whitelisting" do WhitelistsController.permitted_parameters_for(:foo)[:user_id].must_equal ActionController::Parameters.integer WhitelistsController.permitted_parameters_for(:bar)[:user_id].must_equal ActionController::Parameters.integer end - it 'allows nested whitelisting' do + it "allows nested whitelisting" do WhitelistsController.permitted_parameters_for(:foo)[:ticket_id].must_equal ActionController::Parameters.integer WhitelistsController.permitted_parameters_for(:foo)[:group_id].must_be_nil @@ -81,13 +81,13 @@ def show WhitelistsController.permitted_parameters_for(:bar)[:ticket_id].must_be_nil end - it 'allows merging' do + it "allows merging" do WhitelistsController.permitted_parameters_for(:bar)[:nested].constraints.must_equal( "a" => ActionController::Parameters.integer, "b" => ActionController::Parameters.integer ) end - describe 'inheritance' do + describe "inheritance" do let(:child_controller) { Class.new(WhitelistsController) } before do @@ -96,7 +96,7 @@ def show child_controller.permitted_parameters :create, last: ActionController::Parameters.string end - it 'inherits from parent to child' do + it "inherits from parent to child" do WhitelistsController.permitted_parameters_for(:create)[:first]. must_be_instance_of StrongerParameters::StringConstraint child_controller.permitted_parameters_for(:create)[:first]. @@ -104,7 +104,7 @@ def show assert_equal true, child_controller.log_unpermitted_parameters end - it 'does not inherit from child to parent' do + it "does not inherit from child to parent" do assert_nil WhitelistsController.permitted_parameters_for(:create)[:last] child_controller.permitted_parameters_for(:create)[:last]. must_be_instance_of StrongerParameters::StringConstraint @@ -112,12 +112,12 @@ def show end end - describe '#permit_parameters' do + describe "#permit_parameters" do def do_request - get :index, params: parameters, format: 'png' + get :index, params: parameters, format: "png" end - let(:parameters) { {id: '4', authenticity_token: 'auth'} } + let(:parameters) { {id: "4", authenticity_token: "auth"} } before do WhitelistsController.permitted_parameters( @@ -127,7 +127,7 @@ def do_request ) end - it 'does not filter default params' do + it "does not filter default params" do do_request assert_response :success @controller.params.to_h.must_equal( @@ -138,7 +138,7 @@ def do_request ) end - it 'filters request.params' do + it "filters request.params" do do_request assert_response :success @controller.request.params.must_equal( @@ -170,16 +170,16 @@ def do_request @controller.params.to_h["user"]["name"].must_equal("so" => "evil") end - it 'raises when action is not configured' do + it "raises when action is not configured" do assert_raises(KeyError) { get :show, params: {id: 1} } end - it 'raises proper exception even if action is not defined (and not configured)' do - @controller.params.merge!(action: 'ops_not_here', id: 1) + it "raises proper exception even if action is not defined (and not configured)" do + @controller.params.merge!(action: "ops_not_here", id: 1) assert_raises(KeyError) { @controller.send(:permit_parameters) } end - it 'overrides :skip' do + it "overrides :skip" do WhitelistsController.permitted_parameters :index, :skip WhitelistsController.permitted_parameters :index, bar: ActionController::Parameters.boolean get :index, params: {bar: true} @@ -219,13 +219,13 @@ def do_request end end - describe 'headers' do - before { Rails.configuration.stronger_parameters_violation_header = 'X-StrongerParameters-API-Warn' } + describe "headers" do + before { Rails.configuration.stronger_parameters_violation_header = "X-StrongerParameters-API-Warn" } after { Rails.configuration.stronger_parameters_violation_header = nil } - it 'warns about filtered parms' do + it "warns about filtered parms" do do_request - @controller.response.headers['X-StrongerParameters-API-Warn'].must_equal( + @controller.response.headers["X-StrongerParameters-API-Warn"].must_equal( "Removed restricted keys [\"id\"] from parameters according to permitted list" ) end @@ -233,7 +233,7 @@ def do_request it "warns about unfiltered parameters" do WhitelistsController.log_unpermitted_parameters = true do_request - @controller.response.headers['X-StrongerParameters-API-Warn'].must_equal( + @controller.response.headers["X-StrongerParameters-API-Warn"].must_equal( "Found restricted keys [\"id\"] from parameters according to permitted list" ) end @@ -242,21 +242,21 @@ def do_request Rails.configuration.stub(:respond_to?, nil) do do_request end - refute @controller.response.headers['X-StrongerParameters-API-Warn'] + refute @controller.response.headers["X-StrongerParameters-API-Warn"] end - it 'warns about nil values' do + it "warns about nil values" do @controller.params[:id] = nil do_request - @controller.response.headers['X-StrongerParameters-API-Warn'].must_equal( + @controller.response.headers["X-StrongerParameters-API-Warn"].must_equal( "Removed restricted keys [\"id\"] from parameters according to permitted list" ) end - it 'does not warn when not configured' do + it "does not warn when not configured" do Rails.configuration.stronger_parameters_violation_header = nil do_request - refute @controller.response.headers.key?('X-StrongerParameters-API-Warn') + refute @controller.response.headers.key?("X-StrongerParameters-API-Warn") end end end diff --git a/test/stronger_parameters/errors_test.rb b/test/stronger_parameters/errors_test.rb index 56f5555..b2d2449 100644 --- a/test/stronger_parameters/errors_test.rb +++ b/test/stronger_parameters/errors_test.rb @@ -1,5 +1,5 @@ # frozen_string_literal: true -require_relative '../test_helper' +require_relative "../test_helper" SingleCov.covered! diff --git a/test/stronger_parameters/parameters_test.rb b/test/stronger_parameters/parameters_test.rb index 5a8b2a7..4ef4a50 100644 --- a/test/stronger_parameters/parameters_test.rb +++ b/test/stronger_parameters/parameters_test.rb @@ -1,5 +1,5 @@ # frozen_string_literal: true -require_relative '../test_helper' +require_relative "../test_helper" SingleCov.covered! uncovered: 3 # Covered in test/controller_test.rb @@ -7,7 +7,7 @@ describe ".anything" do subject { ActionController::Parameters.anything } - permits '1' + permits "1" permits 1 permits [] end @@ -166,59 +166,59 @@ describe ".bigid" do subject { ActionController::Parameters.bigid } - permits '1', as: 1 + permits "1", as: 1 permits 1 permits (2**63) - 1 rejects(-1) - rejects 'a' + rejects "a" rejects 2**63 end describe ".id" do subject { ActionController::Parameters.id } - permits '1', as: 1 + permits "1", as: 1 permits 1 permits (2**31) - 1 rejects(-1) - rejects 'a' + rejects "a" rejects 2**31 end describe ".ubigid" do subject { ActionController::Parameters.ubigid } - permits '1', as: 1 + permits "1", as: 1 permits 1 permits (2**64) - 1 rejects(-1) - rejects 'a' + rejects "a" rejects 2**64 end describe ".uid" do subject { ActionController::Parameters.uid } - permits '1', as: 1 + permits "1", as: 1 permits 1 permits (2**32) - 1 rejects(-1) - rejects 'a' + rejects "a" rejects 2**32 end describe ".integer32" do subject { ActionController::Parameters.integer32 } - permits '1', as: 1 + permits "1", as: 1 permits (2**31) - 1 permits(-2**31) - rejects 'a' + rejects "a" rejects 2**31 rejects(-2**31 - 1) end @@ -226,11 +226,11 @@ describe ".integer64" do subject { ActionController::Parameters.integer64 } - permits '1', as: 1 + permits "1", as: 1 permits (2**63) - 1 permits(-2**63) - rejects 'a' + rejects "a" rejects 2**63 rejects(-2**63 - 1) end diff --git a/test/stronger_parameters/version_test.rb b/test/stronger_parameters/version_test.rb index 49d6814..fcee662 100644 --- a/test/stronger_parameters/version_test.rb +++ b/test/stronger_parameters/version_test.rb @@ -1,5 +1,5 @@ # frozen_string_literal: true -require_relative '../test_helper' +require_relative "../test_helper" SingleCov.not_covered! # loaded before SingleCov is loaded diff --git a/test/stronger_parameters_test.rb b/test/stronger_parameters_test.rb index e734cdb..52f456c 100644 --- a/test/stronger_parameters_test.rb +++ b/test/stronger_parameters_test.rb @@ -1,4 +1,4 @@ # frozen_string_literal: true -require_relative 'test_helper' +require_relative "test_helper" SingleCov.covered! diff --git a/test/test_helper.rb b/test/test_helper.rb index cc10dee..bf1a852 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -1,29 +1,29 @@ # frozen_string_literal: true ENV["RAILS_ENV"] = "test" -require 'bundler/setup' +require "bundler/setup" -require 'single_cov' +require "single_cov" SingleCov.setup :minitest -require 'maxitest/global_must' -require 'maxitest/autorun' -require 'rails' -require 'action_controller' -require 'rails/generators' +require "maxitest/global_must" +require "maxitest/autorun" +require "rails" +require "action_controller" +require "rails/generators" class FakeApplication < Rails::Application; end Rails.application = FakeApplication Rails.configuration.action_controller = ActiveSupport::OrderedOptions.new -Rails.configuration.secret_key_base = 'secret_key_base' +Rails.configuration.secret_key_base = "secret_key_base" Rails.logger = Logger.new("/dev/null") ActiveSupport.test_order = :random if ActiveSupport.respond_to?(:test_order=) -require 'action_pack' -require 'stronger_parameters' -require 'minitest/rails' +require "action_pack" +require "stronger_parameters" +require "minitest/rails" # Use ActionController::TestCase for Controllers Minitest::Spec::DSL::TYPES.unshift [/Controller$/, ActionController::TestCase] From ddecab1191e897dfb1e3fceec774e2782495f261 Mon Sep 17 00:00:00 2001 From: Benjamin Quorning Date: Fri, 17 Nov 2023 23:55:03 +0100 Subject: [PATCH 3/5] Standard: Fix Layout offenses --- .standard_todo.yml | 146 ------------------ Gemfile | 1 + Rakefile | 1 + gemfiles/common.rb | 1 + gemfiles/rails5.0.gemfile | 1 + gemfiles/rails5.1.gemfile | 1 + gemfiles/rails5.2.gemfile | 1 + gemfiles/rails6.0.gemfile | 1 + gemfiles/rails6.1.gemfile | 1 + gemfiles/rails7.0.gemfile | 1 + gemfiles/rails7.1.gemfile | 1 + lib/stronger_parameters.rb | 1 + lib/stronger_parameters/constraint.rb | 1 + lib/stronger_parameters/constraints.rb | 1 + .../constraints/array_constraint.rb | 1 + .../constraints/boolean_constraint.rb | 3 +- .../constraints/comparison_constraints.rb | 1 + .../constraints/date_constraint.rb | 1 + .../constraints/date_iso8601_constraint.rb | 1 + .../constraints/date_time_constraint.rb | 1 + .../date_time_iso8601_constraint.rb | 1 + .../constraints/decimal_constraint.rb | 1 + .../constraints/enumeration_constraint.rb | 1 + .../constraints/file_constraint.rb | 1 + .../constraints/float_constraint.rb | 1 + .../constraints/hash_constraint.rb | 1 + .../constraints/hex_constraint.rb | 1 + .../constraints/integer_constraint.rb | 1 + .../constraints/nil_constraint.rb | 1 + .../constraints/nil_string_constraint.rb | 1 + .../constraints/regexp_constraint.rb | 1 + .../constraints/string_constraint.rb | 1 + .../constraints/time_constraint.rb | 1 + .../constraints/time_iso8601_constraint.rb | 1 + .../constraints/ulid_constraint.rb | 1 + .../permitted_parameters.rb | 1 + lib/stronger_parameters/errors.rb | 1 + lib/stronger_parameters/parameters.rb | 5 +- lib/stronger_parameters/version.rb | 1 + stronger_parameters.gemspec | 17 +- test/benchmark.rb | 1 + test/controller_test.rb | 3 +- test/coverage_test.rb | 1 + test/stronger_parameters/constraint_test.rb | 9 +- .../constraints/array_constraint_test.rb | 1 + .../constraints/boolean_constraint_test.rb | 19 +-- .../comparison_constraints_test.rb | 1 + .../constraints/date_constraint_test.rb | 1 + .../date_iso8601_constraint_test.rb | 1 + .../constraints/date_time_constraint_test.rb | 1 + .../date_time_iso8601_constraint_test.rb | 1 + .../constraints/decimal_constraint_test.rb | 1 + .../enumeration_constraint_test.rb | 1 + .../constraints/file_constraint_test.rb | 1 + .../constraints/float_constraint_test.rb | 1 + .../constraints/hash_constraint_test.rb | 9 +- .../constraints/hex_constraint_test.rb | 1 + .../constraints/integer_constraint_test.rb | 1 + .../constraints/nil_constraint_test.rb | 1 + .../constraints/nil_string_constraint_test.rb | 1 + .../constraints/regexp_constraint_test.rb | 1 + .../constraints/string_constraint_test.rb | 1 + .../constraints/time_constraint_test.rb | 1 + .../time_iso8601_constraint_test.rb | 1 + .../constraints/ulid_constraint_test.rb | 1 + test/stronger_parameters/constraints_test.rb | 1 + .../permitted_parameters_test.rb | 19 +-- test/stronger_parameters/errors_test.rb | 1 + test/stronger_parameters/parameters_test.rb | 9 +- test/stronger_parameters/version_test.rb | 1 + test/stronger_parameters_test.rb | 1 + test/test_helper.rb | 1 + 72 files changed, 113 insertions(+), 188 deletions(-) diff --git a/.standard_todo.yml b/.standard_todo.yml index fb607b9..ba3eea7 100644 --- a/.standard_todo.yml +++ b/.standard_todo.yml @@ -2,163 +2,17 @@ # Remove from this list as you refactor files. --- ignore: -- Gemfile: - - Layout/EmptyLineAfterMagicComment -- Rakefile: - - Layout/EmptyLineAfterMagicComment -- gemfiles/common.rb: - - Layout/EmptyLineAfterMagicComment -- gemfiles/rails5.0.gemfile: - - Layout/EmptyLineAfterMagicComment -- gemfiles/rails5.1.gemfile: - - Layout/EmptyLineAfterMagicComment -- gemfiles/rails5.2.gemfile: - - Layout/EmptyLineAfterMagicComment -- gemfiles/rails6.0.gemfile: - - Layout/EmptyLineAfterMagicComment -- gemfiles/rails6.1.gemfile: - - Layout/EmptyLineAfterMagicComment -- gemfiles/rails7.0.gemfile: - - Layout/EmptyLineAfterMagicComment -- gemfiles/rails7.1.gemfile: - - Layout/EmptyLineAfterMagicComment -- lib/stronger_parameters.rb: - - Layout/EmptyLineAfterMagicComment -- lib/stronger_parameters/constraint.rb: - - Layout/EmptyLineAfterMagicComment -- lib/stronger_parameters/constraints.rb: - - Layout/EmptyLineAfterMagicComment -- lib/stronger_parameters/constraints/array_constraint.rb: - - Layout/EmptyLineAfterMagicComment -- lib/stronger_parameters/constraints/boolean_constraint.rb: - - Layout/EmptyLineAfterMagicComment - - Layout/ExtraSpacing -- lib/stronger_parameters/constraints/comparison_constraints.rb: - - Layout/EmptyLineAfterMagicComment -- lib/stronger_parameters/constraints/date_constraint.rb: - - Layout/EmptyLineAfterMagicComment -- lib/stronger_parameters/constraints/date_iso8601_constraint.rb: - - Layout/EmptyLineAfterMagicComment -- lib/stronger_parameters/constraints/date_time_constraint.rb: - - Layout/EmptyLineAfterMagicComment -- lib/stronger_parameters/constraints/date_time_iso8601_constraint.rb: - - Layout/EmptyLineAfterMagicComment - lib/stronger_parameters/constraints/decimal_constraint.rb: - - Layout/EmptyLineAfterMagicComment - Performance/RegexpMatch -- lib/stronger_parameters/constraints/enumeration_constraint.rb: - - Layout/EmptyLineAfterMagicComment -- lib/stronger_parameters/constraints/file_constraint.rb: - - Layout/EmptyLineAfterMagicComment -- lib/stronger_parameters/constraints/float_constraint.rb: - - Layout/EmptyLineAfterMagicComment -- lib/stronger_parameters/constraints/hash_constraint.rb: - - Layout/EmptyLineAfterMagicComment -- lib/stronger_parameters/constraints/hex_constraint.rb: - - Layout/EmptyLineAfterMagicComment -- lib/stronger_parameters/constraints/integer_constraint.rb: - - Layout/EmptyLineAfterMagicComment -- lib/stronger_parameters/constraints/nil_constraint.rb: - - Layout/EmptyLineAfterMagicComment -- lib/stronger_parameters/constraints/nil_string_constraint.rb: - - Layout/EmptyLineAfterMagicComment - lib/stronger_parameters/constraints/regexp_constraint.rb: - - Layout/EmptyLineAfterMagicComment - Performance/RegexpMatch -- lib/stronger_parameters/constraints/string_constraint.rb: - - Layout/EmptyLineAfterMagicComment -- lib/stronger_parameters/constraints/time_constraint.rb: - - Layout/EmptyLineAfterMagicComment -- lib/stronger_parameters/constraints/time_iso8601_constraint.rb: - - Layout/EmptyLineAfterMagicComment - lib/stronger_parameters/constraints/ulid_constraint.rb: - - Layout/EmptyLineAfterMagicComment - Performance/RegexpMatch - lib/stronger_parameters/controller_support/permitted_parameters.rb: - - Layout/EmptyLineAfterMagicComment - Lint/AssignmentInCondition -- lib/stronger_parameters/errors.rb: - - Layout/EmptyLineAfterMagicComment - lib/stronger_parameters/parameters.rb: - - Layout/EmptyLineAfterMagicComment - Style/Alias - - Layout/ExtraSpacing - - Layout/SpaceInsideHashLiteralBraces -- lib/stronger_parameters/version.rb: - - Layout/EmptyLineAfterMagicComment -- stronger_parameters.gemspec: - - Layout/EmptyLineAfterMagicComment - - Layout/ExtraSpacing -- test/benchmark.rb: - - Layout/EmptyLineAfterMagicComment -- test/controller_test.rb: - - Layout/EmptyLineAfterMagicComment - - Layout/SpaceInsideHashLiteralBraces -- test/coverage_test.rb: - - Layout/EmptyLineAfterMagicComment -- test/stronger_parameters/constraint_test.rb: - - Layout/EmptyLineAfterMagicComment - - Layout/MultilineOperationIndentation -- test/stronger_parameters/constraints/array_constraint_test.rb: - - Layout/EmptyLineAfterMagicComment -- test/stronger_parameters/constraints/boolean_constraint_test.rb: - - Layout/EmptyLineAfterMagicComment - - Layout/ExtraSpacing -- test/stronger_parameters/constraints/comparison_constraints_test.rb: - - Layout/EmptyLineAfterMagicComment -- test/stronger_parameters/constraints/date_constraint_test.rb: - - Layout/EmptyLineAfterMagicComment -- test/stronger_parameters/constraints/date_iso8601_constraint_test.rb: - - Layout/EmptyLineAfterMagicComment -- test/stronger_parameters/constraints/date_time_constraint_test.rb: - - Layout/EmptyLineAfterMagicComment -- test/stronger_parameters/constraints/date_time_iso8601_constraint_test.rb: - - Layout/EmptyLineAfterMagicComment -- test/stronger_parameters/constraints/decimal_constraint_test.rb: - - Layout/EmptyLineAfterMagicComment -- test/stronger_parameters/constraints/enumeration_constraint_test.rb: - - Layout/EmptyLineAfterMagicComment -- test/stronger_parameters/constraints/file_constraint_test.rb: - - Layout/EmptyLineAfterMagicComment -- test/stronger_parameters/constraints/float_constraint_test.rb: - - Layout/EmptyLineAfterMagicComment -- test/stronger_parameters/constraints/hash_constraint_test.rb: - - Layout/EmptyLineAfterMagicComment - - Layout/DotPosition -- test/stronger_parameters/constraints/hex_constraint_test.rb: - - Layout/EmptyLineAfterMagicComment -- test/stronger_parameters/constraints/integer_constraint_test.rb: - - Layout/EmptyLineAfterMagicComment -- test/stronger_parameters/constraints/nil_constraint_test.rb: - - Layout/EmptyLineAfterMagicComment -- test/stronger_parameters/constraints/nil_string_constraint_test.rb: - - Layout/EmptyLineAfterMagicComment -- test/stronger_parameters/constraints/regexp_constraint_test.rb: - - Layout/EmptyLineAfterMagicComment - test/stronger_parameters/constraints/string_constraint_test.rb: - - Layout/EmptyLineAfterMagicComment - Performance/UnfreezeString -- test/stronger_parameters/constraints/time_constraint_test.rb: - - Layout/EmptyLineAfterMagicComment -- test/stronger_parameters/constraints/time_iso8601_constraint_test.rb: - - Layout/EmptyLineAfterMagicComment -- test/stronger_parameters/constraints/ulid_constraint_test.rb: - - Layout/EmptyLineAfterMagicComment -- test/stronger_parameters/constraints_test.rb: - - Layout/EmptyLineAfterMagicComment - test/stronger_parameters/controller_support/permitted_parameters_test.rb: - - Layout/EmptyLineAfterMagicComment - - Layout/SpaceInsideHashLiteralBraces - - Layout/DotPosition - Performance/UnfreezeString -- test/stronger_parameters/errors_test.rb: - - Layout/EmptyLineAfterMagicComment -- test/stronger_parameters/parameters_test.rb: - - Layout/EmptyLineAfterMagicComment - - Layout/DotPosition -- test/stronger_parameters/version_test.rb: - - Layout/EmptyLineAfterMagicComment -- test/stronger_parameters_test.rb: - - Layout/EmptyLineAfterMagicComment -- test/test_helper.rb: - - Layout/EmptyLineAfterMagicComment diff --git a/Gemfile b/Gemfile index 2efe8f4..f9c7825 100644 --- a/Gemfile +++ b/Gemfile @@ -1,4 +1,5 @@ # frozen_string_literal: true + eval_gemfile Dir["gemfiles/*.gemfile"].max gem "minitest-rails", "~> 7.1" gem "minitest", "~> 5.20" diff --git a/Rakefile b/Rakefile index 95094d3..6819a94 100644 --- a/Rakefile +++ b/Rakefile @@ -1,4 +1,5 @@ # frozen_string_literal: true + require "bundler/setup" require "standard/rake" require "bump/tasks" diff --git a/gemfiles/common.rb b/gemfiles/common.rb index 651cba4..b82e83e 100644 --- a/gemfiles/common.rb +++ b/gemfiles/common.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + source "https://rubygems.org" gemspec path: ".." diff --git a/gemfiles/rails5.0.gemfile b/gemfiles/rails5.0.gemfile index 53dd0ca..337fc86 100644 --- a/gemfiles/rails5.0.gemfile +++ b/gemfiles/rails5.0.gemfile @@ -1,4 +1,5 @@ # frozen_string_literal: true + gem "rails", "~> 5.0.0" eval_gemfile "common.rb" diff --git a/gemfiles/rails5.1.gemfile b/gemfiles/rails5.1.gemfile index b46b927..b1d86e5 100644 --- a/gemfiles/rails5.1.gemfile +++ b/gemfiles/rails5.1.gemfile @@ -1,4 +1,5 @@ # frozen_string_literal: true + gem "rails", "~> 5.1.0" eval_gemfile "common.rb" diff --git a/gemfiles/rails5.2.gemfile b/gemfiles/rails5.2.gemfile index b048bc1..dfe563b 100644 --- a/gemfiles/rails5.2.gemfile +++ b/gemfiles/rails5.2.gemfile @@ -1,4 +1,5 @@ # frozen_string_literal: true + gem "rails", "~> 5.2.0" eval_gemfile "common.rb" diff --git a/gemfiles/rails6.0.gemfile b/gemfiles/rails6.0.gemfile index 57817aa..edaec37 100644 --- a/gemfiles/rails6.0.gemfile +++ b/gemfiles/rails6.0.gemfile @@ -1,4 +1,5 @@ # frozen_string_literal: true + gem "rails", "~> 6.0.0" eval_gemfile "common.rb" diff --git a/gemfiles/rails6.1.gemfile b/gemfiles/rails6.1.gemfile index 35fef85..8fda593 100644 --- a/gemfiles/rails6.1.gemfile +++ b/gemfiles/rails6.1.gemfile @@ -1,4 +1,5 @@ # frozen_string_literal: true + gem "rails", "~> 6.1.0" eval_gemfile "common.rb" diff --git a/gemfiles/rails7.0.gemfile b/gemfiles/rails7.0.gemfile index 5da5010..1695fb3 100644 --- a/gemfiles/rails7.0.gemfile +++ b/gemfiles/rails7.0.gemfile @@ -1,4 +1,5 @@ # frozen_string_literal: true + gem "rails", "~> 7.0.0" eval_gemfile "common.rb" diff --git a/gemfiles/rails7.1.gemfile b/gemfiles/rails7.1.gemfile index a6e7f39..c26a8a8 100644 --- a/gemfiles/rails7.1.gemfile +++ b/gemfiles/rails7.1.gemfile @@ -1,4 +1,5 @@ # frozen_string_literal: true + gem "rails", "~> 7.1.0" eval_gemfile "common.rb" diff --git a/lib/stronger_parameters.rb b/lib/stronger_parameters.rb index 3f1cf16..4b6b146 100644 --- a/lib/stronger_parameters.rb +++ b/lib/stronger_parameters.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + require "stronger_parameters/version" require "action_pack" require "stronger_parameters/parameters" diff --git a/lib/stronger_parameters/constraint.rb b/lib/stronger_parameters/constraint.rb index cce1893..589c179 100644 --- a/lib/stronger_parameters/constraint.rb +++ b/lib/stronger_parameters/constraint.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + require "stronger_parameters/errors" module StrongerParameters diff --git a/lib/stronger_parameters/constraints.rb b/lib/stronger_parameters/constraints.rb index 77675d2..f30f647 100644 --- a/lib/stronger_parameters/constraints.rb +++ b/lib/stronger_parameters/constraints.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + require "stronger_parameters/constraint" require "stronger_parameters/constraints/string_constraint" require "stronger_parameters/constraints/float_constraint" diff --git a/lib/stronger_parameters/constraints/array_constraint.rb b/lib/stronger_parameters/constraints/array_constraint.rb index 9a9a651..a5fa0b5 100644 --- a/lib/stronger_parameters/constraints/array_constraint.rb +++ b/lib/stronger_parameters/constraints/array_constraint.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + require "stronger_parameters/constraint" module StrongerParameters diff --git a/lib/stronger_parameters/constraints/boolean_constraint.rb b/lib/stronger_parameters/constraints/boolean_constraint.rb index 497bc84..e3b21e3 100644 --- a/lib/stronger_parameters/constraints/boolean_constraint.rb +++ b/lib/stronger_parameters/constraints/boolean_constraint.rb @@ -1,9 +1,10 @@ # frozen_string_literal: true + require "stronger_parameters/constraint" module StrongerParameters class BooleanConstraint < Constraint - TRUE_VALUES = [true, "true", "1", 1, "on"].freeze + TRUE_VALUES = [true, "true", "1", 1, "on"].freeze FALSE_VALUES = [false, "false", "0", 0].freeze def value(v) diff --git a/lib/stronger_parameters/constraints/comparison_constraints.rb b/lib/stronger_parameters/constraints/comparison_constraints.rb index cf7aff1..3bb1c9a 100644 --- a/lib/stronger_parameters/constraints/comparison_constraints.rb +++ b/lib/stronger_parameters/constraints/comparison_constraints.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + require "stronger_parameters/constraint" module StrongerParameters diff --git a/lib/stronger_parameters/constraints/date_constraint.rb b/lib/stronger_parameters/constraints/date_constraint.rb index fd10e36..a890c8e 100644 --- a/lib/stronger_parameters/constraints/date_constraint.rb +++ b/lib/stronger_parameters/constraints/date_constraint.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + require "stronger_parameters/constraint" module StrongerParameters diff --git a/lib/stronger_parameters/constraints/date_iso8601_constraint.rb b/lib/stronger_parameters/constraints/date_iso8601_constraint.rb index 4010a4c..4e704ec 100644 --- a/lib/stronger_parameters/constraints/date_iso8601_constraint.rb +++ b/lib/stronger_parameters/constraints/date_iso8601_constraint.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + require "stronger_parameters/constraint" module StrongerParameters diff --git a/lib/stronger_parameters/constraints/date_time_constraint.rb b/lib/stronger_parameters/constraints/date_time_constraint.rb index faa55ec..c4d4b4d 100644 --- a/lib/stronger_parameters/constraints/date_time_constraint.rb +++ b/lib/stronger_parameters/constraints/date_time_constraint.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + require "stronger_parameters/constraint" module StrongerParameters diff --git a/lib/stronger_parameters/constraints/date_time_iso8601_constraint.rb b/lib/stronger_parameters/constraints/date_time_iso8601_constraint.rb index de5fd5f..e616ea7 100644 --- a/lib/stronger_parameters/constraints/date_time_iso8601_constraint.rb +++ b/lib/stronger_parameters/constraints/date_time_iso8601_constraint.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + require "stronger_parameters/constraint" module StrongerParameters diff --git a/lib/stronger_parameters/constraints/decimal_constraint.rb b/lib/stronger_parameters/constraints/decimal_constraint.rb index 4ac42de..5a20b99 100644 --- a/lib/stronger_parameters/constraints/decimal_constraint.rb +++ b/lib/stronger_parameters/constraints/decimal_constraint.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + require "stronger_parameters/constraint" module StrongerParameters diff --git a/lib/stronger_parameters/constraints/enumeration_constraint.rb b/lib/stronger_parameters/constraints/enumeration_constraint.rb index d54a9f9..2861ed1 100644 --- a/lib/stronger_parameters/constraints/enumeration_constraint.rb +++ b/lib/stronger_parameters/constraints/enumeration_constraint.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + require "stronger_parameters/constraint" module StrongerParameters diff --git a/lib/stronger_parameters/constraints/file_constraint.rb b/lib/stronger_parameters/constraints/file_constraint.rb index 8b69221..711f540 100644 --- a/lib/stronger_parameters/constraints/file_constraint.rb +++ b/lib/stronger_parameters/constraints/file_constraint.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + require "stronger_parameters/constraint" module StrongerParameters diff --git a/lib/stronger_parameters/constraints/float_constraint.rb b/lib/stronger_parameters/constraints/float_constraint.rb index 453b078..b979cb0 100644 --- a/lib/stronger_parameters/constraints/float_constraint.rb +++ b/lib/stronger_parameters/constraints/float_constraint.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + require "stronger_parameters/constraint" module StrongerParameters diff --git a/lib/stronger_parameters/constraints/hash_constraint.rb b/lib/stronger_parameters/constraints/hash_constraint.rb index 2a55232..749792b 100644 --- a/lib/stronger_parameters/constraints/hash_constraint.rb +++ b/lib/stronger_parameters/constraints/hash_constraint.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + require "stronger_parameters/constraint" module StrongerParameters diff --git a/lib/stronger_parameters/constraints/hex_constraint.rb b/lib/stronger_parameters/constraints/hex_constraint.rb index 74d08b2..203a0d1 100644 --- a/lib/stronger_parameters/constraints/hex_constraint.rb +++ b/lib/stronger_parameters/constraints/hex_constraint.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + require "stronger_parameters/constraint" module StrongerParameters diff --git a/lib/stronger_parameters/constraints/integer_constraint.rb b/lib/stronger_parameters/constraints/integer_constraint.rb index 4b18b24..c32e300 100644 --- a/lib/stronger_parameters/constraints/integer_constraint.rb +++ b/lib/stronger_parameters/constraints/integer_constraint.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + require "stronger_parameters/constraint" module StrongerParameters diff --git a/lib/stronger_parameters/constraints/nil_constraint.rb b/lib/stronger_parameters/constraints/nil_constraint.rb index f1abd13..88d6069 100644 --- a/lib/stronger_parameters/constraints/nil_constraint.rb +++ b/lib/stronger_parameters/constraints/nil_constraint.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + require "stronger_parameters/constraint" module StrongerParameters diff --git a/lib/stronger_parameters/constraints/nil_string_constraint.rb b/lib/stronger_parameters/constraints/nil_string_constraint.rb index b43749e..42a54f4 100644 --- a/lib/stronger_parameters/constraints/nil_string_constraint.rb +++ b/lib/stronger_parameters/constraints/nil_string_constraint.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + require "stronger_parameters/constraint" module StrongerParameters diff --git a/lib/stronger_parameters/constraints/regexp_constraint.rb b/lib/stronger_parameters/constraints/regexp_constraint.rb index d529860..303d3d8 100644 --- a/lib/stronger_parameters/constraints/regexp_constraint.rb +++ b/lib/stronger_parameters/constraints/regexp_constraint.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + require "stronger_parameters/constraint" module StrongerParameters diff --git a/lib/stronger_parameters/constraints/string_constraint.rb b/lib/stronger_parameters/constraints/string_constraint.rb index 8350b0e..232d9cd 100644 --- a/lib/stronger_parameters/constraints/string_constraint.rb +++ b/lib/stronger_parameters/constraints/string_constraint.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + require "stronger_parameters/constraint" module StrongerParameters diff --git a/lib/stronger_parameters/constraints/time_constraint.rb b/lib/stronger_parameters/constraints/time_constraint.rb index b5b9900..dec70fa 100644 --- a/lib/stronger_parameters/constraints/time_constraint.rb +++ b/lib/stronger_parameters/constraints/time_constraint.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + require "stronger_parameters/constraint" module StrongerParameters diff --git a/lib/stronger_parameters/constraints/time_iso8601_constraint.rb b/lib/stronger_parameters/constraints/time_iso8601_constraint.rb index 6a43790..075a335 100644 --- a/lib/stronger_parameters/constraints/time_iso8601_constraint.rb +++ b/lib/stronger_parameters/constraints/time_iso8601_constraint.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + require "stronger_parameters/constraint" module StrongerParameters diff --git a/lib/stronger_parameters/constraints/ulid_constraint.rb b/lib/stronger_parameters/constraints/ulid_constraint.rb index 651e243..457afcb 100644 --- a/lib/stronger_parameters/constraints/ulid_constraint.rb +++ b/lib/stronger_parameters/constraints/ulid_constraint.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + require "stronger_parameters/constraint" module StrongerParameters diff --git a/lib/stronger_parameters/controller_support/permitted_parameters.rb b/lib/stronger_parameters/controller_support/permitted_parameters.rb index 8e012e2..f81ed6d 100644 --- a/lib/stronger_parameters/controller_support/permitted_parameters.rb +++ b/lib/stronger_parameters/controller_support/permitted_parameters.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + require "stronger_parameters/constraints" module StrongerParameters diff --git a/lib/stronger_parameters/errors.rb b/lib/stronger_parameters/errors.rb index c014c5b..96187b9 100644 --- a/lib/stronger_parameters/errors.rb +++ b/lib/stronger_parameters/errors.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + module StrongerParameters class InvalidValue attr_reader :value, :message diff --git a/lib/stronger_parameters/parameters.rb b/lib/stronger_parameters/parameters.rb index e09ffc9..28a9361 100644 --- a/lib/stronger_parameters/parameters.rb +++ b/lib/stronger_parameters/parameters.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + require "action_pack" require "action_controller/base" @@ -148,7 +149,7 @@ def ulid def hash_filter_with_stronger_parameters(params, filter) stronger_filter = ActiveSupport::HashWithIndifferentAccess.new - other_filter = ActiveSupport::HashWithIndifferentAccess.new + other_filter = ActiveSupport::HashWithIndifferentAccess.new filter.each do |k, v| if v.is_a?(Constraint) @@ -212,7 +213,7 @@ module ControllerSupport # should have the same render vs raise behavior in test/dev ... see permitted_parameters_test.rb rescue_from(StrongerParameters::InvalidParameter) do |e| if request.format.to_s.include?("json") - render json: { error: e.message }, status: :bad_request + render json: {error: e.message}, status: :bad_request else render plain: e.message, status: :bad_request end diff --git a/lib/stronger_parameters/version.rb b/lib/stronger_parameters/version.rb index 370b088..86bd00b 100644 --- a/lib/stronger_parameters/version.rb +++ b/lib/stronger_parameters/version.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + module StrongerParameters VERSION = "2.22.0" end diff --git a/stronger_parameters.gemspec b/stronger_parameters.gemspec index 101313f..bb3f793 100644 --- a/stronger_parameters.gemspec +++ b/stronger_parameters.gemspec @@ -1,16 +1,17 @@ # frozen_string_literal: true + require "./lib/stronger_parameters/version" Gem::Specification.new do |spec| - spec.name = "stronger_parameters" - spec.version = StrongerParameters::VERSION - spec.authors = ["Mick Staugaard"] - spec.email = ["mick@zendesk.com"] - spec.summary = "Type checking and type casting of parameters for Action Pack" - spec.homepage = "https://github.com/zendesk/stronger_parameters" - spec.license = "Apache License Version 2.0" + spec.name = "stronger_parameters" + spec.version = StrongerParameters::VERSION + spec.authors = ["Mick Staugaard"] + spec.email = ["mick@zendesk.com"] + spec.summary = "Type checking and type casting of parameters for Action Pack" + spec.homepage = "https://github.com/zendesk/stronger_parameters" + spec.license = "Apache License Version 2.0" - spec.files = Dir.glob("lib/**/*") + %w[README.md] + spec.files = Dir.glob("lib/**/*") + %w[README.md] spec.add_development_dependency "bundler", "<= 3" spec.add_development_dependency "rake" diff --git a/test/benchmark.rb b/test/benchmark.rb index ad51116..53c49f4 100644 --- a/test/benchmark.rb +++ b/test/benchmark.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + require_relative "test_helper" require "benchmark" diff --git a/test/controller_test.rb b/test/controller_test.rb index b73ff32..b0777fb 100644 --- a/test/controller_test.rb +++ b/test/controller_test.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + require_relative "test_helper" SingleCov.not_covered! @@ -10,7 +11,7 @@ class BooksController < ActionController::Base rescue_from(ActionController::ParameterMissing) do |e| if request.format.to_s.include?("json") - render json: { error: "Required parameter missing: #{e.param}" }, status: :bad_request + render json: {error: "Required parameter missing: #{e.param}"}, status: :bad_request else render plain: "Required parameter missing: #{e.param}", status: :bad_request end diff --git a/test/coverage_test.rb b/test/coverage_test.rb index 37f032f..69cdd65 100644 --- a/test/coverage_test.rb +++ b/test/coverage_test.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + require_relative "test_helper" SingleCov.not_covered! # not testing any code in lib/ diff --git a/test/stronger_parameters/constraint_test.rb b/test/stronger_parameters/constraint_test.rb index 4816c3f..4b1412d 100644 --- a/test/stronger_parameters/constraint_test.rb +++ b/test/stronger_parameters/constraint_test.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + require_relative "../test_helper" SingleCov.covered! @@ -44,8 +45,8 @@ describe "multi-chain" do subject do ActionController::Parameters.integer | - ActionController::Parameters.string | - ActionController::Parameters.boolean + ActionController::Parameters.string | + ActionController::Parameters.boolean end permits "abc" @@ -97,8 +98,8 @@ describe "multi-chain" do subject do ActionController::Parameters.string & - ActionController::Parameters.integer & - ActionController::Parameters.lt(5) + ActionController::Parameters.integer & + ActionController::Parameters.lt(5) end permits "4", as: 4 diff --git a/test/stronger_parameters/constraints/array_constraint_test.rb b/test/stronger_parameters/constraints/array_constraint_test.rb index c3c46a6..81b609c 100644 --- a/test/stronger_parameters/constraints/array_constraint_test.rb +++ b/test/stronger_parameters/constraints/array_constraint_test.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + require_relative "../../test_helper" SingleCov.covered! diff --git a/test/stronger_parameters/constraints/boolean_constraint_test.rb b/test/stronger_parameters/constraints/boolean_constraint_test.rb index 1888238..22881c5 100644 --- a/test/stronger_parameters/constraints/boolean_constraint_test.rb +++ b/test/stronger_parameters/constraints/boolean_constraint_test.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + require_relative "../../test_helper" SingleCov.covered! @@ -6,18 +7,18 @@ describe "boolean parameter constraints" do subject { ActionController::Parameters.boolean } - permits true, as: true - permits "true", as: true - permits "True", as: true - permits 1, as: true - permits "1", as: true - permits "on", as: true + permits true, as: true + permits "true", as: true + permits "True", as: true + permits 1, as: true + permits "1", as: true + permits "on", as: true - permits false, as: false + permits false, as: false permits "false", as: false permits "FALSE", as: false - permits 0, as: false - permits "0", as: false + permits 0, as: false + permits "0", as: false rejects "foo" rejects nil diff --git a/test/stronger_parameters/constraints/comparison_constraints_test.rb b/test/stronger_parameters/constraints/comparison_constraints_test.rb index 69ab2b9..cd6f35b 100644 --- a/test/stronger_parameters/constraints/comparison_constraints_test.rb +++ b/test/stronger_parameters/constraints/comparison_constraints_test.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + require_relative "../../test_helper" SingleCov.covered! diff --git a/test/stronger_parameters/constraints/date_constraint_test.rb b/test/stronger_parameters/constraints/date_constraint_test.rb index 4a31a55..299c66f 100644 --- a/test/stronger_parameters/constraints/date_constraint_test.rb +++ b/test/stronger_parameters/constraints/date_constraint_test.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + require_relative "../../test_helper" SingleCov.covered! diff --git a/test/stronger_parameters/constraints/date_iso8601_constraint_test.rb b/test/stronger_parameters/constraints/date_iso8601_constraint_test.rb index 871e79d..18a54bc 100644 --- a/test/stronger_parameters/constraints/date_iso8601_constraint_test.rb +++ b/test/stronger_parameters/constraints/date_iso8601_constraint_test.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + require_relative "../../test_helper" SingleCov.covered! diff --git a/test/stronger_parameters/constraints/date_time_constraint_test.rb b/test/stronger_parameters/constraints/date_time_constraint_test.rb index 0a5e426..cd1cda0 100644 --- a/test/stronger_parameters/constraints/date_time_constraint_test.rb +++ b/test/stronger_parameters/constraints/date_time_constraint_test.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + require_relative "../../test_helper" SingleCov.covered! diff --git a/test/stronger_parameters/constraints/date_time_iso8601_constraint_test.rb b/test/stronger_parameters/constraints/date_time_iso8601_constraint_test.rb index 5a43ca0..ba2fa41 100644 --- a/test/stronger_parameters/constraints/date_time_iso8601_constraint_test.rb +++ b/test/stronger_parameters/constraints/date_time_iso8601_constraint_test.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + require_relative "../../test_helper" SingleCov.covered! diff --git a/test/stronger_parameters/constraints/decimal_constraint_test.rb b/test/stronger_parameters/constraints/decimal_constraint_test.rb index 9855b02..0082310 100644 --- a/test/stronger_parameters/constraints/decimal_constraint_test.rb +++ b/test/stronger_parameters/constraints/decimal_constraint_test.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + require_relative "../../test_helper" SingleCov.covered! diff --git a/test/stronger_parameters/constraints/enumeration_constraint_test.rb b/test/stronger_parameters/constraints/enumeration_constraint_test.rb index 4d5a86d..f0bb0c2 100644 --- a/test/stronger_parameters/constraints/enumeration_constraint_test.rb +++ b/test/stronger_parameters/constraints/enumeration_constraint_test.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + require_relative "../../test_helper" SingleCov.covered! diff --git a/test/stronger_parameters/constraints/file_constraint_test.rb b/test/stronger_parameters/constraints/file_constraint_test.rb index 26289fa..fc8163c 100644 --- a/test/stronger_parameters/constraints/file_constraint_test.rb +++ b/test/stronger_parameters/constraints/file_constraint_test.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + require_relative "../../test_helper" SingleCov.covered! diff --git a/test/stronger_parameters/constraints/float_constraint_test.rb b/test/stronger_parameters/constraints/float_constraint_test.rb index a88b408..156e788 100644 --- a/test/stronger_parameters/constraints/float_constraint_test.rb +++ b/test/stronger_parameters/constraints/float_constraint_test.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + require_relative "../../test_helper" SingleCov.covered! diff --git a/test/stronger_parameters/constraints/hash_constraint_test.rb b/test/stronger_parameters/constraints/hash_constraint_test.rb index 7983efe..9ad570e 100644 --- a/test/stronger_parameters/constraints/hash_constraint_test.rb +++ b/test/stronger_parameters/constraints/hash_constraint_test.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + require_relative "../../test_helper" SingleCov.covered! @@ -53,8 +54,8 @@ def self.permits(value, options = {}) describe "merged constraints" do describe "hash" do subject do - ActionController::Parameters.map(id: ActionController::Parameters.integer). - merge(ActionController::Parameters.map(name: ActionController::Parameters.string)) + ActionController::Parameters.map(id: ActionController::Parameters.integer) + .merge(ActionController::Parameters.map(name: ActionController::Parameters.string)) end permits(id: 1, name: "Mick") @@ -63,8 +64,8 @@ def self.permits(value, options = {}) describe "other" do subject do - ActionController::Parameters.map(id: ActionController::Parameters.integer). - merge(name: ActionController::Parameters.string) + ActionController::Parameters.map(id: ActionController::Parameters.integer) + .merge(name: ActionController::Parameters.string) end permits(id: 1, name: "Mick") diff --git a/test/stronger_parameters/constraints/hex_constraint_test.rb b/test/stronger_parameters/constraints/hex_constraint_test.rb index a4b7e66..d5ba402 100644 --- a/test/stronger_parameters/constraints/hex_constraint_test.rb +++ b/test/stronger_parameters/constraints/hex_constraint_test.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + require_relative "../../test_helper" SingleCov.covered! diff --git a/test/stronger_parameters/constraints/integer_constraint_test.rb b/test/stronger_parameters/constraints/integer_constraint_test.rb index 1bc24a4..8d29e87 100644 --- a/test/stronger_parameters/constraints/integer_constraint_test.rb +++ b/test/stronger_parameters/constraints/integer_constraint_test.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + require_relative "../../test_helper" SingleCov.covered! diff --git a/test/stronger_parameters/constraints/nil_constraint_test.rb b/test/stronger_parameters/constraints/nil_constraint_test.rb index 69c9eb6..d9f96cb 100644 --- a/test/stronger_parameters/constraints/nil_constraint_test.rb +++ b/test/stronger_parameters/constraints/nil_constraint_test.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + require_relative "../../test_helper" SingleCov.covered! diff --git a/test/stronger_parameters/constraints/nil_string_constraint_test.rb b/test/stronger_parameters/constraints/nil_string_constraint_test.rb index 62daa98..cbe2b4b 100644 --- a/test/stronger_parameters/constraints/nil_string_constraint_test.rb +++ b/test/stronger_parameters/constraints/nil_string_constraint_test.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + require_relative "../../test_helper" SingleCov.covered! diff --git a/test/stronger_parameters/constraints/regexp_constraint_test.rb b/test/stronger_parameters/constraints/regexp_constraint_test.rb index f59b0b4..e20392b 100644 --- a/test/stronger_parameters/constraints/regexp_constraint_test.rb +++ b/test/stronger_parameters/constraints/regexp_constraint_test.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + require_relative "../../test_helper" SingleCov.covered! diff --git a/test/stronger_parameters/constraints/string_constraint_test.rb b/test/stronger_parameters/constraints/string_constraint_test.rb index 9f2e4de..3f9d333 100644 --- a/test/stronger_parameters/constraints/string_constraint_test.rb +++ b/test/stronger_parameters/constraints/string_constraint_test.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + require_relative "../../test_helper" SingleCov.covered! diff --git a/test/stronger_parameters/constraints/time_constraint_test.rb b/test/stronger_parameters/constraints/time_constraint_test.rb index 2ae4967..317dcc0 100644 --- a/test/stronger_parameters/constraints/time_constraint_test.rb +++ b/test/stronger_parameters/constraints/time_constraint_test.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + require_relative "../../test_helper" SingleCov.covered! diff --git a/test/stronger_parameters/constraints/time_iso8601_constraint_test.rb b/test/stronger_parameters/constraints/time_iso8601_constraint_test.rb index 64549f1..fb77863 100644 --- a/test/stronger_parameters/constraints/time_iso8601_constraint_test.rb +++ b/test/stronger_parameters/constraints/time_iso8601_constraint_test.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + require_relative "../../test_helper" SingleCov.covered! diff --git a/test/stronger_parameters/constraints/ulid_constraint_test.rb b/test/stronger_parameters/constraints/ulid_constraint_test.rb index 35c9cbb..3245054 100644 --- a/test/stronger_parameters/constraints/ulid_constraint_test.rb +++ b/test/stronger_parameters/constraints/ulid_constraint_test.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + require_relative "../../test_helper" SingleCov.covered! diff --git a/test/stronger_parameters/constraints_test.rb b/test/stronger_parameters/constraints_test.rb index 794320a..9c001f3 100644 --- a/test/stronger_parameters/constraints_test.rb +++ b/test/stronger_parameters/constraints_test.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + require_relative "../test_helper" SingleCov.covered! diff --git a/test/stronger_parameters/controller_support/permitted_parameters_test.rb b/test/stronger_parameters/controller_support/permitted_parameters_test.rb index be6b696..e0543e4 100644 --- a/test/stronger_parameters/controller_support/permitted_parameters_test.rb +++ b/test/stronger_parameters/controller_support/permitted_parameters_test.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + require_relative "../../test_helper" require "stronger_parameters/controller_support/permitted_parameters" @@ -52,10 +53,10 @@ def show end it "turns Hash into Parameters.map" do - WhitelistsController.permitted_parameters :foo, ticket: { id: ActionController::Parameters.integer } + WhitelistsController.permitted_parameters :foo, ticket: {id: ActionController::Parameters.integer} constraint = WhitelistsController.permitted_parameters_for(:foo)[:ticket] assert_instance_of StrongerParameters::HashConstraint, constraint - assert_equal({ "id" => ActionController::Parameters.integer }, constraint.constraints) + assert_equal({"id" => ActionController::Parameters.integer}, constraint.constraints) end end @@ -97,17 +98,17 @@ def show end it "inherits from parent to child" do - WhitelistsController.permitted_parameters_for(:create)[:first]. - must_be_instance_of StrongerParameters::StringConstraint - child_controller.permitted_parameters_for(:create)[:first]. - must_be_instance_of StrongerParameters::StringConstraint + WhitelistsController.permitted_parameters_for(:create)[:first] + .must_be_instance_of StrongerParameters::StringConstraint + child_controller.permitted_parameters_for(:create)[:first] + .must_be_instance_of StrongerParameters::StringConstraint assert_equal true, child_controller.log_unpermitted_parameters end it "does not inherit from child to parent" do assert_nil WhitelistsController.permitted_parameters_for(:create)[:last] - child_controller.permitted_parameters_for(:create)[:last]. - must_be_instance_of StrongerParameters::StringConstraint + child_controller.permitted_parameters_for(:create)[:last] + .must_be_instance_of StrongerParameters::StringConstraint end end end @@ -123,7 +124,7 @@ def do_request WhitelistsController.permitted_parameters( :index, something: ActionController::Parameters.anything, - user: { name: ActionController::Parameters.string } + user: {name: ActionController::Parameters.string} ) end diff --git a/test/stronger_parameters/errors_test.rb b/test/stronger_parameters/errors_test.rb index b2d2449..59f8a3b 100644 --- a/test/stronger_parameters/errors_test.rb +++ b/test/stronger_parameters/errors_test.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + require_relative "../test_helper" SingleCov.covered! diff --git a/test/stronger_parameters/parameters_test.rb b/test/stronger_parameters/parameters_test.rb index 4ef4a50..7bfbc55 100644 --- a/test/stronger_parameters/parameters_test.rb +++ b/test/stronger_parameters/parameters_test.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + require_relative "../test_helper" SingleCov.covered! uncovered: 3 # Covered in test/controller_test.rb @@ -291,8 +292,8 @@ end it "passes nested constraints in non-constraint" do - params(value: {key: 123}).permit(value: {key: ActionController::Parameters.integer32}).to_h. - must_equal "value" => {"key" => 123} + params(value: {key: 123}).permit(value: {key: ActionController::Parameters.integer32}).to_h + .must_equal "value" => {"key" => 123} end it "fails nested constraints in non-constraint" do @@ -302,8 +303,8 @@ end it "passes nested constraints in non-constraint array" do - params(value: [{key: 123}]).permit(value: [{key: ActionController::Parameters.integer32}]).to_h. - must_equal "value" => [{"key" => 123}] + params(value: [{key: 123}]).permit(value: [{key: ActionController::Parameters.integer32}]).to_h + .must_equal "value" => [{"key" => 123}] end it "fails nested constraints in non-constraint array" do diff --git a/test/stronger_parameters/version_test.rb b/test/stronger_parameters/version_test.rb index fcee662..2c4356d 100644 --- a/test/stronger_parameters/version_test.rb +++ b/test/stronger_parameters/version_test.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + require_relative "../test_helper" SingleCov.not_covered! # loaded before SingleCov is loaded diff --git a/test/stronger_parameters_test.rb b/test/stronger_parameters_test.rb index 52f456c..1b9dddd 100644 --- a/test/stronger_parameters_test.rb +++ b/test/stronger_parameters_test.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + require_relative "test_helper" SingleCov.covered! diff --git a/test/test_helper.rb b/test/test_helper.rb index bf1a852..6594d8d 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + ENV["RAILS_ENV"] = "test" require "bundler/setup" From bc6c274ba2ba0a60fcb0b95d9e483faae928e608 Mon Sep 17 00:00:00 2001 From: Benjamin Quorning Date: Tue, 6 Feb 2024 11:21:29 +0100 Subject: [PATCH 4/5] Standard: Fix safe autocorrections --- .standard_todo.yml | 8 -------- lib/stronger_parameters/constraints/decimal_constraint.rb | 2 +- lib/stronger_parameters/constraints/regexp_constraint.rb | 2 +- lib/stronger_parameters/constraints/ulid_constraint.rb | 4 ++-- lib/stronger_parameters/parameters.rb | 2 +- 5 files changed, 5 insertions(+), 13 deletions(-) diff --git a/.standard_todo.yml b/.standard_todo.yml index ba3eea7..d29ddd9 100644 --- a/.standard_todo.yml +++ b/.standard_todo.yml @@ -2,16 +2,8 @@ # Remove from this list as you refactor files. --- ignore: -- lib/stronger_parameters/constraints/decimal_constraint.rb: - - Performance/RegexpMatch -- lib/stronger_parameters/constraints/regexp_constraint.rb: - - Performance/RegexpMatch -- lib/stronger_parameters/constraints/ulid_constraint.rb: - - Performance/RegexpMatch - lib/stronger_parameters/controller_support/permitted_parameters.rb: - Lint/AssignmentInCondition -- lib/stronger_parameters/parameters.rb: - - Style/Alias - test/stronger_parameters/constraints/string_constraint_test.rb: - Performance/UnfreezeString - test/stronger_parameters/controller_support/permitted_parameters_test.rb: diff --git a/lib/stronger_parameters/constraints/decimal_constraint.rb b/lib/stronger_parameters/constraints/decimal_constraint.rb index 5a20b99..1fe2d25 100644 --- a/lib/stronger_parameters/constraints/decimal_constraint.rb +++ b/lib/stronger_parameters/constraints/decimal_constraint.rb @@ -12,7 +12,7 @@ def initialize(precision, scale) def value(v) match = v.to_s - if match =~ @regex + if match&.match?(@regex) BigDecimal(match) else StrongerParameters::InvalidValue.new(v, "must be a decimal with precision #{@precision} and scale #{@scale}") diff --git a/lib/stronger_parameters/constraints/regexp_constraint.rb b/lib/stronger_parameters/constraints/regexp_constraint.rb index 303d3d8..520c1b2 100644 --- a/lib/stronger_parameters/constraints/regexp_constraint.rb +++ b/lib/stronger_parameters/constraints/regexp_constraint.rb @@ -15,7 +15,7 @@ def value(v) v = @string.value(v) return v if v.is_a?(InvalidValue) - if v =~ regexp + if v&.match?(regexp) v else InvalidValue.new(v, "must match #{regexp.source}") diff --git a/lib/stronger_parameters/constraints/ulid_constraint.rb b/lib/stronger_parameters/constraints/ulid_constraint.rb index 457afcb..87e806b 100644 --- a/lib/stronger_parameters/constraints/ulid_constraint.rb +++ b/lib/stronger_parameters/constraints/ulid_constraint.rb @@ -5,13 +5,13 @@ module StrongerParameters class UlidConstraint < Constraint # https://www.crockford.com/base32.html - INVALID_CHAR_REGEX = /[ilou]|[^a-z0-9]/i.freeze + INVALID_CHAR_REGEX = /[ilou]|[^a-z0-9]/i ULID_LENGTH = 26 def value(v) return invalid_value(v) unless v.is_a?(String) return invalid_value(v) unless v.length == ULID_LENGTH - return invalid_value(v) if v =~ INVALID_CHAR_REGEX + return invalid_value(v) if INVALID_CHAR_REGEX.match?(v) v end diff --git a/lib/stronger_parameters/parameters.rb b/lib/stronger_parameters/parameters.rb index 28a9361..528ac92 100644 --- a/lib/stronger_parameters/parameters.rb +++ b/lib/stronger_parameters/parameters.rb @@ -84,7 +84,7 @@ def ubigid def enumeration(*allowed) EnumerationConstraint.new(*allowed) end - alias enum enumeration + alias_method :enum, :enumeration def boolean BooleanConstraint.new From e162af61f1b4d18f1095421905f3d30b36dfff7b Mon Sep 17 00:00:00 2001 From: Benjamin Quorning Date: Sat, 18 Nov 2023 00:02:44 +0100 Subject: [PATCH 5/5] Standard: Fix last offenses Also, configure `git blame` to ignore the 3 previous commits. --- .git-blame-ignore-revs | 3 +++ .standard_todo.yml | 10 ---------- .../controller_support/permitted_parameters.rb | 2 +- .../constraints/string_constraint_test.rb | 2 +- .../controller_support/permitted_parameters_test.rb | 4 ++-- 5 files changed, 7 insertions(+), 14 deletions(-) create mode 100644 .git-blame-ignore-revs delete mode 100644 .standard_todo.yml diff --git a/.git-blame-ignore-revs b/.git-blame-ignore-revs new file mode 100644 index 0000000..ee10ecf --- /dev/null +++ b/.git-blame-ignore-revs @@ -0,0 +1,3 @@ +bc6c274ba2ba0a60fcb0b95d9e483faae928e608 +ddecab1191e897dfb1e3fceec774e2782495f261 +eee1a5f87757938eb85bdca0a77df4ab81dadd87 \ No newline at end of file diff --git a/.standard_todo.yml b/.standard_todo.yml deleted file mode 100644 index d29ddd9..0000000 --- a/.standard_todo.yml +++ /dev/null @@ -1,10 +0,0 @@ -# Auto generated files with errors to ignore. -# Remove from this list as you refactor files. ---- -ignore: -- lib/stronger_parameters/controller_support/permitted_parameters.rb: - - Lint/AssignmentInCondition -- test/stronger_parameters/constraints/string_constraint_test.rb: - - Performance/UnfreezeString -- test/stronger_parameters/controller_support/permitted_parameters_test.rb: - - Performance/UnfreezeString diff --git a/lib/stronger_parameters/controller_support/permitted_parameters.rb b/lib/stronger_parameters/controller_support/permitted_parameters.rb index f81ed6d..5687081 100644 --- a/lib/stronger_parameters/controller_support/permitted_parameters.rb +++ b/lib/stronger_parameters/controller_support/permitted_parameters.rb @@ -51,7 +51,7 @@ def permitted_parameters(action, permitted) end def permitted_parameters_for(action) - unless for_action = permit_parameters[action] + unless (for_action = permit_parameters[action]) # NOTE: there is no easy way to test this, so make sure to test with # a real rails controller if you make changes. message = "Action #{action} for #{self} does not have any permitted parameters" diff --git a/test/stronger_parameters/constraints/string_constraint_test.rb b/test/stronger_parameters/constraints/string_constraint_test.rb index 3f9d333..eb9c8d6 100644 --- a/test/stronger_parameters/constraints/string_constraint_test.rb +++ b/test/stronger_parameters/constraints/string_constraint_test.rb @@ -13,7 +13,7 @@ rejects Date.today rejects Time.now rejects nil - rejects "\xA1".dup.force_encoding("UTF-8") + rejects (+"\xA1").force_encoding("UTF-8") it "rejects strings that are too long" do assert_rejects(:value) { params(value: "123").permit(value: ActionController::Parameters.string(max_length: 2)) } diff --git a/test/stronger_parameters/controller_support/permitted_parameters_test.rb b/test/stronger_parameters/controller_support/permitted_parameters_test.rb index e0543e4..79da5a0 100644 --- a/test/stronger_parameters/controller_support/permitted_parameters_test.rb +++ b/test/stronger_parameters/controller_support/permitted_parameters_test.rb @@ -165,7 +165,7 @@ def do_request end it "does not remove invalid because they only raise and do not filter" do - parameters[:user] = {name: {so: "evil".dup}} + parameters[:user] = {name: {so: +"evil"}} do_request assert_response :success @controller.params.to_h["user"]["name"].must_equal("so" => "evil") @@ -190,7 +190,7 @@ def do_request describe "when raising on invalid params" do def do_request - get :index, params: {user: {name: ["123".dup]}} + get :index, params: {user: {name: [+"123"]}} end before { ActionController::Parameters.action_on_invalid_parameters = :raise }