https://github.com/3ru/eslint-baseline-compat-contrast
Type‑aware Baseline linting demo
https://github.com/3ru/eslint-baseline-compat-contrast
Last synced: 5 days ago
JSON representation
Type‑aware Baseline linting demo
- Host: GitHub
- URL: https://github.com/3ru/eslint-baseline-compat-contrast
- Owner: 3ru
- Created: 2025-09-20T11:21:47.000Z (11 months ago)
- Default Branch: main
- Last Pushed: 2025-09-20T11:24:31.000Z (11 months ago)
- Last Synced: 2025-10-24T15:56:13.421Z (10 months ago)
- Language: JavaScript
- Homepage:
- Size: 15.6 KB
- Stars: 0
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Baseline vs compat — Type-aware contrast
This repo now contains two contrast scenarios that highlight where `eslint-plugin-baseline-js` outperforms the compat plugins:
1. **Typed Array by copy (`src/sort.ts`)**: `arr.toSorted()` where `arr: number[]`.
- `eslint-plugin-baseline-js` uses TypeScript types and flags Array by copy when Baseline availability is pinned to 2022.
- `eslint-plugin-compat` can detect `[].toSorted()` (array literal) but generally can’t infer that an arbitrary identifier `arr` is an Array.
2. **Pure syntax features (`src/syntax.ts`)**: optional catch binding and logical assignment.
- Baseline delegates to `eslint-plugin-es-x` rules (`no-optional-catch-binding`, `no-logical-assignment-operators`) and we intentionally tighten the Baseline for that one file to 2019 so these ES2020 features exceed policy.
- Neither compat plugin inspects syntax nodes (`CatchClause`, assignment operators, etc.), so these cases stay silent there.
## Install
```bash
npm i
```
## Run (baseline, type‑aware)
```bash
npm run lint:baseline
```
Expected: errors for `src/sort.ts` (Array by copy exceeds Baseline 2022) **and** `src/syntax.ts` (ES2020 syntax exceeds the stricter per-file Baseline 2019).
Example output:
```sh
eslint-baseline-compat-contrast/src/sort.ts
2:5 error Feature 'Array by copy' (array-by-copy) became Baseline in 2023 and exceeds 2022 baseline-js/use-baseline
eslint-baseline-compat-contrast/src/syntax.ts
4:5 error Feature 'Optional catch binding' (optional-catch-binding) became Baseline in 2020 and exceeds 2019 baseline-js/use-baseline
13:8 error Feature 'Logical assignments' (logical-assignments) became Baseline in 2020 and exceeds 2019 baseline-js/use-baseline
✖ 3 problems (3 errors, 0 warnings)
```
If you uncomment the literal case (`[3, 1, 2].toSorted()`), it will also be flagged under the same Baseline policy.
## Run (compat)
```bash
npm run lint:compat
```
Expected: no error for `arr.toSorted()` (identifier receiver). If you uncomment the literal case `[3, 1, 2].toSorted()`, `eslint-plugin-compat` flags that line only (the identifier case remains unflagged).
- `src/syntax.ts` also passes here because `eslint-plugin-compat` does not hook into syntax delegates such as `es-x/no-optional-catch-binding`.
## Run (tscompat)
```bash
npm run lint:tscompat
```
Expected: `@koddsson/eslint-plugin-tscompat` flags `arr.toSorted()` as long as your `browserslist` targets include a browser version that predates Array by copy (for example Chrome 105 with the defaults in this repo). There is still **no report for `src/syntax.ts`**, because the published rule never inspects syntax nodes beyond member access / `new Foo()` / global `Foo()` calls.
Notes after testing `tscompat` 0.2.0:
- It is TypeScript-aware and can catch typed receivers (e.g. `arr.toSorted()` in this sample), but it reports concrete browser versions (`Chrome 105`) instead of Baseline “widely/newly/year” buckets.
- Browsers to check must be configured manually via `browserslist` options; there is no Baseline threshold or “allow everything before 2023” concept.
- The published rule only inspects property/member access, `new Foo()` and global `Foo()` calls; syntax-only features (class features, optional catch binding, logical assignment, etc.) or anything delegated to existing OSS rules in `eslint-plugin-baseline-js` stay out of scope for `tscompat`.