Skip to content

Commit ed0fa4e

Browse files
edg2sbrettz9
authored andcommittedMay 14, 2020
fix: workaround for 'constructor' key in tagNamePreference; fixes #537
1 parent fa3e717 commit ed0fa4e

File tree

4 files changed

+53
-2
lines changed

4 files changed

+53
-2
lines changed
 

‎.README/README.md

+2
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,8 @@ Use `settings.jsdoc.tagNamePreference` to configure a preferred alias name for a
156156
}
157157
```
158158

159+
Note: ESLint does not allow settings to have keys which conflict with Object.prototype e.g. `'constructor'`. To work around this use can use the key `'tag constructor'`.
160+
159161
One may also use an object with a `message` and `replacement`.
160162

161163
The following will report the message `@extends is to be used over @augments as it is more evocative of classes than @augments` upon encountering `@augments`.

‎README.md

+11
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,8 @@ Use `settings.jsdoc.tagNamePreference` to configure a preferred alias name for a
212212
}
213213
```
214214

215+
Note: ESLint does not allow settings to have keys which conflict with Object.prototype e.g. `'constructor'`. To work around this use can use the key `'tag constructor'`.
216+
215217
One may also use an object with a `message` and `replacement`.
216218

217219
The following will report the message `@extends is to be used over @augments as it is more evocative of classes than @augments` upon encountering `@augments`.
@@ -2614,6 +2616,15 @@ function quux (foo) {
26142616
// Settings: {"jsdoc":{"tagNamePreference":{"param":"arg"}}}
26152617
// Message: Invalid JSDoc tag (preference). Replace "param" JSDoc tag with "arg".
26162618

2619+
/**
2620+
* @constructor foo
2621+
*/
2622+
function quux (foo) {
2623+
2624+
}
2625+
// Settings: {"jsdoc":{"tagNamePreference":{"tag constructor":"cons"}}}
2626+
// Message: Invalid JSDoc tag (preference). Replace "constructor" JSDoc tag with "cons".
2627+
26172628
/**
26182629
* @arg foo
26192630
*/

‎src/jsdocUtils.js

+9-2
Original file line numberDiff line numberDiff line change
@@ -223,8 +223,15 @@ const getPreferredTagName = (
223223
return name;
224224
}
225225

226-
if (_.has(tagPreference, name)) {
227-
return tagPreference[name];
226+
// Allow keys to have a 'tag ' prefix to avoid upstream bug in ESLint
227+
// that disallows keys that conflict with Object.prototype,
228+
// e.g. 'tag constructor' for 'constructor' (#537)
229+
const tagPreferenceFixed = _.mapKeys(tagPreference, (value, key) => {
230+
return key.replace('tag ', '');
231+
});
232+
233+
if (_.has(tagPreferenceFixed, name)) {
234+
return tagPreferenceFixed[name];
228235
}
229236

230237
const tagNames = getTagNamesForMode(mode, context);

‎test/rules/assertions/checkTagNames.js

+31
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,37 @@ export default {
112112
},
113113
},
114114
},
115+
{
116+
code: `
117+
/**
118+
* @constructor foo
119+
*/
120+
function quux (foo) {
121+
122+
}
123+
`,
124+
errors: [
125+
{
126+
line: 3,
127+
message: 'Invalid JSDoc tag (preference). Replace "constructor" JSDoc tag with "cons".',
128+
},
129+
],
130+
output: `
131+
/**
132+
* @cons foo
133+
*/
134+
function quux (foo) {
135+
136+
}
137+
`,
138+
settings: {
139+
jsdoc: {
140+
tagNamePreference: {
141+
'tag constructor': 'cons',
142+
},
143+
},
144+
},
145+
},
115146
{
116147
code: `
117148
/**

0 commit comments

Comments
 (0)
Please sign in to comment.