Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Convert to ESLint 9 flat config and move to pnpm, use .mjs and new jest types #2548

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 0 additions & 16 deletions .eslintignore

This file was deleted.

14 changes: 0 additions & 14 deletions .eslintrc

This file was deleted.

12 changes: 9 additions & 3 deletions .github/workflows/action-format.yml
Original file line number Diff line number Diff line change
Expand Up @@ -60,12 +60,18 @@ jobs:
git clone $HEAD_REPO .
git checkout -b "$HEAD_REF" "origin/$HEAD_REF"

- name: Use Node.js LTS (18.x)
- name: Enable corepack to fix https://github.com/actions/setup-node/pull/901
run: corepack enable pnpm

- name: Use Node.js LTS (20.x)
uses: actions/setup-node@1e60f620b9541d16bece96c5465dc8ee9832be0b
with:
node-version: '18'
node-version: 20.x
cache: 'pnpm'

- name: Install project development dependencies
run: npm install --no-save
run: corepack pnpm install --no-save

- name: 'Format code'
run: ./bin/format.sh

Expand Down
6 changes: 4 additions & 2 deletions .github/workflows/action-sync.yml
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,11 @@ jobs:
git checkout -b "$HEAD_REF" "origin/$HEAD_REF"

- name: 'Install dependencies'
run: yarn install
run: |
corepack enable pnpm
corepack pnpm install
- name: 'Sync exercises'
run: npx babel-node scripts/sync
run: corepack pnpm node scripts/sync.mjs

- name: 'Commit changes'
run: |
Expand Down
22 changes: 15 additions & 7 deletions .github/workflows/ci.js.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,33 +13,41 @@ jobs:

steps:
- uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332
- name: Use Node.js LTS (18.x)
- name: Enable corepack to fix https://github.com/actions/setup-node/pull/901
run: corepack enable pnpm

- name: Use Node.js LTS (20.x)
uses: actions/setup-node@1e60f620b9541d16bece96c5465dc8ee9832be0b
with:
node-version: '18'
node-version: 20.x
cache: 'pnpm'

- name: Install project dependencies
run: npm ci
run: corepack pnpm install --frozen-lockfile

- name: Run exercism/javascript ci precheck (checks config, lint code, and runs tests) for all exercises
run: npx babel-node scripts/ci-check
run: corepack pnpm node scripts/ci-check.mjs

ci:
runs-on: ubuntu-22.04

strategy:
matrix:
node-version: ['18', '20']
node-version: [20.x, 22.x]

steps:
- uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332
- name: Enable corepack to fix https://github.com/actions/setup-node/pull/901
run: corepack enable pnpm

- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@1e60f620b9541d16bece96c5465dc8ee9832be0b
with:
node-version: ${{ matrix.node-version }}
cache: 'pnpm'

- name: Install project dependencies
run: npm ci
run: corepack pnpm install --frozen-lockfile

- name: Run exercism/javascript ci (checks config, lint code, and runs tests) for all exercises
run: npx babel-node scripts/ci
run: corepack pnpm node scripts/ci.mjs
52 changes: 37 additions & 15 deletions .github/workflows/pr.ci.js.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,44 +12,66 @@ jobs:
steps:
- name: Checkout PR
uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332
with:
fetch-depth: ${{ github.event_name == 'pull_request' && 2 || 0 }}

- name: Get changed files
id: changed-files
run: |
if ${{ github.event_name == 'pull_request' }}; then
echo "changed_files=$(git diff --name-only --diff-filter=ACM -r HEAD^1 HEAD | xargs)" >> $GITHUB_OUTPUT
else
echo "changed_files=$(git diff --name-only --diff-filter=ACM ${{ github.event.before }} ${{ github.event.after }} | xargs)" >> $GITHUB_OUTPUT
fi

- name: Use Node.js LTS (18.x)
- name: Enable corepack to fix https://github.com/actions/setup-node/pull/901
run: corepack enable pnpm

- name: Use Node.js LTS (20.x)
uses: actions/setup-node@1e60f620b9541d16bece96c5465dc8ee9832be0b
with:
node-version: '18'
node-version: 20.x
cache: 'pnpm'

- name: Install project dependencies
run: npm ci
run: corepack pnpm install --frozen-lockfile

- name: Run exercism/javascript ci precheck (stub files, config integrity) for changed exercises
run: |
PULL_REQUEST_URL=$(jq -r ".pull_request.url" "$GITHUB_EVENT_PATH")
curl --url $"${PULL_REQUEST_URL}/files?per_page=100" --header 'authorization: Bearer ${{ secrets.GITHUB_TOKEN }}' | \
jq -c '.[] | select(.status == "added" or .status == "modified") | select(.filename | match("\\.(js|jsx|md|json)$")) | .filename' | \
xargs -r npx babel-node scripts/pr-check
run: corepack pnpm node scripts/pr.mjs ${{ steps.changed-files.outputs.changed_files }}

ci:
runs-on: ubuntu-22.04

strategy:
matrix:
node-version: ['18', '20']
node-version: [20.x, 22.x]

steps:
- name: Checkout PR
uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332
with:
fetch-depth: ${{ github.event_name == 'pull_request' && 2 || 0 }}

- name: Get changed files
id: changed-files
run: |
if ${{ github.event_name == 'pull_request' }}; then
echo "changed_files=$(git diff --name-only --diff-filter=ACM -r HEAD^1 HEAD | xargs)" >> $GITHUB_OUTPUT
else
echo "changed_files=$(git diff --name-only --diff-filter=ACM ${{ github.event.before }} ${{ github.event.after }} | xargs)" >> $GITHUB_OUTPUT
fi

- name: Enable corepack to fix https://github.com/actions/setup-node/pull/901
run: corepack enable pnpm

- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@1e60f620b9541d16bece96c5465dc8ee9832be0b
with:
node-version: ${{ matrix.node-version }}
cache: 'pnpm'

- name: Install project dependencies
run: npm ci
run: corepack pnpm install --frozen-lockfile

- name: Run exercism/javascript ci (runs tests) for changed/added exercises
run: |
PULL_REQUEST_URL=$(jq -r ".pull_request.url" "$GITHUB_EVENT_PATH")
curl --url $"${PULL_REQUEST_URL}/files?per_page=100" --header 'authorization: Bearer ${{ secrets.GITHUB_TOKEN }}' | \
jq -c '.[] | select(.status == "added" or .status == "modified") | select(.filename | match("\\.(js|jsx|md|json)$")) | .filename' | \
xargs -r npx babel-node scripts/pr
run: corepack pnpm node scripts/pr.mjs ${{ steps.changed-files.outputs.changed_files }}
7 changes: 1 addition & 6 deletions .github/workflows/verify-code-formatting.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,6 @@ jobs:
steps:
- name: 'Checkout code'
uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332
- name: Use Node.js LTS (18.x)
uses: actions/setup-node@1e60f620b9541d16bece96c5465dc8ee9832be0b
with:
node-version: '18'
- name: Install project development dependencies
run: npm i

- name: 'Verify formatting of all files'
run: ./bin/check-formatting.sh
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/node_modules
/bin/configlet
/bin/configlet.exe
/pnpm-lock.yaml
/package-lock.json
/yarn.lock
3 changes: 2 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,6 @@
// because of how whitespace is (not) rendered.
65
]
}
},
"cSpell.words": ["xtest"]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is this intended for here or was it an artifact?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Eh. Yeah i run spellcheck locally but didn't mean to commit this I think.

}
14 changes: 7 additions & 7 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ It's not uncommon that people discover incorrect implementations of certain test

We welcome contributions of all sorts and sizes, from reporting issues to submitting patches, as well as joining the current [discussions 💬][issue-discussion].

> [!WARNING]
> [!WARNING]
> This guide is slightly outdated and doesn't hold the V3 changes yet.

---
Expand Down Expand Up @@ -168,7 +168,7 @@ You may improve these files by making the required changes and opening a new Pul
## Tools

You'll need LTS or higher Node.js to contribute to the _code_ in this repository.
Run `npm install` in the root to be able to run the scripts as listed below.
Run `corepack pnpm install` in the root to be able to run the scripts as listed below.
We use the following dependencies:

- `shelljs` to provide shell interface to scripts
Expand All @@ -177,9 +177,9 @@ We use the following dependencies:
- `babel` to transpile everything so it works _regardless of your version of Node.js_.

We also use `prettier` to format the files.
**Prettier is installed when using `npm install`**.
You may use `npx babel-node scripts/format` to run prettier.
If you want to auto-format using your editor, install via `npm install` and it will Just Work™.
**Prettier is installed when using `corepack pnpm install`**.
You may use `corepack pnpm node scripts/format.mjs` to run prettier.
If you want to auto-format using your editor, install via `corepack pnpm install` and it will Just Work™.

### Fetch configlet

Expand Down Expand Up @@ -210,7 +210,7 @@ It then interactively gives the maintainer the option to include or exclude test

We have various `scripts` to aid with maintaining and contributing to this repository.

> [!IMPORTANT]
> [!IMPORTANT]
> If you encounter the following error:
>
> ```text
Expand Down Expand Up @@ -243,7 +243,7 @@ We have various `scripts` to aid with maintaining and contributing to this repos
```

Use this action to format all the files using the correct version of prettier.
If you want your editor to do this automatically, install the project development dependencies (`npm i`), which includes `prettier`.
If you want your editor to do this automatically, install the project development dependencies (`corepack pnpm install`), which includes `prettier`.
The correct version will be extracted when running `.github/workflows/verify-code-formatting.yml`.

#### `lint`
Expand Down
2 changes: 1 addition & 1 deletion babel.config.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module.exports = {
presets: ['@exercism/babel-preset-javascript'],
presets: [['@exercism/babel-preset-javascript', { corejs: '3.38' }]],
plugins: [],
};
45 changes: 34 additions & 11 deletions bin/check-formatting.sh
Original file line number Diff line number Diff line change
@@ -1,27 +1,50 @@
#!/bin/bash
#!/usr/bin/env bash

if [ -z "$EXERCISM_PRETTIER_VERSION" ]; then
echo "Pulling prettier version from package.json"
EXERCISM_PRETTIER_VERSION=$(npm list prettier | grep -Po '.*\sprettier@\K.*')
set -uo pipefail

if [ -z "${EXERCISM_PRETTIER_VERSION:-}" ]; then
echo "[format] pulling prettier version from pnpm list using sed"
EXERCISM_PRETTIER_VERSION="$(corepack pnpm list prettier --parseable | sed -n -e '1,$s/^.*prettier@//' -e 's/\\node_modules\\prettier//p')"
echo "[format] expected version is now ${EXERCISM_PRETTIER_VERSION:-}"
fi

if [ -z "${EXERCISM_PRETTIER_VERSION:-}" ]; then
echo "[format] pulling prettier version via pnpm-lock.yaml using grep"
EXERCISM_PRETTIER_VERSION="$(cat pnpm-lock.yaml | grep -Po ' prettier@\K[^:]+')"
echo "[format] expected version is now ${EXERCISM_PRETTIER_VERSION:-}"
fi

if [ -z "$EXERCISM_PRETTIER_VERSION" ]; then
if [ -z "${EXERCISM_PRETTIER_VERSION:-}" ]; then
echo "Version could not be pulled using sed or grep" >&2
echo ""
echo "---------------------------------------------------"
echo "This script requires the EXERCISM_PRETTIER_VERSION variable to work."
echo "Please see https://exercism.org/docs/building/markdown/style-guide for guidance."
echo "---------------------------------------------------"
echo "This is what npm list reports:"
echo "$(npm list prettier)"
echo "$(corepack pnpm -v)"
echo ""
echo "This is what corepack pnpm list reports:"
echo "$ corepack pnpm list prettier --parseable"
echo "$(corepack pnpm list prettier --parseable)"
echo ""
echo "And corepack pnpm info reports the following:"
echo "$ corepack pnpm info prettier"
echo "$(corepack pnpm info prettier)"
echo ""
echo "This is the version that can be extracted using sed:"
echo "$ corepack pnpm list prettier --parseable | sed -n -e '1,\$s/^.*prettier@//' -e 's/\\node_modules\\prettier//p'"
echo "└─ $(corepack pnpm list prettier --parseable | sed -n -e '1,$s/^.*prettier@//' -e 's/\\node_modules\\prettier//p')"
echo ""
echo "This is the version that can be extracted:"
echo "$(npm list prettier | grep -Po '.*\sprettier@\K.*')"
echo "This is the version that can be extracted using grep:"
echo "$ cat pnpm-lock.yaml | grep -Po ' prettier@\K[^:]+'"
echo "└─ $(cat pnpm-lock.yaml | grep -Po ' prettier@\K[^:]+')"
echo ""
echo "These files are found in the repo root:"
echo "$(ls -p | grep -v /)"
echo "---------------------------------------------------"
exit 1
else
echo "Running format with prettier@$EXERCISM_PRETTIER_VERSION"
echo "[format] running with prettier@$EXERCISM_PRETTIER_VERSION"
fi

npx "prettier@$EXERCISM_PRETTIER_VERSION" --check "*/**/*.{js,jsx,ts,tsx,css,sass,scss,html,json,md,yml}"
corepack pnpm dlx "prettier@$EXERCISM_PRETTIER_VERSION" --check "**/*.{js,jsx,cjs,mjs,ts,tsx,css,sass,scss,html,json,md,yml}"
Loading