Skip to content

Commit 52c39e2

Browse files
jasonbahlactions-usergithub-code-quality[bot]
authored
fix: resolve all JavaScript linting errors in wp-graphql-ide (#3548)
Co-authored-by: GitHub Actions <[email protected]> Co-authored-by: Copilot Autofix powered by AI <223894421+github-code-quality[bot]@users.noreply.github.com>
1 parent bd56138 commit 52c39e2

File tree

24 files changed

+340
-195
lines changed

24 files changed

+340
-195
lines changed

.github/workflows/js-e2e-tests-reusable.yml

Lines changed: 48 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,15 +61,49 @@ jobs:
6161
working-directory: ${{ inputs.plugin_path }}
6262
composer-options: '--no-progress'
6363

64+
# For plugins that depend on wp-graphql, we also need to install wp-graphql's dependencies
65+
# BEFORE wp-env starts so the vendor directory is available when WordPress loads the plugin
66+
# (wp-env maps plugin dirs as volumes, so host vendor dirs are available in containers)
67+
- name: Install wp-graphql dependencies (if needed)
68+
if: inputs.plugin_name != 'wp-graphql'
69+
uses: ramsey/composer-install@v3
70+
with:
71+
working-directory: plugins/wp-graphql
72+
composer-options: '--no-progress'
73+
6474
- name: Install NPM dependencies
6575
run: npm ci
6676

77+
# Build wp-graphql JS assets if this plugin depends on it
78+
# This must happen before wp-env starts so the built files are available in the container
79+
- name: Build wp-graphql (if required as dependency)
80+
if: inputs.plugin_name != 'wp-graphql'
81+
run: |
82+
echo "📦 Building wp-graphql (required dependency for ${{ inputs.plugin_name }})..."
83+
npm run build -w @wpgraphql/wp-graphql
84+
echo "✅ wp-graphql built successfully"
85+
86+
- name: Cache Playwright browsers
87+
uses: actions/cache@v4
88+
id: playwright-cache
89+
with:
90+
path: |
91+
~/.cache/ms-playwright
92+
key: ${{ runner.os }}-playwright-${{ hashFiles('**/package-lock.json') }}
93+
restore-keys: |
94+
${{ runner.os }}-playwright-
95+
96+
- name: Install Playwright system dependencies
97+
run: npx playwright install-deps chromium
98+
if: steps.playwright-cache.outputs.cache-hit != 'true'
99+
100+
- name: Install Playwright browsers
101+
run: npx playwright install chromium
102+
if: steps.playwright-cache.outputs.cache-hit != 'true'
103+
67104
- name: Build JavaScript assets
68105
run: npm run build
69106

70-
- name: Install Playwright dependencies
71-
run: npx playwright install chromium firefox webkit --with-deps
72-
73107
- name: Cache Docker images
74108
uses: ScribeMD/[email protected]
75109
with:
@@ -96,6 +130,17 @@ jobs:
96130
npm run wp-env run tests-cli -- wp option get siteurl
97131
echo "Testing GraphQL endpoint..."
98132
npm run wp-env run tests-cli -- curl -s -o /dev/null -w "HTTP %{http_code}" http://tests-wordpress/graphql?query=%7B__typename%7D
133+
echo "Waiting for WordPress to be fully ready..."
134+
for i in {1..30}; do
135+
if curl -f -s http://localhost:8888/wp-admin/install.php > /dev/null 2>&1 || curl -f -s http://localhost:8888/wp-admin > /dev/null 2>&1; then
136+
echo "WordPress is ready!"
137+
break
138+
fi
139+
echo "Waiting for WordPress... ($i/30)"
140+
sleep 2
141+
done
142+
echo "Verifying WordPress is accessible from host..."
143+
curl -f -s http://localhost:8888/wp-admin/install.php > /dev/null || curl -f -s http://localhost:8888/wp-admin > /dev/null || (echo "WordPress is not accessible!" && exit 1)
99144
100145
- name: Run E2E tests
101146
run: |

.github/workflows/lint-reusable.yml

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,3 +141,50 @@ jobs:
141141
with:
142142
path: ${{ inputs.plugin_path }}/tests/_output
143143
key: 'phpstan-result-cache-${{ runner.os }}-date-${{ steps.get-date.outputs.date }}'
144+
145+
# Runs JavaScript linting checks.
146+
#
147+
# Performs the following steps:
148+
# - Checks out the repository.
149+
# - Sets up Node.js.
150+
# - Installs NPM dependencies.
151+
# - Runs ESLint on JavaScript files.
152+
# - Only runs if the plugin has JavaScript source files.
153+
lintjs:
154+
name: JavaScript Lint (${{ inputs.plugin_name }})
155+
runs-on: ubuntu-24.04
156+
permissions:
157+
contents: read
158+
timeout-minutes: 10
159+
continue-on-error: true
160+
161+
steps:
162+
- name: Checkout repository
163+
uses: actions/checkout@0c366fd6a839edf440554fa01a7085ccba70ac98 # v6.0.2
164+
with:
165+
show-progress: ${{ runner.debug == '1' && 'true' || 'false' }}
166+
persist-credentials: false
167+
168+
- name: Setup Node.js
169+
uses: actions/setup-node@v6
170+
with:
171+
cache: 'npm'
172+
node-version-file: '.nvmrc'
173+
174+
- name: Install NPM dependencies
175+
run: npm ci
176+
177+
- name: Check if lint:js script exists
178+
id: check-script
179+
working-directory: ${{ inputs.plugin_path }}
180+
run: |
181+
if grep -q '"lint:js"' package.json; then
182+
echo "has_js_lint=true" >> $GITHUB_OUTPUT
183+
else
184+
echo "has_js_lint=false" >> $GITHUB_OUTPUT
185+
fi
186+
187+
- name: Run JavaScript linting
188+
if: steps.check-script.outputs.has_js_lint == 'true'
189+
working-directory: ${{ inputs.plugin_path }}
190+
run: npm run lint:js

.github/workflows/lint.yml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,12 @@ jobs:
6868
- .github/workflows/lint-reusable.yml
6969
- .github/workflows/lint.yml
7070
- plugins/wp-graphql/**/*.php
71+
- plugins/wp-graphql/**/*.js
72+
- plugins/wp-graphql/**/*.jsx
73+
- plugins/wp-graphql/**/*.ts
74+
- plugins/wp-graphql/**/*.tsx
75+
- plugins/wp-graphql/package.json
76+
- plugins/wp-graphql/package-lock.json
7177
- plugins/wp-graphql/composer.json
7278
- plugins/wp-graphql/composer.lock
7379
- plugins/wp-graphql/phpcs.xml.dist
@@ -87,6 +93,12 @@ jobs:
8793
- .github/workflows/lint-reusable.yml
8894
- .github/workflows/lint.yml
8995
- plugins/wp-graphql-ide/**/*.php
96+
- plugins/wp-graphql-ide/**/*.js
97+
- plugins/wp-graphql-ide/**/*.jsx
98+
- plugins/wp-graphql-ide/**/*.ts
99+
- plugins/wp-graphql-ide/**/*.tsx
100+
- plugins/wp-graphql-ide/package.json
101+
- plugins/wp-graphql-ide/package-lock.json
90102
- plugins/wp-graphql-ide/composer.json
91103
- plugins/wp-graphql-ide/composer.lock
92104
- plugins/wp-graphql-ide/phpcs.xml.dist

.husky/pre-commit

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# Run lint-staged for all workspaces
2+
npx lint-staged || exit 1

package-lock.json

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
"@wordpress/prettier-config": "^4.38.0",
3535
"@wordpress/scripts": "^31.3.0",
3636
"husky": "^9.1.7",
37+
"lint-staged": "^16.2.7",
3738
"turbo": "^2.7.6"
3839
},
3940
"overrides": {

plugins/wp-graphql-ide/.wp-env.json

Lines changed: 0 additions & 9 deletions
This file was deleted.

plugins/wp-graphql-ide/package.json

Lines changed: 36 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -22,47 +22,28 @@
2222
"build": "npm run build:main && npm run build:zip",
2323
"build:main": "wp-scripts build",
2424
"build:zip": "wp-scripts plugin-zip",
25+
"check-engines": "wp-scripts check-engines",
26+
"clean": "rimraf node_modules plugins/*/node_modules plugins/*/build build",
27+
"format": "wp-scripts format",
28+
"lint": "npm run lint:js",
29+
"lint:js": "wp-scripts lint-js ./src",
30+
"lint:js:fix": "wp-scripts lint-js --fix ./src",
31+
"prepare": "husky install",
2532
"start": "concurrently --kill-others-on-fail -n 'Main,Plugins' -c 'blue,green' \"wp-scripts start\" \"node bin/start-plugins.js\"",
26-
"test:unit": "jest --config tests/unit/jest.config.js",
27-
"test:e2e": "wp-scripts test-playwright --config tests/e2e/playwright.config.js",
28-
"test:e2e:ui": "wp-scripts test-playwright --config tests/e2e/playwright.config.js --ui",
2933
"pretest:codecept": "npm run build:main || echo '⚠️ Build failed, tests may fail if build assets are missing'",
3034
"test:codecept": "npm run --prefix ../.. wp-env -- run tests-cli --env-cwd=wp-content/plugins/wp-graphql-ide/ -- bash -c 'export TEST_DB_HOST=${WORDPRESS_DB_HOST:-tests-mysql} TEST_DB_NAME=${WORDPRESS_DB_NAME:-tests-wordpress} TEST_DB_USER=${WORDPRESS_DB_USER:-root} TEST_DB_PASSWORD=${WORDPRESS_DB_PASSWORD:-password} TEST_WP_URL=${TEST_WP_URL:-http://tests-wordpress} TEST_WP_TABLE_PREFIX=${TEST_WP_TABLE_PREFIX:-wp_} TEST_WP_DOMAIN=${TEST_WP_DOMAIN:-localhost} TEST_ADMIN_USERNAME=${TEST_ADMIN_USERNAME:-admin} TEST_ADMIN_PASSWORD=${TEST_ADMIN_PASSWORD:-password} TEST_ADMIN_PATH=${TEST_ADMIN_PATH:-/wp-admin} TEST_ADMIN_EMAIL=${TEST_ADMIN_EMAIL:[email protected]} TEST_WP_ROOT_FOLDER=${TEST_WP_ROOT_FOLDER:-/var/www/html} && vendor/bin/codecept \"$@\"' --",
31-
"pretest:codecept:wpunit": "npm run build:main || echo '⚠️ Build failed, tests may fail if build assets are missing'",
32-
"test:codecept:wpunit": "npm run --prefix ../.. wp-env -- run tests-cli --env-cwd=wp-content/plugins/wp-graphql-ide/ -- bash -c 'export TEST_DB_HOST=${WORDPRESS_DB_HOST:-tests-mysql} TEST_DB_NAME=${WORDPRESS_DB_NAME:-tests-wordpress} TEST_DB_USER=${WORDPRESS_DB_USER:-root} TEST_DB_PASSWORD=${WORDPRESS_DB_PASSWORD:-password} TEST_WP_TABLE_PREFIX=${TEST_WP_TABLE_PREFIX:-wp_} TEST_WP_DOMAIN=${TEST_WP_DOMAIN:-localhost} TEST_ADMIN_EMAIL=${TEST_ADMIN_EMAIL:[email protected]} TEST_WP_ROOT_FOLDER=${TEST_WP_ROOT_FOLDER:-/var/www/html} TEST_THEME=${TEST_THEME:-twentytwentyone} && vendor/bin/codecept run wpunit \"$@\"' --",
3335
"test:codecept:acceptance": "npm run --prefix ../.. wp-env -- run tests-cli --env-cwd=wp-content/plugins/wp-graphql-ide/ -- bash -c 'export TEST_DB_HOST=${WORDPRESS_DB_HOST:-tests-mysql} TEST_DB_NAME=${WORDPRESS_DB_NAME:-tests-wordpress} TEST_DB_USER=${WORDPRESS_DB_USER:-root} TEST_DB_PASSWORD=${TEST_DB_PASSWORD:-password} TEST_WP_URL=${TEST_WP_URL:-http://tests-wordpress} TEST_WP_TABLE_PREFIX=${TEST_WP_TABLE_PREFIX:-wp_} TEST_WP_DOMAIN=${TEST_WP_DOMAIN:-localhost} TEST_WP_ROOT_FOLDER=${TEST_WP_ROOT_FOLDER:-/var/www/html} TEST_ADMIN_USERNAME=${TEST_ADMIN_USERNAME:-admin} TEST_ADMIN_PASSWORD=${TEST_ADMIN_PASSWORD:-password} TEST_ADMIN_PATH=${TEST_ADMIN_PATH:-/wp-admin} TEST_ADMIN_EMAIL=${TEST_ADMIN_EMAIL:[email protected]} && vendor/bin/codecept run acceptance \"$@\"' --",
3436
"test:codecept:functional": "npm run --prefix ../.. wp-env -- run tests-cli --env-cwd=wp-content/plugins/wp-graphql-ide/ -- bash -c 'export TEST_DB_HOST=${WORDPRESS_DB_HOST:-tests-mysql} TEST_DB_NAME=${WORDPRESS_DB_NAME:-tests-wordpress} TEST_DB_USER=${WORDPRESS_DB_USER:-root} TEST_DB_PASSWORD=${TEST_DB_PASSWORD:-password} TEST_WP_URL=${TEST_WP_URL:-http://tests-wordpress} TEST_WP_TABLE_PREFIX=${TEST_WP_TABLE_PREFIX:-wp_} TEST_WP_DOMAIN=${TEST_WP_DOMAIN:-localhost} TEST_WP_ROOT_FOLDER=${TEST_WP_ROOT_FOLDER:-/var/www/html} TEST_ADMIN_USERNAME=${TEST_ADMIN_USERNAME:-admin} TEST_ADMIN_PASSWORD=${TEST_ADMIN_PASSWORD:-password} TEST_ADMIN_PATH=${TEST_ADMIN_PATH:-/wp-admin} TEST_ADMIN_EMAIL=${TEST_ADMIN_EMAIL:[email protected]} && vendor/bin/codecept run functional \"$@\"' --",
35-
"lint:js": "wp-scripts lint-js ./src",
36-
"lint:js:fix": "wp-scripts lint-js --fix ./src",
37-
"lint:js:src": "wp-scripts lint-js ./src",
38-
"format": "wp-scripts format",
39-
"format:src": "wp-scripts format ./src",
40-
"check-engines": "wp-scripts check-engines",
41-
"clean": "rimraf node_modules plugins/*/node_modules plugins/*/build build",
42-
"prepare": "husky install",
37+
"pretest:codecept:wpunit": "npm run build:main || echo '⚠️ Build failed, tests may fail if build assets are missing'",
38+
"test:codecept:wpunit": "npm run --prefix ../.. wp-env -- run tests-cli --env-cwd=wp-content/plugins/wp-graphql-ide/ -- bash -c 'export TEST_DB_HOST=${WORDPRESS_DB_HOST:-tests-mysql} TEST_DB_NAME=${WORDPRESS_DB_NAME:-tests-wordpress} TEST_DB_USER=${WORDPRESS_DB_USER:-root} TEST_DB_PASSWORD=${WORDPRESS_DB_PASSWORD:-password} TEST_WP_TABLE_PREFIX=${TEST_WP_TABLE_PREFIX:-wp_} TEST_WP_DOMAIN=${TEST_WP_DOMAIN:-localhost} TEST_ADMIN_EMAIL=${TEST_ADMIN_EMAIL:[email protected]} TEST_WP_ROOT_FOLDER=${TEST_WP_ROOT_FOLDER:-/var/www/html} TEST_THEME=${TEST_THEME:-twentytwentyone} && vendor/bin/codecept run wpunit \"$@\"' --",
39+
"test:e2e": "wp-scripts test-playwright --config tests/e2e/playwright.config.js",
40+
"test:e2e:ui": "wp-scripts test-playwright --config tests/e2e/playwright.config.js --ui",
41+
"test:unit": "jest --config tests/unit/jest.config.js",
4342
"wp-env": "wp-env"
4443
},
45-
"devDependencies": {
46-
"@babel/preset-env": "^7.23.9",
47-
"@babel/preset-react": "^7.23.3",
48-
"@playwright/test": "^1.41.2",
49-
"@testing-library/jest-dom": "^6.4.2",
50-
"@testing-library/react": "^14.2.1",
51-
"@types/node": "^20.11.16",
52-
"@wordpress/e2e-test-utils-playwright": "^0.19.0",
53-
"@wordpress/env": "^9.2.0",
54-
"@wordpress/prettier-config": "^4.38.0",
55-
"@wordpress/scripts": "^27.9.0",
56-
"babel-jest": "^29.7.0",
57-
"chalk": "^5.3.0",
58-
"clsx": "^2.0.0",
59-
"concurrently": "^8.2.2",
60-
"docker-compose": "^0.24.6",
61-
"dotenv": "^16.4.4",
62-
"husky": "^9.0.11",
63-
"lint-staged": "^15.2.10",
64-
"rimraf": "^5.0.0",
65-
"sort-package-json": "^2.7.0"
44+
"lint-staged": {
45+
"package.json": "sort-package-json",
46+
"src/**/*.{js,jsx,ts,tsx}": "wp-scripts lint-js"
6647
},
6748
"dependencies": {
6849
"@graphiql/react": "^0.22.4",
@@ -82,7 +63,26 @@
8263
"react": "^18.2.0",
8364
"vaul": "^0.9.0"
8465
},
85-
"lint-staged": {
86-
"package.json": "sort-package-json"
66+
"devDependencies": {
67+
"@babel/preset-env": "^7.23.9",
68+
"@babel/preset-react": "^7.23.3",
69+
"@playwright/test": "^1.58.0",
70+
"@testing-library/jest-dom": "^6.4.2",
71+
"@testing-library/react": "^14.2.1",
72+
"@types/node": "^22.19.3",
73+
"@wordpress/e2e-test-utils-playwright": "^0.19.0",
74+
"@wordpress/env": "^10.37.0",
75+
"@wordpress/prettier-config": "^4.38.0",
76+
"@wordpress/scripts": "^27.9.0",
77+
"babel-jest": "^29.7.0",
78+
"chalk": "^5.3.0",
79+
"clsx": "^2.0.0",
80+
"concurrently": "^8.2.2",
81+
"docker-compose": "^0.24.6",
82+
"dotenv": "^16.4.4",
83+
"husky": "^9.0.11",
84+
"lint-staged": "^16.2.7",
85+
"rimraf": "^5.0.0",
86+
"sort-package-json": "^2.7.0"
8787
}
8888
}

plugins/wp-graphql-ide/plugins/query-composer-panel/src/components/AbstractArgView.jsx

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ class AbstractArgView extends React.PureComponent {
7777
</select>
7878
);
7979
} else {
80+
// eslint-disable-next-line no-console
8081
console.error(
8182
'arg mismatch between arg and selection',
8283
argType,
@@ -114,6 +115,7 @@ class AbstractArgView extends React.PureComponent {
114115
</div>
115116
);
116117
} else {
118+
// eslint-disable-next-line no-console
117119
console.error(
118120
'arg mismatch between arg and selection',
119121
argType,
@@ -138,7 +140,7 @@ class AbstractArgView extends React.PureComponent {
138140
variableName = baseVariableName;
139141
}
140142
const argPrintedType = arg.type.toString();
141-
const argType = parseType(argPrintedType);
143+
const parsedArgType = parseType(argPrintedType);
142144

143145
const base = {
144146
kind: 'VariableDefinition',
@@ -149,7 +151,7 @@ class AbstractArgView extends React.PureComponent {
149151
value: variableName,
150152
},
151153
},
152-
type: argType,
154+
type: parsedArgType,
153155
directives: [],
154156
};
155157

@@ -196,8 +198,8 @@ class AbstractArgView extends React.PureComponent {
196198
const newlyUnusedVariables = Object.entries(
197199
subVariableUsageCountByName
198200
)
199-
.filter(([_, usageCount]) => usageCount < 2)
200-
.map(([varName, _]) => varName);
201+
.filter(([, usageCount]) => usageCount < 2)
202+
.map(([varName]) => varName);
201203

202204
if (variable) {
203205
const newDoc = this.props.setArgValue(variable, false);
@@ -372,8 +374,10 @@ class AbstractArgView extends React.PureComponent {
372374
className={`graphiql-explorer-${arg.name}`}
373375
>
374376
<span
377+
role="button"
378+
tabIndex="0"
375379
style={{ cursor: 'pointer' }}
376-
onClick={(event) => {
380+
onClick={() => {
377381
const shouldAdd = !argValue;
378382
if (shouldAdd) {
379383
this.props.addArg(true);
@@ -382,6 +386,18 @@ class AbstractArgView extends React.PureComponent {
382386
}
383387
this.setState({ displayArgActions: shouldAdd });
384388
}}
389+
onKeyDown={(e) => {
390+
if (e.key === 'Enter' || e.key === ' ') {
391+
e.preventDefault();
392+
const shouldAdd = !argValue;
393+
if (shouldAdd) {
394+
this.props.addArg(true);
395+
} else {
396+
this.props.removeArg(true);
397+
}
398+
this.setState({ displayArgActions: shouldAdd });
399+
}
400+
}}
385401
>
386402
{isInputObjectType(argType) ? (
387403
<span>

0 commit comments

Comments
 (0)