@sap/eslint-plugin-cds 2.1.0 → 2.3.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/CHANGELOG.md +51 -1
- package/README.md +1 -1
- package/lib/api/formatter.js +165 -188
- package/lib/api/index.js +22 -7
- package/lib/impl/constants.js +5 -24
- package/lib/impl/index.js +53 -13
- package/lib/impl/parser.js +12 -4
- package/lib/impl/processor.js +23 -0
- package/lib/impl/ruleFactory.js +250 -272
- package/lib/impl/rules/assoc2many-ambiguous-key.js +158 -136
- package/lib/impl/rules/cds-compile-error.js +8 -20
- package/lib/impl/rules/latest-cds-version.js +39 -43
- package/lib/impl/rules/min-node-version.js +33 -44
- package/lib/impl/rules/no-db-keywords.js +28 -15
- package/lib/impl/rules/no-join-on-draft-enabled-entities.js +37 -0
- package/lib/impl/rules/require-2many-oncond.js +23 -31
- package/lib/impl/rules/rule.hbs +16 -22
- package/lib/impl/rules/sql-cast-suggestion.js +40 -43
- package/lib/impl/rules/start-elements-lowercase.js +60 -54
- package/lib/impl/rules/start-entities-uppercase.js +44 -54
- package/lib/impl/rules/valid-csv-header.js +92 -0
- package/lib/impl/types.d.ts +48 -0
- package/lib/impl/utils/fuzzySearch.js +87 -0
- package/lib/impl/utils/helpers.js +32 -9
- package/lib/impl/utils/model.js +326 -172
- package/lib/impl/utils/rules.js +472 -251
- package/lib/impl/utils/validate.js +52 -0
- package/package.json +2 -2
- package/lib/impl/rules/index.js +0 -5
- package/lib/impl/rules/test.hbs +0 -10
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Levenshtein distance algorithm using recursive calls and cache
|
|
3
|
+
*
|
|
4
|
+
* @param input search the list for a best match for this string
|
|
5
|
+
* @param list a list of strings to match input against
|
|
6
|
+
* @param log logging method to use, might be null if no logging is wanted
|
|
7
|
+
* @returns array with best matches, is never null but might be empty in case no search was possible
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
const cache = {};
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
module.exports = (input, list, log) => {
|
|
15
|
+
let minDistWords = [];
|
|
16
|
+
|
|
17
|
+
if (input.length > 50 || list.length > 50) {
|
|
18
|
+
return minDistWords;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
let minDist = Number.MAX_SAFE_INTEGER;
|
|
22
|
+
|
|
23
|
+
log && log('\nword\t\tlevDist\t\ttime(ms)');
|
|
24
|
+
|
|
25
|
+
let runtime = 0;
|
|
26
|
+
|
|
27
|
+
for (const word of list) {
|
|
28
|
+
const start = log && Date.now();
|
|
29
|
+
const levDist = levDistance(input, word);
|
|
30
|
+
|
|
31
|
+
if (log) {
|
|
32
|
+
const duration = Date.now() - start;
|
|
33
|
+
runtime = runtime + duration;
|
|
34
|
+
log(`${word}\t\t${levDist}\t\t${duration}`);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
if (levDist === minDist) {
|
|
38
|
+
minDistWords.push(word);
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
if (levDist < minDist) {
|
|
42
|
+
minDist = levDist;
|
|
43
|
+
minDistWords = [word];
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
log && log(`runtime: ${runtime}ms`);
|
|
48
|
+
|
|
49
|
+
return minDistWords.sort();
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
const levDistance = (a, b) => {
|
|
54
|
+
|
|
55
|
+
if (cache[a] && cache[a][b]) {
|
|
56
|
+
return cache[a][b];
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
if (a.length === 0) {
|
|
60
|
+
return addToCache(a, b, b.length);
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
if (b.length === 0) {
|
|
64
|
+
return addToCache(a, b, a.length);
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
const tail_a = a.substring(1);
|
|
68
|
+
const tail_b = b.substring(1);
|
|
69
|
+
|
|
70
|
+
if (a[0] === b[0]) {
|
|
71
|
+
return levDistance(tail_a, tail_b);
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
const lev1 = levDistance(tail_a, b);
|
|
75
|
+
const lev2 = levDistance(a, tail_b);
|
|
76
|
+
const lev3 = levDistance(tail_a, tail_b);
|
|
77
|
+
|
|
78
|
+
const levDist = Math.min(lev1, lev2, lev3) + 1;
|
|
79
|
+
return addToCache(a, b, levDist);
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
|
|
83
|
+
const addToCache = (a, b, value) => {
|
|
84
|
+
cache[a] = cache[a] || {};
|
|
85
|
+
cache[a][b] = value;
|
|
86
|
+
return value;
|
|
87
|
+
}
|
|
@@ -1,17 +1,32 @@
|
|
|
1
|
+
const { files, envFiles, modelFiles } = require("../constants");
|
|
2
|
+
|
|
1
3
|
module.exports = {
|
|
4
|
+
|
|
2
5
|
/**
|
|
3
|
-
* Checks whether
|
|
6
|
+
* Checks whether the given file path contains a file extension allowed by
|
|
7
|
+
* the plugin
|
|
8
|
+
* @param {string} filePath
|
|
4
9
|
* @returns boolean
|
|
5
10
|
*/
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
11
|
+
isValidFile: function (filePath, key = "") {
|
|
12
|
+
function genRegex(key) {
|
|
13
|
+
return new RegExp(
|
|
14
|
+
`${key
|
|
15
|
+
.map((file) => {
|
|
16
|
+
return file.replace("*", "");
|
|
17
|
+
})
|
|
18
|
+
.join("$|")}$`
|
|
19
|
+
);
|
|
20
|
+
}
|
|
21
|
+
if (key === "model") {
|
|
22
|
+
return genRegex(modelFiles).test(filePath);
|
|
23
|
+
} else if (key === "env") {
|
|
24
|
+
return genRegex(envFiles).test(filePath);
|
|
25
|
+
} else {
|
|
26
|
+
return genRegex(files).test(filePath);
|
|
10
27
|
}
|
|
11
|
-
return isTest;
|
|
12
28
|
},
|
|
13
29
|
|
|
14
|
-
|
|
15
30
|
/**
|
|
16
31
|
* Checks whether the plugin is run via the VS Code ESLint extension (editor)
|
|
17
32
|
* @returns boolean
|
|
@@ -21,7 +36,16 @@ module.exports = {
|
|
|
21
36
|
},
|
|
22
37
|
|
|
23
38
|
/**
|
|
24
|
-
*
|
|
39
|
+
* Returns an array of allowed file extensions
|
|
40
|
+
* the plugin can parse of the form "*.ext"
|
|
41
|
+
* @returns {ConfigOverrideFiles} Array of file extensions
|
|
42
|
+
*/
|
|
43
|
+
getFileExtensions: function () {
|
|
44
|
+
return files;
|
|
45
|
+
},
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* Prints a formatted message string according to the styles provided
|
|
25
49
|
* @param msg message to print
|
|
26
50
|
* @param styles array of styles for apply
|
|
27
51
|
* @returns
|
|
@@ -41,5 +65,4 @@ module.exports = {
|
|
|
41
65
|
});
|
|
42
66
|
return `${msgStyle}${msg}${types.reset}`;
|
|
43
67
|
},
|
|
44
|
-
|
|
45
68
|
};
|