Skip to content

Commit

Permalink
fix(check-examples): only exclude optional initial space from descr…
Browse files Browse the repository at this point in the history
…iption, not initial newline (needed for line counts, and rules)

Also updates tests to indicate expected line number
  • Loading branch information
brettz9 committed Nov 30, 2019
1 parent df83290 commit 0e89cc8
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 2 deletions.
2 changes: 1 addition & 1 deletion README.md
Expand Up @@ -908,7 +908,7 @@ function quux2 () {
function quux2 () {

}
// Message: @example warning (id-length): Identifier name 'i' is too short (< 2).
// Message: @example error (no-multiple-empty-lines): Too many blank lines at the beginning of file. Max of 0 allowed.

/**
* @example const i = 5;
Expand Down
2 changes: 1 addition & 1 deletion src/iterateJsdoc.js
Expand Up @@ -54,7 +54,7 @@ const parseComment = (commentNode, indent, trim = true) => {
}

// Tweak original regex to capture only single optional space
const result = str.match(/^\s?((.|\s)+)?/u);
const result = str.match(/^ ?((.|\s)+)?/u);

// Always has at least whitespace due to `indent` we've added
/* istanbul ignore next */
Expand Down
38 changes: 38 additions & 0 deletions test/rules/assertions/checkExamples.js
Expand Up @@ -11,9 +11,11 @@ export default {
`,
errors: [
{
line: 3,
message: '@example error (no-alert): Unexpected alert.',
},
{
line: 3,
message: '@example error (semi): Missing semicolon.',
},
],
Expand All @@ -38,9 +40,11 @@ export default {
`,
errors: [
{
line: 3,
message: '@example error (no-alert): Unexpected alert.',
},
{
line: 3,
message: '@example error (semi): Missing semicolon.',
},
],
Expand All @@ -67,6 +71,7 @@ export default {
`,
errors: [
{
line: 4,
message: '@example error (semi): Extra semicolon.',
},
],
Expand All @@ -93,6 +98,7 @@ export default {
`,
errors: [
{
line: 5,
message: '@example error (semi): Extra semicolon.',
},
],
Expand All @@ -118,6 +124,7 @@ export default {
`,
errors: [
{
line: 4,
message: '@example error (semi): Extra semicolon.',
},
],
Expand All @@ -143,6 +150,7 @@ export default {
`,
errors: [
{
line: 4,
message: '@example error (semi): Extra semicolon.',
},
],
Expand Down Expand Up @@ -173,6 +181,7 @@ export default {
`,
errors: [
{
line: 9,
message: '@example error (semi): Extra semicolon.',
},
],
Expand All @@ -198,6 +207,7 @@ export default {
`,
errors: [
{
line: 4,
message: '@example error (no-undef): \'quux\' is not defined.',
},
],
Expand Down Expand Up @@ -226,6 +236,7 @@ export default {
`,
errors: [
{
line: 6,
message: 'Caption is expected for examples.',
},
],
Expand All @@ -245,6 +256,7 @@ export default {
`,
errors: [
{
line: 3,
message: '@example error (indent): Expected indentation of 0 spaces but found 1.',
},
],
Expand All @@ -267,6 +279,7 @@ export default {
`,
errors: [
{
line: 3,
message: '@example error: Unused eslint-disable directive (no problems were reported from \'semi\').',
},
],
Expand All @@ -286,6 +299,7 @@ export default {
`,
errors: [
{
line: 4,
message: '@example error (semi): Missing semicolon.',
},
],
Expand All @@ -312,9 +326,11 @@ export default {
`,
errors: [
{
line: 3,
message: '@example warning (id-length): Identifier name \'i\' is too short (< 2).',
},
{
line: 4,
message: '@example error (semi): Missing semicolon.',
},
],
Expand All @@ -334,9 +350,11 @@ export default {
`,
errors: [
{
line: 3,
message: '@example warning (id-length): Identifier name \'i\' is too short (< 2).',
},
{
line: 4,
message: '@example error (semi): Missing semicolon.',
},
],
Expand All @@ -359,9 +377,15 @@ export default {
`,
errors: [
{
line: 3,
message: '@example error (no-multiple-empty-lines): Too many blank lines at the beginning of file. Max of 0 allowed.',
},
{
line: 4,
message: '@example warning (id-length): Identifier name \'i\' is too short (< 2).',
},
{
line: 5,
message: '@example error (semi): Missing semicolon.',
},
],
Expand All @@ -378,6 +402,7 @@ export default {
`,
errors: [
{
line: 4,
message: '@example error (semi): Missing semicolon.',
},
],
Expand All @@ -398,6 +423,7 @@ export default {
`,
errors: [
{
line: 4,
message: '@example warning (semi): Missing semicolon.',
},
],
Expand All @@ -423,33 +449,43 @@ export default {
`,
errors: [
{
line: 1,
message: '`settings.jsdoc.captionRequired` has been removed, use options in the rule `check-examples` instead.',
},
{
line: 1,
message: '`settings.jsdoc.exampleCodeRegex` has been removed, use options in the rule `check-examples` instead.',
},
{
line: 1,
message: '`settings.jsdoc.rejectExampleCodeRegex` has been removed, use options in the rule `check-examples` instead.',
},
{
line: 1,
message: '`settings.jsdoc.allowInlineConfig` has been removed, use options in the rule `check-examples` instead.',
},
{
line: 1,
message: '`settings.jsdoc.noDefaultExampleRules` has been removed, use options in the rule `check-examples` instead.',
},
{
line: 1,
message: '`settings.jsdoc.matchingFileName` has been removed, use options in the rule `check-examples` instead.',
},
{
line: 1,
message: '`settings.jsdoc.configFile` has been removed, use options in the rule `check-examples` instead.',
},
{
line: 1,
message: '`settings.jsdoc.eslintrcForExamples` has been removed, use options in the rule `check-examples` instead.',
},
{
line: 1,
message: '`settings.jsdoc.baseConfig` has been removed, use options in the rule `check-examples` instead.',
},
{
line: 1,
message: '`settings.jsdoc.reportUnusedDisableDirectives` has been removed, use options in the rule `check-examples` instead.',
},
],
Expand Down Expand Up @@ -478,6 +514,7 @@ export default {
`,
errors: [
{
line: 4,
message: 'Caption is expected for examples.',
},
],
Expand All @@ -499,6 +536,7 @@ export default {
`,
errors: [
{
line: 4,
message: '@example error (semi): Missing semicolon.',
},
],
Expand Down

0 comments on commit 0e89cc8

Please sign in to comment.