@cldmv/fix-headers 2.2.3 → 2.2.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.
@@ -2,7 +2,7 @@ export namespace detector {
2
2
  export let id: string;
3
3
  export { extensions };
4
4
  export let enabledByDefault: boolean;
5
- export function resolvePreservedPrefix(filePath: any, content: any): string;
5
+ export { isShebang as keepsAboveHeader };
6
6
  export function resolveCommentSyntax(filePath: any): {
7
7
  kind: "block";
8
8
  blockStart: string;
@@ -15,4 +15,5 @@ export namespace detector {
15
15
  * @module fix-headers/detectors/node
16
16
  */
17
17
  declare const extensions: string[];
18
+ import { isShebang } from "./top-lines.mjs";
18
19
  export {};
@@ -2,6 +2,8 @@ export namespace detector {
2
2
  export let id: string;
3
3
  export { extensions };
4
4
  export let enabledByDefault: boolean;
5
+ export function keepsAboveHeader(line: any, index: any): boolean;
6
+ export function resolveContentSkipReason(content: any): string;
5
7
  export function resolveCommentSyntax(filePath: any): {
6
8
  kind: "block";
7
9
  blockStart: string;
@@ -2,7 +2,7 @@ export namespace detector {
2
2
  export let id: string;
3
3
  export { extensions };
4
4
  export let enabledByDefault: boolean;
5
- export function resolvePreservedPrefix(filePath: any, content: any): string;
5
+ export { keepsAboveHeader };
6
6
  export function resolveCommentSyntax(filePath: any): {
7
7
  kind: string;
8
8
  linePrefix: string;
@@ -13,4 +13,12 @@ export namespace detector {
13
13
  * @module fix-headers/detectors/python
14
14
  */
15
15
  declare const extensions: string[];
16
+ /**
17
+ * Whether a line at the top of a Python file keeps its place above the header: a shebang on
18
+ * line 1, or a PEP 263 encoding declaration on line 1 or 2 (Python reads it nowhere else).
19
+ * @param {string} line - The line.
20
+ * @param {number} index - Zero-based line number.
21
+ * @returns {boolean} Whether the line stays above the header.
22
+ */
23
+ declare function keepsAboveHeader(line: string, index: number): boolean;
16
24
  export {};
@@ -2,6 +2,7 @@ export namespace detector {
2
2
  export let id: string;
3
3
  export { extensions };
4
4
  export let enabledByDefault: boolean;
5
+ export function keepsAboveHeader(line: any, index: any): boolean;
5
6
  export function resolveCommentSyntax(filePath: any): {
6
7
  kind: "block";
7
8
  blockStart: string;
@@ -0,0 +1,30 @@
1
+ /**
2
+ * Whether a comment line is a vi/Vim/ex modeline, in either of Vim's forms:
3
+ * `vim: set ts=4 sw=4:` (`se`/`set`, options, a closing `:`, then any text) or
4
+ * `vim: ts=4 sw=4 et` (options to the end of the line, separated by white space or `:`).
5
+ * Every option must be option syntax, and at least one must be `opt=val` or a common boolean
6
+ * option, so prose such as `vi: is the editor we use` is not a modeline. Vim reads modelines
7
+ * only in the first and last few lines of a file (`modelines`, default 5), so one at the top
8
+ * stops working once a header is put above it.
9
+ * @param {string} line - The comment line, comment opener included.
10
+ * @returns {boolean} Whether the line is a modeline.
11
+ */
12
+ export function isModeline(line: string): boolean;
13
+ /**
14
+ * A shebang (`#!`), which only works on a file's first line.
15
+ * @param {string} line - The line.
16
+ * @param {number} index - Zero-based line number in the file.
17
+ * @returns {boolean} Whether the line is a shebang on the first line.
18
+ */
19
+ export function isShebang(line: string, index: number): boolean;
20
+ /**
21
+ * Takes the run of lines at the start of `content` that `keep` accepts, line endings included.
22
+ * The run stops at the first line `keep` rejects (or at a last line without a line break, which
23
+ * is taken when accepted).
24
+ * @param {string} content - Text starting at a line start.
25
+ * @param {(line: string, index: number) => boolean} keep - Whether a line (without its line
26
+ * ending) at a zero-based line number of the file stays above the header.
27
+ * @param {number} [firstIndex=0] - Line number of the first line of `content` in the file.
28
+ * @returns {string} The lines taken.
29
+ */
30
+ export function takeTopLines(content: string, keep: (line: string, index: number) => boolean, firstIndex?: number): string;
@@ -2,6 +2,7 @@ export namespace detector {
2
2
  export let id: string;
3
3
  export { extensions };
4
4
  export let enabledByDefault: boolean;
5
+ export function keepsAboveHeader(line: any, index: any): boolean;
5
6
  export function resolveCommentSyntax(filePath: any): {
6
7
  kind: "line";
7
8
  linePrefix: string;
@@ -1,23 +1,20 @@
1
1
  /**
2
2
  * Splits the text of an existing header block that is not header fields from the fields.
3
3
  * `foreign` holds every line that is neither a field, a separator next to a field, nor an
4
- * empty line around them: description text, unknown `@Tag:` lines, a repeated managed tag,
5
- * a dash line among text, a line wrapping a field's value. `above` holds, for a line-comment
6
- * header only, the directive lines at the top of the comment (a `# -*- coding -*-` line,
7
- * `#cloud-config`, a `yaml-language-server` or `vim:` modeline); they are separate comments
8
- * the header's line match took in, and stay above the header. Lines come back as written
9
- * (comment prefix included), in their original order, with blank lines between them kept
10
- * and blank lines around them dropped.
4
+ * empty line around them: description text, unknown `@Tag:` lines, a dash line among text, a
5
+ * line wrapping a field's value. `copyrights` holds the values of the `@Copyright` lines after
6
+ * the header's own. A stacked copy's lead line (see {@link MOVED_BLOCK_LEAD}) is neither.
7
+ * Lines come back as written (comment prefix included), in their original order, with blank
8
+ * lines between them kept (unless a dropped line sat between the two pieces of text) and blank
9
+ * lines around them dropped.
11
10
  * @param {string} headerText - The existing header block (every stacked segment).
12
11
  * @param {string} [filePath=""] - File path used for syntax selection.
13
12
  * @param {Parameters<typeof findProjectHeader>[2]} [syntaxOptions={}] - Syntax resolution options.
14
- * @param {number} [firstLine=0] - Zero-based line number of the header's first line in the file
15
- * (an encoding declaration only counts on the file's first two lines).
16
- * @returns {{above: string[], foreign: string[]}} The non-field lines, as written.
13
+ * @returns {{foreign: string[], copyrights: string[]}} The non-field lines, as written, and the additional copyright values.
17
14
  */
18
- export function splitHeaderText(headerText: string, filePath?: string, syntaxOptions?: Parameters<typeof findProjectHeader>[2], firstLine?: number): {
19
- above: string[];
15
+ export function splitHeaderText(headerText: string, filePath?: string, syntaxOptions?: Parameters<typeof findProjectHeader>[2]): {
20
16
  foreign: string[];
17
+ copyrights: string[];
21
18
  };
22
19
  /**
23
20
  * Returns the lines of an existing header block that are not header fields (the `foreign`
@@ -28,6 +25,31 @@ export function splitHeaderText(headerText: string, filePath?: string, syntaxOpt
28
25
  * @returns {string[]} The non-field lines, as written.
29
26
  */
30
27
  export function extractForeignHeaderLines(headerText: string, filePath?: string, syntaxOptions?: Parameters<typeof findProjectHeader>[2]): string[];
28
+ /**
29
+ * The holder named by a `@Copyright` value, for comparing two notices: the value without a
30
+ * leading `Copyright`, `(c)` / `©`, the year or year range, and a trailing
31
+ * `All rights reserved.`, with white space collapsed, trailing punctuation dropped and
32
+ * lower-cased. `Copyright (c) 2013-2025 Example Inc. All rights reserved.` and
33
+ * `Copyright (c) 2013-2026 Example Inc. All rights reserved.` name the same holder.
34
+ * @param {string} value - A `@Copyright` value.
35
+ * @returns {string} The holder (empty when the notice names none).
36
+ */
37
+ export function copyrightHolder(value: string): string;
38
+ /**
39
+ * Repairs a file an earlier fix-headers version wrote its header above lines that must come
40
+ * first (`<?php`, `@charset`, a shebang, Go build constraints, a modeline, ...; see
41
+ * getPreservedPrefixForFile), or above a byte order mark. The top of the file is read as one
42
+ * run: lines already kept at the top (possibly none), then file headers with blank lines, then
43
+ * lines that would be kept at the top if they directly followed the first ones (or a byte
44
+ * order mark). Those last lines are moved up to join the first ones, in order, and the headers
45
+ * placed after them, where the header is then rewritten as usual. Any other content before
46
+ * those lines leaves the file as it is: nothing is moved up past it.
47
+ * @param {string} content - File content.
48
+ * @param {string} [filePath=""] - File path used for syntax selection.
49
+ * @param {Parameters<typeof findProjectHeader>[2]} [syntaxOptions={}] - Syntax resolution options.
50
+ * @returns {string} The content with the lines back at the top (unchanged when there is nothing to repair).
51
+ */
52
+ export function restoreTopLines(content: string, filePath?: string, syntaxOptions?: Parameters<typeof findProjectHeader>[2]): string;
31
53
  /**
32
54
  * Finds the first top-level project header block in a file.
33
55
  * @param {string} content - File content.
@@ -54,21 +76,26 @@ export function findProjectHeader(content: string, filePath?: string, syntaxOpti
54
76
  end: number;
55
77
  } | null;
56
78
  /**
57
- * Replaces or inserts a project header block. Text in the existing header that is not a
58
- * header field (see {@link splitHeaderText}) is never dropped: with
59
- * `strictHeaderBlock` (the default) it is written as its own comment block directly below
60
- * the header, separated from it and from the rest of the file by the margin; with
61
- * `strictHeaderBlock: false` it stays inside the header, after the fields. Directive lines a
62
- * line-comment header took in from directly above it stay above it.
63
- * @param {string} content - Original file content.
79
+ * Replaces or inserts a project header block. The existing header is the file's first comment
80
+ * (after what stays above it, see {@link splitPreservedPrefix}) when it is a file header, plus
81
+ * every file header stacked directly after it, which are copies of it: their fields are
82
+ * replaced by the new header's. Text in them that is not a header field (see
83
+ * {@link splitHeaderText}) is never dropped: with `strictHeaderBlock` (the default) it is
84
+ * written as its own comment block directly below the header, separated from it and from the
85
+ * rest of the file by the margin; with `strictHeaderBlock: false` it stays inside the header,
86
+ * after the fields. A `@Copyright` line after the header's own that names the same holder as
87
+ * the new header's (see {@link copyrightHolder}) is a duplicate and dropped; one naming another
88
+ * holder is kept as an additional `@Copyright` field under the new header's, in order, and
89
+ * reported in `extraCopyrights`.
90
+ * @param {string} original - Original file content.
64
91
  * @param {string} newHeader - Generated header text.
65
92
  * @param {string} [filePath=""] - File path used for syntax selection.
66
93
  * @param {{ language?: string, enabledDetectors?: string[], disabledDetectors?: string[], forcedDetectors?: string[], detectorSyntaxOverrides?: Record<string, { linePrefix?: string, lineSeparator?: string, blockStart?: string, blockLinePrefix?: string, blockEnd?: string }>, spacing?: number, margin?: number, strictHeaderBlock?: boolean }} [syntaxOptions={}] - Syntax resolution options.
67
- * @returns {{nextContent: string, changed: boolean, header: string, written: string}} Updated content result: `header` is the
68
- * header block as written, and `written` everything that took the old header's place (comment lines kept above the
69
- * header, the header, and the block of text moved below it).
94
+ * @returns {{nextContent: string, changed: boolean, header: string, written: string, extraCopyrights: string[]}} Updated
95
+ * content result: `header` is the header block as written, `written` everything that took the old header's place (the
96
+ * header and the block of text moved below it), and `extraCopyrights` the additional copyright values the header keeps.
70
97
  */
71
- export function replaceOrInsertHeader(content: string, newHeader: string, filePath?: string, syntaxOptions?: {
98
+ export function replaceOrInsertHeader(original: string, newHeader: string, filePath?: string, syntaxOptions?: {
72
99
  language?: string;
73
100
  enabledDetectors?: string[];
74
101
  disabledDetectors?: string[];
@@ -88,18 +115,19 @@ export function replaceOrInsertHeader(content: string, newHeader: string, filePa
88
115
  changed: boolean;
89
116
  header: string;
90
117
  written: string;
118
+ extraCopyrights: string[];
91
119
  };
92
120
  /**
93
121
  * Returns a file's content with its project header taken out: the file as it would read
94
122
  * with no header at all. Blank lines between the header and the next content, and a body
95
123
  * that is only whitespace, are dropped, so two versions of a file that differ only in their
96
124
  * header (its fields, framing, spacing or margin, or whether it has one) give the same body.
97
- * @param {string} content - File content.
125
+ * @param {string} original - File content.
98
126
  * @param {string} [filePath=""] - File path used for syntax selection.
99
127
  * @param {{ language?: string, enabledDetectors?: string[], disabledDetectors?: string[], forcedDetectors?: string[], detectorSyntaxOverrides?: Record<string, { linePrefix?: string, lineSeparator?: string, blockStart?: string, blockLinePrefix?: string, blockEnd?: string }>, spacing?: number, margin?: number }} [syntaxOptions={}] - Syntax resolution options.
100
128
  * @returns {string} The content outside the header.
101
129
  */
102
- export function extractHeaderlessBody(content: string, filePath?: string, syntaxOptions?: {
130
+ export function extractHeaderlessBody(original: string, filePath?: string, syntaxOptions?: {
103
131
  language?: string;
104
132
  enabledDetectors?: string[];
105
133
  disabledDetectors?: string[];
@@ -0,0 +1,33 @@
1
+ /**
2
+ *
3
+ * @Project: @cldmv/fix-headers
4
+ * @Filename: /src/utils/text.mjs
5
+ * @Date: 2026-10-31T16:30:00-07:00 (1793489400)
6
+ * @Author: Nate Corcoran <CLDMV>
7
+ * @Email: <Shinrai@users.noreply.github.com>
8
+ * -----
9
+ * @Last modified by: Nate Corcoran <CLDMV> (Shinrai@users.noreply.github.com)
10
+ * @Last modified time: 2026-10-31T16:30:00-07:00 (1793489400)
11
+ * -----
12
+ * @Copyright: Copyright (c) 2013-2026 Catalyzed Motivation Inc. All rights reserved.
13
+ *
14
+ */
15
+ /**
16
+ * @fileoverview String checks written as index scans instead of regular expressions, so they
17
+ * run in linear time on any input (the regex forms backtrack polynomially on long runs of
18
+ * `<` or `/`).
19
+ * @module fix-headers/utils/text
20
+ */
21
+ /**
22
+ * Tells whether text contains a `<…>` tag with at least one character inside, the same test
23
+ * as `/<[^>]+>/`.
24
+ * @param {string} text - Text to check.
25
+ * @returns {boolean} Whether a non-empty `<…>` tag is present.
26
+ */
27
+ export function hasAngleTag(text: string): boolean;
28
+ /**
29
+ * Removes every trailing `/`, the same as `.replace(/\/+$/, "")`.
30
+ * @param {string} text - Text to trim.
31
+ * @returns {string} The text without trailing slashes.
32
+ */
33
+ export function trimTrailingSlashes(text: string): string;
File without changes