@storm-software/eslint 0.144.2 → 0.145.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/dist/preset.js +789 -60
- package/dist/types.d.ts +39 -16
- package/package.json +2 -2
- package/dist/dist-JAA754SN.js +0 -415
package/dist/types.d.ts
CHANGED
|
@@ -3742,19 +3742,29 @@ Backward pagination arguments
|
|
|
3742
3742
|
'perfectionist/sort-variable-declarations'?: Linter.RuleEntry<PerfectionistSortVariableDeclarations>
|
|
3743
3743
|
/**
|
|
3744
3744
|
* Enforce using "catalog:" in `package.json`
|
|
3745
|
-
* @see https://github.com/antfu/eslint-plugin-pnpm/blob/main/src/rules/enforce-catalog.test.ts
|
|
3745
|
+
* @see https://github.com/antfu/eslint-plugin-pnpm/blob/main/src/rules/json-enforce-catalog.test.ts
|
|
3746
3746
|
*/
|
|
3747
|
-
'pnpm/enforce-catalog'?: Linter.RuleEntry<
|
|
3747
|
+
'pnpm/json-enforce-catalog'?: Linter.RuleEntry<PnpmJsonEnforceCatalog>
|
|
3748
3748
|
/**
|
|
3749
3749
|
* Prefer having pnpm settings in `pnpm-workspace.yaml` instead of `package.json`. This would requires pnpm v10.6+, see https://github.com/orgs/pnpm/discussions/9037.
|
|
3750
|
-
* @see https://github.com/antfu/eslint-plugin-pnpm/blob/main/src/rules/prefer-workspace-settings.test.ts
|
|
3750
|
+
* @see https://github.com/antfu/eslint-plugin-pnpm/blob/main/src/rules/json-prefer-workspace-settings.test.ts
|
|
3751
3751
|
*/
|
|
3752
|
-
'pnpm/prefer-workspace-settings'?: Linter.RuleEntry<
|
|
3752
|
+
'pnpm/json-prefer-workspace-settings'?: Linter.RuleEntry<PnpmJsonPreferWorkspaceSettings>
|
|
3753
3753
|
/**
|
|
3754
3754
|
* Enforce using valid catalog in `package.json`
|
|
3755
|
-
* @see https://github.com/antfu/eslint-plugin-pnpm/blob/main/src/rules/valid-catalog.test.ts
|
|
3755
|
+
* @see https://github.com/antfu/eslint-plugin-pnpm/blob/main/src/rules/json-valid-catalog.test.ts
|
|
3756
3756
|
*/
|
|
3757
|
-
'pnpm/valid-catalog'?: Linter.RuleEntry<
|
|
3757
|
+
'pnpm/json-valid-catalog'?: Linter.RuleEntry<PnpmJsonValidCatalog>
|
|
3758
|
+
/**
|
|
3759
|
+
* Disallow unused catalogs in `pnpm-workspace.yaml`
|
|
3760
|
+
* @see https://github.com/antfu/eslint-plugin-pnpm/blob/main/src/rules/yaml-no-duplicate-catalog-item.test.ts
|
|
3761
|
+
*/
|
|
3762
|
+
'pnpm/yaml-no-duplicate-catalog-item'?: Linter.RuleEntry<PnpmYamlNoDuplicateCatalogItem>
|
|
3763
|
+
/**
|
|
3764
|
+
* Disallow unused catalogs in `pnpm-workspace.yaml`
|
|
3765
|
+
* @see https://github.com/antfu/eslint-plugin-pnpm/blob/main/src/rules/yaml-no-unused-catalog-item.test.ts
|
|
3766
|
+
*/
|
|
3767
|
+
'pnpm/yaml-no-unused-catalog-item'?: Linter.RuleEntry<[]>
|
|
3758
3768
|
/**
|
|
3759
3769
|
* Require using arrow functions for callbacks
|
|
3760
3770
|
* @see https://eslint.org/docs/latest/rules/prefer-arrow-callback
|
|
@@ -12707,8 +12717,8 @@ type PerfectionistSortVariableDeclarations = []|[{
|
|
|
12707
12717
|
|
|
12708
12718
|
partitionByNewLine?: boolean
|
|
12709
12719
|
}]
|
|
12710
|
-
// ----- pnpm/enforce-catalog -----
|
|
12711
|
-
type
|
|
12720
|
+
// ----- pnpm/json-enforce-catalog -----
|
|
12721
|
+
type PnpmJsonEnforceCatalog = []|[{
|
|
12712
12722
|
|
|
12713
12723
|
allowedProtocols?: string[]
|
|
12714
12724
|
|
|
@@ -12718,20 +12728,33 @@ type PnpmEnforceCatalog = []|[{
|
|
|
12718
12728
|
|
|
12719
12729
|
reuseExistingCatalog?: boolean
|
|
12720
12730
|
|
|
12721
|
-
|
|
12731
|
+
conflicts?: ("new-catalog" | "overrides" | "error")
|
|
12732
|
+
|
|
12733
|
+
fields?: string[]
|
|
12734
|
+
|
|
12735
|
+
ignore?: string[]
|
|
12722
12736
|
}]
|
|
12723
|
-
// ----- pnpm/prefer-workspace-settings -----
|
|
12724
|
-
type
|
|
12737
|
+
// ----- pnpm/json-prefer-workspace-settings -----
|
|
12738
|
+
type PnpmJsonPreferWorkspaceSettings = []|[{
|
|
12739
|
+
|
|
12725
12740
|
autofix?: boolean
|
|
12726
12741
|
}]
|
|
12727
|
-
// ----- pnpm/valid-catalog -----
|
|
12728
|
-
type
|
|
12742
|
+
// ----- pnpm/json-valid-catalog -----
|
|
12743
|
+
type PnpmJsonValidCatalog = []|[{
|
|
12729
12744
|
|
|
12730
12745
|
autoInsert?: boolean
|
|
12731
12746
|
|
|
12732
12747
|
autoInsertDefaultSpecifier?: string
|
|
12733
12748
|
|
|
12734
12749
|
autofix?: boolean
|
|
12750
|
+
|
|
12751
|
+
enforceNoConflict?: boolean
|
|
12752
|
+
|
|
12753
|
+
fields?: unknown[]
|
|
12754
|
+
}]
|
|
12755
|
+
// ----- pnpm/yaml-no-duplicate-catalog-item -----
|
|
12756
|
+
type PnpmYamlNoDuplicateCatalogItem = []|[{
|
|
12757
|
+
allow?: string[]
|
|
12735
12758
|
}]
|
|
12736
12759
|
// ----- prefer-arrow-callback -----
|
|
12737
12760
|
type PreferArrowCallback = []|[{
|
|
@@ -16331,7 +16354,7 @@ type Yoda = []|[("always" | "never")]|[("always" | "never"), {
|
|
|
16331
16354
|
onlyEquality?: boolean
|
|
16332
16355
|
}]
|
|
16333
16356
|
// Names of all the configs
|
|
16334
|
-
type ConfigNames = 'storm/cspell/rules' | 'storm/astro/setup' | 'storm/astro/rules' | 'storm/formatter/setup' | 'storm/imports/rules' | 'storm/graphql/setup' | 'storm/graphql/rules' | 'storm/graphql/relay' | 'storm/javascript/setup' | 'storm/javascript/banner' | 'storm/javascript/rules' | 'storm/jsx/rules' | 'storm/jsdoc/rules' | 'storm/jsonc/setup' | 'storm/jsonc/rules' | 'storm/markdown/setup' | 'storm/markdown/processor' | 'storm/markdown/parser' | 'storm/markdown/disables' | 'storm/mdx/setup' | 'storm/node/rules' | 'storm/nx/setup' | 'storm/nx/schema' | 'storm/nx/dependency-check' | 'storm/nx/module-boundaries' | 'storm/next/rules' | 'storm/prettier/rules' | 'storm/perfectionist/rules' | 'storm/pnpm' | 'storm/react/setup' | 'storm/react/rules' | 'storm/react-native/rules' | 'storm/sort/package-json' | 'storm/stylistic/rules' | 'storm/secrets/rules' | 'storm/storybook/setup' | 'storm/storybook/rules' | 'storm/storybook/main' | 'storm/test/setup' | 'storm/test/rules' | 'storm/toml/setup' | 'storm/toml/rules' | 'storm/regexp/rules' | 'storm/typescript/setup' | 'storm/typescript/parser' | 'storm/typescript/type-aware-parser' | 'storm/typescript/rules' | 'storm/typescript/rules-tsdoc' | 'storm/typescript/rules-type-aware' | 'storm/unicorn/rules' | 'storm/unocss' | 'storm/yaml/setup' | 'storm/yaml/rules'
|
|
16357
|
+
type ConfigNames = 'storm/cspell/rules' | 'storm/astro/setup' | 'storm/astro/rules' | 'storm/formatter/setup' | 'storm/imports/rules' | 'storm/graphql/setup' | 'storm/graphql/rules' | 'storm/graphql/relay' | 'storm/javascript/setup' | 'storm/javascript/banner' | 'storm/javascript/rules' | 'storm/jsx/rules' | 'storm/jsdoc/rules' | 'storm/jsonc/setup' | 'storm/jsonc/rules' | 'storm/markdown/setup' | 'storm/markdown/processor' | 'storm/markdown/parser' | 'storm/markdown/disables' | 'storm/mdx/setup' | 'storm/node/rules' | 'storm/nx/setup' | 'storm/nx/schema' | 'storm/nx/dependency-check' | 'storm/nx/module-boundaries' | 'storm/next/rules' | 'storm/prettier/rules' | 'storm/perfectionist/rules' | 'storm/pnpm/setup' | 'storm/pnpm/package-json' | 'storm/pnpm/pnpm-workspace-yaml' | 'storm/react/setup' | 'storm/react/rules' | 'storm/react-native/rules' | 'storm/sort/package-json' | 'storm/stylistic/rules' | 'storm/secrets/rules' | 'storm/storybook/setup' | 'storm/storybook/rules' | 'storm/storybook/main' | 'storm/test/setup' | 'storm/test/rules' | 'storm/toml/setup' | 'storm/toml/rules' | 'storm/regexp/rules' | 'storm/typescript/setup' | 'storm/typescript/parser' | 'storm/typescript/type-aware-parser' | 'storm/typescript/rules' | 'storm/typescript/rules-tsdoc' | 'storm/typescript/rules-type-aware' | 'storm/unicorn/rules' | 'storm/unocss' | 'storm/yaml/setup' | 'storm/yaml/rules'
|
|
16335
16358
|
|
|
16336
16359
|
/**
|
|
16337
16360
|
* Vendor types from Prettier so we don't rely on the dependency.
|
|
@@ -16812,11 +16835,11 @@ interface OptionsNx extends OptionsOverrides {
|
|
|
16812
16835
|
}
|
|
16813
16836
|
interface OptionsPnpm extends OptionsOverrides {
|
|
16814
16837
|
/**
|
|
16815
|
-
* A list of dependencies to ignore for the `pnpm/enforce-catalog` rule.
|
|
16838
|
+
* A list of dependencies to ignore for the `pnpm/json-enforce-catalog` rule.
|
|
16816
16839
|
*
|
|
16817
16840
|
* @defaultValue ["typescript"]
|
|
16818
16841
|
*/
|
|
16819
|
-
|
|
16842
|
+
ignore?: string[];
|
|
16820
16843
|
}
|
|
16821
16844
|
interface OptionsCSpell extends OptionsOverrides {
|
|
16822
16845
|
/**
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@storm-software/eslint",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.145.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "⚡ A package containing the base ESLint configuration used by Storm Software across many projects.",
|
|
6
6
|
"repository": {
|
|
@@ -186,7 +186,7 @@
|
|
|
186
186
|
"eslint-plugin-no-secrets": "^2.2.1",
|
|
187
187
|
"eslint-plugin-paths": "^1.1.0",
|
|
188
188
|
"eslint-plugin-perfectionist": "^4.9.0",
|
|
189
|
-
"eslint-plugin-pnpm": "0.
|
|
189
|
+
"eslint-plugin-pnpm": "0.3.0",
|
|
190
190
|
"eslint-plugin-prettier": "^5.2.3",
|
|
191
191
|
"eslint-plugin-regexp": "^2.7.0",
|
|
192
192
|
"eslint-plugin-toml": "^0.12.0",
|
package/dist/dist-JAA754SN.js
DELETED
|
@@ -1,415 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
__name
|
|
3
|
-
} from "./chunk-SHUYVCID.js";
|
|
4
|
-
|
|
5
|
-
// ../../node_modules/.pnpm/eslint-plugin-pnpm@0.1.2_patch_hash=fc4ee4a7237efb5ba14023278092ac74b27d4e63c5770dc1217_74126a20697f606656d92d86401c9c8d/node_modules/eslint-plugin-pnpm/dist/index.mjs
|
|
6
|
-
import * as jsoncParser from "jsonc-eslint-parser";
|
|
7
|
-
import fs from "node:fs";
|
|
8
|
-
import process from "node:process";
|
|
9
|
-
import { findUpSync } from "find-up-simple";
|
|
10
|
-
import { parsePnpmWorkspaceYaml } from "pnpm-workspace-yaml";
|
|
11
|
-
var blobUrl = "https://github.com/antfu/eslint-plugin-pnpm/blob/main/src/rules/";
|
|
12
|
-
function RuleCreator(urlCreator) {
|
|
13
|
-
return /* @__PURE__ */ __name(function createNamedRule({
|
|
14
|
-
name,
|
|
15
|
-
meta,
|
|
16
|
-
...rule
|
|
17
|
-
}) {
|
|
18
|
-
return createRule({
|
|
19
|
-
meta: {
|
|
20
|
-
...meta,
|
|
21
|
-
docs: {
|
|
22
|
-
...meta.docs,
|
|
23
|
-
url: urlCreator(name)
|
|
24
|
-
}
|
|
25
|
-
},
|
|
26
|
-
...rule
|
|
27
|
-
});
|
|
28
|
-
}, "createNamedRule");
|
|
29
|
-
}
|
|
30
|
-
__name(RuleCreator, "RuleCreator");
|
|
31
|
-
function createRule({
|
|
32
|
-
create,
|
|
33
|
-
defaultOptions,
|
|
34
|
-
meta
|
|
35
|
-
}) {
|
|
36
|
-
return {
|
|
37
|
-
create: /* @__PURE__ */ __name((context) => {
|
|
38
|
-
const optionsWithDefault = context.options.map((options, index) => {
|
|
39
|
-
return {
|
|
40
|
-
...defaultOptions[index] || {},
|
|
41
|
-
...options || {}
|
|
42
|
-
};
|
|
43
|
-
});
|
|
44
|
-
return create(context, optionsWithDefault);
|
|
45
|
-
}, "create"),
|
|
46
|
-
defaultOptions,
|
|
47
|
-
meta
|
|
48
|
-
};
|
|
49
|
-
}
|
|
50
|
-
__name(createRule, "createRule");
|
|
51
|
-
var createEslintRule = RuleCreator(
|
|
52
|
-
(ruleName) => `${blobUrl}${ruleName}.test.ts`
|
|
53
|
-
);
|
|
54
|
-
function getPackageJsonRootNode(context) {
|
|
55
|
-
if (!context.filename.endsWith("package.json"))
|
|
56
|
-
return;
|
|
57
|
-
const ast = context.sourceCode.ast;
|
|
58
|
-
const root = ast.body[0];
|
|
59
|
-
if (root.expression.type === "JSONObjectExpression")
|
|
60
|
-
return root.expression;
|
|
61
|
-
}
|
|
62
|
-
__name(getPackageJsonRootNode, "getPackageJsonRootNode");
|
|
63
|
-
function* iterateDependencies(context) {
|
|
64
|
-
const root = getPackageJsonRootNode(context);
|
|
65
|
-
if (!root)
|
|
66
|
-
return;
|
|
67
|
-
for (const type of ["dependencies", "devDependencies"]) {
|
|
68
|
-
const node = root.properties.find((property) => property.key.type === "JSONLiteral" && property.key.value === type);
|
|
69
|
-
if (!node)
|
|
70
|
-
continue;
|
|
71
|
-
if (node.value.type !== "JSONObjectExpression")
|
|
72
|
-
continue;
|
|
73
|
-
for (const property of node.value.properties) {
|
|
74
|
-
if (property.value.type !== "JSONLiteral" || property.key.type !== "JSONLiteral")
|
|
75
|
-
continue;
|
|
76
|
-
if (typeof property.value.value !== "string")
|
|
77
|
-
continue;
|
|
78
|
-
const packageName = String(property.key.value);
|
|
79
|
-
const specifier = String(property.value.value);
|
|
80
|
-
yield {
|
|
81
|
-
packageName,
|
|
82
|
-
specifier,
|
|
83
|
-
property
|
|
84
|
-
};
|
|
85
|
-
}
|
|
86
|
-
}
|
|
87
|
-
}
|
|
88
|
-
__name(iterateDependencies, "iterateDependencies");
|
|
89
|
-
function readPnpmWorkspace() {
|
|
90
|
-
const filepath = findUpSync("pnpm-workspace.yaml", { cwd: process.cwd() });
|
|
91
|
-
if (!filepath)
|
|
92
|
-
throw new Error("pnpm-workspace.yaml not found");
|
|
93
|
-
const content = fs.readFileSync(filepath, "utf-8");
|
|
94
|
-
const workspace2 = parsePnpmWorkspaceYaml(content);
|
|
95
|
-
let queueTimer;
|
|
96
|
-
const queue = [];
|
|
97
|
-
const write = /* @__PURE__ */ __name(() => {
|
|
98
|
-
fs.writeFileSync(filepath, workspace2.toString());
|
|
99
|
-
}, "write");
|
|
100
|
-
const hasQueue = /* @__PURE__ */ __name(() => queueTimer != null, "hasQueue");
|
|
101
|
-
const queueChange = /* @__PURE__ */ __name((fn, order) => {
|
|
102
|
-
if (order === "pre")
|
|
103
|
-
queue.unshift(fn);
|
|
104
|
-
else
|
|
105
|
-
queue.push(fn);
|
|
106
|
-
if (queueTimer != null)
|
|
107
|
-
clearTimeout(queueTimer);
|
|
108
|
-
queueTimer = setTimeout(() => {
|
|
109
|
-
queueTimer = void 0;
|
|
110
|
-
const clone = [...queue];
|
|
111
|
-
queue.length = 0;
|
|
112
|
-
for (const fn2 of clone)
|
|
113
|
-
fn2(workspace2);
|
|
114
|
-
if (workspace2.hasChanged())
|
|
115
|
-
write();
|
|
116
|
-
}, 1e3);
|
|
117
|
-
}, "queueChange");
|
|
118
|
-
return {
|
|
119
|
-
...workspace2,
|
|
120
|
-
hasQueue,
|
|
121
|
-
queueChange
|
|
122
|
-
};
|
|
123
|
-
}
|
|
124
|
-
__name(readPnpmWorkspace, "readPnpmWorkspace");
|
|
125
|
-
var WORKSPACE_CACHE_TIME = 1e4;
|
|
126
|
-
var workspaceLastRead;
|
|
127
|
-
var workspace;
|
|
128
|
-
function getPnpmWorkspace() {
|
|
129
|
-
if (workspaceLastRead && workspace && !workspace.hasQueue() && Date.now() - workspaceLastRead > WORKSPACE_CACHE_TIME) {
|
|
130
|
-
workspace = void 0;
|
|
131
|
-
}
|
|
132
|
-
if (!workspace) {
|
|
133
|
-
workspace = readPnpmWorkspace();
|
|
134
|
-
workspaceLastRead = Date.now();
|
|
135
|
-
}
|
|
136
|
-
return workspace;
|
|
137
|
-
}
|
|
138
|
-
__name(getPnpmWorkspace, "getPnpmWorkspace");
|
|
139
|
-
var RULE_NAME$2 = "enforce-catalog";
|
|
140
|
-
var enforceCatalog = createEslintRule({
|
|
141
|
-
name: RULE_NAME$2,
|
|
142
|
-
meta: {
|
|
143
|
-
type: "layout",
|
|
144
|
-
docs: {
|
|
145
|
-
description: 'Enforce using "catalog:" in `package.json`'
|
|
146
|
-
},
|
|
147
|
-
fixable: "code",
|
|
148
|
-
schema: [
|
|
149
|
-
{
|
|
150
|
-
type: "object",
|
|
151
|
-
properties: {
|
|
152
|
-
allowedProtocols: {
|
|
153
|
-
type: "array",
|
|
154
|
-
description: "Allowed protocols in specifier to not be converted to catalog",
|
|
155
|
-
items: {
|
|
156
|
-
type: "string"
|
|
157
|
-
}
|
|
158
|
-
},
|
|
159
|
-
autofix: {
|
|
160
|
-
type: "boolean",
|
|
161
|
-
description: "Whether to autofix the linting error",
|
|
162
|
-
default: false
|
|
163
|
-
},
|
|
164
|
-
defaultCatalog: {
|
|
165
|
-
type: "string",
|
|
166
|
-
description: "Default catalog to use when moving version to catalog with autofix"
|
|
167
|
-
},
|
|
168
|
-
reuseExistingCatalog: {
|
|
169
|
-
type: "boolean",
|
|
170
|
-
description: "Whether to reuse existing catalog when moving version to catalog with autofix",
|
|
171
|
-
default: true
|
|
172
|
-
},
|
|
173
|
-
skipPackages: {
|
|
174
|
-
type: "array",
|
|
175
|
-
description: "A list of packages to skip when enforcing the catalog",
|
|
176
|
-
items: {
|
|
177
|
-
type: "string"
|
|
178
|
-
}
|
|
179
|
-
}
|
|
180
|
-
},
|
|
181
|
-
additionalProperties: false
|
|
182
|
-
}
|
|
183
|
-
],
|
|
184
|
-
messages: {
|
|
185
|
-
expectCatalog: 'Expect to use catalog instead of plain specifier, got "{{specifier}}" for package "{{packageName}}".'
|
|
186
|
-
}
|
|
187
|
-
},
|
|
188
|
-
defaultOptions: [{}],
|
|
189
|
-
create(context, [options = {}]) {
|
|
190
|
-
const {
|
|
191
|
-
allowedProtocols = ["workspace", "link", "file"],
|
|
192
|
-
defaultCatalog = "default",
|
|
193
|
-
autofix = true,
|
|
194
|
-
reuseExistingCatalog = true,
|
|
195
|
-
skipPackages = []
|
|
196
|
-
} = options || {};
|
|
197
|
-
for (const { packageName, specifier, property } of iterateDependencies(context)) {
|
|
198
|
-
if (skipPackages.includes(packageName))
|
|
199
|
-
continue;
|
|
200
|
-
if (specifier.startsWith("catalog:"))
|
|
201
|
-
continue;
|
|
202
|
-
if (allowedProtocols?.some((p) => specifier.startsWith(p)))
|
|
203
|
-
continue;
|
|
204
|
-
const workspace2 = getPnpmWorkspace();
|
|
205
|
-
if (!workspace2)
|
|
206
|
-
return {};
|
|
207
|
-
context.report({
|
|
208
|
-
node: property.value,
|
|
209
|
-
messageId: "expectCatalog",
|
|
210
|
-
data: {
|
|
211
|
-
specifier,
|
|
212
|
-
packageName
|
|
213
|
-
},
|
|
214
|
-
fix: autofix ? (fixer) => {
|
|
215
|
-
const catalog = reuseExistingCatalog ? workspace2.getPackageCatalogs(packageName)[0] || defaultCatalog : defaultCatalog;
|
|
216
|
-
workspace2.queueChange(() => {
|
|
217
|
-
workspace2.setPackage(catalog, packageName, specifier);
|
|
218
|
-
});
|
|
219
|
-
return fixer.replaceText(
|
|
220
|
-
property.value,
|
|
221
|
-
catalog === "default" ? JSON.stringify("catalog:") : JSON.stringify(`catalog:${catalog}`)
|
|
222
|
-
);
|
|
223
|
-
} : void 0
|
|
224
|
-
});
|
|
225
|
-
}
|
|
226
|
-
return {};
|
|
227
|
-
}
|
|
228
|
-
});
|
|
229
|
-
var RULE_NAME$1 = "prefer-workspace-settings";
|
|
230
|
-
var preferWorkspaceSettings = createEslintRule({
|
|
231
|
-
name: RULE_NAME$1,
|
|
232
|
-
meta: {
|
|
233
|
-
type: "layout",
|
|
234
|
-
docs: {
|
|
235
|
-
description: "Prefer having pnpm settings in `pnpm-workspace.yaml` instead of `package.json`. This would requires pnpm v10.6+, see https://github.com/orgs/pnpm/discussions/9037."
|
|
236
|
-
},
|
|
237
|
-
fixable: "code",
|
|
238
|
-
schema: [
|
|
239
|
-
{
|
|
240
|
-
type: "object",
|
|
241
|
-
properties: {
|
|
242
|
-
autofix: { type: "boolean" }
|
|
243
|
-
},
|
|
244
|
-
additionalProperties: false
|
|
245
|
-
}
|
|
246
|
-
],
|
|
247
|
-
messages: {
|
|
248
|
-
unexpectedPnpmSettings: "Unexpected pnpm settings in package.json, should move to pnpm-workspace.yaml"
|
|
249
|
-
}
|
|
250
|
-
},
|
|
251
|
-
defaultOptions: [{}],
|
|
252
|
-
create(context, [options = {}]) {
|
|
253
|
-
const {
|
|
254
|
-
autofix = true
|
|
255
|
-
} = options || {};
|
|
256
|
-
const root = getPackageJsonRootNode(context);
|
|
257
|
-
if (!root)
|
|
258
|
-
return {};
|
|
259
|
-
const pnpmNode = root.properties.find((property) => property.key.type === "JSONLiteral" && property.key.value === "pnpm");
|
|
260
|
-
if (!pnpmNode)
|
|
261
|
-
return {};
|
|
262
|
-
const workspace2 = getPnpmWorkspace();
|
|
263
|
-
if (!workspace2)
|
|
264
|
-
return {};
|
|
265
|
-
context.report({
|
|
266
|
-
node: pnpmNode,
|
|
267
|
-
messageId: "unexpectedPnpmSettings",
|
|
268
|
-
fix: autofix ? (fixer) => {
|
|
269
|
-
const json = JSON.parse(context.sourceCode.text);
|
|
270
|
-
const pnpmSettings = json.pnpm;
|
|
271
|
-
const flatValueParis = [];
|
|
272
|
-
function traverse(value, paths) {
|
|
273
|
-
if (typeof value === "object" && value !== null && !Array.isArray(value)) {
|
|
274
|
-
for (const key in value) {
|
|
275
|
-
traverse(value[key], [...paths, key]);
|
|
276
|
-
}
|
|
277
|
-
} else {
|
|
278
|
-
flatValueParis.push([paths, value]);
|
|
279
|
-
}
|
|
280
|
-
}
|
|
281
|
-
__name(traverse, "traverse");
|
|
282
|
-
traverse(pnpmSettings, []);
|
|
283
|
-
workspace2.queueChange(() => {
|
|
284
|
-
for (const [paths, value] of flatValueParis) {
|
|
285
|
-
workspace2.setPath(paths, value);
|
|
286
|
-
}
|
|
287
|
-
});
|
|
288
|
-
let start = pnpmNode.range[0];
|
|
289
|
-
let end = pnpmNode.range[1];
|
|
290
|
-
const before = context.sourceCode.getTokenBefore(pnpmNode);
|
|
291
|
-
if (before)
|
|
292
|
-
start = before.range[1];
|
|
293
|
-
const after = context.sourceCode.getTokenAfter(pnpmNode);
|
|
294
|
-
if (after?.type === "Punctuator" && after.value === ",")
|
|
295
|
-
end = after.range[1];
|
|
296
|
-
return fixer.removeRange([start, end]);
|
|
297
|
-
} : void 0
|
|
298
|
-
});
|
|
299
|
-
return {};
|
|
300
|
-
}
|
|
301
|
-
});
|
|
302
|
-
var RULE_NAME = "valid-catalog";
|
|
303
|
-
var validCatalog = createEslintRule({
|
|
304
|
-
name: RULE_NAME,
|
|
305
|
-
meta: {
|
|
306
|
-
type: "layout",
|
|
307
|
-
docs: {
|
|
308
|
-
description: "Enforce using valid catalog in `package.json`"
|
|
309
|
-
},
|
|
310
|
-
fixable: "code",
|
|
311
|
-
schema: [
|
|
312
|
-
{
|
|
313
|
-
type: "object",
|
|
314
|
-
properties: {
|
|
315
|
-
autoInsert: {
|
|
316
|
-
type: "boolean",
|
|
317
|
-
description: "Whether to auto insert to catalog if missing",
|
|
318
|
-
default: true
|
|
319
|
-
},
|
|
320
|
-
autoInsertDefaultSpecifier: {
|
|
321
|
-
type: "string",
|
|
322
|
-
description: "Default specifier to use when auto inserting to catalog",
|
|
323
|
-
default: "^0.0.0"
|
|
324
|
-
},
|
|
325
|
-
autofix: {
|
|
326
|
-
type: "boolean",
|
|
327
|
-
description: "Whether to autofix the linting error",
|
|
328
|
-
default: true
|
|
329
|
-
}
|
|
330
|
-
},
|
|
331
|
-
additionalProperties: false
|
|
332
|
-
}
|
|
333
|
-
],
|
|
334
|
-
messages: {
|
|
335
|
-
invalidCatalog: 'Catalog "{{specifier}}" for package "{{packageName}}" is not defined in `pnpm-workspace.yaml`.'
|
|
336
|
-
}
|
|
337
|
-
},
|
|
338
|
-
defaultOptions: [{}],
|
|
339
|
-
create(context, [options = {}]) {
|
|
340
|
-
const {
|
|
341
|
-
autoInsert = true,
|
|
342
|
-
autofix = true,
|
|
343
|
-
autoInsertDefaultSpecifier = "^0.0.0"
|
|
344
|
-
} = options || {};
|
|
345
|
-
for (const { packageName, specifier, property } of iterateDependencies(context)) {
|
|
346
|
-
if (!specifier.startsWith("catalog:"))
|
|
347
|
-
continue;
|
|
348
|
-
const workspace2 = getPnpmWorkspace();
|
|
349
|
-
if (!workspace2)
|
|
350
|
-
return {};
|
|
351
|
-
const currentCatalog = specifier.replace(/^catalog:/, "").trim() || "default";
|
|
352
|
-
const existingCatalogs = workspace2.getPackageCatalogs(packageName);
|
|
353
|
-
if (!existingCatalogs.includes(currentCatalog)) {
|
|
354
|
-
context.report({
|
|
355
|
-
node: property.value,
|
|
356
|
-
messageId: "invalidCatalog",
|
|
357
|
-
data: {
|
|
358
|
-
specifier,
|
|
359
|
-
packageName
|
|
360
|
-
},
|
|
361
|
-
fix: !autofix || !autoInsert && !existingCatalogs.length ? void 0 : (fixer) => {
|
|
362
|
-
let catalog = existingCatalogs[0];
|
|
363
|
-
if (!catalog && autoInsert) {
|
|
364
|
-
catalog = currentCatalog;
|
|
365
|
-
workspace2.queueChange(() => {
|
|
366
|
-
workspace2.setPackage(catalog, packageName, autoInsertDefaultSpecifier);
|
|
367
|
-
}, "pre");
|
|
368
|
-
}
|
|
369
|
-
return fixer.replaceText(
|
|
370
|
-
property.value,
|
|
371
|
-
catalog === "default" ? JSON.stringify("catalog:") : JSON.stringify(`catalog:${catalog}`)
|
|
372
|
-
);
|
|
373
|
-
}
|
|
374
|
-
});
|
|
375
|
-
}
|
|
376
|
-
}
|
|
377
|
-
return {};
|
|
378
|
-
}
|
|
379
|
-
});
|
|
380
|
-
var rules = {
|
|
381
|
-
"enforce-catalog": enforceCatalog,
|
|
382
|
-
"valid-catalog": validCatalog,
|
|
383
|
-
"prefer-workspace-settings": preferWorkspaceSettings
|
|
384
|
-
};
|
|
385
|
-
var plugin = {
|
|
386
|
-
rules
|
|
387
|
-
};
|
|
388
|
-
var configs = {
|
|
389
|
-
recommended: [
|
|
390
|
-
{
|
|
391
|
-
name: "pnpm/package.json",
|
|
392
|
-
files: [
|
|
393
|
-
"package.json",
|
|
394
|
-
"**/package.json"
|
|
395
|
-
],
|
|
396
|
-
languageOptions: {
|
|
397
|
-
parser: jsoncParser
|
|
398
|
-
},
|
|
399
|
-
plugins: {
|
|
400
|
-
pnpm: plugin
|
|
401
|
-
},
|
|
402
|
-
rules: {
|
|
403
|
-
"pnpm/enforce-catalog": "error",
|
|
404
|
-
"pnpm/valid-catalog": "error",
|
|
405
|
-
"pnpm/prefer-workspace-settings": "error"
|
|
406
|
-
}
|
|
407
|
-
}
|
|
408
|
-
]
|
|
409
|
-
};
|
|
410
|
-
plugin.configs = configs;
|
|
411
|
-
export {
|
|
412
|
-
configs,
|
|
413
|
-
plugin as default,
|
|
414
|
-
plugin
|
|
415
|
-
};
|