@cldmv/fix-headers 1.3.11 → 2.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (63) hide show
  1. package/LICENSE +202 -0
  2. package/README.md +313 -25
  3. package/bin/fix-headers.mjs +70 -0
  4. package/dist/index.cjs +28 -0
  5. package/dist/index.mjs +23 -0
  6. package/package.json +42 -22
  7. package/types/src/cli.d.mts +20 -2
  8. package/types/src/config/load.d.mts +36 -0
  9. package/types/src/constants.d.mts +1 -23
  10. package/types/src/core/file-discovery.d.mts +17 -5
  11. package/types/src/core/fix-headers.d.mts +59 -4
  12. package/types/src/core/ignore-rules.d.mts +38 -0
  13. package/types/src/detect/project.d.mts +64 -15
  14. package/types/src/detectors/css.d.mts +0 -8
  15. package/types/src/detectors/go.d.mts +0 -8
  16. package/types/src/detectors/html.d.mts +0 -8
  17. package/types/src/detectors/index.d.mts +28 -7
  18. package/types/src/detectors/json.d.mts +0 -8
  19. package/types/src/detectors/node.d.mts +0 -8
  20. package/types/src/detectors/php.d.mts +0 -8
  21. package/types/src/detectors/python.d.mts +0 -8
  22. package/types/src/detectors/rust.d.mts +0 -8
  23. package/types/src/detectors/yaml.d.mts +0 -8
  24. package/types/src/drivers/go.d.mts +2 -0
  25. package/types/src/drivers/index.d.mts +154 -0
  26. package/types/src/drivers/node.d.mts +2 -0
  27. package/types/src/drivers/php.d.mts +2 -0
  28. package/types/src/drivers/python.d.mts +2 -0
  29. package/types/src/drivers/rust.d.mts +2 -0
  30. package/types/src/drivers/shared.d.mts +78 -0
  31. package/types/src/header/dates.d.mts +108 -0
  32. package/types/src/header/fields.d.mts +48 -0
  33. package/types/src/header/template.d.mts +4 -3
  34. package/types/src/utils/diff.d.mts +53 -0
  35. package/types/src/utils/fs.d.mts +10 -3
  36. package/types/src/utils/git.d.mts +27 -0
  37. package/types/src/utils/time.d.mts +55 -0
  38. package/index.cjs +0 -39
  39. package/index.mjs +0 -20
  40. package/src/cli.mjs +0 -323
  41. package/src/constants.mjs +0 -50
  42. package/src/core/file-discovery.mjs +0 -213
  43. package/src/core/fix-headers.mjs +0 -413
  44. package/src/detect/project.mjs +0 -190
  45. package/src/detectors/css.mjs +0 -67
  46. package/src/detectors/go.mjs +0 -65
  47. package/src/detectors/html.mjs +0 -67
  48. package/src/detectors/index.mjs +0 -187
  49. package/src/detectors/json.mjs +0 -76
  50. package/src/detectors/node.mjs +0 -90
  51. package/src/detectors/php.mjs +0 -66
  52. package/src/detectors/python.mjs +0 -75
  53. package/src/detectors/rust.mjs +0 -62
  54. package/src/detectors/shared.mjs +0 -45
  55. package/src/detectors/yaml.mjs +0 -79
  56. package/src/fix-header.mjs +0 -30
  57. package/src/header/parser.mjs +0 -145
  58. package/src/header/syntax.mjs +0 -69
  59. package/src/header/template.mjs +0 -65
  60. package/src/utils/fs.mjs +0 -138
  61. package/src/utils/git.mjs +0 -135
  62. package/src/utils/time.mjs +0 -44
  63. package/types/src/detectors/shared.d.mts +0 -14
@@ -1,65 +0,0 @@
1
- /**
2
- * @Project: @cldmv/fix-headers
3
- * @Filename: /src/detectors/go.mjs
4
- * @Date: 2026-03-01T17:59:32-08:00 (1772416772)
5
- * @Author: Nate Corcoran <CLDMV>
6
- * @Email: <Shinrai@users.noreply.github.com>
7
- * -----
8
- * @Last modified by: Nate Corcoran <CLDMV> (Shinrai@users.noreply.github.com)
9
- * @Last modified time: 2026-03-01T17:59:32-08:00 (1772416772)
10
- * -----
11
- * @Copyright: Copyright (c) 2026-2026 Catalyzed Motivation Inc. All rights reserved.
12
- */
13
-
14
- import { extname } from "node:path";
15
- import { findNearestMarker } from "./shared.mjs";
16
-
17
- /**
18
- * @fileoverview Go detector implementation.
19
- * @module fix-headers/detectors/go
20
- */
21
-
22
- const markers = ["go.mod"];
23
- const extensions = [".go"];
24
-
25
- /**
26
- * Resolves Go comment syntax.
27
- * @param {string} filePath - File path.
28
- * @returns {{kind: "block", blockStart: string, blockLinePrefix: string, blockEnd: string} | null} Syntax descriptor.
29
- */
30
- function resolveGoCommentSyntax(filePath) {
31
- const extension = extname(filePath).toLowerCase();
32
- if (extensions.includes(extension)) {
33
- return {
34
- kind: "block",
35
- blockStart: "/**",
36
- blockLinePrefix: " *\t",
37
- blockEnd: " */"
38
- };
39
- }
40
- return null;
41
- }
42
-
43
- export const detector = {
44
- id: "go",
45
- priority: 80,
46
- markers,
47
- extensions,
48
- enabledByDefault: true,
49
- findNearestConfig(startPath) {
50
- return findNearestMarker(startPath, markers);
51
- },
52
- parseProjectName(_marker, markerContent, rootDirName) {
53
- const moduleMatch = markerContent.match(/^module\s+(.+)$/m);
54
- if (moduleMatch?.[1]) {
55
- const value = moduleMatch[1].trim();
56
- if (value.length > 0) {
57
- return value;
58
- }
59
- }
60
- return rootDirName;
61
- },
62
- resolveCommentSyntax(filePath) {
63
- return resolveGoCommentSyntax(filePath);
64
- }
65
- };
@@ -1,67 +0,0 @@
1
- /**
2
- * @Project: @cldmv/fix-headers
3
- * @Filename: /src/detectors/html.mjs
4
- * @Date: 2026-03-01T17:59:32-08:00 (1772416772)
5
- * @Author: Nate Corcoran <CLDMV>
6
- * @Email: <Shinrai@users.noreply.github.com>
7
- * -----
8
- * @Last modified by: Nate Corcoran <CLDMV> (Shinrai@users.noreply.github.com)
9
- * @Last modified time: 2026-03-01T17:59:32-08:00 (1772416772)
10
- * -----
11
- * @Copyright: Copyright (c) 2026-2026 Catalyzed Motivation Inc. All rights reserved.
12
- */
13
-
14
- import { extname } from "node:path";
15
- import { findNearestMarker } from "./shared.mjs";
16
-
17
- /**
18
- * @fileoverview HTML detector implementation.
19
- * @module fix-headers/detectors/html
20
- */
21
-
22
- const markers = ["index.html", "vite.config.js", "vite.config.mjs", "next.config.js", "next.config.mjs"];
23
- const extensions = [".html", ".htm"];
24
-
25
- /**
26
- * Parses HTML project name from marker context.
27
- * @param {string} rootDirName - Fallback directory name.
28
- * @returns {string} Project name.
29
- */
30
- function parseHtmlProjectName(rootDirName) {
31
- return rootDirName;
32
- }
33
-
34
- /**
35
- * Resolves HTML comment syntax for HTML-like files.
36
- * @param {string} filePath - File path.
37
- * @returns {{kind: "html", blockStart: string, blockLinePrefix: string, blockEnd: string} | null} Syntax descriptor.
38
- */
39
- function resolveHtmlCommentSyntax(filePath) {
40
- const extension = extname(filePath).toLowerCase();
41
- if (extensions.includes(extension)) {
42
- return {
43
- kind: "html",
44
- blockStart: "<!--",
45
- blockLinePrefix: "\t",
46
- blockEnd: "-->"
47
- };
48
- }
49
- return null;
50
- }
51
-
52
- export const detector = {
53
- id: "html",
54
- priority: 70,
55
- markers,
56
- extensions,
57
- enabledByDefault: true,
58
- findNearestConfig(startPath) {
59
- return findNearestMarker(startPath, markers);
60
- },
61
- parseProjectName(_marker, _markerContent, rootDirName) {
62
- return parseHtmlProjectName(rootDirName);
63
- },
64
- resolveCommentSyntax(filePath) {
65
- return resolveHtmlCommentSyntax(filePath);
66
- }
67
- };
@@ -1,187 +0,0 @@
1
- /**
2
- * @Project: @cldmv/fix-headers
3
- * @Filename: /src/detectors/index.mjs
4
- * @Date: 2026-03-01 16:34:41 -08:00 (1772411681)
5
- * @Author: Nate Corcoran <CLDMV>
6
- * @Email: <Shinrai@users.noreply.github.com>
7
- * -----
8
- * @Last modified by: Nate Corcoran <CLDMV> (Shinrai@users.noreply.github.com)
9
- * @Last modified time: 2026-03-01T17:59:32-08:00 (1772416772)
10
- * -----
11
- * @Copyright: Copyright (c) 2026-2026 Catalyzed Motivation Inc. All rights reserved.
12
- */
13
-
14
- import { readdir } from "node:fs/promises";
15
- import { extname } from "node:path";
16
- import { fileURLToPath, pathToFileURL } from "node:url";
17
- import { dirname, join } from "node:path";
18
-
19
- /**
20
- * @fileoverview Detector registry and shared selector helpers.
21
- * @module fix-headers/detectors
22
- */
23
-
24
- /**
25
- * @typedef {{
26
- * id: string,
27
- * markers: string[],
28
- * extensions: string[],
29
- * enabledByDefault: boolean,
30
- * findNearestConfig: (startPath: string) => Promise<{root: string, marker: string} | null>,
31
- * parseProjectName: (marker: string, markerContent: string, rootDirName: string) => string,
32
- * resolveCommentSyntax: (filePath: string) => ({kind: "block" | "line" | "html", linePrefix?: string, lineSeparator?: string, blockStart?: string, blockLinePrefix?: string, blockEnd?: string} | null),
33
- * resolvePreservedPrefix?: (filePath: string, content: string) => string,
34
- * priority?: number
35
- * }} DetectorProfile
36
- */
37
-
38
- /**
39
- * Loads detector modules from the current directory.
40
- * @returns {Promise<DetectorProfile[]>} Loaded detectors.
41
- */
42
- async function loadDetectorsFromDirectory() {
43
- const directoryPath = dirname(fileURLToPath(import.meta.url));
44
- const files = await readdir(directoryPath);
45
- const detectorFiles = files
46
- .filter((fileName) => fileName.endsWith(".mjs"))
47
- .filter((fileName) => fileName !== "index.mjs" && fileName !== "shared.mjs")
48
- .sort((left, right) => left.localeCompare(right));
49
-
50
- const modules = await Promise.all(
51
- detectorFiles.map((fileName) => {
52
- const fileUrl = pathToFileURL(join(directoryPath, fileName)).href;
53
- return import(fileUrl);
54
- })
55
- );
56
-
57
- return modules.map((moduleExports) => moduleExports.detector).filter((entry) => entry && typeof entry.id === "string");
58
- }
59
-
60
- export const DETECTOR_PROFILES = await loadDetectorsFromDirectory();
61
-
62
- /** @type {Map<string, typeof DETECTOR_PROFILES[number]>} */
63
- const detectorMap = new Map(DETECTOR_PROFILES.map((detector) => [detector.id, detector]));
64
-
65
- /**
66
- * Applies runtime syntax overrides to a detector-provided syntax descriptor.
67
- * @param {{kind: "block" | "line" | "html", linePrefix?: string, lineSeparator?: string, blockStart?: string, blockLinePrefix?: string, blockEnd?: string}} syntax - Base syntax descriptor.
68
- * @param {{ linePrefix?: string, lineSeparator?: string, blockStart?: string, blockLinePrefix?: string, blockEnd?: string } | undefined} override - Override descriptor.
69
- * @returns {{kind: "block" | "line" | "html", linePrefix?: string, lineSeparator?: string, blockStart?: string, blockLinePrefix?: string, blockEnd?: string}} Effective descriptor.
70
- */
71
- function applySyntaxOverride(syntax, override) {
72
- if (!override || typeof override !== "object") {
73
- return syntax;
74
- }
75
-
76
- if (syntax.kind === "line") {
77
- return {
78
- ...syntax,
79
- linePrefix: typeof override.linePrefix === "string" && override.linePrefix.length > 0 ? override.linePrefix : syntax.linePrefix,
80
- lineSeparator: typeof override.lineSeparator === "string" ? override.lineSeparator : syntax.lineSeparator
81
- };
82
- }
83
-
84
- return {
85
- ...syntax,
86
- blockStart: typeof override.blockStart === "string" && override.blockStart.length > 0 ? override.blockStart : syntax.blockStart,
87
- blockLinePrefix:
88
- typeof override.blockLinePrefix === "string" && override.blockLinePrefix.length > 0
89
- ? override.blockLinePrefix
90
- : syntax.blockLinePrefix,
91
- blockEnd: typeof override.blockEnd === "string" && override.blockEnd.length > 0 ? override.blockEnd : syntax.blockEnd
92
- };
93
- }
94
-
95
- /**
96
- * Gets enabled detector profiles based on include/exclude options.
97
- * @param {{ enabledDetectors?: string[], disabledDetectors?: string[] }} [options={}] - Runtime options.
98
- * @returns {typeof DETECTOR_PROFILES} Enabled detector list.
99
- */
100
- export function getEnabledDetectors(options = {}) {
101
- const explicitEnabled = new Set(Array.isArray(options.enabledDetectors) ? options.enabledDetectors : []);
102
- const explicitDisabled = new Set(Array.isArray(options.disabledDetectors) ? options.disabledDetectors : []);
103
-
104
- return DETECTOR_PROFILES.filter((detector) => {
105
- if (explicitEnabled.size > 0) {
106
- return explicitEnabled.has(detector.id);
107
- }
108
-
109
- if (explicitDisabled.has(detector.id)) {
110
- return false;
111
- }
112
-
113
- return detector.enabledByDefault;
114
- });
115
- }
116
-
117
- /**
118
- * Gets allowed file extensions for enabled detectors.
119
- * @param {{ enabledDetectors?: string[], disabledDetectors?: string[], includeExtensions?: string[] }} [options={}] - Runtime options.
120
- * @returns {Set<string>} Allowed extensions.
121
- */
122
- export function getAllowedExtensions(options = {}) {
123
- if (Array.isArray(options.includeExtensions) && options.includeExtensions.length > 0) {
124
- return new Set(options.includeExtensions.map((extension) => extension.toLowerCase()));
125
- }
126
-
127
- const detectors = getEnabledDetectors(options);
128
- return new Set(detectors.flatMap((detector) => detector.extensions));
129
- }
130
-
131
- /**
132
- * Gets a detector by id.
133
- * @param {string} id - Detector id.
134
- * @returns {typeof DETECTOR_PROFILES[number] | undefined} Detector.
135
- */
136
- export function getDetectorById(id) {
137
- return detectorMap.get(id);
138
- }
139
-
140
- /**
141
- * Resolves comment syntax for a file path using detector-specific templates.
142
- * @param {string} filePath - File path.
143
- * @param {{ language?: string, enabledDetectors?: string[], disabledDetectors?: string[], detectors?: DetectorProfile[], detectorSyntaxOverrides?: Record<string, { linePrefix?: string, lineSeparator?: string, blockStart?: string, blockLinePrefix?: string, blockEnd?: string }> }} [options={}] - Runtime options. `detectors` overrides the enabled-detector set (matching {@link detectProjectFromMarkers}).
144
- * @returns {{kind: "block" | "line" | "html", linePrefix?: string, lineSeparator?: string, blockStart?: string, blockLinePrefix?: string, blockEnd?: string}} Syntax descriptor.
145
- */
146
- export function getCommentSyntaxForFile(filePath, options = {}) {
147
- const extension = extname(filePath).toLowerCase();
148
- const detectors = Array.isArray(options.detectors) ? options.detectors : getEnabledDetectors(options);
149
- for (const detector of detectors) {
150
- if (!detector.extensions.includes(extension)) {
151
- continue;
152
- }
153
- const resolved = detector.resolveCommentSyntax(filePath);
154
- if (resolved) {
155
- const overrides =
156
- options.detectorSyntaxOverrides && typeof options.detectorSyntaxOverrides === "object" ? options.detectorSyntaxOverrides : {};
157
- return applySyntaxOverride(resolved, overrides[detector.id]);
158
- }
159
- }
160
-
161
- return { kind: "block", blockStart: "/**", blockLinePrefix: " *\t", blockEnd: " */" };
162
- }
163
-
164
- /**
165
- * Resolves detector-specific leading content that must be preserved above inserted headers.
166
- * @param {string} filePath - File path.
167
- * @param {string} content - Full file content.
168
- * @param {{ language?: string, enabledDetectors?: string[], disabledDetectors?: string[] }} [options={}] - Runtime options.
169
- * @returns {string} Preserved prefix (possibly empty).
170
- */
171
- export function getPreservedPrefixForFile(filePath, content, options = {}) {
172
- const extension = extname(filePath).toLowerCase();
173
- const detectors = getEnabledDetectors(options);
174
- for (const detector of detectors) {
175
- if (!detector.extensions.includes(extension)) {
176
- continue;
177
- }
178
-
179
- if (typeof detector.resolvePreservedPrefix === "function") {
180
- return detector.resolvePreservedPrefix(filePath, content);
181
- }
182
-
183
- return "";
184
- }
185
-
186
- return "";
187
- }
@@ -1,76 +0,0 @@
1
- /**
2
- * @Project: @cldmv/fix-headers
3
- * @Filename: /src/detectors/json.mjs
4
- * @Date: 2026-03-01 20:00:00 -08:00 (1772433600)
5
- * @Author: Nate Corcoran <CLDMV>
6
- * @Email: <Shinrai@users.noreply.github.com>
7
- * -----
8
- * @Last modified by: Nate Corcoran <CLDMV> (Shinrai@users.noreply.github.com)
9
- * @Last modified time: 2026-03-01 20:00:00 -08:00 (1772433600)
10
- * -----
11
- * @Copyright: Copyright (c) 2026-2026 Catalyzed Motivation Inc. All rights reserved.
12
- */
13
-
14
- import { extname } from "node:path";
15
- import { findNearestMarker } from "./shared.mjs";
16
-
17
- /**
18
- * @fileoverview JSON-family detector implementation.
19
- * @module fix-headers/detectors/json
20
- */
21
-
22
- const markers = ["package.json"];
23
- const extensions = [".jsonv", ".jsonc", ".json5"];
24
-
25
- /**
26
- * Parses project name from package marker content.
27
- * @param {string} markerContent - Marker file content.
28
- * @param {string} rootDirName - Fallback root directory name.
29
- * @returns {string} Project name.
30
- */
31
- function parseJsonProjectName(markerContent, rootDirName) {
32
- try {
33
- const parsed = JSON.parse(markerContent);
34
- if (typeof parsed.name === "string" && parsed.name.trim().length > 0) {
35
- return parsed.name.trim();
36
- }
37
- return rootDirName;
38
- } catch {
39
- return rootDirName;
40
- }
41
- }
42
-
43
- /**
44
- * Resolves comment syntax for JSON-family file extensions.
45
- * @param {string} filePath - File path.
46
- * @returns {{kind: "block", blockStart: string, blockLinePrefix: string, blockEnd: string} | null} Syntax descriptor.
47
- */
48
- function resolveJsonCommentSyntax(filePath) {
49
- const extension = extname(filePath).toLowerCase();
50
- if (extensions.includes(extension)) {
51
- return {
52
- kind: "block",
53
- blockStart: "/**",
54
- blockLinePrefix: " *\t",
55
- blockEnd: " */"
56
- };
57
- }
58
- return null;
59
- }
60
-
61
- export const detector = {
62
- id: "json",
63
- priority: 95,
64
- markers,
65
- extensions,
66
- enabledByDefault: true,
67
- findNearestConfig(startPath) {
68
- return findNearestMarker(startPath, markers);
69
- },
70
- parseProjectName(_marker, markerContent, rootDirName) {
71
- return parseJsonProjectName(markerContent, rootDirName);
72
- },
73
- resolveCommentSyntax(filePath) {
74
- return resolveJsonCommentSyntax(filePath);
75
- }
76
- };
@@ -1,90 +0,0 @@
1
- /**
2
- * @Project: @cldmv/fix-headers
3
- * @Filename: /src/detectors/node.mjs
4
- * @Date: 2026-03-01T17:59:32-08:00 (1772416772)
5
- * @Author: Nate Corcoran <CLDMV>
6
- * @Email: <Shinrai@users.noreply.github.com>
7
- * -----
8
- * @Last modified by: Nate Corcoran <CLDMV> (Shinrai@users.noreply.github.com)
9
- * @Last modified time: 2026-03-01T17:59:32-08:00 (1772416772)
10
- * -----
11
- * @Copyright: Copyright (c) 2026-2026 Catalyzed Motivation Inc. All rights reserved.
12
- */
13
-
14
- import { extname } from "node:path";
15
- import { findNearestMarker } from "./shared.mjs";
16
-
17
- /**
18
- * @fileoverview Node.js detector implementation.
19
- * @module fix-headers/detectors/node
20
- */
21
-
22
- const markers = ["package.json"];
23
- const extensions = [".js", ".mjs", ".cjs", ".ts", ".tsx", ".jsx"];
24
-
25
- /**
26
- * Parses Node project name from package marker content.
27
- * @param {string} markerContent - Marker file content.
28
- * @param {string} rootDirName - Fallback root directory name.
29
- * @returns {string} Project name.
30
- */
31
- function parseNodeProjectName(markerContent, rootDirName) {
32
- try {
33
- const parsed = JSON.parse(markerContent);
34
- if (typeof parsed.name === "string" && parsed.name.trim().length > 0) {
35
- return parsed.name.trim();
36
- }
37
- return rootDirName;
38
- } catch {
39
- return rootDirName;
40
- }
41
- }
42
-
43
- /**
44
- * Resolves comment syntax for Node-handled file extensions.
45
- * @param {string} filePath - File path.
46
- * @returns {{kind: "block", blockStart: string, blockLinePrefix: string, blockEnd: string} | null} Syntax descriptor.
47
- */
48
- function resolveNodeCommentSyntax(filePath) {
49
- const extension = extname(filePath).toLowerCase();
50
- if (extensions.includes(extension)) {
51
- return {
52
- kind: "block",
53
- blockStart: "/**",
54
- blockLinePrefix: " *\t",
55
- blockEnd: " */"
56
- };
57
- }
58
- return null;
59
- }
60
-
61
- /**
62
- * Resolves preserved leading prefix for Node files (for example: shebang line).
63
- * @param {string} _filePath - File path.
64
- * @param {string} content - File content.
65
- * @returns {string} Preserved prefix.
66
- */
67
- function resolveNodePreservedPrefix(_filePath, content) {
68
- const shebangMatch = content.match(/^#!.*\b(node|bun|deno|tsx|ts-node)\b.*(?:\r?\n|$)/);
69
- return shebangMatch ? shebangMatch[0] : "";
70
- }
71
-
72
- export const detector = {
73
- id: "node",
74
- priority: 100,
75
- markers,
76
- extensions,
77
- enabledByDefault: true,
78
- findNearestConfig(startPath) {
79
- return findNearestMarker(startPath, markers);
80
- },
81
- parseProjectName(_marker, markerContent, rootDirName) {
82
- return parseNodeProjectName(markerContent, rootDirName);
83
- },
84
- resolvePreservedPrefix(filePath, content) {
85
- return resolveNodePreservedPrefix(filePath, content);
86
- },
87
- resolveCommentSyntax(filePath) {
88
- return resolveNodeCommentSyntax(filePath);
89
- }
90
- };
@@ -1,66 +0,0 @@
1
- /**
2
- * @Project: @cldmv/fix-headers
3
- * @Filename: /src/detectors/php.mjs
4
- * @Date: 2026-03-01T17:59:32-08:00 (1772416772)
5
- * @Author: Nate Corcoran <CLDMV>
6
- * @Email: <Shinrai@users.noreply.github.com>
7
- * -----
8
- * @Last modified by: Nate Corcoran <CLDMV> (Shinrai@users.noreply.github.com)
9
- * @Last modified time: 2026-03-01T17:59:32-08:00 (1772416772)
10
- * -----
11
- * @Copyright: Copyright (c) 2026-2026 Catalyzed Motivation Inc. All rights reserved.
12
- */
13
-
14
- import { extname } from "node:path";
15
- import { findNearestMarker } from "./shared.mjs";
16
-
17
- /**
18
- * @fileoverview PHP detector implementation.
19
- * @module fix-headers/detectors/php
20
- */
21
-
22
- const markers = ["composer.json"];
23
- const extensions = [".php"];
24
-
25
- /**
26
- * Resolves PHP comment syntax.
27
- * @param {string} filePath - File path.
28
- * @returns {{kind: "block", blockStart: string, blockLinePrefix: string, blockEnd: string} | null} Syntax descriptor.
29
- */
30
- function resolvePhpCommentSyntax(filePath) {
31
- const extension = extname(filePath).toLowerCase();
32
- if (extensions.includes(extension)) {
33
- return {
34
- kind: "block",
35
- blockStart: "/**",
36
- blockLinePrefix: " *\t",
37
- blockEnd: " */"
38
- };
39
- }
40
- return null;
41
- }
42
-
43
- export const detector = {
44
- id: "php",
45
- priority: 80,
46
- markers,
47
- extensions,
48
- enabledByDefault: true,
49
- findNearestConfig(startPath) {
50
- return findNearestMarker(startPath, markers);
51
- },
52
- parseProjectName(_marker, markerContent, rootDirName) {
53
- try {
54
- const parsed = JSON.parse(markerContent);
55
- if (typeof parsed.name === "string" && parsed.name.trim().length > 0) {
56
- return parsed.name.trim();
57
- }
58
- return rootDirName;
59
- } catch {
60
- return rootDirName;
61
- }
62
- },
63
- resolveCommentSyntax(filePath) {
64
- return resolvePhpCommentSyntax(filePath);
65
- }
66
- };
@@ -1,75 +0,0 @@
1
- /**
2
- * @Project: @cldmv/fix-headers
3
- * @Filename: /src/detectors/python.mjs
4
- * @Date: 2026-03-01T17:59:32-08:00 (1772416772)
5
- * @Author: Nate Corcoran <CLDMV>
6
- * @Email: <Shinrai@users.noreply.github.com>
7
- * -----
8
- * @Last modified by: Nate Corcoran <CLDMV> (Shinrai@users.noreply.github.com)
9
- * @Last modified time: 2026-03-01T17:59:32-08:00 (1772416772)
10
- * -----
11
- * @Copyright: Copyright (c) 2026-2026 Catalyzed Motivation Inc. All rights reserved.
12
- */
13
-
14
- import { extname } from "node:path";
15
- import { findNearestMarker } from "./shared.mjs";
16
-
17
- /**
18
- * @fileoverview Python detector implementation.
19
- * @module fix-headers/detectors/python
20
- */
21
-
22
- const markers = ["pyproject.toml", "setup.py", "requirements.txt"];
23
- const extensions = [".py"];
24
-
25
- /**
26
- * Parses Python project name from pyproject marker content when possible.
27
- * @param {string} markerContent - Marker content.
28
- * @param {string} rootDirName - Fallback root directory name.
29
- * @returns {string} Project name.
30
- */
31
- function parsePythonProjectName(markerContent, rootDirName) {
32
- const pyprojectMatch = markerContent.match(/^name\s*=\s*["']([^"']+)["']/m);
33
- if (pyprojectMatch?.[1]) {
34
- return pyprojectMatch[1];
35
- }
36
- return rootDirName;
37
- }
38
-
39
- /**
40
- * Resolves preserved leading prefix for Python files (for example: shebang line).
41
- * @param {string} _filePath - File path.
42
- * @param {string} content - File content.
43
- * @returns {string} Preserved prefix.
44
- */
45
- function resolvePythonPreservedPrefix(_filePath, content) {
46
- const shebangMatch = content.match(/^#!.*\bpython(?:\d+(?:\.\d+)*)?\b.*(?:\r?\n|$)/);
47
- return shebangMatch ? shebangMatch[0] : "";
48
- }
49
-
50
- export const detector = {
51
- id: "python",
52
- priority: 80,
53
- markers,
54
- extensions,
55
- enabledByDefault: true,
56
- findNearestConfig(startPath) {
57
- return findNearestMarker(startPath, markers);
58
- },
59
- parseProjectName(_marker, markerContent, rootDirName) {
60
- return parsePythonProjectName(markerContent, rootDirName);
61
- },
62
- resolvePreservedPrefix(filePath, content) {
63
- return resolvePythonPreservedPrefix(filePath, content);
64
- },
65
- resolveCommentSyntax(filePath) {
66
- const extension = extname(filePath).toLowerCase();
67
- if (extensions.includes(extension)) {
68
- return {
69
- kind: "line",
70
- linePrefix: "#"
71
- };
72
- }
73
- return null;
74
- }
75
- };
@@ -1,62 +0,0 @@
1
- /**
2
- * @Project: @cldmv/fix-headers
3
- * @Filename: /src/detectors/rust.mjs
4
- * @Date: 2026-03-01T17:59:32-08:00 (1772416772)
5
- * @Author: Nate Corcoran <CLDMV>
6
- * @Email: <Shinrai@users.noreply.github.com>
7
- * -----
8
- * @Last modified by: Nate Corcoran <CLDMV> (Shinrai@users.noreply.github.com)
9
- * @Last modified time: 2026-03-01T17:59:32-08:00 (1772416772)
10
- * -----
11
- * @Copyright: Copyright (c) 2026-2026 Catalyzed Motivation Inc. All rights reserved.
12
- */
13
-
14
- import { extname } from "node:path";
15
- import { findNearestMarker } from "./shared.mjs";
16
-
17
- /**
18
- * @fileoverview Rust detector implementation.
19
- * @module fix-headers/detectors/rust
20
- */
21
-
22
- const markers = ["Cargo.toml"];
23
- const extensions = [".rs"];
24
-
25
- /**
26
- * Resolves Rust comment syntax.
27
- * @param {string} filePath - File path.
28
- * @returns {{kind: "block", blockStart: string, blockLinePrefix: string, blockEnd: string} | null} Syntax descriptor.
29
- */
30
- function resolveRustCommentSyntax(filePath) {
31
- const extension = extname(filePath).toLowerCase();
32
- if (extensions.includes(extension)) {
33
- return {
34
- kind: "block",
35
- blockStart: "/**",
36
- blockLinePrefix: " *\t",
37
- blockEnd: " */"
38
- };
39
- }
40
- return null;
41
- }
42
-
43
- export const detector = {
44
- id: "rust",
45
- priority: 80,
46
- markers,
47
- extensions,
48
- enabledByDefault: true,
49
- findNearestConfig(startPath) {
50
- return findNearestMarker(startPath, markers);
51
- },
52
- parseProjectName(_marker, markerContent, rootDirName) {
53
- const cargoNameMatch = markerContent.match(/^name\s*=\s*["']([^"']+)["']/m);
54
- if (cargoNameMatch?.[1]) {
55
- return cargoNameMatch[1];
56
- }
57
- return rootDirName;
58
- },
59
- resolveCommentSyntax(filePath) {
60
- return resolveRustCommentSyntax(filePath);
61
- }
62
- };