Skip to content

Commit b0797e4

Browse files
chore: Add UI linter back (#3230)
# What does this PR do? 1. Adds `scripts/run-ui-linter.sh` - Light script that checks whether `node_modules`,`eslint`, and `prettier` exist before running linter - When I introduced [the linter for the UI](https://github.com/llamastack/llama-stack/pull/3156/files#diff-63a9c44a44acf85fea213a857769990937107cf072831e1a26808cfde9d096b9) it forced the UI linter on all users, the small `node_modules` check means that only users that have installed the UI locally (since `node_modules` is in the gitignore) will actually end up having this run. Additionally this does not do any install and just runs the existing linter/prettier as requested by @mattf 2. Updates `.github/workflows/pre-commit.yml` to run CI again - When I introduced the UI linter in the CI [in this PR](#3191) a failure occurred because dependabot needed to be updated to also bump the `package-lock.json` which was done [in this PR](#3212). All of this to say, we shouldn't observe failures from dependabot again. 3. Updates `.pre-commit-config.yaml` - Calls `scripts/run-ui-linter.sh` ## AI Assistance Notice I used Copilot minimally. ## Test Plan As [requested](#3207 (comment)) by @mattf I ran this after removing all of my `node_modules` and the linter passed. Signed-off-by: Francisco Javier Arceo <[email protected]>
1 parent f520e24 commit b0797e4

File tree

3 files changed

+34
-39
lines changed

3 files changed

+34
-39
lines changed

.github/workflows/pre-commit.yml

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -36,20 +36,16 @@ jobs:
3636
**/requirements*.txt
3737
.pre-commit-config.yaml
3838
39-
# npm ci may fail -
40-
# npm error `npm ci` can only install packages when your package.json and package-lock.json or npm-shrinkwrap.json are in sync. Please update your lock file with `npm install` before continuing.
41-
# npm error Invalid: lock file's [email protected] does not satisfy [email protected]
42-
43-
# - name: Set up Node.js
44-
# uses: actions/setup-node@39370e3970a6d050c480ffad4ff0ed4d3fdee5af # v4.1.0
45-
# with:
46-
# node-version: '20'
47-
# cache: 'npm'
48-
# cache-dependency-path: 'llama_stack/ui/'
49-
50-
# - name: Install npm dependencies
51-
# run: npm ci
52-
# working-directory: llama_stack/ui
39+
- name: Set up Node.js
40+
uses: actions/setup-node@39370e3970a6d050c480ffad4ff0ed4d3fdee5af # v4.1.0
41+
with:
42+
node-version: '20'
43+
cache: 'npm'
44+
cache-dependency-path: 'llama_stack/ui/'
45+
46+
- name: Install npm dependencies
47+
run: npm ci
48+
working-directory: llama_stack/ui
5349

5450
- uses: pre-commit/action@2c7b3805fd2a0fd8c1884dcaebf91fc102a13ecd # v3.0.1
5551
continue-on-error: true

.pre-commit-config.yaml

Lines changed: 7 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -146,31 +146,13 @@ repos:
146146
pass_filenames: false
147147
require_serial: true
148148
files: ^.github/workflows/.*$
149-
# ui-prettier and ui-eslint are disabled until we can avoid `npm ci`, which is slow and may fail -
150-
# npm error `npm ci` can only install packages when your package.json and package-lock.json or npm-shrinkwrap.json are in sync. Please update your lock file with `npm install` before continuing.
151-
# npm error Invalid: lock file's [email protected] does not satisfy [email protected]
152-
# and until we have infra for installing prettier and next via npm -
153-
# Lint UI code with ESLint.....................................................Failed
154-
# - hook id: ui-eslint
155-
# - exit code: 127
156-
157-
# > next lint --fix --quiet
158-
# sh: line 1: next: command not found
159-
#
160-
# - id: ui-prettier
161-
# name: Format UI code with Prettier
162-
# entry: bash -c 'cd llama_stack/ui && npm ci && npm run format'
163-
# language: system
164-
# files: ^llama_stack/ui/.*\.(ts|tsx)$
165-
# pass_filenames: false
166-
# require_serial: true
167-
# - id: ui-eslint
168-
# name: Lint UI code with ESLint
169-
# entry: bash -c 'cd llama_stack/ui && npm run lint -- --fix --quiet'
170-
# language: system
171-
# files: ^llama_stack/ui/.*\.(ts|tsx)$
172-
# pass_filenames: false
173-
# require_serial: true
149+
- id: ui-linter
150+
name: Format & Lint UI
151+
entry: bash ./scripts/run-ui-linter.sh
152+
language: system
153+
files: ^llama_stack/ui/.*\.(ts|tsx)$
154+
pass_filenames: false
155+
require_serial: true
174156

175157
- id: check-log-usage
176158
name: Ensure 'llama_stack.log' usage for logging

scripts/run-ui-linter.sh

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
#!/bin/bash
2+
# Copyright (c) Meta Platforms, Inc. and affiliates.
3+
# All rights reserved.
4+
#
5+
# This source code is licensed under the terms described in the LICENSE file in
6+
# the root directory of this source tree.
7+
8+
set -e
9+
cd llama_stack/ui
10+
11+
if [ ! -d node_modules ] || [ ! -x node_modules/.bin/prettier ] || [ ! -x node_modules/.bin/eslint ]; then
12+
echo "UI dependencies not installed, skipping prettier/linter check"
13+
exit 0
14+
fi
15+
16+
npm run format
17+
npm run lint

0 commit comments

Comments
 (0)