I have a workflow that checks for ESLint errors by running yarn lint
command.
Here is how the workflow looks like:
name: Build and deploy
on:
push:
branches:
- '**'
env:
app_name: support_case_ui
bucket_name_dev: support-ui-static-files-dev
bucket_name_prod: support-ui-static-files-prod
IS_FEATURE: ${{ github.ref != 'refs/heads/release' && github.ref != 'refs/heads/main'}}
IS_DEV: ${{ github.ref == 'refs/heads/main' }}
NPM_TOKEN: ${{ secrets.READER_TOKEN }}
jobs:
build:
name: Build
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: 20.x
- uses: actions/cache@v4
id: yarn-cache
with:
path: .yarn/cache
key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }}
restore-keys: |
${{ runner.os }}-yarn-
- name: Set environment variables for frontend build
# Use environment variables from feature just for the build to go green. Using actual env variables in deploy step
run: cat env/.env.dev >> $GITHUB_ENV
- name: Install yarn dependencies
run: yarn --immutable
- name: Check lint
run: yarn lint
- name: Run tests and build
run: yarn test && yarn build
deploy-to-feature:
name: Deploy to feature
runs-on: ubuntu-latest
needs: build
if: github.ref != 'refs/heads/main'
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: 20.x
- uses: actions/cache@v4
id: yarn-cache
with:
path: .yarn/cache
key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }}
restore-keys: |
${{ runner.os }}-yarn-
- name: Install yarn dependencies
run: yarn --immutable
- name: Set environment variables for build
run: cat env/.env.dev >> $GITHUB_ENV
- name: Build app
run: yarn build
- name: Login GCP dev
uses: google-github-actions/auth@v1
with:
credentials_json: ${{ secrets.GCP_SERVICEUSER_KEY_DEV }}
- name: Set up Cloud SDK
uses: google-github-actions/setup-gcloud@v1
- name: Upload static files to feature GCP bucket
run: gsutil -m rsync -R -d dist gs://${{env.bucket_name_dev}}/${{env.app_name}}/feature/static
deploy-to-main:
name: Deploy to main
runs-on: ubuntu-latest
needs: build
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: 20.x
- uses: actions/cache@v4
id: yarn-cache
with:
path: .yarn/cache
key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }}
restore-keys: |
${{ runner.os }}-yarn-
- name: Install yarn dependencies
run: yarn --immutable
- name: Set environment variables for build
run: cat env/.env.main >> $GITHUB_ENV
- name: Build app
run: yarn build
- name: Login GCP dev
uses: google-github-actions/auth@v1
with:
credentials_json: ${{ secrets.GCP_SERVICEUSER_KEY_DEV }}
- name: Set up Cloud SDK
uses: google-github-actions/setup-gcloud@v1
- name: Upload static files to dev GCP bucket
run: gsutil -m rsync -R -d dist gs://${{env.bucket_name_dev}}/${{env.app_name}}/main/static
deploy-to-prod:
name: Deploy to prod
runs-on: ubuntu-latest
needs: build
if: github.ref == 'refs/heads/main'
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: 20.x
- uses: actions/cache@v4
id: yarn-cache
with:
path: .yarn/cache
key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }}
restore-keys: |
${{ runner.os }}-yarn-
- name: Install yarn dependencies
run: yarn --immutable
- name: Set environment variables for build
run: cat env/.env.prod >> $GITHUB_ENV
- name: Build app
run: yarn build
- name: Login GCP dev
uses: google-github-actions/auth@v1
with:
credentials_json: ${{ secrets.GCP_SERVICEUSER_KEY_PROD }}
- name: Set up Cloud SDK
uses: google-github-actions/setup-gcloud@v1
- name: Upload static files to prod GCP bucket
run: gsutil -m rsync -R -d dist gs://${{env.bucket_name_prod}}/${{env.app_name}}/static
For this line of code:
type STEPSTYPE = { [key in Stepper]: number } | { [key in CaseStepper]: number };
I get an error when I run a workflow job:
Error: 52:86 error 'key' is defined but never used @typescript-eslint/no-unused-vars
But if I run yarn lint
locally on my computer I don’t get any errors. It runs without any errors:
yarn run v1.22.19
$ eslint ./src/**/*.{js,ts,tsx} package.json --quiet
✨ Done in 3.76s.
Is there any lint rule where I can avoid error for typescript type definitions, other than no-unused-vars
? I would still like to get errors for unused vars, but in my case it is not a var, just a type that the error is being thrown for.
This is my current eslint configuration:
module.exports = {
parser: "@typescript-eslint/parser", // Specifies the ESLint parser
parserOptions: {
ecmaVersion: 2020, // Allows for the parsing of modern ECMAScript features
sourceType: "module", // Allows for the use of imports
ecmaFeatures: {
jsx: true, // Allows for the parsing of JSX
},
},
settings: {
react: {
version: "detect", // Tells eslint-plugin-react to automatically detect the version of React to use
},
"json/sort-package-json": ["name", "version", "private", "scripts", "dependencies", "devDependencies"],
},
plugins: ["@typescript-eslint", "prettier", "json-format", "simple-import-sort", "unused-imports"],
extends: [
"eslint:recommended",
"plugin:@typescript-eslint/eslint-recommended",
"plugin:@typescript-eslint/recommended",
"plugin:prettier/recommended",
],
rules: {
"sort-imports": "off",
"@typescript-eslint/no-namespace": "off",
"@typescript-eslint/ban-ts-comment": "off",
"simple-import-sort/imports": "error",
"simple-import-sort/exports": "error",
"no-unused-vars": "off",
"unused-imports/no-unused-imports": "error",
"@typescript-eslint/no-var-requires": "warn",
"@typescript-eslint/no-empty-function": "warn",
"@typescript-eslint/ban-types": "warn",
"unused-imports/no-unused-vars": [
"warn",
{ vars: "all", varsIgnorePattern: "^_", args: "after-used", argsIgnorePattern: "^_" },
],
eqeqeq: ["error", "smart"],
},
overrides: [
{
files: ["*.js"],
rules: {
"no-undef": "off",
},
},
],
};
Also, not sure why do I get 2 different outputs locally and in GitHub?
I ran yarn install
locally and workflow is running it as well, so that shouldn’t be a different dependency versions issue. How can I fix this?
2
Answers
TypeScript. In your workflow file, node-version: is specified as
20.x. You can check this
yarn list --pattern eslint
command.I may provide you one more thing that I using everytime is; eslint config
"@typescript-eslint/no-unused-vars": ["error", { "argsIgnorePattern": "^_", "varsIgnorePattern": "^_", "ignoreRestSiblings": true, "caughtErrorsIgnorePattern": "^_", "ignoreRestSiblings": true, "destructuredArrayIgnorePattern": "^_", "ignoreTypeReferences": true }]
As mentioned in the comments, you can make sure that the packages are installed properly
Make sure that the dependencies are installed in the same way as in workflow by running the
yarn install --immutable
command.I hope this helps you solve your problem.
try changing your type to