From 7815e54c0e67f378b8dcb4216d8a860db0b3bbe3 Mon Sep 17 00:00:00 2001 From: Elia Schito Date: Fri, 29 Dec 2023 14:30:40 +0100 Subject: [PATCH] Move linting commands to rake tasks Only check files tracked by git and not generated and temporary files. (cherry picked from commit 413c4c95abb6e0de52932cf8754239b0ea9cc117) # Conflicts: # .circleci/config.yml --- .circleci/config.yml | 20 ++++++++++++++++++++ .eslintrc.json | 10 ---------- .gitignore | 1 + .rubocop.yml | 7 +------ Gemfile | 2 +- Rakefile | 1 + tasks/linting.rake | 19 +++++++++++++++++++ 7 files changed, 43 insertions(+), 17 deletions(-) create mode 100644 tasks/linting.rake diff --git a/.circleci/config.yml b/.circleci/config.yml index 51074664793..4ca993900a3 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -235,6 +235,26 @@ commands: bundle exec rake -rrails -rspree/testing_support/extension_rake -e'Rake::Task["extension:test_app"].invoke' jobs: + lint_code: + docker: + - image: cimg/ruby:3.2-node + environment: + BUNDLE_ONLY: "lint" + steps: + - checkout + - run: 'bundle install' + - run: + name: Check Ruby + command: "bin/rake lint:rb" + - run: + name: Check ERB + command: "bin/rake lint:erb" + - run: + name: Check JavaScript + command: "bin/rake lint:js" + - store_test_results: + path: test-results + solidus_installer: executor: name: sqlite diff --git a/.eslintrc.json b/.eslintrc.json index d49769ebf66..18178945e5b 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -1,15 +1,5 @@ { "extends": "eslint:recommended", - "ignorePatterns": [ - "*tailwind.config.js", - "**/spec", - "**/vendor", - "**/node_modules", - "sandbox", - "coverage", - "core/doc", - "tmp" - ], "parserOptions": { "ecmaVersion": 2019 }, diff --git a/.gitignore b/.gitignore index 9af8c03be0d..3e4993f90ee 100644 --- a/.gitignore +++ b/.gitignore @@ -32,3 +32,4 @@ yarn.lock package-lock.json .env /admin/app/assets/builds +/test-results diff --git a/.rubocop.yml b/.rubocop.yml index 1d351c842af..4dda7c638e7 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -8,12 +8,7 @@ require: AllCops: Exclude: - - 'vendor/**/*' - - '**/vendor/**/*' - - '*/spec/dummy/**/*' - - 'sandbox/**/*' - - '**/templates/**/*' - - 'tmp/**/*' + - '**/{tmp,vendor,spec/dummy,sandbox,templates,pkg}/**/*' TargetRubyVersion: 3.0 NewCops: disable SuggestExtensions: false diff --git a/Gemfile b/Gemfile index a3875fcc878..96e5e9d6577 100644 --- a/Gemfile +++ b/Gemfile @@ -58,7 +58,7 @@ group :admin do end group :lint do - gem 'erb-formatter', require: false + gem 'erb-formatter', '~> 0.7', require: false gem 'rubocop', '~> 1', require: false gem 'rubocop-performance', '~> 1.4', require: false gem 'rubocop-rails', '~> 2.9', require: false diff --git a/Rakefile b/Rakefile index 64473d43214..a7dca64a10b 100644 --- a/Rakefile +++ b/Rakefile @@ -3,3 +3,4 @@ import 'tasks/cleaning.rake' import 'tasks/releasing.rake' import 'tasks/testing.rake' +import 'tasks/linting.rake' diff --git a/tasks/linting.rake b/tasks/linting.rake new file mode 100644 index 00000000000..2d8b1c6993f --- /dev/null +++ b/tasks/linting.rake @@ -0,0 +1,19 @@ +# frozen_string_literal: true + +namespace :lint do + task :rb do + ci_options = "-f junit -o '#{__dir__}/../test-results/rubocop-results.xml' " if ENV['CI'] + + sh %{bundle exec rubocop -P -f q #{ci_options}$(git ls-files -co --exclude-standard | grep -E "\\.rb$" | grep -v "/templates/")} + end + + task :erb do + sh 'bundle exec erb-format $(git ls-files -co --exclude-standard | grep -E "\.html.erb$") > /dev/null' + end + + task :js do + sh 'npx -y eslint $(git ls-files -co --exclude-standard | grep -E "\.js$" | grep -vE "/(vendor|config|spec)/")' + end +end + +task lint: %w[lint:rb lint:erb lint:js]