From 7454ebe227238f602468bbbd2166add47fb3da52 Mon Sep 17 00:00:00 2001 From: "jyc.dev" Date: Sat, 15 Mar 2025 13:01:30 +0100 Subject: [PATCH] Eslint pnpm (#933) * change setup * pnpm i * config * new pnpm * lock --- .changeset/fast-steaks-wait.md | 6 +++ eslint.config.js | 13 ++---- package.json | 9 +--- packages/eslint-config/eslint.config.js | 62 +++++++++++++++++-------- packages/eslint-config/package.json | 5 +- pnpm-lock.yaml | 42 ++++++++++++----- pnpm-workspace.yaml | 11 +++-- 7 files changed, 96 insertions(+), 52 deletions(-) create mode 100644 .changeset/fast-steaks-wait.md diff --git a/.changeset/fast-steaks-wait.md b/.changeset/fast-steaks-wait.md new file mode 100644 index 00000000..0ba38f1f --- /dev/null +++ b/.changeset/fast-steaks-wait.md @@ -0,0 +1,6 @@ +--- +'@kitql/eslint-config': minor +--- + +BREAKING - new eslint-plugin-pnpm config (check https://www.npmjs.com/package/eslint-plugin-pnpm if +you want custom things) diff --git a/eslint.config.js b/eslint.config.js index 4f13bf69..af30c65d 100644 --- a/eslint.config.js +++ b/eslint.config.js @@ -3,14 +3,11 @@ import { kitql } from './packages/eslint-config/eslint.config.js' /** @type { import("eslint").Linter.Config[] } */ export default [ ...kitql({ - // pnpmCatalogs: { - // enable: true, - // files: ['package.json', '**/*.package.json'], - // rules: { - // 'pnpm-catalogs/enforce-catalog': 'error', - // 'pnpm-catalogs/valid-catalog': 'error', - // }, - // }, + pnpmCatalogs: { + yaml_rules: { + 'pnpm/yaml-no-duplicate-catalog-item': ['error', { allow: ['svelte', '@sveltejs/kit'] }], + }, + }, }), { name: 'APP:ignores', diff --git a/package.json b/package.json index 6bf0d4d6..0e95feab 100644 --- a/package.json +++ b/package.json @@ -9,6 +9,7 @@ "release:version": "npm run changeset version", "release": "npm run build && changeset publish --verbose", "reset": "git clean -xdf", + "lint": "kitql-lint", "format": "kitql-lint --format", "up-dep": "pnpm -r up --latest" }, @@ -19,13 +20,5 @@ "esbuild": "catalog:tooling", "prettier": "catalog:linting", "rimraf": "catalog:tooling" - }, - "pnpm": { - "onlyBuiltDependencies": [ - "esbuild" - ], - "patchedDependencies": { - "@sveltejs/package": "patches/@sveltejs__package.patch" - } } } \ No newline at end of file diff --git a/packages/eslint-config/eslint.config.js b/packages/eslint-config/eslint.config.js index b0f38be8..a197c581 100644 --- a/packages/eslint-config/eslint.config.js +++ b/packages/eslint-config/eslint.config.js @@ -1,19 +1,22 @@ import { includeIgnoreFile } from '@eslint/compat' import js from '@eslint/js' -import pnpmCatalogs from 'eslint-plugin-pnpm-catalogs' +import pluginPnpm from 'eslint-plugin-pnpm' import svelte from 'eslint-plugin-svelte' import unusedImports from 'eslint-plugin-unused-imports' import globals from 'globals' import * as jsoncParser from 'jsonc-eslint-parser' import ts from 'typescript-eslint' +import * as yamlParser from 'yaml-eslint-parser' import { findFileOrUp } from './helper/findFileOrUp.js' /** * @typedef {Object} PnpmCatalogsConfig * @property {boolean} [enable=true] - Whether to enable pnpm catalogs rules - * @property {string[]} [files] - Files to apply the rules to - * @property {Record} [rules] - Rules configuration + * @property {string[]} [json_files] - Files to apply the rules to + * @property {Record} [json_rules] - Rules configuration + * @property {string[]} [yaml_files] - Files to apply the rules to + * @property {Record} [yaml_rules] - Rules configuration */ const rulePrettierIgnore = ({ pnpmCatalogsEnabled = true }) => { @@ -34,26 +37,47 @@ const rulePrettierIgnore = ({ pnpmCatalogsEnabled = true }) => { const rulePnpmCatalogs = (options = {}) => { const { enable = true, - files = ['package.json', '**/package.json'], - rules = { - 'pnpm-catalogs/enforce-catalog': 'error', - 'pnpm-catalogs/valid-catalog': 'error', + json_files = ['package.json', '**/package.json'], + json_rules = { + 'pnpm/json-enforce-catalog': 'error', + 'pnpm/json-valid-catalog': 'error', + 'pnpm/json-prefer-workspace-settings': 'error', + ...options.json_rules, + }, + yaml_files = ['pnpm-workspace.yaml'], + yaml_rules = { + 'pnpm/yaml-no-unused-catalog-item': 'error', + 'pnpm/yaml-no-duplicate-catalog-item': 'off', + ...options.yaml_rules, }, } = options - if (!enable) return null + if (!enable) return [] - return { - name: 'pnpm-catalogs:package.json', - files, - languageOptions: { - parser: jsoncParser, + return [ + { + name: 'pnpm/package.json', + files: json_files, + languageOptions: { + parser: jsoncParser, + }, + plugins: { + pnpm: pluginPnpm, + }, + rules: json_rules, }, - plugins: { - 'pnpm-catalogs': pnpmCatalogs, + { + name: 'pnpm/pnpm-workspace-yaml', + files: yaml_files, + languageOptions: { + parser: yamlParser, + }, + plugins: { + pnpm: pluginPnpm, + }, + rules: yaml_rules, }, - rules, - } + ] } const othersRules = () => { @@ -144,7 +168,7 @@ const config = [ // rulePrettierIgnore({ pnpmCatalogsEnabled: true }), ...othersRules(), - rulePnpmCatalogs(), + ...rulePnpmCatalogs(), ] export default config @@ -166,6 +190,6 @@ export const kitql = (options = {}) => { // rulePrettierIgnore({ pnpmCatalogsEnabled }), ...othersRules(), - ...(pnpmCatalogsEnabled ? [rulePnpmCatalogs(pnpmCatalogsConfig)] : []), + ...(pnpmCatalogsEnabled ? rulePnpmCatalogs(pnpmCatalogsConfig) : []), ] } diff --git a/packages/eslint-config/package.json b/packages/eslint-config/package.json index febd1cce..be0a1191 100644 --- a/packages/eslint-config/package.json +++ b/packages/eslint-config/package.json @@ -46,7 +46,7 @@ "@typescript-eslint/parser": "catalog:linting", "commander": "catalog:tooling", "eslint": "catalog:linting", - "eslint-plugin-pnpm-catalogs": "catalog:linting", + "eslint-plugin-pnpm": "catalog:linting", "eslint-plugin-svelte": "catalog:linting", "eslint-plugin-unused-imports": "catalog:linting", "globals": "catalog:linting", @@ -55,7 +55,8 @@ "prettier": "catalog:linting", "prettier-plugin-svelte": "catalog:linting", "prettier-plugin-tailwindcss": "catalog:linting", - "typescript-eslint": "catalog:linting" + "typescript-eslint": "catalog:linting", + "yaml-eslint-parser": "catalog:linting" }, "publishConfig": { "access": "public" diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index be5cc147..3e661818 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -79,9 +79,9 @@ catalogs: eslint: specifier: 9.22.0 version: 9.22.0 - eslint-plugin-pnpm-catalogs: - specifier: 0.1.0 - version: 0.1.0 + eslint-plugin-pnpm: + specifier: 0.3.1 + version: 0.3.1 eslint-plugin-svelte: specifier: 3.1.0 version: 3.1.0 @@ -106,6 +106,9 @@ catalogs: typescript-eslint: specifier: 8.26.0 version: 8.26.0 + yaml-eslint-parser: + specifier: 1.3.0 + version: 1.3.0 remult: remult: specifier: 2.7.31 @@ -264,9 +267,9 @@ importers: eslint: specifier: catalog:linting version: 9.22.0(jiti@1.21.7) - eslint-plugin-pnpm-catalogs: + eslint-plugin-pnpm: specifier: catalog:linting - version: 0.1.0(eslint@9.22.0(jiti@1.21.7)) + version: 0.3.1(eslint@9.22.0(jiti@1.21.7)) eslint-plugin-svelte: specifier: catalog:linting version: 3.1.0(eslint@9.22.0(jiti@1.21.7))(svelte@5.23.0) @@ -294,6 +297,9 @@ importers: typescript-eslint: specifier: catalog:linting version: 8.26.0(eslint@9.22.0(jiti@1.21.7))(typescript@5.8.2) + yaml-eslint-parser: + specifier: catalog:linting + version: 1.3.0 packages/handles: dependencies: @@ -2401,8 +2407,8 @@ packages: peerDependencies: eslint: '>=6.0.0' - eslint-plugin-pnpm-catalogs@0.1.0: - resolution: {integrity: sha512-4FzIfTfr06U3ULStgSMSmpDsfhtxsbSAxKLvXLo+/i/z48v4+4WD0Yr5hTb6E37X/ch8isKiTl4bnnvSENTYFA==} + eslint-plugin-pnpm@0.3.1: + resolution: {integrity: sha512-vi5iHoELIAlBbX4AW8ZGzU3tUnfxuXhC/NKo3qRcI5o9igbz6zJUqSlQ03bPeMqWIGTPatZnbWsNR1RnlNERNQ==} peerDependencies: eslint: ^9.0.0 @@ -3712,8 +3718,8 @@ packages: engines: {node: '>=18'} hasBin: true - pnpm-catalogs-utils@0.1.0: - resolution: {integrity: sha512-avysWJc452htYTnae14ENYTI3fSzZ1U1xNrdSJ2kFgwDaDvdEKIM5Iu+WljP2cdr/HAKKQ1hnuvu3sQJ3Eq/zQ==} + pnpm-workspace-yaml@0.3.1: + resolution: {integrity: sha512-3nW5RLmREmZ8Pm8MbPsO2RM+99RRjYd25ynj3NV0cFsN7CcEl4sDFzgoFmSyduFwxFQ2Qbu3y2UdCh6HlyUOeA==} postcss-less@6.0.0: resolution: {integrity: sha512-FPX16mQLyEjLzEuuJtxA8X3ejDLNGGEG503d2YGZR5Ask1SpDN8KmZUMpzCvyalWRywAn1n1VOA5dcqfCLo5rg==} @@ -4720,6 +4726,10 @@ packages: yallist@4.0.0: resolution: {integrity: sha512-3wdGidZyq5PB084XLES5TpOSRA3wjXAlIWMhum2kRcv/41Sn2emQ0dycQW4uZXLejwKvg6EsvbdlVL+FYEct7A==} + yaml-eslint-parser@1.3.0: + resolution: {integrity: sha512-E/+VitOorXSLiAqtTd7Yqax0/pAS3xaYMP+AUUJGOK1OZG3rhcj9fcJOM5HJ2VrP1FrStVCWr1muTfQCdj4tAA==} + engines: {node: ^14.17.0 || >=16.0.0} + yaml@1.10.2: resolution: {integrity: sha512-r3vXyErRCYJ7wg28yvBY5VSoAF8ZvlcW9/BwUzEtUsjvX/DKs24dIkuwjtuprwJJHsbyUbLApepYTR1BN4uHrg==} engines: {node: '>= 6'} @@ -6865,12 +6875,15 @@ snapshots: eslint: 9.22.0(jiti@1.21.7) semver: 7.7.1 - eslint-plugin-pnpm-catalogs@0.1.0(eslint@9.22.0(jiti@1.21.7)): + eslint-plugin-pnpm@0.3.1(eslint@9.22.0(jiti@1.21.7)): dependencies: eslint: 9.22.0(jiti@1.21.7) find-up-simple: 1.0.1 jsonc-eslint-parser: 2.4.0 - pnpm-catalogs-utils: 0.1.0 + pathe: 2.0.3 + pnpm-workspace-yaml: 0.3.1 + tinyglobby: 0.2.12 + yaml-eslint-parser: 1.3.0 eslint-plugin-svelte@3.1.0(eslint@9.22.0(jiti@1.21.7))(svelte@5.23.0): dependencies: @@ -8613,7 +8626,7 @@ snapshots: optionalDependencies: fsevents: 2.3.2 - pnpm-catalogs-utils@0.1.0: + pnpm-workspace-yaml@0.3.1: dependencies: yaml: 2.7.0 @@ -9692,6 +9705,11 @@ snapshots: yallist@4.0.0: {} + yaml-eslint-parser@1.3.0: + dependencies: + eslint-visitor-keys: 3.4.3 + yaml: 2.7.0 + yaml@1.10.2: {} yaml@2.7.0: {} diff --git a/pnpm-workspace.yaml b/pnpm-workspace.yaml index d3181d46..847852d7 100644 --- a/pnpm-workspace.yaml +++ b/pnpm-workspace.yaml @@ -1,3 +1,9 @@ +onlyBuiltDependencies: + - esbuild + +patchedDependencies: + '@sveltejs/package': patches/@sveltejs__package.patch + packages: - 'packages/*' - 'docs' @@ -11,7 +17,6 @@ catalogs: 'commander': '13.1.0' 'ora': '8.2.0' 'recast': '^0.23.4' # to remove ? - '@types/node': '22.13.9' vite: 'vite': '6.2.1' @@ -33,7 +38,7 @@ catalogs: '@types/eslint': '9.6.1' '@typescript-eslint/parser': '8.26.0' 'eslint': '9.22.0' - 'eslint-plugin-pnpm-catalogs': '0.1.0' + 'eslint-plugin-pnpm': '0.3.1' 'eslint-plugin-svelte': '3.1.0' 'eslint-plugin-unused-imports': '4.1.4' 'globals': '16.0.0' @@ -42,6 +47,7 @@ catalogs: 'prettier-plugin-tailwindcss': '0.6.6' 'typescript-eslint': '8.26.0' jsonc-eslint-parser: 2.4.0 + yaml-eslint-parser: 1.3.0 lib-author-helper: '@changesets/changelog-github': '0.5.1' @@ -63,7 +69,6 @@ catalogs: '@sveltejs/vite-plugin-svelte': '5.0.1' '@sveltejs/adapter-auto': '4.0.0' '@sveltejs/adapter-node': '5.2.12' - '@sveltejs/adapter-static': '3.0.4' svelte: 'svelte': '5.23.0' -- 2.51.2