Coder Social home page Coder Social logo

tsar-boomba / googlejavaformat-action Goto Github PK

View Code? Open in Web Editor NEW

This project forked from axel-op/googlejavaformat-action

0.0 0.0 0.0 5.47 MB

GitHub Action that formats Java files following Google Style guidelines

License: MIT License

JavaScript 100.00%

googlejavaformat-action's Introduction

Google Java Format Action

Automatically format your Java files using Google Java Style guidelines.

This action automatically downloads the latest release of the Google Java Format program.

This action can format your files and push the changes, or just check the formatting without committing anything.

You must checkout your repository with actions/checkout before calling this action (see the example).

Examples

Format all Java files in the repository and commit the changes:

# Example workflow
name: Format

on:
  push:
    branches:
      - master

jobs:

  formatting:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v2 # v2 minimum required
      - uses: axel-op/googlejavaformat-action@v3
        with:
          args: "--skip-sorting-imports --replace"
          # Recommended if you use MacOS:
          # githubToken: ${{ secrets.GITHUB_TOKEN }}

Check if the formatting is correct without pushing anything:

# Example workflow
name: Format

on: [push, pull_request]

jobs:

  formatting:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v2 # v2 minimum required
      - uses: axel-op/googlejavaformat-action@v3
        with:
          args: "--set-exit-if-changed"

Inputs

None of these inputs is required, but you can add them to change the behavior of this action.

githubToken

Recommended if you execute this action on MacOS. Due to this issue, calling the GitHub API from a MacOS machine can result in an error because of a rate limit. To overcome this, provide the GITHUB_TOKEN to authenticate these calls. If you provide it, it will also be used to authenticate the commits made by this action.

version

Set this input to use a specific version of Google Java Format. For example: 1.7, 1.8...

files

A pattern to match the files to format. The default is **/*.java, which means that all Java files in your repository will be formatted.

files-excluded

A pattern to match the files to be ignored. Optional.

skipCommit

Set to true if you don't want the changes to be committed by this action. Default: false.

commitMessage

You can specify a custom commit message. Default: Google Java Format.

args

The arguments to pass to the Google Java Format executable. By default, only --replace is used.

-i, -r, -replace, --replace
  Send formatted output back to files, not stdout.

--assume-filename, -assume-filename
  File name to use for diagnostics when formatting standard input (default is <stdin>).

--aosp, -aosp, -a
  Use AOSP style instead of Google Style (4-space indentation).

--fix-imports-only
  Fix import order and remove any unused imports, but do no other formatting.

--skip-sorting-imports
  Do not fix the import order. Unused imports will still be removed.

--skip-removing-unused-imports
  Do not remove unused imports. Imports will still be sorted.

--skip-reflowing-long-strings
  (JDK 11+) Do not reflow string literals that exceed the column limit.

--skip-javadoc-formatting
  (JDK 11+) Do not reformat javadoc.

--dry-run, -n
  Prints the paths of the files whose contents would change if the formatter were run normally.

--set-exit-if-changed
  Return exit code 1 if there are any formatting changes.

--length, -length
  Character length to format.

--lines, -lines, --line, -line
  Line range(s) to format, like 5:10 (1-based; default is all).

--offset, -offset
  Character offset to format (0-based; default is all).

Note:

  • If you add --dry-run or -n, no commit will be made.
  • The argument --set-exit-if-changed will work as expected and this action will fail if some files need to be formatted.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.