@sap/eslint-plugin-cds 2.3.4 → 2.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.
- package/CHANGELOG.md +40 -0
- package/lib/api/index.js +9 -8
- package/lib/conf/all.js +21 -0
- package/lib/conf/index.js +22 -0
- package/lib/conf/recommended.js +18 -0
- package/lib/constants.js +10 -8
- package/lib/index.js +11 -32
- package/lib/parser.js +158 -7
- package/lib/rules/assoc2many-ambiguous-key.js +21 -38
- package/lib/rules/auth-no-empty-restrictions.js +37 -0
- package/lib/rules/auth-use-requires.js +38 -0
- package/lib/rules/auth-valid-restrict-grant.js +105 -0
- package/lib/rules/auth-valid-restrict-keys.js +43 -0
- package/lib/rules/auth-valid-restrict-to.js +130 -0
- package/lib/rules/auth-valid-restrict-where.js +89 -0
- package/lib/rules/index.js +26 -0
- package/lib/rules/latest-cds-version.js +8 -7
- package/lib/rules/min-node-version.js +10 -9
- package/lib/rules/no-db-keywords.js +16 -17
- package/lib/rules/no-dollar-prefixed-names.js +7 -33
- package/lib/rules/no-join-on-draft-enabled-entities.js +9 -24
- package/lib/rules/require-2many-oncond.js +9 -14
- package/lib/rules/sql-cast-suggestion.js +6 -20
- package/lib/rules/start-elements-lowercase.js +7 -10
- package/lib/rules/start-entities-uppercase.js +6 -9
- package/lib/rules/valid-csv-header.js +66 -66
- package/lib/{api/lint.d.ts → types.d.ts} +4 -7
- package/lib/utils/Cache.js +33 -0
- package/lib/utils/Colors.js +9 -0
- package/lib/utils/createRule.js +304 -0
- package/lib/utils/createRuleDocs.js +361 -0
- package/lib/utils/{fuzzySearch.js → findFuzzy.js} +9 -4
- package/lib/utils/genDocs.js +363 -0
- package/lib/utils/getConfigPath.js +33 -0
- package/lib/utils/getConfiguredFileTypes.js +10 -0
- package/lib/utils/getFileExtensions.js +8 -0
- package/lib/utils/isConfiguredFileType.js +20 -0
- package/lib/utils/jsonc.js +1 -1
- package/lib/utils/jsoncParser.js +1 -0
- package/lib/utils/rules.js +85 -945
- package/lib/utils/runRuleTester.js +111 -0
- package/package.json +8 -5
- package/lib/processor.js +0 -47
- package/lib/utils/helpers.js +0 -47
- package/lib/utils/model.js +0 -387
- package/lib/utils/ruleHelpers.js +0 -56
- package/lib/utils/ruleTester.js +0 -79
- package/lib/utils/validate.js +0 -36
package/lib/utils/ruleTester.js
DELETED
|
@@ -1,79 +0,0 @@
|
|
|
1
|
-
const fs = require("fs");
|
|
2
|
-
const path = require("path");
|
|
3
|
-
|
|
4
|
-
const { RuleTester } = require("eslint");
|
|
5
|
-
const { Cache, initModelRuleTester } = require("./model");
|
|
6
|
-
const { createRule, getRules } = require("./rules");
|
|
7
|
-
const { isValidFile } = require("./helpers");
|
|
8
|
-
|
|
9
|
-
module.exports = {
|
|
10
|
-
/**
|
|
11
|
-
* ESLint RuleTester (used by custom rule creator api)
|
|
12
|
-
* Calls ESLint's RuleTester with custom cds parser and input for
|
|
13
|
-
* valid/invalid checks:
|
|
14
|
-
* Model checks require input 'code' entries
|
|
15
|
-
* Env checks require input 'options' with selected parameters
|
|
16
|
-
* @param {CDSRuleTestOpts} options RuleTester input options
|
|
17
|
-
* @returns RuleTester results
|
|
18
|
-
*/
|
|
19
|
-
runRuleTester: function(options) {
|
|
20
|
-
let parser;
|
|
21
|
-
let rule = {};
|
|
22
|
-
const rulename = path.basename(options.root);
|
|
23
|
-
const plugin = "eslint-plugin-cds";
|
|
24
|
-
if (options.root.includes(plugin)) {
|
|
25
|
-
// For plugin's internal tests, resolve parser from here
|
|
26
|
-
parser = require.resolve("../parser");
|
|
27
|
-
const pluginPath = path.join(path.dirname(options.root), "../..");
|
|
28
|
-
rule = createRule(require(`../rules/${path.basename(options.root)}`));
|
|
29
|
-
Cache.set(
|
|
30
|
-
"rulesInfo",
|
|
31
|
-
getRules(path.join(path.dirname(options.root), "../../lib/rules"), rulename)
|
|
32
|
-
);
|
|
33
|
-
Cache.set("pluginpath", pluginPath);
|
|
34
|
-
} else {
|
|
35
|
-
// Otherwise from project root
|
|
36
|
-
const resolvedPlugin = require.resolve("@sap/eslint-plugin-cds", {
|
|
37
|
-
paths: [options.root],
|
|
38
|
-
});
|
|
39
|
-
parser = path.join(path.dirname(resolvedPlugin), "parser");
|
|
40
|
-
rule = require(path.join(
|
|
41
|
-
options.root,
|
|
42
|
-
`../../rules/${path.basename(options.root)}`
|
|
43
|
-
));
|
|
44
|
-
const pluginPath = path.join(path.dirname(options.root), "../../../..");
|
|
45
|
-
Cache.set("rulesInfo", getRules(path.join(options.root, "../../rules", rulename)));
|
|
46
|
-
Cache.set("pluginpath", pluginPath);
|
|
47
|
-
}
|
|
48
|
-
let tester = new RuleTester({});
|
|
49
|
-
if (parser) {
|
|
50
|
-
tester = new RuleTester({ parser });
|
|
51
|
-
}
|
|
52
|
-
const testerCases = {};
|
|
53
|
-
["valid", "invalid"].forEach((type) => {
|
|
54
|
-
const filePath = path.join(options.root, `${type}/${options.filename}`);
|
|
55
|
-
const model = initModelRuleTester(filePath);
|
|
56
|
-
testerCases[type] = [
|
|
57
|
-
{
|
|
58
|
-
filename: filePath,
|
|
59
|
-
},
|
|
60
|
-
];
|
|
61
|
-
if (!isValidFile(options.filename, 'FILES')) {
|
|
62
|
-
const fileContents = JSON.parse(fs.readFileSync(filePath, "utf8"));
|
|
63
|
-
testerCases[type][0].code = "";
|
|
64
|
-
testerCases[type][0].options = [{ environment: fileContents }];
|
|
65
|
-
} else {
|
|
66
|
-
testerCases[type][0].code = fs.readFileSync(filePath, "utf8");
|
|
67
|
-
testerCases[type][0].options = [{ model }];
|
|
68
|
-
}
|
|
69
|
-
if (type === "invalid") {
|
|
70
|
-
testerCases[type][0].errors = options.errors;
|
|
71
|
-
const fileFixed = path.join(options.root, `fixed/${options.filename}`);
|
|
72
|
-
if (fs.existsSync(fileFixed) && rule.meta.type !== "suggestion") {
|
|
73
|
-
testerCases[type][0].output = fs.readFileSync(fileFixed, "utf8");
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
});
|
|
77
|
-
return tester.run(rulename, rule, testerCases);
|
|
78
|
-
}
|
|
79
|
-
}
|
package/lib/utils/validate.js
DELETED
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @typedef { import("eslint").Rule.RuleContext.options } ContextOptions
|
|
3
|
-
*/
|
|
4
|
-
|
|
5
|
-
module.exports = {
|
|
6
|
-
/**
|
|
7
|
-
* Checks whether the rule name is valid (i.e. is contained within
|
|
8
|
-
* the plugin's or user's *custom* rules).
|
|
9
|
-
* @param context
|
|
10
|
-
* @param pluginRules
|
|
11
|
-
* @param customRules
|
|
12
|
-
* @returns
|
|
13
|
-
*/
|
|
14
|
-
isValidRule: function (context, rules) {
|
|
15
|
-
if (rules.includes(context.id.replace("@sap/cds/", ""))) {
|
|
16
|
-
return true;
|
|
17
|
-
}
|
|
18
|
-
return false;
|
|
19
|
-
},
|
|
20
|
-
|
|
21
|
-
/**
|
|
22
|
-
* Checks whether a cds model is error-free
|
|
23
|
-
* @param context cds context object
|
|
24
|
-
* @returns
|
|
25
|
-
*/
|
|
26
|
-
isValidModel: function (context) {
|
|
27
|
-
const cds = context.cds;
|
|
28
|
-
if (cds) {
|
|
29
|
-
if (cds.model) {
|
|
30
|
-
return !cds.model.err;
|
|
31
|
-
}
|
|
32
|
-
return true; // allow no model
|
|
33
|
-
}
|
|
34
|
-
return false;
|
|
35
|
-
}
|
|
36
|
-
};
|