@stardeck-customer-apps/eslint-plugin 1.1.0 → 1.2.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/dist/index.cjs +143 -2
- package/dist/index.d.cts +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +133 -2
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
2
3
|
var __defProp = Object.defineProperty;
|
|
3
4
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
5
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
5
7
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
8
|
var __export = (target, all) => {
|
|
7
9
|
for (var name in all)
|
|
@@ -15,6 +17,14 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
15
17
|
}
|
|
16
18
|
return to;
|
|
17
19
|
};
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
+
mod
|
|
27
|
+
));
|
|
18
28
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
29
|
|
|
20
30
|
// src/index.ts
|
|
@@ -112,10 +122,140 @@ var rule2 = {
|
|
|
112
122
|
};
|
|
113
123
|
var no_kysely_interactive_transaction_default = rule2;
|
|
114
124
|
|
|
125
|
+
// src/rules/no-module-internal-import.ts
|
|
126
|
+
var import_node_path = __toESM(require("path"), 1);
|
|
127
|
+
var ALIAS_PREFIX = "@/";
|
|
128
|
+
function toPosix(filePath) {
|
|
129
|
+
return filePath.split(import_node_path.default.sep).join("/");
|
|
130
|
+
}
|
|
131
|
+
function findSrcRoot(filename) {
|
|
132
|
+
const parts = toPosix(filename).split("/");
|
|
133
|
+
for (let i = 0; i < parts.length - 1; i++) {
|
|
134
|
+
if (parts[i] === "src" && parts[i + 1] === "modules") {
|
|
135
|
+
return parts.slice(0, i + 1).join("/");
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
let lastSrcIdx = -1;
|
|
139
|
+
for (let i = 0; i < parts.length; i++) {
|
|
140
|
+
if (parts[i] === "src") lastSrcIdx = i;
|
|
141
|
+
}
|
|
142
|
+
if (lastSrcIdx === -1) return null;
|
|
143
|
+
return parts.slice(0, lastSrcIdx + 1).join("/");
|
|
144
|
+
}
|
|
145
|
+
function normalizePosixPath(raw) {
|
|
146
|
+
const absolute = raw.startsWith("/");
|
|
147
|
+
const parts = raw.split("/");
|
|
148
|
+
const stack = [];
|
|
149
|
+
for (const part of parts) {
|
|
150
|
+
if (part === "" || part === ".") continue;
|
|
151
|
+
if (part === "..") {
|
|
152
|
+
if (stack.length === 0) return null;
|
|
153
|
+
stack.pop();
|
|
154
|
+
continue;
|
|
155
|
+
}
|
|
156
|
+
stack.push(part);
|
|
157
|
+
}
|
|
158
|
+
const joined = stack.join("/");
|
|
159
|
+
return absolute ? `/${joined}` : joined;
|
|
160
|
+
}
|
|
161
|
+
function dirnamePosix(filePath) {
|
|
162
|
+
const idx = filePath.lastIndexOf("/");
|
|
163
|
+
if (idx <= 0) return "/";
|
|
164
|
+
return filePath.slice(0, idx);
|
|
165
|
+
}
|
|
166
|
+
function resolveImportPath(filename, srcRoot, specifier) {
|
|
167
|
+
let candidate;
|
|
168
|
+
if (specifier.startsWith(ALIAS_PREFIX)) {
|
|
169
|
+
candidate = `${srcRoot}/${specifier.slice(ALIAS_PREFIX.length)}`;
|
|
170
|
+
} else if (specifier.startsWith("./") || specifier.startsWith("../")) {
|
|
171
|
+
candidate = `${dirnamePosix(toPosix(filename))}/${specifier}`;
|
|
172
|
+
} else {
|
|
173
|
+
return null;
|
|
174
|
+
}
|
|
175
|
+
const normalized = normalizePosixPath(candidate);
|
|
176
|
+
if (!normalized) return null;
|
|
177
|
+
if (normalized !== srcRoot && !normalized.startsWith(`${srcRoot}/`)) {
|
|
178
|
+
return null;
|
|
179
|
+
}
|
|
180
|
+
return normalized;
|
|
181
|
+
}
|
|
182
|
+
function getModuleName(filePath, srcRoot) {
|
|
183
|
+
if (!filePath.startsWith(`${srcRoot}/`)) return null;
|
|
184
|
+
const rel = filePath.slice(srcRoot.length + 1);
|
|
185
|
+
const match = /^modules\/([^/]+)/.exec(rel);
|
|
186
|
+
return match ? match[1] : null;
|
|
187
|
+
}
|
|
188
|
+
function isPublicSurface(resolvedPath, srcRoot, moduleName) {
|
|
189
|
+
const base = `${srcRoot}/modules/${moduleName}`;
|
|
190
|
+
if (resolvedPath === base) return true;
|
|
191
|
+
if (resolvedPath === `${base}/index`) return true;
|
|
192
|
+
if (resolvedPath === `${base}/index.ts`) return true;
|
|
193
|
+
if (resolvedPath === `${base}/index.tsx`) return true;
|
|
194
|
+
return false;
|
|
195
|
+
}
|
|
196
|
+
var rule3 = {
|
|
197
|
+
meta: {
|
|
198
|
+
type: "problem",
|
|
199
|
+
docs: {
|
|
200
|
+
description: "Disallow imports that reach into a vendored module's internals; import only through `@/modules/<name>` (its index)",
|
|
201
|
+
recommended: true
|
|
202
|
+
},
|
|
203
|
+
messages: {
|
|
204
|
+
noInternalImport: "Import '{{module}}' through its public surface ('@/modules/{{module}}') \u2014 '{{source}}' reaches into module internals, which breaks module install/update isolation."
|
|
205
|
+
},
|
|
206
|
+
schema: []
|
|
207
|
+
},
|
|
208
|
+
create(context) {
|
|
209
|
+
const filename = context.filename;
|
|
210
|
+
if (!filename || filename === "<input>" || filename === "<text>") {
|
|
211
|
+
return {};
|
|
212
|
+
}
|
|
213
|
+
const srcRoot = findSrcRoot(filename);
|
|
214
|
+
if (!srcRoot) {
|
|
215
|
+
return {};
|
|
216
|
+
}
|
|
217
|
+
const root = srcRoot;
|
|
218
|
+
const importerModule = getModuleName(toPosix(filename), root);
|
|
219
|
+
function check(node, sourceNode) {
|
|
220
|
+
if (!sourceNode || sourceNode.type !== "Literal") return;
|
|
221
|
+
const value = sourceNode.value;
|
|
222
|
+
if (typeof value !== "string") return;
|
|
223
|
+
const resolved = resolveImportPath(filename, root, value);
|
|
224
|
+
if (!resolved) return;
|
|
225
|
+
const targetModule = getModuleName(resolved, root);
|
|
226
|
+
if (!targetModule) return;
|
|
227
|
+
if (isPublicSurface(resolved, root, targetModule)) return;
|
|
228
|
+
if (importerModule === targetModule) return;
|
|
229
|
+
context.report({
|
|
230
|
+
node,
|
|
231
|
+
messageId: "noInternalImport",
|
|
232
|
+
data: { module: targetModule, source: value }
|
|
233
|
+
});
|
|
234
|
+
}
|
|
235
|
+
return {
|
|
236
|
+
ImportDeclaration(node) {
|
|
237
|
+
check(node, node.source);
|
|
238
|
+
},
|
|
239
|
+
ImportExpression(node) {
|
|
240
|
+
const src = node.source;
|
|
241
|
+
check(node, src);
|
|
242
|
+
},
|
|
243
|
+
ExportNamedDeclaration(node) {
|
|
244
|
+
check(node, node.source);
|
|
245
|
+
},
|
|
246
|
+
ExportAllDeclaration(node) {
|
|
247
|
+
check(node, node.source);
|
|
248
|
+
}
|
|
249
|
+
};
|
|
250
|
+
}
|
|
251
|
+
};
|
|
252
|
+
var no_module_internal_import_default = rule3;
|
|
253
|
+
|
|
115
254
|
// src/rules/index.ts
|
|
116
255
|
var rules = {
|
|
117
256
|
"no-template-literal-classname": no_template_literal_classname_default,
|
|
118
|
-
"no-kysely-interactive-transaction": no_kysely_interactive_transaction_default
|
|
257
|
+
"no-kysely-interactive-transaction": no_kysely_interactive_transaction_default,
|
|
258
|
+
"no-module-internal-import": no_module_internal_import_default
|
|
119
259
|
};
|
|
120
260
|
|
|
121
261
|
// src/configs/recommended.ts
|
|
@@ -128,7 +268,8 @@ var recommended = {
|
|
|
128
268
|
},
|
|
129
269
|
rules: {
|
|
130
270
|
[`${pluginName}/no-template-literal-classname`]: "error",
|
|
131
|
-
[`${pluginName}/no-kysely-interactive-transaction`]: "error"
|
|
271
|
+
[`${pluginName}/no-kysely-interactive-transaction`]: "error",
|
|
272
|
+
[`${pluginName}/no-module-internal-import`]: "error"
|
|
132
273
|
}
|
|
133
274
|
};
|
|
134
275
|
|
package/dist/index.d.cts
CHANGED
|
@@ -4,6 +4,7 @@ import { Linter, ESLint } from 'eslint';
|
|
|
4
4
|
declare const rules: {
|
|
5
5
|
"no-template-literal-classname": eslint.Rule.RuleModule;
|
|
6
6
|
"no-kysely-interactive-transaction": eslint.Rule.RuleModule;
|
|
7
|
+
"no-module-internal-import": eslint.Rule.RuleModule;
|
|
7
8
|
};
|
|
8
9
|
|
|
9
10
|
declare const configs: Record<string, Linter.Config>;
|
package/dist/index.d.ts
CHANGED
|
@@ -4,6 +4,7 @@ import { Linter, ESLint } from 'eslint';
|
|
|
4
4
|
declare const rules: {
|
|
5
5
|
"no-template-literal-classname": eslint.Rule.RuleModule;
|
|
6
6
|
"no-kysely-interactive-transaction": eslint.Rule.RuleModule;
|
|
7
|
+
"no-module-internal-import": eslint.Rule.RuleModule;
|
|
7
8
|
};
|
|
8
9
|
|
|
9
10
|
declare const configs: Record<string, Linter.Config>;
|
package/dist/index.js
CHANGED
|
@@ -84,10 +84,140 @@ var rule2 = {
|
|
|
84
84
|
};
|
|
85
85
|
var no_kysely_interactive_transaction_default = rule2;
|
|
86
86
|
|
|
87
|
+
// src/rules/no-module-internal-import.ts
|
|
88
|
+
import path from "path";
|
|
89
|
+
var ALIAS_PREFIX = "@/";
|
|
90
|
+
function toPosix(filePath) {
|
|
91
|
+
return filePath.split(path.sep).join("/");
|
|
92
|
+
}
|
|
93
|
+
function findSrcRoot(filename) {
|
|
94
|
+
const parts = toPosix(filename).split("/");
|
|
95
|
+
for (let i = 0; i < parts.length - 1; i++) {
|
|
96
|
+
if (parts[i] === "src" && parts[i + 1] === "modules") {
|
|
97
|
+
return parts.slice(0, i + 1).join("/");
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
let lastSrcIdx = -1;
|
|
101
|
+
for (let i = 0; i < parts.length; i++) {
|
|
102
|
+
if (parts[i] === "src") lastSrcIdx = i;
|
|
103
|
+
}
|
|
104
|
+
if (lastSrcIdx === -1) return null;
|
|
105
|
+
return parts.slice(0, lastSrcIdx + 1).join("/");
|
|
106
|
+
}
|
|
107
|
+
function normalizePosixPath(raw) {
|
|
108
|
+
const absolute = raw.startsWith("/");
|
|
109
|
+
const parts = raw.split("/");
|
|
110
|
+
const stack = [];
|
|
111
|
+
for (const part of parts) {
|
|
112
|
+
if (part === "" || part === ".") continue;
|
|
113
|
+
if (part === "..") {
|
|
114
|
+
if (stack.length === 0) return null;
|
|
115
|
+
stack.pop();
|
|
116
|
+
continue;
|
|
117
|
+
}
|
|
118
|
+
stack.push(part);
|
|
119
|
+
}
|
|
120
|
+
const joined = stack.join("/");
|
|
121
|
+
return absolute ? `/${joined}` : joined;
|
|
122
|
+
}
|
|
123
|
+
function dirnamePosix(filePath) {
|
|
124
|
+
const idx = filePath.lastIndexOf("/");
|
|
125
|
+
if (idx <= 0) return "/";
|
|
126
|
+
return filePath.slice(0, idx);
|
|
127
|
+
}
|
|
128
|
+
function resolveImportPath(filename, srcRoot, specifier) {
|
|
129
|
+
let candidate;
|
|
130
|
+
if (specifier.startsWith(ALIAS_PREFIX)) {
|
|
131
|
+
candidate = `${srcRoot}/${specifier.slice(ALIAS_PREFIX.length)}`;
|
|
132
|
+
} else if (specifier.startsWith("./") || specifier.startsWith("../")) {
|
|
133
|
+
candidate = `${dirnamePosix(toPosix(filename))}/${specifier}`;
|
|
134
|
+
} else {
|
|
135
|
+
return null;
|
|
136
|
+
}
|
|
137
|
+
const normalized = normalizePosixPath(candidate);
|
|
138
|
+
if (!normalized) return null;
|
|
139
|
+
if (normalized !== srcRoot && !normalized.startsWith(`${srcRoot}/`)) {
|
|
140
|
+
return null;
|
|
141
|
+
}
|
|
142
|
+
return normalized;
|
|
143
|
+
}
|
|
144
|
+
function getModuleName(filePath, srcRoot) {
|
|
145
|
+
if (!filePath.startsWith(`${srcRoot}/`)) return null;
|
|
146
|
+
const rel = filePath.slice(srcRoot.length + 1);
|
|
147
|
+
const match = /^modules\/([^/]+)/.exec(rel);
|
|
148
|
+
return match ? match[1] : null;
|
|
149
|
+
}
|
|
150
|
+
function isPublicSurface(resolvedPath, srcRoot, moduleName) {
|
|
151
|
+
const base = `${srcRoot}/modules/${moduleName}`;
|
|
152
|
+
if (resolvedPath === base) return true;
|
|
153
|
+
if (resolvedPath === `${base}/index`) return true;
|
|
154
|
+
if (resolvedPath === `${base}/index.ts`) return true;
|
|
155
|
+
if (resolvedPath === `${base}/index.tsx`) return true;
|
|
156
|
+
return false;
|
|
157
|
+
}
|
|
158
|
+
var rule3 = {
|
|
159
|
+
meta: {
|
|
160
|
+
type: "problem",
|
|
161
|
+
docs: {
|
|
162
|
+
description: "Disallow imports that reach into a vendored module's internals; import only through `@/modules/<name>` (its index)",
|
|
163
|
+
recommended: true
|
|
164
|
+
},
|
|
165
|
+
messages: {
|
|
166
|
+
noInternalImport: "Import '{{module}}' through its public surface ('@/modules/{{module}}') \u2014 '{{source}}' reaches into module internals, which breaks module install/update isolation."
|
|
167
|
+
},
|
|
168
|
+
schema: []
|
|
169
|
+
},
|
|
170
|
+
create(context) {
|
|
171
|
+
const filename = context.filename;
|
|
172
|
+
if (!filename || filename === "<input>" || filename === "<text>") {
|
|
173
|
+
return {};
|
|
174
|
+
}
|
|
175
|
+
const srcRoot = findSrcRoot(filename);
|
|
176
|
+
if (!srcRoot) {
|
|
177
|
+
return {};
|
|
178
|
+
}
|
|
179
|
+
const root = srcRoot;
|
|
180
|
+
const importerModule = getModuleName(toPosix(filename), root);
|
|
181
|
+
function check(node, sourceNode) {
|
|
182
|
+
if (!sourceNode || sourceNode.type !== "Literal") return;
|
|
183
|
+
const value = sourceNode.value;
|
|
184
|
+
if (typeof value !== "string") return;
|
|
185
|
+
const resolved = resolveImportPath(filename, root, value);
|
|
186
|
+
if (!resolved) return;
|
|
187
|
+
const targetModule = getModuleName(resolved, root);
|
|
188
|
+
if (!targetModule) return;
|
|
189
|
+
if (isPublicSurface(resolved, root, targetModule)) return;
|
|
190
|
+
if (importerModule === targetModule) return;
|
|
191
|
+
context.report({
|
|
192
|
+
node,
|
|
193
|
+
messageId: "noInternalImport",
|
|
194
|
+
data: { module: targetModule, source: value }
|
|
195
|
+
});
|
|
196
|
+
}
|
|
197
|
+
return {
|
|
198
|
+
ImportDeclaration(node) {
|
|
199
|
+
check(node, node.source);
|
|
200
|
+
},
|
|
201
|
+
ImportExpression(node) {
|
|
202
|
+
const src = node.source;
|
|
203
|
+
check(node, src);
|
|
204
|
+
},
|
|
205
|
+
ExportNamedDeclaration(node) {
|
|
206
|
+
check(node, node.source);
|
|
207
|
+
},
|
|
208
|
+
ExportAllDeclaration(node) {
|
|
209
|
+
check(node, node.source);
|
|
210
|
+
}
|
|
211
|
+
};
|
|
212
|
+
}
|
|
213
|
+
};
|
|
214
|
+
var no_module_internal_import_default = rule3;
|
|
215
|
+
|
|
87
216
|
// src/rules/index.ts
|
|
88
217
|
var rules = {
|
|
89
218
|
"no-template-literal-classname": no_template_literal_classname_default,
|
|
90
|
-
"no-kysely-interactive-transaction": no_kysely_interactive_transaction_default
|
|
219
|
+
"no-kysely-interactive-transaction": no_kysely_interactive_transaction_default,
|
|
220
|
+
"no-module-internal-import": no_module_internal_import_default
|
|
91
221
|
};
|
|
92
222
|
|
|
93
223
|
// src/configs/recommended.ts
|
|
@@ -100,7 +230,8 @@ var recommended = {
|
|
|
100
230
|
},
|
|
101
231
|
rules: {
|
|
102
232
|
[`${pluginName}/no-template-literal-classname`]: "error",
|
|
103
|
-
[`${pluginName}/no-kysely-interactive-transaction`]: "error"
|
|
233
|
+
[`${pluginName}/no-kysely-interactive-transaction`]: "error",
|
|
234
|
+
[`${pluginName}/no-module-internal-import`]: "error"
|
|
104
235
|
}
|
|
105
236
|
};
|
|
106
237
|
|