lint-suite 1.6.2 → 1.6.3
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 +149 -2
- package/eslint.cjs +1049 -309
- package/eslint.cjs.map +4 -4
- package/eslint.js +938 -175
- package/eslint.js.map +4 -4
- package/lib/angular-template.d.ts +1 -0
- package/lib/angular-template.d.ts.map +1 -1
- package/lib/angular.d.ts.map +1 -1
- package/lib/base-practices.d.ts.map +1 -1
- package/lib/line-length.const.d.ts +2 -0
- package/lib/line-length.const.d.ts.map +1 -0
- package/lib/rules/common/class-usage.type.d.ts +25 -0
- package/lib/rules/common/class-usage.type.d.ts.map +1 -0
- package/lib/rules/component-metadata.d.ts +5 -0
- package/lib/rules/component-metadata.d.ts.map +1 -0
- package/lib/rules/no-unstyled-classes/common/no-unstyled-classes.type.d.ts +33 -0
- package/lib/rules/no-unstyled-classes/common/no-unstyled-classes.type.d.ts.map +1 -0
- package/lib/rules/no-unstyled-classes/no-unstyled-classes.d.ts +8 -0
- package/lib/rules/no-unstyled-classes/no-unstyled-classes.d.ts.map +1 -0
- package/lib/rules/no-unstyled-classes/styles/component-stylesheets.d.ts +4 -0
- package/lib/rules/no-unstyled-classes/styles/component-stylesheets.d.ts.map +1 -0
- package/lib/rules/no-unstyled-classes/styles/stylesheet-classes.d.ts +3 -0
- package/lib/rules/no-unstyled-classes/styles/stylesheet-classes.d.ts.map +1 -0
- package/lib/rules/no-unstyled-classes/styles/stylesheet-collection.d.ts +4 -0
- package/lib/rules/no-unstyled-classes/styles/stylesheet-collection.d.ts.map +1 -0
- package/lib/rules/no-unstyled-classes/styles/stylesheet-imports.d.ts +2 -0
- package/lib/rules/no-unstyled-classes/styles/stylesheet-imports.d.ts.map +1 -0
- package/lib/rules/no-unstyled-classes/styles/template-stylesheets.d.ts +3 -0
- package/lib/rules/no-unstyled-classes/styles/template-stylesheets.d.ts.map +1 -0
- package/lib/rules/no-unused-angular-instance-fields/rule/angular/angular-metadata-literals.d.ts.map +1 -1
- package/lib/rules/no-unused-classes/common/no-unused-classes.type.d.ts +24 -0
- package/lib/rules/no-unused-classes/common/no-unused-classes.type.d.ts.map +1 -0
- package/lib/rules/no-unused-classes/no-unused-classes.d.ts +8 -0
- package/lib/rules/no-unused-classes/no-unused-classes.d.ts.map +1 -0
- package/lib/rules/no-unused-classes/styles/component-descriptors.d.ts +3 -0
- package/lib/rules/no-unused-classes/styles/component-descriptors.d.ts.map +1 -0
- package/lib/rules/no-unused-classes/styles/stylesheet-components.d.ts +3 -0
- package/lib/rules/no-unused-classes/styles/stylesheet-components.d.ts.map +1 -0
- package/lib/rules/no-unused-classes/template/template-usage.d.ts +3 -0
- package/lib/rules/no-unused-classes/template/template-usage.d.ts.map +1 -0
- package/lib/rules/one-line-guard/one-line-guard.d.ts +10 -0
- package/lib/rules/one-line-guard/one-line-guard.d.ts.map +1 -0
- package/lib/rules/utils/class-expression-literals.util.d.ts +4 -0
- package/lib/rules/utils/class-expression-literals.util.d.ts.map +1 -0
- package/lib/rules/utils/resolved-rules.util.d.ts +5 -0
- package/lib/rules/utils/resolved-rules.util.d.ts.map +1 -0
- package/lib/rules/utils/selector-classes.util.d.ts +7 -0
- package/lib/rules/utils/selector-classes.util.d.ts.map +1 -0
- package/lib/rules/utils/template-classes.util.d.ts +3 -0
- package/lib/rules/utils/template-classes.util.d.ts.map +1 -0
- package/lib/typescript-local-plugin.d.ts.map +1 -1
- package/lib/typescript-safety.d.ts.map +1 -1
- package/package.json +4 -1
- package/prettier.cjs +6 -1
- package/prettier.cjs.map +3 -3
- package/prettier.d.ts.map +1 -1
- package/prettier.js +4 -1
- package/prettier.js.map +3 -3
- package/stylelint.cjs +680 -4
- package/stylelint.cjs.map +4 -4
- package/stylelint.d.ts.map +1 -1
- package/stylelint.js +708 -4
- package/stylelint.js.map +4 -4
package/eslint.cjs
CHANGED
|
@@ -49,11 +49,654 @@ module.exports = __toCommonJS(eslint_exports);
|
|
|
49
49
|
// packages/lint-suite/src/lib/angular-template.ts
|
|
50
50
|
var import_angular_eslint = require("angular-eslint");
|
|
51
51
|
var import_config = require("eslint/config");
|
|
52
|
+
|
|
53
|
+
// packages/lint-suite/src/lib/rules/define-plugin.util.ts
|
|
54
|
+
var definePlugin = (name, rules) => {
|
|
55
|
+
const meta7 = { name };
|
|
56
|
+
const plugin = { meta: meta7, rules };
|
|
57
|
+
return plugin;
|
|
58
|
+
};
|
|
59
|
+
|
|
60
|
+
// packages/lint-suite/src/lib/rules/no-unstyled-classes/no-unstyled-classes.ts
|
|
61
|
+
var import_utils = require("@typescript-eslint/utils");
|
|
62
|
+
|
|
63
|
+
// packages/lint-suite/src/lib/rules/no-unstyled-classes/styles/component-stylesheets.ts
|
|
64
|
+
var import_node_fs2 = require("node:fs");
|
|
65
|
+
var import_node_path = require("node:path");
|
|
66
|
+
|
|
67
|
+
// packages/lint-suite/src/lib/rules/component-metadata.ts
|
|
68
|
+
var import_node_fs = require("node:fs");
|
|
69
|
+
var import_typescript = require("typescript");
|
|
70
|
+
var componentArgument = (decorator) => {
|
|
71
|
+
const { expression } = decorator;
|
|
72
|
+
if (!(0, import_typescript.isCallExpression)(expression)) return null;
|
|
73
|
+
if (!(0, import_typescript.isIdentifier)(expression.expression)) return null;
|
|
74
|
+
const isComponent = expression.expression.text === "Component";
|
|
75
|
+
if (!isComponent) return null;
|
|
76
|
+
const [argument] = expression.arguments;
|
|
77
|
+
if (argument === void 0) return null;
|
|
78
|
+
if (!(0, import_typescript.isObjectLiteralExpression)(argument)) return null;
|
|
79
|
+
return argument;
|
|
80
|
+
};
|
|
81
|
+
var decoratedMetadata = (node) => {
|
|
82
|
+
if (!(0, import_typescript.canHaveDecorators)(node)) return null;
|
|
83
|
+
const decorators = (0, import_typescript.getDecorators)(node) ?? [];
|
|
84
|
+
for (const decorator of decorators) {
|
|
85
|
+
const metadata = componentArgument(decorator);
|
|
86
|
+
if (metadata !== null) return metadata;
|
|
87
|
+
}
|
|
88
|
+
return null;
|
|
89
|
+
};
|
|
90
|
+
var parseComponentMetadata = (text2, path) => {
|
|
91
|
+
const found = [];
|
|
92
|
+
const visit = (node) => {
|
|
93
|
+
const metadata = decoratedMetadata(node);
|
|
94
|
+
if (metadata !== null) found.push(metadata);
|
|
95
|
+
(0, import_typescript.forEachChild)(node, visit);
|
|
96
|
+
};
|
|
97
|
+
const source = (0, import_typescript.createSourceFile)(path, text2, import_typescript.ScriptTarget.Latest, true);
|
|
98
|
+
(0, import_typescript.forEachChild)(source, visit);
|
|
99
|
+
return found;
|
|
100
|
+
};
|
|
101
|
+
var componentMetadata = (path) => {
|
|
102
|
+
try {
|
|
103
|
+
const text2 = (0, import_node_fs.readFileSync)(path, "utf8");
|
|
104
|
+
return parseComponentMetadata(text2, path);
|
|
105
|
+
} catch {
|
|
106
|
+
return [];
|
|
107
|
+
}
|
|
108
|
+
};
|
|
109
|
+
var literalText = (node) => {
|
|
110
|
+
if (!(0, import_typescript.isStringLiteralLike)(node)) return null;
|
|
111
|
+
return node.text;
|
|
112
|
+
};
|
|
113
|
+
var literalTexts = (node) => {
|
|
114
|
+
const single = literalText(node);
|
|
115
|
+
if (single !== null) return [single];
|
|
116
|
+
if (!(0, import_typescript.isArrayLiteralExpression)(node)) return [];
|
|
117
|
+
const texts = [];
|
|
118
|
+
for (const element of node.elements) {
|
|
119
|
+
const text2 = literalText(element);
|
|
120
|
+
if (text2 !== null) texts.push(text2);
|
|
121
|
+
}
|
|
122
|
+
return texts;
|
|
123
|
+
};
|
|
124
|
+
var metadataValue = (metadata, name) => {
|
|
125
|
+
for (const property of metadata.properties) {
|
|
126
|
+
if (!(0, import_typescript.isPropertyAssignment)(property)) continue;
|
|
127
|
+
if (!(0, import_typescript.isIdentifier)(property.name)) continue;
|
|
128
|
+
const isMatch = property.name.text === name;
|
|
129
|
+
if (isMatch) return property.initializer;
|
|
130
|
+
}
|
|
131
|
+
return null;
|
|
132
|
+
};
|
|
133
|
+
var metadataTexts = (metadata, name) => {
|
|
134
|
+
const value = metadataValue(metadata, name);
|
|
135
|
+
if (value === null) return [];
|
|
136
|
+
return literalTexts(value);
|
|
137
|
+
};
|
|
138
|
+
|
|
139
|
+
// packages/lint-suite/src/lib/rules/no-unstyled-classes/styles/component-stylesheets.ts
|
|
140
|
+
var SIBLING_EXTENSIONS = [".scss", ".css"];
|
|
141
|
+
var HTML_EXTENSION = /\.html$/iu;
|
|
142
|
+
var matchesTemplate = (metadata, directory, templateFilename) => {
|
|
143
|
+
const urls = metadataTexts(metadata, "templateUrl");
|
|
144
|
+
const [templateUrl] = urls;
|
|
145
|
+
if (templateUrl === void 0) return false;
|
|
146
|
+
const declared = (0, import_node_path.resolve)(directory, templateUrl);
|
|
147
|
+
const linted = (0, import_node_path.resolve)(templateFilename);
|
|
148
|
+
return declared === linted;
|
|
149
|
+
};
|
|
150
|
+
var templateMetadata = (componentPath, templateFilename) => {
|
|
151
|
+
const components = componentMetadata(componentPath);
|
|
152
|
+
const directory = (0, import_node_path.dirname)(componentPath);
|
|
153
|
+
const matches = (metadata) => {
|
|
154
|
+
return matchesTemplate(metadata, directory, templateFilename);
|
|
155
|
+
};
|
|
156
|
+
const matched = components.find(matches);
|
|
157
|
+
if (matched !== void 0) return matched;
|
|
158
|
+
const isOnly = components.length === 1;
|
|
159
|
+
if (!isOnly) return null;
|
|
160
|
+
const [only] = components;
|
|
161
|
+
return only ?? null;
|
|
162
|
+
};
|
|
163
|
+
var stylesheetFiles = (paths, directory) => {
|
|
164
|
+
const sources = [];
|
|
165
|
+
for (const path of paths) {
|
|
166
|
+
const resolved = (0, import_node_path.resolve)(directory, path);
|
|
167
|
+
const isPresent = (0, import_node_fs2.existsSync)(resolved);
|
|
168
|
+
if (!isPresent) continue;
|
|
169
|
+
const source = { kind: "file", path: resolved };
|
|
170
|
+
sources.push(source);
|
|
171
|
+
}
|
|
172
|
+
return sources;
|
|
173
|
+
};
|
|
174
|
+
var inlineSources = (styles, componentPath) => {
|
|
175
|
+
const sourceOf = (style) => {
|
|
176
|
+
const source = {
|
|
177
|
+
kind: "inline",
|
|
178
|
+
source: style,
|
|
179
|
+
path: componentPath
|
|
180
|
+
};
|
|
181
|
+
return source;
|
|
182
|
+
};
|
|
183
|
+
return styles.map(sourceOf);
|
|
184
|
+
};
|
|
185
|
+
var metadataSources = (componentPath, templateFilename) => {
|
|
186
|
+
const metadata = templateMetadata(componentPath, templateFilename);
|
|
187
|
+
if (metadata === null) return [];
|
|
188
|
+
const singleUrl = metadataTexts(metadata, "styleUrl");
|
|
189
|
+
const listedUrls = metadataTexts(metadata, "styleUrls");
|
|
190
|
+
const styles = metadataTexts(metadata, "styles");
|
|
191
|
+
const directory = (0, import_node_path.dirname)(componentPath);
|
|
192
|
+
const urls = [...singleUrl, ...listedUrls];
|
|
193
|
+
const files = stylesheetFiles(urls, directory);
|
|
194
|
+
const inline = inlineSources(styles, componentPath);
|
|
195
|
+
return [...files, ...inline];
|
|
196
|
+
};
|
|
197
|
+
var siblingSources = (templateFilename) => {
|
|
198
|
+
const base2 = templateFilename.replace(HTML_EXTENSION, "");
|
|
199
|
+
const candidateOf = (extension) => `${base2}${extension}`;
|
|
200
|
+
const candidates = SIBLING_EXTENSIONS.map(candidateOf);
|
|
201
|
+
return stylesheetFiles(candidates, (0, import_node_path.dirname)(templateFilename));
|
|
202
|
+
};
|
|
203
|
+
var componentStylesheets = (templateFilename) => {
|
|
204
|
+
const componentPath = templateFilename.replace(HTML_EXTENSION, ".ts");
|
|
205
|
+
const sources = metadataSources(componentPath, templateFilename);
|
|
206
|
+
if (sources.length > 0) return sources;
|
|
207
|
+
return siblingSources(templateFilename);
|
|
208
|
+
};
|
|
209
|
+
|
|
210
|
+
// packages/lint-suite/src/lib/rules/no-unstyled-classes/styles/stylesheet-classes.ts
|
|
211
|
+
var import_node_fs4 = require("node:fs");
|
|
212
|
+
var import_node_path3 = require("node:path");
|
|
213
|
+
var import_postcss_scss = require("postcss-scss");
|
|
214
|
+
|
|
215
|
+
// packages/lint-suite/src/lib/rules/no-unstyled-classes/styles/stylesheet-imports.ts
|
|
216
|
+
var import_node_fs3 = require("node:fs");
|
|
217
|
+
var import_node_path2 = require("node:path");
|
|
218
|
+
var QUOTED = /'([^']*)'|"([^"]*)"/u;
|
|
219
|
+
var SKIPPED_PREFIXES = ["sass:", "http", "url("];
|
|
220
|
+
var specifierOf = (params) => {
|
|
221
|
+
const match = QUOTED.exec(params);
|
|
222
|
+
if (!match) return null;
|
|
223
|
+
return match[1] ?? match[2] ?? null;
|
|
224
|
+
};
|
|
225
|
+
var isResolvable = (specifier) => {
|
|
226
|
+
const isEmpty = specifier.length === 0;
|
|
227
|
+
if (isEmpty) return false;
|
|
228
|
+
const isSkipped = SKIPPED_PREFIXES.some(
|
|
229
|
+
(prefix) => specifier.startsWith(prefix)
|
|
230
|
+
);
|
|
231
|
+
if (isSkipped) return false;
|
|
232
|
+
return !specifier.endsWith(".css");
|
|
233
|
+
};
|
|
234
|
+
var candidatesOf = (path) => {
|
|
235
|
+
const isStylesheet = path.endsWith(".scss");
|
|
236
|
+
if (isStylesheet) return [path, (0, import_node_path2.join)((0, import_node_path2.dirname)(path), `_${(0, import_node_path2.basename)(path)}`)];
|
|
237
|
+
const partial = (0, import_node_path2.join)((0, import_node_path2.dirname)(path), `_${(0, import_node_path2.basename)(path)}.scss`);
|
|
238
|
+
return [
|
|
239
|
+
`${path}.scss`,
|
|
240
|
+
partial,
|
|
241
|
+
(0, import_node_path2.join)(path, "index.scss"),
|
|
242
|
+
(0, import_node_path2.join)(path, "_index.scss")
|
|
243
|
+
];
|
|
244
|
+
};
|
|
245
|
+
var resolveStylesheetImport = (params, directory) => {
|
|
246
|
+
const specifier = specifierOf(params);
|
|
247
|
+
if (specifier === null) return null;
|
|
248
|
+
const isCandidate = isResolvable(specifier);
|
|
249
|
+
if (!isCandidate) return null;
|
|
250
|
+
const path = (0, import_node_path2.resolve)(directory, specifier);
|
|
251
|
+
const candidates = candidatesOf(path);
|
|
252
|
+
const existing = candidates.find((candidate) => (0, import_node_fs3.existsSync)(candidate));
|
|
253
|
+
return existing ?? null;
|
|
254
|
+
};
|
|
255
|
+
|
|
256
|
+
// packages/lint-suite/src/lib/rules/utils/selector-classes.util.ts
|
|
257
|
+
var import_postcss_selector_parser = __toESM(require("postcss-selector-parser"), 1);
|
|
258
|
+
var INTERPOLATION_TOKEN = "zzinterpzz";
|
|
259
|
+
var PARENT_TOKEN = "zzparentzz";
|
|
260
|
+
var UNKNOWN_PARENT_SELECTOR = `.${PARENT_TOKEN}`;
|
|
261
|
+
var UNKNOWN_PARTS = new RegExp(
|
|
262
|
+
`${INTERPOLATION_TOKEN}|${PARENT_TOKEN}`,
|
|
263
|
+
"gu"
|
|
264
|
+
);
|
|
265
|
+
var INTERPOLATION = /#\{[^}]*\}/gu;
|
|
266
|
+
var REGEXP_META = /[.*+?^${}()|[\]\\]/gu;
|
|
267
|
+
var escapeRegExp = (part) => {
|
|
268
|
+
return part.replaceAll(REGEXP_META, "\\$&");
|
|
269
|
+
};
|
|
270
|
+
var classNamePattern = (value) => {
|
|
271
|
+
const literals = value.split(UNKNOWN_PARTS).map(escapeRegExp);
|
|
272
|
+
const joined = literals.join(".*");
|
|
273
|
+
return `^${joined}$`;
|
|
274
|
+
};
|
|
275
|
+
var withoutParent = (selector) => {
|
|
276
|
+
return selector.replaceAll("&", UNKNOWN_PARENT_SELECTOR);
|
|
277
|
+
};
|
|
278
|
+
var withParent = (selector, parent) => {
|
|
279
|
+
const hasNesting = selector.includes("&");
|
|
280
|
+
if (hasNesting) return selector.replaceAll("&", parent);
|
|
281
|
+
return `${parent} ${selector}`;
|
|
282
|
+
};
|
|
283
|
+
var resolveSelectors = (selectors, parents) => {
|
|
284
|
+
const hasParents = parents.length > 0;
|
|
285
|
+
if (!hasParents) return selectors.map(withoutParent);
|
|
286
|
+
const resolved = [];
|
|
287
|
+
for (const parent of parents) {
|
|
288
|
+
for (const selector of selectors) {
|
|
289
|
+
resolved.push(withParent(selector, parent));
|
|
290
|
+
}
|
|
291
|
+
}
|
|
292
|
+
return resolved;
|
|
293
|
+
};
|
|
294
|
+
var selectorClasses = (selector) => {
|
|
295
|
+
const exact = [];
|
|
296
|
+
const patterns = [];
|
|
297
|
+
const normalized = selector.replaceAll(INTERPOLATION, INTERPOLATION_TOKEN);
|
|
298
|
+
const collect2 = (node) => {
|
|
299
|
+
const isBareParent = node.value === PARENT_TOKEN;
|
|
300
|
+
if (isBareParent) return;
|
|
301
|
+
const hasInterpolation = node.value.includes(INTERPOLATION_TOKEN);
|
|
302
|
+
const hasUnknownParent = node.value.includes(PARENT_TOKEN);
|
|
303
|
+
const isDynamic = hasInterpolation || hasUnknownParent;
|
|
304
|
+
if (isDynamic) {
|
|
305
|
+
patterns.push(classNamePattern(node.value));
|
|
306
|
+
return;
|
|
307
|
+
}
|
|
308
|
+
exact.push(node.value);
|
|
309
|
+
};
|
|
310
|
+
try {
|
|
311
|
+
const root = (0, import_postcss_selector_parser.default)().astSync(normalized);
|
|
312
|
+
root.walkClasses(collect2);
|
|
313
|
+
} catch {
|
|
314
|
+
const empty = { exact: [], patterns: [] };
|
|
315
|
+
return empty;
|
|
316
|
+
}
|
|
317
|
+
const classes = { exact, patterns };
|
|
318
|
+
return classes;
|
|
319
|
+
};
|
|
320
|
+
var classMatcher = (exact, patterns) => {
|
|
321
|
+
const matches = (name) => {
|
|
322
|
+
const isExact = exact.has(name);
|
|
323
|
+
if (isExact) return true;
|
|
324
|
+
return patterns.some((pattern) => pattern.test(name));
|
|
325
|
+
};
|
|
326
|
+
return matches;
|
|
327
|
+
};
|
|
328
|
+
|
|
329
|
+
// packages/lint-suite/src/lib/rules/utils/resolved-rules.util.ts
|
|
330
|
+
var walkContainer = (container, parents, visit) => {
|
|
331
|
+
for (const node of container.nodes ?? []) {
|
|
332
|
+
if (node.type === "rule") {
|
|
333
|
+
const resolved = resolveSelectors(node.selectors, parents);
|
|
334
|
+
visit(node, resolved, parents);
|
|
335
|
+
walkContainer(node, resolved, visit);
|
|
336
|
+
continue;
|
|
337
|
+
}
|
|
338
|
+
if (node.type !== "atrule") continue;
|
|
339
|
+
walkContainer(node, parents, visit);
|
|
340
|
+
}
|
|
341
|
+
};
|
|
342
|
+
var walkResolvedRules = (root, visit) => {
|
|
343
|
+
walkContainer(root, [], visit);
|
|
344
|
+
};
|
|
345
|
+
|
|
346
|
+
// packages/lint-suite/src/lib/rules/no-unstyled-classes/styles/stylesheet-collection.ts
|
|
347
|
+
var IMPORT_AT_RULES = /* @__PURE__ */ new Set(["use", "import", "forward"]);
|
|
348
|
+
var addSelectors = (selectors, entry) => {
|
|
349
|
+
for (const selector of selectors) {
|
|
350
|
+
const { exact, patterns } = selectorClasses(selector);
|
|
351
|
+
entry.classes.push(...exact);
|
|
352
|
+
entry.patterns.push(...patterns);
|
|
353
|
+
}
|
|
354
|
+
};
|
|
355
|
+
var addImport = (node, entry, directory) => {
|
|
356
|
+
const isImport = IMPORT_AT_RULES.has(node.name);
|
|
357
|
+
if (!isImport) return;
|
|
358
|
+
const imported = resolveStylesheetImport(node.params, directory);
|
|
359
|
+
if (imported !== null) entry.imports.push(imported);
|
|
360
|
+
};
|
|
361
|
+
var collectStylesheet = (root, directory) => {
|
|
362
|
+
const entry = { classes: [], patterns: [], imports: [] };
|
|
363
|
+
const onRule = (_rule, resolved) => {
|
|
364
|
+
addSelectors(resolved, entry);
|
|
365
|
+
};
|
|
366
|
+
const onAtRule = (node) => {
|
|
367
|
+
addImport(node, entry, directory);
|
|
368
|
+
};
|
|
369
|
+
walkResolvedRules(root, onRule);
|
|
370
|
+
root.walkAtRules(onAtRule);
|
|
371
|
+
return entry;
|
|
372
|
+
};
|
|
373
|
+
|
|
374
|
+
// packages/lint-suite/src/lib/rules/no-unstyled-classes/styles/stylesheet-classes.ts
|
|
375
|
+
var stylesheets = /* @__PURE__ */ new Map();
|
|
376
|
+
var emptyEntry = () => {
|
|
377
|
+
const entry = { classes: [], patterns: [], imports: [] };
|
|
378
|
+
return entry;
|
|
379
|
+
};
|
|
380
|
+
var parseStylesheet = (source, path) => {
|
|
381
|
+
try {
|
|
382
|
+
const root = (0, import_postcss_scss.parse)(source, { from: path });
|
|
383
|
+
return collectStylesheet(root, (0, import_node_path3.dirname)(path));
|
|
384
|
+
} catch {
|
|
385
|
+
return emptyEntry();
|
|
386
|
+
}
|
|
387
|
+
};
|
|
388
|
+
var fileEntry = (path) => {
|
|
389
|
+
try {
|
|
390
|
+
const stats = (0, import_node_fs4.statSync)(path, { bigint: true });
|
|
391
|
+
const version = `${stats.mtimeNs}:${stats.size}`;
|
|
392
|
+
const cached = stylesheets.get(path);
|
|
393
|
+
if (cached?.version === version) return cached.entry;
|
|
394
|
+
const entry = parseStylesheet((0, import_node_fs4.readFileSync)(path, "utf8"), path);
|
|
395
|
+
const fresh = { entry, version };
|
|
396
|
+
stylesheets.set(path, fresh);
|
|
397
|
+
return entry;
|
|
398
|
+
} catch {
|
|
399
|
+
return emptyEntry();
|
|
400
|
+
}
|
|
401
|
+
};
|
|
402
|
+
var addEntry = (entry, sink, visited) => {
|
|
403
|
+
for (const name of entry.classes) sink.exact.add(name);
|
|
404
|
+
sink.patterns.push(...entry.patterns);
|
|
405
|
+
for (const imported of entry.imports) {
|
|
406
|
+
const isVisited = visited.has(imported);
|
|
407
|
+
if (isVisited) continue;
|
|
408
|
+
visited.add(imported);
|
|
409
|
+
addEntry(fileEntry(imported), sink, visited);
|
|
410
|
+
}
|
|
411
|
+
};
|
|
412
|
+
var addSource = (source, sink, visited) => {
|
|
413
|
+
if (source.kind === "file") {
|
|
414
|
+
const isVisited = visited.has(source.path);
|
|
415
|
+
if (isVisited) return;
|
|
416
|
+
visited.add(source.path);
|
|
417
|
+
addEntry(fileEntry(source.path), sink, visited);
|
|
418
|
+
return;
|
|
419
|
+
}
|
|
420
|
+
addEntry(parseStylesheet(source.source, source.path), sink, visited);
|
|
421
|
+
};
|
|
422
|
+
var toRegExp = (pattern) => {
|
|
423
|
+
return new RegExp(pattern, "u");
|
|
424
|
+
};
|
|
425
|
+
var stylesheetClasses = (sources) => {
|
|
426
|
+
const exact = /* @__PURE__ */ new Set();
|
|
427
|
+
const patterns = [];
|
|
428
|
+
const sink = { exact, patterns };
|
|
429
|
+
const visited = /* @__PURE__ */ new Set();
|
|
430
|
+
for (const source of sources) addSource(source, sink, visited);
|
|
431
|
+
const compiled = patterns.map(toRegExp);
|
|
432
|
+
const has = classMatcher(exact, compiled);
|
|
433
|
+
const size = exact.size + compiled.length;
|
|
434
|
+
const classes = { has, size };
|
|
435
|
+
return classes;
|
|
436
|
+
};
|
|
437
|
+
|
|
438
|
+
// packages/lint-suite/src/lib/rules/no-unstyled-classes/styles/template-stylesheets.ts
|
|
439
|
+
var templateStylesheets = (templateFilename, cwd, globalStyles) => {
|
|
440
|
+
let known = null;
|
|
441
|
+
const lookup = () => {
|
|
442
|
+
if (known !== null) return known;
|
|
443
|
+
const component = componentStylesheets(templateFilename);
|
|
444
|
+
const global = stylesheetFiles(globalStyles, cwd);
|
|
445
|
+
const sources = [...component, ...global];
|
|
446
|
+
known = stylesheetClasses(sources);
|
|
447
|
+
return known;
|
|
448
|
+
};
|
|
449
|
+
return lookup;
|
|
450
|
+
};
|
|
451
|
+
|
|
452
|
+
// packages/lint-suite/src/lib/rules/utils/template-classes.util.ts
|
|
453
|
+
var import_compiler2 = require("@angular/compiler");
|
|
454
|
+
|
|
455
|
+
// packages/lint-suite/src/lib/rules/utils/class-expression-literals.util.ts
|
|
456
|
+
var import_compiler = require("@angular/compiler");
|
|
457
|
+
var WHITESPACE = /\s+/u;
|
|
458
|
+
var EXPRESSION_FILE = "class-expression";
|
|
459
|
+
var parser = new import_compiler.Parser(new import_compiler.Lexer());
|
|
460
|
+
var spanOf = (source) => {
|
|
461
|
+
const file = new import_compiler.ParseSourceFile(source, EXPRESSION_FILE);
|
|
462
|
+
const start = new import_compiler.ParseLocation(file, 0, 0, 0);
|
|
463
|
+
const span = new import_compiler.ParseSourceSpan(start, start.moveBy(source.length));
|
|
464
|
+
return span;
|
|
465
|
+
};
|
|
466
|
+
var astOf = (parsed) => {
|
|
467
|
+
const hasErrors = parsed.errors.length > 0;
|
|
468
|
+
if (hasErrors) return null;
|
|
469
|
+
return parsed.ast;
|
|
470
|
+
};
|
|
471
|
+
var parseClassExpression = (source) => {
|
|
472
|
+
try {
|
|
473
|
+
const span = spanOf(source);
|
|
474
|
+
const interpolation = parser.parseInterpolation(source, span, 0, null);
|
|
475
|
+
if (interpolation) return astOf(interpolation);
|
|
476
|
+
const binding = parser.parseBinding(source, span, 0);
|
|
477
|
+
return astOf(binding);
|
|
478
|
+
} catch {
|
|
479
|
+
return null;
|
|
480
|
+
}
|
|
481
|
+
};
|
|
482
|
+
var addNames = (value, names) => {
|
|
483
|
+
for (const token of value.split(WHITESPACE)) {
|
|
484
|
+
if (token) names.push(token);
|
|
485
|
+
}
|
|
486
|
+
};
|
|
487
|
+
var addPrimitive = (ast, names) => {
|
|
488
|
+
if (typeof ast.value === "string") addNames(ast.value, names);
|
|
489
|
+
};
|
|
490
|
+
var addMapKeys = (ast, names) => {
|
|
491
|
+
for (const key2 of ast.keys) {
|
|
492
|
+
if (key2.kind !== "spread") addNames(key2.key, names);
|
|
493
|
+
}
|
|
494
|
+
};
|
|
495
|
+
var addInterpolation = (ast, names) => {
|
|
496
|
+
for (const text2 of ast.strings) addNames(text2, names);
|
|
497
|
+
};
|
|
498
|
+
var collect = (ast, names) => {
|
|
499
|
+
if (ast instanceof import_compiler.LiteralPrimitive) {
|
|
500
|
+
addPrimitive(ast, names);
|
|
501
|
+
return;
|
|
502
|
+
}
|
|
503
|
+
if (ast instanceof import_compiler.LiteralMap) {
|
|
504
|
+
addMapKeys(ast, names);
|
|
505
|
+
return;
|
|
506
|
+
}
|
|
507
|
+
if (ast instanceof import_compiler.Interpolation) {
|
|
508
|
+
addInterpolation(ast, names);
|
|
509
|
+
return;
|
|
510
|
+
}
|
|
511
|
+
if (ast instanceof import_compiler.LiteralArray) {
|
|
512
|
+
for (const expression of ast.expressions) collect(expression, names);
|
|
513
|
+
return;
|
|
514
|
+
}
|
|
515
|
+
if (ast instanceof import_compiler.Conditional) {
|
|
516
|
+
collect(ast.trueExp, names);
|
|
517
|
+
collect(ast.falseExp, names);
|
|
518
|
+
}
|
|
519
|
+
};
|
|
520
|
+
var classExpressionLiterals = (source) => {
|
|
521
|
+
const ast = parseClassExpression(source);
|
|
522
|
+
if (ast === null) return [];
|
|
523
|
+
const names = [];
|
|
524
|
+
collect(ast, names);
|
|
525
|
+
return [...new Set(names)];
|
|
526
|
+
};
|
|
527
|
+
|
|
528
|
+
// packages/lint-suite/src/lib/rules/utils/template-classes.util.ts
|
|
529
|
+
var CLASS_ATTRIBUTE = "class";
|
|
530
|
+
var CLASS_BINDING_PREFIX = "class.";
|
|
531
|
+
var TOKEN = /\S+/gu;
|
|
532
|
+
var expressionSource = (value) => {
|
|
533
|
+
if (!("source" in value)) return null;
|
|
534
|
+
const { source } = value;
|
|
535
|
+
if (typeof source !== "string") return null;
|
|
536
|
+
return source;
|
|
537
|
+
};
|
|
538
|
+
var staticClasses = (attribute) => {
|
|
539
|
+
const classes = [];
|
|
540
|
+
const valueSpan = attribute.valueSpan ?? attribute.sourceSpan;
|
|
541
|
+
for (const token of attribute.value.matchAll(TOKEN)) {
|
|
542
|
+
const start = valueSpan.start.moveBy(token.index);
|
|
543
|
+
const end = valueSpan.start.moveBy(token.index + token[0].length);
|
|
544
|
+
const span = new import_compiler2.ParseSourceSpan(start, end);
|
|
545
|
+
const templateClass = { name: token[0], span };
|
|
546
|
+
classes.push(templateClass);
|
|
547
|
+
}
|
|
548
|
+
return classes;
|
|
549
|
+
};
|
|
550
|
+
var boundClassName = (input) => {
|
|
551
|
+
const { details } = input.keySpan;
|
|
552
|
+
if (details === null) return null;
|
|
553
|
+
const isClassBinding = details.startsWith(CLASS_BINDING_PREFIX);
|
|
554
|
+
if (!isClassBinding) return null;
|
|
555
|
+
return input.name;
|
|
556
|
+
};
|
|
557
|
+
var isClassExpression = (input) => {
|
|
558
|
+
const isClassName = input.name === CLASS_ATTRIBUTE;
|
|
559
|
+
if (!isClassName) return false;
|
|
560
|
+
const { details } = input.keySpan;
|
|
561
|
+
if (details === null) return true;
|
|
562
|
+
return details === CLASS_ATTRIBUTE;
|
|
563
|
+
};
|
|
564
|
+
var expressionClasses = (input) => {
|
|
565
|
+
const source = expressionSource(input.value);
|
|
566
|
+
if (source === null) return [];
|
|
567
|
+
const names = classExpressionLiterals(source);
|
|
568
|
+
const templateClassOf = (name) => {
|
|
569
|
+
const templateClass = { name, span: input.sourceSpan };
|
|
570
|
+
return templateClass;
|
|
571
|
+
};
|
|
572
|
+
return names.map(templateClassOf);
|
|
573
|
+
};
|
|
574
|
+
var inputClasses = (input) => {
|
|
575
|
+
const bound = boundClassName(input);
|
|
576
|
+
if (bound !== null) {
|
|
577
|
+
const templateClass = { name: bound, span: input.keySpan };
|
|
578
|
+
return [templateClass];
|
|
579
|
+
}
|
|
580
|
+
const isExpression = isClassExpression(input);
|
|
581
|
+
if (!isExpression) return [];
|
|
582
|
+
return expressionClasses(input);
|
|
583
|
+
};
|
|
584
|
+
var templateClasses = (node) => {
|
|
585
|
+
const classes = [];
|
|
586
|
+
for (const attribute of node.attributes) {
|
|
587
|
+
const isClassName = attribute.name === CLASS_ATTRIBUTE;
|
|
588
|
+
if (isClassName) classes.push(...staticClasses(attribute));
|
|
589
|
+
}
|
|
590
|
+
for (const input of node.inputs) {
|
|
591
|
+
classes.push(...inputClasses(input));
|
|
592
|
+
}
|
|
593
|
+
return classes;
|
|
594
|
+
};
|
|
595
|
+
|
|
596
|
+
// packages/lint-suite/src/lib/rules/no-unstyled-classes/no-unstyled-classes.ts
|
|
597
|
+
var PARSER_REQUIRED = "no-unstyled-classes requires '@angular-eslint/template-parser'.";
|
|
598
|
+
var docs = {
|
|
599
|
+
description: "Disallow template class names that no stylesheet of the component selects"
|
|
600
|
+
};
|
|
601
|
+
var messages = {
|
|
602
|
+
unstyledClass: "Class '{{name}}' is not selected by any stylesheet of this template."
|
|
603
|
+
};
|
|
604
|
+
var stringItems = { type: "string" };
|
|
605
|
+
var ignoreClassPatternsSchema = {
|
|
606
|
+
type: "array",
|
|
607
|
+
items: stringItems,
|
|
608
|
+
description: "Regular expressions for class names that are never reported."
|
|
609
|
+
};
|
|
610
|
+
var globalStylesSchema = {
|
|
611
|
+
type: "array",
|
|
612
|
+
items: stringItems,
|
|
613
|
+
description: "Stylesheets merged into the known classes of every template."
|
|
614
|
+
};
|
|
615
|
+
var properties = {
|
|
616
|
+
ignoreClassPatterns: ignoreClassPatternsSchema,
|
|
617
|
+
globalStyles: globalStylesSchema
|
|
618
|
+
};
|
|
619
|
+
var optionsSchema = {
|
|
620
|
+
type: "object",
|
|
621
|
+
properties,
|
|
622
|
+
additionalProperties: false
|
|
623
|
+
};
|
|
624
|
+
var schema = [optionsSchema];
|
|
625
|
+
var meta = {
|
|
626
|
+
type: "problem",
|
|
627
|
+
docs,
|
|
628
|
+
schema,
|
|
629
|
+
messages
|
|
630
|
+
};
|
|
631
|
+
var ruleDefaults = {
|
|
632
|
+
ignoreClassPatterns: ["^(js|qa|mat|cdk|mdc)-"],
|
|
633
|
+
globalStyles: []
|
|
634
|
+
};
|
|
635
|
+
var defaultOptions = [ruleDefaults];
|
|
636
|
+
var createRule = import_utils.ESLintUtils.RuleCreator(
|
|
637
|
+
() => "https://github.com/F0rty-Tw0/lint-suite#no-unstyled-classes"
|
|
638
|
+
);
|
|
639
|
+
var isTemplateServices = (services) => {
|
|
640
|
+
if (!("convertNodeSourceSpanToLoc" in services)) return false;
|
|
641
|
+
return typeof services.convertNodeSourceSpanToLoc === "function";
|
|
642
|
+
};
|
|
643
|
+
var toRegExp2 = (pattern) => new RegExp(pattern, "u");
|
|
644
|
+
var no_unstyled_classes_default = createRule({
|
|
645
|
+
name: "no-unstyled-classes",
|
|
646
|
+
meta,
|
|
647
|
+
defaultOptions,
|
|
648
|
+
create(context, [options]) {
|
|
649
|
+
const { parserServices } = context.sourceCode;
|
|
650
|
+
if (parserServices === void 0) throw new Error(PARSER_REQUIRED);
|
|
651
|
+
if (!isTemplateServices(parserServices)) throw new Error(PARSER_REQUIRED);
|
|
652
|
+
const ignored = options.ignoreClassPatterns.map(toRegExp2);
|
|
653
|
+
const stylesheets2 = templateStylesheets(
|
|
654
|
+
context.filename,
|
|
655
|
+
context.cwd,
|
|
656
|
+
options.globalStyles
|
|
657
|
+
);
|
|
658
|
+
const listeners = {
|
|
659
|
+
Element(node) {
|
|
660
|
+
const isCustomElement = node.name.includes("-");
|
|
661
|
+
if (isCustomElement) return;
|
|
662
|
+
const classes = templateClasses(node);
|
|
663
|
+
if (classes.length === 0) return;
|
|
664
|
+
const known = stylesheets2();
|
|
665
|
+
if (known.size === 0) return;
|
|
666
|
+
for (const { name, span } of classes) {
|
|
667
|
+
const isIgnored = ignored.some((pattern) => pattern.test(name));
|
|
668
|
+
if (isIgnored) continue;
|
|
669
|
+
const isStyled = known.has(name);
|
|
670
|
+
if (isStyled) continue;
|
|
671
|
+
const loc = parserServices.convertNodeSourceSpanToLoc(span);
|
|
672
|
+
const data = { name };
|
|
673
|
+
const report = {
|
|
674
|
+
loc,
|
|
675
|
+
messageId: "unstyledClass",
|
|
676
|
+
data
|
|
677
|
+
};
|
|
678
|
+
context.report(report);
|
|
679
|
+
}
|
|
680
|
+
}
|
|
681
|
+
};
|
|
682
|
+
return listeners;
|
|
683
|
+
}
|
|
684
|
+
});
|
|
685
|
+
|
|
686
|
+
// packages/lint-suite/src/lib/angular-template.ts
|
|
687
|
+
var lintSuiteAngularTemplatePlugin = definePlugin(
|
|
688
|
+
"lint-suite-angular-template",
|
|
689
|
+
{ "no-unstyled-classes": no_unstyled_classes_default }
|
|
690
|
+
);
|
|
52
691
|
var angularTemplate = (0, import_config.defineConfig)([
|
|
53
692
|
{
|
|
54
693
|
files: ["**/*.html"],
|
|
55
694
|
extends: [...import_angular_eslint.configs.templateAccessibility, ...import_angular_eslint.configs.templateRecommended],
|
|
695
|
+
plugins: {
|
|
696
|
+
"lint-suite-angular-template": lintSuiteAngularTemplatePlugin
|
|
697
|
+
},
|
|
56
698
|
rules: {
|
|
699
|
+
"lint-suite-angular-template/no-unstyled-classes": "error",
|
|
57
700
|
"@angular-eslint/template/prefer-template-literal": "error",
|
|
58
701
|
"@angular-eslint/template/no-any": "error",
|
|
59
702
|
"@angular-eslint/template/no-duplicate-attributes": "error",
|
|
@@ -125,33 +768,26 @@ var import_angular_eslint2 = require("angular-eslint");
|
|
|
125
768
|
var import_config2 = require("eslint/config");
|
|
126
769
|
var import_globals = __toESM(require("globals"), 1);
|
|
127
770
|
|
|
128
|
-
// packages/lint-suite/src/lib/rules/define-plugin.util.ts
|
|
129
|
-
var definePlugin = (name, rules) => {
|
|
130
|
-
const meta5 = { name };
|
|
131
|
-
const plugin = { meta: meta5, rules };
|
|
132
|
-
return plugin;
|
|
133
|
-
};
|
|
134
|
-
|
|
135
771
|
// packages/lint-suite/src/lib/rules/no-unused-angular-instance-fields/rule/no-unused-angular-instance-fields.ts
|
|
136
|
-
var
|
|
772
|
+
var import_utils11 = require("@typescript-eslint/utils");
|
|
137
773
|
|
|
138
774
|
// packages/lint-suite/src/lib/rules/no-unused-angular-instance-fields/rule/angular/angular-imports.ts
|
|
139
|
-
var
|
|
775
|
+
var import_utils2 = require("@typescript-eslint/utils");
|
|
140
776
|
var calleeRoot = (node) => {
|
|
141
|
-
if (node.type ===
|
|
142
|
-
if (node.type !==
|
|
777
|
+
if (node.type === import_utils2.TSESTree.AST_NODE_TYPES.Identifier) return node;
|
|
778
|
+
if (node.type !== import_utils2.TSESTree.AST_NODE_TYPES.MemberExpression || node.object.type === import_utils2.TSESTree.AST_NODE_TYPES.Super) {
|
|
143
779
|
return void 0;
|
|
144
780
|
}
|
|
145
781
|
return calleeRoot(node.object);
|
|
146
782
|
};
|
|
147
783
|
var angularName = (node, imports) => {
|
|
148
|
-
if (node.type ===
|
|
784
|
+
if (node.type === import_utils2.TSESTree.AST_NODE_TYPES.Identifier) {
|
|
149
785
|
return imports.get(node.name);
|
|
150
786
|
}
|
|
151
|
-
if (node.type !==
|
|
787
|
+
if (node.type !== import_utils2.TSESTree.AST_NODE_TYPES.MemberExpression || node.computed || node.property.type !== import_utils2.TSESTree.AST_NODE_TYPES.Identifier) {
|
|
152
788
|
return null;
|
|
153
789
|
}
|
|
154
|
-
if (node.object.type ===
|
|
790
|
+
if (node.object.type === import_utils2.TSESTree.AST_NODE_TYPES.Identifier) {
|
|
155
791
|
const namespaceAlias = imports.get(node.object.name);
|
|
156
792
|
if (namespaceAlias === null) return node.property.name;
|
|
157
793
|
}
|
|
@@ -171,25 +807,25 @@ var addAngularImport = (node, imports) => {
|
|
|
171
807
|
return;
|
|
172
808
|
}
|
|
173
809
|
for (const specifier of node.specifiers) {
|
|
174
|
-
if (specifier.type ===
|
|
810
|
+
if (specifier.type === import_utils2.TSESTree.AST_NODE_TYPES.ImportNamespaceSpecifier) {
|
|
175
811
|
imports.set(specifier.local.name, null);
|
|
176
|
-
} else if (specifier.type ===
|
|
812
|
+
} else if (specifier.type === import_utils2.TSESTree.AST_NODE_TYPES.ImportSpecifier && specifier.importKind !== "type") {
|
|
177
813
|
const { imported } = specifier;
|
|
178
|
-
const
|
|
179
|
-
const importedName =
|
|
814
|
+
const isIdentifier9 = imported.type === import_utils2.TSESTree.AST_NODE_TYPES.Identifier;
|
|
815
|
+
const importedName = isIdentifier9 ? imported.name : imported.value;
|
|
180
816
|
imports.set(specifier.local.name, importedName);
|
|
181
817
|
}
|
|
182
818
|
}
|
|
183
819
|
};
|
|
184
820
|
var angularClassMetadata = (node, imports) => {
|
|
185
821
|
for (const decorator of node.decorators) {
|
|
186
|
-
if (decorator.expression.type !==
|
|
822
|
+
if (decorator.expression.type !== import_utils2.TSESTree.AST_NODE_TYPES.CallExpression) {
|
|
187
823
|
continue;
|
|
188
824
|
}
|
|
189
825
|
const kind = angularName(decorator.expression.callee, imports);
|
|
190
826
|
const metadata = decorator.expression.arguments.at(0);
|
|
191
827
|
const isComponentOrDirective = kind === "Component" || kind === "Directive";
|
|
192
|
-
if (isComponentOrDirective && metadata?.type ===
|
|
828
|
+
if (isComponentOrDirective && metadata?.type === import_utils2.TSESTree.AST_NODE_TYPES.ObjectExpression) {
|
|
193
829
|
const classMetadata = {
|
|
194
830
|
component: kind === "Component",
|
|
195
831
|
metadata
|
|
@@ -202,7 +838,7 @@ var angularClassMetadata = (node, imports) => {
|
|
|
202
838
|
var angularClassImports = (ast) => {
|
|
203
839
|
const imports = /* @__PURE__ */ new Map();
|
|
204
840
|
for (const node of ast.body) {
|
|
205
|
-
if (node.type ===
|
|
841
|
+
if (node.type === import_utils2.TSESTree.AST_NODE_TYPES.ImportDeclaration) {
|
|
206
842
|
addAngularImport(node, imports);
|
|
207
843
|
}
|
|
208
844
|
}
|
|
@@ -217,10 +853,10 @@ var angularClassImports = (ast) => {
|
|
|
217
853
|
};
|
|
218
854
|
|
|
219
855
|
// packages/lint-suite/src/lib/rules/no-unused-angular-instance-fields/rule/angular/angular-member-candidates.ts
|
|
220
|
-
var
|
|
856
|
+
var import_utils4 = require("@typescript-eslint/utils");
|
|
221
857
|
|
|
222
858
|
// packages/lint-suite/src/lib/rules/no-unused-angular-instance-fields/rule/angular/angular-managed-fields.ts
|
|
223
|
-
var
|
|
859
|
+
var import_utils3 = require("@typescript-eslint/utils");
|
|
224
860
|
var managedApis = /* @__PURE__ */ new Set([
|
|
225
861
|
"input",
|
|
226
862
|
"model",
|
|
@@ -233,33 +869,33 @@ var managedApis = /* @__PURE__ */ new Set([
|
|
|
233
869
|
var hasAutomaticEffectCleanup = (node) => {
|
|
234
870
|
const options = node.arguments.at(1);
|
|
235
871
|
if (options === void 0) return true;
|
|
236
|
-
if (options.type !==
|
|
872
|
+
if (options.type !== import_utils3.TSESTree.AST_NODE_TYPES.ObjectExpression) return false;
|
|
237
873
|
return options.properties.every((property) => {
|
|
238
|
-
if (property.type !==
|
|
874
|
+
if (property.type !== import_utils3.TSESTree.AST_NODE_TYPES.Property || property.computed) {
|
|
239
875
|
return false;
|
|
240
876
|
}
|
|
241
|
-
const manualCleanup = property.key.type ===
|
|
242
|
-
return !manualCleanup || property.value.type ===
|
|
877
|
+
const manualCleanup = property.key.type === import_utils3.TSESTree.AST_NODE_TYPES.Identifier && property.key.name === "manualCleanup" || property.key.type === import_utils3.TSESTree.AST_NODE_TYPES.Literal && property.key.value === "manualCleanup";
|
|
878
|
+
return !manualCleanup || property.value.type === import_utils3.TSESTree.AST_NODE_TYPES.Literal && property.value.value === false;
|
|
243
879
|
});
|
|
244
880
|
};
|
|
245
881
|
var angularCoreImportedName = (definition) => {
|
|
246
882
|
if (definition?.type !== "ImportBinding") return null;
|
|
247
|
-
if (definition.node.type !==
|
|
883
|
+
if (definition.node.type !== import_utils3.TSESTree.AST_NODE_TYPES.ImportSpecifier) {
|
|
248
884
|
return null;
|
|
249
885
|
}
|
|
250
|
-
if (definition.parent.type !==
|
|
886
|
+
if (definition.parent.type !== import_utils3.TSESTree.AST_NODE_TYPES.ImportDeclaration) {
|
|
251
887
|
return null;
|
|
252
888
|
}
|
|
253
889
|
if (definition.parent.source.value !== "@angular/core") return null;
|
|
254
890
|
const { imported } = definition.node;
|
|
255
|
-
if (imported.type ===
|
|
891
|
+
if (imported.type === import_utils3.TSESTree.AST_NODE_TYPES.Identifier) {
|
|
256
892
|
return imported.name;
|
|
257
893
|
}
|
|
258
894
|
return imported.value;
|
|
259
895
|
};
|
|
260
896
|
var isAngularComponentRefField = (node, sourceCode) => {
|
|
261
897
|
const type = node.typeAnnotation?.typeAnnotation;
|
|
262
|
-
if (type?.type !==
|
|
898
|
+
if (type?.type !== import_utils3.TSESTree.AST_NODE_TYPES.TSTypeReference || type.typeName.type !== import_utils3.TSESTree.AST_NODE_TYPES.Identifier) {
|
|
263
899
|
return false;
|
|
264
900
|
}
|
|
265
901
|
const reference = sourceCode.getScope(type.typeName).references.find(({ identifier }) => identifier === type.typeName);
|
|
@@ -267,7 +903,7 @@ var isAngularComponentRefField = (node, sourceCode) => {
|
|
|
267
903
|
return angularCoreImportedName(definition) === "ComponentRef";
|
|
268
904
|
};
|
|
269
905
|
var isManagedField = (node, imports, allowEffectFields, sourceCode) => {
|
|
270
|
-
if (node.value?.type !==
|
|
906
|
+
if (node.value?.type !== import_utils3.TSESTree.AST_NODE_TYPES.CallExpression) return false;
|
|
271
907
|
const name = angularName(node.value.callee, imports);
|
|
272
908
|
const isString = typeof name === "string";
|
|
273
909
|
if (!isString) return false;
|
|
@@ -302,12 +938,12 @@ var formsInterfaceMethods = {
|
|
|
302
938
|
Validator: ["validate", "registerOnValidatorChange"]
|
|
303
939
|
};
|
|
304
940
|
var isInstanceField = (node) => {
|
|
305
|
-
if (node.type !==
|
|
306
|
-
return node.key.type ===
|
|
941
|
+
if (node.type !== import_utils4.TSESTree.AST_NODE_TYPES.PropertyDefinition) return false;
|
|
942
|
+
return node.key.type === import_utils4.TSESTree.AST_NODE_TYPES.Identifier;
|
|
307
943
|
};
|
|
308
944
|
var isInstanceMethod = (node) => {
|
|
309
|
-
if (node.type !==
|
|
310
|
-
return node.key.type ===
|
|
945
|
+
if (node.type !== import_utils4.TSESTree.AST_NODE_TYPES.MethodDefinition) return false;
|
|
946
|
+
return node.key.type === import_utils4.TSESTree.AST_NODE_TYPES.Identifier;
|
|
311
947
|
};
|
|
312
948
|
var isExcludedField = (node, localPrivateOnly, sourceCode) => {
|
|
313
949
|
const isModified = node.static || node.declare || node.override;
|
|
@@ -334,7 +970,7 @@ var isExcludedMethod = (node, localPrivateOnly, implementedMethods) => {
|
|
|
334
970
|
var implementedFormsMethods = (node) => {
|
|
335
971
|
const methods = /* @__PURE__ */ new Set();
|
|
336
972
|
for (const heritage of node.implements) {
|
|
337
|
-
if (heritage.expression.type !==
|
|
973
|
+
if (heritage.expression.type !== import_utils4.TSESTree.AST_NODE_TYPES.Identifier) {
|
|
338
974
|
continue;
|
|
339
975
|
}
|
|
340
976
|
for (const name of formsInterfaceMethods[heritage.expression.name] ?? []) {
|
|
@@ -381,32 +1017,34 @@ var methodCandidate = (node, localPrivateOnly, implementedMethods) => {
|
|
|
381
1017
|
};
|
|
382
1018
|
|
|
383
1019
|
// packages/lint-suite/src/lib/rules/no-unused-angular-instance-fields/rule/angular/angular-metadata-reads.ts
|
|
384
|
-
var
|
|
385
|
-
var
|
|
1020
|
+
var import_node_path4 = require("node:path");
|
|
1021
|
+
var import_utils6 = require("@typescript-eslint/utils");
|
|
386
1022
|
|
|
387
1023
|
// packages/lint-suite/src/lib/rules/no-unused-angular-instance-fields/rule/angular/angular-metadata-literals.ts
|
|
388
|
-
var
|
|
1024
|
+
var import_utils5 = require("@typescript-eslint/utils");
|
|
389
1025
|
var text = (node) => {
|
|
390
|
-
if (node?.type ===
|
|
1026
|
+
if (node?.type === import_utils5.TSESTree.AST_NODE_TYPES.Literal && typeof node.value === "string") {
|
|
391
1027
|
return node.value;
|
|
392
1028
|
}
|
|
393
|
-
if (node?.type !==
|
|
1029
|
+
if (node?.type !== import_utils5.TSESTree.AST_NODE_TYPES.TemplateLiteral) return null;
|
|
394
1030
|
const hasExpressions = node.expressions.length > 0;
|
|
395
1031
|
if (hasExpressions) return null;
|
|
396
|
-
|
|
1032
|
+
const [quasi] = node.quasis;
|
|
1033
|
+
if (quasi === void 0) return null;
|
|
1034
|
+
return quasi.value.cooked;
|
|
397
1035
|
};
|
|
398
1036
|
var key = (property) => {
|
|
399
|
-
if (property.type !==
|
|
1037
|
+
if (property.type !== import_utils5.TSESTree.AST_NODE_TYPES.Property || property.computed) {
|
|
400
1038
|
return null;
|
|
401
1039
|
}
|
|
402
|
-
if (property.key.type ===
|
|
1040
|
+
if (property.key.type === import_utils5.TSESTree.AST_NODE_TYPES.Identifier) {
|
|
403
1041
|
return property.key.name;
|
|
404
1042
|
}
|
|
405
1043
|
return text(property.key);
|
|
406
1044
|
};
|
|
407
|
-
var
|
|
1045
|
+
var metadataValue2 = (metadata, name) => {
|
|
408
1046
|
for (const property of metadata.properties) {
|
|
409
|
-
if (property.type !==
|
|
1047
|
+
if (property.type !== import_utils5.TSESTree.AST_NODE_TYPES.Property) continue;
|
|
410
1048
|
const propertyKey = key(property);
|
|
411
1049
|
if (propertyKey === name) return property.value;
|
|
412
1050
|
}
|
|
@@ -414,24 +1052,24 @@ var metadataValue = (metadata, name) => {
|
|
|
414
1052
|
};
|
|
415
1053
|
|
|
416
1054
|
// packages/lint-suite/src/lib/rules/no-unused-angular-instance-fields/rule/angular/angular-template-parsing.ts
|
|
417
|
-
var
|
|
418
|
-
var
|
|
1055
|
+
var import_compiler5 = require("@angular/compiler");
|
|
1056
|
+
var import_node_fs5 = require("node:fs");
|
|
419
1057
|
|
|
420
1058
|
// packages/lint-suite/src/lib/rules/no-unused-angular-instance-fields/rule/angular/angular-expression-reads.ts
|
|
421
|
-
var
|
|
1059
|
+
var import_compiler4 = require("@angular/compiler");
|
|
422
1060
|
|
|
423
1061
|
// packages/lint-suite/src/lib/rules/no-unused-angular-instance-fields/utils/angular-read-target.util.ts
|
|
424
|
-
var
|
|
1062
|
+
var import_compiler3 = require("@angular/compiler");
|
|
425
1063
|
var isReadTarget = (node) => {
|
|
426
|
-
const isPropertyRead = node instanceof
|
|
427
|
-
const isSafePropertyRead = node instanceof
|
|
428
|
-
const isKeyedRead = node instanceof
|
|
429
|
-
const isSafeKeyedRead = node instanceof
|
|
1064
|
+
const isPropertyRead = node instanceof import_compiler3.PropertyRead;
|
|
1065
|
+
const isSafePropertyRead = node instanceof import_compiler3.SafePropertyRead;
|
|
1066
|
+
const isKeyedRead = node instanceof import_compiler3.KeyedRead;
|
|
1067
|
+
const isSafeKeyedRead = node instanceof import_compiler3.SafeKeyedRead;
|
|
430
1068
|
return isPropertyRead || isSafePropertyRead || isKeyedRead || isSafeKeyedRead;
|
|
431
1069
|
};
|
|
432
1070
|
|
|
433
1071
|
// packages/lint-suite/src/lib/rules/no-unused-angular-instance-fields/rule/angular/angular-expression-reads.ts
|
|
434
|
-
var ReadCollector = class extends
|
|
1072
|
+
var ReadCollector = class extends import_compiler4.CombinedRecursiveAstVisitor {
|
|
435
1073
|
reads = /* @__PURE__ */ new Set();
|
|
436
1074
|
boundTarget;
|
|
437
1075
|
action;
|
|
@@ -441,11 +1079,11 @@ var ReadCollector = class extends import_compiler2.CombinedRecursiveAstVisitor {
|
|
|
441
1079
|
this.action = action;
|
|
442
1080
|
}
|
|
443
1081
|
record(node) {
|
|
444
|
-
if (node.receiver instanceof
|
|
1082
|
+
if (node.receiver instanceof import_compiler4.ThisReceiver) {
|
|
445
1083
|
this.reads.add(node.name);
|
|
446
1084
|
return;
|
|
447
1085
|
}
|
|
448
|
-
if (!(node.receiver instanceof
|
|
1086
|
+
if (!(node.receiver instanceof import_compiler4.ImplicitReceiver)) return;
|
|
449
1087
|
const isBindableName = !this.action || node.name !== "$event";
|
|
450
1088
|
if (!isBindableName) return;
|
|
451
1089
|
const expressionTarget = this.boundTarget?.getExpressionTarget(node);
|
|
@@ -457,7 +1095,7 @@ var ReadCollector = class extends import_compiler2.CombinedRecursiveAstVisitor {
|
|
|
457
1095
|
if (isReadTarget(node.left)) {
|
|
458
1096
|
this.visit(node.left.receiver);
|
|
459
1097
|
}
|
|
460
|
-
if (node.left instanceof
|
|
1098
|
+
if (node.left instanceof import_compiler4.KeyedRead || node.left instanceof import_compiler4.SafeKeyedRead) {
|
|
461
1099
|
this.visit(node.left.key);
|
|
462
1100
|
}
|
|
463
1101
|
this.visit(node.right);
|
|
@@ -482,11 +1120,11 @@ var collectAngularExpressionReads = (nodes, boundTarget, action) => {
|
|
|
482
1120
|
|
|
483
1121
|
// packages/lint-suite/src/lib/rules/no-unused-angular-instance-fields/rule/angular/angular-template-parsing.ts
|
|
484
1122
|
var externalTemplates = /* @__PURE__ */ new Map();
|
|
485
|
-
var
|
|
486
|
-
var templateBinder = new
|
|
1123
|
+
var parser2 = new import_compiler5.Parser(new import_compiler5.Lexer());
|
|
1124
|
+
var templateBinder = new import_compiler5.R3TargetBinder(null);
|
|
487
1125
|
var templateReads = (template, filename) => {
|
|
488
1126
|
try {
|
|
489
|
-
const result = (0,
|
|
1127
|
+
const result = (0, import_compiler5.parseTemplate)(template, filename);
|
|
490
1128
|
if (result.errors?.length) return null;
|
|
491
1129
|
return collectAngularExpressionReads(
|
|
492
1130
|
result.nodes,
|
|
@@ -499,11 +1137,11 @@ var templateReads = (template, filename) => {
|
|
|
499
1137
|
};
|
|
500
1138
|
var externalTemplateReads = (filename) => {
|
|
501
1139
|
try {
|
|
502
|
-
const stats = (0,
|
|
1140
|
+
const stats = (0, import_node_fs5.statSync)(filename, { bigint: true });
|
|
503
1141
|
const version = `${stats.mtimeNs}:${stats.size}`;
|
|
504
1142
|
const cached = externalTemplates.get(filename);
|
|
505
1143
|
if (cached?.version === version) return cached.reads;
|
|
506
|
-
const reads = templateReads((0,
|
|
1144
|
+
const reads = templateReads((0, import_node_fs5.readFileSync)(filename, "utf8"), filename);
|
|
507
1145
|
externalTemplates.set(filename, { reads, version });
|
|
508
1146
|
return reads;
|
|
509
1147
|
} catch {
|
|
@@ -511,14 +1149,14 @@ var externalTemplateReads = (filename) => {
|
|
|
511
1149
|
}
|
|
512
1150
|
};
|
|
513
1151
|
var parseExpression = (expression, span, action) => {
|
|
514
|
-
if (action) return
|
|
515
|
-
return
|
|
1152
|
+
if (action) return parser2.parseAction(expression, span, 0);
|
|
1153
|
+
return parser2.parseBinding(expression, span, 0);
|
|
516
1154
|
};
|
|
517
1155
|
var expressionReads = (expression, filename, action) => {
|
|
518
1156
|
try {
|
|
519
|
-
const file = new
|
|
520
|
-
const start = new
|
|
521
|
-
const span = new
|
|
1157
|
+
const file = new import_compiler5.ParseSourceFile(expression, filename);
|
|
1158
|
+
const start = new import_compiler5.ParseLocation(file, 0, 0, 0);
|
|
1159
|
+
const span = new import_compiler5.ParseSourceSpan(start, start.moveBy(expression.length));
|
|
522
1160
|
const result = parseExpression(expression, span, action);
|
|
523
1161
|
if (result.errors.length > 0) return null;
|
|
524
1162
|
return collectAngularExpressionReads([result], void 0, action);
|
|
@@ -551,13 +1189,13 @@ var hostPropertyReads = (property, reads, filename) => {
|
|
|
551
1189
|
};
|
|
552
1190
|
var hostReads = (host, reads, filename) => {
|
|
553
1191
|
if (!host) return true;
|
|
554
|
-
if (host.type !==
|
|
1192
|
+
if (host.type !== import_utils6.TSESTree.AST_NODE_TYPES.ObjectExpression) return false;
|
|
555
1193
|
const hasUnreadableKey = host.properties.some(
|
|
556
1194
|
(property) => key(property) === null
|
|
557
1195
|
);
|
|
558
1196
|
if (hasUnreadableKey) return false;
|
|
559
1197
|
for (const property of host.properties) {
|
|
560
|
-
if (property.type !==
|
|
1198
|
+
if (property.type !== import_utils6.TSESTree.AST_NODE_TYPES.Property) return false;
|
|
561
1199
|
const hasPropertyReads = hostPropertyReads(property, reads, filename);
|
|
562
1200
|
if (!hasPropertyReads) return false;
|
|
563
1201
|
}
|
|
@@ -571,11 +1209,11 @@ var inlineTemplateReads = (template, reads, filename) => {
|
|
|
571
1209
|
var externalTemplatePropertyReads = (templateUrl, reads, filename) => {
|
|
572
1210
|
if (!templateUrl) return true;
|
|
573
1211
|
const url = text(templateUrl);
|
|
574
|
-
return url !== null && addReads(reads, externalTemplateReads((0,
|
|
1212
|
+
return url !== null && addReads(reads, externalTemplateReads((0, import_node_path4.resolve)((0, import_node_path4.dirname)(filename), url)));
|
|
575
1213
|
};
|
|
576
1214
|
var componentTemplateReads = (metadata, reads, filename) => {
|
|
577
|
-
const template =
|
|
578
|
-
const templateUrl =
|
|
1215
|
+
const template = metadataValue2(metadata, "template");
|
|
1216
|
+
const templateUrl = metadataValue2(metadata, "templateUrl");
|
|
579
1217
|
return inlineTemplateReads(template, reads, filename) && externalTemplatePropertyReads(templateUrl, reads, filename);
|
|
580
1218
|
};
|
|
581
1219
|
var metadataReads = (options) => {
|
|
@@ -586,7 +1224,7 @@ var metadataReads = (options) => {
|
|
|
586
1224
|
const hasUnreadableKey = metadata.properties.some(isUnreadableKey);
|
|
587
1225
|
if (hasUnreadableKey) return null;
|
|
588
1226
|
const reads = /* @__PURE__ */ new Set();
|
|
589
|
-
const hostValue =
|
|
1227
|
+
const hostValue = metadataValue2(metadata, "host");
|
|
590
1228
|
const hasHostReads = hostReads(hostValue, reads, filename);
|
|
591
1229
|
if (!hasHostReads) return null;
|
|
592
1230
|
if (!options.component) return reads;
|
|
@@ -672,16 +1310,16 @@ var reportUnusedMembers = (options) => {
|
|
|
672
1310
|
};
|
|
673
1311
|
|
|
674
1312
|
// packages/lint-suite/src/lib/rules/no-unused-angular-instance-fields/rule/typescript/typescript-class-read-visitor.ts
|
|
675
|
-
var
|
|
1313
|
+
var import_utils10 = require("@typescript-eslint/utils");
|
|
676
1314
|
|
|
677
1315
|
// packages/lint-suite/src/lib/rules/no-unused-angular-instance-fields/rule/typescript/typescript-field-reads.ts
|
|
678
|
-
var
|
|
1316
|
+
var import_utils7 = require("@typescript-eslint/utils");
|
|
679
1317
|
var expressionWrapperTypes = /* @__PURE__ */ new Set([
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
1318
|
+
import_utils7.TSESTree.AST_NODE_TYPES.TSAsExpression,
|
|
1319
|
+
import_utils7.TSESTree.AST_NODE_TYPES.TSInstantiationExpression,
|
|
1320
|
+
import_utils7.TSESTree.AST_NODE_TYPES.TSNonNullExpression,
|
|
1321
|
+
import_utils7.TSESTree.AST_NODE_TYPES.TSSatisfiesExpression,
|
|
1322
|
+
import_utils7.TSESTree.AST_NODE_TYPES.TSTypeAssertion
|
|
685
1323
|
]);
|
|
686
1324
|
var isTypeScriptExpressionWrapper = (node) => {
|
|
687
1325
|
return expressionWrapperTypes.has(node.type);
|
|
@@ -695,10 +1333,10 @@ var unwrapTypeScriptExpression = (node) => {
|
|
|
695
1333
|
};
|
|
696
1334
|
var isThisExpression = (node) => {
|
|
697
1335
|
const unwrapped = unwrapTypeScriptExpression(node);
|
|
698
|
-
return unwrapped?.type ===
|
|
1336
|
+
return unwrapped?.type === import_utils7.TSESTree.AST_NODE_TYPES.ThisExpression;
|
|
699
1337
|
};
|
|
700
1338
|
var destructuringParts = (node) => {
|
|
701
|
-
if (node.type ===
|
|
1339
|
+
if (node.type === import_utils7.TSESTree.AST_NODE_TYPES.VariableDeclarator) {
|
|
702
1340
|
const variableParts = {
|
|
703
1341
|
pattern: node.id,
|
|
704
1342
|
source: node.init
|
|
@@ -715,10 +1353,10 @@ var destructuringParts = (node) => {
|
|
|
715
1353
|
return null;
|
|
716
1354
|
};
|
|
717
1355
|
var propertyName = (property) => {
|
|
718
|
-
if (property.type !==
|
|
1356
|
+
if (property.type !== import_utils7.TSESTree.AST_NODE_TYPES.Property || property.computed) {
|
|
719
1357
|
return null;
|
|
720
1358
|
}
|
|
721
|
-
if (property.key.type ===
|
|
1359
|
+
if (property.key.type === import_utils7.TSESTree.AST_NODE_TYPES.Identifier) {
|
|
722
1360
|
return property.key.name;
|
|
723
1361
|
}
|
|
724
1362
|
const { value } = property.key;
|
|
@@ -728,7 +1366,7 @@ var propertyName = (property) => {
|
|
|
728
1366
|
var destructuredThisReads = (node) => {
|
|
729
1367
|
const parts = destructuringParts(node);
|
|
730
1368
|
if (!parts) return void 0;
|
|
731
|
-
if (parts.pattern.type !==
|
|
1369
|
+
if (parts.pattern.type !== import_utils7.TSESTree.AST_NODE_TYPES.ObjectPattern) {
|
|
732
1370
|
return void 0;
|
|
733
1371
|
}
|
|
734
1372
|
const isThisSource = isThisExpression(parts.source);
|
|
@@ -743,13 +1381,13 @@ var destructuredThisReads = (node) => {
|
|
|
743
1381
|
};
|
|
744
1382
|
|
|
745
1383
|
// packages/lint-suite/src/lib/rules/no-unused-angular-instance-fields/rule/typescript/typescript-lexical-this.ts
|
|
746
|
-
var
|
|
1384
|
+
var import_utils8 = require("@typescript-eslint/utils");
|
|
747
1385
|
var componentThis = (node, thisStack) => {
|
|
748
|
-
if (node.type ===
|
|
1386
|
+
if (node.type === import_utils8.TSESTree.AST_NODE_TYPES.ArrowFunctionExpression) {
|
|
749
1387
|
return thisStack.at(-1) ?? false;
|
|
750
1388
|
}
|
|
751
1389
|
const { parent } = node;
|
|
752
|
-
if (parent.type !==
|
|
1390
|
+
if (parent.type !== import_utils8.TSESTree.AST_NODE_TYPES.MethodDefinition) return false;
|
|
753
1391
|
return !parent.static;
|
|
754
1392
|
};
|
|
755
1393
|
var lexicalThisVisitor = (thisStack) => {
|
|
@@ -793,40 +1431,40 @@ var lexicalThisVisitor = (thisStack) => {
|
|
|
793
1431
|
};
|
|
794
1432
|
|
|
795
1433
|
// packages/lint-suite/src/lib/rules/no-unused-angular-instance-fields/rule/typescript/typescript-write-targets.ts
|
|
796
|
-
var
|
|
1434
|
+
var import_utils9 = require("@typescript-eslint/utils");
|
|
797
1435
|
var parentOf = (node) => {
|
|
798
|
-
if (node.type ===
|
|
1436
|
+
if (node.type === import_utils9.TSESTree.AST_NODE_TYPES.Program) return void 0;
|
|
799
1437
|
return node.parent;
|
|
800
1438
|
};
|
|
801
1439
|
var isPatternTarget = (parent, child) => {
|
|
802
1440
|
if (parent === void 0) return false;
|
|
803
|
-
if (parent.type ===
|
|
1441
|
+
if (parent.type === import_utils9.TSESTree.AST_NODE_TYPES.ArrayPattern) {
|
|
804
1442
|
return parent.elements.some((element) => element === child);
|
|
805
1443
|
}
|
|
806
|
-
if (parent.type ===
|
|
1444
|
+
if (parent.type === import_utils9.TSESTree.AST_NODE_TYPES.AssignmentPattern) {
|
|
807
1445
|
return parent.left === child;
|
|
808
1446
|
}
|
|
809
|
-
if (parent.type ===
|
|
1447
|
+
if (parent.type === import_utils9.TSESTree.AST_NODE_TYPES.ObjectPattern) {
|
|
810
1448
|
return parent.properties.some((property) => property === child);
|
|
811
1449
|
}
|
|
812
|
-
if (parent.type ===
|
|
813
|
-
const isObjectPattern = parent.parent.type ===
|
|
1450
|
+
if (parent.type === import_utils9.TSESTree.AST_NODE_TYPES.Property) {
|
|
1451
|
+
const isObjectPattern = parent.parent.type === import_utils9.TSESTree.AST_NODE_TYPES.ObjectPattern;
|
|
814
1452
|
return parent.value === child && isObjectPattern;
|
|
815
1453
|
}
|
|
816
|
-
if (parent.type ===
|
|
1454
|
+
if (parent.type === import_utils9.TSESTree.AST_NODE_TYPES.RestElement) {
|
|
817
1455
|
return parent.argument === child;
|
|
818
1456
|
}
|
|
819
1457
|
return false;
|
|
820
1458
|
};
|
|
821
1459
|
var isSimpleAssignmentTarget = (parent, current) => {
|
|
822
|
-
if (parent?.type !==
|
|
1460
|
+
if (parent?.type !== import_utils9.TSESTree.AST_NODE_TYPES.AssignmentExpression) {
|
|
823
1461
|
return false;
|
|
824
1462
|
}
|
|
825
1463
|
return parent.left === current && parent.operator === "=";
|
|
826
1464
|
};
|
|
827
1465
|
var isLoopTarget = (parent, current) => {
|
|
828
|
-
const isForIn = parent?.type ===
|
|
829
|
-
const isForOf = parent?.type ===
|
|
1466
|
+
const isForIn = parent?.type === import_utils9.TSESTree.AST_NODE_TYPES.ForInStatement;
|
|
1467
|
+
const isForOf = parent?.type === import_utils9.TSESTree.AST_NODE_TYPES.ForOfStatement;
|
|
830
1468
|
const isLoop = isForIn || isForOf;
|
|
831
1469
|
if (!isLoop) return false;
|
|
832
1470
|
return parent.left === current;
|
|
@@ -843,7 +1481,7 @@ var isDirectWrite = (node) => {
|
|
|
843
1481
|
current = parent;
|
|
844
1482
|
parent = parentOf(parent);
|
|
845
1483
|
}
|
|
846
|
-
const isDeleteExpression2 = parent?.type ===
|
|
1484
|
+
const isDeleteExpression2 = parent?.type === import_utils9.TSESTree.AST_NODE_TYPES.UnaryExpression && parent.operator === "delete";
|
|
847
1485
|
const isAssignment = isSimpleAssignmentTarget(parent, current);
|
|
848
1486
|
return isAssignment || isDeleteExpression2;
|
|
849
1487
|
};
|
|
@@ -892,7 +1530,7 @@ var trackMemberRead = (node, stack, thisStack, dynamicClasses) => {
|
|
|
892
1530
|
if (!receiverIsThis || node.computed) return;
|
|
893
1531
|
const isWriteOnlyTarget = isWriteOnly(node);
|
|
894
1532
|
if (isWriteOnlyTarget) return;
|
|
895
|
-
if (node.property.type ===
|
|
1533
|
+
if (node.property.type === import_utils10.TSESTree.AST_NODE_TYPES.Identifier) {
|
|
896
1534
|
current.reads.add(node.property.name);
|
|
897
1535
|
}
|
|
898
1536
|
};
|
|
@@ -942,10 +1580,10 @@ var classReadVisitor = (classes, stack, dynamicClasses) => {
|
|
|
942
1580
|
};
|
|
943
1581
|
|
|
944
1582
|
// packages/lint-suite/src/lib/rules/no-unused-angular-instance-fields/project-usage/project-usage.ts
|
|
945
|
-
var
|
|
1583
|
+
var import_typescript18 = require("typescript");
|
|
946
1584
|
|
|
947
1585
|
// packages/lint-suite/src/lib/rules/no-unused-angular-instance-fields/project-usage/angular/angular-directive-index.ts
|
|
948
|
-
var
|
|
1586
|
+
var import_compiler6 = require("@angular/compiler");
|
|
949
1587
|
var classShape = ({
|
|
950
1588
|
component,
|
|
951
1589
|
declaration,
|
|
@@ -970,7 +1608,7 @@ var directiveShape = (classes) => {
|
|
|
970
1608
|
};
|
|
971
1609
|
var parseSelector = (selector) => {
|
|
972
1610
|
try {
|
|
973
|
-
return
|
|
1611
|
+
return import_compiler6.CssSelector.parse(selector);
|
|
974
1612
|
} catch {
|
|
975
1613
|
return null;
|
|
976
1614
|
}
|
|
@@ -978,7 +1616,7 @@ var parseSelector = (selector) => {
|
|
|
978
1616
|
var buildDirectiveIndex = (classes) => {
|
|
979
1617
|
const byDeclaration = /* @__PURE__ */ new Map();
|
|
980
1618
|
const byExportAs = /* @__PURE__ */ new Map();
|
|
981
|
-
const componentMatcher = new
|
|
1619
|
+
const componentMatcher = new import_compiler6.SelectorMatcher();
|
|
982
1620
|
for (const angularClass2 of classes) {
|
|
983
1621
|
const { component, declaration, exportAs, selector } = angularClass2;
|
|
984
1622
|
byDeclaration.set(declaration, angularClass2);
|
|
@@ -1003,17 +1641,17 @@ var buildDirectiveIndex = (classes) => {
|
|
|
1003
1641
|
};
|
|
1004
1642
|
|
|
1005
1643
|
// packages/lint-suite/src/lib/rules/no-unused-angular-instance-fields/project-usage/angular/angular-template-reads.ts
|
|
1006
|
-
var
|
|
1007
|
-
var
|
|
1644
|
+
var import_node_fs6 = require("node:fs");
|
|
1645
|
+
var import_typescript4 = require("typescript");
|
|
1008
1646
|
|
|
1009
1647
|
// packages/lint-suite/src/lib/rules/no-unused-angular-instance-fields/project-usage/angular/angular-template-read-resolution.ts
|
|
1010
|
-
var
|
|
1648
|
+
var import_compiler9 = require("@angular/compiler");
|
|
1011
1649
|
|
|
1012
1650
|
// packages/lint-suite/src/lib/rules/no-unused-angular-instance-fields/project-usage/angular/angular-resolved-path.ts
|
|
1013
|
-
var
|
|
1651
|
+
var import_typescript3 = require("typescript");
|
|
1014
1652
|
|
|
1015
1653
|
// packages/lint-suite/src/lib/rules/no-unused-angular-instance-fields/project-usage/utils/type-property-symbols.util.ts
|
|
1016
|
-
var
|
|
1654
|
+
var import_typescript2 = require("typescript");
|
|
1017
1655
|
var symbolsForName = (checker, type, name) => {
|
|
1018
1656
|
const symbol = checker.getPropertyOfType(checker.getApparentType(type), name);
|
|
1019
1657
|
if (symbol) return [symbol];
|
|
@@ -1030,7 +1668,7 @@ var symbolsForName = (checker, type, name) => {
|
|
|
1030
1668
|
var stringIndexTypes = (checker, type) => {
|
|
1031
1669
|
const indexedType = checker.getIndexTypeOfType(
|
|
1032
1670
|
checker.getApparentType(type),
|
|
1033
|
-
|
|
1671
|
+
import_typescript2.IndexKind.String
|
|
1034
1672
|
);
|
|
1035
1673
|
if (indexedType) return [indexedType];
|
|
1036
1674
|
const isUnionOrIntersection = type.isUnionOrIntersection();
|
|
@@ -1046,7 +1684,7 @@ var stringIndexTypes = (checker, type) => {
|
|
|
1046
1684
|
|
|
1047
1685
|
// packages/lint-suite/src/lib/rules/no-unused-angular-instance-fields/project-usage/angular/angular-resolved-path.ts
|
|
1048
1686
|
var hasAnyOrUnknownFlag = (type) => {
|
|
1049
|
-
const anyOrUnknown =
|
|
1687
|
+
const anyOrUnknown = import_typescript3.TypeFlags.Any | import_typescript3.TypeFlags.Unknown;
|
|
1050
1688
|
return (type.flags & anyOrUnknown) !== 0;
|
|
1051
1689
|
};
|
|
1052
1690
|
var isAnyOrUnknown = (types) => {
|
|
@@ -1058,7 +1696,7 @@ var addTypes = (sink, types) => {
|
|
|
1058
1696
|
}
|
|
1059
1697
|
};
|
|
1060
1698
|
var callReturnTypes = (checker, type) => {
|
|
1061
|
-
const signatures = checker.getSignaturesOfType(type,
|
|
1699
|
+
const signatures = checker.getSignaturesOfType(type, import_typescript3.SignatureKind.Call);
|
|
1062
1700
|
return signatures.map((signature) => signature.getReturnType());
|
|
1063
1701
|
};
|
|
1064
1702
|
var memberTypes = (symbols, declaration, checker, sink) => {
|
|
@@ -1108,15 +1746,15 @@ var addResolvedPath = ({
|
|
|
1108
1746
|
};
|
|
1109
1747
|
|
|
1110
1748
|
// packages/lint-suite/src/lib/rules/no-unused-angular-instance-fields/project-usage/angular/angular-template-read-chains.ts
|
|
1111
|
-
var
|
|
1749
|
+
var import_compiler7 = require("@angular/compiler");
|
|
1112
1750
|
var isPropertyReadLike = (node) => {
|
|
1113
|
-
const isPlainRead = node instanceof
|
|
1114
|
-
const isSafeRead = node instanceof
|
|
1751
|
+
const isPlainRead = node instanceof import_compiler7.PropertyRead;
|
|
1752
|
+
const isSafeRead = node instanceof import_compiler7.SafePropertyRead;
|
|
1115
1753
|
return isPlainRead || isSafeRead;
|
|
1116
1754
|
};
|
|
1117
1755
|
var isRootRead = (read) => {
|
|
1118
|
-
const isImplicitReceiver = read.receiver instanceof
|
|
1119
|
-
const isThisReceiver = read.receiver instanceof
|
|
1756
|
+
const isImplicitReceiver = read.receiver instanceof import_compiler7.ImplicitReceiver;
|
|
1757
|
+
const isThisReceiver = read.receiver instanceof import_compiler7.ThisReceiver;
|
|
1120
1758
|
return isImplicitReceiver || isThisReceiver;
|
|
1121
1759
|
};
|
|
1122
1760
|
var chainStep = (read) => {
|
|
@@ -1126,7 +1764,7 @@ var chainStep = (read) => {
|
|
|
1126
1764
|
const readStep = { called: false, next: receiver };
|
|
1127
1765
|
return readStep;
|
|
1128
1766
|
}
|
|
1129
|
-
const isCallReceiver = receiver instanceof
|
|
1767
|
+
const isCallReceiver = receiver instanceof import_compiler7.Call;
|
|
1130
1768
|
if (!isCallReceiver) return null;
|
|
1131
1769
|
const target = receiver.receiver;
|
|
1132
1770
|
const isReadLikeTarget = isPropertyReadLike(target);
|
|
@@ -1144,11 +1782,11 @@ var readChain = (node) => {
|
|
|
1144
1782
|
current = step.next;
|
|
1145
1783
|
names.unshift({ called: step.called, name: current.name });
|
|
1146
1784
|
}
|
|
1147
|
-
if (!(current instanceof
|
|
1785
|
+
if (!(current instanceof import_compiler7.PropertyRead)) return null;
|
|
1148
1786
|
const chain = { names, root: current };
|
|
1149
1787
|
return chain;
|
|
1150
1788
|
};
|
|
1151
|
-
var ReadCollector2 = class extends
|
|
1789
|
+
var ReadCollector2 = class extends import_compiler7.CombinedRecursiveAstVisitor {
|
|
1152
1790
|
reads = [];
|
|
1153
1791
|
referenceOwners = /* @__PURE__ */ new Map();
|
|
1154
1792
|
record(node) {
|
|
@@ -1183,7 +1821,7 @@ var ReadCollector2 = class extends import_compiler5.CombinedRecursiveAstVisitor
|
|
|
1183
1821
|
if (isReadTarget(node.left)) {
|
|
1184
1822
|
this.visit(node.left.receiver);
|
|
1185
1823
|
}
|
|
1186
|
-
if (node.left instanceof
|
|
1824
|
+
if (node.left instanceof import_compiler7.KeyedRead || node.left instanceof import_compiler7.SafeKeyedRead) {
|
|
1187
1825
|
this.visit(node.left.key);
|
|
1188
1826
|
}
|
|
1189
1827
|
this.visit(node.right);
|
|
@@ -1200,7 +1838,7 @@ var ReadCollector2 = class extends import_compiler5.CombinedRecursiveAstVisitor
|
|
|
1200
1838
|
};
|
|
1201
1839
|
|
|
1202
1840
|
// packages/lint-suite/src/lib/rules/no-unused-angular-instance-fields/project-usage/angular/angular-template-references.ts
|
|
1203
|
-
var
|
|
1841
|
+
var import_compiler8 = require("@angular/compiler");
|
|
1204
1842
|
|
|
1205
1843
|
// packages/lint-suite/src/lib/rules/no-unused-angular-instance-fields/project-usage/utils/read-chain-text.util.ts
|
|
1206
1844
|
var segmentText = (segment) => {
|
|
@@ -1219,9 +1857,9 @@ var referenceTargets = (reference, owner, directives, scope) => {
|
|
|
1219
1857
|
if (exportAs !== "") {
|
|
1220
1858
|
const exportedTargets = directives.byExportAs.get(exportAs) ?? [];
|
|
1221
1859
|
targets = [...exportedTargets];
|
|
1222
|
-
} else if (owner instanceof
|
|
1860
|
+
} else if (owner instanceof import_compiler8.TmplAstElement) {
|
|
1223
1861
|
directives.componentMatcher.match(
|
|
1224
|
-
(0,
|
|
1862
|
+
(0, import_compiler8.createCssSelectorFromNode)(owner),
|
|
1225
1863
|
(_selector, declarations) => {
|
|
1226
1864
|
targets.push(...declarations);
|
|
1227
1865
|
}
|
|
@@ -1261,7 +1899,7 @@ var identifierNames = (text2) => {
|
|
|
1261
1899
|
const matches = text2.match(/[A-Za-z_$][\w$]*/gu) ?? [];
|
|
1262
1900
|
return new Set(matches);
|
|
1263
1901
|
};
|
|
1264
|
-
var templateBinder2 = new
|
|
1902
|
+
var templateBinder2 = new import_compiler9.R3TargetBinder(null);
|
|
1265
1903
|
var unparsedTemplateReads = (context, source, error) => {
|
|
1266
1904
|
const names = identifierNames(source);
|
|
1267
1905
|
const message = error ?? "unknown error";
|
|
@@ -1286,7 +1924,7 @@ var addComponentRead = (context, names) => {
|
|
|
1286
1924
|
sink.addFallbackNames(fallbackNames, reason);
|
|
1287
1925
|
};
|
|
1288
1926
|
var chainEntity = (boundTarget, chain) => {
|
|
1289
|
-
const isThisRead = chain.root.receiver instanceof
|
|
1927
|
+
const isThisRead = chain.root.receiver instanceof import_compiler9.ThisReceiver;
|
|
1290
1928
|
if (isThisRead) return null;
|
|
1291
1929
|
return boundTarget.getExpressionTarget(chain.root);
|
|
1292
1930
|
};
|
|
@@ -1296,7 +1934,7 @@ var addChainRead = (context, reads, boundTarget, chain) => {
|
|
|
1296
1934
|
addComponentRead(context, chain.names);
|
|
1297
1935
|
return false;
|
|
1298
1936
|
}
|
|
1299
|
-
if (!(entity instanceof
|
|
1937
|
+
if (!(entity instanceof import_compiler9.TmplAstReference)) return false;
|
|
1300
1938
|
const owner = reads.referenceOwners.get(entity);
|
|
1301
1939
|
const names = chain.names.slice(1);
|
|
1302
1940
|
addReferenceRead(context, entity, owner, names);
|
|
@@ -1321,7 +1959,7 @@ var addTemplateReads = ({
|
|
|
1321
1959
|
scope,
|
|
1322
1960
|
sink
|
|
1323
1961
|
};
|
|
1324
|
-
const parsed = (0,
|
|
1962
|
+
const parsed = (0, import_compiler9.parseTemplate)(source, fileName);
|
|
1325
1963
|
if (parsed.errors?.length) {
|
|
1326
1964
|
const error = parsed.errors[0]?.msg;
|
|
1327
1965
|
return unparsedTemplateReads(context, source, error);
|
|
@@ -1344,8 +1982,8 @@ var addTemplateReads = ({
|
|
|
1344
1982
|
var memberNameOf = (member) => {
|
|
1345
1983
|
const name = member.name;
|
|
1346
1984
|
if (!name) return [];
|
|
1347
|
-
const isIdentifierName = (0,
|
|
1348
|
-
const isStringName = (0,
|
|
1985
|
+
const isIdentifierName = (0, import_typescript4.isIdentifier)(name);
|
|
1986
|
+
const isStringName = (0, import_typescript4.isStringLiteralLike)(name);
|
|
1349
1987
|
const isTextName = isIdentifierName || isStringName;
|
|
1350
1988
|
if (!isTextName) return [];
|
|
1351
1989
|
const names = [name.text];
|
|
@@ -1361,13 +1999,13 @@ var unknownTemplateNames = ({ declaration, scope }, allNames) => {
|
|
|
1361
1999
|
return names;
|
|
1362
2000
|
};
|
|
1363
2001
|
var templateFileVersion = (fileName) => {
|
|
1364
|
-
const { mtimeNs, size } = (0,
|
|
2002
|
+
const { mtimeNs, size } = (0, import_node_fs6.statSync)(fileName, { bigint: true });
|
|
1365
2003
|
const version = { fileName, mtimeNs, size };
|
|
1366
2004
|
return version;
|
|
1367
2005
|
};
|
|
1368
2006
|
var templateFileIsCurrent = (version) => {
|
|
1369
2007
|
try {
|
|
1370
|
-
const current = (0,
|
|
2008
|
+
const current = (0, import_node_fs6.statSync)(version.fileName, { bigint: true });
|
|
1371
2009
|
return current.mtimeNs === version.mtimeNs && current.size === version.size;
|
|
1372
2010
|
} catch {
|
|
1373
2011
|
return false;
|
|
@@ -1391,7 +2029,7 @@ var templateSourceOf = (angularClass2, allNames, sink, versions) => {
|
|
|
1391
2029
|
const templateFileName = template.fileName;
|
|
1392
2030
|
try {
|
|
1393
2031
|
versions.push(templateFileVersion(templateFileName));
|
|
1394
|
-
const source = (0,
|
|
2032
|
+
const source = (0, import_node_fs6.readFileSync)(templateFileName, "utf8");
|
|
1395
2033
|
const externalSource = {
|
|
1396
2034
|
fileName: templateFileName,
|
|
1397
2035
|
source
|
|
@@ -1439,15 +2077,15 @@ var collectAngularTemplateReads = ({
|
|
|
1439
2077
|
};
|
|
1440
2078
|
|
|
1441
2079
|
// packages/lint-suite/src/lib/rules/no-unused-angular-instance-fields/project-usage/typescript/typescript-reads.ts
|
|
1442
|
-
var
|
|
2080
|
+
var import_typescript11 = require("typescript");
|
|
1443
2081
|
|
|
1444
2082
|
// packages/lint-suite/src/lib/rules/no-unused-angular-instance-fields/project-usage/typescript/typescript-angular-interface-methods.ts
|
|
1445
|
-
var
|
|
2083
|
+
var import_typescript6 = require("typescript");
|
|
1446
2084
|
|
|
1447
2085
|
// packages/lint-suite/src/lib/rules/no-unused-angular-instance-fields/project-usage/typescript/typescript-symbol-reads.ts
|
|
1448
|
-
var
|
|
2086
|
+
var import_typescript5 = require("typescript");
|
|
1449
2087
|
var aliasTarget = (checker, symbol) => {
|
|
1450
|
-
const isAlias = (symbol.flags &
|
|
2088
|
+
const isAlias = (symbol.flags & import_typescript5.SymbolFlags.Alias) !== 0;
|
|
1451
2089
|
if (!isAlias) return symbol;
|
|
1452
2090
|
return checker.getAliasedSymbol(symbol);
|
|
1453
2091
|
};
|
|
@@ -1499,11 +2137,11 @@ var literalPropertyNames = (type) => {
|
|
|
1499
2137
|
return names;
|
|
1500
2138
|
};
|
|
1501
2139
|
var propertyName2 = (checker, node) => {
|
|
1502
|
-
const isIdentifierName = (0,
|
|
1503
|
-
const isPrivateName = (0,
|
|
1504
|
-
const isStringName = (0,
|
|
1505
|
-
const isNumericName = (0,
|
|
1506
|
-
const isBigIntName = (0,
|
|
2140
|
+
const isIdentifierName = (0, import_typescript5.isIdentifier)(node);
|
|
2141
|
+
const isPrivateName = (0, import_typescript5.isPrivateIdentifier)(node);
|
|
2142
|
+
const isStringName = (0, import_typescript5.isStringLiteralLike)(node);
|
|
2143
|
+
const isNumericName = (0, import_typescript5.isNumericLiteral)(node);
|
|
2144
|
+
const isBigIntName = (0, import_typescript5.isBigIntLiteral)(node);
|
|
1507
2145
|
const isLiteralName = isIdentifierName || isPrivateName || isStringName || isNumericName || isBigIntName;
|
|
1508
2146
|
if (isLiteralName) return [node.text];
|
|
1509
2147
|
return literalPropertyNames(checker.getTypeAtLocation(node.expression));
|
|
@@ -1511,7 +2149,7 @@ var propertyName2 = (checker, node) => {
|
|
|
1511
2149
|
|
|
1512
2150
|
// packages/lint-suite/src/lib/rules/no-unused-angular-instance-fields/project-usage/typescript/typescript-angular-interface-methods.ts
|
|
1513
2151
|
var isAngularMethodSignature = (declaration) => {
|
|
1514
|
-
const isMethod = (0,
|
|
2152
|
+
const isMethod = (0, import_typescript6.isMethodSignature)(declaration);
|
|
1515
2153
|
if (!isMethod) return false;
|
|
1516
2154
|
const fileName = declaration.getSourceFile().fileName.replaceAll("\\", "/");
|
|
1517
2155
|
return fileName.includes("/node_modules/@angular/");
|
|
@@ -1533,7 +2171,7 @@ var addImplementations = (heritageType, classType, checker, sink) => {
|
|
|
1533
2171
|
var collectAngularInterfaceMethods = (node, checker, sink) => {
|
|
1534
2172
|
const heritageClauses = node.heritageClauses ?? [];
|
|
1535
2173
|
const implementsClauses = heritageClauses.filter(
|
|
1536
|
-
(clause) => clause.token ===
|
|
2174
|
+
(clause) => clause.token === import_typescript6.SyntaxKind.ImplementsKeyword
|
|
1537
2175
|
);
|
|
1538
2176
|
if (implementsClauses.length === 0) return;
|
|
1539
2177
|
const classType = checker.getTypeAtLocation(node);
|
|
@@ -1547,26 +2185,26 @@ var collectAngularInterfaceMethods = (node, checker, sink) => {
|
|
|
1547
2185
|
};
|
|
1548
2186
|
|
|
1549
2187
|
// packages/lint-suite/src/lib/rules/no-unused-angular-instance-fields/project-usage/typescript/typescript-destructuring-reads.ts
|
|
1550
|
-
var
|
|
2188
|
+
var import_typescript9 = require("typescript");
|
|
1551
2189
|
|
|
1552
2190
|
// packages/lint-suite/src/lib/rules/no-unused-angular-instance-fields/project-usage/typescript/typescript-assignment-pattern-elements.ts
|
|
1553
|
-
var
|
|
2191
|
+
var import_typescript7 = require("typescript");
|
|
1554
2192
|
var nestedPattern = (expression) => {
|
|
1555
|
-
const isArrayLiteral = (0,
|
|
1556
|
-
const isObjectLiteral = (0,
|
|
2193
|
+
const isArrayLiteral = (0, import_typescript7.isArrayLiteralExpression)(expression);
|
|
2194
|
+
const isObjectLiteral = (0, import_typescript7.isObjectLiteralExpression)(expression);
|
|
1557
2195
|
const isNested = isArrayLiteral || isObjectLiteral;
|
|
1558
2196
|
if (!isNested) return null;
|
|
1559
2197
|
return expression;
|
|
1560
2198
|
};
|
|
1561
2199
|
var nestedPropertyPattern = (property) => {
|
|
1562
|
-
const isAssignment = (0,
|
|
2200
|
+
const isAssignment = (0, import_typescript7.isPropertyAssignment)(property);
|
|
1563
2201
|
if (!isAssignment) return null;
|
|
1564
2202
|
return nestedPattern(property.initializer);
|
|
1565
2203
|
};
|
|
1566
2204
|
var arrayElementRead = (element, index) => {
|
|
1567
|
-
const isOmitted = (0,
|
|
2205
|
+
const isOmitted = (0, import_typescript7.isOmittedExpression)(element);
|
|
1568
2206
|
if (isOmitted) return null;
|
|
1569
|
-
const isRestElement = (0,
|
|
2207
|
+
const isRestElement = (0, import_typescript7.isSpreadElement)(element);
|
|
1570
2208
|
const indexNames = [String(index)];
|
|
1571
2209
|
const names = isRestElement ? null : indexNames;
|
|
1572
2210
|
const nested = nestedPattern(element);
|
|
@@ -1579,7 +2217,7 @@ var arrayElementRead = (element, index) => {
|
|
|
1579
2217
|
return read;
|
|
1580
2218
|
};
|
|
1581
2219
|
var propertyRead = (property, checker) => {
|
|
1582
|
-
const isRestProperty = (0,
|
|
2220
|
+
const isRestProperty = (0, import_typescript7.isSpreadAssignment)(property);
|
|
1583
2221
|
if (isRestProperty) {
|
|
1584
2222
|
const restRead = {
|
|
1585
2223
|
location: property,
|
|
@@ -1598,7 +2236,7 @@ var propertyRead = (property, checker) => {
|
|
|
1598
2236
|
return read;
|
|
1599
2237
|
};
|
|
1600
2238
|
var assignmentPatternElements = (pattern, checker) => {
|
|
1601
|
-
const isArrayPattern = (0,
|
|
2239
|
+
const isArrayPattern = (0, import_typescript7.isArrayLiteralExpression)(pattern);
|
|
1602
2240
|
if (isArrayPattern) {
|
|
1603
2241
|
const reads = [];
|
|
1604
2242
|
for (const [index, element] of pattern.elements.entries()) {
|
|
@@ -1613,10 +2251,10 @@ var assignmentPatternElements = (pattern, checker) => {
|
|
|
1613
2251
|
};
|
|
1614
2252
|
|
|
1615
2253
|
// packages/lint-suite/src/lib/rules/no-unused-angular-instance-fields/project-usage/typescript/typescript-binding-pattern-elements.ts
|
|
1616
|
-
var
|
|
2254
|
+
var import_typescript8 = require("typescript");
|
|
1617
2255
|
var isBindingPattern = (node) => {
|
|
1618
|
-
const isArrayPattern = (0,
|
|
1619
|
-
const isObjectPattern = (0,
|
|
2256
|
+
const isArrayPattern = (0, import_typescript8.isArrayBindingPattern)(node);
|
|
2257
|
+
const isObjectPattern = (0, import_typescript8.isObjectBindingPattern)(node);
|
|
1620
2258
|
return isArrayPattern || isObjectPattern;
|
|
1621
2259
|
};
|
|
1622
2260
|
var nestedPattern2 = (element) => {
|
|
@@ -1626,12 +2264,12 @@ var nestedPattern2 = (element) => {
|
|
|
1626
2264
|
};
|
|
1627
2265
|
var bindingNames = (checker, element) => {
|
|
1628
2266
|
if (element.propertyName) return propertyName2(checker, element.propertyName);
|
|
1629
|
-
const isIdentifierName = (0,
|
|
2267
|
+
const isIdentifierName = (0, import_typescript8.isIdentifier)(element.name);
|
|
1630
2268
|
if (!isIdentifierName) return null;
|
|
1631
2269
|
return [element.name.text];
|
|
1632
2270
|
};
|
|
1633
2271
|
var arrayElementRead2 = (element, index) => {
|
|
1634
|
-
const isOmitted = (0,
|
|
2272
|
+
const isOmitted = (0, import_typescript8.isOmittedExpression)(element);
|
|
1635
2273
|
if (isOmitted) return null;
|
|
1636
2274
|
const isRestElement = Boolean(element.dotDotDotToken);
|
|
1637
2275
|
const indexNames = [String(index)];
|
|
@@ -1665,7 +2303,7 @@ var objectElementRead = (element, checker) => {
|
|
|
1665
2303
|
return read;
|
|
1666
2304
|
};
|
|
1667
2305
|
var bindingPatternElements = (pattern, checker) => {
|
|
1668
|
-
const isArrayPattern = (0,
|
|
2306
|
+
const isArrayPattern = (0, import_typescript8.isArrayBindingPattern)(pattern);
|
|
1669
2307
|
if (isArrayPattern) {
|
|
1670
2308
|
const reads = [];
|
|
1671
2309
|
for (const [index, element] of pattern.elements.entries()) {
|
|
@@ -1731,11 +2369,11 @@ var collectPatternReads = (pattern, type, context) => {
|
|
|
1731
2369
|
var collectBindingReads = (node, context) => {
|
|
1732
2370
|
const isBinding = isBindingPattern(node);
|
|
1733
2371
|
if (!isBinding) return;
|
|
1734
|
-
const isBindingElementParent = (0,
|
|
2372
|
+
const isBindingElementParent = (0, import_typescript9.isBindingElement)(node.parent);
|
|
1735
2373
|
const isNestedBindingName = isBindingElementParent && node.parent.name === node;
|
|
1736
2374
|
if (isNestedBindingName) return;
|
|
1737
2375
|
const declaration = node.parent;
|
|
1738
|
-
const isDeclaration = (0,
|
|
2376
|
+
const isDeclaration = (0, import_typescript9.isVariableDeclaration)(declaration);
|
|
1739
2377
|
const isInitializedDeclaration = isDeclaration && declaration.initializer !== void 0;
|
|
1740
2378
|
const source = isInitializedDeclaration ? declaration.initializer : declaration;
|
|
1741
2379
|
const sourceTypeOf = () => context.checker.getTypeAtLocation(source);
|
|
@@ -1743,12 +2381,12 @@ var collectBindingReads = (node, context) => {
|
|
|
1743
2381
|
collectPatternReads(node, sourceType, context);
|
|
1744
2382
|
};
|
|
1745
2383
|
var collectAssignmentReads = (node, context) => {
|
|
1746
|
-
const isBinary = (0,
|
|
2384
|
+
const isBinary = (0, import_typescript9.isBinaryExpression)(node);
|
|
1747
2385
|
if (!isBinary) return;
|
|
1748
|
-
const isEqualsAssignment = node.operatorToken.kind ===
|
|
2386
|
+
const isEqualsAssignment = node.operatorToken.kind === import_typescript9.SyntaxKind.EqualsToken;
|
|
1749
2387
|
if (!isEqualsAssignment) return;
|
|
1750
|
-
const isArrayTarget = (0,
|
|
1751
|
-
const isObjectTarget = (0,
|
|
2388
|
+
const isArrayTarget = (0, import_typescript9.isArrayLiteralExpression)(node.left);
|
|
2389
|
+
const isObjectTarget = (0, import_typescript9.isObjectLiteralExpression)(node.left);
|
|
1752
2390
|
const isDestructuringAssignment = isArrayTarget || isObjectTarget;
|
|
1753
2391
|
if (!isDestructuringAssignment) return;
|
|
1754
2392
|
const rightTypeOf = () => context.checker.getTypeAtLocation(node.right);
|
|
@@ -1762,42 +2400,42 @@ var collectDestructuringReads = (node, checker, sink, candidateNames) => {
|
|
|
1762
2400
|
};
|
|
1763
2401
|
|
|
1764
2402
|
// packages/lint-suite/src/lib/rules/no-unused-angular-instance-fields/project-usage/typescript/typescript-write-targets.ts
|
|
1765
|
-
var
|
|
2403
|
+
var import_typescript10 = require("typescript");
|
|
1766
2404
|
var isExpressionWrapper = (parent, child) => {
|
|
1767
|
-
const isParenthesized = (0,
|
|
1768
|
-
const isAs = (0,
|
|
1769
|
-
const isTypeAssertion = (0,
|
|
1770
|
-
const isNonNull = (0,
|
|
1771
|
-
const isSatisfies = (0,
|
|
2405
|
+
const isParenthesized = (0, import_typescript10.isParenthesizedExpression)(parent);
|
|
2406
|
+
const isAs = (0, import_typescript10.isAsExpression)(parent);
|
|
2407
|
+
const isTypeAssertion = (0, import_typescript10.isTypeAssertionExpression)(parent);
|
|
2408
|
+
const isNonNull = (0, import_typescript10.isNonNullExpression)(parent);
|
|
2409
|
+
const isSatisfies = (0, import_typescript10.isSatisfiesExpression)(parent);
|
|
1772
2410
|
const isCast = isAs || isTypeAssertion || isSatisfies;
|
|
1773
2411
|
const isWrapper = isParenthesized || isNonNull || isCast;
|
|
1774
2412
|
if (!isWrapper) return false;
|
|
1775
2413
|
return parent.expression === child;
|
|
1776
2414
|
};
|
|
1777
2415
|
var isPatternContainer = (parent, child) => {
|
|
1778
|
-
const isArrayLiteral = (0,
|
|
2416
|
+
const isArrayLiteral = (0, import_typescript10.isArrayLiteralExpression)(parent);
|
|
1779
2417
|
if (isArrayLiteral) {
|
|
1780
2418
|
return parent.elements.some((element) => element === child);
|
|
1781
2419
|
}
|
|
1782
|
-
const isObjectLiteral = (0,
|
|
2420
|
+
const isObjectLiteral = (0, import_typescript10.isObjectLiteralExpression)(parent);
|
|
1783
2421
|
if (isObjectLiteral) {
|
|
1784
2422
|
return parent.properties.some((property) => property === child);
|
|
1785
2423
|
}
|
|
1786
|
-
const isAssignment = (0,
|
|
2424
|
+
const isAssignment = (0, import_typescript10.isPropertyAssignment)(parent);
|
|
1787
2425
|
if (isAssignment) return parent.initializer === child;
|
|
1788
|
-
const isSpread = (0,
|
|
2426
|
+
const isSpread = (0, import_typescript10.isSpreadAssignment)(parent);
|
|
1789
2427
|
if (!isSpread) return false;
|
|
1790
2428
|
return parent.expression === child;
|
|
1791
2429
|
};
|
|
1792
2430
|
var isWriteTarget = (parent, current) => {
|
|
1793
|
-
const isBinary = (0,
|
|
1794
|
-
const isBinaryTarget = isBinary && parent.left === current && parent.operatorToken.kind ===
|
|
2431
|
+
const isBinary = (0, import_typescript10.isBinaryExpression)(parent);
|
|
2432
|
+
const isBinaryTarget = isBinary && parent.left === current && parent.operatorToken.kind === import_typescript10.SyntaxKind.EqualsToken;
|
|
1795
2433
|
if (isBinaryTarget) return true;
|
|
1796
|
-
const isDelete = (0,
|
|
2434
|
+
const isDelete = (0, import_typescript10.isDeleteExpression)(parent);
|
|
1797
2435
|
const isDeleteTarget = isDelete && parent.expression === current;
|
|
1798
2436
|
if (isDeleteTarget) return true;
|
|
1799
|
-
const isForIn = (0,
|
|
1800
|
-
const isForOf = (0,
|
|
2437
|
+
const isForIn = (0, import_typescript10.isForInStatement)(parent);
|
|
2438
|
+
const isForOf = (0, import_typescript10.isForOfStatement)(parent);
|
|
1801
2439
|
const isIteration = isForIn || isForOf;
|
|
1802
2440
|
return isIteration && parent.initializer === current;
|
|
1803
2441
|
};
|
|
@@ -1837,9 +2475,9 @@ var addElementAccessRead = (node, checker, sink, candidateNames) => {
|
|
|
1837
2475
|
};
|
|
1838
2476
|
var collectTypeScriptReads = (sourceFile, checker, sink, candidateNames) => {
|
|
1839
2477
|
const visit = (node) => {
|
|
1840
|
-
const isPropertyAccess = (0,
|
|
1841
|
-
const isElementAccess = (0,
|
|
1842
|
-
const isClass = (0,
|
|
2478
|
+
const isPropertyAccess = (0, import_typescript11.isPropertyAccessExpression)(node);
|
|
2479
|
+
const isElementAccess = (0, import_typescript11.isElementAccessExpression)(node);
|
|
2480
|
+
const isClass = (0, import_typescript11.isClassLike)(node);
|
|
1843
2481
|
if (isPropertyAccess) {
|
|
1844
2482
|
addPropertyAccessRead(node, checker, sink, candidateNames);
|
|
1845
2483
|
} else if (isElementAccess) {
|
|
@@ -1848,21 +2486,21 @@ var collectTypeScriptReads = (sourceFile, checker, sink, candidateNames) => {
|
|
|
1848
2486
|
collectAngularInterfaceMethods(node, checker, sink);
|
|
1849
2487
|
}
|
|
1850
2488
|
collectDestructuringReads(node, checker, sink, candidateNames);
|
|
1851
|
-
(0,
|
|
2489
|
+
(0, import_typescript11.forEachChild)(node, visit);
|
|
1852
2490
|
};
|
|
1853
2491
|
visit(sourceFile);
|
|
1854
2492
|
};
|
|
1855
2493
|
|
|
1856
2494
|
// packages/lint-suite/src/lib/rules/no-unused-angular-instance-fields/project-usage/typescript/typescript-type-dependencies.ts
|
|
1857
|
-
var
|
|
2495
|
+
var import_typescript12 = require("typescript");
|
|
1858
2496
|
var isObjectType = (type) => {
|
|
1859
|
-
return (type.flags &
|
|
2497
|
+
return (type.flags & import_typescript12.TypeFlags.Object) !== 0;
|
|
1860
2498
|
};
|
|
1861
2499
|
var isTypeReference = (type) => {
|
|
1862
|
-
return (type.objectFlags &
|
|
2500
|
+
return (type.objectFlags & import_typescript12.ObjectFlags.Reference) !== 0;
|
|
1863
2501
|
};
|
|
1864
2502
|
var isInterfaceType = (type) => {
|
|
1865
|
-
return (type.objectFlags &
|
|
2503
|
+
return (type.objectFlags & import_typescript12.ObjectFlags.ClassOrInterface) !== 0;
|
|
1866
2504
|
};
|
|
1867
2505
|
var addDeclarationFiles = (type, dependencies) => {
|
|
1868
2506
|
for (const symbol of [type.getSymbol(), type.aliasSymbol]) {
|
|
@@ -1893,7 +2531,7 @@ var addTypeDependencies = (checker, type, dependencies, seen) => {
|
|
|
1893
2531
|
return;
|
|
1894
2532
|
}
|
|
1895
2533
|
addDeclarationFiles(type, dependencies);
|
|
1896
|
-
const isTypeParameter = (type.flags &
|
|
2534
|
+
const isTypeParameter = (type.flags & import_typescript12.TypeFlags.TypeParameter) !== 0;
|
|
1897
2535
|
if (isTypeParameter) {
|
|
1898
2536
|
const constraint = checker.getBaseConstraintOfType(type);
|
|
1899
2537
|
if (constraint) {
|
|
@@ -1956,24 +2594,24 @@ var computeEntry = (index, sourceFile, checker) => {
|
|
|
1956
2594
|
};
|
|
1957
2595
|
const reads = collectFileReads(index, sourceFile, checker, sink);
|
|
1958
2596
|
dependencies.delete(sourceFile);
|
|
1959
|
-
const
|
|
2597
|
+
const fileEntry2 = {
|
|
1960
2598
|
...reads,
|
|
1961
2599
|
declarations,
|
|
1962
2600
|
dependencies,
|
|
1963
2601
|
fallbackNames,
|
|
1964
2602
|
sourceFile
|
|
1965
2603
|
};
|
|
1966
|
-
return
|
|
2604
|
+
return fileEntry2;
|
|
1967
2605
|
};
|
|
1968
2606
|
|
|
1969
2607
|
// packages/lint-suite/src/lib/rules/no-unused-angular-instance-fields/project-usage/angular/angular-component-discovery.ts
|
|
1970
|
-
var
|
|
2608
|
+
var import_typescript16 = require("typescript");
|
|
1971
2609
|
|
|
1972
2610
|
// packages/lint-suite/src/lib/rules/no-unused-angular-instance-fields/project-usage/angular/angular-component-scope.ts
|
|
1973
|
-
var
|
|
2611
|
+
var import_typescript15 = require("typescript");
|
|
1974
2612
|
|
|
1975
2613
|
// packages/lint-suite/src/lib/rules/no-unused-angular-instance-fields/project-usage/angular/angular-decorator-kind.ts
|
|
1976
|
-
var
|
|
2614
|
+
var import_typescript13 = require("typescript");
|
|
1977
2615
|
var decoratorKinds = [
|
|
1978
2616
|
"Component",
|
|
1979
2617
|
"Directive",
|
|
@@ -1993,8 +2631,8 @@ var parentOf2 = (node) => {
|
|
|
1993
2631
|
var importedFromAngularCore = (declaration) => {
|
|
1994
2632
|
let current = parentOf2(declaration);
|
|
1995
2633
|
while (current) {
|
|
1996
|
-
if ((0,
|
|
1997
|
-
return (0,
|
|
2634
|
+
if ((0, import_typescript13.isImportDeclaration)(current)) {
|
|
2635
|
+
return (0, import_typescript13.isStringLiteralLike)(current.moduleSpecifier) && current.moduleSpecifier.text === "@angular/core";
|
|
1998
2636
|
}
|
|
1999
2637
|
current = parentOf2(current);
|
|
2000
2638
|
}
|
|
@@ -2006,7 +2644,7 @@ var resolveAlias = (symbol, discovery) => {
|
|
|
2006
2644
|
for (const declaration of current.declarations ?? []) {
|
|
2007
2645
|
discovery.dependencies.add(declaration.getSourceFile());
|
|
2008
2646
|
}
|
|
2009
|
-
if ((current.flags &
|
|
2647
|
+
if ((current.flags & import_typescript13.SymbolFlags.Alias) === 0) return current;
|
|
2010
2648
|
const next = discovery.checker.getImmediateAliasedSymbol(current);
|
|
2011
2649
|
if (!next || next === current) return current;
|
|
2012
2650
|
current = next;
|
|
@@ -2029,10 +2667,10 @@ var angularDecoratorKind = (expression, discovery) => {
|
|
|
2029
2667
|
return name;
|
|
2030
2668
|
};
|
|
2031
2669
|
var classDecoratorKind = (declaration, discovery) => {
|
|
2032
|
-
const hasDecorators = (0,
|
|
2670
|
+
const hasDecorators = (0, import_typescript13.canHaveDecorators)(declaration);
|
|
2033
2671
|
if (!hasDecorators) return null;
|
|
2034
|
-
for (const decorator of (0,
|
|
2035
|
-
const isDecoratorCall = (0,
|
|
2672
|
+
for (const decorator of (0, import_typescript13.getDecorators)(declaration) ?? []) {
|
|
2673
|
+
const isDecoratorCall = (0, import_typescript13.isCallExpression)(decorator.expression);
|
|
2036
2674
|
if (!isDecoratorCall) continue;
|
|
2037
2675
|
const kind = angularDecoratorKind(
|
|
2038
2676
|
decorator.expression.expression,
|
|
@@ -2044,17 +2682,17 @@ var classDecoratorKind = (declaration, discovery) => {
|
|
|
2044
2682
|
};
|
|
2045
2683
|
|
|
2046
2684
|
// packages/lint-suite/src/lib/rules/no-unused-angular-instance-fields/project-usage/angular/angular-metadata-values.ts
|
|
2047
|
-
var
|
|
2048
|
-
var
|
|
2685
|
+
var import_node_path5 = require("node:path");
|
|
2686
|
+
var import_typescript14 = require("typescript");
|
|
2049
2687
|
var stringValue = (node, discovery) => {
|
|
2050
2688
|
if (!node) return null;
|
|
2051
|
-
const isStringLiteral = (0,
|
|
2689
|
+
const isStringLiteral = (0, import_typescript14.isStringLiteralLike)(node);
|
|
2052
2690
|
if (isStringLiteral) return node.text;
|
|
2053
|
-
const isIdentifierNode = (0,
|
|
2054
|
-
const isPropertyAccessNode = (0,
|
|
2691
|
+
const isIdentifierNode = (0, import_typescript14.isIdentifier)(node);
|
|
2692
|
+
const isPropertyAccessNode = (0, import_typescript14.isPropertyAccessExpression)(node);
|
|
2055
2693
|
if (isIdentifierNode || isPropertyAccessNode) {
|
|
2056
2694
|
const symbol = discovery.checker.getSymbolAtLocation(
|
|
2057
|
-
(0,
|
|
2695
|
+
(0, import_typescript14.isIdentifier)(node) ? node : node.name
|
|
2058
2696
|
);
|
|
2059
2697
|
if (symbol) {
|
|
2060
2698
|
resolveAlias(symbol, discovery);
|
|
@@ -2065,11 +2703,11 @@ var stringValue = (node, discovery) => {
|
|
|
2065
2703
|
};
|
|
2066
2704
|
var metadataProperty = (metadata, name) => {
|
|
2067
2705
|
for (const property of metadata.properties) {
|
|
2068
|
-
const isAssignment = (0,
|
|
2706
|
+
const isAssignment = (0, import_typescript14.isPropertyAssignment)(property);
|
|
2069
2707
|
if (!isAssignment) continue;
|
|
2070
|
-
const isIdentifierName = (0,
|
|
2071
|
-
const isStringName = (0,
|
|
2072
|
-
const isNumericName = (0,
|
|
2708
|
+
const isIdentifierName = (0, import_typescript14.isIdentifier)(property.name);
|
|
2709
|
+
const isStringName = (0, import_typescript14.isStringLiteralLike)(property.name);
|
|
2710
|
+
const isNumericName = (0, import_typescript14.isNumericLiteral)(property.name);
|
|
2073
2711
|
const isLiteralName = isIdentifierName || isStringName || isNumericName;
|
|
2074
2712
|
const isPropertyNamed = isLiteralName && property.name.text === name;
|
|
2075
2713
|
if (isPropertyNamed) return property.initializer;
|
|
@@ -2088,7 +2726,7 @@ var templateOf = (metadata, fileName, discovery) => {
|
|
|
2088
2726
|
if (url) {
|
|
2089
2727
|
const text2 = stringValue(url, discovery);
|
|
2090
2728
|
if (text2 === null) return void 0;
|
|
2091
|
-
const externalFileName = (0,
|
|
2729
|
+
const externalFileName = (0, import_node_path5.resolve)((0, import_node_path5.dirname)(fileName), text2);
|
|
2092
2730
|
const externalTemplate = {
|
|
2093
2731
|
fileName: externalFileName,
|
|
2094
2732
|
kind: "external"
|
|
@@ -2107,14 +2745,14 @@ var exportAsOf = (metadata, discovery) => {
|
|
|
2107
2745
|
// packages/lint-suite/src/lib/rules/no-unused-angular-instance-fields/project-usage/angular/angular-component-scope.ts
|
|
2108
2746
|
var booleanValue = (node) => {
|
|
2109
2747
|
if (!node) return void 0;
|
|
2110
|
-
if (node.kind ===
|
|
2111
|
-
if (node.kind ===
|
|
2748
|
+
if (node.kind === import_typescript15.SyntaxKind.TrueKeyword) return true;
|
|
2749
|
+
if (node.kind === import_typescript15.SyntaxKind.FalseKeyword) return false;
|
|
2112
2750
|
return void 0;
|
|
2113
2751
|
};
|
|
2114
2752
|
var classesOf = (symbol, discovery) => {
|
|
2115
2753
|
const resolved = resolveAlias(symbol, discovery);
|
|
2116
2754
|
const declarations = resolved.declarations ?? [];
|
|
2117
|
-
return declarations.filter(
|
|
2755
|
+
return declarations.filter(import_typescript15.isClassLike);
|
|
2118
2756
|
};
|
|
2119
2757
|
var scopedClasses = (classes, discovery) => {
|
|
2120
2758
|
const scoped = [];
|
|
@@ -2128,8 +2766,8 @@ var scopedClasses = (classes, discovery) => {
|
|
|
2128
2766
|
return scoped;
|
|
2129
2767
|
};
|
|
2130
2768
|
var importedClasses = (element, discovery) => {
|
|
2131
|
-
const isIdentifierElement = (0,
|
|
2132
|
-
const isPropertyAccessElement = (0,
|
|
2769
|
+
const isIdentifierElement = (0, import_typescript15.isIdentifier)(element);
|
|
2770
|
+
const isPropertyAccessElement = (0, import_typescript15.isPropertyAccessExpression)(element);
|
|
2133
2771
|
if (!isIdentifierElement && !isPropertyAccessElement) return null;
|
|
2134
2772
|
const target = isIdentifierElement ? element : element.name;
|
|
2135
2773
|
const symbol = discovery.checker.getSymbolAtLocation(target);
|
|
@@ -2144,7 +2782,7 @@ var scopeOf = (metadata, discovery) => {
|
|
|
2144
2782
|
const isModuleDeclared = standalone === void 0 && !imports;
|
|
2145
2783
|
if (standalone === false || isModuleDeclared) return null;
|
|
2146
2784
|
if (!imports) return [];
|
|
2147
|
-
const isImportsArray = (0,
|
|
2785
|
+
const isImportsArray = (0, import_typescript15.isArrayLiteralExpression)(imports);
|
|
2148
2786
|
if (!isImportsArray) return null;
|
|
2149
2787
|
const scope = [];
|
|
2150
2788
|
for (const element of imports.elements) {
|
|
@@ -2197,7 +2835,7 @@ var decoratedClass = (declaration, call, discovery) => {
|
|
|
2197
2835
|
const bareDiscovery = { ...base2, valid: !component };
|
|
2198
2836
|
return bareDiscovery;
|
|
2199
2837
|
}
|
|
2200
|
-
const isMetadataObject = (0,
|
|
2838
|
+
const isMetadataObject = (0, import_typescript16.isObjectLiteralExpression)(metadata);
|
|
2201
2839
|
if (!isMetadataObject) {
|
|
2202
2840
|
const invalidDiscovery = { ...base2, valid: false };
|
|
2203
2841
|
return invalidDiscovery;
|
|
@@ -2205,10 +2843,10 @@ var decoratedClass = (declaration, call, discovery) => {
|
|
|
2205
2843
|
return describedClass(base2, metadata, discovery);
|
|
2206
2844
|
};
|
|
2207
2845
|
var angularClass = (declaration, discovery) => {
|
|
2208
|
-
const hasDecorators = (0,
|
|
2846
|
+
const hasDecorators = (0, import_typescript16.canHaveDecorators)(declaration);
|
|
2209
2847
|
if (!hasDecorators) return null;
|
|
2210
|
-
for (const decorator of (0,
|
|
2211
|
-
const isDecoratorCall = (0,
|
|
2848
|
+
for (const decorator of (0, import_typescript16.getDecorators)(declaration) ?? []) {
|
|
2849
|
+
const isDecoratorCall = (0, import_typescript16.isCallExpression)(decorator.expression);
|
|
2212
2850
|
if (!isDecoratorCall) continue;
|
|
2213
2851
|
const found = decoratedClass(declaration, decorator.expression, discovery);
|
|
2214
2852
|
if (found) return found;
|
|
@@ -2219,14 +2857,14 @@ var angularClasses = (sourceFile, checker) => {
|
|
|
2219
2857
|
const classes = [];
|
|
2220
2858
|
const discovery = { checker, dependencies: /* @__PURE__ */ new Set() };
|
|
2221
2859
|
const visit = (node) => {
|
|
2222
|
-
const isClass = (0,
|
|
2860
|
+
const isClass = (0, import_typescript16.isClassLike)(node);
|
|
2223
2861
|
if (isClass) {
|
|
2224
2862
|
const found = angularClass(node, discovery);
|
|
2225
2863
|
if (found) {
|
|
2226
2864
|
classes.push(found);
|
|
2227
2865
|
}
|
|
2228
2866
|
}
|
|
2229
|
-
(0,
|
|
2867
|
+
(0, import_typescript16.forEachChild)(node, visit);
|
|
2230
2868
|
};
|
|
2231
2869
|
visit(sourceFile);
|
|
2232
2870
|
discovery.dependencies.delete(sourceFile);
|
|
@@ -2327,23 +2965,23 @@ var dropStaleTemplateEntries = (index, force) => {
|
|
|
2327
2965
|
};
|
|
2328
2966
|
|
|
2329
2967
|
// packages/lint-suite/src/lib/rules/no-unused-angular-instance-fields/project-usage/typescript/typescript-candidate-names.ts
|
|
2330
|
-
var
|
|
2968
|
+
var import_typescript17 = require("typescript");
|
|
2331
2969
|
var isDecoratedClass = (node) => {
|
|
2332
|
-
const isDecoratable = (0,
|
|
2970
|
+
const isDecoratable = (0, import_typescript17.canHaveDecorators)(node);
|
|
2333
2971
|
if (!isDecoratable) return false;
|
|
2334
|
-
const decorators = (0,
|
|
2972
|
+
const decorators = (0, import_typescript17.getDecorators)(node);
|
|
2335
2973
|
const decoratorCount = decorators?.length ?? 0;
|
|
2336
2974
|
return decoratorCount > 0;
|
|
2337
2975
|
};
|
|
2338
2976
|
var addMemberNames = (node, names) => {
|
|
2339
|
-
const isClass = (0,
|
|
2977
|
+
const isClass = (0, import_typescript17.isClassLike)(node);
|
|
2340
2978
|
if (!isClass) return;
|
|
2341
2979
|
const isDecorated = isDecoratedClass(node);
|
|
2342
2980
|
if (!isDecorated) return;
|
|
2343
2981
|
for (const member of node.members) {
|
|
2344
2982
|
if (!member.name) continue;
|
|
2345
|
-
const isIdentifierName = (0,
|
|
2346
|
-
const isStringName = (0,
|
|
2983
|
+
const isIdentifierName = (0, import_typescript17.isIdentifier)(member.name);
|
|
2984
|
+
const isStringName = (0, import_typescript17.isStringLiteralLike)(member.name);
|
|
2347
2985
|
const isNamedMember = isIdentifierName || isStringName;
|
|
2348
2986
|
if (isNamedMember) {
|
|
2349
2987
|
names.add(member.name.text);
|
|
@@ -2354,7 +2992,7 @@ var collectCandidateNames = (sourceFile) => {
|
|
|
2354
2992
|
const names = /* @__PURE__ */ new Set();
|
|
2355
2993
|
const visit = (node) => {
|
|
2356
2994
|
addMemberNames(node, names);
|
|
2357
|
-
(0,
|
|
2995
|
+
(0, import_typescript17.forEachChild)(node, visit);
|
|
2358
2996
|
};
|
|
2359
2997
|
visit(sourceFile);
|
|
2360
2998
|
return names;
|
|
@@ -2470,11 +3108,11 @@ var reconcile = (index, program) => {
|
|
|
2470
3108
|
// packages/lint-suite/src/lib/rules/no-unused-angular-instance-fields/project-usage/project-usage.ts
|
|
2471
3109
|
var indexes = /* @__PURE__ */ new Map();
|
|
2472
3110
|
var memberName = (node) => {
|
|
2473
|
-
const isMember = (0,
|
|
3111
|
+
const isMember = (0, import_typescript18.isClassElement)(node);
|
|
2474
3112
|
if (!isMember) return null;
|
|
2475
3113
|
if (!node.name) return null;
|
|
2476
|
-
const isIdentifierName = (0,
|
|
2477
|
-
const isStringName = (0,
|
|
3114
|
+
const isIdentifierName = (0, import_typescript18.isIdentifier)(node.name);
|
|
3115
|
+
const isStringName = (0, import_typescript18.isStringLiteralLike)(node.name);
|
|
2478
3116
|
const isNamedMember = isIdentifierName || isStringName;
|
|
2479
3117
|
if (!isNamedMember) return null;
|
|
2480
3118
|
return node.name.text;
|
|
@@ -2538,10 +3176,10 @@ var projectUsage = (program) => {
|
|
|
2538
3176
|
};
|
|
2539
3177
|
|
|
2540
3178
|
// packages/lint-suite/src/lib/rules/no-unused-angular-instance-fields/rule/no-unused-angular-instance-fields.ts
|
|
2541
|
-
var
|
|
3179
|
+
var docs2 = {
|
|
2542
3180
|
description: "Disallow unread instance fields and methods in Angular components and directives"
|
|
2543
3181
|
};
|
|
2544
|
-
var
|
|
3182
|
+
var messages2 = {
|
|
2545
3183
|
unusedField: "Angular instance field '{{name}}' is never read.",
|
|
2546
3184
|
unusedMethod: "Angular instance method '{{name}}' is never read."
|
|
2547
3185
|
};
|
|
@@ -2554,34 +3192,34 @@ var analysisSchema = {
|
|
|
2554
3192
|
enum: ["local", "project"],
|
|
2555
3193
|
description: "Choose local-file or typed whole-project analysis."
|
|
2556
3194
|
};
|
|
2557
|
-
var
|
|
3195
|
+
var properties2 = {
|
|
2558
3196
|
allowEffectFields: allowEffectFieldsSchema,
|
|
2559
3197
|
analysis: analysisSchema
|
|
2560
3198
|
};
|
|
2561
|
-
var
|
|
3199
|
+
var optionsSchema2 = {
|
|
2562
3200
|
type: "object",
|
|
2563
|
-
properties,
|
|
3201
|
+
properties: properties2,
|
|
2564
3202
|
additionalProperties: false
|
|
2565
3203
|
};
|
|
2566
|
-
var
|
|
2567
|
-
var
|
|
3204
|
+
var schema2 = [optionsSchema2];
|
|
3205
|
+
var meta2 = {
|
|
2568
3206
|
type: "problem",
|
|
2569
|
-
docs,
|
|
2570
|
-
schema,
|
|
2571
|
-
messages
|
|
3207
|
+
docs: docs2,
|
|
3208
|
+
schema: schema2,
|
|
3209
|
+
messages: messages2
|
|
2572
3210
|
};
|
|
2573
|
-
var
|
|
3211
|
+
var ruleDefaults2 = {
|
|
2574
3212
|
allowEffectFields: false,
|
|
2575
3213
|
analysis: "local"
|
|
2576
3214
|
};
|
|
2577
|
-
var
|
|
2578
|
-
var
|
|
3215
|
+
var defaultOptions2 = [ruleDefaults2];
|
|
3216
|
+
var createRule2 = import_utils11.ESLintUtils.RuleCreator(
|
|
2579
3217
|
() => "https://eslint.org/docs/latest/rules/no-unused-private-class-members"
|
|
2580
3218
|
);
|
|
2581
3219
|
var projectParserServices = (context, analysis) => {
|
|
2582
3220
|
if (analysis !== "project") return void 0;
|
|
2583
3221
|
try {
|
|
2584
|
-
return
|
|
3222
|
+
return import_utils11.ESLintUtils.getParserServices(context);
|
|
2585
3223
|
} catch {
|
|
2586
3224
|
throw new Error(
|
|
2587
3225
|
"Project analysis requires parser services with type information."
|
|
@@ -2599,10 +3237,10 @@ var projectMemberUsedFor = (parserServices) => {
|
|
|
2599
3237
|
};
|
|
2600
3238
|
return memberUsed;
|
|
2601
3239
|
};
|
|
2602
|
-
var no_unused_angular_instance_fields_default =
|
|
3240
|
+
var no_unused_angular_instance_fields_default = createRule2({
|
|
2603
3241
|
name: "no-unused-instance-fields",
|
|
2604
|
-
meta,
|
|
2605
|
-
defaultOptions,
|
|
3242
|
+
meta: meta2,
|
|
3243
|
+
defaultOptions: defaultOptions2,
|
|
2606
3244
|
create(context, [options]) {
|
|
2607
3245
|
const analysis = options.analysis ?? "local";
|
|
2608
3246
|
const isSpec = isSpecFile(context.filename);
|
|
@@ -2642,6 +3280,9 @@ var no_unused_angular_instance_fields_default = createRule({
|
|
|
2642
3280
|
var lintSuiteAngularPlugin = definePlugin("lint-suite-angular", {
|
|
2643
3281
|
"no-unused-instance-fields": no_unused_angular_instance_fields_default
|
|
2644
3282
|
});
|
|
3283
|
+
var inlineTemplates = import_angular_eslint2.processInlineTemplates && {
|
|
3284
|
+
processor: import_angular_eslint2.processInlineTemplates
|
|
3285
|
+
};
|
|
2645
3286
|
var angular = (0, import_config2.defineConfig)([
|
|
2646
3287
|
{
|
|
2647
3288
|
files: ["**/*.ts"],
|
|
@@ -2659,7 +3300,7 @@ var angular = (0, import_config2.defineConfig)([
|
|
|
2659
3300
|
projectService: true
|
|
2660
3301
|
}
|
|
2661
3302
|
},
|
|
2662
|
-
|
|
3303
|
+
...inlineTemplates,
|
|
2663
3304
|
rules: {
|
|
2664
3305
|
"lint-suite-angular/no-unused-instance-fields": [
|
|
2665
3306
|
"error",
|
|
@@ -2769,6 +3410,11 @@ var baseLimits = (0, import_config3.defineConfig)([
|
|
|
2769
3410
|
|
|
2770
3411
|
// packages/lint-suite/src/lib/base-practices.ts
|
|
2771
3412
|
var import_config4 = require("eslint/config");
|
|
3413
|
+
|
|
3414
|
+
// packages/lint-suite/src/lib/line-length.const.ts
|
|
3415
|
+
var MAX_LINE_LENGTH = 135;
|
|
3416
|
+
|
|
3417
|
+
// packages/lint-suite/src/lib/base-practices.ts
|
|
2772
3418
|
var basePractices = (0, import_config4.defineConfig)([
|
|
2773
3419
|
{
|
|
2774
3420
|
files: [
|
|
@@ -2827,7 +3473,7 @@ var basePractices = (0, import_config4.defineConfig)([
|
|
|
2827
3473
|
"max-len": [
|
|
2828
3474
|
"error",
|
|
2829
3475
|
{
|
|
2830
|
-
code:
|
|
3476
|
+
code: MAX_LINE_LENGTH,
|
|
2831
3477
|
ignoreComments: true
|
|
2832
3478
|
}
|
|
2833
3479
|
],
|
|
@@ -3382,7 +4028,7 @@ var typescriptRecommended = (0, import_config17.defineConfig)([
|
|
|
3382
4028
|
var import_config18 = require("eslint/config");
|
|
3383
4029
|
|
|
3384
4030
|
// packages/lint-suite/src/lib/rules/explicit-accessibility/explicit-accessibility.ts
|
|
3385
|
-
var
|
|
4031
|
+
var import_utils12 = require("@typescript-eslint/utils");
|
|
3386
4032
|
|
|
3387
4033
|
// packages/lint-suite/src/lib/rules/explicit-accessibility/common/explicit-accessibility.const.ts
|
|
3388
4034
|
var accessibilities = [
|
|
@@ -3390,10 +4036,10 @@ var accessibilities = [
|
|
|
3390
4036
|
"private",
|
|
3391
4037
|
"protected"
|
|
3392
4038
|
];
|
|
3393
|
-
var
|
|
4039
|
+
var docs3 = {
|
|
3394
4040
|
description: "Require explicit accessibility modifiers on class members"
|
|
3395
4041
|
};
|
|
3396
|
-
var
|
|
4042
|
+
var messages3 = {
|
|
3397
4043
|
missingAccessibility: "Class member '{{ name }}' is missing an explicit accessibility modifier (public/private/protected).",
|
|
3398
4044
|
setAccessibility: "Add the '{{ accessibility }}' modifier."
|
|
3399
4045
|
};
|
|
@@ -3402,49 +4048,49 @@ var defaultAccessibilitySchema = {
|
|
|
3402
4048
|
enum: ["public", "private", "protected", "none"],
|
|
3403
4049
|
description: "The accessibility modifier inserted by the auto-fix; constructors always get public. 'none' reports without an auto-fix and offers all three levels as suggestions."
|
|
3404
4050
|
};
|
|
3405
|
-
var
|
|
4051
|
+
var properties3 = {
|
|
3406
4052
|
defaultAccessibility: defaultAccessibilitySchema
|
|
3407
4053
|
};
|
|
3408
|
-
var
|
|
4054
|
+
var optionsSchema3 = {
|
|
3409
4055
|
type: "object",
|
|
3410
|
-
properties:
|
|
4056
|
+
properties: properties3,
|
|
3411
4057
|
additionalProperties: false
|
|
3412
4058
|
};
|
|
3413
|
-
var
|
|
3414
|
-
var
|
|
4059
|
+
var schema3 = [optionsSchema3];
|
|
4060
|
+
var meta3 = {
|
|
3415
4061
|
type: "suggestion",
|
|
3416
|
-
docs:
|
|
4062
|
+
docs: docs3,
|
|
3417
4063
|
fixable: "code",
|
|
3418
4064
|
hasSuggestions: true,
|
|
3419
|
-
schema:
|
|
3420
|
-
messages:
|
|
4065
|
+
schema: schema3,
|
|
4066
|
+
messages: messages3
|
|
3421
4067
|
};
|
|
3422
|
-
var
|
|
4068
|
+
var defaultOptions3 = [{ defaultAccessibility: "public" }];
|
|
3423
4069
|
|
|
3424
4070
|
// packages/lint-suite/src/lib/rules/explicit-accessibility/explicit-accessibility.ts
|
|
3425
|
-
var
|
|
4071
|
+
var createRule3 = import_utils12.ESLintUtils.RuleCreator(
|
|
3426
4072
|
() => "https://github.com/F0rty-Tw0/lint-suite#explicit-accessibility"
|
|
3427
4073
|
);
|
|
3428
4074
|
var isPrivateMember = (node) => {
|
|
3429
|
-
if (node.type ===
|
|
3430
|
-
return node.key.type ===
|
|
4075
|
+
if (node.type === import_utils12.TSESTree.AST_NODE_TYPES.TSParameterProperty) return false;
|
|
4076
|
+
return node.key.type === import_utils12.TSESTree.AST_NODE_TYPES.PrivateIdentifier;
|
|
3431
4077
|
};
|
|
3432
4078
|
var isConstructor = (node) => {
|
|
3433
|
-
if (node.type !==
|
|
4079
|
+
if (node.type !== import_utils12.TSESTree.AST_NODE_TYPES.MethodDefinition) return false;
|
|
3434
4080
|
return node.kind === "constructor";
|
|
3435
4081
|
};
|
|
3436
4082
|
var reportTarget = (node) => {
|
|
3437
|
-
if (node.type !==
|
|
4083
|
+
if (node.type !== import_utils12.TSESTree.AST_NODE_TYPES.TSParameterProperty) {
|
|
3438
4084
|
return node.key;
|
|
3439
4085
|
}
|
|
3440
4086
|
const { parameter } = node;
|
|
3441
|
-
if (parameter.type ===
|
|
4087
|
+
if (parameter.type === import_utils12.TSESTree.AST_NODE_TYPES.AssignmentPattern) {
|
|
3442
4088
|
return parameter.left;
|
|
3443
4089
|
}
|
|
3444
4090
|
return parameter;
|
|
3445
4091
|
};
|
|
3446
4092
|
var memberName2 = (target, sourceCode) => {
|
|
3447
|
-
if (target.type ===
|
|
4093
|
+
if (target.type === import_utils12.TSESTree.AST_NODE_TYPES.Identifier) return target.name;
|
|
3448
4094
|
return sourceCode.getText(target);
|
|
3449
4095
|
};
|
|
3450
4096
|
var modifierToken = (node, sourceCode) => {
|
|
@@ -3488,10 +4134,10 @@ var suggestionsOf = (node, fixAccessibility, sourceCode) => {
|
|
|
3488
4134
|
};
|
|
3489
4135
|
return accessibilities.filter(isOtherAccessibility).map(suggestionFor);
|
|
3490
4136
|
};
|
|
3491
|
-
var explicit_accessibility_default =
|
|
4137
|
+
var explicit_accessibility_default = createRule3({
|
|
3492
4138
|
name: "explicit-accessibility",
|
|
3493
|
-
meta:
|
|
3494
|
-
defaultOptions:
|
|
4139
|
+
meta: meta3,
|
|
4140
|
+
defaultOptions: defaultOptions3,
|
|
3495
4141
|
create(context, [{ defaultAccessibility = "public" }]) {
|
|
3496
4142
|
const { sourceCode } = context;
|
|
3497
4143
|
const check = (node) => {
|
|
@@ -3528,40 +4174,40 @@ var explicit_accessibility_default = createRule2({
|
|
|
3528
4174
|
});
|
|
3529
4175
|
|
|
3530
4176
|
// packages/lint-suite/src/lib/rules/no-inline-object-types/no-inline-object-types.ts
|
|
3531
|
-
var
|
|
3532
|
-
var
|
|
4177
|
+
var import_utils13 = require("@typescript-eslint/utils");
|
|
4178
|
+
var docs4 = {
|
|
3533
4179
|
description: "Require nested object types inside a type alias to be extracted to a named type alias"
|
|
3534
4180
|
};
|
|
3535
|
-
var
|
|
4181
|
+
var messages4 = {
|
|
3536
4182
|
inlineObjectType: "Inline object type must be extracted to a named type alias."
|
|
3537
4183
|
};
|
|
3538
|
-
var
|
|
4184
|
+
var meta4 = {
|
|
3539
4185
|
type: "suggestion",
|
|
3540
|
-
docs:
|
|
4186
|
+
docs: docs4,
|
|
3541
4187
|
schema: [],
|
|
3542
|
-
messages:
|
|
4188
|
+
messages: messages4
|
|
3543
4189
|
};
|
|
3544
|
-
var
|
|
4190
|
+
var createRule4 = import_utils13.ESLintUtils.RuleCreator(
|
|
3545
4191
|
() => "https://github.com/F0rty-Tw0/lint-suite#no-inline-object-types"
|
|
3546
4192
|
);
|
|
3547
4193
|
var enclosingTypeAlias = (node) => {
|
|
3548
4194
|
let current = node.parent;
|
|
3549
|
-
while (current && current.type !==
|
|
3550
|
-
if (current.type ===
|
|
4195
|
+
while (current && current.type !== import_utils13.TSESTree.AST_NODE_TYPES.Program) {
|
|
4196
|
+
if (current.type === import_utils13.TSESTree.AST_NODE_TYPES.TSTypeAliasDeclaration) {
|
|
3551
4197
|
return current;
|
|
3552
4198
|
}
|
|
3553
4199
|
current = current.parent;
|
|
3554
4200
|
}
|
|
3555
4201
|
return void 0;
|
|
3556
4202
|
};
|
|
3557
|
-
var no_inline_object_types_default =
|
|
4203
|
+
var no_inline_object_types_default = createRule4({
|
|
3558
4204
|
name: "no-inline-object-types",
|
|
3559
|
-
meta:
|
|
4205
|
+
meta: meta4,
|
|
3560
4206
|
defaultOptions: [],
|
|
3561
4207
|
create(context) {
|
|
3562
4208
|
const listeners = {
|
|
3563
4209
|
TSTypeLiteral(node) {
|
|
3564
|
-
const isAliasBody = node.parent.type ===
|
|
4210
|
+
const isAliasBody = node.parent.type === import_utils13.TSESTree.AST_NODE_TYPES.TSTypeAliasDeclaration;
|
|
3565
4211
|
if (isAliasBody) return;
|
|
3566
4212
|
const enclosingAlias = enclosingTypeAlias(node);
|
|
3567
4213
|
if (!enclosingAlias) return;
|
|
@@ -3576,46 +4222,138 @@ var no_inline_object_types_default = createRule3({
|
|
|
3576
4222
|
}
|
|
3577
4223
|
});
|
|
3578
4224
|
|
|
4225
|
+
// packages/lint-suite/src/lib/rules/one-line-guard/one-line-guard.ts
|
|
4226
|
+
var import_utils14 = require("@typescript-eslint/utils");
|
|
4227
|
+
var docs5 = {
|
|
4228
|
+
description: "Require a lone return/throw/continue/break guard to drop its braces when the whole if statement fits on one line"
|
|
4229
|
+
};
|
|
4230
|
+
var messages5 = {
|
|
4231
|
+
oneLineGuard: "Lone {{ keyword }} guard fits within {{ max }} columns; write it on one line without braces."
|
|
4232
|
+
};
|
|
4233
|
+
var schema4 = [
|
|
4234
|
+
{
|
|
4235
|
+
type: "object",
|
|
4236
|
+
properties: {
|
|
4237
|
+
maxLineLength: { type: "integer", minimum: 1 }
|
|
4238
|
+
},
|
|
4239
|
+
additionalProperties: false
|
|
4240
|
+
}
|
|
4241
|
+
];
|
|
4242
|
+
var meta5 = {
|
|
4243
|
+
type: "suggestion",
|
|
4244
|
+
docs: docs5,
|
|
4245
|
+
fixable: "code",
|
|
4246
|
+
schema: schema4,
|
|
4247
|
+
messages: messages5
|
|
4248
|
+
};
|
|
4249
|
+
var createRule5 = import_utils14.ESLintUtils.RuleCreator(
|
|
4250
|
+
() => "https://github.com/F0rty-Tw0/lint-suite#one-line-guard"
|
|
4251
|
+
);
|
|
4252
|
+
var GUARD_KEYWORDS = /* @__PURE__ */ new Set([
|
|
4253
|
+
import_utils14.TSESTree.AST_NODE_TYPES.ReturnStatement,
|
|
4254
|
+
import_utils14.TSESTree.AST_NODE_TYPES.ThrowStatement,
|
|
4255
|
+
import_utils14.TSESTree.AST_NODE_TYPES.ContinueStatement,
|
|
4256
|
+
import_utils14.TSESTree.AST_NODE_TYPES.BreakStatement
|
|
4257
|
+
]);
|
|
4258
|
+
var soleStatement = (body) => {
|
|
4259
|
+
if (body.type !== import_utils14.TSESTree.AST_NODE_TYPES.BlockStatement) return void 0;
|
|
4260
|
+
if (body.body.length !== 1) return void 0;
|
|
4261
|
+
return body.body[0];
|
|
4262
|
+
};
|
|
4263
|
+
var guardStatement = (node) => {
|
|
4264
|
+
if (node.alternate) return void 0;
|
|
4265
|
+
const statement = soleStatement(node.consequent);
|
|
4266
|
+
if (!statement) return void 0;
|
|
4267
|
+
const isGuardKeyword = GUARD_KEYWORDS.has(statement.type);
|
|
4268
|
+
if (!isGuardKeyword) return void 0;
|
|
4269
|
+
return statement;
|
|
4270
|
+
};
|
|
4271
|
+
var headText = (node, sourceCode) => {
|
|
4272
|
+
return sourceCode.text.slice(node.range[0], node.consequent.range[0]).trimEnd();
|
|
4273
|
+
};
|
|
4274
|
+
var collapsedLine = (node, head, bodyText, sourceCode) => {
|
|
4275
|
+
const line = sourceCode.lines[node.loc.start.line - 1] ?? "";
|
|
4276
|
+
const prefix = line.slice(0, node.loc.start.column);
|
|
4277
|
+
return `${prefix}${head} ${bodyText}`;
|
|
4278
|
+
};
|
|
4279
|
+
var one_line_guard_default = createRule5({
|
|
4280
|
+
name: "one-line-guard",
|
|
4281
|
+
meta: meta5,
|
|
4282
|
+
defaultOptions: [{ maxLineLength: 80 }],
|
|
4283
|
+
create(context, [{ maxLineLength }]) {
|
|
4284
|
+
const { sourceCode } = context;
|
|
4285
|
+
const listeners = {
|
|
4286
|
+
IfStatement(node) {
|
|
4287
|
+
const statement = guardStatement(node);
|
|
4288
|
+
if (!statement) return;
|
|
4289
|
+
const hasComments = sourceCode.getCommentsInside(node.consequent).length > 0;
|
|
4290
|
+
if (hasComments) return;
|
|
4291
|
+
const head = headText(node, sourceCode);
|
|
4292
|
+
const isMultiLineHead = head.includes("\n");
|
|
4293
|
+
if (isMultiLineHead) return;
|
|
4294
|
+
const bodyText = sourceCode.getText(statement);
|
|
4295
|
+
const isMultiLineBody = bodyText.includes("\n");
|
|
4296
|
+
if (isMultiLineBody) return;
|
|
4297
|
+
const collapsed = collapsedLine(node, head, bodyText, sourceCode);
|
|
4298
|
+
if (collapsed.length > maxLineLength) return;
|
|
4299
|
+
const [keywordToken] = sourceCode.getTokens(statement);
|
|
4300
|
+
if (keywordToken === void 0) return;
|
|
4301
|
+
const keyword = keywordToken.value;
|
|
4302
|
+
const data = { keyword, max: maxLineLength };
|
|
4303
|
+
const fix = (fixer) => fixer.replaceText(node.consequent, bodyText);
|
|
4304
|
+
const report = {
|
|
4305
|
+
node,
|
|
4306
|
+
messageId: "oneLineGuard",
|
|
4307
|
+
data,
|
|
4308
|
+
fix
|
|
4309
|
+
};
|
|
4310
|
+
context.report(report);
|
|
4311
|
+
}
|
|
4312
|
+
};
|
|
4313
|
+
return listeners;
|
|
4314
|
+
}
|
|
4315
|
+
});
|
|
4316
|
+
|
|
3579
4317
|
// packages/lint-suite/src/lib/rules/readonly-type-properties/readonly-type-properties.ts
|
|
3580
|
-
var
|
|
3581
|
-
var
|
|
4318
|
+
var import_utils15 = require("@typescript-eslint/utils");
|
|
4319
|
+
var docs6 = {
|
|
3582
4320
|
description: "Require readonly on primitive-typed type and interface properties"
|
|
3583
4321
|
};
|
|
3584
|
-
var
|
|
4322
|
+
var messages6 = {
|
|
3585
4323
|
missingReadonly: "Type property '{{ name }}' should be readonly. Disable this rule on the line if mutation is required."
|
|
3586
4324
|
};
|
|
3587
|
-
var
|
|
4325
|
+
var meta6 = {
|
|
3588
4326
|
type: "suggestion",
|
|
3589
|
-
docs:
|
|
4327
|
+
docs: docs6,
|
|
3590
4328
|
fixable: "code",
|
|
3591
4329
|
schema: [],
|
|
3592
|
-
messages:
|
|
4330
|
+
messages: messages6
|
|
3593
4331
|
};
|
|
3594
|
-
var
|
|
4332
|
+
var createRule6 = import_utils15.ESLintUtils.RuleCreator(
|
|
3595
4333
|
() => "https://github.com/F0rty-Tw0/lint-suite#readonly-type-properties"
|
|
3596
4334
|
);
|
|
3597
4335
|
var propertyName3 = (node, sourceCode) => {
|
|
3598
|
-
if (node.key.type ===
|
|
4336
|
+
if (node.key.type === import_utils15.TSESTree.AST_NODE_TYPES.Identifier) {
|
|
3599
4337
|
return node.key.name;
|
|
3600
4338
|
}
|
|
3601
4339
|
return sourceCode.getText(node.key);
|
|
3602
4340
|
};
|
|
3603
4341
|
var PRIMITIVE_KEYWORDS = /* @__PURE__ */ new Set([
|
|
3604
|
-
|
|
3605
|
-
|
|
3606
|
-
|
|
3607
|
-
|
|
3608
|
-
|
|
3609
|
-
|
|
3610
|
-
|
|
4342
|
+
import_utils15.TSESTree.AST_NODE_TYPES.TSStringKeyword,
|
|
4343
|
+
import_utils15.TSESTree.AST_NODE_TYPES.TSNumberKeyword,
|
|
4344
|
+
import_utils15.TSESTree.AST_NODE_TYPES.TSBooleanKeyword,
|
|
4345
|
+
import_utils15.TSESTree.AST_NODE_TYPES.TSBigIntKeyword,
|
|
4346
|
+
import_utils15.TSESTree.AST_NODE_TYPES.TSSymbolKeyword,
|
|
4347
|
+
import_utils15.TSESTree.AST_NODE_TYPES.TSNullKeyword,
|
|
4348
|
+
import_utils15.TSESTree.AST_NODE_TYPES.TSUndefinedKeyword
|
|
3611
4349
|
]);
|
|
3612
4350
|
var isPrimitive = (type) => {
|
|
3613
4351
|
const isPrimitiveKeyword = PRIMITIVE_KEYWORDS.has(type.type);
|
|
3614
4352
|
if (isPrimitiveKeyword) return true;
|
|
3615
|
-
if (type.type ===
|
|
4353
|
+
if (type.type === import_utils15.TSESTree.AST_NODE_TYPES.TSLiteralType || type.type === import_utils15.TSESTree.AST_NODE_TYPES.TSTemplateLiteralType) {
|
|
3616
4354
|
return true;
|
|
3617
4355
|
}
|
|
3618
|
-
if (type.type ===
|
|
4356
|
+
if (type.type === import_utils15.TSESTree.AST_NODE_TYPES.TSUnionType || type.type === import_utils15.TSESTree.AST_NODE_TYPES.TSIntersectionType) {
|
|
3619
4357
|
return type.types.every(isPrimitive);
|
|
3620
4358
|
}
|
|
3621
4359
|
return false;
|
|
@@ -3627,9 +4365,9 @@ var readonlyFix = (node, sourceCode) => {
|
|
|
3627
4365
|
return fixer.insertTextBefore(firstToken, "readonly ");
|
|
3628
4366
|
};
|
|
3629
4367
|
};
|
|
3630
|
-
var readonly_type_properties_default =
|
|
4368
|
+
var readonly_type_properties_default = createRule6({
|
|
3631
4369
|
name: "readonly-type-properties",
|
|
3632
|
-
meta:
|
|
4370
|
+
meta: meta6,
|
|
3633
4371
|
defaultOptions: [],
|
|
3634
4372
|
create(context) {
|
|
3635
4373
|
const { sourceCode } = context;
|
|
@@ -3658,7 +4396,8 @@ var readonly_type_properties_default = createRule4({
|
|
|
3658
4396
|
var localPlugin = definePlugin("local", {
|
|
3659
4397
|
"explicit-accessibility": explicit_accessibility_default,
|
|
3660
4398
|
"readonly-type-properties": readonly_type_properties_default,
|
|
3661
|
-
"no-inline-object-types": no_inline_object_types_default
|
|
4399
|
+
"no-inline-object-types": no_inline_object_types_default,
|
|
4400
|
+
"one-line-guard": one_line_guard_default
|
|
3662
4401
|
});
|
|
3663
4402
|
|
|
3664
4403
|
// packages/lint-suite/src/lib/typescript-safety.ts
|
|
@@ -3670,6 +4409,7 @@ var typescriptSafety = (0, import_config18.defineConfig)([
|
|
|
3670
4409
|
"local/explicit-accessibility": "error",
|
|
3671
4410
|
"local/readonly-type-properties": "error",
|
|
3672
4411
|
"local/no-inline-object-types": "error",
|
|
4412
|
+
"local/one-line-guard": ["error", { maxLineLength: MAX_LINE_LENGTH }],
|
|
3673
4413
|
"@typescript-eslint/explicit-function-return-type": "error",
|
|
3674
4414
|
"@typescript-eslint/no-empty-function": "error",
|
|
3675
4415
|
"@typescript-eslint/no-unused-vars": "error",
|