# GitHub Code Scanning

> Get HTMLHint to run on every pull request with GitHub Code Scanning.

Thanks to the newly added SARIF formatter, HTMLHint can now be integrated with [GitHub Code Scanning](https://docs.github.com/en/code-security/code-scanning/integrating-with-code-scanning/uploading-a-sarif-file-to-github) to automatically check your HTML code.

![Screenshot of the HTMLHint GitHub Code Scanning Integration](/img/htmlhint-github-code-scanning.png)

This integration can help maintain code quality and ensures that HTML standards are met across your projects. Fixing issues will automatically remove the warnings from the Code Scanning tab in GitHub.

## Setting Up GitHub Code Scanning

[Section titled “Setting Up GitHub Code Scanning”](#setting-up-github-code-scanning)

To set up HTMLHint with GitHub Code Scanning, you need to create a workflow file in your repository. This file will define the steps to run HTMLHint on your HTML files whenever a pull request is made.

1. **Create a Workflow File**: In your repository, create a directory named `.github/workflows` if it doesn’t already exist. Inside this directory, create a file named `htmlhint.yml`.
2. **Define the Workflow**: Add the following content to `htmlhint.yml`:

```yaml
name: HTMLHint (SARIF) Code Scanning


on:
  pull_request:
    branches:
      - main
  workflow_dispatch:


jobs:
  build:
    runs-on: ubuntu-latest
    steps:
      - name: Checkout code
        uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8 # v6.0.1
        with:
          persist-credentials: false


      - name: Set up Node.js
        uses: actions/setup-node@6044e13b5dc448c55e2357c09f80417699197238 # v6.2.0


      # If you need a website build script, include the steps here


      - name: Run HTMLHint (SARIF)
        run: npx htmlhint . --format sarif || true
        # Continue even if HTMLHint finds issues


      - name: Upload SARIF file
        uses: github/codeql-action/upload-sarif@b20883b0cd1f46c72ae0ba6d1090936928f9fa30 # v4.32.0
        with:
          sarif_file: website/htmlhint.sarif
          category: HTMLHint
        if: always()
```

For a real-world example, you can see the Upload SARIF steps in the workflow for the HTMLHint website in the [HTMLHint GitHub repository](https://github.com/htmlhint/HTMLHint/blob/main/.github/workflows/website.yml#L39). Make sure to adjust the `sarif_file` path to match where HTMLHint outputs the SARIF file in your project.

Note

For private and internal repositories, code scanning is available when GitHub Code Security features are enabled for the repository. If you see the error GitHub Code Security or GitHub Advanced Security must be enabled for this repository to use code scanning, check that GitHub Code Security is enabled. For more information, see [Managing security and analysis settings for your repository](https://docs.github.com/en/repositories/managing-your-repositorys-settings-and-features/enabling-features-for-your-repository/managing-security-and-analysis-settings-for-your-repository).