Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improvements for RequireDescriptionCompleteSentence #59

Merged
merged 3 commits into from
Feb 13, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 16 additions & 8 deletions src/rules/requireDescriptionCompleteSentence.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,21 @@ const extractParagraphs = (text) => {
};

const extractSentences = (text) => {
return text.split(/\.\s+|\.$/).filter((sentence) => {
return text

// Remove all {} tags.
.replace(/\{[\s\S]*?\}\s*/g, '')
.split(/[.?!:](?:\s+|$)/)

// Ignore sentences with only whitespaces.
return !/^\s*$/.test(sentence);
}).map((sentence) => {
.filter((sentence) => {
return !/^\s*$/.test(sentence);
})

// Re-add the dot.
return sentence + '.';
});
.map((sentence) => {
return sentence + '.';
});
};

const isNewLinePrecededByAPeriod = (text) => {
Expand Down Expand Up @@ -52,7 +60,7 @@ const validateDescription = (description, report, jsdocNode, sourceCode) => {
const fix = (fixer) => {
let text = sourceCode.getText(jsdocNode);

if (!_.endsWith(paragraph, '.')) {
if (!/[.:?!]$/.test(paragraph)) {
const line = _.last(paragraph.split('\n'));

text = text.replace(line, line + '.');
Expand All @@ -75,7 +83,7 @@ const validateDescription = (description, report, jsdocNode, sourceCode) => {
report('Sentence should start with an uppercase character.', fix);
}

if (!/\.$/.test(paragraph)) {
if (!/[.!?]$/.test(paragraph)) {
report('Sentence must end with a period.', fix);

return true;
Expand All @@ -102,7 +110,7 @@ export default iterateJsdoc(({
}

const tags = _.filter(jsdoc.tags, (tag) => {
return _.includes(['param', 'returns'], tag.tag);
return _.includes(['param', 'arg', 'argument', 'returns', 'return'], tag.tag);
});

_.some(tags, (tag) => {
Expand Down
124 changes: 124 additions & 0 deletions test/rules/assertions/requireDescriptionCompleteSentence.js
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,32 @@ export default {
}
`
},
{
code: `
/**
* {@see Foo.bar} buz
*/
function quux (foo) {

}
`,
errors: [
{
message: 'Sentence should start with an uppercase character.'
},
{
message: 'Sentence must end with a period.'
}
],
output: `
/**
* {@see Foo.bar} Buz.
*/
function quux (foo) {

}
`
},
{
code: `
/**
Expand Down Expand Up @@ -258,6 +284,78 @@ export default {
*/
function longDescription (foo) {

}
`
},
{
code: `
/**
* @arg {number} foo - Foo
*/
function quux (foo) {

}
`,
errors: [
{
message: 'Sentence must end with a period.'
}
],
output: `
/**
* @arg {number} foo - Foo.
*/
function quux (foo) {

}
`
},
{
code: `
/**
* @argument {number} foo - Foo
*/
function quux (foo) {

}
`,
errors: [
{
message: 'Sentence must end with a period.'
}
],
output: `
/**
* @argument {number} foo - Foo.
*/
function quux (foo) {

}
`
},
{
code: `
/**
* @return {number} foo
*/
function quux (foo) {

}
`,
errors: [
{
message: 'Sentence should start with an uppercase character.'
},
{
message: 'Sentence must end with a period.'
}
],
output: `
/**
* @return {number} Foo.
*/
function quux (foo) {

}
`
}
Expand Down Expand Up @@ -335,6 +433,32 @@ export default {
*/
function quux () {

}
`
},
{
code: `
/**
* Foo. {@see Math.sin}.
*/
function quux () {

}
`
},
{
code: `
/**
* Foo?
*
* Bar!
*
* Baz:
* 1. Foo.
* 2. Bar.
*/
function quux () {

}
`
}
Expand Down