From 12e30fc370cec2b3755198edebf61d653d637969 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Iv=C3=A1n=20Ovejero?= Date: Wed, 11 Sep 2024 20:52:08 +0200 Subject: [PATCH 1/8] Pin version of eslint-plugin-local to 3.21.0 --- scripts/lint-codebase.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/lint-codebase.sh b/scripts/lint-codebase.sh index 446bc8d..ac89ed0 100755 --- a/scripts/lint-codebase.sh +++ b/scripts/lint-codebase.sh @@ -12,7 +12,7 @@ echo 'Step 0: Setting up...' npm install --ignore-scripts -npm install eslint-plugin-local +npm install eslint-plugin-local@3.21.0 pnpm build # ----- # From 081aa1590b155bb8c700c17ba6147a903b8bde99 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Iv=C3=A1n=20Ovejero?= Date: Wed, 11 Sep 2024 20:53:54 +0200 Subject: [PATCH 2/8] Temporarily fetch only 10 files --- scripts/fetch-codebase.mjs | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/scripts/fetch-codebase.mjs b/scripts/fetch-codebase.mjs index 985a280..c0849d1 100644 --- a/scripts/fetch-codebase.mjs +++ b/scripts/fetch-codebase.mjs @@ -37,14 +37,16 @@ async function getFilenames() { getFullData: true, }); - return files.filter( - (file) => - file.path.endsWith(".ts") && - !file.path.endsWith(".d.ts") && - !file.path.endsWith(".test.ts") && - !file.path.includes("nodes-base/test") && - !file.path.includes("nodes-base/utils") - ); + return files + .filter( + (file) => + file.path.endsWith(".ts") && + !file.path.endsWith(".d.ts") && + !file.path.endsWith(".test.ts") && + !file.path.includes("nodes-base/test") && + !file.path.includes("nodes-base/utils") + ) + .slice(0, 10); // @TEMP } async function fetchFile(file, signal) { From 81e6747ec74098e910f0dc54338778fb3421beb8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Iv=C3=A1n=20Ovejero?= Date: Wed, 11 Sep 2024 20:55:31 +0200 Subject: [PATCH 3/8] Try with 4.0.0 --- scripts/lint-codebase.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/lint-codebase.sh b/scripts/lint-codebase.sh index ac89ed0..8fe8b1a 100755 --- a/scripts/lint-codebase.sh +++ b/scripts/lint-codebase.sh @@ -12,7 +12,7 @@ echo 'Step 0: Setting up...' npm install --ignore-scripts -npm install eslint-plugin-local@3.21.0 +npm install eslint-plugin-local@4.0.0 pnpm build # ----- # From 22e4aeb56b25fb4bc558bef3aabaff0135189819 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Iv=C3=A1n=20Ovejero?= Date: Wed, 11 Sep 2024 20:59:25 +0200 Subject: [PATCH 4/8] Try with 1.0.0 --- scripts/lint-codebase.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/lint-codebase.sh b/scripts/lint-codebase.sh index 8fe8b1a..f17d05b 100755 --- a/scripts/lint-codebase.sh +++ b/scripts/lint-codebase.sh @@ -12,7 +12,7 @@ echo 'Step 0: Setting up...' npm install --ignore-scripts -npm install eslint-plugin-local@4.0.0 +npm install eslint-plugin-local@1.0.0 pnpm build # ----- # From aabd6abc0b8ceef246da1ef8fef181683689f308 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Iv=C3=A1n=20Ovejero?= Date: Wed, 11 Sep 2024 21:27:01 +0200 Subject: [PATCH 5/8] Switch `n8n-nodes-base` refs to `local` --- scripts/make-dot-eslintplugin-js.mjs | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/scripts/make-dot-eslintplugin-js.mjs b/scripts/make-dot-eslintplugin-js.mjs index c38ff62..2d5898e 100644 --- a/scripts/make-dot-eslintplugin-js.mjs +++ b/scripts/make-dot-eslintplugin-js.mjs @@ -16,10 +16,12 @@ const pluginIndexFile = path.resolve(DIST_DIR, "index.js"); shell.cp(pluginIndexFile, ".eslintplugin.js"); const oldContent = shell.cat(".eslintplugin.js"); -const newContent = oldContent.replace( - /__dirname, "lib", "rules"/, - '__dirname, "dist", "lib", "rules"' // adjust reference based on new location (root) -); +const newContent = oldContent + .replace( + /__dirname, "lib", "rules"/, + '__dirname, "dist", "lib", "rules"' // adjust reference based on new location (root) + ) + .replace(/n8n-nodes-base/g, "local"); new ShellString(newContent).to(".eslintplugin.js"); From cb1abc295600969f4b8207e756346bd1d96463dd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Iv=C3=A1n=20Ovejero?= Date: Wed, 11 Sep 2024 21:41:03 +0200 Subject: [PATCH 6/8] Clean up script --- scripts/lint-codebase.sh | 36 ++++++++++++++++++++++-------------- 1 file changed, 22 insertions(+), 14 deletions(-) diff --git a/scripts/lint-codebase.sh b/scripts/lint-codebase.sh index f17d05b..f69c380 100755 --- a/scripts/lint-codebase.sh +++ b/scripts/lint-codebase.sh @@ -1,21 +1,29 @@ #!/bin/bash -# This script runs this commit of `eslint-plugin-n8n-nodes-base` on the -# n8n codebase to ensure the linter does not crash during the run. +# This script runs all rules in `eslint-plugin-n8n-nodes-base` (as they exist in +# this commit) on `n8n-io/n8n/packages/nodes-base`. The purpose is to ensure the +# linter runs successfully (does not crash) on the entire codebase during a CI +# run. The actual lint results can be disregarded. -# ----- # +# To do so, we build all rules locally and run ESLint on a lint config file that +# points to those locally built rules. Specifically, we set up an +# `.eslintrc.lc.js` file that enables the `eslint-plugin-local` plugin and two +# configs: `eslint-plugin-local/nodes` and `eslint-plugin-local/credentials` . +# Those configs made up of locally built rules are in an `.eslintplugin.js` +# file, which `eslint-plugin-local` uses to resolve the rules. + +# ----------------------------------------------------------- # -# 0. Install dependencies with npm. We must use npm instead of pnpm to -# allow `eslint-plugin-local` to `require('../../.eslintplugin')`. -# The flag `--ignore-scripts` bypasses the pnpm block at `preinstall`. +# 0. Install dependencies. Use npm instead of pnpm to allow +# `eslint-plugin-local` to `require('../../.eslintplugin')`. +# `--ignore-scripts` bypasses the pnpm block at `preinstall`. -echo 'Step 0: Setting up...' +echo 'Step 0: Installing dependencies...' npm install --ignore-scripts npm install eslint-plugin-local@1.0.0 pnpm build -# ----- # # 1. `index.js` is the entrypoint to this plugin - it is copied during build # to `/dist/index.js` and references the rules dir at `/dist/lib/rules`. @@ -25,11 +33,10 @@ pnpm build # and located at root, so we copy `index.js` into `.eslintplugin.js`, with # the rules dir path adjusted relative to the root of the project. -echo 'Step 1: Creating .eslintplugin.js...' +echo 'Step 1: Creating `.eslintplugin.js`...' node scripts/make-dot-eslintplugin-js.mjs -# ----- # # 2. Fetch the entire codebase from the n8n repo at GitHub. @@ -37,7 +44,6 @@ echo 'Step 2: Fetching codebase...' node scripts/fetch-codebase.mjs -# ----- # # 3. Run this commit of `eslint-plugin-n8n-nodes-base` on the codebase, # using the ESLint config `eslintrc.lc.js` (lc -> lint codebase), which @@ -56,10 +62,12 @@ echo 'Step 3: Linting codebase...' # ----- # if [[ $? == 2 ]] ; then - echo 'ERROR: Linter crashed while running through codebase' + echo '❌ Error: Linter crashed while running through codebase' + echo 'Review and fix the failing lint rule(s) before releasing' exit 1 fi -echo 'SUCCESS: Linter successfully ran through codebase' -echo 'Ignore any actual lint errors or warnings from the run' +echo '✅ Success: Linter successfully ran through codebase' +echo 'The goal was to ensure the linter does not crash during the run' +echo 'You can disregard any actual lint errors or warnings from the run' exit 0 From 2f5df207d5eccd9391b8cfe959319323ecf8e1fc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Iv=C3=A1n=20Ovejero?= Date: Wed, 11 Sep 2024 21:41:09 +0200 Subject: [PATCH 7/8] Remove temp limitation --- scripts/fetch-codebase.mjs | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/scripts/fetch-codebase.mjs b/scripts/fetch-codebase.mjs index c0849d1..985a280 100644 --- a/scripts/fetch-codebase.mjs +++ b/scripts/fetch-codebase.mjs @@ -37,16 +37,14 @@ async function getFilenames() { getFullData: true, }); - return files - .filter( - (file) => - file.path.endsWith(".ts") && - !file.path.endsWith(".d.ts") && - !file.path.endsWith(".test.ts") && - !file.path.includes("nodes-base/test") && - !file.path.includes("nodes-base/utils") - ) - .slice(0, 10); // @TEMP + return files.filter( + (file) => + file.path.endsWith(".ts") && + !file.path.endsWith(".d.ts") && + !file.path.endsWith(".test.ts") && + !file.path.includes("nodes-base/test") && + !file.path.includes("nodes-base/utils") + ); } async function fetchFile(file, signal) { From 2818f06fda6e10783d57a3ea46e86cf4dd8dc97d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Iv=C3=A1n=20Ovejero?= Date: Wed, 11 Sep 2024 21:46:25 +0200 Subject: [PATCH 8/8] Documet --- .github/workflows/test-lint-codebase.yml | 10 +++++++-- scripts/lint-codebase.sh | 28 +++++++++++------------- 2 files changed, 21 insertions(+), 17 deletions(-) diff --git a/.github/workflows/test-lint-codebase.yml b/.github/workflows/test-lint-codebase.yml index c54dbe9..7b1cbf1 100644 --- a/.github/workflows/test-lint-codebase.yml +++ b/.github/workflows/test-lint-codebase.yml @@ -1,11 +1,17 @@ -# Workflow only meant to be manually run to test the `lint-codebase` command +# `lint-codebase` runs all rules in `eslint-plugin-n8n-nodes-base` (as they +# exist in this commit) on `n8n-io/n8n/packages/nodes-base`. The purpose is to +# ensure the linter runs successfully (does not crash) on the entire codebase. +# `lint-codebase` is part of the `ci-release` action. + +# This GitHub action `test-lint-codebase` is meant to be run manually for debugging. + name: Test lint-codebase on: workflow_dispatch: jobs: - test-lint-codebase-command: + test-lint-codebase: runs-on: ubuntu-latest steps: diff --git a/scripts/lint-codebase.sh b/scripts/lint-codebase.sh index f69c380..79aaeae 100755 --- a/scripts/lint-codebase.sh +++ b/scripts/lint-codebase.sh @@ -14,9 +14,9 @@ # ----------------------------------------------------------- # -# 0. Install dependencies. Use npm instead of pnpm to allow -# `eslint-plugin-local` to `require('../../.eslintplugin')`. -# `--ignore-scripts` bypasses the pnpm block at `preinstall`. +# 0. Install dependencies. Use npm instead of pnpm to allow `eslint-plugin-local` +# to `require('../../.eslintplugin')`. `--ignore-scripts` bypasses the pnpm block at +# `preinstall`. echo 'Step 0: Installing dependencies...' @@ -25,13 +25,13 @@ npm install eslint-plugin-local@1.0.0 pnpm build -# 1. `index.js` is the entrypoint to this plugin - it is copied during build -# to `/dist/index.js` and references the rules dir at `/dist/lib/rules`. -# This reference is relative to the entrypoint's location after copy. +# 1. `index.js` is the entrypoint to this plugin - it is copied during build to +# `/dist/index.js` and references the rules dir at `/dist/lib/rules`. This reference +# is relative to the entrypoint's location after copy. -# `eslint-plugin-local` requires the entrypoint to be named `.eslintplugin.js` -# and located at root, so we copy `index.js` into `.eslintplugin.js`, with -# the rules dir path adjusted relative to the root of the project. +# `eslint-plugin-local` requires the entrypoint to be named `.eslintplugin.js` and located +# at root, so we copy `index.js` into `.eslintplugin.js`, with the rules dir path adjusted +# relative to the root of the project. echo 'Step 1: Creating `.eslintplugin.js`...' @@ -45,11 +45,10 @@ echo 'Step 2: Fetching codebase...' node scripts/fetch-codebase.mjs -# 3. Run this commit of `eslint-plugin-n8n-nodes-base` on the codebase, -# using the ESLint config `eslintrc.lc.js` (lc -> lint codebase), which -# references `.eslintplugin.js` (all rules) via `eslint-plugin-local`. -# The flag `--no-eslintrc` prevents ESLint from finding and using -# the sibling `.eslintrc.js` that is intended for this plugin. +# 3. Run this commit of `eslint-plugin-n8n-nodes-base` on the codebase, using the ESLint +# config `eslintrc.lc.js` (lc -> lint codebase), which references `.eslintplugin.js` +# (all rules) via `eslint-plugin-local`. The flag `--no-eslintrc` prevents ESLint from +# finding and using the sibling `.eslintrc.js` that is intended for this plugin. echo 'Step 3: Linting codebase...' @@ -68,6 +67,5 @@ if [[ $? == 2 ]] ; then fi echo '✅ Success: Linter successfully ran through codebase' -echo 'The goal was to ensure the linter does not crash during the run' echo 'You can disregard any actual lint errors or warnings from the run' exit 0