@sasjs/lint 5.3.1 → 5.5.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 (53) hide show
  1. package/README.md +52 -0
  2. package/format/adjustLineLength.d.ts +34 -0
  3. package/format/adjustLineLength.js +159 -0
  4. package/format/adjustLineLength.js.map +1 -0
  5. package/format/formatFile.d.ts +3 -1
  6. package/format/formatFile.js +4 -4
  7. package/format/formatFile.js.map +1 -1
  8. package/format/formatFolder.d.ts +3 -1
  9. package/format/formatFolder.js +38 -7
  10. package/format/formatFolder.js.map +1 -1
  11. package/format/formatProject.d.ts +2 -1
  12. package/format/formatProject.js +2 -2
  13. package/format/formatProject.js.map +1 -1
  14. package/format/formatText.d.ts +19 -1
  15. package/format/formatText.js +23 -3
  16. package/format/formatText.js.map +1 -1
  17. package/format/longLines.d.ts +60 -0
  18. package/format/longLines.js +90 -0
  19. package/format/longLines.js.map +1 -0
  20. package/format/reflowComments.d.ts +28 -0
  21. package/format/reflowComments.js +305 -0
  22. package/format/reflowComments.js.map +1 -0
  23. package/format/rewrapText.d.ts +38 -0
  24. package/format/rewrapText.js +389 -0
  25. package/format/rewrapText.js.map +1 -0
  26. package/format/shared.js +34 -5
  27. package/format/shared.js.map +1 -1
  28. package/format/splitTrailingComments.d.ts +22 -0
  29. package/format/splitTrailingComments.js +68 -0
  30. package/format/splitTrailingComments.js.map +1 -0
  31. package/package.json +11 -24
  32. package/sasjslint-schema.json +10 -1
  33. package/types/FormatOptions.d.ts +29 -0
  34. package/types/FormatOptions.js +3 -0
  35. package/types/FormatOptions.js.map +1 -0
  36. package/types/KeywordCase.d.ts +10 -0
  37. package/types/KeywordCase.js +13 -0
  38. package/types/KeywordCase.js.map +1 -0
  39. package/types/LintConfig.d.ts +10 -0
  40. package/types/LintConfig.js +17 -0
  41. package/types/LintConfig.js.map +1 -1
  42. package/types/index.d.ts +2 -0
  43. package/types/index.js +2 -0
  44. package/types/index.js.map +1 -1
  45. package/utils/getDataSectionsDetail.d.ts +14 -0
  46. package/utils/getDataSectionsDetail.js +29 -13
  47. package/utils/getDataSectionsDetail.js.map +1 -1
  48. package/utils/getLintConfig.d.ts +1 -0
  49. package/utils/getLintConfig.js +1 -0
  50. package/utils/getLintConfig.js.map +1 -1
  51. package/utils/scanLine.d.ts +59 -0
  52. package/utils/scanLine.js +115 -0
  53. package/utils/scanLine.js.map +1 -0
@@ -0,0 +1,389 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.rewrapText = exports.splitWithTerminators = void 0;
4
+ const LineEndings_1 = require("../types/LineEndings");
5
+ const getDataSectionsDetail_1 = require("../utils/getDataSectionsDetail");
6
+ const scanLine_1 = require("../utils/scanLine");
7
+ const longLines_1 = require("./longLines");
8
+ /**
9
+ * A macro keyword that reads the token after it, so a break that leaves one at
10
+ * the end of a line is legal but reads badly.
11
+ *
12
+ * The delimiter before the keyword is required: without it the pattern also
13
+ * matches any word ENDING in those letters - `todo`, `redo`, `pseudo` - and the
14
+ * pass walks back to an earlier space for a reason that does not exist, leaving
15
+ * lines shorter than the limit allows. The `%` sigil counts as a delimiter in its
16
+ * own right, so the unspaced form `%do i=1%to` is still recognised.
17
+ */
18
+ const leadingKeyword = /(?:^|[\s(;,=]|%)%?(?:let|global|local|then|else|do|to|by)$/i;
19
+ /**
20
+ * The index of the last safe break point at or before `maximum`, searching only
21
+ * the range from `firstIndex`, so a caller looking for a break after the one it
22
+ * already took is not handed the one behind it.
23
+ */
24
+ const lastPositionAtMost = (positions, maximum, lastIndex, firstIndex = 0) => {
25
+ let low = firstIndex;
26
+ let high = lastIndex;
27
+ let found = -1;
28
+ while (low <= high) {
29
+ const middle = (low + high) >> 1;
30
+ if (positions[middle] <= maximum) {
31
+ found = middle;
32
+ low = middle + 1;
33
+ }
34
+ else {
35
+ high = middle - 1;
36
+ }
37
+ }
38
+ return found;
39
+ };
40
+ /**
41
+ * Breaks one line into lines no longer than `limit`, or returns `null` when no
42
+ * break produces a line that fits.
43
+ *
44
+ * The break is greedy: the last safe space that fits, walking back towards the
45
+ * indentation until one is found, so a wrap never turns one diagnostic into
46
+ * two. A continuation is indented one `indentationMultiple` past the line it
47
+ * came from, which keeps a file that satisfies `indentationMultiple` doing so.
48
+ */
49
+ const lastBreakBefore = (line, positions, maximum, start) => {
50
+ const last = lastPositionAtMost(positions, maximum, positions.length - 1);
51
+ let fallback = -1;
52
+ for (let index = last; index >= 0; index--) {
53
+ const position = positions[index];
54
+ if (position <= start)
55
+ break;
56
+ if (!leadingKeyword.test(line.slice(0, position).trimEnd()))
57
+ return position;
58
+ if (fallback < 0)
59
+ fallback = position;
60
+ }
61
+ return fallback;
62
+ };
63
+ /**
64
+ * The break points that sit at a statement boundary - the space immediately
65
+ * after a `;` in the code view.
66
+ *
67
+ * A newline there is always inert: the statement has ended, so no `%trim(` is
68
+ * needed, no macro variable value can gain whitespace and no `put` can gain an
69
+ * output line. They are therefore preferred over a break inside a statement,
70
+ * which is why `%let a=1; %let b=2;` breaks between the two statements rather
71
+ * than in the middle of the second one.
72
+ *
73
+ * @param {string} code - the line with literals and comments blanked, so the
74
+ * `;` inside a quoted value is not a boundary.
75
+ * @param {number[]} positions - the line's safe break points.
76
+ * @returns {number[]} the break points that follow a terminator.
77
+ */
78
+ const statementBoundaries = (code, positions) => positions.filter((position) => code.slice(0, position).trimEnd().endsWith(';'));
79
+ /** The index of the first safe break point at or after `minimum`. */
80
+ const firstPositionAtLeast = (positions, minimum) => {
81
+ let low = 0;
82
+ let high = positions.length - 1;
83
+ let found = -1;
84
+ while (low <= high) {
85
+ const middle = (low + high) >> 1;
86
+ if (positions[middle] >= minimum) {
87
+ found = middle;
88
+ high = middle - 1;
89
+ }
90
+ else {
91
+ low = middle + 1;
92
+ }
93
+ }
94
+ return found;
95
+ };
96
+ /**
97
+ * Breaks a macro declaration before its parameter commas, or returns `null`
98
+ * when it cannot.
99
+ *
100
+ * The declaration is the one statement the macro rules read as a whole, so the
101
+ * break is placed only at a comma that separates two parameters - never inside
102
+ * one - and a continuation line starts with the comma, which is how the library
103
+ * already writes a call that does not fit. `%mend` has no parameters and is
104
+ * left alone.
105
+ *
106
+ * @param {string} line - the declaration.
107
+ * @param {string} code - the same line with literals blanked, so a comma inside
108
+ * a quoted default is not mistaken for a separator.
109
+ * @param {number} limit - the maximum line length.
110
+ * @param {number} multiple - the indentation multiple.
111
+ * @returns {string[] | null} the lines, or `null` when no split fits.
112
+ */
113
+ const splitMacroDeclaration = (line, code, limit, multiple) => {
114
+ const opening = /^\s*%macro\s+[\w.]+\s*\(/i.exec(code);
115
+ if (!opening)
116
+ return null;
117
+ const open = opening[0].length - 1;
118
+ let depth = 0;
119
+ let close = -1;
120
+ for (let index = open; index < code.length; index++) {
121
+ if (code[index] === '(')
122
+ depth++;
123
+ else if (code[index] === ')' && --depth === 0) {
124
+ close = index;
125
+ break;
126
+ }
127
+ }
128
+ if (close < 0)
129
+ return null;
130
+ const inside = code.slice(open + 1, close);
131
+ const commas = [];
132
+ depth = 0;
133
+ for (let index = 0; index < inside.length; index++) {
134
+ if (inside[index] === '(')
135
+ depth++;
136
+ else if (inside[index] === ')')
137
+ depth--;
138
+ else if (inside[index] === ',' && depth === 0)
139
+ commas.push(index + open + 1);
140
+ }
141
+ if (!commas.length)
142
+ return null;
143
+ const indent = /^\s*/.exec(line)[0];
144
+ const continuationIndent = (0, longLines_1.continuationIndentFor)(indent, multiple);
145
+ const parameters = [];
146
+ let from = open + 1;
147
+ commas.forEach((comma) => {
148
+ parameters.push(line.slice(from, comma));
149
+ from = comma + 1;
150
+ });
151
+ parameters.push(line.slice(from, close));
152
+ const tail = line.slice(close);
153
+ const pieces = [];
154
+ let current = line.slice(0, open + 1) + parameters[0];
155
+ for (const parameter of parameters.slice(1)) {
156
+ const candidate = current + ',' + parameter;
157
+ if (candidate.length <= limit)
158
+ current = candidate;
159
+ else {
160
+ pieces.push(current);
161
+ current = continuationIndent + ',' + parameter;
162
+ }
163
+ if (current.length > limit)
164
+ return null;
165
+ }
166
+ if (current.length + tail.length <= limit) {
167
+ pieces.push(current + tail);
168
+ }
169
+ else {
170
+ pieces.push(current);
171
+ pieces.push(continuationIndent + tail);
172
+ }
173
+ return pieces.length > 1 && pieces.every((piece) => piece.length <= limit)
174
+ ? pieces
175
+ : null;
176
+ };
177
+ /**
178
+ * Breaks a `put`-family statement by ending the line with `%trim(` and opening
179
+ * the continuation with `)`, or returns `null` when it cannot.
180
+ *
181
+ * The newline and the continuation's indentation become the argument of
182
+ * `%trim`, which resolves to nothing, so the statement SAS reads is the same
183
+ * text it read before the break - `%put NOTE- the text %trim(` and
184
+ * `)continues;` write one line, not two. The space before `%trim(` is the
185
+ * separator the two halves need, so the space is kept rather than lost.
186
+ *
187
+ * @param {string} line - the line to break.
188
+ * @param {number} limit - the maximum line length.
189
+ * @param {number} multiple - the indentation multiple.
190
+ * @param {number[]} positions - the indexes of the line's safe spaces.
191
+ * @param {number} from - the index where the statement's text begins.
192
+ * @returns {string[] | null} the lines, or `null` when no break fits.
193
+ */
194
+ const splitWithTrim = (line, limit, multiple, positions, from, boundaries) => {
195
+ const indent = /^\s*/.exec(line)[0];
196
+ const continuationIndent = (0, longLines_1.continuationIndentFor)(indent, multiple);
197
+ const opening = '%trim(';
198
+ const pieces = [];
199
+ let prefix = '';
200
+ let start = (0, longLines_1.firstNonSpace)(line, 0);
201
+ let textFrom = from;
202
+ for (;;) {
203
+ const tail = line.slice(start);
204
+ if (prefix.length + tail.length <= limit) {
205
+ pieces.push((pieces.length ? prefix : '') + tail);
206
+ return pieces.length > 1 ? pieces : null;
207
+ }
208
+ // A statement boundary is the cheapest break there is: the text above ends
209
+ // with its `;`, so nothing has to be swallowed and the piece carries no
210
+ // `%trim(` machinery. Take it when it fits, and fall back to a break inside
211
+ // the statement only when none does.
212
+ // The first piece is emitted from column 0, so it is measured from there;
213
+ // a later one carries the prefix and starts at `start`. Measuring the first
214
+ // piece from `start` accepts one up to `limit + indent.length` characters
215
+ // and leaves a line that still raises `maxLineLength`.
216
+ const boundaryFrom = pieces.length ? start : 0;
217
+ const boundary = boundaries.filter((position) => position > start && prefix.length + position - boundaryFrom <= limit);
218
+ if (boundary.length) {
219
+ const at = boundary[boundary.length - 1];
220
+ pieces.push(pieces.length ? prefix + line.slice(start, at) : line.slice(0, at));
221
+ start = at + 1;
222
+ textFrom = start;
223
+ prefix = continuationIndent;
224
+ continue;
225
+ }
226
+ // The piece carries the prefix, the text up to the space it breaks at,
227
+ // and the `%trim(` that swallows the break. The space itself is carried by
228
+ // the `) ` that opens the next piece. The first piece is measured from the
229
+ // start of the line, because it keeps the line's own indentation.
230
+ const pieceFrom = pieces.length ? start : 0;
231
+ const maximum = pieceFrom + limit - prefix.length - opening.length;
232
+ // Only a break after the text already placed can be taken: the search starts
233
+ // at the first position at or after `textFrom`, which is where this piece
234
+ // begins.
235
+ const firstIndex = firstPositionAtLeast(positions, textFrom);
236
+ // No break point is left after the text already placed, so the whole line
237
+ // stays as it is rather than being broken somewhere behind itself.
238
+ if (firstIndex < 0)
239
+ return null;
240
+ const cut = lastPositionAtMost(positions, maximum, positions.length - 1, firstIndex);
241
+ const at = cut >= 0 ? positions[cut] : -1;
242
+ if (at < 0)
243
+ return null;
244
+ // The first piece keeps the line's own indentation and keyword; every
245
+ // later one starts with the `)` that closes the `%trim(` above it, and the
246
+ // blank the break replaced follows it. A blank left at the end of the
247
+ // upper line would be discarded, because SAS drops one that sits
248
+ // immediately before a macro call - and a trailing blank is what
249
+ // `noTrailingSpaces` reports anyway.
250
+ pieces.push((pieces.length ? prefix + line.slice(start, at) : line.slice(0, at)) +
251
+ opening);
252
+ start = at + 1;
253
+ textFrom = start;
254
+ prefix = continuationIndent + ') ';
255
+ }
256
+ };
257
+ const wrapLine = (line, limit, multiple, positions, boundaries) => {
258
+ const indent = /^\s*/.exec(line)[0];
259
+ const continuationIndent = (0, longLines_1.continuationIndentFor)(indent, multiple);
260
+ const continuationWidth = continuationIndent.length;
261
+ const lines = [];
262
+ let start = (0, longLines_1.firstNonSpace)(line, 0);
263
+ let first = true;
264
+ while (line.length - start + (first ? start : continuationWidth) > limit) {
265
+ // A continuation line carries its indentation, so it has that much less
266
+ // room than the line it replaces.
267
+ const maximum = first ? limit : start + limit - continuationWidth;
268
+ // A statement boundary first: it ends a whole statement, so the line reads
269
+ // as SAS rather than as a slice of one.
270
+ const boundary = lastBreakBefore(line, boundaries, maximum, start);
271
+ const cut = boundary >= 0
272
+ ? boundary
273
+ : lastBreakBefore(line, positions, maximum, start);
274
+ // No break point fits: the tail stays on one line and the caller leaves the
275
+ // whole line as it is.
276
+ if (cut < 0)
277
+ return null;
278
+ lines.push(first
279
+ ? line.slice(0, cut).trimEnd()
280
+ : continuationIndent + line.slice(start, cut).trimEnd());
281
+ start = (0, longLines_1.firstNonSpace)(line, cut);
282
+ first = false;
283
+ }
284
+ lines.push(first ? line : continuationIndent + line.slice(start));
285
+ return lines;
286
+ };
287
+ /**
288
+ * The lines of the text, each paired with the terminator that follows it.
289
+ *
290
+ * The terminator is kept rather than assumed, so a line a pass does not touch
291
+ * keeps its own bytes - including in a file whose endings are mixed, and in a
292
+ * file that has no final terminator at all.
293
+ */
294
+ const splitWithTerminators = (text) => {
295
+ var _a;
296
+ const parts = text.split(/(\r\n|\n)/);
297
+ const lines = [];
298
+ for (let index = 0; index < parts.length; index += 2) {
299
+ lines.push({ line: parts[index], ending: (_a = parts[index + 1]) !== null && _a !== void 0 ? _a : '' });
300
+ }
301
+ return lines;
302
+ };
303
+ exports.splitWithTerminators = splitWithTerminators;
304
+ /**
305
+ * Wraps the lines of a file that exceed `maxLineLength`, and leaves every other
306
+ * line byte-identical.
307
+ *
308
+ * Lines that are left alone, because a break would change what SAS reads or
309
+ * what another rule has to parse:
310
+ *
311
+ * - `datalines` / `cards` / `parmcards` records, and the statement that opens
312
+ * them, where a newline ends the record;
313
+ * - `%macro` and `%mend` declarations, which the macro rules read as one
314
+ * statement;
315
+ * - a `%*` comment statement, which is prose;
316
+ * - a `put` / `putlog` / `%put` / `%window` / `%display` statement and every
317
+ * line of it, where a newline is a line of output rather than a delimiter;
318
+ * - any line that carries a block comment, which `reflowComments` owns.
319
+ *
320
+ * A line is wrapped only when every line it becomes fits the limit, so the pass
321
+ * never turns one diagnostic into two.
322
+ *
323
+ * @param {string} text - the text to rewrap.
324
+ * @param {LintConfig} configuration - the configuration in force, header
325
+ * override included.
326
+ * @returns {string} the rewrapped text, with every untouched line's own
327
+ * terminator preserved.
328
+ */
329
+ const rewrapText = (text, configuration) => {
330
+ if (!text)
331
+ return text;
332
+ // The limit is off when the rule is absent from the config, not when
333
+ // `maxLineLength` reads 0: a switched-off limit leaves the property at its
334
+ // documented default of 80.
335
+ if (!configuration.lineLintRules.some((rule) => rule.name === 'maxLineLength'))
336
+ return text;
337
+ const entries = (0, exports.splitWithTerminators)(text);
338
+ const dataSections = (0, getDataSectionsDetail_1.getDataSectionsDetail)(text, configuration);
339
+ const multiple = (0, longLines_1.indentationMultipleOf)(configuration);
340
+ // The terminator for a break inserted into a line that has none of its own
341
+ // (the final line of a file with no final newline).
342
+ const defaultEnding = configuration.lineEndings === LineEndings_1.LineEndings.CRLF ? '\r\n' : '\n';
343
+ const result = [];
344
+ let state = (0, scanLine_1.cleanState)();
345
+ // Whether the previous line opened a `put`-family statement that has not
346
+ // reached its terminator yet, which makes this line a continuation of it.
347
+ let breakAwareOpen = false;
348
+ let changed = false;
349
+ entries.forEach(({ line, ending }, index) => {
350
+ // A data record is data, so it is not scanned: a comment marker or an
351
+ // apostrophe in one would otherwise stay open for the rest of the file.
352
+ const isData = (0, getDataSectionsDetail_1.checkIsDataLine)(dataSections, index);
353
+ const scanned = isData ? (0, scanLine_1.noScan)() : (0, scanLine_1.scanLine)(line, state);
354
+ state = scanned.endState;
355
+ const breakAware = isData
356
+ ? { line: false, open: false }
357
+ : (0, longLines_1.breakAwareState)(scanned.code, breakAwareOpen);
358
+ breakAwareOpen = breakAware.open;
359
+ // Break points that sit at a statement boundary, which the wrap and the
360
+ // `%trim(` break both prefer.
361
+ const boundaries = statementBoundaries(scanned.code, scanned.positions);
362
+ // Trailing spaces are another rule's finding: a line whose content fits is
363
+ // left for that fix rather than wrapped into a blank continuation.
364
+ const fits = line.trimEnd().length <= configuration.maxLineLength;
365
+ const wrapped = isData || longLines_1.macroComment.test(line) || fits
366
+ ? null
367
+ : longLines_1.macroDeclaration.test(line)
368
+ ? splitMacroDeclaration(line, scanned.code, configuration.maxLineLength, multiple)
369
+ : breakAware.line && !scanned.hasComment
370
+ ? splitWithTrim(line, configuration.maxLineLength, multiple, scanned.positions, (0, longLines_1.putTextStart)(line), boundaries)
371
+ : scanned.hasComment
372
+ ? null
373
+ : wrapLine(line, configuration.maxLineLength, multiple, scanned.positions, boundaries);
374
+ if (!wrapped) {
375
+ result.push(line + ending);
376
+ return;
377
+ }
378
+ changed = true;
379
+ // The break inside the line takes that line's own terminator, and a
380
+ // break in the final line takes the configured one.
381
+ const breakEnding = ending || defaultEnding;
382
+ wrapped.forEach((piece, pieceIndex) => {
383
+ result.push(piece + (pieceIndex === wrapped.length - 1 ? ending : breakEnding));
384
+ });
385
+ });
386
+ return changed ? result.join('') : text;
387
+ };
388
+ exports.rewrapText = rewrapText;
389
+ //# sourceMappingURL=rewrapText.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"rewrapText.js","sourceRoot":"","sources":["../../src/format/rewrapText.ts"],"names":[],"mappings":";;;AACA,sDAAkD;AAClD,0EAGuC;AACvC,gDAAgE;AAChE,2CAQoB;AAEpB;;;;;;;;;GASG;AACH,MAAM,cAAc,GAClB,6DAA6D,CAAA;AAE/D;;;;GAIG;AACH,MAAM,kBAAkB,GAAG,CACzB,SAAmB,EACnB,OAAe,EACf,SAAiB,EACjB,UAAU,GAAG,CAAC,EACN,EAAE;IACV,IAAI,GAAG,GAAG,UAAU,CAAA;IACpB,IAAI,IAAI,GAAG,SAAS,CAAA;IACpB,IAAI,KAAK,GAAG,CAAC,CAAC,C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C,IAAI,CAAC,EAClB,UAAU,CACX;oBACH,CAAC,CAAC,OAAO,CAAC,UAAU;wBAClB,CAAC,CAAC,IAAI;wBACN,CAAC,CAAC,QAAQ,CACN,IAAI,EACJ,aAAa,CAAC,aAAa,EAC3B,QAAQ,EACR,OAAO,CAAC,SAAS,EACjB,UAAU,CACX,CAAA;QAEb,IAAI,CAAC,OAAO,EAAE,CAAC;YACb,MAAM,CAAC,IAAI,CAAC,IAAI,GAAG,MAAM,CAAC,CAAA;YAC1B,OAAM;QACR,CAAC;QAED,OAAO,GAAG,IAAI,CAAA;QACd,oEAAoE;QACpE,oDAAoD;QACpD,MAAM,WAAW,GAAG,MAAM,IAAI,aAAa,CAAA;QAC3C,OAAO,CAAC,OAAO,CAAC,CAAC,KAAK,EAAE,UAAU,EAAE,EAAE;YACpC,MAAM,CAAC,IAAI,CACT,KAAK,GAAG,CAAC,UAAU,KAAK,OAAO,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,WAAW,CAAC,CACnE,CAAA;QACH,CAAC,CAAC,CAAA;IACJ,CAAC,CAAC,CAAA;IAEF,OAAO,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,IAAI,CAAA;AACzC,CAAC,CAAA;AA5FY,QAAA,UAAU,cA4FtB"}
package/format/shared.js CHANGED
@@ -1,18 +1,47 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.processLine = exports.processText = void 0;
4
- const LineEndings_1 = require("../types/LineEndings");
4
+ const parseLintOverride_1 = require("../utils/parseLintOverride");
5
5
  const splitText_1 = require("../utils/splitText");
6
+ const adjustLineLength_1 = require("./adjustLineLength");
7
+ const reflowComments_1 = require("./reflowComments");
8
+ const rewrapText_1 = require("./rewrapText");
9
+ const splitTrailingComments_1 = require("./splitTrailingComments");
10
+ /**
11
+ * How many times the passes run before the result is taken as final.
12
+ *
13
+ * A run is not idempotent on its own: `adjustLineLength` raises the file's own
14
+ * `maxLineLength` when it writes an exception, so a second run works to a
15
+ * higher limit and can wrap a line the first run declined. Running the passes
16
+ * until the text stops changing makes the output a fixed point, which is what
17
+ * "formatting twice changes nothing" means - and the bound stops a pair of
18
+ * states that undo each other from looping.
19
+ */
20
+ const maxPasses = 3;
6
21
  const processText = (text, config) => {
7
- const processedText = processContent(config, text);
22
+ let current = text;
23
+ // A pass that writes an exception has raised the limit the next pass works
24
+ // to, so the override is re-read from the text each time round.
25
+ let effective = (0, parseLintOverride_1.applyLintOverride)(current, config);
26
+ for (let pass = 0; pass < maxPasses; pass++) {
27
+ const next = processOnce(current, effective);
28
+ if (next === current)
29
+ break;
30
+ current = next;
31
+ effective = (0, parseLintOverride_1.applyLintOverride)(current, config);
32
+ }
33
+ return current;
34
+ };
35
+ exports.processText = processText;
36
+ const processOnce = (text, config) => {
37
+ const rewrapped = (0, rewrapText_1.rewrapText)((0, splitTrailingComments_1.splitTrailingComments)(processContent(config, text), config), config);
38
+ const processedText = (0, adjustLineLength_1.adjustLineLength)((0, reflowComments_1.reflowComments)(rewrapped, config), config);
8
39
  const lines = (0, splitText_1.splitText)(processedText, config);
9
40
  const formattedLines = lines.map((line) => {
10
41
  return (0, exports.processLine)(config, line);
11
42
  });
12
- const configuredLineEnding = config.lineEndings === LineEndings_1.LineEndings.LF ? '\n' : '\r\n';
13
- return formattedLines.join(configuredLineEnding);
43
+ return formattedLines.join((0, adjustLineLength_1.lineEndingOf)(config));
14
44
  };
15
- exports.processText = processText;
16
45
  const processContent = (config, content) => {
17
46
  let processedContent = content;
18
47
  config.fileLintRules
@@ -1 +1 @@
1
- {"version":3,"file":"shared.js","sourceRoot":"","sources":["../../src/format/shared.ts"],"names":[],"mappings":";;;AACA,sDAAkD;AAClD,kDAA8C;AAEvC,MAAM,WAAW,GAAG,CAAC,IAAY,EAAE,MAAkB,EAAE,EAAE;IAC9D,MAAM,aAAa,GAAG,cAAc,CA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E,MAAM,CAAC,CAAA;IAC9C,MAAM,cAAc,GAAG,KAAK,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE;QACxC,OAAO,IAAA,mBAAW,EAAC,MAAM,EAAE,IAAI,CAAC,CAAA;IAClC,CAAC,CAAC,CAAA;IAEF,OAAO,cAAc,CAAC,IAAI,CAAC,IAAA,+BAAY,EAAC,MAAM,CAAC,CAAC,CAAA;AAClD,CAAC,CAAA;AAED,MAAM,cAAc,GAAG,CAAC,MAAkB,EAAE,OAAe,EAAU,EAAE;IACrE,IAAI,gBAAgB,GAAG,OAAO,CAAA;IAC9B,MAAM,CAAC,aAAa;SACjB,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC;SACtB,OAAO,CAAC,CAAC,IAAI,EAAE,EAAE;QAChB,gBAAgB,GAAG,IAAI,CAAC,GAAI,CAAC,gBAAgB,EAAE,MAAM,CAAC,CAAA;IACxD,CAAC,CAAC,CAAA;IAEJ,OAAO,gBAAgB,CAAA;AACzB,CAAC,CAAA;AAEM,MAAM,WAAW,GAAG,CAAC,MAAkB,EAAE,IAAY,EAAU,EAAE;IACtE,IAAI,aAAa,GAAG,IAAI,CAAA;IACxB,MAAM,CAAC,aAAa;SACjB,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC;SACtB,OAAO,CAAC,CAAC,IAAI,EAAE,EAAE;QAChB,aAAa,GAAG,IAAI,CAAC,GAAI,CAAC,aAAa,EAAE,MAAM,CAAC,CAAA;IAClD,CAAC,CAAC,CAAA;IAEJ,OAAO,aAAa,CAAA;AACtB,CAAC,CAAA;AATY,QAAA,WAAW,eASvB"}
@@ -0,0 +1,22 @@
1
+ import { LintConfig } from '../types';
2
+ /**
3
+ * Lifts a trailing block comment onto a line of its own when the code it sits
4
+ * after is what has to be shortened.
5
+ *
6
+ * A line like
7
+ *
8
+ * , var /* variable name from which to return the format *\/
9
+ *
10
+ * is 63 characters whose code is 9, and no pass may break a line carrying a
11
+ * comment - so the comment moves down and both halves become ordinary lines:
12
+ * the code is wrapped by `rewrapText` if it is still too long, and the comment
13
+ * is reflowed by `reflowComments` like any other prose.
14
+ *
15
+ * A line is split only when it exceeds the limit, so a file that already fits
16
+ * keeps its layout. A `datalines` record is data and is never touched.
17
+ *
18
+ * @param {string} text - the text to read.
19
+ * @param {LintConfig} configuration - the configuration in force.
20
+ * @returns {string} the text, with over-long code/comment lines split.
21
+ */
22
+ export declare const splitTrailingComments: (text: string, configuration: LintConfig) => string;
@@ -0,0 +1,68 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.splitTrailingComments = void 0;
4
+ const getDataSectionsDetail_1 = require("../utils/getDataSectionsDetail");
5
+ const scanLine_1 = require("../utils/scanLine");
6
+ const adjustLineLength_1 = require("./adjustLineLength");
7
+ const rewrapText_1 = require("./rewrapText");
8
+ /**
9
+ * Lifts a trailing block comment onto a line of its own when the code it sits
10
+ * after is what has to be shortened.
11
+ *
12
+ * A line like
13
+ *
14
+ * , var /* variable name from which to return the format *\/
15
+ *
16
+ * is 63 characters whose code is 9, and no pass may break a line carrying a
17
+ * comment - so the comment moves down and both halves become ordinary lines:
18
+ * the code is wrapped by `rewrapText` if it is still too long, and the comment
19
+ * is reflowed by `reflowComments` like any other prose.
20
+ *
21
+ * A line is split only when it exceeds the limit, so a file that already fits
22
+ * keeps its layout. A `datalines` record is data and is never touched.
23
+ *
24
+ * @param {string} text - the text to read.
25
+ * @param {LintConfig} configuration - the configuration in force.
26
+ * @returns {string} the text, with over-long code/comment lines split.
27
+ */
28
+ const splitTrailingComments = (text, configuration) => {
29
+ if (!text)
30
+ return text;
31
+ if (!configuration.lineLintRules.some((rule) => rule.name === 'maxLineLength'))
32
+ return text;
33
+ const entries = (0, rewrapText_1.splitWithTerminators)(text);
34
+ const dataSections = (0, getDataSectionsDetail_1.getDataSectionsDetail)(text, configuration);
35
+ const output = [];
36
+ let state = (0, scanLine_1.cleanState)();
37
+ let changed = false;
38
+ entries.forEach(({ line, ending }, index) => {
39
+ const isData = (0, getDataSectionsDetail_1.checkIsDataLine)(dataSections, index);
40
+ const scanned = isData ? (0, scanLine_1.noScan)() : (0, scanLine_1.scanLine)(line, state);
41
+ state = scanned.endState;
42
+ const span = scanned.comments[0];
43
+ const code = span ? line.slice(0, span.start) : '';
44
+ // A line is split whenever it is over the limit and carries code before a
45
+ // comment, including when the CODE alone overruns: the code then goes to the
46
+ // wrapper (or to `adjustLineLength`) and the comment to the reflow, so each
47
+ // half reaches the pass that owns it instead of the line being refused by
48
+ // both.
49
+ const splits = !isData &&
50
+ !!span &&
51
+ line.length > configuration.maxLineLength &&
52
+ code.trim() !== '';
53
+ if (!splits) {
54
+ output.push(line + ending);
55
+ return;
56
+ }
57
+ changed = true;
58
+ const indent = /^\s*/.exec(line)[0];
59
+ // The break takes the line's own terminator; the final line of a file with
60
+ // no final newline takes the configured one instead.
61
+ const breakEnding = ending || (0, adjustLineLength_1.lineEndingOf)(configuration);
62
+ output.push(code.trimEnd() + breakEnding);
63
+ output.push(indent + line.slice(span.start) + ending);
64
+ });
65
+ return changed ? output.join('') : text;
66
+ };
67
+ exports.splitTrailingComments = splitTrailingComments;
68
+ //# sourceMappingURL=splitTrailingComments.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"splitTrailingComments.js","sourceRoot":"","sources":["../../src/format/splitTrailingComments.ts"],"names":[],"mappings":";;;AACA,0EAGuC;AACvC,gDAAgE;AAChE,yDAAiD;AACjD,6CAAmD;AAEnD;;;;;;;;;;;;;;;;;;;GAmBG;AACI,MAAM,qBAAqB,GAAG,CACnC,IAAY,EACZ,aAAyB,EACjB,EAAE;IACV,IAAI,CAAC,IAAI;QAAE,OAAO,IAAI,CAAA;IAEtB,IACE,CAAC,aAAa,CAAC,aAAa,CAAC,IAAI,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,C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,IAAI,CAAA;QACd,MAAM,MAAM,GAAG,MAAM,CAAC,IAAI,CAAC,IAAI,CAAE,CAAC,CAAC,CAAC,CAAA;QACpC,2EAA2E;QAC3E,qDAAqD;QACrD,MAAM,WAAW,GAAG,MAAM,IAAI,IAAA,+BAAY,EAAC,aAAa,CAAC,CAAA;QAEzD,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,OAAO,EAAE,GAAG,WAAW,CAAC,CAAA;QACzC,MAAM,CAAC,IAAI,CAAC,MAAM,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,KAAK,CAAC,GAAG,MAAM,CAAC,CAAA;IACvD,CAAC,CAAC,CAAA;IAEF,OAAO,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,IAAI,CAAA;AACzC,CAAC,CAAA;AApDY,QAAA,qBAAqB,yBAoDjC"}
package/package.json CHANGED
@@ -5,38 +5,24 @@
5
5
  "node": ">=22"
6
6
  },
7
7
  "scripts": {
8
- "test": "jest --coverage",
9
8
  "build": "rimraf build && tsc",
9
+ "check:package": "node scripts/checkPackageContents.mjs",
10
10
  "generate:macros": "node ./scripts/generate-macro-names.mjs",
11
- "prebuild": "node checkNodeVersion",
12
- "publishInit": "cp -r ./build/* . && rm -rf ./build && rm -rf ./src && rm tsconfig.json",
13
- "package:lib": "npm run build && cp ./package.json ./checkNodeVersion.js build && cp README.md build && cd build && npm version \"5.0.0\" && npm pack",
14
- "lint:fix": "npx prettier --write \"{src,test}/**/*.{ts,tsx,js,jsx,html,css,sass,less,json,yml,md,graphql}\"",
15
11
  "lint": "npx prettier --check \"{src,test}/**/*.{ts,tsx,js,jsx,html,css,sass,less,json,yml,md,graphql}\"",
12
+ "lint:fix": "npx prettier --write \"{src,test}/**/*.{ts,tsx,js,jsx,html,css,sass,less,json,yml,md,graphql}\"",
16
13
  "mutation": "stryker run",
17
14
  "mutation:changed": "node scripts/mutation-gate.mjs pr",
18
15
  "mutation:watch": "node scripts/mutation-gate.mjs weekly",
19
- "check:package": "node scripts/checkPackageContents.mjs"
16
+ "package:lib": "npm run build && cp ./package.json ./checkNodeVersion.js build && cp README.md build && cd build && npm version \"5.0.0\" && npm pack",
17
+ "prebuild": "node checkNodeVersion",
18
+ "prepublishOnly": "node -e \"const v=require('./package.json').version; if (/^0\\.0\\.0/.test(v)) { console.error('refusing to publish ' + v + ': the version is stamped from the tag (npm version <tag> --no-git-tag-version)'); process.exit(1) }\"",
19
+ "publishInit": "cp -r ./build/* . && rm -rf ./build && rm -rf ./src && rm tsconfig.json",
20
+ "release": "sasjs-release",
21
+ "test": "jest --coverage"
20
22
  },
21
23
  "publishConfig": {
22
24
  "access": "public"
23
25
  },
24
- "release": {
25
- "branches": [
26
- "main"
27
- ],
28
- "plugins": [
29
- "@semantic-release/commit-analyzer",
30
- "@semantic-release/release-notes-generator",
31
- [
32
- "@semantic-release/exec",
33
- {
34
- "prepareCmd": "npm version ${nextRelease.version} --no-git-tag-version --allow-same-version"
35
- }
36
- ],
37
- "@semantic-release/github"
38
- ]
39
- },
40
26
  "repository": {
41
27
  "type": "git",
42
28
  "url": "git+https://github.com/sasjs/lint.git"
@@ -56,7 +42,8 @@
56
42
  "homepage": "https://github.com/sasjs/lint#readme",
57
43
  "devDependencies": {
58
44
  "@nogoo9/gitleaks": "8.30.1-post.2",
59
- "@sasjs/sas-language": "0.3.3",
45
+ "@sasjs/release": "0.4.0",
46
+ "@sasjs/sas-language": "0.6.0",
60
47
  "@stryker-mutator/core": "10.1.1",
61
48
  "@stryker-mutator/jest-runner": "10.1.1",
62
49
  "@types/jest": "30.0.0",
@@ -93,7 +80,7 @@
93
80
  "glob": "^14.0.2",
94
81
  "minimatch": "^11.0.1"
95
82
  },
96
- "version": "5.3.1",
83
+ "version": "5.5.0",
97
84
  "devEngines": {
98
85
  "runtime": {
99
86
  "name": "node",