@prefer-jsr/eslint-plugin-prefer-jsr
v0.3.4
Published
ESLint plugin that suggests using JSR packages over NPM when available
Maintainers
Readme
@prefer-jsr/eslint-plugin-prefer-jsr
An ESLint plugin that suggests using JSR packages over NPM when available.
Installation
pnpm i jsr:@prefer-jsr/eslint-plugin-prefer-jsryarn add jsr:@prefer-jsr/eslint-plugin-prefer-jsrnpx jsr add @prefer-jsr/eslint-plugin-prefer-jsrnpm install --save-dev @prefer-jsr/eslint-plugin-prefer-jsrWith new ESLint JSON language feature (recommended)
pnpm i jsr:@eslint/jsonyarn add jsr:@eslint/jsonnpx jsr add @eslint/jsonnpm install --save-dev @eslint/jsonWith the legacy JSON parser
pnpm add -D jsonc-eslint-parseryarn add -D jsonc-eslint-parsernpm install --save-dev jsonc-eslint-parserUsage
This plugin works with package.json files and supports both the new @eslint/json parser and the legacy jsonc-eslint-parser.
Recommended Config
One way to use this plugin is with the recommended config:
// eslint.config.js
import { defineConfig } from 'eslint/config';
import preferJsr from '@prefer-jsr/eslint-plugin-prefer-jsr';
import json from '@eslint/json';
export default defineConfig([
{
plugins: {
preferJsr,
json,
},
extends: ['prefer-jsr/recommended'],
},
]);The recommended config automatically:
- Applies to
**/package.jsonfiles - Enables the
@prefer-jsr/prefer-jsrrule witherrorseverity
Flat Config (ESLint 9+) with @eslint/json
For more control, you can configure the plugin manually:
// eslint.config.js
import preferJsr from '@prefer-jsr/eslint-plugin-prefer-jsr';
import json from '@eslint/json';
export default [
{
files: ['package.json'],
language: 'json/json',
plugins: {
'@prefer-jsr': preferJsr,
json,
},
rules: {
'@prefer-jsr/prefer-jsr': 'error',
},
},
];Flat Config (ESLint 9+) with jsonc-eslint-parser (legacy)
// eslint.config.js
import preferJsr from '@prefer-jsr/eslint-plugin-prefer-jsr';
import jsoncParser from 'jsonc-eslint-parser';
export default [
{
files: ['package.json'],
languageOptions: {
parser: jsoncParser,
},
plugins: {
'@prefer-jsr': preferJsr,
},
rules: {
'@prefer-jsr/prefer-jsr': 'error',
},
},
];Rules
prefer-jsr
This rule warns when a dependency in package.json has a JSR equivalent available.
example mappings:
zod→@zod/zod@eslint/markdown→@eslint/markdown
Configuration
The rule accepts an options object with the following properties:
ignore(array): List of package names to ignore
Examples
Basic usage:
{
rules: {
'@prefer-jsr/prefer-jsr': 'error',
},
}Ignoring specific packages:
{
rules: {
'@prefer-jsr/prefer-jsr': ['error', {
ignore: ['legacy-package', 'special-case']
}],
},
}Valid
{
"dependencies": {
"@zod/zod": "jsr:^4.1.12"
}
}Invalid
{
"dependencies": {
"zod": "^4.1.12"
}
}Auto-fix available: The rule can automatically replace NPM dependencies with their JSR equivalents.
Features
- 🔍 Detection: Identifies NPM dependencies that have JSR equivalents
- 🔧 Auto-fix: Automatically replaces NPM imports with JSR versions
- 📦 Package.json support: Works with all dependency types (
dependencies,devDependencies,peerDependencies,optionalDependencies) - 🎯 Modern: Uses
@eslint/jsonfor proper JSON language support
Dependencies
This plugin specifically supports JSR packages that have been identified as having NPM equivalents. The mapping is maintained in the plugin and can be extended over time.
Contributing
Building
Run nx build eslint-plugin to build the library.
Running unit tests
Run nx test eslint-plugin to execute the unit tests via Vitest.
