@sasjs/lint 2.7.0 → 4.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/README.md +60 -5
- package/format/formatFile.js +2 -1
- package/format/formatFile.js.map +1 -1
- package/format/formatText.js +1 -1
- package/format/formatText.js.map +1 -1
- package/lint/lintFile.js +3 -2
- package/lint/lintFile.js.map +1 -1
- package/lint/lintText.js +1 -1
- package/lint/lintText.js.map +1 -1
- package/package.json +3 -1
- package/rules/file/index.d.ts +2 -0
- package/rules/file/index.js +5 -1
- package/rules/file/index.js.map +1 -1
- 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 +51 -15
- package/scripts/generate-macro-names.mjs +101 -0
- package/types/LintConfig.d.ts +13 -0
- package/types/LintConfig.js +37 -15
- package/types/LintConfig.js.map +1 -1
- package/utils/getLintConfig.d.ts +26 -13
- package/utils/getLintConfig.js +28 -15
- 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 +5 -0
- package/utils/index.js +5 -0
- package/utils/index.js.map +1 -1
- package/utils/mergeLintConfig.d.ts +10 -0
- package/utils/mergeLintConfig.js +67 -0
- package/utils/mergeLintConfig.js.map +1 -0
- package/utils/parseLintOverride.d.ts +36 -0
- package/utils/parseLintOverride.js +109 -0
- package/utils/parseLintOverride.js.map +1 -0
- 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
|
@@ -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.d.ts
CHANGED
|
@@ -9,6 +9,8 @@ import { Severity } from './Severity';
|
|
|
9
9
|
* More types of rules, when available, will be added here.
|
|
10
10
|
*/
|
|
11
11
|
export declare class LintConfig {
|
|
12
|
+
/** The JSON this configuration was built from, so it can be overridden. */
|
|
13
|
+
readonly source: any;
|
|
12
14
|
readonly ignoreList: string[];
|
|
13
15
|
readonly allowedGremlins: string[];
|
|
14
16
|
readonly lineLintRules: LineLintRule[];
|
|
@@ -25,4 +27,15 @@ export declare class LintConfig {
|
|
|
25
27
|
};
|
|
26
28
|
readonly requiredMacroOptions: string[];
|
|
27
29
|
constructor(json?: any);
|
|
30
|
+
/**
|
|
31
|
+
* Returns a new configuration with an override merged over this one, so a
|
|
32
|
+
* file can adjust the rules that apply to it.
|
|
33
|
+
*
|
|
34
|
+
* Scalars replace, arrays are additive and objects merge key by key - see
|
|
35
|
+
* `mergeLintConfig`.
|
|
36
|
+
*
|
|
37
|
+
* @param {object} json - the override, as read from a `@sasjslint` block.
|
|
38
|
+
* @returns {LintConfig} a new configuration; this one is unchanged.
|
|
39
|
+
*/
|
|
40
|
+
override(json: any): LintConfig;
|
|
28
41
|
}
|
package/types/LintConfig.js
CHANGED
|
@@ -6,6 +6,7 @@ const line_1 = require("../rules/line");
|
|
|
6
6
|
const path_1 = require("../rules/path");
|
|
7
7
|
const LineEndings_1 = require("./LineEndings");
|
|
8
8
|
const utils_1 = require("../utils");
|
|
9
|
+
const mergeLintConfig_1 = require("../utils/mergeLintConfig");
|
|
9
10
|
const Severity_1 = require("./Severity");
|
|
10
11
|
/**
|
|
11
12
|
* LintConfig is the logical representation of the .sasjslint file.
|
|
@@ -29,6 +30,7 @@ class LintConfig {
|
|
|
29
30
|
this.defaultHeader = (0, utils_1.getDefaultHeader)();
|
|
30
31
|
this.severityLevel = {};
|
|
31
32
|
this.requiredMacroOptions = [];
|
|
33
|
+
this.source = json !== null && json !== void 0 ? json : {};
|
|
32
34
|
if (json === null || json === void 0 ? void 0 : json.ignoreList) {
|
|
33
35
|
if (Array.isArray(json.ignoreList)) {
|
|
34
36
|
json.ignoreList.forEach((item) => {
|
|
@@ -52,9 +54,13 @@ class LintConfig {
|
|
|
52
54
|
if ((json === null || json === void 0 ? void 0 : json.noTabs) === false || (json === null || json === void 0 ? void 0 : json.noTabIndentation) === false) {
|
|
53
55
|
this.lineLintRules.pop();
|
|
54
56
|
}
|
|
55
|
-
|
|
57
|
+
// An absent setting falls back to the default, so the rule is on unless the
|
|
58
|
+
// value switches it off (0 or a negative number).
|
|
59
|
+
if ((json === null || json === void 0 ? void 0 : json.maxLineLength) === undefined || (json === null || json === void 0 ? void 0 : json.maxLineLength) > 0) {
|
|
56
60
|
this.lineLintRules.push(line_1.maxLineLength);
|
|
57
|
-
|
|
61
|
+
if (!isNaN(json === null || json === void 0 ? void 0 : json.maxLineLength)) {
|
|
62
|
+
this.maxLineLength = json.maxLineLength;
|
|
63
|
+
}
|
|
58
64
|
if (!isNaN(json === null || json === void 0 ? void 0 : json.maxHeaderLineLength)) {
|
|
59
65
|
this.maxHeaderLineLength = json.maxHeaderLineLength;
|
|
60
66
|
}
|
|
@@ -86,7 +92,7 @@ class LintConfig {
|
|
|
86
92
|
if ((json === null || json === void 0 ? void 0 : json.lowerCaseFileNames) !== false) {
|
|
87
93
|
this.pathLintRules.push(path_1.lowerCaseFileNames);
|
|
88
94
|
}
|
|
89
|
-
if (json === null || json === void 0 ? void 0 : json.hasMacroNameInMend) {
|
|
95
|
+
if ((json === null || json === void 0 ? void 0 : json.hasMacroNameInMend) !== false) {
|
|
90
96
|
this.fileLintRules.push(file_1.hasMacroNameInMend);
|
|
91
97
|
}
|
|
92
98
|
if ((json === null || json === void 0 ? void 0 : json.noNestedMacros) !== false) {
|
|
@@ -101,25 +107,28 @@ class LintConfig {
|
|
|
101
107
|
if (json === null || json === void 0 ? void 0 : json.hasRequiredMacroOptions) {
|
|
102
108
|
this.fileLintRules.push(file_1.hasRequiredMacroOptions);
|
|
103
109
|
if (json === null || json === void 0 ? void 0 : json.requiredMacroOptions) {
|
|
104
|
-
if (Array.isArray(json.requiredMacroOptions)
|
|
105
|
-
json.requiredMacroOptions.length > 0) {
|
|
106
|
-
json.requiredMacroOptions.forEach((item) => {
|
|
107
|
-
if (typeof item === 'string') {
|
|
108
|
-
this.requiredMacroOptions.push(item);
|
|
109
|
-
}
|
|
110
|
-
else {
|
|
111
|
-
throw new Error(`Property "requiredMacroOptions" has invalid type of values. It can only contain strings.`);
|
|
112
|
-
}
|
|
113
|
-
});
|
|
114
|
-
}
|
|
115
|
-
else {
|
|
110
|
+
if (!Array.isArray(json.requiredMacroOptions)) {
|
|
116
111
|
throw new Error(`Property "requiredMacroOptions" can only be an array of strings.`);
|
|
117
112
|
}
|
|
113
|
+
json.requiredMacroOptions.forEach((item) => {
|
|
114
|
+
if (typeof item === 'string') {
|
|
115
|
+
this.requiredMacroOptions.push(item);
|
|
116
|
+
}
|
|
117
|
+
else {
|
|
118
|
+
throw new Error(`Property "requiredMacroOptions" has invalid type of values. It can only contain strings.`);
|
|
119
|
+
}
|
|
120
|
+
});
|
|
118
121
|
}
|
|
119
122
|
}
|
|
120
123
|
if (json === null || json === void 0 ? void 0 : json.noSingleAsteriskComments) {
|
|
121
124
|
this.fileLintRules.push(file_1.noSingleAsteriskComments);
|
|
122
125
|
}
|
|
126
|
+
if ((json === null || json === void 0 ? void 0 : json.noUndeclaredMacros) !== false) {
|
|
127
|
+
this.fileLintRules.push(file_1.noUndeclaredMacros);
|
|
128
|
+
}
|
|
129
|
+
if ((json === null || json === void 0 ? void 0 : json.noUnusedMacros) !== false) {
|
|
130
|
+
this.fileLintRules.push(file_1.noUnusedMacros);
|
|
131
|
+
}
|
|
123
132
|
if ((json === null || json === void 0 ? void 0 : json.noGremlins) !== false) {
|
|
124
133
|
this.lineLintRules.push(line_1.noGremlins);
|
|
125
134
|
if (json === null || json === void 0 ? void 0 : json.allowedGremlins) {
|
|
@@ -145,6 +154,19 @@ class LintConfig {
|
|
|
145
154
|
}
|
|
146
155
|
}
|
|
147
156
|
}
|
|
157
|
+
/**
|
|
158
|
+
* Returns a new configuration with an override merged over this one, so a
|
|
159
|
+
* file can adjust the rules that apply to it.
|
|
160
|
+
*
|
|
161
|
+
* Scalars replace, arrays are additive and objects merge key by key - see
|
|
162
|
+
* `mergeLintConfig`.
|
|
163
|
+
*
|
|
164
|
+
* @param {object} json - the override, as read from a `@sasjslint` block.
|
|
165
|
+
* @returns {LintConfig} a new configuration; this one is unchanged.
|
|
166
|
+
*/
|
|
167
|
+
override(json) {
|
|
168
|
+
return new LintConfig((0, mergeLintConfig_1.mergeLintConfig)(this.source, json));
|
|
169
|
+
}
|
|
148
170
|
}
|
|
149
171
|
exports.LintConfig = LintConfig;
|
|
150
172
|
//# sourceMappingURL=LintConfig.js.map
|
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,8DAA0D;AAC1D,yCAAqC;AAErC;;;;;;GAMG;AACH,MAAa,UAAU;IAiBrB,YAAY,IAAU;QAdb,eAAU,GAAa,EAAE,CAAA;QACzB,oBA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ACH,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;IAED;;;;;;;;;OASG;IACH,QAAQ,CAAC,IAAS;QAChB,OAAO,IAAI,UAAU,CAAC,IAAA,iCAAe,EAAC,IAAI,CAAC,MAAM,EAAE,IAAI,CAAC,CAAC,CAAA;IAC3D,CAAC;CACF;AA/LD,gCA+LC"}
|
package/utils/getLintConfig.d.ts
CHANGED
|
@@ -2,26 +2,39 @@ import { LintConfig } from '../types/LintConfig';
|
|
|
2
2
|
import { LineEndings } from '../types/LineEndings';
|
|
3
3
|
export declare const getDefaultHeader: () => string;
|
|
4
4
|
/**
|
|
5
|
-
* Default configuration that is used when a .sasjslint file is not found
|
|
5
|
+
* Default configuration that is used when a .sasjslint file is not found.
|
|
6
|
+
*
|
|
7
|
+
* It lists every setting the linter reads, with its default value, so it
|
|
8
|
+
* doubles as the reference for the `.sasjslint` file. `getLintConfig.spec.ts`
|
|
9
|
+
* enumerates the settings the config reads and fails if this object misses one,
|
|
10
|
+
* and the README mirrors it.
|
|
6
11
|
*/
|
|
7
12
|
export declare const DefaultLintConfiguration: {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
noEncodedPasswords: boolean;
|
|
13
|
+
allowedGremlins: never[];
|
|
14
|
+
defaultHeader: string;
|
|
11
15
|
hasDoxygenHeader: boolean;
|
|
12
|
-
|
|
16
|
+
hasMacroNameInMend: boolean;
|
|
17
|
+
hasMacroParentheses: boolean;
|
|
18
|
+
hasRequiredMacroOptions: boolean;
|
|
19
|
+
ignoreList: never[];
|
|
20
|
+
indentationMultiple: number;
|
|
21
|
+
lineEndings: LineEndings;
|
|
13
22
|
lowerCaseFileNames: boolean;
|
|
14
|
-
maxLineLength: number;
|
|
15
|
-
maxHeaderLineLength: number;
|
|
16
23
|
maxDataLineLength: number;
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
24
|
+
maxHeaderLineLength: number;
|
|
25
|
+
maxLineLength: number;
|
|
26
|
+
noEncodedPasswords: boolean;
|
|
27
|
+
noGremlins: boolean;
|
|
20
28
|
noNestedMacros: boolean;
|
|
21
|
-
|
|
29
|
+
noSingleAsteriskComments: boolean;
|
|
30
|
+
noSpacesInFileNames: boolean;
|
|
31
|
+
noTabs: boolean;
|
|
32
|
+
noTrailingSpaces: boolean;
|
|
33
|
+
noUndeclaredMacros: boolean;
|
|
34
|
+
noUnusedMacros: boolean;
|
|
35
|
+
requiredMacroOptions: never[];
|
|
36
|
+
severityLevel: {};
|
|
22
37
|
strictMacroDefinition: boolean;
|
|
23
|
-
noGremlins: boolean;
|
|
24
|
-
defaultHeader: string;
|
|
25
38
|
};
|
|
26
39
|
/**
|
|
27
40
|
* Fetches the config from the .sasjslint file (at project root or home directory) and creates a LintConfig object.
|
package/utils/getLintConfig.js
CHANGED
|
@@ -20,29 +20,42 @@ 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
|
-
* Default configuration that is used when a .sasjslint file is not found
|
|
26
|
+
* Default configuration that is used when a .sasjslint file is not found.
|
|
27
|
+
*
|
|
28
|
+
* It lists every setting the linter reads, with its default value, so it
|
|
29
|
+
* doubles as the reference for the `.sasjslint` file. `getLintConfig.spec.ts`
|
|
30
|
+
* enumerates the settings the config reads and fails if this object misses one,
|
|
31
|
+
* and the README mirrors it.
|
|
27
32
|
*/
|
|
28
33
|
exports.DefaultLintConfiguration = {
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
noEncodedPasswords: true,
|
|
34
|
+
allowedGremlins: [],
|
|
35
|
+
defaultHeader: (0, exports.getDefaultHeader)(),
|
|
32
36
|
hasDoxygenHeader: true,
|
|
33
|
-
noSpacesInFileNames: true,
|
|
34
|
-
lowerCaseFileNames: true,
|
|
35
|
-
maxLineLength: 80,
|
|
36
|
-
maxHeaderLineLength: 80,
|
|
37
|
-
maxDataLineLength: 80,
|
|
38
|
-
noTabIndentation: true,
|
|
39
|
-
indentationMultiple: 2,
|
|
40
37
|
hasMacroNameInMend: true,
|
|
41
|
-
noNestedMacros: true,
|
|
42
38
|
hasMacroParentheses: true,
|
|
43
|
-
|
|
39
|
+
hasRequiredMacroOptions: false,
|
|
40
|
+
ignoreList: [],
|
|
41
|
+
indentationMultiple: 2,
|
|
42
|
+
lineEndings: LineEndings_1.LineEndings.OFF,
|
|
43
|
+
lowerCaseFileNames: true,
|
|
44
|
+
maxDataLineLength: 80,
|
|
45
|
+
maxHeaderLineLength: 80,
|
|
46
|
+
maxLineLength: 80,
|
|
47
|
+
noEncodedPasswords: true,
|
|
44
48
|
noGremlins: true,
|
|
45
|
-
|
|
49
|
+
noNestedMacros: true,
|
|
50
|
+
noSingleAsteriskComments: false,
|
|
51
|
+
noSpacesInFileNames: true,
|
|
52
|
+
noTabs: true,
|
|
53
|
+
noTrailingSpaces: true,
|
|
54
|
+
noUndeclaredMacros: true,
|
|
55
|
+
noUnusedMacros: true,
|
|
56
|
+
requiredMacroOptions: [],
|
|
57
|
+
severityLevel: {},
|
|
58
|
+
strictMacroDefinition: true
|
|
46
59
|
};
|
|
47
60
|
/**
|
|
48
61
|
* Fetches the config from the .sasjslint file (at project root or home directory) and creates a LintConfig object.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getLintConfig.js","sourceRoot":"","sources":["../../src/utils/getLintConfig.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;
|
|
1
|
+
{"version":3,"file":"getLintConfig.js","sourceRoot":"","sources":["../../src/utils/getLintConfig.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAmDA,sCASC;AA5DD,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;;;;;;;GAOG;AACU,QAAA,wBAAwB,GAAG;IACtC,eAAe,EAAE,EAAE;IACnB,aAAa,EAAE,IAAA,wBAAgB,GAAE;IACjC,gBAAgB,EAAE,IAAI;IACtB,kBAAkB,EAAE,IAAI;IACxB,mBAAmB,EAAE,IAAI;IACzB,uBAAuB,EAAE,KAAK;IAC9B,UAAU,EAAE,EAAE;IACd,mBAAmB,EAAE,CAAC;IACtB,WAAW,EAAE,yBAAW,CAAC,GAAG;IAC5B,kBAAkB,EAAE,IAAI;IACxB,iBAAiB,EAAE,EAAE;IACrB,mBAAmB,EAAE,EAAE;IACvB,aAAa,EAAE,EAAE;IACjB,kBAAkB,EAAE,IAAI;IACxB,UAAU,EAAE,IAAI;IAChB,cAAc,EAAE,IAAI;IACpB,wBAAwB,EAAE,KAAK;IAC/B,mBAAmB,EAAE,IAAI;IACzB,MAAM,EAAE,IAAI;IACZ,gBAAgB,EAAE,IAAI;IACtB,kBAAkB,EAAE,IAAI;IACxB,cAAc,EAAE,IAAI;IACpB,oBAAoB,EAAE,EAAE;IACxB,aAAa,EAAE,EAAE;IACjB,qBAAqB,EAAE,IAAI;CAC5B,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;
|