Skip to content
Merged
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
1 change: 1 addition & 0 deletions .github/workflows/CODEOWNERS
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* @menglinmaker
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,13 @@
 

## Features:
- [x] Track compat issues across multiple imports and packages
- [x] Configure range of providers according to [runtime-compat](https://runtime-compat.unjs.io/)
- [x] Detect incompatible class instantiations
- [x] Detect incompatible class property access
- [ ] Disable rules
- [ ] Detect incompatible event listeners
- [ ] Detect compat issues hidden within packages

**Note: Project is in alpha. API may change**

Expand All @@ -42,7 +44,6 @@ export default [runtimeCompat.configs.custom(['node', 'bun', 'deno'])];
```

## Limitations:
- Does not [lint across multiple files](https://github.com/eslint/eslint/discussions/15388#discussioncomment-1747795) since ESLint only analyses each file in isolation by building an AST for each file.
- Cannot detect when globals are overridden

## Attibution
Expand Down
5 changes: 5 additions & 0 deletions e2e/dummy-dependency/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export const _Cache = Cache

export const createCacheInternally = () => {
return { cache: new Cache() }
}
13 changes: 13 additions & 0 deletions e2e/dummy-dependency/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"name": "@eslint-plugin-runtime-compat/dummy-dependency",
"version": "0.0.0",
"private": "true",
"main": "./dist/index.js",
"types": "./dist/index.d.ts",
"files": ["dist"],
"scripts": {
"format": "biome check --write --verbose",
"build": "tsup index.ts --format cjs,esm --dts --clean --sourcemap",
"clean": "rm -rf node_modules"
}
}
17 changes: 17 additions & 0 deletions e2e/import-package-compat/eslint.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import runtimeCompat from '@menglinmaker/eslint-plugin-runtime-compat'
import tseslint from 'typescript-eslint'

export default [
...tseslint.configs.recommended,
runtimeCompat.configs.recommended,
{
languageOptions: {
parserOptions: {
projectService: {
allowDefaultProject: ['*.js'],
},
tsconfigRootDir: import.meta.dirname,
},
},
},
]
16 changes: 16 additions & 0 deletions e2e/import-package-compat/index.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { execSync } from 'node:child_process'
import { describe, expect, it } from 'vitest'

describe('Multi file import linting test', () => {
it('should detect [Cache] incompatability', () => {
try {
execSync('pnpm test:lint', {
cwd: import.meta.dirname,
encoding: 'utf8',
})
} catch (e) {
// @ts-expect-error error is not well defined
expect(e.stdout).toContain('class - [Cache] - Unsupported standard API')
}
})
})
8 changes: 8 additions & 0 deletions e2e/import-package-compat/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { _Cache } from '@eslint-plugin-runtime-compat/dummy-dependency'

Promise.all([
async () => {
// Expect type of: Cache
new _Cache()
},
])
19 changes: 19 additions & 0 deletions e2e/import-package-compat/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"private": true,
"type": "module",
"scripts": {
"format": "biome check --write --verbose",
"test": "vitest",
"test:dev": "vitest --watch",
"test:lint": "eslint",
"clean": "rm -rf node_modules"
},
"dependencies": {
"@eslint-plugin-runtime-compat/dummy-dependency": "workspace:*"
},
"devDependencies": {
"eslint": "9.15.0",
"typescript-eslint": "8.15.0",
"@menglinmaker/eslint-plugin-runtime-compat": "workspace:*"
}
}
8 changes: 8 additions & 0 deletions e2e/import-package-compat/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"extends": "../../tsconfig.json",
"compilerOptions": {
"module": "ESNext",
"moduleResolution": "bundler"
},
"include": ["*.ts"]
}
17 changes: 17 additions & 0 deletions e2e/internal-package-compat/eslint.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import runtimeCompat from '@menglinmaker/eslint-plugin-runtime-compat'
import tseslint from 'typescript-eslint'

export default [
...tseslint.configs.recommended,
runtimeCompat.configs.recommended,
{
languageOptions: {
parserOptions: {
projectService: {
allowDefaultProject: ['*.js'],
},
tsconfigRootDir: import.meta.dirname,
},
},
},
]
16 changes: 16 additions & 0 deletions e2e/internal-package-compat/index.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { execSync } from 'node:child_process'
import { describe, expect, it } from 'vitest'

describe.skip('Package internal compat linting test', () => {
it('should detect [Cache] incompatability', () => {
try {
execSync('pnpm test:lint', {
cwd: import.meta.dirname,
encoding: 'utf8',
})
} catch (e) {
// @ts-expect-error error is not well defined
expect(e.stdout).toContain('class - [Cache] - Unsupported standard API')
}
})
})
8 changes: 8 additions & 0 deletions e2e/internal-package-compat/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { createCacheInternally } from '@eslint-plugin-runtime-compat/dummy-dependency'

Promise.all([
async () => {
// Usupported api called within package: Cache
createCacheInternally()
},
])
19 changes: 19 additions & 0 deletions e2e/internal-package-compat/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"private": true,
"type": "module",
"scripts": {
"format": "biome check --write --verbose",
"test": "vitest",
"test:dev": "vitest --watch",
"test:lint": "eslint",
"clean": "rm -rf node_modules"
},
"dependencies": {
"@eslint-plugin-runtime-compat/dummy-dependency": "workspace:*"
},
"devDependencies": {
"eslint": "9.15.0",
"typescript-eslint": "8.15.0",
"@menglinmaker/eslint-plugin-runtime-compat": "workspace:*"
}
}
8 changes: 8 additions & 0 deletions e2e/internal-package-compat/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"extends": "../../tsconfig.json",
"compilerOptions": {
"module": "ESNext",
"moduleResolution": "bundler"
},
"include": ["*.ts"]
}
1 change: 1 addition & 0 deletions packages/data/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
"format": "biome check --write --verbose",
"lint": "tsc --noEmit --incremental",
"test": "vitest",
"test:dev": "vitest --watch",
"build": "pnpm install runtime-compat-data@latest && ts-node preprocess.ts && tsup src/index.ts --format cjs,esm --dts --clean --sourcemap",
"clean": "rm -rf node_modules"
},
Expand Down
2 changes: 1 addition & 1 deletion packages/data/src/runtime.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ const getUnsupportedRuntimes = (
* @param unsupported - Unsupported runtimes.
* @returns Error message.
*/
export const errorMessage = (
const errorMessage = (
keys: string[],
url: string,
status: StatusBlock,
Expand Down
Loading