@sasjs/lint 3.0.0 → 4.1.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.
@@ -0,0 +1,109 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.applyLintOverride = exports.getLintOverride = void 0;
4
+ const getHeaderLinesCount_1 = require("./getHeaderLinesCount");
5
+ const splitText_1 = require("./splitText");
6
+ /**
7
+ * The tag that introduces a per-file override, with the object that must follow
8
+ * it. The tag has to start a header line, and the `{` has to come immediately
9
+ * after it, so a `@brief` that mentions the syntax in prose, a longer tag such
10
+ * as `@sasjslintFoo`, and a tag with something else after it are all left alone
11
+ * rather than read as an override.
12
+ */
13
+ const marker = /^[^\w]*@sasjslint\s*\{/m;
14
+ /**
15
+ * Reads a balanced JSON object from `start`, honouring strings and escapes so
16
+ * a brace inside a value does not end the scan early.
17
+ */
18
+ const readObject = (text, start) => {
19
+ let depth = 0;
20
+ let inString = false;
21
+ let escaped = false;
22
+ for (let index = start; index < text.length; index++) {
23
+ const char = text[index];
24
+ if (inString) {
25
+ if (escaped)
26
+ escaped = false;
27
+ else if (char === '\\')
28
+ escaped = true;
29
+ else if (char === '"')
30
+ inString = false;
31
+ continue;
32
+ }
33
+ if (char === '"') {
34
+ inString = true;
35
+ }
36
+ else if (char === '{') {
37
+ depth++;
38
+ }
39
+ else if (char === '}') {
40
+ depth--;
41
+ if (depth === 0)
42
+ return text.slice(start, index + 1);
43
+ }
44
+ }
45
+ return null;
46
+ };
47
+ /**
48
+ * Reads the per-file override from the header of a file.
49
+ *
50
+ * The override is a `@sasjslint` tag followed by a JSON object, anywhere in the
51
+ * Doxygen header:
52
+ *
53
+ * ```
54
+ * /**
55
+ * @file
56
+ * @brief Calls the settlement API
57
+ *
58
+ * @sasjslint {"maxHeaderLineLength": 200, "noUndeclaredMacros": false}
59
+ * **\/
60
+ * ```
61
+ *
62
+ * Only the header is read, so an override cannot be buried in the body of a
63
+ * file. A tag that is missing, unterminated, malformed or not an object is
64
+ * ignored rather than raised: the linter must not fail on bad input.
65
+ *
66
+ * @param {string} text - the text content of the file.
67
+ * @param {LintConfig} config - the resolved configuration, used to find the
68
+ * header and its line endings.
69
+ * @returns {object | null} the override, or null when there is none.
70
+ */
71
+ const getLintOverride = (text, config) => {
72
+ if (!text)
73
+ return null;
74
+ const headerLinesCount = (0, getHeaderLinesCount_1.getHeaderLinesCount)(text, config);
75
+ if (!headerLinesCount)
76
+ return null;
77
+ const header = (0, splitText_1.splitText)(text, config).slice(0, headerLinesCount).join('\n');
78
+ const match = marker.exec(header);
79
+ if (!match)
80
+ return null;
81
+ // The match ends with the opening brace.
82
+ const brace = match.index + match[0].length - 1;
83
+ const body = readObject(header, brace);
84
+ if (!body)
85
+ return null;
86
+ try {
87
+ // The body always starts with `{`, so a successful parse is an object.
88
+ return JSON.parse(body);
89
+ }
90
+ catch (_a) {
91
+ return null;
92
+ }
93
+ };
94
+ exports.getLintOverride = getLintOverride;
95
+ /**
96
+ * Returns the configuration to lint a file with: the given configuration, with
97
+ * the file's own `@sasjslint` override merged over it. The header wins, since
98
+ * it is the more specific statement.
99
+ *
100
+ * @param {string} text - the text content of the file.
101
+ * @param {LintConfig} config - the resolved configuration.
102
+ * @returns {LintConfig} the effective configuration.
103
+ */
104
+ const applyLintOverride = (text, config) => {
105
+ const override = (0, exports.getLintOverride)(text, config);
106
+ return override ? config.override(override) : config;
107
+ };
108
+ exports.applyLintOverride = applyLintOverride;
109
+ //# sourceMappingURL=parseLintOverride.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"parseLintOverride.js","sourceRoot":"","sources":["../../src/utils/parseLintOverride.ts"],"names":[],"mappings":";;;AACA,+DAA2D;AAC3D,2CAAuC;AAEvC;;;;;;GAMG;AACH,MAAM,MAAM,GAAG,yBAAyB,CAAA;AAExC;;;GAGG;AACH,MAAM,UAAU,GAAG,CAAC,IAAY,EAAE,KAAa,EAAiB,EAAE;IAChE,IA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