Move linting commands to rake tasks

Only check files tracked by git and not generated and temporary files.
This commit is contained in:
Elia Schito 2023-12-29 14:30:40 +01:00
parent e1361eedc9
commit 413c4c95ab
No known key found for this signature in database
GPG Key ID: 9A79FC0070180BEE
7 changed files with 26 additions and 27 deletions

View File

@ -246,20 +246,13 @@ jobs:
- run: 'bundle install'
- run:
name: Check Ruby
command: |
bundle exec rubocop --parallel --format junit --out "$PWD/test-results/rubocop-results.xml" --format progress
command: "bin/rake lint:rb"
- run:
name: Check ERB
command: |
# enable recursive globbing with "**"
shopt -s globstar
# we're only interested in errors
bundle exec erb-format **/*.html.erb > /dev/null
command: "bin/rake lint:erb"
- run:
name: Check JavaScript
command: |
npx -y eslint "**/*.js"
command: "bin/rake lint:js"
- store_test_results:
path: test-results

View File

@ -1,15 +1,5 @@
{
"extends": "eslint:recommended",
"ignorePatterns": [
"*tailwind.config.js",
"**/spec",
"**/vendor",
"**/node_modules",
"sandbox",
"coverage",
"core/doc",
"tmp"
],
"parserOptions": {
"ecmaVersion": 2019
},

1
.gitignore vendored
View File

@ -32,3 +32,4 @@ yarn.lock
package-lock.json
.env
/admin/app/assets/builds
/test-results

View File

@ -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

View File

@ -61,7 +61,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

View File

@ -3,3 +3,4 @@
import 'tasks/cleaning.rake'
import 'tasks/releasing.rake'
import 'tasks/testing.rake'
import 'tasks/linting.rake'

19
tasks/linting.rake Normal file
View File

@ -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]