npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

eslint-suggestion-action

v4.1.7

Published

[![Build](https://github.com/CatChen/eslint-suggestion-action/actions/workflows/build.yml/badge.svg?branch=main&event=push)](https://github.com/CatChen/eslint-suggestion-action/actions/workflows/build.yml) [![Test](https://github.com/CatChen/eslint-sugges

Downloads

38

Readme

eslint-suggestion-action

Build Test ESLint CodeQL

This GitHub Action runs ESLint and provides inline feedback to the changes in a Pull Request. Features:

  1. If ESLint can auto-fix a problem the fix would be created as an inline suggestion. You can decide whether you want to accept the fix as suggested.
  2. It only provides feedback for the lines that are changed in the Pull Request. It doesn't create noise for pre-existing code that doesn't pass ESLint.

Examples

When there is only one fix available this action will suggest that fix:

fix-example-screenshot

When there are multiple suggestions available this action will show them all and let you decide which one matches your intent:

suggestion-example-screenshot

Usage

Set up a GitHub Action like this:

name: ESLint

on:
  push:
    branches: [main] # or [master] if that's name of the main branch
  pull_request:
    branches: [main] # or [master] if that's name of the main branch

jobs:
  build:
    runs-on: ubuntu-latest

    steps:
      - uses: actions/checkout@v3
      - uses: actions/setup-node@v4
        with:
          node-version: '20'
          check-latest: true

      - name: Install dependencies
        run: yarn install # or npm ci if you use npm and have the package-lock.json file

      - uses: CatChen/eslint-suggestion-action@v4
        with:
          request-changes: true # optional
          fail-check: false # optional
          github-token: ${{ secrets.GITHUB_TOKEN }} # optional
          directory: './' # optional
          targets: '.' # optional
          eslint-lib-path: './node_modules/eslint/lib/api.js' # optional
          config-path: '' # optional

Save the file to .github/workflows/eslint.yml. It will start working on new Pull Requests.

Options

request-changes

This option determines whether this GitHub Action should request change if there's any ESLint issue. This option has no effect when the Workflow isn't triggered by a pull_request event. The default value is true.

fail-check

This option determines whether the GitHub Workflow should fail if there's any ESLint issue. The default value is false.

github-token

The default value is ${{ github.token }}, which is the GitHub token generated for this workflow. You can create a different token with a different set of permissions and use it here as well.

directory

The default value is "./". This action uses the ESLint installed in your project. This makes sure that it's using your project's ESLint config (plugins, rules, etc). It gets to know your project's location from this value.

targets

The default value is ".". For example, it could be "src" or "src/**/*.ts" for a typical TypeScript project with source code files in the src directory. Use glob pattern to match multiple directories if necessary, for example "{src,lib}" instead of "src lib" or "{src, lib}" to match both the src directory and the lib directory.

eslint-lib-path

The default value is "./node_modules/eslint/lib/api.js". This action uses the ESLint installed in your project. This makes sure that it's using your project's ESLint version. It gets to know your project's ESLint library location from this value.

eslint-bin-path (deprecated)

The default value is "node_modules/.bin/eslint". This action uses the ESLint installed in your project. This makes sure that it's using your project's ESLint version. It gets to know your project's ESLint binary location from this value.

config-path

The default value is an empty string. This action uses ESLint's default config file when this value is empty. That means .eslintrc.json or .eslintrc.js for ESLint up to 8.56.0, and eslint.config.json for ESLint 8.57.0 or 9+. If you name your config file differently you can set it here.

FAQ

What is the difference between a fix and a suggestion in ESLint?

ESLint documentation defines a fix as a change that wouldn't change the runtime behavior of code and cause it to stop working. In constrast, when fixes aren't appropriate to be automatically applied, for example, if a fix potentially changes functionality or if there are multiple valid ways to fix a rule depending on the implementation intent a rule will provide one or multiple suggestions. We have to review and decide if any one of them is appropriate.

Can I have GitHub suggestions outside of the scope?

No. To be precise, it's mostly no. GitHub only allows comments within diff hunks. That means the lines that are changed and up to three adjacent lines before and after. There's no way to comment outside of diff hunks, in GitHub's interface or through API. For better consistency, this action doesn't create GitHub suggestions outside of the scope, even if it's within diff hunk.

How can I avoid having annotation in generated code inside a project?

Please follow GitHub's documentation and use .gitattributes to mark those files and directories correctly. GitHub will hide those files in Pull Request.