Search code examples
c#.netcontinuous-integrationgithub-actionseditorconfig

Validate .editorconfig file using Github Action


I want to make sure that any pull request in my Github repo follows the rules defined in .editorconfig (ASp.NET Core 5 C# project). I have found https://github.com/github/super-linter to lint the code using,

I have added the below linter.yml file in my workflow,

---
###########################
###########################
## Linter GitHub Actions ##
###########################
###########################
name: Lint Code Base

#
# Documentation:
# https://help.github.com/en/articles/workflow-syntax-for-github-actions
#

#############################
# Start the job on all push #
#############################
on:
    push:
    branches-ignore: [main]
    # Remove the line above to run when pushing to main
    pull_request:
    branches: [main]

###############
# Set the Job #
###############
jobs:
    build:
    # Name the Job
    name: Lint Code Base
    # Set the agent to run on
    runs-on: ubuntu-latest

    ##################
    # Load all steps #
    ##################
    steps:
        ##########################
        # Checkout the code base #
        ##########################
        - name: Checkout Code
        uses: actions/checkout@v2
        with:
            # Full git history is needed to get a proper list of changed files within `super-linter`
            fetch-depth: 0

        ################################
        # Run Linter against codebase #
        ################################
        - name: Lint Code Base
        uses: github/super-linter@v4
        env:
            VALIDATE_ALL_CODEBASE: false
            DEFAULT_BRANCH: main
            GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

It is successful but I don't see it is validating the .editorconfig rules in the root of the Github repository? Am I missing something?


Solution

  • Checking the Environment Variables from the Super Linter Github Action, the default value for the EDITORCONFIG_FILE_NAME file is .ecrc.

    Therefore, if your file's name is .editorconfig you'll have to add it to the action arguments list with something like:

    - name: Lint Code Base
      uses: github/super-linter@v4
      env:
        VALIDATE_ALL_CODEBASE: false
        DEFAULT_BRANCH: main
        GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
        EDITORCONFIG_FILE_NAME: .editorconfig
    

    Recognizing this file, the Super Linter action will use the editorconfig-checker repository to check it.

    EDIT: Based on comments, dotnet-format used by super linter also automatically uses the .editorconf file. If you want to check it usung this linter, no need to set EDITORCONFIG_FILE_NAME. Only, set VALIDATE_CSHARP: true