Skip to content

Commit

Permalink
Add CI workflow to lint TypeScript and JavaScript code
Browse files Browse the repository at this point in the history
On every push and pull request that affects relevant files, and periodically, run eslint on the repository's TypeScript
and JavaScript files.

eslint is configured via the .eslintrc.yml file:
https://eslint.org/docs/user-guide/configuring/configuration-files
  • Loading branch information
MatteoPologruto committed May 17, 2023
1 parent ab6203d commit 074af1f
Show file tree
Hide file tree
Showing 8 changed files with 8,762 additions and 4,834 deletions.
24 changes: 24 additions & 0 deletions .eslintrc.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Source: https://github.com/per1234/.github/blob/main/workflow-templates/assets/check-typescript/.eslintrc.yml
# See: https://github.com/typescript-eslint/typescript-eslint/blob/main/docs/linting/README.md#configuration
# The code style defined in this file is the official standardized style to be used in all Arduino projects and should
# not be modified.

extends:
- airbnb-typescript/base
- prettier
- 'eslint:recommended'
- 'plugin:@typescript-eslint/recommended'
- 'plugin:import/recommended'
plugins:
- "@typescript-eslint"
parser: "@typescript-eslint/parser"
parserOptions:
project:
- "./tsconfig.eslint.json"
rules:
max-len:
- error
- code: 180
no-console: "off"
no-underscore-dangle: "off"
root: true
58 changes: 58 additions & 0 deletions .github/workflows/check-typescript-task.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
# Source: https://github.com/per1234/.github/blob/main/workflow-templates/check-typescript-task.md
name: Check TypeScript

env:
# See: https://github.com/actions/setup-node/#readme
NODE_VERSION: 16.x

# See: https://docs.github.com/en/actions/reference/events-that-trigger-workflows
on:
push:
paths:
- ".github/workflows/check-typescript-task.ya?ml"
- ".eslintignore"
- "**/.eslintrc*"
- "package.json"
- "package-lock.json"
- "Taskfile.ya?ml"
- "tsconfig.eslint.json"
- "tsconfig.json"
- "**.[jt]sx?"
pull_request:
paths:
- ".github/workflows/check-typescript-task.ya?ml"
- ".eslintignore"
- "**/.eslintrc*"
- "package.json"
- "package-lock.json"
- "Taskfile.ya?ml"
- "tsconfig.eslint.json"
- "tsconfig.json"
- "**.[jt]sx?"
workflow_dispatch:
repository_dispatch:

permissions:
contents: read

jobs:
check:
runs-on: ubuntu-latest

steps:
- name: Checkout repository
uses: actions/checkout@v3

- name: Setup Node.js
uses: actions/setup-node@v3
with:
node-version: ${{ env.NODE_VERSION }}

- name: Install Task
uses: arduino/setup-task@v1
with:
repo-token: ${{ secrets.GITHUB_TOKEN }}
version: 3.x

- name: Lint
run: task ts:lint
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
[![Check Taskfiles status](https://github.com/arduino/setup-protoc/actions/workflows/check-taskfiles.yml/badge.svg)](https://github.com/arduino/setup-protoc/actions/workflows/check-taskfiles.yml)
[![Integration Tests status](https://github.com/arduino/setup-protoc/actions/workflows/test-integration.yml/badge.svg)](https://github.com/arduino/setup-protoc/actions/workflows/test-integration.yml)
[![Check npm status](https://github.com/arduino/setup-protoc/actions/workflows/check-npm-task.yml/badge.svg)](https://github.com/arduino/setup-protoc/actions/workflows/check-npm-task.yml)
[![Check TypeScript status](https://github.com/arduino/setup-protoc/actions/workflows/check-typescript-task.yml/badge.svg)](https://github.com/arduino/setup-protoc/actions/workflows/check-typescript-task.yml)

This action makes the `protoc` compiler available to Workflows.

Expand Down
13 changes: 13 additions & 0 deletions Taskfile.yml
Original file line number Diff line number Diff line change
Expand Up @@ -228,3 +228,16 @@ tasks:
else
echo "{{.RAW_PATH}}"
fi
ts:lint:
desc: Lint TypeScript code
deps:
- task: npm:install-deps
cmds:
- npx eslint --ext .js,.jsx,.ts,.tsx .

ts:fix-lint:
desc: Fix TypeScript code linting violations
deps:
- task: npm:install-deps
cmds:
- npx eslint --ext .js,.jsx,.ts,.tsx --fix .
Loading

0 comments on commit 074af1f

Please sign in to comment.