1- import type { OptionsIsInEditor , TypedFlatConfigItem } from '../types'
1+ import type { OptionsPnpm , TypedFlatConfigItem } from '../types'
2+ import fs from 'node:fs/promises'
3+ import { findUp } from 'find-up-simple'
24
35import { interopDefault } from '../utils'
46
7+ async function detectCatalogUsage ( ) : Promise < boolean > {
8+ const workspaceFile = await findUp ( 'pnpm-workspace.yaml' )
9+ if ( ! workspaceFile )
10+ return false
11+
12+ const yaml = await fs . readFile ( workspaceFile , 'utf-8' )
13+ return yaml . includes ( 'catalog:' ) || yaml . includes ( 'catalogs:' )
14+ }
15+
516export async function pnpm (
6- options : OptionsIsInEditor ,
17+ options : OptionsPnpm ,
718) : Promise < TypedFlatConfigItem [ ] > {
819 const [
920 pluginPnpm ,
@@ -15,6 +26,11 @@ export async function pnpm(
1526 interopDefault ( import ( 'jsonc-eslint-parser' ) ) ,
1627 ] )
1728
29+ const {
30+ catalogs = detectCatalogUsage ( ) ,
31+ isInEditor = false ,
32+ } = options
33+
1834 return [
1935 {
2036 files : [
@@ -29,17 +45,21 @@ export async function pnpm(
2945 pnpm : pluginPnpm ,
3046 } ,
3147 rules : {
32- 'pnpm/json-enforce-catalog' : [
33- 'error' ,
34- { autofix : ! options . isInEditor } ,
35- ] ,
48+ ...( catalogs
49+ ? {
50+ 'pnpm/json-enforce-catalog' : [
51+ 'error' ,
52+ { autofix : ! isInEditor } ,
53+ ] ,
54+ }
55+ : { } ) ,
3656 'pnpm/json-prefer-workspace-settings' : [
3757 'error' ,
38- { autofix : ! options . isInEditor } ,
58+ { autofix : ! isInEditor } ,
3959 ] ,
4060 'pnpm/json-valid-catalog' : [
4161 'error' ,
42- { autofix : ! options . isInEditor } ,
62+ { autofix : ! isInEditor } ,
4363 ] ,
4464 } ,
4565 } ,
0 commit comments