diff --git a/.hound.yml b/.hound.yml new file mode 100644 index 0000000000..c67bfecae9 --- /dev/null +++ b/.hound.yml @@ -0,0 +1,3 @@ +ruby: + enabled: true + config_file: .rubocop.yml \ No newline at end of file diff --git a/.rubocop.yml b/.rubocop.yml new file mode 100644 index 0000000000..a22df7c695 --- /dev/null +++ b/.rubocop.yml @@ -0,0 +1,265 @@ +AllCops: + Exclude: + - *.gemspec + +AccessorMethodName: + Enabled: false + +ActionFilter: + Enabled: false + +Alias: + Enabled: false + +AndOr: + Enabled: false + +ArrayJoin: + Enabled: false + +AsciiComments: + Enabled: false + +AsciiIdentifiers: + Enabled: false + +Attr: + Enabled: false + +BlockNesting: + Enabled: false + +Blocks: + Enabled: false + +CaseEquality: + Enabled: false + +CharacterLiteral: + Enabled: false + +ClassAndModuleChildren: + Enabled: false + +ClassLength: + Enabled: false + +ClassVars: + Enabled: false + +CollectionMethods: + PreferredMethods: + find: detect + reduce: inject + collect: map + find_all: select + +ColonMethodCall: + Enabled: false + +CommentAnnotation: + Enabled: false + +CyclomaticComplexity: + Enabled: false + +Delegate: + Enabled: false + +DeprecatedHashMethods: + Enabled: false + +Documentation: + Enabled: false + +DotPosition: + EnforcedStyle: leading + +DoubleNegation: + Enabled: false + +EachWithObject: + Enabled: false + +EmptyLiteral: + Enabled: false + +Encoding: + Enabled: false + +EvenOdd: + Enabled: false + +FileName: + Enabled: false + +FlipFlop: + Enabled: false + +FormatString: + Enabled: false + +GlobalVars: + Enabled: false + +GuardClause: + Enabled: false + +IfUnlessModifier: + Enabled: false + +IfWithSemicolon: + Enabled: false + +InlineComment: + Enabled: false + +Lambda: + Enabled: false + +LambdaCall: + Enabled: false + +LineEndConcatenation: + Enabled: false + +LineLength: + Max: 100 + +MethodLength: + Enabled: false + +ModuleFunction: + Enabled: false + +NegatedIf: + Enabled: false + +NegatedWhile: + Enabled: false + +Next: + Enabled: false + +NilComparison: + Enabled: false + +Not: + Enabled: false + +NumericLiterals: + Enabled: false + +OneLineConditional: + Enabled: false + +OpMethod: + Enabled: false + +ParameterLists: + Enabled: false + +PercentLiteralDelimiters: + Enabled: false + +PerlBackrefs: + Enabled: false + +PredicateName: + NamePrefixBlacklist: + - is_ + +Proc: + Enabled: false + +RaiseArgs: + Enabled: false + +RegexpLiteral: + Enabled: false + +SelfAssignment: + Enabled: false + +SingleLineBlockParams: + Enabled: false + +SingleLineMethods: + Enabled: false + +SignalException: + Enabled: false + +SpecialGlobalVars: + Enabled: false + +StringLiterals: + EnforcedStyle: single_quotes + +VariableInterpolation: + Enabled: false + +TrailingComma: + Enabled: false + +TrivialAccessors: + Enabled: false + +VariableInterpolation: + Enabled: false + +WhenThen: + Enabled: false + +WhileUntilModifier: + Enabled: false + +WordArray: + Enabled: false + +# Lint + +AmbiguousOperator: + Enabled: false + +AmbiguousRegexpLiteral: + Enabled: false + +AssignmentInCondition: + Enabled: false + +ConditionPosition: + Enabled: false + +DeprecatedClassMethods: + Enabled: false + +ElseLayout: + Enabled: false + +HandleExceptions: + Enabled: false + +InvalidCharacterLiteral: + Enabled: false + +LiteralInCondition: + Enabled: false + +LiteralInInterpolation: + Enabled: false + +Loop: + Enabled: false + +ParenthesesAsGroupedExpression: + Enabled: false + +RequireParentheses: + Enabled: false + +UnderscorePrefixedVariableName: + Enabled: false + +Void: + Enabled: false \ No newline at end of file diff --git a/lib/open_project/auth_plugins.rb b/lib/open_project/auth_plugins.rb index 68fa31071f..3ddb40b0ef 100644 --- a/lib/open_project/auth_plugins.rb +++ b/lib/open_project/auth_plugins.rb @@ -29,9 +29,9 @@ module OpenProject module AuthPlugins - require "open_project/plugins/auth_plugin" - require "omniauth/flexible_builder" - require "omniauth/flexible_strategy" - require "open_project/auth_plugins/engine" + require 'open_project/plugins/auth_plugin' + require 'omniauth/flexible_builder' + require 'omniauth/flexible_strategy' + require 'open_project/auth_plugins/engine' end end diff --git a/lib/open_project/auth_plugins/engine.rb b/lib/open_project/auth_plugins/engine.rb index 59ef54a123..5a3ea8a087 100644 --- a/lib/open_project/auth_plugins/engine.rb +++ b/lib/open_project/auth_plugins/engine.rb @@ -36,8 +36,8 @@ module OpenProject::AuthPlugins include OpenProject::Plugins::ActsAsOpEngine register 'openproject-auth_plugins', - :author_url => 'http://finn.de', - :requires_openproject => '>= 3.1.0pre1' + author_url: 'http://finn.de', + requires_openproject: '>= 3.1.0pre1' initializer 'auth_plugins.register_hooks' do require 'open_project/auth_plugins/hooks' diff --git a/lib/open_project/auth_plugins/hooks.rb b/lib/open_project/auth_plugins/hooks.rb index 039bfce1da..9cd6797040 100644 --- a/lib/open_project/auth_plugins/hooks.rb +++ b/lib/open_project/auth_plugins/hooks.rb @@ -29,6 +29,6 @@ module OpenProject::AuthPlugins class Hooks < Redmine::Hook::ViewListener - render_on :view_account_login_auth_provider, :partial => 'hooks/login/providers' + render_on :view_account_login_auth_provider, partial: 'hooks/login/providers' end end diff --git a/lib/open_project/auth_plugins/version.rb b/lib/open_project/auth_plugins/version.rb index cb2c3bb528..b64fbe4828 100644 --- a/lib/open_project/auth_plugins/version.rb +++ b/lib/open_project/auth_plugins/version.rb @@ -29,6 +29,6 @@ module OpenProject module AuthPlugins - VERSION = "4.1.0" + VERSION = '4.1.0' end end diff --git a/lib/open_project/plugins/auth_plugin.rb b/lib/open_project/plugins/auth_plugin.rb index 467c8da0b7..f2e53e4ffb 100644 --- a/lib/open_project/plugins/auth_plugin.rb +++ b/lib/open_project/plugins/auth_plugin.rb @@ -47,20 +47,20 @@ module OpenProject::Plugins end def self.providers_for(strategy) - strategies[strategy_key(strategy)].map(&:call).flatten.map { |p| p.to_hash } + strategies[strategy_key(strategy)].map(&:call).flatten.map(&:to_hash) end def self.providers - strategies.values.flatten.map(&:call).flatten.map { |p| p.to_hash } + strategies.values.flatten.map(&:call).flatten.map(&:to_hash) end def self.strategy_key(strategy) return strategy if strategy.is_a? Symbol name = strategy.name.demodulize - camelization = OmniAuth.config.camelizations.select do |k, v| + camelization = OmniAuth.config.camelizations.select do |_k, v| v == name - end.take(1).map do |k, v| + end.take(1).map do |k, _v| k end.first diff --git a/openproject-auth_plugins.gemspec b/openproject-auth_plugins.gemspec index 7ca76a3f7b..a8d91c251f 100644 --- a/openproject-auth_plugins.gemspec +++ b/openproject-auth_plugins.gemspec @@ -1,22 +1,22 @@ # encoding: UTF-8 -$:.push File.expand_path("../lib", __FILE__) +$:.push File.expand_path('../lib', __FILE__) require 'open_project/auth_plugins/version' Gem::Specification.new do |s| - s.name = "openproject-auth_plugins" + s.name = 'openproject-auth_plugins' s.version = OpenProject::AuthPlugins::VERSION - s.authors = "Finn GmbH" - s.email = "info@finn.de" - s.homepage = "https://www.openproject.org/projects/auth-plugins" + s.authors = 'Finn GmbH' + s.email = 'info@finn.de' + s.homepage = 'https://www.openproject.org/projects/auth-plugins' s.summary = 'OpenProject Auth Plugins' - s.description = "Integration of OmniAuth strategy providers for authentication in Openproject." - s.license = "GPLv3" + s.description = 'Integration of OmniAuth strategy providers for authentication in Openproject.' + s.license = 'GPLv3' - s.files = Dir["{app,config,db,lib}/**/*"] + %w(doc/CHANGELOG.md README.md) + s.files = Dir['{app,config,db,lib}/**/*'] + %w(doc/CHANGELOG.md README.md) - s.add_dependency "rails", "~> 3.2.14" - s.add_dependency "omniauth", "~> 1.0" + s.add_dependency 'rails', '~> 3.2.14' + s.add_dependency 'omniauth', '~> 1.0' - s.add_development_dependency "rspec", "~> 2.14" + s.add_development_dependency 'rspec', '~> 2.14' end diff --git a/spec/requests/auth_plugins.rb b/spec/requests/auth_plugins.rb index 1f0f16ac3b..b8ec93dcce 100644 --- a/spec/requests/auth_plugins.rb +++ b/spec/requests/auth_plugins.rb @@ -37,13 +37,13 @@ describe OpenProject::Plugins::AuthPlugin do let(:strategies) { {} } let(:providers_a) do - lambda { [{name: 'a1'}, {name: 'a2'}] } + lambda { [{ name: 'a1' }, { name: 'a2' }] } end let(:providers_b) do - lambda { [{name: 'b1'}] } + lambda { [{ name: 'b1' }] } end let(:providers_c) do - lambda { [{name: 'c1'}] } + lambda { [{ name: 'c1' }] } end let(:middlewares) { [] } @@ -56,7 +56,7 @@ describe OpenProject::Plugins::AuthPlugin do middlewares << strategy } - app.stub_chain(:config, :middleware, :use) { |mw, &block| + app.stub_chain(:config, :middleware, :use) { |_mw, &block| omniauth_builder.instance_eval(&block) } diff --git a/spec/requests/flexible_strategy_spec.rb b/spec/requests/flexible_strategy_spec.rb index 543d0875ae..41d9bf9fe7 100644 --- a/spec/requests/flexible_strategy_spec.rb +++ b/spec/requests/flexible_strategy_spec.rb @@ -38,16 +38,16 @@ describe OmniAuth::FlexibleStrategy do end end - def env_for(url, opts={}) + def env_for(url, opts = {}) Rack::MockRequest.env_for(url, opts).tap do |env| env['rack.session'] = {} end end - let(:app) { ->(env) { [200, env, "ok"] } } + let(:app) { ->(env) { [200, env, 'ok'] } } let(:middleware) { MockStrategy.new(app) } - let(:provider_a) { {name: 'provider_a', identifier: 'a'} } - let(:provider_b) { {name: 'provider_b', identifier: 'b'} } + let(:provider_a) { { name: 'provider_a', identifier: 'a' } } + let(:provider_b) { { name: 'provider_b', identifier: 'b' } } before do allow(OpenProject::Plugins::AuthPlugin).to receive(:providers_for).with(MockStrategy) { @@ -67,7 +67,7 @@ describe OmniAuth::FlexibleStrategy do end it 'should not match other paths' do - code, env = middleware.call env_for("http://www.example.com/auth/other_provider") + code, env = middleware.call env_for('http://www.example.com/auth/other_provider') expect(env).not_to include 'omniauth.strategy' # no hit end @@ -87,7 +87,7 @@ describe OmniAuth::FlexibleStrategy do end it 'should not match other paths' do - code, env = middleware.call env_for("http://www.example.com/auth/other_provider/callback") + code, env = middleware.call env_for('http://www.example.com/auth/other_provider/callback') expect(code).to eq 200 expect(env).not_to include 'omniauth.strategy' # no hit @@ -116,16 +116,16 @@ describe OmniAuth::FlexibleStrategy do context 'with a mapping set' do it 'returns an attribute hash' do - middleware.call env_for("http://www.example.com/auth/provider_with_mapping") + middleware.call env_for('http://www.example.com/auth/provider_with_mapping') attribute_map = middleware.omniauth_hash_to_user_attributes(auth_hash) - expect(attribute_map).to eq({ uid: 'foo', mail: 'foo@example.com' }) + expect(attribute_map).to eq(uid: 'foo', mail: 'foo@example.com') end end context 'without a mapping set' do it 'returns an empty hash' do - middleware.call env_for("http://www.example.com/auth/provider_a") + middleware.call env_for('http://www.example.com/auth/provider_a') attribute_map = middleware.omniauth_hash_to_user_attributes(auth_hash) expect(attribute_map).to eq({}) diff --git a/spec/views/hooks/login/_providers.html.erb_spec.rb b/spec/views/hooks/login/_providers.html.erb_spec.rb index 37c3b0afa6..60ea99e042 100644 --- a/spec/views/hooks/login/_providers.html.erb_spec.rb +++ b/spec/views/hooks/login/_providers.html.erb_spec.rb @@ -31,16 +31,16 @@ require 'spec_helper' describe 'rendering the login buttons for all providers' do let(:providers) do [ - {name: 'mock_auth'}, - {name: 'test_auth', display_name: 'Test'}, - {name: 'foob_auth', icon: 'foobar.png'} + { name: 'mock_auth' }, + { name: 'test_auth', display_name: 'Test' }, + { name: 'foob_auth', icon: 'foobar.png' } ] end before do allow(OpenProject::Plugins::AuthPlugin).to receive(:providers).and_return(providers) - render :partial => 'hooks/login/providers', :handlers => [:erb], :formats => [:html] + render partial: 'hooks/login/providers', handlers: [:erb], formats: [:html] end it 'should show the mock_auth button with the name as its label' do