@storm-software/eslint 0.143.0 → 0.144.1

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 CHANGED
@@ -21,7 +21,7 @@ This package is part of the <b>⚡Storm-Ops</b> monorepo. The Storm-Ops packages
21
21
 
22
22
  <h3 align="center">💻 Visit <a href="https://stormsoftware.com" target="_blank">stormsoftware.com</a> to stay up to date with this developer</h3><br />
23
23
 
24
- [![Version](https://img.shields.io/badge/version-0.142.1-1fb2a6.svg?style=for-the-badge&color=1fb2a6)](https://prettier.io/)&nbsp;[![Nx](https://img.shields.io/badge/Nx-17.0.2-lightgrey?style=for-the-badge&logo=nx&logoWidth=20&&color=1fb2a6)](http://nx.dev/)&nbsp;[![NextJs](https://img.shields.io/badge/Next.js-14.0.2-lightgrey?style=for-the-badge&logo=nextdotjs&logoWidth=20&color=1fb2a6)](https://nextjs.org/)&nbsp;[![Commitizen friendly](https://img.shields.io/badge/commitizen-friendly-brightgreen.svg?style=for-the-badge&logo=commitlint&color=1fb2a6)](http://commitizen.github.io/cz-cli/)&nbsp;![Semantic-Release](https://img.shields.io/badge/%20%20%F0%9F%93%A6%F0%9F%9A%80-semantic--release-e10079.svg?style=for-the-badge&color=1fb2a6)&nbsp;[![documented with Fumadocs](https://img.shields.io/badge/documented_with-fumadocs-success.svg?style=for-the-badge&logo=readthedocs&color=1fb2a6)](https://fumadocs.vercel.app/)&nbsp;![GitHub Workflow Status (with event)](https://img.shields.io/github/actions/workflow/status/storm-software/storm-ops/cr.yml?style=for-the-badge&logo=github-actions&color=1fb2a6)
24
+ [![Version](https://img.shields.io/badge/version-0.144.0-1fb2a6.svg?style=for-the-badge&color=1fb2a6)](https://prettier.io/)&nbsp;[![Nx](https://img.shields.io/badge/Nx-17.0.2-lightgrey?style=for-the-badge&logo=nx&logoWidth=20&&color=1fb2a6)](http://nx.dev/)&nbsp;[![NextJs](https://img.shields.io/badge/Next.js-14.0.2-lightgrey?style=for-the-badge&logo=nextdotjs&logoWidth=20&color=1fb2a6)](https://nextjs.org/)&nbsp;[![Commitizen friendly](https://img.shields.io/badge/commitizen-friendly-brightgreen.svg?style=for-the-badge&logo=commitlint&color=1fb2a6)](http://commitizen.github.io/cz-cli/)&nbsp;![Semantic-Release](https://img.shields.io/badge/%20%20%F0%9F%93%A6%F0%9F%9A%80-semantic--release-e10079.svg?style=for-the-badge&color=1fb2a6)&nbsp;[![documented with Fumadocs](https://img.shields.io/badge/documented_with-fumadocs-success.svg?style=for-the-badge&logo=readthedocs&color=1fb2a6)](https://fumadocs.vercel.app/)&nbsp;![GitHub Workflow Status (with event)](https://img.shields.io/github/actions/workflow/status/storm-software/storm-ops/cr.yml?style=for-the-badge&logo=github-actions&color=1fb2a6)
25
25
 
26
26
  <!-- prettier-ignore-start -->
27
27
  <!-- markdownlint-disable -->
@@ -1,13 +1,11 @@
1
1
  import {
2
2
  correctPaths
3
- } from "./chunk-2QUIVW4L.js";
3
+ } from "./chunk-G7QVU75O.js";
4
4
  import {
5
- __name,
6
- init_esm_shims
7
- } from "./chunk-LCTBQU5F.js";
5
+ __name
6
+ } from "./chunk-SHUYVCID.js";
8
7
 
9
8
  // src/utils/find-workspace-root.ts
10
- init_esm_shims();
11
9
  import { existsSync } from "node:fs";
12
10
  import { join } from "node:path";
13
11
  var MAX_PATH_SEARCH_DEPTH = 30;
@@ -1,10 +1,8 @@
1
1
  import {
2
- __name,
3
- init_esm_shims
4
- } from "./chunk-LCTBQU5F.js";
2
+ __name
3
+ } from "./chunk-SHUYVCID.js";
5
4
 
6
5
  // src/utils/helpers.ts
7
- init_esm_shims();
8
6
  import { isPackageExists } from "local-pkg";
9
7
  import process from "node:process";
10
8
  import { fileURLToPath } from "node:url";
@@ -1,9 +1,4 @@
1
- import {
2
- init_esm_shims
3
- } from "./chunk-LCTBQU5F.js";
4
-
5
1
  // src/utils/constants.ts
6
- init_esm_shims();
7
2
  var GLOB_CODE_BLOCK = "**/*.md{,x}/*";
8
3
  var GLOB_CODE_FILE = "**/*.{,c,m}{j,t}s{,x}";
9
4
  var ACRONYMS_LIST = [
@@ -1,13 +1,11 @@
1
1
  import {
2
2
  joinPaths
3
- } from "./chunk-2QUIVW4L.js";
3
+ } from "./chunk-G7QVU75O.js";
4
4
  import {
5
- __name,
6
- init_esm_shims
7
- } from "./chunk-LCTBQU5F.js";
5
+ __name
6
+ } from "./chunk-SHUYVCID.js";
8
7
 
9
8
  // src/utils/tsconfig-path.ts
10
- init_esm_shims();
11
9
  import { existsSync } from "node:fs";
12
10
  function getTsConfigPath(basePath = "./") {
13
11
  let tsconfigPath = "tsconfig.json";
@@ -1,10 +1,8 @@
1
1
  import {
2
- __name,
3
- init_esm_shims
4
- } from "./chunk-LCTBQU5F.js";
2
+ __name
3
+ } from "./chunk-SHUYVCID.js";
5
4
 
6
5
  // src/utils/format-config.ts
7
- init_esm_shims();
8
6
  var formatConfig = /* @__PURE__ */ __name((name, config = []) => {
9
7
  return config.map((config2, index) => {
10
8
  if (!config2 || config2.name) {
@@ -1,10 +1,8 @@
1
1
  import {
2
- __name,
3
- init_esm_shims
4
- } from "./chunk-LCTBQU5F.js";
2
+ __name
3
+ } from "./chunk-SHUYVCID.js";
5
4
 
6
5
  // src/utils/correct-paths.ts
7
- init_esm_shims();
8
6
  var _DRIVE_LETTER_START_RE = /^[A-Za-z]:\//;
9
7
  function normalizeWindowsPath(input = "") {
10
8
  if (!input) {
@@ -1,9 +1,4 @@
1
- import {
2
- init_esm_shims
3
- } from "./chunk-LCTBQU5F.js";
4
-
5
1
  // src/utils/ignores.ts
6
- init_esm_shims();
7
2
  var DEFAULT_IGNORES = [
8
3
  "**/.git/**",
9
4
  "**/node_modules/**",
@@ -0,0 +1,6 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
3
+
4
+ export {
5
+ __name
6
+ };
@@ -1,16 +1,14 @@
1
1
  import {
2
2
  getFileBanner
3
- } from "./chunk-FOMXGINY.js";
3
+ } from "./chunk-ZUIV57VZ.js";
4
4
  import {
5
5
  GLOB_SRC
6
- } from "./chunk-IQ2DH5EI.js";
6
+ } from "./chunk-AIKLBIPC.js";
7
7
  import {
8
- __name,
9
- init_esm_shims
10
- } from "./chunk-LCTBQU5F.js";
8
+ __name
9
+ } from "./chunk-SHUYVCID.js";
11
10
 
12
11
  // src/utils/banner-plugin.ts
13
- init_esm_shims();
14
12
  import { ESLintUtils } from "@typescript-eslint/utils";
15
13
  import os from "node:os";
16
14
  function match(actual, expected) {
@@ -1,13 +1,11 @@
1
1
  import {
2
2
  ACRONYMS_LIST
3
- } from "./chunk-IQ2DH5EI.js";
3
+ } from "./chunk-AIKLBIPC.js";
4
4
  import {
5
- __name,
6
- init_esm_shims
7
- } from "./chunk-LCTBQU5F.js";
5
+ __name
6
+ } from "./chunk-SHUYVCID.js";
8
7
 
9
8
  // src/utils/get-file-banner.ts
10
- init_esm_shims();
11
9
  var getFileBanner = /* @__PURE__ */ __name((repositoryName = "") => {
12
10
  if (!repositoryName) {
13
11
  repositoryName = process.env.STORM_NAME || "";
@@ -0,0 +1,415 @@
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
+ };