From 66609d235eed2732e07398cb2bb73ed9d93aeb7a Mon Sep 17 00:00:00 2001 From: undergoundwires Date: Fri, 24 Jan 2025 02:54:37 +0100 Subject: [PATCH] Use ESLint standard + Prettier, drop Airbnb Airbnb's ESLint config does not support v9 and is less maintained (airbnb/javascript#2961), creating a maintenance liability. Switch to ESLint standard for code quality/bug detection and Prettier for code styling. This separation of concerns improves maintainability. Changes: - Remove Airbnb dependency - Upgrade ESLint to v9 - Apply new linting rules - Standardize lint commands with 'lint:' prefix - Add external URL linting and Prettier to GitHub workflow - Recommend Prettier VSCode extensio --- .eslintrc.yml | 15 - .github/workflows/bump-and-release.yaml | 3 +- .github/workflows/publish.yaml | 22 +- .github/workflows/quality-checks.yaml | 21 +- .gitignore | 4 + .prettierignore | 4 + .vscode/extensions.json | 3 + README.md | 96 +-- compile.js | 48 +- eslint.config.mjs | 8 + img/gitops.drawio.png | Bin 851219 -> 771428 bytes package-lock.json | 788 ++++++++++-------------- package.json | 18 +- prettier.config.mjs | 10 + src/ez-consent.js | 65 +- src/themes/box-bottom-left.css | 73 ++- src/themes/subtle-bottom-right.css | 79 ++- 17 files changed, 595 insertions(+), 662 deletions(-) delete mode 100644 .eslintrc.yml create mode 100644 .prettierignore create mode 100644 .vscode/extensions.json create mode 100644 eslint.config.mjs create mode 100644 prettier.config.mjs diff --git a/.eslintrc.yml b/.eslintrc.yml deleted file mode 100644 index 058327c..0000000 --- a/.eslintrc.yml +++ /dev/null @@ -1,15 +0,0 @@ -env: - browser: true - commonjs: true - es6: true -extends: airbnb-base -globals: - Atomics: readonly - SharedArrayBuffer: readonly -parserOptions: - ecmaVersion: 2018 -rules: { - "no-use-before-define": 0 -} -ignorePatterns: - - 'dist/' diff --git a/.github/workflows/bump-and-release.yaml b/.github/workflows/bump-and-release.yaml index 26e0b83..86c69bc 100644 --- a/.github/workflows/bump-and-release.yaml +++ b/.github/workflows/bump-and-release.yaml @@ -10,8 +10,7 @@ jobs: if: github.event.base_ref == 'refs/heads/master' runs-on: ubuntu-latest steps: - - - uses: undergroundwires/bump-everywhere@master + - uses: undergroundwires/bump-everywhere@master with: user: undergroundwires-bot release-token: ${{secrets.BUMP_GITHUB_PAT}} # Does not trigger release pipeline if we use default token: https://github.community/t5/GitHub-Actions/Github-Action-trigger-on-release-not-working-if-releases-was/td-p/34559 diff --git a/.github/workflows/publish.yaml b/.github/workflows/publish.yaml index 7354b2d..5ca363e 100644 --- a/.github/workflows/publish.yaml +++ b/.github/workflows/publish.yaml @@ -5,7 +5,6 @@ on: types: [created] # It will be triggered when a NON-draft release is created and published. jobs: - distribute: runs-on: ubuntu-latest steps: @@ -49,24 +48,20 @@ jobs: needs: distribute runs-on: ubuntu-latest steps: - - - uses: actions/checkout@v4 + - uses: actions/checkout@v4 with: ref: master # Otherwise it defaults to the version tag missing bump commit fetch-depth: 0 # Fetch all history - - - name: Checkout to bump commit + - name: Checkout to bump commit run: git checkout "$(git rev-list "${{ github.event.release.tag_name }}"..master | tail -1)" - - - name: Create dist folder + - name: Create dist folder run: | mkdir "/tmp/package-dist" cp -r . "/tmp/package-dist" rm -rf "/tmp/package-dist/.git" rm -rf "/tmp/package-dist/.github" rm -rf "/tmp/package-dist/node_modules" - - - name: Upload dist folder + - name: Upload dist folder uses: actions/upload-artifact@v4 with: name: npm-artifact @@ -76,19 +71,16 @@ jobs: needs: create-package runs-on: ubuntu-latest steps: - - - uses: actions/setup-node@v4 + - uses: actions/setup-node@v4 with: node-version: 22.x registry-url: https://registry.npmjs.org/ - - - name: Download npm artifact + - name: Download npm artifact uses: actions/download-artifact@v4 with: name: npm-artifact path: npm-dist - - - name: Publish npm package + - name: Publish npm package run: cd npm-dist && npm publish env: NODE_AUTH_TOKEN: ${{secrets.NPM_TOKEN}} diff --git a/.github/workflows/quality-checks.yaml b/.github/workflows/quality-checks.yaml index 4b8fd7e..fe45442 100644 --- a/.github/workflows/quality-checks.yaml +++ b/.github/workflows/quality-checks.yaml @@ -1,26 +1,29 @@ name: Quality checks - on: push - jobs: lint: runs-on: ubuntu-latest strategy: matrix: lint-command: - - npm run lint-js - - npm run lint-css - - npm run lint-md-urls-relative - - npm run lint-md - - npm run lint-md-consistency + - 'lint:eslint' + - 'lint:prettier' + - 'lint:css' + - 'lint:md' + - 'lint:md:urls:relative' + - 'lint:md:urls:external' + - 'lint:md:consistency' steps: - name: Checkout uses: actions/checkout@v4 + - name: Setup node uses: actions/setup-node@v4 with: node-version: '22.x' + - name: Install dependencies run: npm ci - - name: Ensure consistency - run: ${{ matrix.lint-command }} + + - name: Run ${{ matrix.lint-command }} + run: npm run ${{ matrix.lint-command }} diff --git a/.gitignore b/.gitignore index 746e81f..404c110 100644 --- a/.gitignore +++ b/.gitignore @@ -7,3 +7,7 @@ dist/ # draw.io back-ups *.bkp *.dtmp + +# Visual Studio Code +.vscode/**/* +!.vscode/extensions.json diff --git a/.prettierignore b/.prettierignore new file mode 100644 index 0000000..8193c0a --- /dev/null +++ b/.prettierignore @@ -0,0 +1,4 @@ +# https://prettier.io/docs/en/ignore + +dist +CHANGELOG.md \ No newline at end of file diff --git a/.vscode/extensions.json b/.vscode/extensions.json new file mode 100644 index 0000000..c83e263 --- /dev/null +++ b/.vscode/extensions.json @@ -0,0 +1,3 @@ +{ + "recommendations": ["esbenp.prettier-vscode"] +} diff --git a/README.md b/README.md index b086a25..6e66e77 100644 --- a/README.md +++ b/README.md @@ -10,6 +10,7 @@ [![](https://github.com/undergroundwires/ez-consent/workflows/Bump%20&%20release/badge.svg)](./.github/workflows/bump-and-release.yaml) [![](https://github.com/undergroundwires/ez-consent/workflows/Quality%20checks/badge.svg)](./.github/workflows/quality-checks.yaml) [![Auto-versioned by bump-everywhere](https://github.com/undergroundwires/bump-everywhere/blob/master/badge.svg?raw=true)](https://github.com/undergroundwires/bump-everywhere) + - Vanilla JavaScript only ✔️ @@ -31,11 +32,11 @@ The simplest way to get started is to add it to your page: ```html ``` @@ -90,10 +91,10 @@ Or you can import `ez_consent` as a module: Or import it via `webpack`, `gulp`, `rollup` etc.: ```js -import { ez_consent } from "./node_modules/ez-consent/src/ez-consent" +import { ez_consent } from './node_modules/ez-consent/src/ez-consent'; ``` -*[top↑](#ez-consent)* +_[top↑](#ez-consent)_ #### 2. Initialize @@ -103,11 +104,11 @@ experience by optimizing script loading. This can help your pages rank better in ```html