@sap/eslint-plugin-cds 2.0.4 → 2.2.1

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 CHANGED
@@ -6,9 +6,90 @@ This project adheres to [Semantic Versioning](http://semver.org/).
6
6
 
7
7
  The format is based on [Keep a Changelog](http://keepachangelog.com/).
8
8
 
9
+ ## [2.1.2] - 2021-10-05
10
+
11
+ ## Changed
12
+
13
+ - Allow not only *.js but also other file types (i.e. *.ts, etc) to bypass plugin rules
14
+
15
+ ## [2.1.1] - 2021-10-04
16
+
17
+ ## Changed
18
+
19
+ - Added preprocessor to avoid (other plugins) parsing errors on cds files
20
+
21
+ ## [2.2.0] - 2021-10-29
22
+
23
+ ## Added
24
+
25
+ - Added typings to javascript for all exposed apis
26
+
27
+ ## Changed
28
+
29
+ - Aligned rule creation and tester api with ESLint
30
+
31
+ ## [2.1.2] - 2021-10-05
32
+
33
+ ## Changed
34
+
35
+ - Allow not only *.js but also other file types (i.e. *.ts, etc) to bypass plugin rules
36
+
37
+ ## [2.1.1] - 2021-10-04
38
+
39
+ ## Changed
40
+
41
+ - Added preprocessor to avoid (other plugins) parsing errors on cds files
42
+
43
+ ## [2.2.1] - 2021-10-29
44
+
45
+ ## Changed
46
+
47
+ - Optimized model loading and fixed bug in loading of 'outsider' files
48
+
49
+ ## [2.2.0] - 2021-10-29
50
+
51
+ ## Added
52
+
53
+ - Added typings to javascript for all exposed apis
54
+
55
+ ## Changed
56
+
57
+ - Aligned rule creation and tester api with ESLint
58
+
59
+ ## [2.1.2] - 2021-10-05
60
+
61
+ ## Changed
62
+
63
+ - Allow not only *.js but also other file types (i.e. *.ts, etc) to bypass plugin rules
64
+
65
+ ## [2.1.1] - 2021-10-04
66
+
67
+ ## Changed
68
+
69
+ - Added preprocessor to avoid (other plugins) parsing errors on cds files
70
+
71
+ ## [2.1.0] - 2021-09-23
72
+
73
+ ## Changed
74
+
75
+ - Source code is now Javascript only
76
+ - Rule API simplified to only include report and cds
77
+ - Added new rules `no-db-keywords` and `require-2many-oncond`
78
+ - Filter out lint messages when run from command line with custom formatter
79
+
80
+ ## [2.0.5] - 2021-07-18
81
+
82
+
83
+ ### Added
84
+
85
+ - When used from within VS Code ESLint exnteion, do not show environment rules
86
+ ### Changed
87
+
88
+ - Rule 'min-node-version' reverted to use cds.resolve not cds.home
9
89
 
10
90
  ## [2.0.4] - 2021-07-12
11
91
 
92
+
12
93
  ### Added
13
94
 
14
95
  - Plugin also considers 'outsider' files which are not part of a model
@@ -191,4 +272,4 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/).
191
272
 
192
273
  ## [1.0.0] - 2020-12-07
193
274
 
194
- - Initial release 1.0.0
275
+ - Initial release 1.0.0
package/README.md CHANGED
@@ -1,7 +1,6 @@
1
1
  # @sap/eslint-plugin-cds
2
2
 
3
3
 
4
- The [ESLint](https://eslint.org) plugin includes a set of recommended [SAP Cloud Application Programming Model (CAP)](https://cap.cloud.sap) model and environment rules. The aim of CDS linting is to catch issues with CDS models and with the environment early.
4
+ The [ESLint](https://eslint.org) plugin includes a set of recommended [SAP Cloud Application Programming Model (CAP)](https://cap.cloud.sap) model and environment rules. The aim of CDS linting is to catch issues with CDS models and with the environment early. To use this module we recommend to install [@sap/cds-dk](https://www.npmjs.com/package/@sap/cds-dk) globally.
5
5
 
6
-
7
- <!-- See the [CDS Linting documentation](https://cap.cloud.sap/docs/get-started/tools/lint) for more details, or jump directly to a complete [list of rules](https://cap.cloud.sap/docs/get-started/tools/lint#rules). CAP provides a set of recommended rules. On top, you can create your own, application-specific rules. -->
6
+ See the [CDS Linting documentation](https://cap.cloud.sap/docs/tools/#cds-lint) for more details, or jump directly to a complete [list of rules](https://cap.cloud.sap/docs/tools/#cds-lint-rules). CAP provides a set of recommended rules. On top, you can create your own, application-specific rules.
@@ -1,132 +1,183 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
5
- }) : (function(o, m, k, k2) {
6
- if (k2 === undefined) k2 = k;
7
- o[k2] = m[k];
8
- }));
9
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
10
- Object.defineProperty(o, "default", { enumerable: true, value: v });
11
- }) : function(o, v) {
12
- o["default"] = v;
13
- });
14
- var __importStar = (this && this.__importStar) || function (mod) {
15
- if (mod && mod.__esModule) return mod;
16
- var result = {};
17
- if (mod != null) for (var k in mod) if (k !== "default" && Object.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
18
- __setModuleDefault(result, mod);
19
- return result;
20
- };
21
- const path = __importStar(require("path"));
22
- const CLIEngine = require("eslint").CLIEngine;
23
- const formatter = CLIEngine.getFormatter('stylish');
24
- const utils_1 = require("../impl/utils");
1
+ /**
2
+ * Custom ESLint formatter:
3
+ * https://eslint.org/docs/developer-guide/working-with-custom-formatters
4
+ * Here, we take the ESLint.LintResult[] and format it into ESLint's standard (stylish) error report.
5
+ * Then, we adapt it to report environment errors:
6
+ * - Separately from model errors
7
+ * - Report them within a project scope but independent of a specific file within that scope
8
+ */
9
+ const fs = require("fs");
10
+ const path = require("path");
11
+ const { CLIEngine } = require("eslint");
12
+ // Note: CliEngine depracted, but new Node API requires
13
+ // async Linter framework
14
+ const formatter = CLIEngine.getFormatter("stylish");
15
+ const { Cache } = require("../impl/utils/model");
16
+ const { styleText, isEditor, isTest } = require("../impl/utils/helpers");
17
+
18
+ const CONSTANTS = require("../impl/constants");
19
+
20
+ /* eslint-disable-next-line no-control-regex */
25
21
  const REGEX_STRIP_ANSI = /[\u001b\u009b][[()#;?]*(?:[0-9]{1,4}(?:;[0-9]{0,4})*)?[0-9A-ORZcf-nqry=><]/g;
26
22
  const REGEX_NEWLINE = /\r?\n/g;
27
- function getPluginRules(data) {
28
- const rules = { 'environment': [], 'model': [], 'recommended': [] };
29
- Object.keys(data.rulesMeta).forEach((rule) => {
30
- if (data.rulesMeta[rule]) {
31
- const category = data.rulesMeta[rule].docs.category;
32
- if (category === "Model Validation") {
33
- rules.model.push(rule);
34
- rules.recommended.push(rule);
35
- }
36
- else if (category === "Environment") {
37
- rules.environment.push(rule);
38
- rules.recommended.push(rule);
39
- }
23
+
24
+ let projects = Cache.getModels();
25
+
26
+ module.exports = function (results, data) {
27
+ let output = "";
28
+ // Get plugin ruleIDs
29
+ const rules = getPluginRules(data);
30
+ // Get ruleIDs from custom rules
31
+ const customRules = [];
32
+ projects.forEach((project) => {
33
+ const customRulesPath = path.resolve(project, CONSTANTS.customRulesDir, "rules");
34
+ if (fs.existsSync(customRulesPath)) {
35
+ fs.readdirSync(customRulesPath).forEach((customRule) => {
36
+ const ruleID = path.basename(customRule, ".js");
37
+ if (!customRules.includes(ruleID)) {
38
+ customRules.push(ruleID);
40
39
  }
41
- });
42
- return rules;
40
+ });
41
+ }
42
+ });
43
+ if (!Cache.has("err")) {
44
+ // Filter out error messages not from plugin or custom rules
45
+ if (!isEditor() && !isTest()) {
46
+ results.forEach((result) => {
47
+ result.messages = result.messages.filter(
48
+ (msg) =>
49
+ rules.model.includes(msg.ruleId) ||
50
+ rules.environment.includes(msg.ruleId) ||
51
+ customRules.includes(msg.ruleId)
52
+ );
53
+ });
54
+ }
55
+ // Get standard ESLint 'stylish' output
56
+ const outputStylish = formatter(results);
57
+
58
+ // Split according to category
59
+ const msgs = splitOutput(outputStylish, rules);
60
+
61
+ // Format new CDSLint output
62
+ output = formatOutput(output, msgs);
63
+ }
64
+ return output;
65
+ };
66
+
67
+ /**
68
+ * Splits rules by config and category
69
+ * @param data Rules meta data
70
+ * @returns rules object based on category
71
+ */
72
+ function getPluginRules(data) {
73
+ const rules = { environment: [], model: [], recommended: [] };
74
+ Object.keys(data.rulesMeta).forEach((rule) => {
75
+ if (data.rulesMeta[rule]) {
76
+ const category = data.rulesMeta[rule].docs.category;
77
+ if (category === CONSTANTS.categories.model) {
78
+ rules.model.push(rule);
79
+ rules.recommended.push(rule);
80
+ } else if (category === CONSTANTS.categories.env) {
81
+ rules.environment.push(rule);
82
+ rules.recommended.push(rule);
83
+ }
84
+ }
85
+ });
86
+ return rules;
43
87
  }
88
+
89
+ /**
90
+ * Obtains ESLint's standard (*stylish*) output, then splits and reccollects error messages
91
+ * based on rule category and content type (msg vs. error count/report)
92
+ * @param outputStylish ESLint's standard output
93
+ * @param rules Plugin rules based on category
94
+ * @returns Collected msgs
95
+ */
44
96
  function splitOutput(outputStylish, rules) {
45
- const msgs = { 'environment': {}, 'model': {}, 'report': [] };
46
- let projects = utils_1.Cache.getModels();
47
- let file = '';
48
- outputStylish.split(REGEX_NEWLINE).forEach((line) => {
49
- const lineStripped = line.replace(REGEX_STRIP_ANSI, '');
50
- const lineStrippedSplit = lineStripped.split(' ');
51
- const rule = lineStrippedSplit[lineStrippedSplit.length - 1];
52
- if (!lineStripped.startsWith(' ') && !rules.recommended.includes(rule) && !lineStripped.startsWith('✖')) {
53
- file = line;
54
- if (process.argv[1].includes('jest') || process.argv[1].includes('mocha')) {
55
- projects = [path.dirname(lineStripped)];
56
- }
57
- }
58
- else if (rules.environment.includes(rule)) {
59
- const delimiter = line.split(/ +/, 2)[1];
60
- const lineWithoutLocation = line.split(delimiter)[1];
61
- let project = '';
62
- for (let i = 0; i < projects.length; i++) {
63
- project = projects[i];
64
- if (file.includes(project)) {
65
- project = utils_1.styleText(project, ['link']);
66
- break;
67
- }
68
- }
69
- if (project) {
70
- if (!Object.keys(msgs['environment']).includes(project)) {
71
- msgs['environment'][project] = [lineWithoutLocation];
72
- }
73
- else if (!msgs['environment'][project].includes(lineWithoutLocation)) {
74
- msgs['environment'][project].push(lineWithoutLocation);
75
- }
76
- }
97
+ const msgs = { environment: {}, model: {}, report: [] };
98
+ let projects = Cache.getModels();
99
+ let file = "";
100
+ outputStylish.split(REGEX_NEWLINE).forEach((line) => {
101
+ const lineStripped = line.replace(REGEX_STRIP_ANSI, "");
102
+ // Collect model file (default)
103
+ const lineStrippedSplit = lineStripped.split(" ");
104
+ const rule = lineStrippedSplit[lineStrippedSplit.length - 1];
105
+ if (
106
+ !lineStripped.startsWith(" ") &&
107
+ !rules.recommended.includes(rule) &&
108
+ !lineStripped.startsWith("✖")
109
+ ) {
110
+ file = line;
111
+ if (process.argv[1].includes("jest") || process.argv[1].includes("mocha")) {
112
+ projects = [path.dirname(lineStripped)];
113
+ }
114
+ } else if (rules.environment.includes(rule)) {
115
+ // Collect error/warning messages from @sap/cds/ rules
116
+ const delimiter = line.split(/ +/, 2)[1];
117
+ const lineWithoutLocation = line.split(delimiter)[1];
118
+ let project = "";
119
+ for (let i = 0; i < projects.length; i++) {
120
+ project = projects[i];
121
+ if (file.includes(project)) {
122
+ project = styleText(project, ["link"]);
123
+ break;
77
124
  }
78
- else if (lineStripped && !rules.environment.includes(rule) &&
79
- !lineStripped.includes("potentially fixable") &&
80
- !lineStripped.startsWith('✖')) {
81
- if (lineStripped) {
82
- if (!msgs['model'][file]) {
83
- msgs['model'][file] = [line];
84
- }
85
- else {
86
- msgs['model'][file].push(line);
87
- }
88
- }
125
+ }
126
+ if (project) {
127
+ if (!Object.keys(msgs.environment).includes(project)) {
128
+ msgs.environment[project] = [lineWithoutLocation];
129
+ } else if (!msgs.environment[project].includes(lineWithoutLocation)) {
130
+ msgs.environment[project].push(lineWithoutLocation);
89
131
  }
90
- else if (lineStripped.startsWith('✖') ||
91
- lineStripped.includes("potentially fixable")) {
92
- msgs['report'].push(line);
132
+ }
133
+ } else if (
134
+ lineStripped &&
135
+ !rules.environment.includes(rule) &&
136
+ !lineStripped.includes("potentially fixable") &&
137
+ !lineStripped.startsWith("✖")
138
+ ) {
139
+ if (lineStripped) {
140
+ if (!msgs.model[file]) {
141
+ msgs.model[file] = [line];
142
+ } else {
143
+ msgs.model[file].push(line);
93
144
  }
94
- });
95
- return msgs;
145
+ }
146
+ } else if (lineStripped.startsWith("✖") || lineStripped.includes("potentially fixable")) {
147
+ msgs.report.push(line);
148
+ }
149
+ });
150
+ return msgs;
96
151
  }
152
+
153
+ /**
154
+ * Takes the collected error messages and collects them
155
+ * in a final string for ESLint to output
156
+ * @param output final string to output
157
+ * @param msgs error messages based on category
158
+ * @returns
159
+ */
97
160
  function formatOutput(output, msgs) {
98
- if (Object.keys(msgs['model']).length > 0) {
99
- for (const fileModel in msgs['model']) {
100
- if (msgs['model'][fileModel].length > 0) {
101
- output += `${fileModel}\n`;
102
- output += `${msgs['model'][fileModel].join('\n')}\n\n`;
103
- }
104
- }
105
- }
106
- if (Object.keys(msgs['environment']).length > 0) {
107
- for (const fileModel in msgs['environment']) {
108
- if (msgs['environment'][fileModel].length > 0) {
109
- output += `${fileModel}\n`;
110
- output += `${msgs['environment'][fileModel].join('\n')}\n\n`;
111
- }
112
- }
161
+ // First, output model msgs per file (from ESLint 'stylish' output)
162
+ for (const fileModel in msgs.model) {
163
+ if (msgs.model[fileModel].length > 0) {
164
+ output += `${fileModel}\n`;
165
+ output += `${msgs.model[fileModel].join("\n")}\n\n`;
113
166
  }
114
- if (output && msgs['report']) {
115
- output += `${msgs['report'].join('\n')}`;
167
+ }
168
+ // Next, output env msgs (file-independent but associated to project)
169
+ for (const fileModel in msgs.environment) {
170
+ if (msgs.environment[fileModel].length > 0) {
171
+ output += `${fileModel}\n`;
172
+ output += `${msgs.environment[fileModel].join("\n")}\n\n`;
116
173
  }
117
- if (output) {
118
- output = `\n${output}`;
119
- }
120
- return output;
174
+ }
175
+ // Finally output error/warning report count
176
+ if (output && msgs.report) {
177
+ output += `${msgs.report.join("\n")}`;
178
+ }
179
+ if (output) {
180
+ output = `\n${output}`;
181
+ }
182
+ return output;
121
183
  }
122
- module.exports = function (results, data) {
123
- let output = '';
124
- if (!utils_1.Cache.has('err')) {
125
- const outputStylish = formatter(results);
126
- const rules = getPluginRules(data);
127
- const msgs = splitOutput(outputStylish, rules);
128
- output = formatOutput(output, msgs);
129
- }
130
- return output;
131
- };
132
- //# sourceMappingURL=formatter.js.map
package/lib/api/index.js CHANGED
@@ -1,9 +1,22 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- var ruleFactory_1 = require("../impl/ruleFactory");
4
- Object.defineProperty(exports, "createRule", { enumerable: true, get: function () { return ruleFactory_1.createRule; } });
5
- Object.defineProperty(exports, "getRuleTester", { enumerable: true, get: function () { return ruleFactory_1.getRuleTester; } });
6
- var utils_1 = require("../impl/utils");
7
- Object.defineProperty(exports, "getConfigPath", { enumerable: true, get: function () { return utils_1.getConfigPath; } });
8
- Object.defineProperty(exports, "getFileExtensions", { enumerable: true, get: function () { return utils_1.getFileExtensions; } });
9
- //# sourceMappingURL=index.js.map
1
+ /**
2
+ * Our custom ESLint plugin API should:
3
+ * - Expose 'defineRule', and 'runRuleTester' to users to support the addition of *custom* cds rules
4
+ * - Expose 'getConfigPath', 'getFileExtensions', and 'genDocs' for usage in 'cds lint' (@sap/cds-dk)
5
+ * - Expose 'parserPath' for 'cds lint' rule unit tests with ESLint's ruleTester
6
+ */
7
+
8
+ const { createRule, defineRule, runRuleTester } = require("../impl/ruleFactory");
9
+ const { getConfigPath } = require("../impl/utils/model");
10
+ const { getFileExtensions } = require("../impl/utils/rules");
11
+ const { genDocs } = require("../impl/utils/rules");
12
+ const parserPath = require.resolve("../impl/parser");
13
+
14
+ module.exports = {
15
+ createRule,
16
+ defineRule,
17
+ runRuleTester,
18
+ getConfigPath,
19
+ getFileExtensions,
20
+ genDocs,
21
+ parserPath,
22
+ };
@@ -1,49 +1,43 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.Constants = void 0;
4
- class Constants {
5
- }
6
- exports.Constants = Constants;
7
- Constants.envRules = [
8
- "latest-cds-version",
9
- "min-node-version"
10
- ];
11
- Constants.modelRules = [
12
- "csn-compile-error",
13
- "assocs-card-flaw",
14
- "lower-camelcase-elements",
15
- "sql-cast-suggestion",
16
- "upper-camelcase-entities"
17
- ];
18
- Constants.ruleSeverities = {
19
- "csn-compile-error": 2,
20
- "assocs-card-flaw": 1,
21
- "latest-cds-version": 1,
22
- "lower-camelcase-elements": 1,
23
- "min-node-version": 2,
24
- "sql-cast-suggestion": 1,
25
- "upper-camelcase-entities": 1
1
+ /**
2
+ * This file contains all constants for:
3
+ * - categories: The category labels we use to for model and environment rules
4
+ * - customRulesDir: The custom rules directory name in the user's project home
5
+ * which contains the subdirs 'docs', 'rules' and 'tests'
6
+ * - recommended: The set of this plugin's recommended rules and their severities
7
+ * - globals: The globals which should be exposed to ESLint by this plugin
8
+ * - files: Any additional file extensions which ESLint should lint
9
+ */
10
+
11
+ module.exports = {
12
+ categories: {
13
+ env: "Environment",
14
+ model: "Model Validation",
15
+ },
16
+
17
+ customRulesDir: ".eslint",
18
+
19
+ recommended: {
20
+ "@sap/cds/assoc2many-ambiguous-key": 1,
21
+ "@sap/cds/cds-compile-error": 2,
22
+ "@sap/cds/min-node-version": 2,
23
+ "@sap/cds/no-db-keywords": 2,
24
+ "@sap/cds/require-2many-oncond": 2,
25
+ "@sap/cds/sql-cast-suggestion": 1
26
+ },
27
+
28
+ globals: {
29
+ SELECT: true,
30
+ INSERT: true,
31
+ UPDATE: true,
32
+ DELETE: true,
33
+ CREATE: true,
34
+ DROP: true,
35
+ CDL: true,
36
+ CQL: true,
37
+ CXL: true,
38
+ cds: true,
39
+ },
40
+
41
+ files: ["*.cds", "*.csn"],
42
+
26
43
  };
27
- Constants.globals = {
28
- "SELECT": true,
29
- "INSERT": true,
30
- "UPDATE": true,
31
- "DELETE": true,
32
- "CREATE": true,
33
- "DROP": true,
34
- "CDL": true,
35
- "CQL": true,
36
- "CXL": true,
37
- "cds": true
38
- };
39
- Constants.overrides = [
40
- {
41
- "files": ["*.cds", "*.csn"],
42
- "parser": "./parser",
43
- "parserOptions": {
44
- "ecmaVersion": 2019,
45
- "sourceType": "module"
46
- }
47
- }
48
- ];
49
- //# sourceMappingURL=constants.js.map
package/lib/impl/index.js CHANGED
@@ -1,51 +1,58 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.configs = exports.globals = exports.rules = void 0;
7
- const utils_1 = require("./utils");
8
- const constants_1 = require("./constants");
9
- const csn_compile_error_1 = __importDefault(require("./rules/csn-compile-error"));
10
- const assocs_card_flaw_1 = __importDefault(require("./rules/assocs-card-flaw"));
11
- const latest_cds_version_1 = __importDefault(require("./rules/latest-cds-version"));
12
- const lower_camelcase_elements_1 = __importDefault(require("./rules/lower-camelcase-elements"));
13
- const min_node_version_1 = __importDefault(require("./rules/min-node-version"));
14
- const sql_cast_suggestion_1 = __importDefault(require("./rules/sql-cast-suggestion"));
15
- const upper_camelcase_entities_1 = __importDefault(require("./rules/upper-camelcase-entities"));
16
- const rules = {
17
- "csn-compile-error": csn_compile_error_1.default,
18
- "assocs-card-flaw": assocs_card_flaw_1.default,
19
- "latest-cds-version": latest_cds_version_1.default,
20
- "lower-camelcase-elements": lower_camelcase_elements_1.default,
21
- "min-node-version": min_node_version_1.default,
22
- "sql-cast-suggestion": sql_cast_suggestion_1.default,
23
- "upper-camelcase-entities": upper_camelcase_entities_1.default
24
- };
25
- exports.rules = rules;
26
- const envRules = utils_1.getRules(constants_1.Constants.envRules, constants_1.Constants.ruleSeverities);
27
- const modelRules = utils_1.getRules(constants_1.Constants.modelRules, constants_1.Constants.ruleSeverities);
28
- const recRules = Object.assign({}, modelRules, utils_1.getRules([
29
- "min-node-version"
30
- ], constants_1.Constants.ruleSeverities));
31
- const configs = {
32
- "recommended": {
33
- "plugins": ["@sap/eslint-plugin-cds"],
34
- "overrides": constants_1.Constants.overrides,
35
- "rules": recRules
36
- },
37
- "model": {
38
- "plugins": ["@sap/eslint-plugin-cds"],
39
- "overrides": constants_1.Constants.overrides,
40
- "rules": modelRules
1
+ /**
2
+ * Custom ESLint plugin:
3
+ * https://eslint.org/docs/developer-guide/working-with-plugins
4
+ * This file exposes our plugins ESLint configuration, which must:
5
+ * - Expose any 'configs' for prescribed rule configuration bundles
6
+ * (i.e. "recommended"). See shareable configs:
7
+ * https://eslint.org/docs/developer-guide/shareable-configs
8
+ * - Expose any 'globals' for use in ESLint
9
+ * - Expose any 'processors' for use in ESLint
10
+ * - Expose any 'rules' for use in ESLint
11
+ * We also initiate and cache the objects 'rulesInfo' and 'cds' for later use.
12
+ */
13
+
14
+ const path = require("path");
15
+ const processor = require("./processor");
16
+ const plugin = require("../../package.json").name;
17
+
18
+ const { getRules } = require("../impl/utils/rules");
19
+ const {
20
+ Cache,
21
+ getCDSProxy,
22
+ getLocation,
23
+ getRange,
24
+ } = require("../impl/utils/model");
25
+ const { files, globals, recommended } = require("./constants");
26
+
27
+ const cds = require("@sap/cds");
28
+ cds.getLocation = getLocation;
29
+ cds.getRange = getRange;
30
+ Cache.set("cds", getCDSProxy(cds));
31
+
32
+ let rulesInfo;
33
+ if (!Cache.has("rulesInfo")) {
34
+ rulesInfo = getRules(path.join(__dirname, "rules"));
35
+ Cache.set("rulesInfo", rulesInfo);
36
+ } else {
37
+ rulesInfo = Cache.get("rulesInfo");
38
+ }
39
+
40
+ module.exports = {
41
+ configs: {
42
+ recommended: {
43
+ globals,
44
+ plugins: [plugin],
45
+ overrides: [
46
+ {
47
+ files: files,
48
+ processor: "@sap/cds/cds",
49
+ },
50
+ ],
51
+ rules: recommended,
41
52
  },
42
- "environment": {
43
- "plugins": ["@sap/eslint-plugin-cds"],
44
- "overrides": constants_1.Constants.overrides,
45
- "rules": envRules
46
- }
53
+ },
54
+ processors: {
55
+ cds: processor,
56
+ },
57
+ rules: rulesInfo.rules,
47
58
  };
48
- exports.configs = configs;
49
- const globals = constants_1.Constants.globals;
50
- exports.globals = globals;
51
- //# sourceMappingURL=index.js.map