Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: gajus/eslint-plugin-jsdoc
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: v34.2.1
Choose a base ref
...
head repository: gajus/eslint-plugin-jsdoc
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: v34.2.2
Choose a head ref
  • 2 commits
  • 13 files changed
  • 1 contributor

Commits on May 14, 2021

  1. fix(no-missing-syntax): pass in missing comment

    Also documents `message` values and adds test line numbers.
    brettz9 committed May 14, 2021

    Verified

    This commit was signed with the committer’s verified signature. The key has expired.
    lukekarrys Luke Karrys
    Copy the full SHA
    a977896 View commit details
  2. fix(check-param-names): adjusts line numbers to be nearer problemat…

    …ic item
    
    Also adds test line numbers.
    brettz9 committed May 14, 2021

    Verified

    This commit was signed with the committer’s verified signature. The key has expired.
    lukekarrys Luke Karrys
    Copy the full SHA
    e6c9ab2 View commit details
3 changes: 2 additions & 1 deletion .README/rules/no-missing-syntax.md
Original file line number Diff line number Diff line change
@@ -42,7 +42,8 @@ Use the `minimum` property (defaults to 1) to indicate how many are required
for the rule to be reported.

Use the `message` property to indicate the specific error to be shown when an
error is reported for that context being found missing.
error is reported for that context being found missing. You may use
`{{context}}` and `{{comment}}` with such messages.

Set to `"any"` if you want the rule to apply to any jsdoc block throughout
your files (as is necessary for finding function blocks not attached to a
11 changes: 6 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
@@ -7601,7 +7601,8 @@ Use the `minimum` property (defaults to 1) to indicate how many are required
for the rule to be reported.
Use the `message` property to indicate the specific error to be shown when an
error is reported for that context being found missing.
error is reported for that context being found missing. You may use
`{{context}}` and `{{comment}}` with such messages.
Set to `"any"` if you want the rule to apply to any jsdoc block throughout
your files (as is necessary for finding function blocks not attached to a
@@ -7628,16 +7629,16 @@ function quux () {
}
// "jsdoc/no-missing-syntax": ["error"|"warn", {"contexts":[{"comment":"JSDocBlock[postDelimiter=\"\"]:has(JSDocTypeUnion[left.name=\"Foo\"])","context":"FunctionDeclaration"}]}]
// Message: Syntax is required: FunctionDeclaration
// Message: Syntax is required: FunctionDeclaration with JSDocBlock[postDelimiter=""]:has(JSDocTypeUnion[left.name="Foo"])

/**
* @implements {Bar|Foo}
*/
function quux () {

}
// "jsdoc/no-missing-syntax": ["error"|"warn", {"contexts":[{"comment":"JSDocBlock[postDelimiter=\"\"]:has(JSDocTypeUnion[left.name=\"Foo\"])","context":"FunctionDeclaration","message":"Problematic function syntax: `{{context}}`."}]}]
// Message: Problematic function syntax: `FunctionDeclaration`.
// "jsdoc/no-missing-syntax": ["error"|"warn", {"contexts":[{"comment":"JSDocBlock[postDelimiter=\"\"]:has(JSDocTypeUnion[left.name=\"Foo\"])","context":"FunctionDeclaration","message":"Problematically missing function syntax: `{{context}}` with `{{comment}}`."}]}]
// Message: Problematically missing function syntax: `FunctionDeclaration` with `JSDocBlock[postDelimiter=""]:has(JSDocTypeUnion[left.name="Foo"])`.

/**
* @implements {Bar|Foo}
@@ -7663,7 +7664,7 @@ function quux () {

}
// "jsdoc/no-missing-syntax": ["error"|"warn", {"contexts":[{"comment":"JSDocBlock[postDelimiter=\"\"]:has(JSDocTypeUnion[left.name=\"Bar\"])","context":"FunctionDeclaration","minimum":2}]}]
// Message: Syntax is required: FunctionDeclaration
// Message: Syntax is required: FunctionDeclaration with JSDocBlock[postDelimiter=""]:has(JSDocTypeUnion[left.name="Bar"])
````

The following patterns are not considered problems:
2 changes: 2 additions & 0 deletions src/iterateJsdoc.js
Original file line number Diff line number Diff line change
@@ -39,6 +39,8 @@ const getBasicUtils = (context, {tagNamePreference, mode}) => {
return jsdocUtils.parseClosureTemplateTag(tag);
};

utils.pathDoesNotBeginWith = jsdocUtils.pathDoesNotBeginWith;

utils.getPreferredTagNameObject = ({tagName}) => {
const ret = jsdocUtils.getPreferredTagName(context, mode, tagName, tagNamePreference);
const isObject = ret && typeof ret === 'object';
6 changes: 6 additions & 0 deletions src/jsdocUtils.js
Original file line number Diff line number Diff line change
@@ -1219,6 +1219,11 @@ const comparePaths = (name) => {
};
};
const pathDoesNotBeginWith = (name, otherPathName) => {
return !name.startsWith(otherPathName) &&
!dropPathSegmentQuotes(name).startsWith(dropPathSegmentQuotes(otherPathName));
};
const getRegexFromString = (regexString, requiredFlags) => {
const match = regexString.match(/^\/(.*)\/([gimyus]*)$/us);
let flags = 'u';
@@ -1266,6 +1271,7 @@ export default {
isValidTag,
overrideTagStructure,
parseClosureTemplateTag,
pathDoesNotBeginWith,
setTagStructure,
tagMightHaveNamepath,
tagMightHaveNamePosition,
15 changes: 12 additions & 3 deletions src/rules/checkParamNames.js
Original file line number Diff line number Diff line change
@@ -99,16 +99,25 @@ const validateParameterNames = (
if (!checkRestProperty && rests[idx]) {
return;
}
missingProperties.push(name);
const missingIndex = actualNames.findIndex((actualName) => {
return utils.pathDoesNotBeginWith(name, actualName);
});
const line = tag.source[0].number - 1 + (missingIndex > -1 ? missingIndex : actualNames.length);
missingProperties.push({
name,
tagPlacement: {
line: line === 0 ? 1 : line,
},
});
} else if (actualTypes[actualNameIdx].search(checkTypesRegex) === -1 && actualTypes[actualNameIdx] !== '') {
notCheckingNames.push(name);
}
});

const hasMissing = missingProperties.length;
if (hasMissing) {
missingProperties.forEach((missingProperty) => {
report(`Missing @${targetTagName} "${missingProperty}"`, null, tag);
missingProperties.forEach(({tagPlacement, name: missingProperty}) => {
report(`Missing @${targetTagName} "${missingProperty}"`, null, tagPlacement);
});
}

4 changes: 3 additions & 1 deletion src/rules/noMissingSyntax.js
Original file line number Diff line number Diff line change
@@ -56,9 +56,11 @@ export default iterateJsdoc(({
!state.selectorMap[contextStr][comment] ||
state.selectorMap[contextStr][comment] < (cntxt?.minimum ?? 1)
) {
const message = cntxt?.message ?? 'Syntax is required: {{context}}';
const message = cntxt?.message ?? 'Syntax is required: {{context}}' +
(comment ? ' with {{comment}}' : '');
context.report({
data: {
comment,
context: contextStr,
},
loc: {
28 changes: 28 additions & 0 deletions test/rules/assertions/checkLineAlignment.js
Original file line number Diff line number Diff line change
@@ -12,6 +12,7 @@ export default {
`,
errors: [
{
line: 2,
message: 'Expected JSDoc block lines to be aligned.',
type: 'Block',
},
@@ -42,6 +43,7 @@ export default {
`,
errors: [
{
line: 2,
message: 'Expected JSDoc block lines to be aligned.',
type: 'Block',
},
@@ -72,6 +74,7 @@ export default {
`,
errors: [
{
line: 2,
message: 'Expected JSDoc block lines to be aligned.',
type: 'Block',
},
@@ -101,6 +104,7 @@ export default {
`,
errors: [
{
line: 2,
message: 'Expected JSDoc block lines to be aligned.',
type: 'Block',
},
@@ -130,6 +134,7 @@ export default {
`,
errors: [
{
line: 2,
message: 'Expected JSDoc block lines to be aligned.',
type: 'Block',
},
@@ -159,6 +164,7 @@ export default {
`,
errors: [
{
line: 2,
message: 'Expected JSDoc block lines to be aligned.',
type: 'Block',
},
@@ -188,6 +194,7 @@ export default {
`,
errors: [
{
line: 2,
message: 'Expected JSDoc block lines to be aligned.',
type: 'Block',
},
@@ -217,6 +224,7 @@ export default {
`,
errors: [
{
line: 2,
message: 'Expected JSDoc block lines to be aligned.',
type: 'Block',
},
@@ -248,6 +256,7 @@ export default {
`,
errors: [
{
line: 3,
message: 'Expected JSDoc block lines to be aligned.',
type: 'Block',
},
@@ -281,6 +290,7 @@ export default {
`,
errors: [
{
line: 3,
message: 'Expected JSDoc block lines to be aligned.',
type: 'Block',
},
@@ -312,6 +322,7 @@ export default {
`,
errors: [
{
line: 2,
message: 'Expected JSDoc block lines to be aligned.',
type: 'Block',
},
@@ -344,6 +355,7 @@ export default {
`,
errors: [
{
line: 2,
message: 'Expected JSDoc block lines to be aligned.',
type: 'Block',
},
@@ -377,6 +389,7 @@ export default {
`,
errors: [
{
line: 2,
message: 'Expected JSDoc block lines to be aligned.',
type: 'Block',
},
@@ -410,6 +423,7 @@ export default {
`,
errors: [
{
line: 2,
message: 'Expected JSDoc block lines to be aligned.',
type: 'Block',
},
@@ -445,6 +459,7 @@ export default {
`,
errors: [
{
line: 2,
message: 'Expected JSDoc block lines to be aligned.',
type: 'Block',
},
@@ -477,10 +492,12 @@ export default {
`,
errors: [
{
line: 5,
message: 'Expected JSDoc block lines to not be aligned.',
type: 'Block',
},
{
line: 6,
message: 'Expected JSDoc block lines to not be aligned.',
type: 'Block',
},
@@ -510,6 +527,7 @@ export default {
`,
errors: [
{
line: 6,
message: 'Expected JSDoc block lines to not be aligned.',
type: 'Block',
},
@@ -539,6 +557,7 @@ export default {
`,
errors: [
{
line: 6,
message: 'Expected JSDoc block lines to not be aligned.',
type: 'Block',
},
@@ -568,6 +587,7 @@ export default {
`,
errors: [
{
line: 6,
message: 'Expected JSDoc block lines to not be aligned.',
type: 'Block',
},
@@ -595,6 +615,7 @@ export default {
`,
errors: [
{
line: 2,
message: 'Expected JSDoc block lines to be aligned.',
type: 'Block',
},
@@ -628,6 +649,7 @@ export default {
`,
errors: [
{
line: 2,
message: 'Expected JSDoc block lines to be aligned.',
type: 'Block',
},
@@ -659,6 +681,7 @@ export default {
`,
errors: [
{
line: 2,
message: 'Expected JSDoc block lines to be aligned.',
type: 'Block',
},
@@ -718,6 +741,7 @@ export default {
`,
errors: [
{
line: 6,
message: 'Expected JSDoc block lines to not be aligned.',
type: 'Block',
},
@@ -745,6 +769,7 @@ export default {
`,
errors: [
{
line: 6,
message: 'Expected JSDoc block lines to not be aligned.',
type: 'Block',
},
@@ -772,6 +797,7 @@ export default {
`,
errors: [
{
line: 5,
message: 'Expected JSDoc block lines to not be aligned.',
type: 'Block',
},
@@ -800,6 +826,7 @@ export default {
`,
errors: [
{
line: 7,
message: 'Expected JSDoc block lines to not be aligned.',
type: 'Block',
},
@@ -873,6 +900,7 @@ export default {
`,
errors: [
{
line: 2,
message: 'Expected JSDoc block lines to be aligned.',
type: 'Block',
},
Loading