wearerequired / lint-action

✨ GitHub Action for detecting and auto-fixing lint errors
MIT License
568 stars 136 forks source link

Add support for `pnpm` and custom commands #703

Closed HaakonSvane closed 1 year ago

HaakonSvane commented 1 year ago

Hi all, I don't see any mentions of support for pnpm in the guides. Also, monorepos usually configure their own linting commands through the build system (we use turbo run lint for example). It would be handy if support for this was provided by the action. Basically, I'd love to be able to run the linters with my own commands.

Tiketti commented 1 year ago

While I agree that it would be great to have examples in documentation for pnpm, too, I just modified the sample workflow a bit to for that use case. I hope you find it useful:

# ... the basic set up here

jobs:
  run-linters:
    name: Run linters
    runs-on: ubuntu-latest

    steps:
      - uses: actions/checkout@v3
      - uses: pnpm/action-setup@v2
        with:
          version: 8

      - name: Use Node.js 20
        uses: actions/setup-node@v3
        with:
          node-version: 20
          cache: 'pnpm'

      - name: Install dependencies
        run: pnpm install

      - name: Run linters
        uses: wearerequired/lint-action@v2
        with:
          eslint: true
          prettier: true
          eslint_extensions: ts,tsx
HaakonSvane commented 1 year ago

Thanks @Tiketti! Perhaps I should have been more clear on what I meant. Looking at the linting code for Prettier, it seems that all commands are run using npm. This is not too big of a deal for me personally, but I guess it wouldn't hurt to run the commands with the repo package manager instead.

What IS problematic for me is that the action runs these two linters (eslint and prettier) directly. For monorepos, it is common to use a build system to handle caching. This requires setting up proxy commands like:

{
  "scripts": {
    "lint": "turbo run lint", 
  }
}

which handles caching of script outputs to reduce redundant command usage. The current lint-action behaviour does not allow for any custom commands like these. I suggest including a custom command argument that lets you specify what command to run in the repo. For example:

# ...
- name: Run linters
   uses: wearerequired/lint-action@v2
   with:
     eslint: true
     prettier: true
     # example commands
     eslint_command: "yarn lint"
     prettier_command: "yarn format" 

Or alternatively just let the linter arguments also accept a command instead of just a boolean value (don't know if GH actions allow for this):

# ...
- name: Run linters
   uses: wearerequired/lint-action@v2
   with:
     eslint: "yarn lint"
     prettier: "yarn format"
github-actions[bot] commented 1 year ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.