Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Add assets for JavaScript code linting
An ESLint configuration file provides the standardized configuration for use in Arduino tooling projects. This uses the
Airbnb base configuration. Since Prettier provides code formatting, overlapping ESLint rules are disable via
eslint-config-prettier.

A task is provided to run ESLint on the JavaScript code files of the project the assets are applied to.

On every push and pull request that affects relevant files, and periodically, a GitHub Actions workflow runs this task.
  • Loading branch information
per1234 committed Jul 26, 2022
commit b4c7537df0fdaab84f9c442831cec15b7b6f9371
19 changes: 19 additions & 0 deletions workflow-templates/assets/check-javascript-task/Taskfile.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# See: https://taskfile.dev/#/usage
version: "3"

tasks:
# Source: https://github.com/arduino/tooling-project-assets/blob/main/workflow-templates/assets/check-javascript-task/Taskfile.yml
js:fix:
desc: Fix JavaScript code linting violations
deps:
- task: npm:install-deps
cmds:
- npx eslint --ext .js,.jsx --fix .

# Source: https://github.com/arduino/tooling-project-assets/blob/main/workflow-templates/assets/check-javascript-task/Taskfile.yml
js:lint:
desc: Lint JavaScript code
deps:
- task: npm:install-deps
cmds:
- npx eslint --ext .js,.jsx .
14 changes: 14 additions & 0 deletions workflow-templates/assets/check-javascript/.eslintrc.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# Source: https://github.com/arduino/tooling-project-assets/blob/main/workflow-templates/assets/check-javascript/.eslintrc.yml
# See: https://eslint.org/docs/user-guide/configuring/
# 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-base
- prettier
rules:
max-len:
- error
- code: 180
no-console: "off"
no-underscore-dangle: "off"
93 changes: 93 additions & 0 deletions workflow-templates/check-javascript-task.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
# "Check JavaScript" workflow (Task)

Workflow file: [check-javascript-task.yml](check-javascript-task.yml)

Use [**ESLint**](https://eslint.org/) to lint the repository's JavaScript files.

**Note:** This workflow is focused on linting. Formatting checks for JavaScript are provided by the ["Check Prettier Formatting" workflow (Task)](https://github.com/arduino/tooling-project-assets/blob/main/workflow-templates/check-prettier-formatting-task.md), so both should be used.

This is the version of the workflow for projects using the [Task](https://taskfile.dev/#/) task runner tool.

## Installation

### Workflow

Install the [`check-javascript-task.yml`](check-javascript-task.yml) GitHub Actions workflow to `.github/workflows/`

### Assets

- [`.eslintrc.yml`](assets/check-javascript/.eslintrc.yml) - **ESLint** configuration file.
❗ The code style defined in this file is the official standardized style to be used in all Arduino projects and should not be modified.
- Install to: repository root
- [`Taskfile.yml`](assets/check-javascript-task/Taskfile.yml) - JavaScript linting tasks.
- Install to: repository root (or merge into the existing `Taskfile.yml`).
- [`Taskfile.yml`](assets/npm-task/Taskfile.yml) - npm tasks.
- Install to: repository root (or merge into the existing `Taskfile.yml`).

### Dependencies

The tool dependencies of this workflow are managed by [npm](https://www.npmjs.com/).

Add the dependencies by running this command:

```text
npm install --save-dev eslint@^8.19.0 eslint-config-prettier@^8.5.0
npx install-peerdeps --dev eslint-config-airbnb-base
```

Commit the resulting changes to the `package.json` and `package-lock.json` files.

### Configuration

#### Workflow

Configure the version of [**Node.js**](https://nodejs.org) used for development of the project in the `env.NODE_VERSION` field of `check-javascript-task.yml`.

#### `.gitignore`

Add the following to [`/.gitignore`](https://git-scm.com/docs/gitignore):

```gitignore
/node_modules/
```

### Readme badge

Markdown badge:

```markdown
[![Check JavaScript status](https://github.com/TODO_REPO_OWNER/TODO_REPO_NAME/actions/workflows/check-javascript-task.yml/badge.svg)](https://github.com/TODO_REPO_OWNER/TODO_REPO_NAME/actions/workflows/check-javascript-task.yml)
```

Replace the `TODO_REPO_OWNER` and `TODO_REPO_NAME` placeholders in the URLs with the final repository owner and name ([example](https://raw.githubusercontent.com/arduino-libraries/ArduinoIoTCloud/master/README.md)).

---

Asciidoc badge:

```adoc
image:https://github.com/{repository-owner}/{repository-name}/actions/workflows/check-javascript-task.yml/badge.svg["Check JavaScript status", link="https://github.com/{repository-owner}/{repository-name}/actions/workflows/check-javascript-task.yml"]
```

Define the `{repository-owner}` and `{repository-name}` attributes and use them throughout the readme ([example](https://raw.githubusercontent.com/arduino-libraries/WiFiNINA/master/README.adoc)).

## Commit message

```
Add CI workflow to lint JavaScript code

On every push and pull request that affects relevant files, and periodically, run ESLint on the repository's JavaScript
files.

ESLint is configured via the .eslintrc.yml file:
https://eslint.org/docs/user-guide/configuring/configuration-files
```

## PR message

```markdown
On every push and pull request that affects relevant files, and periodically, run [**ESLint**](https://eslint.org/) on the repository's JavaScript files.

**ESLint** is configured via the `.eslintrc.yml` file:
https://eslint.org/docs/latest/user-guide/configuring/configuration-files
```
54 changes: 54 additions & 0 deletions workflow-templates/check-javascript-task.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
# Source: https://github.com/arduino/tooling-project-assets/blob/main/workflow-templates/check-javascript-task.md
name: Check JavaScript

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

# See: https://docs.github.com/actions/using-workflows/events-that-trigger-workflows
on:
push:
paths:
- ".github/workflows/check-javascript-task.ya?ml"
- ".eslintignore"
- "**/.eslintrc*"
- "package.json"
- "package-lock.json"
- "Taskfile.ya?ml"
- "**.jsx?"
pull_request:
paths:
- ".github/workflows/check-javascript-task.ya?ml"
- ".eslintignore"
- "**/.eslintrc*"
- "package.json"
- "package-lock.json"
- "Taskfile.ya?ml"
- "**.jsx?"
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 js:lint
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
# Source: https://github.com/arduino/tooling-project-assets/blob/main/workflow-templates/check-javascript-task.md
name: Check JavaScript

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

# See: https://docs.github.com/actions/using-workflows/events-that-trigger-workflows
on:
push:
paths:
- ".github/workflows/check-javascript-task.ya?ml"
- ".eslintignore"
- "**/.eslintrc*"
- "package.json"
- "package-lock.json"
- "Taskfile.ya?ml"
- "**.jsx?"
pull_request:
paths:
- ".github/workflows/check-javascript-task.ya?ml"
- ".eslintignore"
- "**/.eslintrc*"
- "package.json"
- "package-lock.json"
- "Taskfile.ya?ml"
- "**.jsx?"
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 js:lint