From e1bc1626d9639e0675ce7ecbe0dc589fb47c72e8 Mon Sep 17 00:00:00 2001 From: Ken-ichi Date: Mon, 18 Nov 2024 21:27:20 -0800 Subject: [PATCH] chore: lint Ruby files with Rubocop (#2435) * fix: set up Ruby before linting in Github Actions * chore: separate linting from fixing Before we commit we want to fix as much as possible, but when we're checking a pull request we're not going to commit anything so we want to know about all the problems, including the fixable ones. --- .github/workflows/crowdin-pull.yml | 6 ++++++ .github/workflows/test.yml | 17 +++++++++++++---- .husky/pre-commit | 2 +- Gemfile | 3 ++- Gemfile.lock | 22 ++++++++++++++++++++++ ios/Podfile | 4 ++-- package.json | 8 ++++++-- scripts/clean_icon_svgs.rb | 4 +--- 8 files changed, 53 insertions(+), 13 deletions(-) diff --git a/.github/workflows/crowdin-pull.yml b/.github/workflows/crowdin-pull.yml index 6b64e459b..866a124de 100644 --- a/.github/workflows/crowdin-pull.yml +++ b/.github/workflows/crowdin-pull.yml @@ -45,6 +45,12 @@ jobs: if: steps.cache.outputs.cache-hit != 'true' run: npm install + # Need this for pre-commit linting of Ruby + - name: Install Ruby and gems + uses: ruby/setup-ruby@v1 + with: + bundler-cache: true + - name: Sync with Crowdin uses: crowdin/github-action@v2 with: diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 5548d3668..63bcc2e0d 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -12,7 +12,7 @@ concurrency: jobs: test: - name: Run Tests + name: Run tests runs-on: ubuntu-latest steps: - name: Check out Git repository @@ -30,12 +30,21 @@ jobs: path: node_modules key: node-modules-${{ hashFiles('**/package-lock.json') }} - - name: Install Dependencies + - name: Install dependencies if: steps.cache.outputs.cache-hit != 'true' run: npm install - - run: npm run lint - - run: npm test + # Need this for linting Ruby + - name: Install Ruby and gems + uses: ruby/setup-ruby@v1 + with: + bundler-cache: true + + - name: Lint + run: npm run lint + + - name: Test + run: npm test notify: name: Notify Slack diff --git a/.husky/pre-commit b/.husky/pre-commit index b2ccacf89..a81773f91 100755 --- a/.husky/pre-commit +++ b/.husky/pre-commit @@ -14,7 +14,7 @@ else fi # Run lint and flow -npm run lint +npm run lint:fix # Generate translations from strings.ftl npm run translate diff --git a/Gemfile b/Gemfile index 97e9d3fd0..0963303a6 100644 --- a/Gemfile +++ b/Gemfile @@ -6,10 +6,11 @@ ruby ">= 2.6.10" # Cocoapods 1.15 introduced a bug which break the build. We will remove the upper # bound in the template on Cocoapods with next React Native release. -gem "cocoapods", ">= 1.13", "< 1.15" gem "activesupport", ">= 6.1.7.5", "< 7.1.0" +gem "cocoapods", ">= 1.13", "< 1.15" gem "fastlane" # Temporary workaround for https://github.com/fastlane/fastlane/issues/26682 gem "fastlane-sirp", git: "https://github.com/appbot/fastlane-sirp.git", ref: "sysrandom_fix" gem "nokogiri" +gem "rubocop" diff --git a/Gemfile.lock b/Gemfile.lock index db5fd2a80..7c8b3a2d8 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -23,6 +23,7 @@ GEM httpclient (~> 2.8, >= 2.8.3) json (>= 1.5.1) artifactory (3.0.17) + ast (2.4.2) atomos (0.1.3) aws-eventstream (1.3.0) aws-partitions (1.996.0) @@ -216,6 +217,7 @@ GEM json (2.7.5) jwt (2.9.3) base64 + language_server-protocol (3.17.0.3) mini_magick (4.13.2) mini_mime (1.1.5) mini_portile2 (2.8.5) @@ -233,10 +235,16 @@ GEM racc (~> 1.4) optparse (0.5.0) os (1.1.4) + parallel (1.26.3) + parser (3.3.6.0) + ast (~> 2.4.1) + racc plist (3.7.1) public_suffix (4.0.7) racc (1.7.3) + rainbow (3.1.1) rake (13.2.1) + regexp_parser (2.9.2) representable (3.2.0) declarative (< 0.1.0) trailblazer-option (>= 0.1.1, < 0.2.0) @@ -244,7 +252,20 @@ GEM retriable (3.1.2) rexml (3.3.9) rouge (2.0.7) + rubocop (1.68.0) + json (~> 2.3) + language_server-protocol (>= 3.17.0) + parallel (~> 1.10) + parser (>= 3.3.0.2) + rainbow (>= 2.2.2, < 4.0) + regexp_parser (>= 2.4, < 3.0) + rubocop-ast (>= 1.32.2, < 2.0) + ruby-progressbar (~> 1.7) + unicode-display_width (>= 2.4.0, < 3.0) + rubocop-ast (1.36.1) + parser (>= 3.3.1.0) ruby-macho (2.5.1) + ruby-progressbar (1.13.0) ruby2_keywords (0.0.5) rubyzip (2.3.2) security (0.1.5) @@ -292,6 +313,7 @@ DEPENDENCIES fastlane fastlane-sirp! nokogiri + rubocop RUBY VERSION ruby 2.7.5p203 diff --git a/ios/Podfile b/ios/Podfile index 4c8424f7a..cdc556da4 100644 --- a/ios/Podfile +++ b/ios/Podfile @@ -54,7 +54,7 @@ setup_permissions( # ``` # flipper_config = ENV["NO_FLIPPER"] == "1" ? FlipperConfiguration.disabled : FlipperConfiguration.enabled -linkage = ENV["USE_FRAMEWORKS"] +linkage = ENV.fetch( "USE_FRAMEWORKS", nil ) unless linkage.nil? Pod::UI.puts "Configuring Pod with #{linkage}ally linked Frameworks".green use_frameworks! linkage: linkage.to_sym @@ -127,7 +127,7 @@ target "iNaturalistReactNative" do end end - installer.target_installation_results.pod_target_installation_results.each do | _pod_name, inst_result | + installer.target_installation_results.pod_target_installation_results.each_value do | inst_result | inst_result.native_target.build_configurations.each do | build_config | # For third party modules who have React-bridging dependency to search correct headers build_config.build_settings["HEADER_SEARCH_PATHS"] ||= "$(inherited) " diff --git a/package.json b/package.json index de7c24420..b350c2687 100644 --- a/package.json +++ b/package.json @@ -13,9 +13,13 @@ "test": "jest tests/integration && jest tests/unit tests/helpers", "test:clear": "jest --clearCache", "test:memory": "jest --runInBand --logHeapUsage", - "lint": "npm run lint:eslint && npm run lint:flow", - "lint:eslint": "eslint . --fix", + "lint": "npm run lint:eslint && npm run lint:flow && npm run lint:rubocop", + "lint:fix": "npm run lint:eslint:fix && npm run lint:flow && npm run lint:rubocop:fix", + "lint:eslint": "eslint .", + "lint:eslint:fix": "eslint . --fix", "lint:flow": "flow check", + "lint:rubocop": "bundle exec rubocop", + "lint:rubocop:fix": "bundle exec rubocop -A", "lint:tsc": "tsc --allowJs false --noEmit", "postinstall": "husky && patch-package", "translate": "node src/i18n/i18ncli.js build", diff --git a/scripts/clean_icon_svgs.rb b/scripts/clean_icon_svgs.rb index 7aabd0bf5..91dc30f25 100755 --- a/scripts/clean_icon_svgs.rb +++ b/scripts/clean_icon_svgs.rb @@ -38,9 +38,7 @@ num_cleaned = 0 # doc.at("svg").remove_attribute "xmlns:inkscape" # doc.at("svg").remove_attribute "xmlns:sodipodi" doc.remove_namespaces! - File.open( path, "w" ) do | file | - file.write( doc.to_xml( indent: 2 ) ) - end + File.write( path, doc.to_xml( indent: 2 ) ) num_cleaned += 1 end puts "Cleaned #{num_cleaned} SVGs"