Skip to content

Commit

Permalink
Refactor lint-codebase command (ivov#151)
Browse files Browse the repository at this point in the history
  • Loading branch information
ivov authored Feb 12, 2023
1 parent c6dceda commit 5e5145a
Show file tree
Hide file tree
Showing 10 changed files with 76 additions and 44 deletions.
26 changes: 0 additions & 26 deletions .github/workflows/checks.yml

This file was deleted.

26 changes: 26 additions & 0 deletions .github/workflows/on-push.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
name: On push

on: push

jobs:
run-checks:
runs-on: ubuntu-latest

steps:
- name: Check out commit
uses: actions/checkout@v3

- name: Set up Node.js
uses: actions/setup-node@v3
with:
node-version: "16"
cache: "npm"

- name: Run plugin checks
run: |
npm ci
npm run lint-plugin
npm test
npm run typecheck
env:
CI: true
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
name: Publish to npm
name: On release

on:
release:
types: [created]

jobs:
build:
publish-to-npm:
runs-on: ubuntu-latest

steps:
Expand All @@ -18,11 +18,10 @@ jobs:
node-version: 16
registry-url: https://registry.npmjs.org

- name: Check codebase lint, publish
run: |
npm ci
npm run build
npm run lint-codebase
npm publish
- name: Lint codebase
run: npm run lint-codebase

- name: Publish to npm
run: npm publish
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@ node_modules
.DS_Store
.todo
scripts/downloads/*
.eslintplugin.js
.eslintplugin.js
lint-run.log
2 changes: 1 addition & 1 deletion jest.config.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
module.exports = {
testEnvironment: "node",
transform: { "^.+\\.ts$": "esbuild-jest" },
testPathIgnorePatterns: ["/dist/", "/node_modules/"],
testPathIgnorePatterns: ["/dist/", "/node_modules/", "/scripts/downloads"],
};
4 changes: 3 additions & 1 deletion lint-codebase-config.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
/**
* Config for the `lint-codebase` command.
* Base config for the `lint-codebase` command.
*
* Implicitly references rules in `.eslintplugin.js` via `eslint-plugin-local`.
*
* @type {import('@types/eslint').ESLint.ConfigData}
*/
Expand Down
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,13 @@
],
"scripts": {
"build": "node scripts/build.mjs",
"typecheck": "tsc --noEmit",
"doc": "npm run build; node scripts/make-docs.mjs",
"format": "prettier lib scripts tests --write",
"lint-plugin": "eslint lib tests --ext .ts",
"lint-codebase": "node scripts/get-codebase.mjs && node scripts/make-lint-codebase-config.mjs && npm install eslint-plugin-n8n-nodes-base && chmod +x ./scripts/lint-codebase.sh && ./scripts/lint-codebase.sh",
"lint-codebase": "chmod +x scripts/lint-codebase.sh && scripts/lint-codebase.sh",
"test": "jest",
"test:watch": "jest --watch",
"prepublishOnly": "npm run lint-plugin && npm run test && npm run build && npm run lint-codebase"
"test:watch": "jest --watch"
},
"dependencies": {
"@typescript-eslint/utils": "^5.17.0",
Expand Down
7 changes: 6 additions & 1 deletion scripts/get-codebase.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,12 @@ async function getFilenames() {
});

return files.filter(
(file) => file.path.endsWith(".ts") && !file.path.endsWith(".d.ts")
(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")
);
}

Expand Down
28 changes: 25 additions & 3 deletions scripts/lint-codebase.sh
Original file line number Diff line number Diff line change
@@ -1,12 +1,34 @@
#!/bin/bash

echo 'Linting codebase...'
echo 'Step 1: Setting up linter...'

./node_modules/eslint/bin/eslint.js --no-eslintrc --config lint-codebase-config.js --ext .ts scripts/downloads
npm ci
npm run build
node scripts/make-lint-codebase-config.mjs

# `make-lint-codebase-config.mjs` creates `.eslintplugin.js`, based on
# `dist/index.js` (same as `index.js`) but with the rules dir path adjusted
# relative to the root. `.eslintplugin.js` contains all the linter's rules
# and is referenced implicitly by `lint-codebase-config.js``

echo 'Step 2: Fetching codebase...'

node scripts/get-codebase.mjs

echo 'Step 3: Linting codebase...'

./node_modules/eslint/bin/eslint.js \
--no-eslintrc \
--config lint-codebase-config.js \
--ext .ts \
scripts/downloads \
> lint-run.log

if [[ $? == 2 ]] ; then
echo "Linter crashed while linting codebase"
echo 'Linter crashed while running through codebase'
exit 1
fi

echo 'Linter successfully ran through codebase'

exit 0
3 changes: 3 additions & 0 deletions scripts/make-lint-codebase-config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,7 @@ const newContent = oldContent.replace(
/__dirname, "lib", "rules"/,
'__dirname, "dist", "lib", "rules"' // adjust reference based on new (root) location
);

new ShellString(newContent).to(".eslintplugin.js");

console.log("Created .eslintplugin.js");

0 comments on commit 5e5145a

Please sign in to comment.