Browse Source

Maintenance: Improve stylelint handling in overcommit.

Co-authored-by: Dusan Vuckovic <dv@zammad.com>
Martin Gruner 8 months ago
parent
commit
e275d4ee4c
6 changed files with 37 additions and 16 deletions
  1. 1 1
      .gitlab/ci/lint.yml
  2. 6 2
      .overcommit.yml
  3. 3 1
      Gemfile
  4. 11 5
      Gemfile.lock
  5. 9 3
      doc/developer_manual/standards/code-style-guide.md
  6. 7 4
      package.json

+ 1 - 1
.gitlab/ci/lint.yml

@@ -110,7 +110,7 @@
     - echo "TypeScript compiler check…"
     - echo "TypeScript compiler check…"
     - pnpm lint:ts
     - pnpm lint:ts
     - echo "ESLint check…"
     - echo "ESLint check…"
-    - pnpm lint:js app/frontend/ .eslint-plugin-zammad/
+    - pnpm lint:js
     - pnpm analyse:vite-bundle -t list -o ./tmp/vite-bundle-stats.yml
     - pnpm analyse:vite-bundle -t list -o ./tmp/vite-bundle-stats.yml
     - .gitlab/verify_vite_bundle_size.rb
     - .gitlab/verify_vite_bundle_size.rb
     # Artifacts are stored for failed jobs
     # Artifacts are stored for failed jobs

+ 6 - 2
.overcommit.yml

@@ -30,7 +30,11 @@ PreCommit:
   Stylelint:
   Stylelint:
     enabled: true
     enabled: true
     required_executable: 'pnpm'
     required_executable: 'pnpm'
-    command: ['pnpm', '--silent', 'lint:css']
+    command: ['pnpm', '--silent', 'lint:css:cmd']
+    include:
+      - '**/*.scss'
+      - '**/*.css'
+      - '**/*.vue'
   TranslationCatalogCheck:
   TranslationCatalogCheck:
     required_executable: 'rails'
     required_executable: 'rails'
     enabled: true
     enabled: true
@@ -69,7 +73,7 @@ PreCommit:
   EsLint:
   EsLint:
     required_executable: 'pnpm'
     required_executable: 'pnpm'
     enabled: true
     enabled: true
-    command: ['pnpm', 'lint:js']
+    command: ['pnpm', 'lint:js:cmd']
     exclude:
     exclude:
       - 'app/assets/**/*'
       - 'app/assets/**/*'
       - 'public/assets/chat/**/*'
       - 'public/assets/chat/**/*'

+ 3 - 1
Gemfile

@@ -224,7 +224,9 @@ group :development, :test do
 
 
   # code QA
   # code QA
   gem 'brakeman', require: false
   gem 'brakeman', require: false
-  gem 'overcommit'
+  # TODO: switch back to released gem once 0.64.0 has been relased with
+  #   https://github.com/sds/overcommit/issues/823
+  gem 'overcommit', git: 'https://github.com/sds/overcommit', branch: 'main'
   gem 'rubocop'
   gem 'rubocop'
   gem 'rubocop-capybara'
   gem 'rubocop-capybara'
   gem 'rubocop-factory_bot'
   gem 'rubocop-factory_bot'

+ 11 - 5
Gemfile.lock

@@ -1,3 +1,13 @@
+GIT
+  remote: https://github.com/sds/overcommit
+  revision: 26e78aa9e5e907ed41ebdac8098483af4d54865c
+  branch: main
+  specs:
+    overcommit (0.63.0)
+      childprocess (>= 0.6.3, < 6)
+      iniparse (~> 1.4)
+      rexml (~> 3.2)
+
 GIT
 GIT
   remote: https://github.com/tschaefer/ruby-keycloak-admin/
   remote: https://github.com/tschaefer/ruby-keycloak-admin/
   revision: 79b38d75859e08617879ffc75d5313e41c6974b1
   revision: 79b38d75859e08617879ffc75d5313e41c6974b1
@@ -426,10 +436,6 @@ GEM
     openssl (3.2.0)
     openssl (3.2.0)
     openssl-signature_algorithm (1.3.0)
     openssl-signature_algorithm (1.3.0)
       openssl (> 2.0)
       openssl (> 2.0)
-    overcommit (0.63.0)
-      childprocess (>= 0.6.3, < 6)
-      iniparse (~> 1.4)
-      rexml (~> 3.2)
     parallel (1.25.1)
     parallel (1.25.1)
     parser (3.3.3.0)
     parser (3.3.3.0)
       ast (~> 2.4.1)
       ast (~> 2.4.1)
@@ -800,7 +806,7 @@ DEPENDENCIES
   omniauth-twitter
   omniauth-twitter
   omniauth-weibo-oauth2!
   omniauth-weibo-oauth2!
   openssl
   openssl
-  overcommit
+  overcommit!
   parallel
   parallel
   pg (~> 1.5, >= 1.5.4)
   pg (~> 1.5, >= 1.5.4)
   pry-byebug
   pry-byebug

+ 9 - 3
doc/developer_manual/standards/code-style-guide.md

@@ -23,16 +23,22 @@ $ bundle exec rubocop --parallel
 # Type checks, ESLint & Stylelint
 # Type checks, ESLint & Stylelint
 $ pnpm lint
 $ pnpm lint
 
 
+# Type checks, ESLint & Stylelint with automatic fixing
+$ pnpm lint:fix
+
 # Just type checking
 # Just type checking
 $ pnpm lint:ts
 $ pnpm lint:ts
 
 
-# ESLint checks with automatic fixing
+# Just ESLint checks
+$ pnpm lint:js
+
+# Just ESLint checks with automatic fixing
 $ pnpm lint:js:fix
 $ pnpm lint:js:fix
 
 
-# Stylelint
+# Just Stylelint checks
 $ pnpm lint:css
 $ pnpm lint:css
 
 
-# Stylelint with automatic fixing
+# Just Stylelint checks with automatic fixing
 $ pnpm lint:css:fix
 $ pnpm lint:css:fix
 
 
 # Coffeelint
 # Coffeelint

+ 7 - 4
package.json

@@ -6,11 +6,14 @@
     "dev": "RAILS_ENV=development forego start -f Procfile.dev",
     "dev": "RAILS_ENV=development forego start -f Procfile.dev",
     "dev:https": "VITE_RUBY_HOST=0.0.0.0 VITE_RUBY_HTTPS=true RAILS_ENV=development forego start -f Procfile.dev-https",
     "dev:https": "VITE_RUBY_HOST=0.0.0.0 VITE_RUBY_HTTPS=true RAILS_ENV=development forego start -f Procfile.dev-https",
     "i18n": "rails generate zammad:translation_catalog",
     "i18n": "rails generate zammad:translation_catalog",
-    "lint": "pnpm lint:ts && pnpm lint:js app/frontend/ .eslint-plugin-zammad/ && pnpm lint:css",
+    "lint": "pnpm lint:ts && pnpm lint:js && pnpm lint:css",
+    "lint:fix": "pnpm lint:ts && pnpm lint:js:fix && pnpm lint:css:fix",
     "lint:ts": "vue-tsc --noEmit",
     "lint:ts": "vue-tsc --noEmit",
-    "lint:js": "eslint --cache --cache-location ./tmp/eslintcache.js --cache-strategy content -c .eslintrc.js --ext .js,.ts,.vue",
-    "lint:js:fix": "pnpm lint:js app/frontend/ .eslint-plugin-zammad/ --fix",
-    "lint:css": "stylelint **/*.{css,vue,scss}",
+    "lint:js": "pnpm lint:js:cmd app/frontend/ .eslint-plugin-zammad/",
+    "lint:js:cmd": "eslint --cache --cache-location ./tmp/eslintcache.js --cache-strategy content -c .eslintrc.js --ext .js,.ts,.vue",
+    "lint:js:fix": "pnpm lint:js --fix",
+    "lint:css": "pnpm lint:css:cmd **/*.{css,vue,scss}",
+    "lint:css:cmd": "stylelint",
     "lint:css:fix": "pnpm lint:css --fix",
     "lint:css:fix": "pnpm lint:css --fix",
     "test": "VTL_SKIP_AUTO_CLEANUP=true TZ=utc vitest",
     "test": "VTL_SKIP_AUTO_CLEANUP=true TZ=utc vitest",
     "test:ct": "cd .dev/cypress; CY_OPEN=true pnpm cypress open --component --project ../../ --config-file .dev/cypress/cypress.config.mjs",
     "test:ct": "cd .dev/cypress; CY_OPEN=true pnpm cypress open --component --project ../../ --config-file .dev/cypress/cypress.config.mjs",