@podman-desktop/eslint-plugin 0.2.0 → 0.3.0-next.202603061658-1db9d75

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.
Files changed (2) hide show
  1. package/dist/index.js +122 -80
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -1,63 +1,102 @@
1
- import { execFileSync as g } from "node:child_process";
2
- import { lstatSync as E } from "node:fs";
3
- import { resolve as m } from "node:path";
4
- const F = "0.2.0", N = {
5
- version: F
1
+ import { execFileSync as p } from "node:child_process";
2
+ import { lstatSync as O, readFileSync as P } from "node:fs";
3
+ import { resolve as l } from "node:path";
4
+ const L = "0.3.0-next.202603061658-1db9d75", $ = {
5
+ version: L
6
6
  };
7
- let Y, I, y, u;
8
- function O() {
9
- if (u !== void 0) return;
7
+ let S, Y, d, f, y = !1, T;
8
+ function A() {
9
+ return process.env.GITHUB_ACTIONS === "true" && process.env.GITHUB_EVENT_NAME === "pull_request";
10
+ }
11
+ function H() {
12
+ const e = process.env.GITHUB_REF;
13
+ if (e) {
14
+ const t = /^refs\/pull\/(\d+)\/merge$/.exec(e);
15
+ if (t) return t[1];
16
+ }
17
+ const r = process.env.GITHUB_EVENT_PATH;
18
+ if (r)
19
+ try {
20
+ const t = JSON.parse(P(r, "utf-8"));
21
+ if (t?.pull_request?.number) return String(t.pull_request.number);
22
+ } catch {
23
+ }
24
+ }
25
+ function _(e) {
26
+ if (!A()) return !1;
27
+ const r = H();
28
+ if (!r) return !1;
29
+ const t = process.env.GITHUB_REPOSITORY;
30
+ if (!t) return !1;
31
+ try {
32
+ const i = p(
33
+ "gh",
34
+ ["api", "--paginate", `repos/${t}/pulls/${r}/files`, "--jq", ".[].filename"],
35
+ { stdio: "pipe", encoding: "utf-8" }
36
+ ), s = /* @__PURE__ */ new Set();
37
+ for (const n of i.split(`
38
+ `))
39
+ n && s.add(l(e, n));
40
+ return T = s, y = !0, !0;
41
+ } catch {
42
+ return !1;
43
+ }
44
+ }
45
+ function v() {
46
+ if (f !== void 0) return;
10
47
  try {
11
- y = g("git", ["rev-parse", "--show-toplevel"], {
48
+ d = p("git", ["rev-parse", "--show-toplevel"], {
12
49
  stdio: "pipe",
13
50
  encoding: "utf-8"
14
- }).trim(), u = !0;
51
+ }).trim(), f = !0;
15
52
  } catch {
16
- u = !1;
53
+ f = !1;
17
54
  return;
18
55
  }
56
+ if (_(d))
57
+ return;
19
58
  const e = /* @__PURE__ */ new Map();
20
- Y = e;
21
- const s = y;
59
+ S = e;
60
+ const r = d;
22
61
  try {
23
- const i = g(
62
+ const i = p(
24
63
  "git",
25
64
  ["log", "--format=format:COMMIT:%ad", "--date=format:%Y", "--name-only", "--diff-filter=ACDMRT"],
26
65
  { stdio: "pipe", encoding: "utf-8", maxBuffer: 52428800 }
27
66
  );
28
- let r;
29
- for (const t of i.split(`
67
+ let s;
68
+ for (const n of i.split(`
30
69
  `))
31
- if (t) {
32
- if (t.startsWith("COMMIT:")) {
33
- r = Number(t.slice(7));
70
+ if (n) {
71
+ if (n.startsWith("COMMIT:")) {
72
+ s = Number(n.slice(7));
34
73
  continue;
35
74
  }
36
- if (r !== void 0) {
37
- const o = m(s, t);
38
- e.has(o) || e.set(o, r);
75
+ if (s !== void 0) {
76
+ const o = l(r, n);
77
+ e.has(o) || e.set(o, s);
39
78
  }
40
79
  }
41
80
  } catch {
42
- u = !1;
81
+ f = !1;
43
82
  }
44
- const n = /* @__PURE__ */ new Set();
45
- I = n;
83
+ const t = /* @__PURE__ */ new Set();
84
+ Y = t;
46
85
  try {
47
- const i = g("git", ["status", "--porcelain"], {
86
+ const i = p("git", ["status", "--porcelain"], {
48
87
  stdio: "pipe",
49
88
  encoding: "utf-8"
50
89
  });
51
- for (const r of i.split(`
90
+ for (const s of i.split(`
52
91
  `)) {
53
- if (!r || r.length < 4) continue;
54
- const t = r.slice(3), o = t.indexOf(" -> "), c = o !== -1 ? t.slice(o + 4) : t;
55
- n.add(m(s, c));
92
+ if (!s || s.length < 4) continue;
93
+ const n = s.slice(3), o = n.indexOf(" -> "), c = o !== -1 ? n.slice(o + 4) : n;
94
+ t.add(l(r, c));
56
95
  }
57
96
  } catch {
58
97
  }
59
98
  }
60
- const R = [
99
+ const D = [
61
100
  "Copyright (C) {year} Red Hat, Inc.",
62
101
  "",
63
102
  'Licensed under the Apache License, Version 2.0 (the "License");',
@@ -73,45 +112,46 @@ const R = [
73
112
  "limitations under the License.",
74
113
  "",
75
114
  "SPDX-License-Identifier: Apache-2.0"
76
- ], $ = /Copyright \(C\) (\d{4})(?:[-,\s]+(\d{4}))* (.+)/;
77
- function A(e) {
78
- O();
79
- const s = m(e);
80
- if (I?.has(s))
115
+ ], M = /Copyright \(C\) (\d{4})(?:[-,\s]+(\d{4}))* (.+)/;
116
+ function G(e) {
117
+ if (v(), y)
118
+ return (/* @__PURE__ */ new Date()).getFullYear();
119
+ const r = l(e);
120
+ if (Y?.has(r))
81
121
  return (/* @__PURE__ */ new Date()).getFullYear();
82
- const n = Y?.get(s);
83
- if (n !== void 0)
84
- return n;
85
- const i = E(e, { throwIfNoEntry: !1 });
122
+ const t = S?.get(r);
123
+ if (t !== void 0)
124
+ return t;
125
+ const i = O(e, { throwIfNoEntry: !1 });
86
126
  return i ? i.mtime.getFullYear() : (/* @__PURE__ */ new Date()).getFullYear();
87
127
  }
88
- function P(e) {
128
+ function j(e) {
89
129
  return /\.ya?ml$/i.test(e);
90
130
  }
91
- const D = /\.(svelte|md)$/i;
92
- function M(e) {
93
- return D.test(e);
131
+ const B = /\.(svelte|md)$/i;
132
+ function U(e) {
133
+ return B.test(e);
94
134
  }
95
- function j(e, s) {
96
- const n = R.map((t) => t.replace("{year}", e));
97
- if (P(s)) {
98
- const t = "#" + "*".repeat(79), o = n.map((c) => c === "" ? "#" : `# ${c}`).join(`
135
+ function q(e, r) {
136
+ const t = D.map((n) => n.replace("{year}", e));
137
+ if (j(r)) {
138
+ const n = "#" + "*".repeat(79), o = t.map((c) => c === "" ? "#" : `# ${c}`).join(`
99
139
  `);
100
- return `${t}
140
+ return `${n}
101
141
  ${o}
102
- ${t}
142
+ ${n}
103
143
 
104
144
  `;
105
145
  }
106
- const i = "*".repeat(79), r = n.map((t) => t === "" ? " *" : ` * ${t}`).join(`
146
+ const i = "*".repeat(79), s = t.map((n) => n === "" ? " *" : ` * ${n}`).join(`
107
147
  `);
108
148
  return `/${i}
109
- ${r}
149
+ ${s}
110
150
  ${i}/
111
151
 
112
152
  `;
113
153
  }
114
- const H = {
154
+ const k = {
115
155
  meta: {
116
156
  type: "suggestion",
117
157
  docs: {
@@ -125,67 +165,69 @@ const H = {
125
165
  }
126
166
  },
127
167
  create(e) {
128
- const s = e.filename;
129
- if (M(s))
168
+ const r = e.filename;
169
+ if (U(r))
170
+ return {};
171
+ if (v(), y && !T?.has(l(d ?? "", r)))
130
172
  return {};
131
- let n;
173
+ let t;
132
174
  function i() {
133
- return n === void 0 && (n = A(s)), n;
175
+ return t === void 0 && (t = G(r)), t;
134
176
  }
135
177
  return {
136
- Program(r) {
178
+ Program(s) {
137
179
  const o = e.sourceCode.getText(), c = o.split(`
138
180
  `).slice(0, 30).join(`
139
- `), a = $.exec(c);
181
+ `), a = M.exec(c);
140
182
  if (!a) {
141
183
  e.report({
142
- node: r,
184
+ node: s,
143
185
  messageId: "missingHeader",
144
- fix(f) {
145
- const v = j(String((/* @__PURE__ */ new Date()).getFullYear()), s);
146
- return f.insertTextBeforeRange([0, 0], v);
186
+ fix(h) {
187
+ const F = q(String((/* @__PURE__ */ new Date()).getFullYear()), r);
188
+ return h.insertTextBeforeRange([0, 0], F);
147
189
  }
148
190
  });
149
191
  return;
150
192
  }
151
- const p = Number.parseInt(a[1], 10), h = (a[2] ? Number.parseInt(a[2], 10) : null) ?? p, l = (/* @__PURE__ */ new Date()).getFullYear();
152
- if (h >= l)
193
+ const g = Number.parseInt(a[1], 10), I = (a[2] ? Number.parseInt(a[2], 10) : null) ?? g, u = (/* @__PURE__ */ new Date()).getFullYear();
194
+ if (I >= u)
153
195
  return;
154
- const x = i();
155
- if (h >= x)
196
+ const E = i();
197
+ if (I >= E)
156
198
  return;
157
- const d = o.indexOf(a[0]);
158
- if (d === -1) return;
159
- const w = 14, C = a[3].length + 1, L = d + w, T = d + a[0].length - C, b = p === l ? String(l) : `${p}-${l}`;
199
+ const m = o.indexOf(a[0]);
200
+ if (m === -1) return;
201
+ const b = 14, N = a[3].length + 1, w = m + b, C = m + a[0].length - N, R = g === u ? String(u) : `${g}-${u}`;
160
202
  e.report({
161
- node: r,
203
+ node: s,
162
204
  messageId: "outdatedYear",
163
- fix(f) {
164
- return f.replaceTextRange([L, T], b);
205
+ fix(h) {
206
+ return h.replaceTextRange([w, C], R);
165
207
  }
166
208
  });
167
209
  }
168
210
  };
169
211
  }
170
- }, S = {
212
+ }, x = {
171
213
  meta: {
172
214
  name: "@podman-desktop/eslint-plugin",
173
- version: N.version
215
+ version: $.version
174
216
  },
175
217
  rules: {
176
- copyright: H
218
+ copyright: k
177
219
  },
178
220
  configs: {}
179
- }, k = S.configs;
180
- k.recommended = {
221
+ }, V = x.configs;
222
+ V.recommended = {
181
223
  files: ["**/*.{js,mjs,cjs,ts,mts,cts,jsx,tsx}"],
182
224
  plugins: {
183
- "@podman-desktop/eslint-plugin": S
225
+ "@podman-desktop/eslint-plugin": x
184
226
  },
185
227
  rules: {
186
228
  "@podman-desktop/eslint-plugin/copyright": "error"
187
229
  }
188
230
  };
189
231
  export {
190
- S as default
232
+ x as default
191
233
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@podman-desktop/eslint-plugin",
3
- "version": "0.2.0",
3
+ "version": "0.3.0-next.202603061658-1db9d75",
4
4
  "description": "ESLint plugin with rules for Podman Desktop",
5
5
  "license": "Apache-2.0",
6
6
  "repository": {