@sasjs/lint 2.6.0 → 3.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.
- package/.git-hooks/pre-commit +18 -0
- package/.github/CONTRIBUTING.md +27 -0
- package/.github/workflows/build.yml +13 -7
- package/.github/workflows/publish.yml +12 -1
- package/.pre-commit-config.yaml +16 -0
- package/README.md +49 -1
- package/package.json +12 -12
- package/rules/file/index.d.ts +3 -0
- package/rules/file/index.js +7 -1
- package/rules/file/index.js.map +1 -1
- package/rules/file/noSingleAsteriskComments.d.ts +7 -0
- package/rules/file/noSingleAsteriskComments.js +219 -0
- package/rules/file/noSingleAsteriskComments.js.map +1 -0
- package/rules/file/noUndeclaredMacros.d.ts +7 -0
- package/rules/file/noUndeclaredMacros.js +77 -0
- package/rules/file/noUndeclaredMacros.js.map +1 -0
- package/rules/file/noUnusedMacros.d.ts +7 -0
- package/rules/file/noUnusedMacros.js +67 -0
- package/rules/file/noUnusedMacros.js.map +1 -0
- package/sasjslint-schema.json +53 -2
- package/scripts/generate-macro-names.mjs +101 -0
- package/types/LintConfig.js +9 -0
- package/types/LintConfig.js.map +1 -1
- package/utils/getLintConfig.js +1 -1
- package/utils/getLintConfig.js.map +1 -1
- package/utils/headerMacros.d.ts +51 -0
- package/utils/headerMacros.js +309 -0
- package/utils/headerMacros.js.map +1 -0
- package/utils/index.d.ts +3 -0
- package/utils/index.js +3 -0
- package/utils/index.js.map +1 -1
- package/utils/parseMacroCalls.d.ts +28 -0
- package/utils/parseMacroCalls.js +230 -0
- package/utils/parseMacroCalls.js.map +1 -0
- package/utils/sasMacros.d.ts +16 -0
- package/utils/sasMacros.generated.d.ts +6 -0
- package/utils/sasMacros.generated.js +136 -0
- package/utils/sasMacros.generated.js.map +1 -0
- package/utils/sasMacros.js +22 -0
- package/utils/sasMacros.js.map +1 -0
- package/scripts/audit.mjs +0 -131
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.noUnusedMacros = void 0;
|
|
4
|
+
const types_1 = require("../../types");
|
|
5
|
+
const LintRuleType_1 = require("../../types/LintRuleType");
|
|
6
|
+
const Severity_1 = require("../../types/Severity");
|
|
7
|
+
const headerMacros_1 = require("../../utils/headerMacros");
|
|
8
|
+
const parseMacroCalls_1 = require("../../utils/parseMacroCalls");
|
|
9
|
+
const name = 'noUnusedMacros';
|
|
10
|
+
const description = 'Report macros declared in the <h4> SAS Macros </h4> section that the file does not use.';
|
|
11
|
+
const message = `Macro '{macro}' is declared in the <h4> SAS Macros </h4> section but not used in the file`;
|
|
12
|
+
/**
|
|
13
|
+
* Collects the macros declared in the `<h4> SAS Macros </h4>` section that the
|
|
14
|
+
* file itself never invokes. A macro that appears more than once is reported
|
|
15
|
+
* once, at its first entry.
|
|
16
|
+
*/
|
|
17
|
+
const getUnusedMacros = (value, config) => {
|
|
18
|
+
if (!value)
|
|
19
|
+
return [];
|
|
20
|
+
const used = new Set((0, parseMacroCalls_1.parseMacroCalls)(value, config).map((call) => call.name.toLowerCase()));
|
|
21
|
+
const unused = [];
|
|
22
|
+
const reported = new Set();
|
|
23
|
+
(0, headerMacros_1.getHeaderMacros)(value, config)
|
|
24
|
+
.filter((macro) => macro.section === 'sasMacros')
|
|
25
|
+
.forEach((macro) => {
|
|
26
|
+
const key = macro.name.toLowerCase();
|
|
27
|
+
if (reported.has(key))
|
|
28
|
+
return;
|
|
29
|
+
reported.add(key);
|
|
30
|
+
if (used.has(key))
|
|
31
|
+
return;
|
|
32
|
+
unused.push(macro);
|
|
33
|
+
});
|
|
34
|
+
return unused;
|
|
35
|
+
};
|
|
36
|
+
const test = (value, config) => {
|
|
37
|
+
const cfg = config || new types_1.LintConfig();
|
|
38
|
+
const severity = cfg.severityLevel[name] || Severity_1.Severity.Warning;
|
|
39
|
+
return getUnusedMacros(value, cfg).map((macro) => ({
|
|
40
|
+
message: message.replace('{macro}', macro.name),
|
|
41
|
+
lineNumber: macro.lineNumber,
|
|
42
|
+
startColumnNumber: macro.startColumnNumber,
|
|
43
|
+
endColumnNumber: macro.endColumnNumber,
|
|
44
|
+
severity
|
|
45
|
+
}));
|
|
46
|
+
};
|
|
47
|
+
const fix = (value, config) => {
|
|
48
|
+
const cfg = config || new types_1.LintConfig();
|
|
49
|
+
const macros = getUnusedMacros(value, cfg).map((macro) => macro.name);
|
|
50
|
+
if (!macros.length)
|
|
51
|
+
return value;
|
|
52
|
+
return (0, headerMacros_1.removeMacrosFromHeader)(value, cfg, macros);
|
|
53
|
+
};
|
|
54
|
+
/**
|
|
55
|
+
* Lint rule that reports macros declared in the `<h4> SAS Macros </h4>` section
|
|
56
|
+
* of a file header that the file itself never invokes. The formatter removes
|
|
57
|
+
* them from the header.
|
|
58
|
+
*/
|
|
59
|
+
exports.noUnusedMacros = {
|
|
60
|
+
type: LintRuleType_1.LintRuleType.File,
|
|
61
|
+
name,
|
|
62
|
+
description,
|
|
63
|
+
message,
|
|
64
|
+
test,
|
|
65
|
+
fix
|
|
66
|
+
};
|
|
67
|
+
//# sourceMappingURL=noUnusedMacros.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"noUnusedMacros.js","sourceRoot":"","sources":["../../../src/rules/file/noUnusedMacros.ts"],"names":[],"mappings":";;;AAAA,uCAAoD;AAEpD,2DAAuD;AACvD,mDAA+C;AAC/C,2DAIiC;AACjC,iEAA6D;AAE7D,MAAM,IAAI,GAAG,gBAAgB,CAAA;AAC7B,MAAM,WAAW,GACf,yFAAyF,CAAA;AAC3F,MAAM,OAAO,GAAG,2FAA2F,CAAA;AAE3G;;;;GAIG;AACH,MAAM,eAAe,GAAG,CAAC,KAAa,EAAE,MAAkB,EAAiB,EAAE;IAC3E,IAAI,CAAC,KAAK;QAAE,OAAO,EAAE,CAAA;IAErB,MAAM,IAAI,GAAG,IAAI,GAAG,CAClB,IAAA,iCAAe,EAAC,KAAK,EAAE,MAAM,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,eAAe;QACtC,QAAQ;KACT,CAAC,CAAC,CAAA;AACL,CAAC,CAAA;AAED,MAAM,GAAG,GAAG,CAAC,KAAa,EAAE,MAAmB,EAAU,EAAE;IACzD,MAAM,GAAG,GAAG,MAAM,IAAI,IAAI,kBAAU,EAAE,CAAA;IACtC,MAAM,MAAM,GAAG,eAAe,CAAC,KAAK,EAAE,GAAG,CAAC,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,CAAC,IAAI,CAAC,CAAA;IAErE,IAAI,CAAC,MAAM,CAAC,MAAM;QAAE,OAAO,KAAK,CAAA;IAEhC,OAAO,IAAA,qCAAsB,EAAC,KAAK,EAAE,GAAG,EAAE,MAAM,CAAC,CAAA;AACnD,CAAC,CAAA;AAED;;;;GAIG;AACU,QAAA,cAAc,GAAiB;IAC1C,IAAI,EAAE,2BAAY,CAAC,IAAI;IACvB,IAAI;IACJ,WAAW;IACX,OAAO;IACP,IAAI;IACJ,GAAG;CACJ,CAAA"}
|
package/sasjslint-schema.json
CHANGED
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
"default": {
|
|
8
8
|
"noEncodedPasswords": true,
|
|
9
9
|
"hasDoxygenHeader": true,
|
|
10
|
-
"defaultHeader": "/**{lineEnding} @file{lineEnding} @brief <Your brief here>{lineEnding} <h4> SAS Macros </h4>{lineEnding}**/",
|
|
10
|
+
"defaultHeader": "/**{lineEnding} @file{lineEnding} @brief <Your brief here>{lineEnding}{lineEnding} <h4> SAS Macros </h4>{lineEnding}{lineEnding}**/",
|
|
11
11
|
"hasMacroNameInMend": false,
|
|
12
12
|
"hasMacroParentheses": true,
|
|
13
13
|
"indentationMultiple": 2,
|
|
@@ -17,9 +17,12 @@
|
|
|
17
17
|
"maxDataLineLength": 80,
|
|
18
18
|
"noGremlins": true,
|
|
19
19
|
"noNestedMacros": true,
|
|
20
|
+
"noSingleAsteriskComments": false,
|
|
20
21
|
"noSpacesInFileNames": true,
|
|
21
22
|
"noTabs": true,
|
|
22
23
|
"noTrailingSpaces": true,
|
|
24
|
+
"noUndeclaredMacros": true,
|
|
25
|
+
"noUnusedMacros": true,
|
|
23
26
|
"lineEndings": "off",
|
|
24
27
|
"strictMacroDefinition": true,
|
|
25
28
|
"ignoreList": ["sajsbuild", "sasjsresults"],
|
|
@@ -42,6 +45,9 @@
|
|
|
42
45
|
"indentationMultiple": 4,
|
|
43
46
|
"hasMacroNameInMend": true,
|
|
44
47
|
"noNestedMacros": true,
|
|
48
|
+
"noSingleAsteriskComments": false,
|
|
49
|
+
"noUndeclaredMacros": true,
|
|
50
|
+
"noUnusedMacros": true,
|
|
45
51
|
"hasMacroParentheses": true,
|
|
46
52
|
"lineEndings": "crlf",
|
|
47
53
|
"strictMacroDefinition": true,
|
|
@@ -72,7 +78,7 @@
|
|
|
72
78
|
"type": "string",
|
|
73
79
|
"title": "defaultHeader",
|
|
74
80
|
"description": "This sets the default program header - applies when a SAS program does NOT begin with `/**`.",
|
|
75
|
-
"default": "/**{lineEnding} @file{lineEnding} @brief <Your brief here>{lineEnding} <h4> SAS Macros </h4>{lineEnding}**/",
|
|
81
|
+
"default": "/**{lineEnding} @file{lineEnding} @brief <Your brief here>{lineEnding}{lineEnding} <h4> SAS Macros </h4>{lineEnding}{lineEnding}**/",
|
|
76
82
|
"examples": []
|
|
77
83
|
},
|
|
78
84
|
"noGremlins": {
|
|
@@ -159,6 +165,14 @@
|
|
|
159
165
|
"default": true,
|
|
160
166
|
"examples": [true, false]
|
|
161
167
|
},
|
|
168
|
+
"noSingleAsteriskComments": {
|
|
169
|
+
"$id": "#/properties/noSingleAsteriskComments",
|
|
170
|
+
"type": "boolean",
|
|
171
|
+
"title": "noSingleAsteriskComments",
|
|
172
|
+
"description": "Enforces the absence of SAS comment statements that begin with a single asterisk, such as `* some text;`. Shows a warning for each such comment. Defaults to off.",
|
|
173
|
+
"default": false,
|
|
174
|
+
"examples": [true, false]
|
|
175
|
+
},
|
|
162
176
|
"noSpacesInFileNames": {
|
|
163
177
|
"$id": "#/properties/noSpacesInFileNames",
|
|
164
178
|
"type": "boolean",
|
|
@@ -183,6 +197,22 @@
|
|
|
183
197
|
"default": true,
|
|
184
198
|
"examples": [true, false]
|
|
185
199
|
},
|
|
200
|
+
"noUndeclaredMacros": {
|
|
201
|
+
"$id": "#/properties/noUndeclaredMacros",
|
|
202
|
+
"type": "boolean",
|
|
203
|
+
"title": "noUndeclaredMacros",
|
|
204
|
+
"description": "Reports a warning for each macro a file invokes without declaring it in the `<h4> SAS Macros </h4>` or `<h4> Other Macros </h4>` section of the header. Macros that ship with SAS are always considered declared. The formatter resolves the warning by adding the macro names to the header, sorted alphabetically.",
|
|
205
|
+
"default": true,
|
|
206
|
+
"examples": [true, false]
|
|
207
|
+
},
|
|
208
|
+
"noUnusedMacros": {
|
|
209
|
+
"$id": "#/properties/noUnusedMacros",
|
|
210
|
+
"type": "boolean",
|
|
211
|
+
"title": "noUnusedMacros",
|
|
212
|
+
"description": "Reports a warning for each macro declared in the `<h4> SAS Macros </h4>` section of the header that the file itself never invokes. The formatter removes the unused entries. A macro can be referenced indirectly, so the warning is advisory.",
|
|
213
|
+
"default": true,
|
|
214
|
+
"examples": [true, false]
|
|
215
|
+
},
|
|
186
216
|
"lineEndings": {
|
|
187
217
|
"$id": "#/properties/lineEndings",
|
|
188
218
|
"type": "string",
|
|
@@ -306,6 +336,13 @@
|
|
|
306
336
|
"enum": ["error", "warn"],
|
|
307
337
|
"default": "warn"
|
|
308
338
|
},
|
|
339
|
+
"noSingleAsteriskComments": {
|
|
340
|
+
"$id": "#/properties/severityLevel/noSingleAsteriskComments",
|
|
341
|
+
"title": "noSingleAsteriskComments",
|
|
342
|
+
"type": "string",
|
|
343
|
+
"enum": ["error", "warn"],
|
|
344
|
+
"default": "warn"
|
|
345
|
+
},
|
|
309
346
|
"noSpacesInFileNames": {
|
|
310
347
|
"$id": "#/properties/severityLevel/noSpacesInFileNames",
|
|
311
348
|
"title": "noSpacesInFileNames",
|
|
@@ -327,6 +364,20 @@
|
|
|
327
364
|
"enum": ["error", "warn"],
|
|
328
365
|
"default": "warn"
|
|
329
366
|
},
|
|
367
|
+
"noUndeclaredMacros": {
|
|
368
|
+
"$id": "#/properties/severityLevel/noUndeclaredMacros",
|
|
369
|
+
"title": "noUndeclaredMacros",
|
|
370
|
+
"type": "string",
|
|
371
|
+
"enum": ["error", "warn"],
|
|
372
|
+
"default": "warn"
|
|
373
|
+
},
|
|
374
|
+
"noUnusedMacros": {
|
|
375
|
+
"$id": "#/properties/severityLevel/noUnusedMacros",
|
|
376
|
+
"title": "noUnusedMacros",
|
|
377
|
+
"type": "string",
|
|
378
|
+
"enum": ["error", "warn"],
|
|
379
|
+
"default": "warn"
|
|
380
|
+
},
|
|
330
381
|
"lineEndings": {
|
|
331
382
|
"$id": "#/properties/severityLevel/lineEndings",
|
|
332
383
|
"title": "lineEndings",
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Generates `src/utils/sasMacros.generated.ts` from the SAS language data.
|
|
3
|
+
*
|
|
4
|
+
* The list of macros that ship with SAS is not lint's to maintain: it is
|
|
5
|
+
* language data, and `@sasjs/sas-language` owns it. This script reads the
|
|
6
|
+
* `macroStatements` and `macroFunctions` groups and emits the names the
|
|
7
|
+
* `noUndeclaredMacros` rule treats as declared.
|
|
8
|
+
*
|
|
9
|
+
* The output is committed so that the published package carries no dependency
|
|
10
|
+
* on the data package, and `src/utils/sasMacros.spec.ts` regenerates the list
|
|
11
|
+
* from the same data and fails when the two differ, so a refresh upstream
|
|
12
|
+
* cannot leave the constant stale.
|
|
13
|
+
*
|
|
14
|
+
* Run with `npm run generate:macros`.
|
|
15
|
+
*/
|
|
16
|
+
import { readFile, writeFile } from 'node:fs/promises'
|
|
17
|
+
import path from 'node:path'
|
|
18
|
+
import { fileURLToPath } from 'node:url'
|
|
19
|
+
|
|
20
|
+
const ROOT = path.resolve(path.dirname(fileURLToPath(import.meta.url)), '..')
|
|
21
|
+
const PACKAGE = '@sasjs/sas-language'
|
|
22
|
+
const GROUPS = ['macroStatements', 'macroFunctions']
|
|
23
|
+
const TARGET = path.join(ROOT, 'src', 'utils', 'sasMacros.generated.ts')
|
|
24
|
+
|
|
25
|
+
const indexPath = (group) =>
|
|
26
|
+
path.join(
|
|
27
|
+
ROOT,
|
|
28
|
+
'node_modules',
|
|
29
|
+
...PACKAGE.split('/'),
|
|
30
|
+
'data',
|
|
31
|
+
`${group}.index.json`
|
|
32
|
+
)
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* Every macro name a group carries, as a bare lower-case name. Compound
|
|
36
|
+
* entries such as `%DO %UNTIL` are dropped: they are a spelling of the
|
|
37
|
+
* `%DO` statement and no source token can match them.
|
|
38
|
+
*/
|
|
39
|
+
const collectMacroNames = async () => {
|
|
40
|
+
const names = new Set()
|
|
41
|
+
|
|
42
|
+
for (const group of GROUPS) {
|
|
43
|
+
let parsed
|
|
44
|
+
try {
|
|
45
|
+
parsed = JSON.parse(await readFile(indexPath(group), 'utf8'))
|
|
46
|
+
} catch (error) {
|
|
47
|
+
throw new Error(
|
|
48
|
+
`cannot read ${PACKAGE}/data/${group}.index.json - run 'npm install' first (${error.message})`
|
|
49
|
+
)
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
if (!Array.isArray(parsed?.entries)) {
|
|
53
|
+
throw new Error(
|
|
54
|
+
`${PACKAGE}/data/${group}.index.json has an unexpected shape: expected { entries: [] }`
|
|
55
|
+
)
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
for (const entry of parsed.entries) {
|
|
59
|
+
const name = String(entry?.[0] ?? '')
|
|
60
|
+
.replace(/^%/, '')
|
|
61
|
+
.trim()
|
|
62
|
+
.toLowerCase()
|
|
63
|
+
if (!name || /\s/.test(name)) continue
|
|
64
|
+
names.add(name)
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
return [...names].sort()
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
/**
|
|
72
|
+
* The generated file's text.
|
|
73
|
+
*/
|
|
74
|
+
const render = (names) =>
|
|
75
|
+
[
|
|
76
|
+
'// Generated by scripts/generate-macro-names.mjs from @sasjs/sas-language.',
|
|
77
|
+
'// Do not edit. Regenerate with `npm run generate:macros`.',
|
|
78
|
+
'',
|
|
79
|
+
'/**',
|
|
80
|
+
' * The macro names that ship with SAS, lower-cased and without the leading',
|
|
81
|
+
' * `%`, as published in the macroStatements and macroFunctions groups of',
|
|
82
|
+
' * `@sasjs/sas-language`.',
|
|
83
|
+
' */',
|
|
84
|
+
'export const sasMacros: readonly string[] = [',
|
|
85
|
+
...names.map((name) => ` '${name}',`),
|
|
86
|
+
']',
|
|
87
|
+
''
|
|
88
|
+
].join('\n')
|
|
89
|
+
|
|
90
|
+
const main = async () => {
|
|
91
|
+
const names = await collectMacroNames()
|
|
92
|
+
await writeFile(TARGET, render(names))
|
|
93
|
+
console.log(
|
|
94
|
+
`written: src/utils/sasMacros.generated.ts (${names.length} names)`
|
|
95
|
+
)
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
main().catch((error) => {
|
|
99
|
+
console.error(`generation failed: ${error.message}`)
|
|
100
|
+
process.exit(1)
|
|
101
|
+
})
|
package/types/LintConfig.js
CHANGED
|
@@ -117,6 +117,15 @@ class LintConfig {
|
|
|
117
117
|
}
|
|
118
118
|
}
|
|
119
119
|
}
|
|
120
|
+
if (json === null || json === void 0 ? void 0 : json.noSingleAsteriskComments) {
|
|
121
|
+
this.fileLintRules.push(file_1.noSingleAsteriskComments);
|
|
122
|
+
}
|
|
123
|
+
if ((json === null || json === void 0 ? void 0 : json.noUndeclaredMacros) !== false) {
|
|
124
|
+
this.fileLintRules.push(file_1.noUndeclaredMacros);
|
|
125
|
+
}
|
|
126
|
+
if ((json === null || json === void 0 ? void 0 : json.noUnusedMacros) !== false) {
|
|
127
|
+
this.fileLintRules.push(file_1.noUnusedMacros);
|
|
128
|
+
}
|
|
120
129
|
if ((json === null || json === void 0 ? void 0 : json.noGremlins) !== false) {
|
|
121
130
|
this.lineLintRules.push(line_1.noGremlins);
|
|
122
131
|
if (json === null || json === void 0 ? void 0 : json.allowedGremlins) {
|
package/types/LintConfig.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"LintConfig.js","sourceRoot":"","sources":["../../src/types/LintConfig.ts"],"names":[],"mappings":";;;AAAA,
|
|
1
|
+
{"version":3,"file":"LintConfig.js","sourceRoot":"","sources":["../../src/types/LintConfig.ts"],"names":[],"mappings":";;;AAAA,wCAWsB;AACtB,wCAOsB;AACtB,wCAAuE;AACvE,+CAA2C;AAE3C,oCAA2C;AAC3C,yCAAqC;AAErC;;;;;;GAMG;AACH,MAAa,UAAU;IAerB,YAAY,IAAU;QAdb,eAAU,GAAa,EAAE,CAAA;QACzB,oBAAe,GAAa,EAAE,CAAA;QAC9B,kBAAa,GAAmB,EAAE,CAAA;QAClC,kBAAa,GAAmB,EAAE,CAAA;QAClC,kBAAa,GAAmB,EAAE,CAAA;QAClC,kBAAa,GAAW,EAAE,CAAA;QAC1B,wBAAmB,GAAW,EAAE,CAAA;QAChC,sBAAiB,GAAW,EAAE,CAAA;QAC9B,wBAAmB,GAAW,CAAC,CAAA;QAC/B,gBAAW,GAAgB,yBAAW,CAAC,EAAE,CAAA;QACzC,kBAAa,GAAW,IAAA,wBAAgB,GAAE,CAAA;QAC1C,kBAAa,GAAgC,EAAE,CAAA;QAC/C,yBAAoB,GAAa,EAAE,CAAA;QAG1C,IAAI,IAAI,aAAJ,IAAI,uBAAJ,IAAI,CAAE,UAAU,EAAE,CAAC;YACrB,IAAI,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,UAAU,CAAC,EAAE,CAAC;gBACnC,IAAI,CAAC,UAAU,CAAC,OAAO,CAAC,CAAC,IAAS,EAAE,EAAE;oBACpC,IAAI,OAAO,IAAI,KAAK,QAAQ;wBAAE,IAAI,CAAC,UAAU,CAAC,IAAI,CAAC,IAAI,CAAC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K,QAAQ,IAAI,kBAAkB,CAAC,IAAI,CAAC,IAAI,CAAC;4BAC3D,IAAI,CAAC,eAAe,CAAC,IAAI,CAAC,IAAI,CAAC,CAAA;;4BAE/B,MAAM,IAAI,KAAK,CACb,gIAAgI,CACjI,CAAA;oBACL,CAAC,CAAC,CAAA;gBACJ,CAAC;qBAAM,CAAC;oBACN,MAAM,IAAI,KAAK,CACb,wGAAwG,CACzG,CAAA;gBACH,CAAC;YACH,CAAC;QACH,CAAC;QAED,IAAI,IAAI,aAAJ,IAAI,uBAAJ,IAAI,CAAE,aAAa,EAAE,CAAC;YACxB,KAAK,MAAM,CAAC,IAAI,EAAE,QAAQ,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,IAAI,CAAC,aAAa,CAAC,EAAE,CAAC;gBAClE,IAAI,QAAQ,KAAK,MAAM;oBAAE,IAAI,CAAC,aAAa,CAAC,IAAI,CAAC,GAAG,mBAAQ,CAAC,OAAO,CAAA;gBACpE,IAAI,QAAQ,KAAK,OAAO;oBAAE,IAAI,CAAC,aAAa,CAAC,IAAI,CAAC,GAAG,mBAAQ,CAAC,KAAK,CAAA;YACrE,CAAC;QACH,CAAC;IACH,CAAC;CACF;AA3KD,gCA2KC"}
|
package/utils/getLintConfig.js
CHANGED
|
@@ -20,7 +20,7 @@ const LintConfig_1 = require("../types/LintConfig");
|
|
|
20
20
|
const file_1 = require("@sasjs/utils/file");
|
|
21
21
|
const getProjectRoot_1 = require("./getProjectRoot");
|
|
22
22
|
const LineEndings_1 = require("../types/LineEndings");
|
|
23
|
-
const getDefaultHeader = () => `/**{lineEnding} @file{lineEnding} @brief <Your brief here>{lineEnding} <h4> SAS Macros </h4>{lineEnding}**/`;
|
|
23
|
+
const getDefaultHeader = () => `/**{lineEnding} @file{lineEnding} @brief <Your brief here>{lineEnding}{lineEnding} <h4> SAS Macros </h4>{lineEnding}{lineEnding}**/`;
|
|
24
24
|
exports.getDefaultHeader = getDefaultHeader;
|
|
25
25
|
/**
|
|
26
26
|
* Default configuration that is used when a .sasjslint file is not found
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getLintConfig.js","sourceRoot":"","sources":["../../src/utils/getLintConfig.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAsCA,sCASC;AA/CD,gDAAuB;AACvB,4CAAmB;AACnB,oDAAgD;AAChD,4CAA4C;AAC5C,qDAAiD;AACjD,sDAAkD;AAE3C,MAAM,gBAAgB,GAAG,GAAG,EAAE,CACnC,
|
|
1
|
+
{"version":3,"file":"getLintConfig.js","sourceRoot":"","sources":["../../src/utils/getLintConfig.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAsCA,sCASC;AA/CD,gDAAuB;AACvB,4CAAmB;AACnB,oDAAgD;AAChD,4CAA4C;AAC5C,qDAAiD;AACjD,sDAAkD;AAE3C,MAAM,gBAAgB,GAAG,GAAG,EAAE,CACnC,wIAAwI,CAAA;AAD7H,QAAA,gBAAgB,oBAC6G;AAE1I;;GAEG;AACU,QAAA,wBAAwB,GAAG;IACtC,WAAW,EAAE,yBAAW,CAAC,GAAG;IAC5B,gBAAgB,EAAE,IAAI;IACtB,kBAAkB,EAAE,IAAI;IACxB,gBAAgB,EAAE,IAAI;IACtB,mBAAmB,EAAE,IAAI;IACzB,kBAAkB,EAAE,IAAI;IACxB,aAAa,EAAE,EAAE;IACjB,mBAAmB,EAAE,EAAE;IACvB,iBAAiB,EAAE,EAAE;IACrB,gBAAgB,EAAE,IAAI;IACtB,mBAAmB,EAAE,CAAC;IACtB,kBAAkB,EAAE,IAAI;IACxB,cAAc,EAAE,IAAI;IACpB,mBAAmB,EAAE,IAAI;IACzB,qBAAqB,EAAE,IAAI;IAC3B,UAAU,EAAE,IAAI;IAChB,aAAa,EAAE,IAAA,wBAAgB,GAAE;CAClC,CAAA;AAED;;;;GAIG;AACH,SAAsB,aAAa;;QACjC,MAAM,WAAW,GAAG,MAAM,IAAA,+BAAc,GAAE,CAAA;QAC1C,MAAM,gBAAgB,GAAG,WAAW,IAAI,YAAE,CAAC,OAAO,EAAE,CAAA;QACpD,MAAM,aAAa,GAAG,MAAM,IAAA,eAAQ,EAClC,cAAI,CAAC,IAAI,CAAC,gBAAgB,EAAE,YAAY,CAAC,CAC1C,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,EAAE;YACZ,OAAO,IAAI,CAAC,SAAS,CAAC,gCAAwB,CAAC,CAAA;QACjD,CAAC,CAAC,CAAA;QACF,OAAO,IAAI,uBAAU,CAAC,IAAI,CAAC,KAAK,CAAC,aAAa,CAAC,CAAC,CAAA;IAClD,CAAC;CAAA"}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { LintConfig } from '../types';
|
|
2
|
+
/**
|
|
3
|
+
* A macro that is declared in the header of a file, along with the position of
|
|
4
|
+
* its `@li` entry.
|
|
5
|
+
*/
|
|
6
|
+
export interface HeaderMacro {
|
|
7
|
+
name: string;
|
|
8
|
+
lineNumber: number;
|
|
9
|
+
startColumnNumber: number;
|
|
10
|
+
endColumnNumber: number;
|
|
11
|
+
section: 'sasMacros' | 'otherMacros';
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Reads the macros declared in the header of a file - both the
|
|
15
|
+
* `<h4> SAS Macros </h4>` and the `<h4> Other Macros </h4>` sections.
|
|
16
|
+
* @param {string} text - the text content of the file.
|
|
17
|
+
* @param {LintConfig} config - the lint configuration, used for line endings.
|
|
18
|
+
* @returns {HeaderMacro[]} the declared macros, in the order they appear.
|
|
19
|
+
*/
|
|
20
|
+
export declare const getHeaderMacros: (text: string, config?: LintConfig) => HeaderMacro[];
|
|
21
|
+
/**
|
|
22
|
+
* Adds macro names to the `<h4> SAS Macros </h4>` section of a file header,
|
|
23
|
+
* merging them with the entries that are already listed, de-duplicating by
|
|
24
|
+
* name, and sorting the result alphabetically. A new section is added when the
|
|
25
|
+
* header has none.
|
|
26
|
+
*
|
|
27
|
+
* A blank line separates the section from the header content before it and from
|
|
28
|
+
* whatever follows the list, so the section reads as its own block.
|
|
29
|
+
*
|
|
30
|
+
* @param {string} text - the text content of the file.
|
|
31
|
+
* @param {LintConfig} config - the lint configuration, used for line endings.
|
|
32
|
+
* @param {string[]} macros - the macro names to add.
|
|
33
|
+
* @returns {string} the updated text content.
|
|
34
|
+
*/
|
|
35
|
+
export declare const addMacrosToHeader: (text: string, config: LintConfig, macros: string[]) => string;
|
|
36
|
+
/**
|
|
37
|
+
* Removes macro names from the `<h4> SAS Macros </h4>` section of a file
|
|
38
|
+
* header. The section header itself is kept, so an empty list remains a valid
|
|
39
|
+
* place for the formatter to add entries. The blank line before the section and
|
|
40
|
+
* after the list is preserved.
|
|
41
|
+
*
|
|
42
|
+
* The file is returned unchanged when it has no Doxygen header, when the header
|
|
43
|
+
* has no `SAS Macros` section, when the section cannot be rewritten safely, or
|
|
44
|
+
* when none of the named macros are listed.
|
|
45
|
+
*
|
|
46
|
+
* @param {string} text - the text content of the file.
|
|
47
|
+
* @param {LintConfig} config - the lint configuration, used for line endings.
|
|
48
|
+
* @param {string[]} macros - the macro names to remove.
|
|
49
|
+
* @returns {string} the updated text content.
|
|
50
|
+
*/
|
|
51
|
+
export declare const removeMacrosFromHeader: (text: string, config: LintConfig, macros: string[]) => string;
|