From f62c956a02ec77ba0b47240d10424608698dbdfd Mon Sep 17 00:00:00 2001 From: Tayler Phillips Date: Mon, 7 Oct 2024 14:12:07 -0400 Subject: [PATCH 1/8] Add rubocop --- Gemfile | 11 +++++ rubocop.yml | 91 ++++++++++++++++++++++++++++++++++++++ salesforce_ar_sync.gemspec | 11 +---- 3 files changed, 103 insertions(+), 10 deletions(-) create mode 100644 rubocop.yml diff --git a/Gemfile b/Gemfile index ea7339b..29dcda3 100644 --- a/Gemfile +++ b/Gemfile @@ -3,3 +3,14 @@ source 'https://rubygems.org' gemspec gem "appraisal" +gem "rubocop", "~> 1.66" + +gem "rubocop-rspec", "~> 3.1" + +gem "rubocop-performance", "~> 1.22" +gem 'ammeter', '~> 1.1.2' +gem 'rake' +gem 'rspec' +gem 'sqlite3', '~> 1.4' +gem 'vcr' +gem 'webmock' diff --git a/rubocop.yml b/rubocop.yml new file mode 100644 index 0000000..bf25bbf --- /dev/null +++ b/rubocop.yml @@ -0,0 +1,91 @@ +require: + - rubocop-rspec + - rubocop-performance + +AllCops: + NewCops: enable + # Exclude: + # - config/**/* + ExtraDetails: enable + +# Ruby + +Layout/LineLength: + Max: 120 + +Layout/MultilineMethodCallBraceLayout: + EnforcedStyle: new_line + +Lint/AmbiguousBlockAssociation: + AllowedMethods: [change not_change] + +Metrics/AbcSize: + Severity: warning + CountRepeatedAttributes: false # potential change + +Metrics/ClassLength: + Max: 300 + Details: >- + Look for ways to decrease class size by pulling logic into services, concerns, etc. + +Metrics/MethodLength: + CountAsOne: ['array', 'hash', 'heredoc', 'method_call'] + +Metrics/CyclomaticComplexity: + Severity: warning + Details: >- + Look for ways to simplify/refactor the method. Pull logic out into more specific methods. + +Metrics/ModuleLength: + Enabled: false + +Metrics/PerceivedComplexity: + Severity: warning + Details: >- + Look for ways to simplify/refactor the method. Pull logic out into more specific methods. + +Style/AndOr: + EnforcedStyle: always + Details: >- + And/Or methods have unexpected complexity attached to them. Try not to use them. + +Style/Documentation: + Enabled: false + +Style/FrozenStringLiteralComment: + Details: >- + Add `# frozen_string_literal: true` to the top of the file. + Frozen string literals help the memory profile of the application by making strings immutable and register a single time. + +Style/NumericLiterals: + Severity: warning + +# RSpec + +RSpec/DescribeClass: + Exclude: + - '**/spec/features/**/*' + - '**/spec/requests/**/*' + - '**/spec/routing/**/*' + - '**/spec/system/**/*' + - '**/spec/views/**/*' + IgnoredMetadata: + type: + - request + - routing + - view + - feature + - system + - task + +RSpec/ExampleLength: + CountAsOne: + - array + - heredoc + - hash + +RSpec/NestedGroups: + Max: 5 + +RSpec/PredicateMatcher: + Enabled: false diff --git a/salesforce_ar_sync.gemspec b/salesforce_ar_sync.gemspec index 1bc06fe..47c1646 100644 --- a/salesforce_ar_sync.gemspec +++ b/salesforce_ar_sync.gemspec @@ -9,21 +9,12 @@ Gem::Specification.new do |gem| gem.files = Dir['README.md', 'LICENSE', 'lib/**/*', 'app/**/*', 'config/**/*'] gem.executables = gem.files.grep(%r{^bin/}).map { |f| File.basename(f) } - gem.test_files = gem.files.grep(%r{^(test|spec|features)/}) gem.name = 'salesforce_ar_sync' gem.require_paths = ['lib'] gem.version = SalesforceArSync::VERSION gem.add_dependency 'actionpack-xml_parser' gem.add_dependency 'rails', '>= 5' + gem.add_dependency 'restforce', '~> 5.0.5' gem.add_dependency 'rexml', '~> 3.2' - - gem.add_development_dependency 'ammeter', '~> 1.1.2' - gem.add_development_dependency 'rake' - gem.add_development_dependency 'rspec' - gem.add_development_dependency 'sqlite3', '~> 1.4' - gem.add_development_dependency 'vcr' - gem.add_development_dependency 'webmock' - - gem.add_runtime_dependency 'restforce', '~> 5.0.5' end From f455b5ab75aaf50c627e34120fd7eef00f8ccdbf Mon Sep 17 00:00:00 2001 From: Tayler Phillips Date: Mon, 7 Oct 2024 15:14:21 -0400 Subject: [PATCH 2/8] Setup trunk in the repo. Apply suggestions after running manaul check --- .trunk/.gitignore | 9 +++++++++ .trunk/configs/.markdownlint.yaml | 2 ++ .trunk/configs/.yamllint.yaml | 7 +++++++ .trunk/trunk.yaml | 31 +++++++++++++++++++++++++++++++ rubocop.yml | 12 ++++++------ salesforce_ar_sync.gemspec | 3 ++- 6 files changed, 57 insertions(+), 7 deletions(-) create mode 100644 .trunk/.gitignore create mode 100644 .trunk/configs/.markdownlint.yaml create mode 100644 .trunk/configs/.yamllint.yaml create mode 100644 .trunk/trunk.yaml diff --git a/.trunk/.gitignore b/.trunk/.gitignore new file mode 100644 index 0000000..15966d0 --- /dev/null +++ b/.trunk/.gitignore @@ -0,0 +1,9 @@ +*out +*logs +*actions +*notifications +*tools +plugins +user_trunk.yaml +user.yaml +tmp diff --git a/.trunk/configs/.markdownlint.yaml b/.trunk/configs/.markdownlint.yaml new file mode 100644 index 0000000..b40ee9d --- /dev/null +++ b/.trunk/configs/.markdownlint.yaml @@ -0,0 +1,2 @@ +# Prettier friendly markdownlint config (all formatting rules disabled) +extends: markdownlint/style/prettier diff --git a/.trunk/configs/.yamllint.yaml b/.trunk/configs/.yamllint.yaml new file mode 100644 index 0000000..184e251 --- /dev/null +++ b/.trunk/configs/.yamllint.yaml @@ -0,0 +1,7 @@ +rules: + quoted-strings: + required: only-when-needed + extra-allowed: ["{|}"] + key-duplicates: {} + octal-values: + forbid-implicit-octal: true diff --git a/.trunk/trunk.yaml b/.trunk/trunk.yaml new file mode 100644 index 0000000..123b464 --- /dev/null +++ b/.trunk/trunk.yaml @@ -0,0 +1,31 @@ +# This file controls the behavior of Trunk: https://docs.trunk.io/cli +# To learn more about the format of this file, see https://docs.trunk.io/reference/trunk-yaml +version: 0.1 +cli: + version: 1.22.6 +# Trunk provides extensibility via plugins. (https://docs.trunk.io/plugins) +plugins: + sources: + - id: trunk + ref: v1.6.3 + uri: https://github.com/trunk-io/plugins +# Many linters and tools depend on runtimes - configure them here. (https://docs.trunk.io/runtimes) +runtimes: + enabled: + - node@18.12.1 + - python@3.10.8 + - ruby@3.1.4 +# This is the section where you manage your linters. (https://docs.trunk.io/check/configuration) +lint: + enabled: + - rubocop@1.39.0 + - brakeman@5.4.0 + - checkov@3.2.257 + - git-diff-check + - markdownlint@0.42.0 + - prettier@3.3.3 + - trufflehog@3.82.6 + - yamllint@1.35.1 +actions: + enabled: + - trunk-upgrade-available diff --git a/rubocop.yml b/rubocop.yml index bf25bbf..d249211 100644 --- a/rubocop.yml +++ b/rubocop.yml @@ -29,7 +29,7 @@ Metrics/ClassLength: Look for ways to decrease class size by pulling logic into services, concerns, etc. Metrics/MethodLength: - CountAsOne: ['array', 'hash', 'heredoc', 'method_call'] + CountAsOne: ["array", "hash", "heredoc", "method_call"] Metrics/CyclomaticComplexity: Severity: warning @@ -64,11 +64,11 @@ Style/NumericLiterals: RSpec/DescribeClass: Exclude: - - '**/spec/features/**/*' - - '**/spec/requests/**/*' - - '**/spec/routing/**/*' - - '**/spec/system/**/*' - - '**/spec/views/**/*' + - "**/spec/features/**/*" + - "**/spec/requests/**/*" + - "**/spec/routing/**/*" + - "**/spec/system/**/*" + - "**/spec/views/**/*" IgnoredMetadata: type: - request diff --git a/salesforce_ar_sync.gemspec b/salesforce_ar_sync.gemspec index 47c1646..9d68a08 100644 --- a/salesforce_ar_sync.gemspec +++ b/salesforce_ar_sync.gemspec @@ -2,7 +2,8 @@ require File.expand_path('lib/salesforce_ar_sync/version', __dir__) Gem::Specification.new do |gem| gem.authors = ['Michael Halliday', 'Nick Neufeld', 'Andrew Coates', 'Devon Noonan', 'Liam Nediger'] - gem.email = ['mhalliday@infotech.com', 'nneufeld@infotech.com', 'acoates@infotech.com', 'dnoonan@infotech.com', 'lnediger@infotech.com'] + gem.email = ['mhalliday@infotech.com', 'nneufeld@infotech.com', 'acoates@infotech.com', + 'dnoonan@infotech.com', 'lnediger@infotech.com'] gem.description = 'ActiveRecord extension & rails engine for syncing data with Salesforce.com' gem.summary = 'ActiveRecord extension & rails engine for syncing data with Salesforce.com' gem.homepage = 'http://github.com/InfoTech/' From 18399bea685f2f6a8c28363a2f5b4c8da2752a34 Mon Sep 17 00:00:00 2001 From: Tayler Phillips Date: Mon, 7 Oct 2024 15:18:28 -0400 Subject: [PATCH 3/8] Unquote strings in rubocop.yml --- rubocop.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rubocop.yml b/rubocop.yml index d249211..424fc6c 100644 --- a/rubocop.yml +++ b/rubocop.yml @@ -29,7 +29,7 @@ Metrics/ClassLength: Look for ways to decrease class size by pulling logic into services, concerns, etc. Metrics/MethodLength: - CountAsOne: ["array", "hash", "heredoc", "method_call"] + CountAsOne: [array, hash, heredoc, method_call] Metrics/CyclomaticComplexity: Severity: warning From ac2166e7200ee60ffeb55803affd489e6e4430da Mon Sep 17 00:00:00 2001 From: Tayler Phillips Date: Mon, 7 Oct 2024 15:54:36 -0400 Subject: [PATCH 4/8] Add some rubocop lintable code --- lib/salesforce_ar_sync.rb | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/lib/salesforce_ar_sync.rb b/lib/salesforce_ar_sync.rb index 5149448..c686103 100644 --- a/lib/salesforce_ar_sync.rb +++ b/lib/salesforce_ar_sync.rb @@ -16,6 +16,15 @@ module SalesforceArSync def self.setup yield self end + + def someBadRuby_code + puts "This is a bad method"; + + + return + + return "Return value" + end end if defined?(ActiveRecord::Base) From 5d6f0df95091559c36d67e08e7ca2171dbeeb6e7 Mon Sep 17 00:00:00 2001 From: Tayler Phillips Date: Mon, 7 Oct 2024 16:17:03 -0400 Subject: [PATCH 5/8] Test with internal trunk action --- .github/workflows/linter.yml | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 .github/workflows/linter.yml diff --git a/.github/workflows/linter.yml b/.github/workflows/linter.yml new file mode 100644 index 0000000..7341780 --- /dev/null +++ b/.github/workflows/linter.yml @@ -0,0 +1,17 @@ +name: Linter +on: + pull_request: + branches: + - master + - main +jobs: + trunk-code-quality: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + # ... other setup steps + - name: Trunk Check + uses: trunk-io/trunk-action@v1 + with: + post-annotations: true + # ... other CI steps From 6e57a24291a27eb41de2f6c5a7e55a6ab2f6996e Mon Sep 17 00:00:00 2001 From: Tayler Phillips Date: Mon, 7 Oct 2024 16:22:02 -0400 Subject: [PATCH 6/8] Add permissions to write back to pull requests --- .github/workflows/linter.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.github/workflows/linter.yml b/.github/workflows/linter.yml index 7341780..a380096 100644 --- a/.github/workflows/linter.yml +++ b/.github/workflows/linter.yml @@ -4,6 +4,9 @@ on: branches: - master - main +permissions: + contents: read + pull-requests: write jobs: trunk-code-quality: runs-on: ubuntu-latest From a5494a3c712b0c17fae47b8ea7b3d6ad7499c984 Mon Sep 17 00:00:00 2001 From: Tayler Phillips Date: Mon, 7 Oct 2024 16:30:33 -0400 Subject: [PATCH 7/8] Fix permissions once again --- .github/workflows/linter.yml | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/.github/workflows/linter.yml b/.github/workflows/linter.yml index a380096..4219520 100644 --- a/.github/workflows/linter.yml +++ b/.github/workflows/linter.yml @@ -4,12 +4,16 @@ on: branches: - master - main -permissions: - contents: read - pull-requests: write +permissions: read-all +concurrency: + group: ${{ github.head_ref || github.run_id }} + cancel-in-progress: true jobs: trunk-code-quality: runs-on: ubuntu-latest + permissions: + checks: write # For trunk to post annotations + contents: read # For repo checkout steps: - uses: actions/checkout@v4 # ... other setup steps From f53cb8a94f3518f10d1bf1cfb579afd5c7aeee69 Mon Sep 17 00:00:00 2001 From: Tayler Phillips Date: Mon, 7 Oct 2024 16:35:35 -0400 Subject: [PATCH 8/8] Remove the manual install. --- .github/workflows/linter.yml | 24 ------------------------ 1 file changed, 24 deletions(-) delete mode 100644 .github/workflows/linter.yml diff --git a/.github/workflows/linter.yml b/.github/workflows/linter.yml deleted file mode 100644 index 4219520..0000000 --- a/.github/workflows/linter.yml +++ /dev/null @@ -1,24 +0,0 @@ -name: Linter -on: - pull_request: - branches: - - master - - main -permissions: read-all -concurrency: - group: ${{ github.head_ref || github.run_id }} - cancel-in-progress: true -jobs: - trunk-code-quality: - runs-on: ubuntu-latest - permissions: - checks: write # For trunk to post annotations - contents: read # For repo checkout - steps: - - uses: actions/checkout@v4 - # ... other setup steps - - name: Trunk Check - uses: trunk-io/trunk-action@v1 - with: - post-annotations: true - # ... other CI steps