Skip to content

mezgoodle/auto-formatter

Use this GitHub action with your project
Add this Action to an existing workflow or create a new one
View on Marketplace

Repository files navigation

auto-formatter

Language

This repository is for the GitHub Action to run a auto-formatter. It is a simple combination of various libraries, written in bash, to help formate your code automatically.

Version

Current version keep only python format. In next version more languages will be available.

Project is no longer being developed for various reasons.

How it Works

The auto-formatter launches linters that can formate code, do this and commit to your repository.

Supported Linters

Developers on GitHub can call the GitHub Action to formate their code base with the following list of libraries:

Language Library
NodeJs eslint
Python autopep8
CSS stylelint
MarkDown markdownlint
HTML clean-html

How to use

To use this GitHub Action you will need to complete the following:

  1. Create a new file in your repository called .github/workflows/formatter.yml
  2. Copy the example workflow from below into that new file, no extra configuration required
  3. Commit that file to a new branch
  4. Open up a pull request and observe the action working
  5. Enjoy your more stable, and cleaner code base

Example connecting GitHub Action Workflow

In your repository you should have a .github/workflows folder with GitHub Action similar to below:

  • .github/workflows/formatter.yml

This file should have the following code:

---
####################
####################
## Auto Formatter ##
####################
####################
name: Formate Code

#
# Documentation:
# https://github.com/mezgoodle/auto-formatter
#

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

###############
# Set the Job #
###############
jobs:
  build:
    # Name the Job
    name: Formate Code
    # 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 `auto-formatter`
          fetch-depth: 0

      ################################
      # Run Auto-formatter against code base #
      ################################
      - name: Auto-Formatter
        uses: mezgoodle/[email protected]
        env:
            GITHUB_TOKEN: ${{ secrets.TOKEN }}

Add Super-Linter badge in your repository README

You can show Super-Linter status with a badge in your repository README

Auto formate code

Format:

![Auto formate code](https://github.com/<OWNER>/<REPOSITORY>/workflows/Auto%20formate%20code/badge.svg)

Example:

![Auto formate code](https://github.com/mezgoodle/auto-formatter/workflows/Auto%20formate%20code/badge.svg)

Environment variables

The super-linter allows you to pass the following ENV variables to be able to trigger different functionality.

Note: All the VALIDATE_[LANGUAGE] variables behave in a very specific way:

  • If none of them are passed, then they all default to false.
  • If any one of the variables are set to true, we default to leaving any unset variable to false.
  • If any one of the variables are set to false, we default to leaving any unset variable to false.
ENV VAR Default Value Notes
python false Flag to enable or disable the formatting process of the Python language.

Motivation

At first I was inspired by this project. I wanted to do the same, but with formatting. It is also a great opportunity to learn how to work with Docker and how to create your own GitHub workflow. Also it was the amazing time working together with my dad.

Build status

Here you can see build status of continuous integration:

Docker Image CI Docker Image CI Lint Code Base

Contribute

Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change. Also look at the CONTRIBUTING.md.

Credits

Links to any repo, articles which inspired me to build this project:

License

MIT © mezgoodle