From 681e8ec44424985dd091d54ae8915a4d2833da9c Mon Sep 17 00:00:00 2001 From: Sebastian Serth Date: Sat, 13 Apr 2024 23:42:31 +0200 Subject: [PATCH] Add GitHub CI workflow for slim lint --- .github/workflows/ci.yml | 30 ++++++++++++++++++++++++++++++ .slim-lint.yml | 32 ++++++++++++++++++++++++++++++++ Gemfile | 1 + Gemfile.lock | 4 ++++ 4 files changed, 67 insertions(+) create mode 100644 .slim-lint.yml diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 26dd4032..3d327ef8 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -108,3 +108,33 @@ jobs: skip_install: true use_bundler: true fail_on_error: true + + slim-lint: + permissions: + # Required: allow read access to the content for analysis. + contents: read + # Allow write access to checks to allow the action to annotate code in the PR. + checks: write + + runs-on: ubuntu-latest + + steps: + - name: Checkout code + uses: actions/checkout@v4 + + - name: Setup Ruby + uses: ruby/setup-ruby@v1 + with: + ruby-version: 3.3 + bundler-cache: true + + - name: Run slim-lint + run: bundle exec slim-lint app/views --reporter checkstyle > checkstyle-result.xml + + - name: Upload slim-lint results as GitHub annotations + uses: lcollins/checkstyle-github-action@v2.0.0 + if: ${{ success() || failure() }} + with: + name: Slim-Lint Report + title: Analyze Slim templates for linting issues + path: checkstyle-result.xml diff --git a/.slim-lint.yml b/.slim-lint.yml new file mode 100644 index 00000000..ae0bdb0f --- /dev/null +++ b/.slim-lint.yml @@ -0,0 +1,32 @@ +linters: + # Disabled a few linters that are not relevant to our use case + EmptyLines: + enabled: false + + ConsecutiveControlStatements: + enabled: false + + LineLength: + enabled: false + + # Enable additional linters + EmbeddedEngines: + enabled: true + forbidden_engines: + # JavaScript is not allowed due to our Content Security Policy (CSP) + - javascript + + InstanceVariables: + enabled: false # TODO: Enable + include: + # Include only Rails partial templates by default + - app/views/**/_*.html.slim + + StrictLocalsMissing: + enabled: false # TODO: Enable + include: + # Include only Rails partial templates by default + - app/views/**/_*.html.slim + + Zwsp: + enabled: true diff --git a/Gemfile b/Gemfile index 4c6d8c5c..b4c55c92 100644 --- a/Gemfile +++ b/Gemfile @@ -80,6 +80,7 @@ group :development, :staging do gem 'rubocop-performance' gem 'rubocop-rails', require: false gem 'rubocop-rspec' + gem 'slim_lint', require: false end group :test do diff --git a/Gemfile.lock b/Gemfile.lock index 738d6e81..42610073 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -499,6 +499,9 @@ GEM actionpack (>= 3.1) railties (>= 3.1) slim (>= 3.0, < 6.0, != 5.0.0) + slim_lint (0.27.0) + rubocop (>= 1.0, < 2.0) + slim (>= 3.0, < 6.0) snaky_hash (2.0.1) hashie version_gem (~> 1.1, >= 1.1.1) @@ -641,6 +644,7 @@ DEPENDENCIES shoulda-matchers simplecov slim-rails + slim_lint sorcery sprockets-rails stackprof