github-actionseslint

ESLint only runs locally (not github actions). Ignore patternt and src pattern conflict


It seems to be a weird bug where I'm fairly certain that I don't have any eslint ignore directory rules, and I in fact have eslint problems from the directory in question both from CLI and vscode on local machine. I suppose that a round about solution would be for github actions to not consider the push to broken if some sub directory of the directory I'm actually linting to supposedly be ignored. GitHub Actions error message:

> npx eslint src/** *.{js,jsx,ts,tsx} --fix


Oops! Something went wrong! :(

ESLint: 8.57.0

You are linting "src/api", but all of the files matching the glob pattern "src/api" are ignored.

If you don't want to lint these files, remove the pattern "src/api" from the list of arguments passed to ESLint.

Workflow:

name: GitHub Actions Demo
run-name: ${{ github.actor }} is testing out GitHub Actions 🚀
on:
  push:
    branches:
      - deploy
jobs:
  everything:
    runs-on: ubuntu-latest
    # container:
    #   image: cypress/included
    steps:
      - name: Checkout
        uses: actions/checkout@v4
      - name: Cypress install
        uses: cypress-io/github-action@v6
        with:
          # Disable running of tests within install job
          runTests: false
          build: npm install
      - name: Cypress run
        uses: cypress-io/github-action@v6
        with:
          start: npm run dev
      - name: Run ESLint
        run: npm run lint
      - name: Update Schema
        run: npm run updateSchema
      - name: deploy
        uses: cloudflare/wrangler-action@v3
        with:
          apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }}

No any ignore rules package.json or files for ignoring them

import globals from "globals";
import pluginJs from "@eslint/js";
import tseslint from "typescript-eslint";
import eslintPluginUnicorn from "eslint-plugin-unicorn";
import eslintConfigPrettier from "eslint-config-prettier";

export default [
  {languageOptions: { globals: globals.browser }},
  pluginJs.configs.recommended,
  eslintPluginUnicorn.configs['flat/recommended'],

  // ...tseslint.configs.recommended,
  // ...tseslint.configs.recommendedTypeChecked,

  {
    languageOptions: {
      globals: globals.browser,
      parserOptions: {
        project: true,
        // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
        tsconfigRootDir: import.meta.dirname,
      },
    },
    rules: {
      // "@typescript-eslint/no-floating-promises": "error",
      "unicorn/filename-case": [
        "error",
        {
          case: "camelCase",
        },
      ],
    },
  },
  // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
  // pluginJs.configs.recommended,
  // // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
  // eslintPluginUnicorn.configs["flat/recommended"],
  // // //...tseslint.configs.recommended,
  // // ...tseslint.configs.recommendedTypeChecked,
  // eslintConfigPrettier,
];

Solution

  • I see three changes that would likely fix the bug you’re encountering.

    1/ Amend package.json:

    {
      "lint": "eslint eslint.config.mjs src/**/*.{js,jsx,ts,tsx} --fix",
    }
    

    2/ Double-check to make sure that your tsconfig.json also includes all the files in your lint scope. The tsconfig scope must be wider than your lint scope (EDIT 2024/06/23: Only true when linting files included in TypeScript transpilation).

    For example:

    {
      "include": [
        "./src/**/*.js",
        "./src/**/*.jsx",
        "./src/**/*.ts",
        "./src/**/*.tsx",
      ]
    }