knip 6.0.4 → 6.0.5

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.
@@ -60,7 +60,7 @@ export const analyze = async ({ analyzedFiles, counselor, chief, collector, depu
60
60
  if (isIgnored &&
61
61
  (isReferenced || isReferencedInUsedExport(exportedItem, filePath, isIncludeEntryExports))) {
62
62
  for (const tagName of exportedItem.jsDocTags) {
63
- if (options.tags[1].includes(tagName.replace(/^@/, ''))) {
63
+ if (options.tags[1].includes(tagName)) {
64
64
  collector.addTagHint({ type: 'tag', filePath, identifier, tagName });
65
65
  }
66
66
  }
@@ -114,7 +114,7 @@ export const analyze = async ({ analyzedFiles, counselor, chief, collector, depu
114
114
  }
115
115
  else if (isIgnored) {
116
116
  for (const tagName of exportedItem.jsDocTags) {
117
- if (options.tags[1].includes(tagName.replace(/^@/, ''))) {
117
+ if (options.tags[1].includes(tagName)) {
118
118
  collector.addTagHint({ type: 'tag', filePath, identifier: id, tagName });
119
119
  }
120
120
  }
@@ -45,7 +45,7 @@ const resolveConfig = async (localConfig, options) => {
45
45
  commands = [target.options.command];
46
46
  else if (target.options?.commands)
47
47
  commands = target.options.commands.map(commandConfig => typeof commandConfig === 'string' ? commandConfig : commandConfig.command);
48
- const cwd = target.options?.cwd ? join(options.cwd, target.options.cwd) : undefined;
48
+ const cwd = target.options?.cwd ? join(options.cwd, target.options.cwd) : options.cwd;
49
49
  return options.getInputsFromScripts(commands, { cwd });
50
50
  });
51
51
  const configInputs = targets.flatMap(target => {
@@ -47,7 +47,7 @@ export interface ExportMember extends Position {
47
47
  readonly identifier: Identifier;
48
48
  readonly type: SymbolType;
49
49
  readonly fix: Fix;
50
- readonly jsDocTags: Tags;
50
+ jsDocTags: Tags;
51
51
  readonly flags: number;
52
52
  hasRefsInFile: boolean;
53
53
  }
@@ -11,7 +11,7 @@ import { walkAST } from "./visitors/walk.js";
11
11
  const jsDocImportRe = /import\(\s*['"]([^'"]+)['"]\s*\)(?:\.(\w+))?/g;
12
12
  const jsDocImportTagRe = /@import\s+(?:\{[^}]*\}|\*\s+as\s+\w+)\s+from\s+['"]([^'"]+)['"]/g;
13
13
  const jsxImportSourceRe = /@jsxImportSource\s+(\S+)/;
14
- const referenceTypesRe = /\/\s*<reference\s+types\s*=\s*"([^"]+)"\s*\/>/;
14
+ const referenceTypesRe = /\s*<reference\s+types\s*=\s*"([^"]+)"\s*\/>/;
15
15
  const envRe = /@(?:vitest|jest)-environment\s+(\S+)/g;
16
16
  const getImportsAndExports = (filePath, sourceText, resolveModule, options, ignoreExportsUsedInFile, skipExportsForFile, visitor, pluginCtx, cachedParseResult) => {
17
17
  const skipExports = skipExportsForFile || !options.isReportExports;
@@ -303,7 +303,7 @@ const getImportsAndExports = (filePath, sourceText, resolveModule, options, igno
303
303
  addImport(id, undefined, undefined, undefined, comment.start + results.index, modifiers);
304
304
  }
305
305
  if (comment.type === 'Line') {
306
- const refMatch = ('/' + comment.value).match(referenceTypesRe);
306
+ const refMatch = comment.value.match(referenceTypesRe);
307
307
  if (refMatch) {
308
308
  addImport(refMatch[1], undefined, undefined, undefined, comment.start, IMPORT_FLAGS.TYPE_ONLY);
309
309
  }
@@ -1,6 +1,7 @@
1
1
  import { parseSync, rawTransferSupported, } from 'oxc-parser';
2
2
  import { DEFAULT_EXTENSIONS, FIX_FLAGS, SYMBOL_TYPE } from "../../constants.js";
3
3
  import { extname } from "../../util/path.js";
4
+ import { EMPTY_TAGS } from "./jsdoc.js";
4
5
  const defaultParseOptions = {
5
6
  sourceType: 'unambiguous',
6
7
  experimentalRawTransfer: rawTransferSupported(),
@@ -57,6 +58,18 @@ export function extractNamespaceMembers(decl, options, lineStarts, getJSDocTags,
57
58
  const members = [];
58
59
  const addMember = (name, pos, stmtStart, stmtEnd) => {
59
60
  const fullName = prefix ? `${prefix}.${name}` : name;
61
+ const tags = getJSDocTags(stmtStart);
62
+ const existing = members.find(m => m.identifier === fullName);
63
+ if (existing) {
64
+ if (tags.size) {
65
+ if (existing.jsDocTags === EMPTY_TAGS)
66
+ existing.jsDocTags = new Set(tags);
67
+ else
68
+ for (const t of tags)
69
+ existing.jsDocTags.add(t);
70
+ }
71
+ return;
72
+ }
60
73
  const { line, col } = getLineAndCol(lineStarts, pos);
61
74
  const fix = options.isFixExports
62
75
  ? [stmtStart, stmtEnd, FIX_FLAGS.OBJECT_BINDING | FIX_FLAGS.WITH_NEWLINE]
@@ -69,7 +82,7 @@ export function extractNamespaceMembers(decl, options, lineStarts, getJSDocTags,
69
82
  col,
70
83
  fix,
71
84
  hasRefsInFile: false,
72
- jsDocTags: getJSDocTags(stmtStart),
85
+ jsDocTags: tags,
73
86
  flags: 0,
74
87
  });
75
88
  };
package/dist/util/tag.js CHANGED
@@ -4,11 +4,11 @@ export const splitTags = (rawTags) => {
4
4
  return tags.reduce(([incl, excl], tag) => {
5
5
  const match = tag.match(/[a-zA-Z]+/);
6
6
  if (match)
7
- (tag.startsWith('-') ? excl : incl).push(match[0]);
7
+ (tag.startsWith('-') ? excl : incl).push(`@${match[0]}`);
8
8
  return [incl, excl];
9
9
  }, [[], []]);
10
10
  };
11
- const hasTag = (tags, jsDocTags) => tags.some(tag => jsDocTags.has(`@${tag}`));
11
+ const hasTag = (tags, jsDocTags) => tags.some(tag => jsDocTags.has(tag));
12
12
  export const shouldIgnore = (jsDocTags, tags) => {
13
13
  const [includeJSDocTags, excludeJSDocTags] = tags;
14
14
  if (includeJSDocTags.length > 0 && !hasTag(includeJSDocTags, jsDocTags))
package/dist/version.d.ts CHANGED
@@ -1 +1 @@
1
- export declare const version = "6.0.4";
1
+ export declare const version = "6.0.5";
package/dist/version.js CHANGED
@@ -1 +1 @@
1
- export const version = '6.0.4';
1
+ export const version = '6.0.5';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "knip",
3
- "version": "6.0.4",
3
+ "version": "6.0.5",
4
4
  "description": "Find and fix unused dependencies, exports and files in your TypeScript and JavaScript projects",
5
5
  "keywords": [
6
6
  "analysis",