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 446bc8d..79aaeae 100755 --- a/scripts/lint-codebase.sh +++ b/scripts/lint-codebase.sh @@ -1,35 +1,42 @@ #!/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 +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...' +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,13 +44,11 @@ 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...' @@ -56,10 +61,11 @@ 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 'You can disregard any actual lint errors or warnings from the run' exit 0 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");