Skip to content

Commit efa0e68

Browse files
committed
Merge branch 'master' into add-more-type-checks-to-valid-types
* master: feat(match-description): allow `description` and `desc` tags to be matched for validation refactor: use template string when appropriate
2 parents fec8b67 + 9b63f40 commit efa0e68

30 files changed

+218
-52
lines changed

.README/rules/match-description.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,6 @@ Overrides the default contexts (see below).
8282
|Context|`ArrowFunctionExpression`, `FunctionDeclaration`, `FunctionExpression`; others when `contexts` option enabled|
8383
|Tags|N/A by default but see `tags` options|
8484
|Settings||
85-
|Options|`contexts`, `tags` (allows for 'param', 'arg', 'argument', 'returns', 'return'), `mainDescription`, `matchDescription`|
85+
|Options|`contexts`, `tags` (allows for 'param', 'arg', 'argument', 'returns', 'return', 'description', 'desc'), `mainDescription`, `matchDescription`|
8686

8787
<!-- assertions matchDescription -->

README.md

Lines changed: 47 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2495,7 +2495,7 @@ Overrides the default contexts (see below).
24952495
|Context|`ArrowFunctionExpression`, `FunctionDeclaration`, `FunctionExpression`; others when `contexts` option enabled|
24962496
|Tags|N/A by default but see `tags` options|
24972497
|Settings||
2498-
|Options|`contexts`, `tags` (allows for 'param', 'arg', 'argument', 'returns', 'return'), `mainDescription`, `matchDescription`|
2498+
|Options|`contexts`, `tags` (allows for 'param', 'arg', 'argument', 'returns', 'return', 'description', 'desc'), `mainDescription`, `matchDescription`|
24992499

25002500
The following patterns are considered problems:
25012501

@@ -2571,6 +2571,17 @@ function quux (foo) {
25712571
// Options: [{"tags":{"param":true}}]
25722572
// Message: JSDoc description does not satisfy the regex pattern.
25732573

2574+
/**
2575+
* Foo.
2576+
*
2577+
* @description foo foo.
2578+
*/
2579+
function quux (foo) {
2580+
2581+
}
2582+
// Options: [{"tags":{"description":true}}]
2583+
// Message: JSDoc description does not satisfy the regex pattern.
2584+
25742585
/**
25752586
* Foo
25762587
*
@@ -2695,6 +2706,16 @@ function quux () {
26952706
// Options: [{"tags":{"param":"[А-Я][А-я]+\\."}}]
26962707
// Message: JSDoc description does not satisfy the regex pattern.
26972708

2709+
/**
2710+
* @description notRet
2711+
* @returns Тест.
2712+
*/
2713+
function quux () {
2714+
2715+
}
2716+
// Options: [{"tags":{"description":"[А-Я][А-я]+\\."}}]
2717+
// Message: JSDoc description does not satisfy the regex pattern.
2718+
26982719
/**
26992720
* foo.
27002721
*/
@@ -2784,6 +2805,15 @@ function quux () {
27842805
}
27852806
// Options: [{"tags":{"returns":"[А-Я][А-я]+\\."}}]
27862807

2808+
/**
2809+
* @param notRet
2810+
* @description Тест.
2811+
*/
2812+
function quux () {
2813+
2814+
}
2815+
// Options: [{"tags":{"description":"[А-Я][А-я]+\\."}}]
2816+
27872817
/**
27882818
* Foo
27892819
* bar.
@@ -2800,6 +2830,14 @@ function quux () {
28002830
}
28012831
// Options: [{"tags":{"returns":true}}]
28022832

2833+
/**
2834+
* @description Foo bar.
2835+
*/
2836+
function quux () {
2837+
2838+
}
2839+
// Options: [{"tags":{"description":true}}]
2840+
28032841
/**
28042842
* Foo. {@see Math.sin}.
28052843
*/
@@ -2921,6 +2959,14 @@ const q = {
29212959

29222960
};
29232961
// Options: [{"contexts":[]}]
2962+
2963+
/**
2964+
* @description foo.
2965+
*/
2966+
function quux () {
2967+
2968+
}
2969+
// Options: [{"tags":{"param":true}}]
29242970
````
29252971

29262972

src/bin/readme-assertions.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,15 +30,15 @@ const formatCodeSnippet = (setup) => {
3030
paragraphs.push(trimCode(setup.code));
3131

3232
if (setup.settings) {
33-
paragraphs.push('// Settings: ' + JSON.stringify(setup.settings));
33+
paragraphs.push(`// Settings: ${JSON.stringify(setup.settings)}`);
3434
}
3535

3636
if (setup.options) {
37-
paragraphs.push('// Options: ' + JSON.stringify(setup.options));
37+
paragraphs.push(`// Options: ${JSON.stringify(setup.options)}`);
3838
}
3939

4040
if (setup.errors) {
41-
paragraphs.push('// Message: ' + setup.errors[0].message);
41+
paragraphs.push(`// Message: ${setup.errors[0].message}`);
4242
}
4343

4444
return paragraphs.join('\n');
@@ -74,7 +74,7 @@ const updateDocuments = (assertions) => {
7474
const ruleAssertions = assertions[ruleName];
7575

7676
if (!ruleAssertions) {
77-
throw new Error('No assertions available for rule "' + ruleName + '".');
77+
throw new Error(`No assertions available for rule "${ruleName}".`);
7878
}
7979

8080
return 'The following patterns are considered problems:\n\n````js\n' + ruleAssertions.invalid.join('\n\n') +

src/exportParser.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ const getSymbol = function (node, globals, scope, opt) {
7777
}
7878
*/
7979
/* istanbul ignore next */
80-
debug('MemberExpression: Missing property ' + node.property.name);
80+
debug(`MemberExpression: Missing property ${node.property.name}`);
8181

8282
/* istanbul ignore next */
8383
return null;

src/iterateJsdoc.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import getJSDocComment from './eslint/getJSDocComment';
55

66
const parseComment = (commentNode, indent) => {
77
// Preserve JSDoc block start/end indentation.
8-
return commentParser(indent + '/*' + commentNode.value + indent + '*/', {
8+
return commentParser(`${indent}/*${commentNode.value}${indent}*/`, {
99
// @see https://github.com/yavorskiy/comment-parser/issues/21
1010
parsers: [
1111
commentParser.PARSERS.parse_tag,

src/jsdocUtils.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -491,7 +491,7 @@ const hasReturnValue = (node, context, ignoreAsync) => {
491491
}
492492
}
493493
/* istanbul ignore next */
494-
throw new Error('Unknown element ' + node.type);
494+
throw new Error(`Unknown element ${node.type}`);
495495
};
496496

497497
/** @param {string} tag */

src/rules/checkAlignment.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ export default iterateJsdoc(({
2424
// Ignore the first line and all lines not starting with `*`
2525
const ignored = !index || line.split('*')[0].trim().length;
2626

27-
return ignored ? line : indent + ' ' + _.trimStart(line);
27+
return ignored ? line : `${indent} ${_.trimStart(line)}`;
2828
})
2929
.join('\n');
3030

src/rules/checkExamples.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ export default iterateJsdoc(({
6666
utils.forEachPreferredTag('example', (tag, targetTagName) => {
6767
// If a space is present, we should ignore it
6868
const initialTag = tag.source.match(
69-
new RegExp('^@' + escapeRegexString(targetTagName) + ' ?', 'u')
69+
new RegExp(`^@${escapeRegexString(targetTagName)} ?`, 'u')
7070
);
7171
const initialTagLength = initialTag[0].length;
7272
const firstLinePrefixLength = preTagSpaceLength + initialTagLength;

src/rules/checkParamNames.js

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ const validateParameterNames = (targetTagName : string, functionParameterNames :
1313
if (paramTags.some((tg, idx) => {
1414
return tg.name === tag.name && idx !== index;
1515
})) {
16-
report('Duplicate @' + targetTagName + ' "' + tag.name + '"');
16+
report(`Duplicate @${targetTagName} "${tag.name}"`);
1717

1818
return true;
1919
}
@@ -60,7 +60,7 @@ const validateParameterNamesDeep = (targetTagName : string, jsdocParameterNames
6060

6161
if (isPropertyPath) {
6262
if (!lastRealParameter) {
63-
report('@' + targetTagName + ' path declaration ("' + jsdocParameterName + '") appears before any real parameter.');
63+
report(`@${targetTagName} path declaration ("${jsdocParameterName}") appears before any real parameter.`);
6464

6565
return true;
6666
}
@@ -72,8 +72,10 @@ const validateParameterNamesDeep = (targetTagName : string, jsdocParameterNames
7272
}
7373

7474
if (pathRootNodeName !== lastRealParameter) {
75-
report('@' + targetTagName + ' path declaration ("' + jsdocParameterName + '") root node name ("' +
76-
pathRootNodeName + '") does not match previous real parameter name ("' + lastRealParameter + '").');
75+
report(
76+
`@${targetTagName} path declaration ("${jsdocParameterName}") root node name ("${pathRootNodeName}") ` +
77+
`does not match previous real parameter name ("${lastRealParameter}").`
78+
);
7779

7880
return true;
7981
}

src/rules/checkTagNames.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,13 +56,13 @@ export default iterateJsdoc(({
5656

5757
if (preferredTagName !== tagName) {
5858
report(message, (fixer) => {
59-
const replacement = sourceCode.getText(jsdocNode).replace('@' + tagName, '@' + preferredTagName);
59+
const replacement = sourceCode.getText(jsdocNode).replace(`@${tagName}`, `@${preferredTagName}`);
6060

6161
return fixer.replaceText(jsdocNode, replacement);
6262
}, jsdocTag);
6363
}
6464
} else {
65-
report('Invalid JSDoc tag name "' + tagName + '".', null, jsdocTag);
65+
report(`Invalid JSDoc tag name "${tagName}".`, null, jsdocTag);
6666
}
6767
});
6868
}, {

0 commit comments

Comments
 (0)