From 1a80569af4e1194881b6893bd235c6ffa94a07e0 Mon Sep 17 00:00:00 2001 From: Dmitry Overchuk Date: Wed, 27 Jan 2021 18:11:56 +0300 Subject: [PATCH] Added rubocop support --- .rubocop.yml | 376 ++++++++++++++++++++++++++++++++++++++++++++++ Example/Podfile | 2 +- Gemfile | 10 +- Gemfile.lock | 26 +++- TinkoffID.podspec | 8 +- fastlane/Fastfile | 118 ++++++++------- 6 files changed, 474 insertions(+), 66 deletions(-) create mode 100644 .rubocop.yml diff --git a/.rubocop.yml b/.rubocop.yml new file mode 100644 index 0000000..18399d5 --- /dev/null +++ b/.rubocop.yml @@ -0,0 +1,376 @@ +require: + - rubocop/require_tools + +AllCops: + TargetRubyVersion: 2.6 + Exclude: + - 'bin/**/*' + +Style/MultipleComparison: + Enabled: false + +Style/PercentLiteralDelimiters: + Enabled: false + +# kind_of? is a good way to check a type +Style/ClassCheck: + EnforcedStyle: kind_of? + +Style/FrozenStringLiteralComment: + Enabled: false + +# This doesn't work with older versions of Ruby (pre 2.4.0) +Style/SafeNavigation: + Enabled: false + +# .length == 0 is also good, we don't always want .zero? +Style/NumericPredicate: + Enabled: false + +# this would cause errors with long lanes +Metrics/BlockLength: + Enabled: false + +# this is a bit buggy +Metrics/ModuleLength: + Enabled: false + +# certificate_1 is an okay variable name +Naming/VariableNumber: + Enabled: false + +# This is used a lot across the fastlane code base for config files +Lint/MissingSuper: + Enabled: false + +Style/MissingRespondToMissing: + Enabled: false + +# This rule isn't useful, lots of discussion happening around it also +# e.g. https://github.com/bbatsov/rubocop/issues/2338 +# MultilineBlockChain: +# Enabled: false + +# +# File.chmod(0777, f) +# +# is easier to read than +# +# File.chmod(0o777, f) +# +Style/NumericLiteralPrefix: + Enabled: false + +# +# command = (!clean_expired.nil? || !clean_pattern.nil?) ? CLEANUP : LIST +# +# is easier to read than +# +# command = !clean_expired.nil? || !clean_pattern.nil? ? CLEANUP : LIST +# +Style/TernaryParentheses: + Enabled: false + +# sometimes it is useful to have those empty methods +Style/EmptyMethod: + Enabled: false + +Require/MissingRequireStatement: + Enabled: false + +# We could potentially enable the 2 below: +Layout/FirstHashElementIndentation: + Enabled: false + +Layout/HashAlignment: + Enabled: false + +# HoundCI doesn't like this rule +Layout/DotPosition: + Enabled: false + +# We allow !! as it's an easy way to convert to boolean +Style/DoubleNegation: + Enabled: false + +# Prevent to replace [] into %i +Style/SymbolArray: + Enabled: false + +# We still support Ruby 2.0.0 +Layout/HeredocIndentation: + Enabled: false + +# Sometimes we allow a rescue block that doesn't contain code +Lint/SuppressedException: + Enabled: false + +# Cop supports --auto-correct. +Lint/UnusedBlockArgument: + Enabled: false + +Lint/AmbiguousBlockAssociation: + Enabled: false + +# Needed for $verbose +Style/GlobalVars: + Enabled: false + +# We want to allow class Fastlane::Class +Style/ClassAndModuleChildren: + Enabled: false + +# $? Exit +Style/SpecialGlobalVars: + Enabled: false + +Metrics/AbcSize: + Enabled: false + +Metrics/MethodLength: + Enabled: false + +Metrics/CyclomaticComplexity: + Enabled: false + +# The %w might be confusing for new users +Style/WordArray: + MinSize: 19 + +# raise and fail are both okay +Style/SignalException: + Enabled: false + +# Better too much 'return' than one missing +Style/RedundantReturn: + Enabled: false + +# Having if in the same line might not always be good +Style/IfUnlessModifier: + Enabled: false + +# and and or is okay +Style/AndOr: + Enabled: true + EnforcedStyle: conditionals + +# Configuration parameters: CountComments. +Metrics/ClassLength: + Max: 320 + + +# Configuration parameters: AllowURI, URISchemes. +Layout/LineLength: + Max: 370 + +# Configuration parameters: CountKeywordArgs. +Metrics/ParameterLists: + Max: 17 + +Metrics/PerceivedComplexity: + Max: 18 + +# Sometimes it's easier to read without guards +Style/GuardClause: + Enabled: false + +# We allow both " and ' +Style/StringLiterals: + Enabled: false + +# something = if something_else +# that's confusing +Style/ConditionalAssignment: + Enabled: false + +# Better to have too much self than missing a self +Style/RedundantSelf: + Enabled: false + +# e.g. +# def self.is_supported?(platform) +# we may never use `platform` +Lint/UnusedMethodArgument: + Enabled: false + +# the let(:key) { ... } +Lint/ParenthesesAsGroupedExpression: + Enabled: true + +# This would reject is_ in front of methods +# We use `is_supported?` everywhere already +Naming/PredicateName: + Enabled: false + +# We allow the $ +Style/PerlBackrefs: + Enabled: false + +# Disable '+ should be surrounded with a single space' for xcodebuild_spec.rb +Layout/SpaceAroundOperators: + Enabled: true + +# They have not to be snake_case +Naming/FileName: + Exclude: + - '**/Brewfile' + - '**/Gemfile' + - '**/Podfile' + - '**/Rakefile' + - '**/Fastfile' + - '**/Deliverfile' + - '**/Snapfile' + - '**/*.gemspec' + - '**/*.podspec' + +# We're not there yet +Style/Documentation: + Enabled: false + +# Added after upgrade to 0.38.0 +Style/MutableConstant: + Enabled: false + +# length > 0 is good +Style/ZeroLengthPredicate: + Enabled: false + +# Adds complexity +Style/IfInsideElse: + Enabled: false + +# Sometimes we just want to 'collect' +Style/CollectionMethods: + Enabled: false + +Naming/AccessorMethodName: + Enabled: false + +# ( ) for method calls +Style/MethodCallWithArgsParentheses: + Enabled: true + IgnoredMethods: + - 'require' + - 'require_relative' + - 'fastlane_require' + - 'gem' + - 'program' + - 'command' + - 'raise' + - 'attr_accessor' + - 'attr_reader' + - 'desc' + - 'lane' + - 'private_lane' + - 'platform' + # rspec tests code below + - 'to' + - 'not_to' + - 'describe' + - 'it' + - 'be' + - 'context' + - 'before' + - 'after' + +# suggested by rubocop +Layout/BeginEndAlignment: # (new in 0.91) + Enabled: true +Layout/EmptyLinesAroundAttributeAccessor: # (new in 0.83) + Enabled: true +Layout/SpaceAroundMethodCallOperator: # (new in 0.82) + Enabled: true +Lint/BinaryOperatorWithIdenticalOperands: # (new in 0.89) + Enabled: true +Lint/ConstantDefinitionInBlock: # (new in 0.91) + Enabled: true +Lint/DeprecatedOpenSSLConstant: # (new in 0.84) + Enabled: true +Lint/DuplicateElsifCondition: # (new in 0.88) + Enabled: true +Lint/DuplicateRequire: # (new in 0.90) + Enabled: true +Lint/DuplicateRescueException: # (new in 0.89) + Enabled: true +Lint/EmptyConditionalBody: # (new in 0.89) + Enabled: true +Lint/EmptyFile: # (new in 0.90) + Enabled: true +Lint/FloatComparison: # (new in 0.89) + Enabled: true +Lint/HashCompareByIdentity: # (new in 0.93) + Enabled: true +Lint/IdentityComparison: # (new in 0.91) + Enabled: true +Lint/MixedRegexpCaptureTypes: # (new in 0.85) + Enabled: true +Lint/OutOfRangeRegexpRef: # (new in 0.89) + Enabled: true +Lint/RaiseException: # (new in 0.81) + Enabled: true +Lint/RedundantSafeNavigation: # (new in 0.93) + Enabled: true +Lint/SelfAssignment: # (new in 0.89) + Enabled: true +Lint/StructNewOverride: # (new in 0.81) + Enabled: true +Lint/TopLevelReturnWithArgument: # (new in 0.89) + Enabled: true +Lint/TrailingCommaInAttributeDeclaration: # (new in 0.90) + Enabled: true +Lint/UnreachableLoop: # (new in 0.89) + Enabled: true +Lint/UselessMethodDefinition: # (new in 0.90) + Enabled: true +Lint/UselessTimes: # (new in 0.91) + Enabled: true +Style/AccessorGrouping: # (new in 0.87) + Enabled: true +Style/BisectedAttrAccessor: # (new in 0.87) + Enabled: true +Style/CaseLikeIf: # (new in 0.88) + Enabled: true +Style/ClassEqualityComparison: # (new in 0.93) + Enabled: true +Style/CombinableLoops: # (new in 0.90) + Enabled: true +Style/ExplicitBlockArgument: # (new in 0.89) + Enabled: true +Style/ExponentialNotation: # (new in 0.82) + Enabled: true +Style/GlobalStdStream: # (new in 0.89) + Enabled: true +Style/HashAsLastArrayItem: # (new in 0.88) + Enabled: true +Style/HashEachMethods: # (new in 0.80) + Enabled: true +Style/HashLikeCase: # (new in 0.88) + Enabled: true +Style/HashTransformKeys: # (new in 0.80) + Enabled: true +Style/HashTransformValues: # (new in 0.80) + Enabled: true +Style/KeywordParametersOrder: # (new in 0.90) + Enabled: true +Style/OptionalBooleanParameter: # (new in 0.89) + Enabled: true +Style/RedundantAssignment: # (new in 0.87) + Enabled: true +Style/RedundantFetchBlock: # (new in 0.86) + Enabled: true +Style/RedundantFileExtensionInRequire: # (new in 0.88) + Enabled: true +Style/RedundantRegexpCharacterClass: # (new in 0.85) + Enabled: true +Style/RedundantRegexpEscape: # (new in 0.85) + Enabled: true +Style/RedundantSelfAssignment: # (new in 0.90) + Enabled: true +Style/SingleArgumentDig: # (new in 0.89) + Enabled: true +Style/SlicingWithRange: # (new in 0.83) + Enabled: true +Style/SoleNestedConditional: # (new in 0.89) + Enabled: true +Style/StringConcatenation: # (new in 0.89) + Enabled: true diff --git a/Example/Podfile b/Example/Podfile index 63f6c3c..68edf55 100644 --- a/Example/Podfile +++ b/Example/Podfile @@ -1,6 +1,6 @@ use_frameworks! target 'TinkoffIDExample' do - pod 'TinkoffID', :path => '../', :testspecs => ['Tests'] + pod 'TinkoffID', path: '../', testspecs: ['Tests'] pod 'SnapKit' end diff --git a/Gemfile b/Gemfile index e4b5be5..253977a 100644 --- a/Gemfile +++ b/Gemfile @@ -1,11 +1,9 @@ -# Autogenerated by fastlane -# -# Ensure this file is checked in to source control! - source "https://rubygems.org" -gem 'fastlane' -gem 'cocoapods' +gem 'cocoapods', '~> 1.10.1' +gem 'fastlane', '~> 2.172.0' +gem 'rubocop', '~> 0.93.1' +gem 'rubocop-require_tools' plugins_path = File.join(File.dirname(__FILE__), 'fastlane', 'Pluginfile') eval_gemfile(plugins_path) if File.exist?(plugins_path) diff --git a/Gemfile.lock b/Gemfile.lock index 794c41e..ef0fccf 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -13,6 +13,7 @@ GEM httpclient (~> 2.8, >= 2.8.3) json (>= 1.5.1) artifactory (3.0.15) + ast (2.4.2) atomos (0.1.3) aws-eventstream (1.1.0) aws-partitions (1.419.0) @@ -203,9 +204,14 @@ GEM naturally (2.2.1) netrc (0.11.0) os (1.1.1) + parallel (1.20.1) + parser (3.0.0.0) + ast (~> 2.4.1) plist (3.6.0) public_suffix (4.0.6) + rainbow (3.0.0) rake (13.0.3) + regexp_parser (2.0.3) representable (3.0.4) declarative (< 0.1.0) declarative-option (< 0.2.0) @@ -213,7 +219,21 @@ GEM retriable (3.1.2) rexml (3.2.4) rouge (2.0.7) + rubocop (0.93.1) + parallel (~> 1.10) + parser (>= 2.7.1.5) + rainbow (>= 2.2.2, < 4.0) + regexp_parser (>= 1.8) + rexml + rubocop-ast (>= 0.6.0) + ruby-progressbar (~> 1.7) + unicode-display_width (>= 1.4.0, < 2.0) + rubocop-ast (1.4.1) + parser (>= 2.7.1.5) + rubocop-require_tools (0.1.2) + rubocop (>= 0.49.1) ruby-macho (1.4.0) + ruby-progressbar (1.11.0) ruby2_keywords (0.0.4) rubyzip (2.3.0) security (0.1.3) @@ -260,9 +280,11 @@ PLATFORMS ruby DEPENDENCIES - cocoapods - fastlane + cocoapods (~> 1.10.1) + fastlane (~> 2.172.0) fastlane-plugin-changelog + rubocop (~> 0.93.1) + rubocop-require_tools BUNDLED WITH 2.1.4 diff --git a/TinkoffID.podspec b/TinkoffID.podspec index 7ffd290..3b985db 100644 --- a/TinkoffID.podspec +++ b/TinkoffID.podspec @@ -4,14 +4,14 @@ Pod::Spec.new do |s| s.version = '0.0.1' s.author = { 'Дмитрий Оверчук' => 'd.overchuk@tinkoff.ru' } s.homepage = 'https://github.com/tinkoff-mobile-tech/TinkoffID' - s.license = { :type => 'MIT', :file => 'LICENSE' } - s.source = { :git => 'https://github.com/tinkoff-mobile-tech/TinkoffID.git', :tag => s.version.to_s } + s.license = { type: 'MIT', file: 'LICENSE' } + s.source = { git: 'https://github.com/tinkoff-mobile-tech/TinkoffID.git', tag: s.version.to_s } s.ios.deployment_target = '10.0' s.swift_version = '5.0' s.source_files = 'Sources/**/*.swift' s.resources = 'Sources/**/*.{xcassets,lproj}' - s.test_spec 'Tests' do |test_spec| - test_spec.source_files = 'Tests/**/*.{swift}' + s.test_spec('Tests') do |test_spec| + test_spec.source_files = 'Tests/**/*.{swift}' end end diff --git a/fastlane/Fastfile b/fastlane/Fastfile index 69882cc..f3d7fa8 100644 --- a/fastlane/Fastfile +++ b/fastlane/Fastfile @@ -1,78 +1,90 @@ - lane :release do |options| - # Checking bump type - bump_type = resolve_bump_type(options) - - # Checking that everything is alright - checkup() + # Checking bump type + bump_type = resolve_bump_type(options) + + # Checking that everything is alright + checkup - # Checking git - ensure_git_status_clean() - ensure_git_branch(branch: "master") + # Checking git + ensure_git_status_clean + ensure_git_branch(branch: "master") - # Bumping podspec version - version = version_bump_podspec(bump_type: bump_type) + # Bumping podspec version + version = version_bump_podspec(bump_type: bump_type) - # Stamping changelog - stamp_changelog(section_identifier: version) + # Stamping changelog + stamp_changelog(section_identifier: version) - # Creating release commit and tag - git_commit(path: "CHANGELOG.md", message: "Release #{version}") - add_git_tag(tag: version) + # Creating release commit and tag + git_commit(path: "CHANGELOG.md", message: "Release #{version}") + add_git_tag(tag: version) - # Pushing to remote repo - push_to_git_remote(tags: true) + # Pushing to remote repo + push_to_git_remote(tags: true) - #Pushing podspec to Cocoapods repo - push_podspec() + # Pushing podspec to Cocoapods repo + push_podspec end lane :checkup do - # Linting podspec - lint_podspec() + # Linting ruby files + lint_ruby_files + + # Linting podspec + lint_podspec - # Buidling Swift package - build_swift_package() + # Buidling Swift package + build_swift_package end lane :build_swift_package do - project_name = "TinkoffID.xcodeproj" - scheme_name = "TinkoffID-Package" - config_file_name = "Config.xcconfig" - - # Creating configuration file - sh("echo SWIFT_ACTIVE_COMPILATION_CONDITIONS=''> #{config_file_name}") - - # Generating xcode project - sh("swift package generate-xcodeproj --xcconfig-overrides #{config_file_name}") - - # Building generated xcode project - sh("xcodebuild clean build -project ../#{project_name} -sdk iphoneos -scheme '#{scheme_name}'") - - #Cleaning up - sh("rm -f #{config_file_name}") - sh("rm -rf ../#{project_name}") + project_name = "TinkoffID.xcodeproj" + scheme_name = "TinkoffID-Package" + config_file_name = "Config.xcconfig" + + # Creating configuration file + sh("echo SWIFT_ACTIVE_COMPILATION_CONDITIONS=''> #{config_file_name}") + + # Generating xcode project + sh("swift package generate-xcodeproj --xcconfig-overrides #{config_file_name}") + + # Building generated xcode project + sh("xcodebuild clean build -project ../#{project_name} -sdk iphoneos -scheme '#{scheme_name}'") + + # Cleaning up + sh("rm -f #{config_file_name}") + sh("rm -rf ../#{project_name}") end -lane :lint_podspec do - pod_lib_lint(allow_warnings: true) +lane :lint_ruby_files do + pod_lib_lint(allow_warnings: true) +end + +lane :lint_fastfile do + Dir.chdir("..") do + error_callback = lambda do |result| + UI.user_error!("rubocop execution failed: #{result}") + end + + sh('bundle exec rubocop -c .rubocop.yml', error_callback: error_callback) + end end lane :push_podspec do - podspec_name = "TinkoffID.podspec" + podspec_name = "TinkoffID.podspec" - pod_push( - path: podspec_name, - allow_warnings: true, - skip_tests: true - ) + pod_push( + path: podspec_name, + allow_warnings: true, + skip_tests: true + ) end def resolve_bump_type(options) - valid_bump_types = ['patch', 'minor', 'major'] - bump_type = valid_bump_types.include?(options[:type]) ? options[:type] : nil + valid_bump_types = ['patch', 'minor', 'major'] + bump_type = valid_bump_types.include?(options[:type]) ? options[:type] : nil - UI.abort_with_message! ("Bump type is not specified or incorrect! You can use `type: #{valid_bump_types.join('/')}` to specify it.") unless bump_type + UI.abort_with_message!("Bump type is not specified or incorrect! You can use `type: #{valid_bump_types.join('/')}` to specify it.") unless bump_type - return bump_type -end \ No newline at end of file + return bump_type +end