-
-
Notifications
You must be signed in to change notification settings - Fork 153
/
warnRemovedSettings.js
107 lines (96 loc) · 2.41 KB
/
warnRemovedSettings.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
/**
* @typedef {(
* | "require-jsdoc"
* | "require-returns"
* | "valid-types"
* | "require-example"
* | "check-examples"
* )} RulesWithMovedSettings
*/
/** @type {WeakMap<Object, Set<string>>} */
const warnedSettings = new WeakMap();
/**
* Warn only once for each context and setting
*
* @param {Object} context
* @param {string} setting
*/
const hasBeenWarned = (context, setting) => {
return warnedSettings.has(context) && warnedSettings.get(context).has(setting);
};
const markSettingAsWarned = (context, setting) => {
if (!warnedSettings.has(context)) {
warnedSettings.set(context, new Set());
}
warnedSettings.get(context).add(setting);
};
/**
* @param {Object} obj
* @param {string} property
* @returns {boolean}
*/
const has = (obj, property) => {
return Object.prototype.hasOwnProperty.call(obj, property);
};
/**
*
* @param {RulesWithMovedSettings} ruleName
* @returns {string[]}
*/
const getMovedSettings = (ruleName) => {
switch (ruleName) {
case 'require-jsdoc':
return ['exemptEmptyFunctions'];
case 'require-returns':
return ['forceRequireReturn'];
case 'valid-types':
return ['allowEmptyNamepaths', 'checkSeesForNamepaths'];
case 'require-example':
return ['avoidExampleOnConstructors'];
// TODO: move settings of check-examples to options
/* istanbul ignore next */
case 'check-examples':
return [
'captionRequired',
'exampleCodeRegex',
'rejectExampleCodeRegex',
'allowInlineConfig',
'noDefaultExampleRules',
'matchingFileName',
'configFile',
'eslintrcForExamples',
'baseConfig',
'reportUnusedDisableDirectives'
];
}
/* istanbul ignore next */
return [];
};
/**
* @param {Object} context
* @param {RulesWithMovedSettings} ruleName
*/
export default function warnRemovedSettings (context, ruleName) {
const movedSettings = getMovedSettings(ruleName);
if (!context.settings || !context.settings.jsdoc) {
return;
}
for (const setting of movedSettings) {
if (
has(context.settings.jsdoc, setting) &&
!hasBeenWarned(context, setting)
) {
context.report({
loc: {
start: {
column: 1,
line: 1
}
},
message: `\`settings.jsdoc.${setting}\` has been removed, ` +
`use options in the rule \`${ruleName}\` instead.`
});
markSettingAsWarned(context, setting);
}
}
}