Skip to content

Commit a828002

Browse files
committed
Merge branch 'master' into ds/destructuring
* master: fix: in conjunction with `comment-parser` update, remove last line break in last tag description for proper stringification (and fix old tests) test(no-types): check the fix for no-types preserves asterisks fix(require-jsdoc): check above export for named exports; fixes gajus#526 # Conflicts: # test/rules/assertions/requireParam.js
2 parents 0013651 + fdf129b commit a828002

File tree

9 files changed

+91
-21
lines changed

9 files changed

+91
-21
lines changed

README.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5426,6 +5426,17 @@ function quux (foo) {
54265426
*/
54275427
function quux () {
54285428
5429+
}
5430+
// Message: Types are not permitted on @returns.
5431+
5432+
/**
5433+
* Beep
5434+
* Boop
5435+
*
5436+
* @returns {number}
5437+
*/
5438+
function quux () {
5439+
54295440
}
54305441
// Message: Types are not permitted on @returns.
54315442
````
@@ -8186,6 +8197,10 @@ const hello = name => {
81868197
};
81878198
// Options: [{"require":{"ArrowFunctionExpression":true,"FunctionDeclaration":false}}]
81888199
// Message: Missing JSDoc comment.
8200+
8201+
export const loginSuccessAction = (): BaseActionPayload => ({ type: LOGIN_SUCCESSFUL });
8202+
// Options: [{"require":{"ArrowFunctionExpression":true,"FunctionDeclaration":false}}]
8203+
// Message: Missing JSDoc comment.
81898204
````
81908205
81918206
The following patterns are not considered problems:

package.json

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
"url": "http://gajus.com"
66
},
77
"dependencies": {
8-
"comment-parser": "^0.7.2",
8+
"comment-parser": "^0.7.4",
99
"debug": "^4.1.1",
1010
"jsdoctypeparser": "^6.1.0",
1111
"lodash": "^4.17.15",
@@ -16,12 +16,12 @@
1616
"description": "JSDoc linting rules for ESLint.",
1717
"devDependencies": {
1818
"@babel/cli": "^7.8.4",
19-
"@babel/core": "^7.9.0",
19+
"@babel/core": "^7.9.6",
2020
"@babel/node": "^7.8.7",
2121
"@babel/plugin-transform-flow-strip-types": "^7.9.0",
22-
"@babel/preset-env": "^7.9.5",
22+
"@babel/preset-env": "^7.9.6",
2323
"@babel/register": "^7.9.0",
24-
"@typescript-eslint/parser": "^2.28.0",
24+
"@typescript-eslint/parser": "^2.31.0",
2525
"babel-eslint": "^10.1.0",
2626
"babel-plugin-add-module-exports": "^1.0.2",
2727
"babel-plugin-istanbul": "^6.0.0",
@@ -32,10 +32,10 @@
3232
"gitdown": "^3.1.3",
3333
"glob": "^7.1.6",
3434
"husky": "^4.2.5",
35-
"mocha": "^7.1.1",
35+
"mocha": "^7.1.2",
3636
"nyc": "^15.0.1",
3737
"rimraf": "^3.0.2",
38-
"semantic-release": "^17.0.6",
38+
"semantic-release": "^17.0.7",
3939
"typescript": "^3.8.3"
4040
},
4141
"engines": {

src/bin/generateReadme.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,9 @@ import glob from 'glob';
88
import Gitdown from 'gitdown';
99

1010
const trimCode = (code) => {
11-
let lines = code.replace(/^\n/u, '').trimEnd().split('\n');
11+
// todo[engine:node@>10]: Change to `trimEnd`
12+
// eslint-disable-next-line unicorn/prefer-trim-start-end
13+
let lines = code.replace(/^\n/u, '').trimRight().split('\n');
1214

1315
const firsLineIndentation = lines[0].match(/^\s+/u);
1416
const lastLineIndentation = lines[lines.length - 1].match(/^\s+/u);

src/eslint/getJSDocComment.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,11 @@ const getReducedASTNode = function (node, sourceCode) {
154154
}
155155
}
156156

157-
if (parent && parent.type !== 'FunctionDeclaration' && parent.type !== 'Program') {
157+
if (parent) {
158+
if (parent.parent.type === 'ExportNamedDeclaration') {
159+
return parent.parent;
160+
}
161+
158162
return parent;
159163
}
160164
}

src/iterateJsdoc.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,10 @@ const getUtils = (
154154

155155
utils.stringify = (tagBlock) => {
156156
const indent = jsdocUtils.getIndent(sourceCode);
157+
if (ruleConfig.noTrim) {
158+
const lastTag = tagBlock.tags[tagBlock.tags.length - 1];
159+
lastTag.description = lastTag.description.replace(/\n$/, '');
160+
}
157161

158162
return commentStringify([tagBlock], {indent}).slice(indent.length - 1);
159163
};

src/rules/noTypes.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,4 +36,5 @@ export default iterateJsdoc(({
3636
],
3737
type: 'suggestion',
3838
},
39+
noTrim: true,
3940
});

test/rules/assertions/noTypes.js

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,35 @@ export default {
124124
*/
125125
function quux () {
126126
127+
}
128+
`,
129+
},
130+
{
131+
code: `
132+
/**
133+
* Beep
134+
* Boop
135+
*
136+
* @returns {number}
137+
*/
138+
function quux () {
139+
140+
}
141+
`,
142+
errors: [
143+
{
144+
message: 'Types are not permitted on @returns.',
145+
},
146+
],
147+
output: `
148+
/**
149+
* Beep
150+
* Boop
151+
*
152+
* @returns
153+
*/
154+
function quux () {
155+
127156
}
128157
`,
129158
},

test/rules/assertions/requireJsdoc.js

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1384,6 +1384,34 @@ export default {
13841384
};
13851385
`,
13861386
},
1387+
{
1388+
code: `
1389+
export const loginSuccessAction = (): BaseActionPayload => ({ type: LOGIN_SUCCESSFUL });
1390+
`,
1391+
errors: [
1392+
{
1393+
message: 'Missing JSDoc comment.',
1394+
},
1395+
],
1396+
options: [
1397+
{
1398+
require: {
1399+
ArrowFunctionExpression: true,
1400+
FunctionDeclaration: false,
1401+
},
1402+
},
1403+
],
1404+
output: `
1405+
/**
1406+
*
1407+
*/
1408+
export const loginSuccessAction = (): BaseActionPayload => ({ type: LOGIN_SUCCESSFUL });
1409+
`,
1410+
parser: require.resolve('@typescript-eslint/parser'),
1411+
parserOptions: {
1412+
sourceType: 'module',
1413+
},
1414+
},
13871415
],
13881416
valid: [{
13891417
code: `

test/rules/assertions/requireParam.js

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -733,7 +733,6 @@ export default {
733733
interface ITest {
734734
/**
735735
* Test description.
736-
*
737736
* @param id
738737
*/
739738
TestMethod(id: number): void;
@@ -773,7 +772,6 @@ export default {
773772
{
774773
/**
775774
* A test method.
776-
*
777775
* @param id
778776
*/
779777
abstract TestFunction(id);
@@ -840,7 +838,6 @@ export default {
840838
output: `
841839
/**
842840
* A test function.
843-
*
844841
* @param id
845842
*/
846843
declare let TestFunction: (id) => void;
@@ -868,7 +865,6 @@ export default {
868865
output: `
869866
/**
870867
* A test function.
871-
*
872868
* @param id
873869
*/
874870
let TestFunction: (id) => void;
@@ -900,7 +896,6 @@ export default {
900896
output: `
901897
/**
902898
* A test function.
903-
*
904899
* @param id
905900
*/
906901
function test(
@@ -935,7 +930,6 @@ export default {
935930
output: `
936931
/**
937932
* A test function.
938-
*
939933
* @param id
940934
*/
941935
let test = (processor: (id: number) => string) =>
@@ -969,7 +963,6 @@ export default {
969963
class TestClass {
970964
/**
971965
* A class property.
972-
*
973966
* @param id
974967
*/
975968
public Test: (id: number) => string;
@@ -1003,7 +996,6 @@ export default {
1003996
class TestClass {
1004997
/**
1005998
* A class method.
1006-
*
1007999
* @param id
10081000
*/
10091001
public TestMethod(): (id: number) => string
@@ -1037,7 +1029,6 @@ export default {
10371029
interface TestInterface {
10381030
/**
10391031
* An interface property.
1040-
*
10411032
* @param id
10421033
*/
10431034
public Test: (id: number) => string;
@@ -1069,7 +1060,6 @@ export default {
10691060
interface TestInterface {
10701061
/**
10711062
* An interface method.
1072-
*
10731063
* @param id
10741064
*/
10751065
public TestMethod(): (id: number) => string;
@@ -1098,7 +1088,6 @@ export default {
10981088
output: `
10991089
/**
11001090
* A function with return type
1101-
*
11021091
* @param id
11031092
*/
11041093
function test(): (id: number) => string;
@@ -1129,7 +1118,6 @@ export default {
11291118
output: `
11301119
/**
11311120
* A function with return type
1132-
*
11331121
* @param id
11341122
*/
11351123
let test = (): (id: number) => string =>
@@ -1192,7 +1180,6 @@ export default {
11921180
class Client {
11931181
/**
11941182
* Set collection data.
1195-
*
11961183
* @param {Object} data The collection data object.
11971184
* @param {number} data.last_modified
11981185
* @param {Object} options The options object.

0 commit comments

Comments
 (0)