From a9a77ccce3d6a49ffa6d6f94d511558b1858178a Mon Sep 17 00:00:00 2001 From: net57 Date: Tue, 21 Apr 2020 22:16:00 +0200 Subject: [PATCH 01/12] Update bundler to v2 --- Gemfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Gemfile b/Gemfile index ed7218c..b1973e5 100644 --- a/Gemfile +++ b/Gemfile @@ -16,7 +16,7 @@ group :development, :test do gem 'middleman', '~> 4.1', require: false gem 'aruba', '~>0.14.2', require: false gem 'awesome_print', require: 'ap' - gem 'bundler', '~> 1.3', require: false + gem 'bundler', '~> 2.0', require: false gem 'command_exec', require: false gem 'coveralls', require: false gem 'cucumber', require: false From 039491c4d49be833d05592dec5a17a7d935b2d82 Mon Sep 17 00:00:00 2001 From: net57 Date: Tue, 21 Apr 2020 22:35:28 +0200 Subject: [PATCH 02/12] add support for the miniracer runtime --- Gemfile | 5 ++ README.md | 5 +- lib/proxy_pac_rb.rb | 1 + lib/proxy_pac_rb/runtimes.rb | 2 + lib/proxy_pac_rb/runtimes/miniracer.rb | 83 ++++++++++++++++++++++++++ 5 files changed, 95 insertions(+), 1 deletion(-) create mode 100644 lib/proxy_pac_rb/runtimes/miniracer.rb diff --git a/Gemfile b/Gemfile index b1973e5..e3bb040 100644 --- a/Gemfile +++ b/Gemfile @@ -56,4 +56,9 @@ group :runtimes do group :therubyrhino do gem 'therubyrhino', require: 'rhino' end + + group :mini_racer do + gem 'mini_racer', require: 'mini_racer' + end + end diff --git a/README.md b/README.md index 25e2c1f..ed100ba 100644 --- a/README.md +++ b/README.md @@ -7,7 +7,9 @@ [![Downloads](http://img.shields.io/gem/dt/proxy_pac_rb.svg?style=flat)](http://rubygems.org/gems/proxy_pac_rb) -`proxy_pac_rb` is a gem to compress, lint and parse [proxy auto-config](http://en.wikipedia.org/wiki/Proxy_auto-config) files. It comes with a cli program, some rack middlewares and can be used from within ruby scripts as well. `proxy_pac_rb` uses a JavaScript runtime to evaulate a proxy auto-config file the same way a browser does to determine what proxy (if any at all) should a program use to connect to a server. You must install on of the supported JavaScript runtimes: [therubyracer](https://rubygems.org/gems/therubyracer) or [therubyrhino](https://rubygems.org/gems/therubyrhino/). +`proxy_pac_rb` is a gem to compress, lint and parse [proxy auto-config](http://en.wikipedia.org/wiki/Proxy_auto-config +) files. It comes with a cli program, some rack middlewares and can be used from within ruby scripts as well +. `proxy_pac_rb` uses a JavaScript runtime to evaulate a proxy auto-config file the same way a browser does to determine what proxy (if any at all) should a program use to connect to a server. You must install on of the supported JavaScript runtimes: [miniracer](https://github.com/rubyjs/mini_racer), [therubyracer](https://rubygems.org/gems/therubyracer) or [therubyrhino](https://rubygems.org/gems/therubyrhino/). Big thanks to [sstephenson](https://github.com/sstephenson)'s [execjs](https://github.com/sstephenson/execjs) for the runtime wrapper code and to @@ -35,6 +37,7 @@ After installing the `proxy_pac_rb` gem you must install a JavaScript runtime. C * [therubyracer](https://rubygems.org/gems/therubyracer) Google V8 embedded within Ruby * [therubyrhino](https://rubygems.org/gems/therubyrhino/) Mozilla Rhino embedded within JRuby +* [miniracer](https://github.com/rubyjs/mini_racer) Minimal, modern embedded V8 for Ruby ## Usage diff --git a/lib/proxy_pac_rb.rb b/lib/proxy_pac_rb.rb index 7920d02..ffa31d5 100644 --- a/lib/proxy_pac_rb.rb +++ b/lib/proxy_pac_rb.rb @@ -28,6 +28,7 @@ require 'proxy_pac_rb/runtime' require 'proxy_pac_rb/runtimes/rubyracer' require 'proxy_pac_rb/runtimes/rubyrhino' +require 'proxy_pac_rb/runtimes/miniracer' require 'proxy_pac_rb/runtimes' require 'proxy_pac_rb/parser' require 'proxy_pac_rb/javascript' diff --git a/lib/proxy_pac_rb/runtimes.rb b/lib/proxy_pac_rb/runtimes.rb index 77ba0b4..cbe252b 100644 --- a/lib/proxy_pac_rb/runtimes.rb +++ b/lib/proxy_pac_rb/runtimes.rb @@ -2,6 +2,7 @@ module ProxyPacRb # JavaScript Runtimes module Runtimes + MiniRacer = MiniRacerRuntime.new RubyRacer = RubyRacerRuntime.new RubyRhino = RubyRhinoRuntime.new @@ -33,6 +34,7 @@ def names def runtimes @runtimes ||= [ + MiniRacer, RubyRacer, RubyRhino ] diff --git a/lib/proxy_pac_rb/runtimes/miniracer.rb b/lib/proxy_pac_rb/runtimes/miniracer.rb new file mode 100644 index 0000000..ddbc9b6 --- /dev/null +++ b/lib/proxy_pac_rb/runtimes/miniracer.rb @@ -0,0 +1,83 @@ +# frozen_string_literal: true +module ProxyPacRb + # Mini Racer Runtime + class MiniRacerRuntime < Runtime + # Context + class Context < Runtime::Context + def initialize(_runtime, source = '', _environment = nil) + source = encode(source) + + self.context = ::MiniRacer::Context.new + context.eval(source) + end + + def include(environment) + environment.available_methods.each do |name| + context.attach(name.to_s, environment.method(name)) + end + end + + def exec(source, options = {}) + source = encode(source) + + # rubocop:disable Security/Eval, Style/EvalWithLocation + eval "(function(){#{source}})()", options if /\S/ =~ source + # rubocop:enable Security/Eval, Style/EvalWithLocation + end + + def eval(source, _options = {}) + source = encode(source) + + return nil unless /\S/ =~ source + + begin + unbox context.eval("(#{source})") + rescue MiniRacer::Error => e + raise ProgramError, e + end + end + + def call(properties, *args) + unbox context.eval("#{properties}.apply(this, #{::JSON.generate(args)})") + rescue MiniRacer::Error => e + raise ProgramError, e + end + + def unbox(value) + if Array === value + value.map! do |v| + if MiniRacer::JavaScriptFunction === value + nil + else + unbox(v) + end + end + elsif Hash === value + value.each do |k, v| + if MiniRacer::JavaScriptFunction === v + value.delete k + else + value[k] = unbox(v) + end + end + value + elsif MiniRacer::JavaScriptFunction === value + nil + else + value + end + end + end + + def name + 'mini_racer (V8)' + end + + def available? + require 'mini_racer' + true + rescue LoadError + false + end + end +end From 40449ef6f183cbf45b9524ef68e095674790308e Mon Sep 17 00:00:00 2001 From: net57 Date: Tue, 21 Apr 2020 22:37:19 +0200 Subject: [PATCH 03/12] Change test of ProxyPacCompressor to avoid UTF8 Conversion error hell --- spec/rack/proxy_pac_compressor_spec.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/spec/rack/proxy_pac_compressor_spec.rb b/spec/rack/proxy_pac_compressor_spec.rb index 3c054d7..45bcbc2 100644 --- a/spec/rack/proxy_pac_compressor_spec.rb +++ b/spec/rack/proxy_pac_compressor_spec.rb @@ -37,7 +37,7 @@ end context 'when invalid proxy pac is given' do - let(:compressed_content) { %{Unexpected token: string (§$ )} } + let(:compressed_content) { %{Unexpected token: string (!$ )} } let(:app) do a = Class.new(Sinatra::Base) do @@ -48,7 +48,7 @@ get '/' do <<~EOS.chomp function FindProxyForURL(url, host) { - return $"§$ "DIRECT"; + return $"!$ "DIRECT"; } EOS end From e1e9f937820d6de21cab2e26c08ac466d9b7928f Mon Sep 17 00:00:00 2001 From: net57 Date: Tue, 21 Apr 2020 22:38:03 +0200 Subject: [PATCH 04/12] adjust rubocop files for version 0.82 --- .rubocop.yml | 4 +- .rubocop_todo.yml | 230 ++++++++++++++++++++++++++++++++++++++++++---- 2 files changed, 214 insertions(+), 20 deletions(-) diff --git a/.rubocop.yml b/.rubocop.yml index 27ed16e..baa1c31 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -4,7 +4,7 @@ AllCops: - 'tmp/**/*' - Gemfile DisplayCopNames: true - TargetRubyVersion: 2.3 + TargetRubyVersion: 2.6 Style/GuardClause: Enabled: false @@ -38,7 +38,7 @@ Metrics/MethodLength: Max: 76 Metrics/PerceivedComplexity: - Max: 8 + Max: 9 # Configuration parameters: EnforcedStyle, SupportedStyles. Style/MethodName: diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index 4fe0df7..bf38aca 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -1,27 +1,55 @@ # This configuration was generated by # `rubocop --auto-gen-config` -# on 2017-06-04 19:50:00 +0000 using RuboCop version 0.49.1. +# on 2020-04-21 18:35:05 +0000 using RuboCop version 0.82.0. # The point is for the user to remove these configuration records # one by one as the offenses are removed from the code base. # Note that changes in the inspected code, or installation of new # versions of RuboCop, may require this file to be generated again. -# Offense count: 82 +# Offense count: 3 +# Cop supports --auto-correct. +# Configuration parameters: TreatCommentsAsGroupSeparators, Include. +# Include: **/*.gemspec +Gemspec/OrderedDependencies: + Exclude: + - 'proxy_pac_rb.gemspec' + +# Offense count: 1 +# Configuration parameters: Include. +# Include: **/*.gemspec +Gemspec/RequiredRubyVersion: + Exclude: + - 'proxy_pac_rb.gemspec' + +# Offense count: 1 +# Cop supports --auto-correct. +Layout/ClosingHeredocIndentation: + Exclude: + - 'proxy_pac_rb.gemspec' + +# Offense count: 1 +# Cop supports --auto-correct. +Layout/EmptyLineAfterGuardClause: + Exclude: + - 'lib/proxy_pac_rb/rspec/matchers/base_matcher.rb' + +# Offense count: 83 # Cop supports --auto-correct. Layout/EmptyLineAfterMagicComment: Enabled: false -# Offense count: 87 -# Configuration parameters: EnforcedStyle, SupportedStyles. +# Offense count: 1 +# Configuration parameters: EnforcedStyle. # SupportedStyles: native, lf, crlf Layout/EndOfLine: - Enabled: false + Exclude: + - 'Vagrantfile' # Offense count: 27 # Cop supports --auto-correct. -# Configuration parameters: EnforcedStyle, SupportedStyles. -# SupportedStyles: auto_detection, squiggly, active_support, powerpack, unindent -Layout/IndentHeredoc: +# Configuration parameters: EnforcedStyle. +# SupportedStyles: squiggly, active_support, powerpack, unindent +Layout/HeredocIndentation: Exclude: - 'lib/proxy_pac_rb/cli/init_proxy_pac.rb' - 'lib/proxy_pac_rb/proxy_pac_js.rb' @@ -34,27 +62,147 @@ Layout/IndentHeredoc: - 'spec/rspec/readability_spec.rb' - 'spec/rspec/validitiy_spec.rb' +# Offense count: 1 +# Cop supports --auto-correct. +Layout/RescueEnsureAlignment: + Exclude: + - 'lib/proxy_pac_rb/rspec/helpers.rb' + +# Offense count: 1 +# Cop supports --auto-correct. +# Configuration parameters: AllowForAlignment, EnforcedStyleForExponentOperator. +# SupportedStylesForExponentOperator: space, no_space +Layout/SpaceAroundOperators: + Exclude: + - 'lib/proxy_pac_rb/rack/proxy_pac_compressor.rb' + +# Offense count: 2 +# Cop supports --auto-correct. +Lint/RedundantCopDisableDirective: + Exclude: + - 'lib/proxy_pac_rb/environment.rb' + - 'lib/proxy_pac_rb/javascript.rb' + +# Offense count: 1 +# Cop supports --auto-correct. +Lint/SendWithMixinArgument: + Exclude: + - 'Rakefile' + +# Offense count: 1 +# Configuration parameters: AllowComments. +Lint/SuppressedException: + Exclude: + - 'lib/proxy_pac_rb/environment.rb' + # Offense count: 17 # Configuration parameters: CountComments, ExcludedMethods. +# ExcludedMethods: refine Metrics/BlockLength: Max: 178 +# Offense count: 1 +# Configuration parameters: IgnoredMethods. +Metrics/PerceivedComplexity: + Max: 9 + +# Offense count: 47 +# Configuration parameters: ForbiddenDelimiters. +# ForbiddenDelimiters: (?-mix:(^|\s)(EO[A-Z]{1}|END)(\s|$)) +Naming/HeredocDelimiterNaming: + Exclude: + - 'lib/proxy_pac_rb/cli/init_proxy_pac.rb' + - 'lib/proxy_pac_rb/proxy_pac_js.rb' + - 'spec/api/proxy_pac_compressor_spec.rb' + - 'spec/api/proxy_pac_dumper_spec.rb' + - 'spec/api/proxy_pac_file_spec.rb' + - 'spec/api/proxy_pac_linter_spec.rb' + - 'spec/api/proxy_pac_loader_spec.rb' + - 'spec/api/proxy_pac_parser_spec.rb' + - 'spec/parser_spec.rb' + - 'spec/rack/proxy_pac_compressor_spec.rb' + - 'spec/rack/proxy_pac_linter_spec.rb' + - 'spec/rspec/compare_proxy_pac_files_spec.rb' + - 'spec/rspec/parse_proxy_pac_spec.rb' + - 'spec/rspec/readability_spec.rb' + - 'spec/rspec/validitiy_spec.rb' + +# Offense count: 1 +# Configuration parameters: MinNameLength, AllowNamesEndingInNumbers, AllowedNames, ForbiddenNames. +# AllowedNames: io, id, to, by, on, in, at, ip, db, os, pp +Naming/MethodParameterName: + Exclude: + - 'lib/proxy_pac_rb/proxy_pac_file.rb' + +# Offense count: 8 +# Cop supports --auto-correct. +# Configuration parameters: PreferredName. +Naming/RescuedExceptionsVariableName: + Exclude: + - 'lib/proxy_pac_rb/cli/find_proxy.rb' + - 'lib/proxy_pac_rb/javascript_compiler.rb' + - 'lib/proxy_pac_rb/proxy_pac_linter.rb' + - 'lib/proxy_pac_rb/proxy_pac_loader.rb' + - 'lib/proxy_pac_rb/proxy_pac_parser.rb' + - 'lib/proxy_pac_rb/rack/proxy_pac_compressor.rb' + - 'lib/proxy_pac_rb/rspec/matchers/base_matcher.rb' + +# Offense count: 1 +# Configuration parameters: EnforcedStyle, AllowModifiersOnSymbols. +# SupportedStyles: inline, group +Style/AccessModifierDeclarations: + Exclude: + - 'lib/proxy_pac_rb/rspec/matchers/base_matcher.rb' + # Offense count: 1 # Cop supports --auto-correct. -# Configuration parameters: EnforcedStyle, SupportedStyles. +# Configuration parameters: EnforcedStyle. # SupportedStyles: compact, expanded Style/EmptyMethod: Exclude: - 'lib/proxy_pac_rb/runtime.rb' +# Offense count: 32 +# Cop supports --auto-correct. +Style/Encoding: + Enabled: false + +# Offense count: 2 +Style/EvalWithLocation: + Exclude: + - 'lib/proxy_pac_rb/runtimes/rubyracer.rb' + - 'lib/proxy_pac_rb/runtimes/rubyrhino.rb' + +# Offense count: 5 +# Cop supports --auto-correct. +Style/ExpandPathArguments: + Exclude: + - 'bin/pprb' + - 'lib/proxy_pac_rb/cli/init_proxy_pac.rb' + - 'lib/proxy_pac_rb/main.rb' + - 'script/config.ru' + - 'templates/test_framework/rspec/spec_helper.rb' + +# Offense count: 27 +# Configuration parameters: . +# SupportedStyles: annotated, template, unannotated +Style/FormatStringToken: + EnforcedStyle: unannotated + # Offense count: 1 # Cop supports --auto-correct. -# Configuration parameters: EnforcedStyle, SupportedStyles. -# SupportedStyles: when_needed, always, never +# Configuration parameters: EnforcedStyle. +# SupportedStyles: always, always_true, never Style/FrozenStringLiteralComment: Exclude: - 'Vagrantfile' +# Offense count: 1 +# Cop supports --auto-correct. +Style/IfUnlessModifier: + Exclude: + - 'lib/proxy_pac_rb/encoding.rb' + # Offense count: 1 # Cop supports --auto-correct. # Configuration parameters: InverseMethods, InverseBlocks. @@ -62,6 +210,21 @@ Style/InverseMethods: Exclude: - 'lib/proxy_pac_rb/rspec.rb' +# Offense count: 1 +Style/MethodMissingSuper: + Exclude: + - 'lib/proxy_pac_rb/javascript.rb' + +# Offense count: 1 +Style/MissingRespondToMissing: + Exclude: + - 'lib/proxy_pac_rb/javascript.rb' + +# Offense count: 1 +Style/MixinUsage: + Exclude: + - 'spec/spec_helper.rb' + # Offense count: 7 # Cop supports --auto-correct. # Configuration parameters: PreferredDelimiters. @@ -74,18 +237,49 @@ Style/PercentLiteralDelimiters: - 'spec/environment_spec.rb' - 'templates/test_framework/rspec/support/aruba.rb' +# Offense count: 5 +# Cop supports --auto-correct. +Style/RedundantBegin: + Exclude: + - 'lib/proxy_pac_rb/cli/find_proxy.rb' + - 'lib/proxy_pac_rb/environment.rb' + - 'lib/proxy_pac_rb/runtimes/rubyracer.rb' + +# Offense count: 6 +# Cop supports --auto-correct. +# Configuration parameters: EnforcedStyle. +# SupportedStyles: implicit, explicit +Style/RescueStandardError: + Exclude: + - 'lib/proxy_pac_rb/proxy_pac_linter.rb' + - 'lib/proxy_pac_rb/proxy_pac_loader.rb' + - 'lib/proxy_pac_rb/proxy_pac_parser.rb' + - 'lib/proxy_pac_rb/rack/proxy_pac_compressor.rb' + - 'lib/proxy_pac_rb/rspec/helpers.rb' + - 'lib/proxy_pac_rb/runtimes/rubyracer.rb' + +# Offense count: 11 +# Cop supports --auto-correct. +Style/StderrPuts: + Exclude: + - 'lib/proxy_pac_rb/cli/compress_proxy_pac.rb' + - 'lib/proxy_pac_rb/cli/find_proxy.rb' + - 'lib/proxy_pac_rb/cli/lint_proxy_pac.rb' + - 'lib/proxy_pac_rb/cli/show.rb' + - 'lib/proxy_pac_rb/cli_validator.rb' + - 'lib/proxy_pac_rb/parser.rb' + # Offense count: 2 # Cop supports --auto-correct. -# Configuration parameters: MinSize, SupportedStyles. +# Configuration parameters: MinSize. # SupportedStyles: percent, brackets Style/SymbolArray: EnforcedStyle: brackets -# Offense count: 4 +# Offense count: 1 # Cop supports --auto-correct. -Style/YodaCondition: +# Configuration parameters: EnforcedStyleForMultiline. +# SupportedStylesForMultiline: comma, consistent_comma, no_comma +Style/TrailingCommaInHashLiteral: Exclude: - - 'lib/proxy_pac_rb/proxy_pac_file.rb' - - 'lib/proxy_pac_rb/rack/proxy_pac_compressor.rb' - - 'lib/proxy_pac_rb/rack/proxy_pac_linter.rb' - - 'lib/proxy_pac_rb/rspec/helpers.rb' + - 'lib/proxy_pac_rb/proxy_pac_compressor.rb' From 43363ea36699151fb56b7c16e6312b2f3fa27e7c Mon Sep 17 00:00:00 2001 From: net57 Date: Wed, 22 Apr 2020 12:14:32 +0200 Subject: [PATCH 05/12] refactor MiniRacerRuntime to use most of the code extracted from execjs gem. All credits go to execjs gem author --- lib/proxy_pac_rb/runtimes/miniracer.rb | 45 +++++++++++++++++++------- 1 file changed, 33 insertions(+), 12 deletions(-) diff --git a/lib/proxy_pac_rb/runtimes/miniracer.rb b/lib/proxy_pac_rb/runtimes/miniracer.rb index ddbc9b6..3900208 100644 --- a/lib/proxy_pac_rb/runtimes/miniracer.rb +++ b/lib/proxy_pac_rb/runtimes/miniracer.rb @@ -1,6 +1,8 @@ # frozen_string_literal: true module ProxyPacRb # Mini Racer Runtime + # little adaptation from execjs gem. + # All credits go to execjs gem author class MiniRacerRuntime < Runtime # Context class Context < Runtime::Context @@ -8,7 +10,7 @@ def initialize(_runtime, source = '', _environment = nil) source = encode(source) self.context = ::MiniRacer::Context.new - context.eval(source) + translate { context.eval(source) } end def include(environment) @@ -30,26 +32,22 @@ def eval(source, _options = {}) return nil unless /\S/ =~ source - begin - unbox context.eval("(#{source})") - rescue MiniRacer::Error => e - raise ProgramError, e - end + translate { context.eval("(#{source})") } end def call(properties, *args) - unbox context.eval("#{properties}.apply(this, #{::JSON.generate(args)})") - rescue MiniRacer::Error => e - raise ProgramError, e + translate { context.eval("#{properties}.apply(this, #{::JSON.generate(args)})") } end - def unbox(value) + private + + def strip_functions!(value) if Array === value value.map! do |v| if MiniRacer::JavaScriptFunction === value nil else - unbox(v) + strip_functions!(v) end end elsif Hash === value @@ -57,7 +55,7 @@ def unbox(value) if MiniRacer::JavaScriptFunction === v value.delete k else - value[k] = unbox(v) + value[k] = strip_functions!(v) end end value @@ -67,6 +65,29 @@ def unbox(value) value end end + + def translate + strip_functions! yield + rescue MiniRacer::RuntimeError => e + ex = ProgramError.new e.message + if backtrace = e.backtrace # rubocop:disable Lint/AssignmentInCondition + backtrace = backtrace.map do |line| + if line =~ /JavaScript at/ + line.sub('JavaScript at ', '') + .sub('', '(proxypac)') + .strip + else + line + end + end + ex.set_backtrace backtrace + end + raise ex + rescue MiniRacer::ParseError => e + ex = RuntimeError.new e.message + ex.set_backtrace(['(proxypac):1'] + e.backtrace) + raise ex + end end def name From e1248877e09a53e2745bf0a8b2939a05ff7fddca Mon Sep 17 00:00:00 2001 From: net57 Date: Sat, 25 Apr 2020 21:28:16 +0200 Subject: [PATCH 06/12] remove most version requirements on gems add comment how to declare runtimes in Gemfile --- Gemfile | 26 ++++++++++++++------------ proxy_pac_rb.gemspec | 10 +++++----- 2 files changed, 19 insertions(+), 17 deletions(-) diff --git a/Gemfile b/Gemfile index e3bb040..807996d 100644 --- a/Gemfile +++ b/Gemfile @@ -13,15 +13,15 @@ group :debug do end group :development, :test do - gem 'middleman', '~> 4.1', require: false - gem 'aruba', '~>0.14.2', require: false + gem 'middleman', require: false + gem 'aruba', require: false gem 'awesome_print', require: 'ap' - gem 'bundler', '~> 2.0', require: false + gem 'bundler', require: false gem 'command_exec', require: false gem 'coveralls', require: false gem 'cucumber', require: false gem 'erubis' - gem 'fedux_org-stdlib', '~>0.11.17', require: false + gem 'fedux_org-stdlib', require: false gem 'filegen' gem 'foreman', require: false gem 'fuubar', require: false @@ -49,16 +49,18 @@ group :profile do end group :runtimes do - group :therubyracer do - gem 'therubyracer', require: 'v8' - end - - group :therubyrhino do - gem 'therubyrhino', require: 'rhino' - end - + # mini_racer & therubyracer can't sit in the same gemfile + # uncomment the needed one and comment the other + # group :mini_racer do gem 'mini_racer', require: 'mini_racer' end + # group :therubyracer do + # gem 'therubyracer', require: 'v8' + # end + + group :therubyrhino do + gem 'therubyrhino', require: 'rhino', platform: :jruby + end end diff --git a/proxy_pac_rb.gemspec b/proxy_pac_rb.gemspec index e9187f0..264c1e3 100644 --- a/proxy_pac_rb.gemspec +++ b/proxy_pac_rb.gemspec @@ -21,12 +21,12 @@ DESC spec.test_files = spec.files.grep(%r{^(test|spec|features)/}) spec.require_paths = ['lib'] - spec.add_runtime_dependency 'addressable', '~>2.3' - spec.add_runtime_dependency 'activesupport', '>=4.1', '<5.2' + spec.add_runtime_dependency 'addressable' + spec.add_runtime_dependency 'activesupport', '>=4.1' spec.add_runtime_dependency 'uglifier', '>= 2.7.1' - spec.add_runtime_dependency 'excon', '~> 0.45.3' - spec.add_runtime_dependency 'contracts', '~> 0.9' - spec.add_runtime_dependency 'thor', '~> 0.19' + spec.add_runtime_dependency 'excon' + spec.add_runtime_dependency 'contracts' + spec.add_runtime_dependency 'thor' spec.required_ruby_version = '~> 2.3' end From f48c1064164408750818876dd42b349a5c8d1ec5 Mon Sep 17 00:00:00 2001 From: net57 Date: Sat, 25 Apr 2020 21:32:44 +0200 Subject: [PATCH 07/12] Add vagrantfile to help testing on windows --- Vagrantfile | 101 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 101 insertions(+) create mode 100644 Vagrantfile diff --git a/Vagrantfile b/Vagrantfile new file mode 100644 index 0000000..4c42cb8 --- /dev/null +++ b/Vagrantfile @@ -0,0 +1,101 @@ +# -*- mode: ruby -*- +# vi: set ft=ruby : + +# All Vagrant configuration is done below. The "2" in Vagrant.configure +# configures the configuration version (we support older styles for +# backwards compatibility). Please don't change it unless you know what +# you're doing. +Vagrant.configure('2') do |config| + # The most common configuration options are documented and commented below. + # For a complete reference, please see the online documentation at + # https://docs.vagrantup.com. + + # Every Vagrant development environment requires a box. You can search for + # boxes at https://atlas.hashicorp.com/search. + config.vm.box = 'bento/ubuntu-18.04' + + # Disable automatic box update checking. If you disable this, then + # boxes will only be checked for updates when the user runs + # `vagrant box outdated`. This is not recommended. + # config.vm.box_check_update = false + + # Create a forwarded port mapping which allows access to a specific port + # within the machine from a port on the host machine. In the example below, + # accessing "localhost:8080" will access port 80 on the guest machine. + config.vm.network 'forwarded_port', guest: 3000, host: 3000, host_ip: 'localhost' + + # Create a private network, which allows host-only access to the machine + # using a specific IP. + # config.vm.network "private_network", ip: "192.168.33.10" + + # Create a public network, which generally matched to bridged network. + # Bridged networks make the machine appear as another physical device on + # your network. + # config.vm.network "public_network" + + # Share an additional folder to the guest VM. The first argument is + # the path on the host to the actual folder. The second argument is + # the path on the guest to mount the folder. And the optional third + # argument is a set of non-required options. + # config.vm.synced_folder "../data", "/vagrant_data" + + # Provider-specific configuration so you can fine-tune various + # backing providers for Vagrant. These expose provider-specific options. + # Example for VirtualBox: + # + # config.vm.provider "virtualbox" do |vb| + # # Display the VirtualBox GUI when booting the machine + # vb.gui = true + # + # # Customize the amount of memory on the VM: + # vb.memory = "1024" + # end + config.vm.provider 'virtualbox' do |vb| + vb.memory = '1024' + end + # + # View the documentation for the provider you are using for more + # information on available options. + + # Define a Vagrant Push strategy for pushing to Atlas. Other push strategies + # such as FTP and Heroku are also available. See the documentation at + # https://docs.vagrantup.com/v2/push/atlas.html for more information. + # config.push.define "atlas" do |push| + # push.app = "YOUR_ATLAS_USERNAME/YOUR_APPLICATION_NAME" + # end + + # Enable provisioning with a shell script. Additional provisioners such as + # Puppet, Chef, Ansible, Salt, and Docker are also available. Please see the + # documentation for more information about their specific syntax and use. + # config.vm.provision "shell", inline: <<-SHELL + # apt-get update + # apt-get install -y apache2 + # SHELL + config.vm.provision 'shell', inline: <<-SHELL + # for ruby repository + sudo apt-get install -y software-properties-common + sudo add-apt-repository -y ppa:brightbox/ruby-ng + # for nodejs repository + curl -sL https://deb.nodesource.com/setup_12.x | sudo -E bash - + # for yarn repository + curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | sudo apt-key add - + echo "deb https://dl.yarnpkg.com/debian/ stable main" | sudo tee /etc/apt/sources.list.d/yarn.list + # update + sudo apt-get update + sudo apt-get -y dist-upgrade + # install ruby & prerequisite + # select the wanted ruby version rubyx.x & rubyx.x-dev + sudo apt-get install -y git-core curl zlib1g-dev build-essential libssl-dev libreadline-dev \ + libyaml-dev libsqlite3-dev sqlite3 libxml2-dev libxslt1-dev \ + libcurl4-openssl-dev libffi-dev \ + ruby2.6 ruby2.6-dev \ + nodejs yarn + # install rubygems, bundler + # limit rubygems to version 3.0.6 to avoid deprecation warnings about Gem::ConfigMap + sudo gem update --system 3.0.6 --no-doc + sudo gem install bundler --no-doc + # cleanup + sudo apt-get autoremove -y + sudo apt-get autoclean -y + SHELL +end From 9eb92a1bff1063c064d317b4b2d6c965b3525834 Mon Sep 17 00:00:00 2001 From: net57 Date: Thu, 30 Apr 2020 21:32:50 +0200 Subject: [PATCH 08/12] require ruby >= 2.3 in gemspec --- proxy_pac_rb.gemspec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/proxy_pac_rb.gemspec b/proxy_pac_rb.gemspec index 264c1e3..64a9015 100644 --- a/proxy_pac_rb.gemspec +++ b/proxy_pac_rb.gemspec @@ -28,5 +28,5 @@ DESC spec.add_runtime_dependency 'contracts' spec.add_runtime_dependency 'thor' - spec.required_ruby_version = '~> 2.3' + spec.required_ruby_version = '>= 2.3' end From f6a4854ee79ab36cc9b29cb482605f5ba39d3155 Mon Sep 17 00:00:00 2001 From: net57 Date: Mon, 3 Feb 2025 23:33:04 +0100 Subject: [PATCH 09/12] update to ruby 3.4 --- .gitignore | 1 + .ruby-version | 1 + Vagrantfile | 131 ++++++++++++++++++-------------------------------- 3 files changed, 50 insertions(+), 83 deletions(-) create mode 100644 .ruby-version diff --git a/.gitignore b/.gitignore index 402e6c2..83a9588 100644 --- a/.gitignore +++ b/.gitignore @@ -4,3 +4,4 @@ pkg/* coverage tmp/ Gemfile.lock +.vagrant diff --git a/.ruby-version b/.ruby-version new file mode 100644 index 0000000..47b322c --- /dev/null +++ b/.ruby-version @@ -0,0 +1 @@ +3.4.1 diff --git a/Vagrantfile b/Vagrantfile index 4c42cb8..f707086 100644 --- a/Vagrantfile +++ b/Vagrantfile @@ -1,101 +1,66 @@ +# frozen_string_literal: true + # -*- mode: ruby -*- # vi: set ft=ruby : -# All Vagrant configuration is done below. The "2" in Vagrant.configure -# configures the configuration version (we support older styles for -# backwards compatibility). Please don't change it unless you know what -# you're doing. +RUBY_V = File.read('./.ruby-version').chomp Vagrant.configure('2') do |config| - # The most common configuration options are documented and commented below. - # For a complete reference, please see the online documentation at - # https://docs.vagrantup.com. - - # Every Vagrant development environment requires a box. You can search for - # boxes at https://atlas.hashicorp.com/search. - config.vm.box = 'bento/ubuntu-18.04' - - # Disable automatic box update checking. If you disable this, then - # boxes will only be checked for updates when the user runs - # `vagrant box outdated`. This is not recommended. - # config.vm.box_check_update = false - - # Create a forwarded port mapping which allows access to a specific port - # within the machine from a port on the host machine. In the example below, - # accessing "localhost:8080" will access port 80 on the guest machine. - config.vm.network 'forwarded_port', guest: 3000, host: 3000, host_ip: 'localhost' - - # Create a private network, which allows host-only access to the machine - # using a specific IP. - # config.vm.network "private_network", ip: "192.168.33.10" - - # Create a public network, which generally matched to bridged network. - # Bridged networks make the machine appear as another physical device on - # your network. - # config.vm.network "public_network" - - # Share an additional folder to the guest VM. The first argument is - # the path on the host to the actual folder. The second argument is - # the path on the guest to mount the folder. And the optional third - # argument is a set of non-required options. - # config.vm.synced_folder "../data", "/vagrant_data" - - # Provider-specific configuration so you can fine-tune various - # backing providers for Vagrant. These expose provider-specific options. - # Example for VirtualBox: - # - # config.vm.provider "virtualbox" do |vb| - # # Display the VirtualBox GUI when booting the machine - # vb.gui = true - # - # # Customize the amount of memory on the VM: - # vb.memory = "1024" - # end - config.vm.provider 'virtualbox' do |vb| + config.vm.box = 'bento/debian-12' + config.vm.network 'forwarded_port', guest: 3000, host: 3033, host_ip: 'localhost' + # change to 'virtualbox' if you use it in place of vmware + config.vm.provider 'vmware_desktop' do |vb| vb.memory = '1024' + vb.gui = false end - # - # View the documentation for the provider you are using for more - # information on available options. - - # Define a Vagrant Push strategy for pushing to Atlas. Other push strategies - # such as FTP and Heroku are also available. See the documentation at - # https://docs.vagrantup.com/v2/push/atlas.html for more information. - # config.push.define "atlas" do |push| - # push.app = "YOUR_ATLAS_USERNAME/YOUR_APPLICATION_NAME" - # end - - # Enable provisioning with a shell script. Additional provisioners such as - # Puppet, Chef, Ansible, Salt, and Docker are also available. Please see the - # documentation for more information about their specific syntax and use. - # config.vm.provision "shell", inline: <<-SHELL - # apt-get update - # apt-get install -y apache2 - # SHELL config.vm.provision 'shell', inline: <<-SHELL - # for ruby repository - sudo apt-get install -y software-properties-common - sudo add-apt-repository -y ppa:brightbox/ruby-ng # for nodejs repository - curl -sL https://deb.nodesource.com/setup_12.x | sudo -E bash - - # for yarn repository - curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | sudo apt-key add - - echo "deb https://dl.yarnpkg.com/debian/ stable main" | sudo tee /etc/apt/sources.list.d/yarn.list - # update + # see https://github.com/nodesource/distributions#debian-and-ubuntu-based-distributions + sudo apt-get install -y ca-certificates curl gnupg + NODE_MAJOR=22 + curl -fsSL https://deb.nodesource.com/setup_$NODE_MAJOR.x -o nodesource_setup.sh + sudo -E bash nodesource_setup.sh + # update the apt repositories sudo apt-get update + # update the system sudo apt-get -y dist-upgrade - # install ruby & prerequisite - # select the wanted ruby version rubyx.x & rubyx.x-dev + # install ruby prerequisite sudo apt-get install -y git-core curl zlib1g-dev build-essential libssl-dev libreadline-dev \ libyaml-dev libsqlite3-dev sqlite3 libxml2-dev libxslt1-dev \ libcurl4-openssl-dev libffi-dev \ - ruby2.6 ruby2.6-dev \ nodejs yarn - # install rubygems, bundler - # limit rubygems to version 3.0.6 to avoid deprecation warnings about Gem::ConfigMap - sudo gem update --system 3.0.6 --no-doc - sudo gem install bundler --no-doc # cleanup sudo apt-get autoremove -y - sudo apt-get autoclean -y + sudo apt-get clean -y SHELL + + config.vm.provision :shell, privileged: false, inline: <<~SCRIPT + if [ ! -d ~/.rbenv ]; then + git clone https://github.com/rbenv/rbenv.git ~/.rbenv + echo 'export PATH="$HOME/.rbenv/bin:$PATH"' >> ~/.bashrc + echo 'eval "$(rbenv init -)"' >> ~/.bashrc + fi + git -C /home/vagrant/.rbenv pull + + if [ ! -d ~/.rbenv/plugins/ruby-build ]; then + git clone https://github.com/rbenv/ruby-build.git ~/.rbenv/plugins/ruby-build + echo 'export PATH="$HOME/.rbenv/plugins/ruby-build/bin:$PATH"' >> ~/.bashrc + fi + git -C /home/vagrant/.rbenv/plugins/ruby-build pull + export PATH="$HOME/.rbenv/bin:$PATH" + export PATH="$HOME/.rbenv/plugins/ruby-build/bin:$PATH" + + eval "$(rbenv init -)" + if [ ! -e .rbenv/versions/#{RUBY_V} ]; then + rbenv install #{RUBY_V} + rbenv global #{RUBY_V} + gem update --system --no-doc + rbenv rehash + fi + cd /vagrant + # if [ ! -e /home/vagrant/.rbenv/shims/bundle ]; then + gem update --system --no-doc + rbenv rehash + # fi + bundle install + SCRIPT end From 77f98a46a12adfd3930bf31f006e3566f865545b Mon Sep 17 00:00:00 2001 From: net57 Date: Mon, 3 Feb 2025 23:33:32 +0100 Subject: [PATCH 10/12] adjuts rubocop files to new version --- .rubocop.yml | 12 +-- .rubocop_todo.yml | 260 ++++++++++++++++++++++++++++++++++++---------- 2 files changed, 212 insertions(+), 60 deletions(-) diff --git a/.rubocop.yml b/.rubocop.yml index baa1c31..89c4dbc 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -4,7 +4,8 @@ AllCops: - 'tmp/**/*' - Gemfile DisplayCopNames: true - TargetRubyVersion: 2.6 + TargetRubyVersion: 3.4 + NewCops: enable Style/GuardClause: Enabled: false @@ -13,7 +14,7 @@ Metrics/AbcSize: Max: 38 # Configuration parameters: AllowURI. -Metrics/LineLength: +Layout/LineLength: Max: 225 # Configuration parameters: CountKeywordArgs. @@ -31,7 +32,7 @@ Metrics/ClassLength: Max: 174 Metrics/CyclomaticComplexity: - Max: 7 + Max: 9 # Configuration parameters: CountComments. Metrics/MethodLength: @@ -41,9 +42,6 @@ Metrics/PerceivedComplexity: Max: 9 # Configuration parameters: EnforcedStyle, SupportedStyles. -Style/MethodName: +Naming/MethodName: Exclude: - lib/proxy_pac_rb/environment.rb - -Style/GuardClause: - Enabled: false diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index bf38aca..ff067b3 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -1,54 +1,89 @@ # This configuration was generated by # `rubocop --auto-gen-config` -# on 2020-04-21 18:35:05 +0000 using RuboCop version 0.82.0. +# on 2025-02-03 22:23:49 UTC using RuboCop version 1.71.1. # The point is for the user to remove these configuration records # one by one as the offenses are removed from the code base. # Note that changes in the inspected code, or installation of new # versions of RuboCop, may require this file to be generated again. +# Offense count: 6 +# This cop supports safe autocorrection (--autocorrect). +# Configuration parameters: Include. +# Include: **/*.gemspec +Gemspec/AddRuntimeDependency: + Exclude: + - 'proxy_pac_rb.gemspec' + +# Offense count: 1 +# This cop supports safe autocorrection (--autocorrect). +# Configuration parameters: Severity, Include. +# Include: **/*.gemspec +Gemspec/DeprecatedAttributeAssignment: + Exclude: + - 'proxy_pac_rb.gemspec' + # Offense count: 3 -# Cop supports --auto-correct. -# Configuration parameters: TreatCommentsAsGroupSeparators, Include. +# This cop supports safe autocorrection (--autocorrect). +# Configuration parameters: TreatCommentsAsGroupSeparators, ConsiderPunctuation, Include. # Include: **/*.gemspec Gemspec/OrderedDependencies: Exclude: - 'proxy_pac_rb.gemspec' # Offense count: 1 -# Configuration parameters: Include. +# This cop supports safe autocorrection (--autocorrect). +# Configuration parameters: Severity, Include. +# Include: **/*.gemspec +Gemspec/RequireMFA: + Exclude: + - 'proxy_pac_rb.gemspec' + +# Offense count: 1 +# Configuration parameters: Severity, Include. # Include: **/*.gemspec Gemspec/RequiredRubyVersion: Exclude: - 'proxy_pac_rb.gemspec' +# Offense count: 3 +# This cop supports safe autocorrection (--autocorrect). +# Configuration parameters: EnforcedStyleAlignWith, Severity. +# SupportedStylesAlignWith: start_of_line, begin +Layout/BeginEndAlignment: + Exclude: + - 'lib/proxy_pac_rb/rspec/helpers.rb' + - 'lib/proxy_pac_rb/rspec/matchers/proxy.rb' + # Offense count: 1 -# Cop supports --auto-correct. +# This cop supports safe autocorrection (--autocorrect). Layout/ClosingHeredocIndentation: Exclude: - 'proxy_pac_rb.gemspec' # Offense count: 1 -# Cop supports --auto-correct. +# This cop supports safe autocorrection (--autocorrect). Layout/EmptyLineAfterGuardClause: Exclude: - 'lib/proxy_pac_rb/rspec/matchers/base_matcher.rb' -# Offense count: 83 -# Cop supports --auto-correct. +# Offense count: 84 +# This cop supports safe autocorrection (--autocorrect). Layout/EmptyLineAfterMagicComment: Enabled: false -# Offense count: 1 +# Offense count: 5 # Configuration parameters: EnforcedStyle. # SupportedStyles: native, lf, crlf Layout/EndOfLine: Exclude: - 'Vagrantfile' + - 'lib/proxy_pac_rb.rb' + - 'lib/proxy_pac_rb/environment.rb' + - 'lib/proxy_pac_rb/runtimes.rb' + - 'spec/rack/proxy_pac_linter_spec.rb' # Offense count: 27 -# Cop supports --auto-correct. -# Configuration parameters: EnforcedStyle. -# SupportedStyles: squiggly, active_support, powerpack, unindent +# This cop supports safe autocorrection (--autocorrect). Layout/HeredocIndentation: Exclude: - 'lib/proxy_pac_rb/cli/init_proxy_pac.rb' @@ -63,52 +98,97 @@ Layout/HeredocIndentation: - 'spec/rspec/validitiy_spec.rb' # Offense count: 1 -# Cop supports --auto-correct. +# This cop supports safe autocorrection (--autocorrect). +# Configuration parameters: EnforcedStyle, IndentationWidth. +# SupportedStyles: aligned, indented +Layout/LineEndStringConcatenationIndentation: + Exclude: + - 'lib/proxy_pac_rb/runtimes.rb' + +# Offense count: 1 +# This cop supports safe autocorrection (--autocorrect). Layout/RescueEnsureAlignment: Exclude: - 'lib/proxy_pac_rb/rspec/helpers.rb' # Offense count: 1 -# Cop supports --auto-correct. -# Configuration parameters: AllowForAlignment, EnforcedStyleForExponentOperator. -# SupportedStylesForExponentOperator: space, no_space -Layout/SpaceAroundOperators: +# This cop supports safe autocorrection (--autocorrect). +# Configuration parameters: AllowInHeredoc. +Layout/TrailingWhitespace: Exclude: - - 'lib/proxy_pac_rb/rack/proxy_pac_compressor.rb' + - '.simplecov' + +# Offense count: 4 +# Configuration parameters: AllowedParentClasses. +Lint/MissingSuper: + Exclude: + - 'lib/proxy_pac_rb/rspec/matchers/proxy.rb' + - 'lib/proxy_pac_rb/runtimes/miniracer.rb' + - 'lib/proxy_pac_rb/runtimes/rubyracer.rb' + - 'lib/proxy_pac_rb/runtimes/rubyrhino.rb' # Offense count: 2 -# Cop supports --auto-correct. +# This cop supports safe autocorrection (--autocorrect). Lint/RedundantCopDisableDirective: Exclude: - 'lib/proxy_pac_rb/environment.rb' - 'lib/proxy_pac_rb/javascript.rb' # Offense count: 1 -# Cop supports --auto-correct. +# This cop supports unsafe autocorrection (--autocorrect-all). +Lint/RedundantRequireStatement: + Exclude: + - 'lib/proxy_pac_rb.rb' + +# Offense count: 1 +# This cop supports safe autocorrection (--autocorrect). Lint/SendWithMixinArgument: Exclude: - 'Rakefile' # Offense count: 1 -# Configuration parameters: AllowComments. +# Configuration parameters: AllowComments, AllowNil. Lint/SuppressedException: Exclude: - 'lib/proxy_pac_rb/environment.rb' -# Offense count: 17 -# Configuration parameters: CountComments, ExcludedMethods. -# ExcludedMethods: refine +# Offense count: 1 +# This cop supports safe autocorrection (--autocorrect). +# Configuration parameters: EnforcedStyle. +# SupportedStyles: strict, consistent +Lint/SymbolConversion: + Exclude: + - 'lib/proxy_pac_rb/basic_configuration.rb' + +# Offense count: 18 +# Configuration parameters: CountComments, CountAsOne, AllowedMethods, AllowedPatterns. +# AllowedMethods: refine Metrics/BlockLength: Max: 178 +# Offense count: 4 +# Configuration parameters: AllowedMethods, AllowedPatterns. +Metrics/CyclomaticComplexity: + Max: 9 + # Offense count: 1 -# Configuration parameters: IgnoredMethods. +# Configuration parameters: AllowedMethods, AllowedPatterns, Max. Metrics/PerceivedComplexity: - Max: 9 + Exclude: + - 'lib/proxy_pac_rb/runtimes/miniracer.rb' + +# Offense count: 3 +# This cop supports safe autocorrection (--autocorrect). +# Configuration parameters: EnforcedStyle, BlockForwardingName. +# SupportedStyles: anonymous, explicit +Naming/BlockForwarding: + Exclude: + - 'lib/proxy_pac_rb/javascript.rb' + - 'lib/proxy_pac_rb/rspec.rb' # Offense count: 47 # Configuration parameters: ForbiddenDelimiters. -# ForbiddenDelimiters: (?-mix:(^|\s)(EO[A-Z]{1}|END)(\s|$)) +# ForbiddenDelimiters: (?i-mx:(^|\s)(EO[A-Z]{1}|END)(\s|$)) Naming/HeredocDelimiterNaming: Exclude: - 'lib/proxy_pac_rb/cli/init_proxy_pac.rb' @@ -129,13 +209,13 @@ Naming/HeredocDelimiterNaming: # Offense count: 1 # Configuration parameters: MinNameLength, AllowNamesEndingInNumbers, AllowedNames, ForbiddenNames. -# AllowedNames: io, id, to, by, on, in, at, ip, db, os, pp +# AllowedNames: as, at, by, cc, db, id, if, in, io, ip, of, on, os, pp, to Naming/MethodParameterName: Exclude: - 'lib/proxy_pac_rb/proxy_pac_file.rb' # Offense count: 8 -# Cop supports --auto-correct. +# This cop supports safe autocorrection (--autocorrect). # Configuration parameters: PreferredName. Naming/RescuedExceptionsVariableName: Exclude: @@ -148,72 +228,122 @@ Naming/RescuedExceptionsVariableName: - 'lib/proxy_pac_rb/rspec/matchers/base_matcher.rb' # Offense count: 1 -# Configuration parameters: EnforcedStyle, AllowModifiersOnSymbols. -# SupportedStyles: inline, group -Style/AccessModifierDeclarations: +# Configuration parameters: EnforcedStyle, CheckMethodNames, CheckSymbols, AllowedIdentifiers, AllowedPatterns. +# SupportedStyles: snake_case, normalcase, non_integer +# AllowedIdentifiers: capture3, iso8601, rfc1123_date, rfc822, rfc2822, rfc3339, x86_64 +Naming/VariableNumber: Exclude: - - 'lib/proxy_pac_rb/rspec/matchers/base_matcher.rb' + - 'spec/api/proxy_pac_file_spec.rb' + +# Offense count: 14 +# This cop supports safe autocorrection (--autocorrect). +# Configuration parameters: AllowOnlyRestArgument, UseAnonymousForwarding, RedundantRestArgumentNames, RedundantKeywordRestArgumentNames, RedundantBlockArgumentNames. +# RedundantRestArgumentNames: args, arguments +# RedundantKeywordRestArgumentNames: kwargs, options, opts +# RedundantBlockArgumentNames: blk, block, proc +Style/ArgumentsForwarding: + Exclude: + - 'lib/proxy_pac_rb/basic_configuration.rb' + - 'lib/proxy_pac_rb/parser.rb' + - 'lib/proxy_pac_rb/rspec.rb' + - 'lib/proxy_pac_rb/runtimes/rubyracer.rb' + - 'lib/proxy_pac_rb/runtimes/rubyrhino.rb' # Offense count: 1 -# Cop supports --auto-correct. -# Configuration parameters: EnforcedStyle. +# This cop supports unsafe autocorrection (--autocorrect-all). +# Configuration parameters: MinBranchesCount. +Style/CaseLikeIf: + Exclude: + - 'lib/proxy_pac_rb/runtimes/miniracer.rb' + +# Offense count: 7 +Style/DocumentDynamicEvalDefinition: + Exclude: + - 'lib/proxy_pac_rb/runtimes/miniracer.rb' + - 'lib/proxy_pac_rb/runtimes/rubyracer.rb' + - 'lib/proxy_pac_rb/runtimes/rubyrhino.rb' + +# Offense count: 1 +# This cop supports safe autocorrection (--autocorrect). +# Configuration parameters: AutoCorrect, EnforcedStyle. # SupportedStyles: compact, expanded Style/EmptyMethod: Exclude: - 'lib/proxy_pac_rb/runtime.rb' # Offense count: 32 -# Cop supports --auto-correct. +# This cop supports safe autocorrection (--autocorrect). Style/Encoding: Enabled: false # Offense count: 2 +# This cop supports safe autocorrection (--autocorrect). Style/EvalWithLocation: Exclude: - 'lib/proxy_pac_rb/runtimes/rubyracer.rb' - 'lib/proxy_pac_rb/runtimes/rubyrhino.rb' -# Offense count: 5 -# Cop supports --auto-correct. +# Offense count: 11 +# This cop supports safe autocorrection (--autocorrect). Style/ExpandPathArguments: Exclude: - 'bin/pprb' - 'lib/proxy_pac_rb/cli/init_proxy_pac.rb' - 'lib/proxy_pac_rb/main.rb' + - 'proxy_pac_rb.gemspec' - 'script/config.ru' + - 'script/console' + - 'spec/spec_helper.rb' - 'templates/test_framework/rspec/spec_helper.rb' -# Offense count: 27 -# Configuration parameters: . +# Offense count: 2 +# This cop supports safe autocorrection (--autocorrect). +# Configuration parameters: AllowedVars. +Style/FetchEnvVar: + Exclude: + - 'lib/proxy_pac_rb/runtimes.rb' + +# Offense count: 22 +# This cop supports safe autocorrection (--autocorrect). +# Configuration parameters: MaxUnannotatedPlaceholdersAllowed, AllowedMethods, AllowedPatterns. # SupportedStyles: annotated, template, unannotated Style/FormatStringToken: EnforcedStyle: unannotated # Offense count: 1 -# Cop supports --auto-correct. +# This cop supports unsafe autocorrection (--autocorrect-all). # Configuration parameters: EnforcedStyle. # SupportedStyles: always, always_true, never Style/FrozenStringLiteralComment: Exclude: - - 'Vagrantfile' + - '**/*.arb' + - '.simplecov' + +# Offense count: 1 +# This cop supports unsafe autocorrection (--autocorrect-all). +Style/HashExcept: + Exclude: + - 'lib/proxy_pac_rb/rspec.rb' # Offense count: 1 -# Cop supports --auto-correct. +# This cop supports safe autocorrection (--autocorrect). Style/IfUnlessModifier: Exclude: - 'lib/proxy_pac_rb/encoding.rb' # Offense count: 1 -# Cop supports --auto-correct. +# This cop supports unsafe autocorrection (--autocorrect-all). # Configuration parameters: InverseMethods, InverseBlocks. Style/InverseMethods: Exclude: - 'lib/proxy_pac_rb/rspec.rb' -# Offense count: 1 -Style/MethodMissingSuper: +# Offense count: 2 +# This cop supports unsafe autocorrection (--autocorrect-all). +Style/MapIntoArray: Exclude: - - 'lib/proxy_pac_rb/javascript.rb' + - 'lib/proxy_pac_rb/rack/proxy_pac_compressor.rb' + - 'lib/proxy_pac_rb/rack/proxy_pac_linter.rb' # Offense count: 1 Style/MissingRespondToMissing: @@ -226,7 +356,7 @@ Style/MixinUsage: - 'spec/spec_helper.rb' # Offense count: 7 -# Cop supports --auto-correct. +# This cop supports safe autocorrection (--autocorrect). # Configuration parameters: PreferredDelimiters. Style/PercentLiteralDelimiters: Exclude: @@ -238,15 +368,31 @@ Style/PercentLiteralDelimiters: - 'templates/test_framework/rspec/support/aruba.rb' # Offense count: 5 -# Cop supports --auto-correct. +# This cop supports safe autocorrection (--autocorrect). Style/RedundantBegin: Exclude: - 'lib/proxy_pac_rb/cli/find_proxy.rb' - 'lib/proxy_pac_rb/environment.rb' - 'lib/proxy_pac_rb/runtimes/rubyracer.rb' +# Offense count: 7 +# This cop supports safe autocorrection (--autocorrect). +Style/RedundantConstantBase: + Exclude: + - 'proxy_pac_rb.gemspec' + - 'script/console' + - 'spec/spec_helper.rb' + - 'templates/test_framework/rspec/spec_helper.rb' + +# Offense count: 4 +# This cop supports safe autocorrection (--autocorrect). +Style/RedundantStringEscape: + Exclude: + - 'spec/api/proxy_pac_compressor_spec.rb' + - 'spec/rack/proxy_pac_compressor_spec.rb' + # Offense count: 6 -# Cop supports --auto-correct. +# This cop supports safe autocorrection (--autocorrect). # Configuration parameters: EnforcedStyle. # SupportedStyles: implicit, explicit Style/RescueStandardError: @@ -259,7 +405,7 @@ Style/RescueStandardError: - 'lib/proxy_pac_rb/runtimes/rubyracer.rb' # Offense count: 11 -# Cop supports --auto-correct. +# This cop supports safe autocorrection (--autocorrect). Style/StderrPuts: Exclude: - 'lib/proxy_pac_rb/cli/compress_proxy_pac.rb' @@ -269,15 +415,23 @@ Style/StderrPuts: - 'lib/proxy_pac_rb/cli_validator.rb' - 'lib/proxy_pac_rb/parser.rb' +# Offense count: 6 +# This cop supports safe autocorrection (--autocorrect). +# Configuration parameters: EnforcedStyle, ConsistentQuotesInMultiline. +# SupportedStyles: single_quotes, double_quotes +Style/StringLiterals: + Exclude: + - '.simplecov' + # Offense count: 2 -# Cop supports --auto-correct. +# This cop supports safe autocorrection (--autocorrect). # Configuration parameters: MinSize. # SupportedStyles: percent, brackets Style/SymbolArray: EnforcedStyle: brackets # Offense count: 1 -# Cop supports --auto-correct. +# This cop supports safe autocorrection (--autocorrect). # Configuration parameters: EnforcedStyleForMultiline. # SupportedStylesForMultiline: comma, consistent_comma, no_comma Style/TrailingCommaInHashLiteral: From eaad086b58fffd8fdec32e6fa480a58f339595be Mon Sep 17 00:00:00 2001 From: net57 Date: Mon, 3 Feb 2025 23:33:49 +0100 Subject: [PATCH 11/12] follow rubocop advices --- lib/proxy_pac_rb/rspec/matchers/base_matcher.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/proxy_pac_rb/rspec/matchers/base_matcher.rb b/lib/proxy_pac_rb/rspec/matchers/base_matcher.rb index 15412fd..07a88e8 100644 --- a/lib/proxy_pac_rb/rspec/matchers/base_matcher.rb +++ b/lib/proxy_pac_rb/rspec/matchers/base_matcher.rb @@ -166,14 +166,14 @@ def failure_message_when_negated end # @private - # rubocop:disable Style/PredicateName + # rubocop:disable Naming/PredicateName def self.has_default_failure_messages?(matcher) matcher.method(:failure_message).owner == self && matcher.method(:failure_message_when_negated).owner == self rescue NameError false end - # rubocop:enable Style/PredicateName + # rubocop:enable Naming/PredicateName end include DefaultFailureMessages From 150bd49285adfa78756081339c3dc7b0d9492e37 Mon Sep 17 00:00:00 2001 From: net57 Date: Fri, 4 Apr 2025 22:34:38 +0200 Subject: [PATCH 12/12] update gem description --- proxy_pac_rb.gemspec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/proxy_pac_rb.gemspec b/proxy_pac_rb.gemspec index 64a9015..ce3490d 100644 --- a/proxy_pac_rb.gemspec +++ b/proxy_pac_rb.gemspec @@ -11,7 +11,7 @@ Gem::Specification.new do |spec| spec.homepage = 'https://github.com/dg-vrnetze/proxy_pac_rb' spec.summary = 'Compress, lint and parse proxy auto-config files from commandline, rack-compatible applications and custom ruby code.' spec.description = <<-DESC -"proxy_pac_rb" is a gem to compress, lint and parse proxy auto-config files. It comes with a cli program, some rack middlewares and can be used from within ruby scripts as well. "proxy_pac_rb" uses a JavaScript runtime to evaulate a proxy auto-config file the same way a browser does to determine what proxy (if any at all) should a program use to connect to a server. You must install on of the supported JavaScript runtimes: therubyracer or therubyrhino +"proxy_pac_rb" is a gem to compress, lint and parse proxy auto-config files. It comes with a cli program, some rack middlewares and can be used from within ruby scripts as well. "proxy_pac_rb" uses a JavaScript runtime to evaulate a proxy auto-config file the same way a browser does to determine what proxy (if any at all) should a program use to connect to a server. You must install on of the supported JavaScript runtimes: miniracer, therubyracer or therubyrhino DESC spec.license = 'MIT'