UNPKG

2.83 kBJavaScriptView Raw
1"use strict";
2
3Object.defineProperty(exports, "__esModule", {
4 value: true
5});
6exports.default = warnRemovedSettings;
7
8var _WarnSettings = _interopRequireDefault(require("./WarnSettings"));
9
10function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
11
12const warnSettings = (0, _WarnSettings.default)();
13/**
14 * @typedef {(
15 * | "require-jsdoc"
16 * | "require-returns"
17 * | "valid-types"
18 * | "require-example"
19 * | "check-examples"
20 * )} RulesWithMovedSettings
21 */
22
23/**
24 * @param {object} obj
25 * @param {string} property
26 * @returns {boolean}
27 */
28
29const has = (obj, property) => {
30 return Object.prototype.hasOwnProperty.call(obj, property);
31};
32/**
33 *
34 * @param {RulesWithMovedSettings} ruleName
35 * @returns {string[]}
36 */
37
38
39const getMovedSettings = ruleName => {
40 switch (ruleName) {
41 case 'require-jsdoc':
42 return ['exemptEmptyFunctions'];
43
44 case 'require-returns':
45 return ['forceRequireReturn'];
46
47 case 'valid-types':
48 return ['allowEmptyNamepaths', 'checkSeesForNamepaths'];
49
50 case 'require-example':
51 return ['avoidExampleOnConstructors'];
52
53 case 'check-examples':
54 return ['captionRequired', 'exampleCodeRegex', 'rejectExampleCodeRegex', 'allowInlineConfig', 'noDefaultExampleRules', 'matchingFileName', 'configFile', 'eslintrcForExamples', 'baseConfig', 'reportUnusedDisableDirectives'];
55 }
56 /* istanbul ignore next */
57
58
59 return [];
60};
61/**
62 * @param {object} context
63 * @param {RulesWithMovedSettings} ruleName
64 */
65
66
67function warnRemovedSettings(context, ruleName) {
68 const movedSettings = getMovedSettings(ruleName);
69
70 if (!context.settings || !context.settings.jsdoc) {
71 return;
72 }
73
74 var _iteratorNormalCompletion = true;
75 var _didIteratorError = false;
76 var _iteratorError = undefined;
77
78 try {
79 for (var _iterator = movedSettings[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
80 const setting = _step.value;
81
82 if (has(context.settings.jsdoc, setting) && !warnSettings.hasBeenWarned(context, setting)) {
83 context.report({
84 loc: {
85 start: {
86 column: 1,
87 line: 1
88 }
89 },
90 message: `\`settings.jsdoc.${setting}\` has been removed, ` + `use options in the rule \`${ruleName}\` instead.`
91 });
92 warnSettings.markSettingAsWarned(context, setting);
93 }
94 }
95 } catch (err) {
96 _didIteratorError = true;
97 _iteratorError = err;
98 } finally {
99 try {
100 if (!_iteratorNormalCompletion && _iterator.return != null) {
101 _iterator.return();
102 }
103 } finally {
104 if (_didIteratorError) {
105 throw _iteratorError;
106 }
107 }
108 }
109}
110
111module.exports = exports.default;
112//# sourceMappingURL=warnRemovedSettings.js.map
\No newline at end of file