@podman-desktop/eslint-plugin 0.1.1 → 0.1.2
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/dist/index.js +114 -48
- package/dist/rules/copyright.d.ts +1 -0
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -1,7 +1,63 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
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.1.2", N = {
|
|
5
|
+
version: F
|
|
6
|
+
};
|
|
7
|
+
let Y, I, y, u;
|
|
8
|
+
function O() {
|
|
9
|
+
if (u !== void 0) return;
|
|
10
|
+
try {
|
|
11
|
+
y = g("git", ["rev-parse", "--show-toplevel"], {
|
|
12
|
+
stdio: "pipe",
|
|
13
|
+
encoding: "utf-8"
|
|
14
|
+
}).trim(), u = !0;
|
|
15
|
+
} catch {
|
|
16
|
+
u = !1;
|
|
17
|
+
return;
|
|
18
|
+
}
|
|
19
|
+
const e = /* @__PURE__ */ new Map();
|
|
20
|
+
Y = e;
|
|
21
|
+
const s = y;
|
|
22
|
+
try {
|
|
23
|
+
const i = g(
|
|
24
|
+
"git",
|
|
25
|
+
["log", "--format=format:COMMIT:%ad", "--date=format:%Y", "--name-only", "--diff-filter=ACDMRT"],
|
|
26
|
+
{ stdio: "pipe", encoding: "utf-8", maxBuffer: 52428800 }
|
|
27
|
+
);
|
|
28
|
+
let r;
|
|
29
|
+
for (const t of i.split(`
|
|
30
|
+
`))
|
|
31
|
+
if (t) {
|
|
32
|
+
if (t.startsWith("COMMIT:")) {
|
|
33
|
+
r = Number(t.slice(7));
|
|
34
|
+
continue;
|
|
35
|
+
}
|
|
36
|
+
if (r !== void 0) {
|
|
37
|
+
const o = m(s, t);
|
|
38
|
+
e.has(o) || e.set(o, r);
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
} catch {
|
|
42
|
+
u = !1;
|
|
43
|
+
}
|
|
44
|
+
const n = /* @__PURE__ */ new Set();
|
|
45
|
+
I = n;
|
|
46
|
+
try {
|
|
47
|
+
const i = g("git", ["status", "--porcelain"], {
|
|
48
|
+
stdio: "pipe",
|
|
49
|
+
encoding: "utf-8"
|
|
50
|
+
});
|
|
51
|
+
for (const r of i.split(`
|
|
52
|
+
`)) {
|
|
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));
|
|
56
|
+
}
|
|
57
|
+
} catch {
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
const R = [
|
|
5
61
|
"Copyright (C) {year} Red Hat, Inc.",
|
|
6
62
|
"",
|
|
7
63
|
'Licensed under the Apache License, Version 2.0 (the "License");',
|
|
@@ -17,38 +73,45 @@ const E = "0.1.1", L = {
|
|
|
17
73
|
"limitations under the License.",
|
|
18
74
|
"",
|
|
19
75
|
"SPDX-License-Identifier: Apache-2.0"
|
|
20
|
-
],
|
|
21
|
-
function
|
|
22
|
-
|
|
23
|
-
|
|
76
|
+
], $ = /Copyright \(C\) (\d{4})(?:[-,\s]+(\d{4}))* (.+)/;
|
|
77
|
+
function A(e) {
|
|
78
|
+
O();
|
|
79
|
+
const s = m(e);
|
|
80
|
+
if (I?.has(s))
|
|
81
|
+
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 });
|
|
86
|
+
return i ? i.mtime.getFullYear() : (/* @__PURE__ */ new Date()).getFullYear();
|
|
24
87
|
}
|
|
25
|
-
function
|
|
88
|
+
function P(e) {
|
|
26
89
|
return /\.ya?ml$/i.test(e);
|
|
27
90
|
}
|
|
28
|
-
const
|
|
29
|
-
function
|
|
30
|
-
return
|
|
91
|
+
const D = /\.(svelte|md)$/i;
|
|
92
|
+
function M(e) {
|
|
93
|
+
return D.test(e);
|
|
31
94
|
}
|
|
32
|
-
function
|
|
33
|
-
const
|
|
34
|
-
if (
|
|
35
|
-
const
|
|
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(`
|
|
36
99
|
`);
|
|
37
|
-
return `${
|
|
38
|
-
${
|
|
39
|
-
${
|
|
100
|
+
return `${t}
|
|
101
|
+
${o}
|
|
102
|
+
${t}
|
|
40
103
|
|
|
41
104
|
`;
|
|
42
105
|
}
|
|
43
|
-
const i = "*".repeat(79),
|
|
106
|
+
const i = "*".repeat(79), r = n.map((t) => t === "" ? " *" : ` * ${t}`).join(`
|
|
44
107
|
`);
|
|
45
108
|
return `/${i}
|
|
46
|
-
${
|
|
109
|
+
${r}
|
|
47
110
|
${i}/
|
|
48
111
|
|
|
49
112
|
`;
|
|
50
113
|
}
|
|
51
|
-
const
|
|
114
|
+
const H = {
|
|
52
115
|
meta: {
|
|
53
116
|
type: "suggestion",
|
|
54
117
|
docs: {
|
|
@@ -62,64 +125,67 @@ const A = {
|
|
|
62
125
|
}
|
|
63
126
|
},
|
|
64
127
|
create(e) {
|
|
65
|
-
const
|
|
66
|
-
if (
|
|
128
|
+
const s = e.filename;
|
|
129
|
+
if (M(s))
|
|
67
130
|
return {};
|
|
68
|
-
let
|
|
131
|
+
let n;
|
|
69
132
|
function i() {
|
|
70
|
-
return
|
|
133
|
+
return n === void 0 && (n = A(s)), n;
|
|
71
134
|
}
|
|
72
135
|
return {
|
|
73
|
-
Program(
|
|
74
|
-
const
|
|
136
|
+
Program(r) {
|
|
137
|
+
const o = e.sourceCode.getText(), c = o.split(`
|
|
75
138
|
`).slice(0, 30).join(`
|
|
76
|
-
`),
|
|
77
|
-
if (!
|
|
139
|
+
`), a = $.exec(c);
|
|
140
|
+
if (!a) {
|
|
78
141
|
e.report({
|
|
79
|
-
node:
|
|
142
|
+
node: r,
|
|
80
143
|
messageId: "missingHeader",
|
|
81
|
-
fix(
|
|
82
|
-
const
|
|
83
|
-
return
|
|
144
|
+
fix(f) {
|
|
145
|
+
const v = j(String((/* @__PURE__ */ new Date()).getFullYear()), s);
|
|
146
|
+
return f.insertTextBeforeRange([0, 0], v);
|
|
84
147
|
}
|
|
85
148
|
});
|
|
86
149
|
return;
|
|
87
150
|
}
|
|
88
|
-
const
|
|
89
|
-
if (
|
|
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)
|
|
153
|
+
return;
|
|
154
|
+
const x = i();
|
|
155
|
+
if (h >= x)
|
|
90
156
|
return;
|
|
91
|
-
const d =
|
|
157
|
+
const d = o.indexOf(a[0]);
|
|
92
158
|
if (d === -1) return;
|
|
93
|
-
const
|
|
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}`;
|
|
94
160
|
e.report({
|
|
95
|
-
node:
|
|
161
|
+
node: r,
|
|
96
162
|
messageId: "outdatedYear",
|
|
97
|
-
fix(
|
|
98
|
-
return
|
|
163
|
+
fix(f) {
|
|
164
|
+
return f.replaceTextRange([L, T], b);
|
|
99
165
|
}
|
|
100
166
|
});
|
|
101
167
|
}
|
|
102
168
|
};
|
|
103
169
|
}
|
|
104
|
-
},
|
|
170
|
+
}, S = {
|
|
105
171
|
meta: {
|
|
106
172
|
name: "@podman-desktop/eslint-plugin",
|
|
107
|
-
version:
|
|
173
|
+
version: N.version
|
|
108
174
|
},
|
|
109
175
|
rules: {
|
|
110
|
-
copyright:
|
|
176
|
+
copyright: H
|
|
111
177
|
},
|
|
112
178
|
configs: {}
|
|
113
|
-
},
|
|
114
|
-
|
|
179
|
+
}, k = S.configs;
|
|
180
|
+
k.recommended = {
|
|
115
181
|
files: ["**/*.{js,mjs,cjs,ts,mts,cts,jsx,tsx}"],
|
|
116
182
|
plugins: {
|
|
117
|
-
"@podman-desktop/eslint-plugin":
|
|
183
|
+
"@podman-desktop/eslint-plugin": S
|
|
118
184
|
},
|
|
119
185
|
rules: {
|
|
120
186
|
"@podman-desktop/eslint-plugin/copyright": "error"
|
|
121
187
|
}
|
|
122
188
|
};
|
|
123
189
|
export {
|
|
124
|
-
|
|
190
|
+
S as default
|
|
125
191
|
};
|