@knip/mcp 0.0.22 → 0.0.23
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/package.json +3 -3
- package/src/docs/docs/blog/brief-history.md +1 -1
- package/src/docs/docs/blog/for-editors-and-agents.md +1 -1
- package/src/docs/docs/blog/knip-v3.mdx +1 -1
- package/src/docs/docs/blog/knip-v4.mdx +1 -1
- package/src/docs/docs/blog/knip-v5.mdx +1 -1
- package/src/docs/docs/blog/knip-v6.md +145 -0
- package/src/docs/docs/blog/release-notes-v2.md +1 -1
- package/src/docs/docs/blog/slim-down-to-speed-up.md +1 -1
- package/src/docs/docs/blog/state-of-knip.md +1 -1
- package/src/docs/docs/blog/two-years.mdx +1 -1
- package/src/docs/docs/explanations/comparison-and-migration.md +2 -2
- package/src/docs/docs/features/auto-fix.mdx +3 -33
- package/src/docs/docs/features/reporters.md +16 -13
- package/src/docs/docs/features/rules-and-filters.md +1 -1
- package/src/docs/docs/guides/handling-issues.mdx +32 -48
- package/src/docs/docs/guides/performance.md +7 -62
- package/src/docs/docs/index.mdx +3 -3
- package/src/docs/docs/overview/configuration.md +1 -1
- package/src/docs/docs/overview/getting-started.mdx +1 -1
- package/src/docs/docs/reference/cli.md +31 -56
- package/src/docs/docs/reference/configuration.md +7 -7
- package/src/docs/docs/reference/faq.md +48 -63
- package/src/docs/docs/reference/issue-types.md +17 -17
- package/src/docs/docs/typescript/unused-exports.md +7 -8
- package/src/docs/docs/writing-a-plugin/index.md +14 -34
|
@@ -251,20 +251,20 @@ This is why plugins can implement the `resolveFromAST` function.
|
|
|
251
251
|
### 8. resolveFromAST
|
|
252
252
|
|
|
253
253
|
Let's take a look at the Astro plugin implementation. This example assumes some
|
|
254
|
-
familiarity with Abstract Syntax Trees (AST)
|
|
255
|
-
|
|
256
|
-
fun and a little less tedious.
|
|
254
|
+
familiarity with Abstract Syntax Trees (AST). Knip provides AST helpers to make
|
|
255
|
+
implementing plugins more fun and a little less tedious.
|
|
257
256
|
|
|
258
257
|
Anyway, let's dive in. Here's how we're adding the Starlight `components` paths
|
|
259
258
|
to the default `production` file patterns:
|
|
260
259
|
|
|
261
260
|
```ts
|
|
262
|
-
import
|
|
261
|
+
import type { Program } from 'oxc-parser';
|
|
263
262
|
import {
|
|
263
|
+
findCallArg,
|
|
264
264
|
getDefaultImportName,
|
|
265
265
|
getImportMap,
|
|
266
266
|
getPropertyValues,
|
|
267
|
-
} from '../../typescript/ast-helpers.
|
|
267
|
+
} from '../../typescript/ast-helpers.ts';
|
|
268
268
|
|
|
269
269
|
const title = 'Astro';
|
|
270
270
|
|
|
@@ -275,44 +275,24 @@ const production = [
|
|
|
275
275
|
'src/actions/index.{js,ts}',
|
|
276
276
|
];
|
|
277
277
|
|
|
278
|
-
const
|
|
279
|
-
const
|
|
280
|
-
const importMap = getImportMap(sourceFile);
|
|
278
|
+
const getComponentPaths = (program: Program) => {
|
|
279
|
+
const importMap = getImportMap(program);
|
|
281
280
|
const importName = getDefaultImportName(importMap, '@astrojs/starlight');
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
ts.isCallExpression(node) &&
|
|
286
|
-
ts.isIdentifier(node.expression) &&
|
|
287
|
-
node.expression.text === importName // match the starlight() function call
|
|
288
|
-
) {
|
|
289
|
-
const starlightConfig = node.arguments[0];
|
|
290
|
-
if (ts.isObjectLiteralExpression(starlightConfig)) {
|
|
291
|
-
const values = getPropertyValues(starlightConfig, 'components');
|
|
292
|
-
for (const value of values) componentPaths.add(value);
|
|
293
|
-
}
|
|
294
|
-
}
|
|
295
|
-
|
|
296
|
-
ts.forEachChild(node, visit);
|
|
297
|
-
}
|
|
298
|
-
|
|
299
|
-
visit(sourceFile);
|
|
300
|
-
|
|
301
|
-
return componentPaths;
|
|
281
|
+
if (!importName) return new Set<string>();
|
|
282
|
+
const starlightConfig = findCallArg(program, importName);
|
|
283
|
+
return getPropertyValues(starlightConfig, 'components');
|
|
302
284
|
};
|
|
303
285
|
|
|
304
|
-
const resolveFromAST: ResolveFromAST = (
|
|
305
|
-
|
|
306
|
-
// as production entry files so they're also part of the analysis
|
|
307
|
-
const componentPaths = getComponentPathsFromSourceFile(sourceFile);
|
|
286
|
+
const resolveFromAST: ResolveFromAST = (program: Program) => {
|
|
287
|
+
const componentPaths = getComponentPaths(program);
|
|
308
288
|
return [...production, ...componentPaths].map(id => toProductionEntry(id));
|
|
309
289
|
};
|
|
310
290
|
|
|
311
|
-
const plugin: Plugin {
|
|
291
|
+
const plugin: Plugin = {
|
|
312
292
|
title,
|
|
313
293
|
production,
|
|
314
294
|
resolveFromAST,
|
|
315
|
-
}
|
|
295
|
+
};
|
|
316
296
|
|
|
317
297
|
export default plugin;
|
|
318
298
|
```
|