Skip to content

Commit 519bf87

Browse files
committed
Merge branch 'master' into 177-support-ts-param-props
* master: (22 commits) docs(code comment): make reference to @template being non-standard tag docs(contributing): clarify reasons for adhering to AngularJS syntax testing: add back timeouts as still occasionally timing out docs(contributing): note on merging chore: add `.ncurc.js` to avoid `npm-check-updates` indicating `peerDependencies` (with `eslint`) having update available build: add test for eslint@5 in ci chore: update `eslint` in `peerDependencies` to 6.0.0 chore: bump .travis.yml to use node 10 over 6 docs: generate docs chore: add `.ncurc.js` to avoid `npm-check-updates` indicating `peerDependencies` (with `eslint`) having update available fix(require-jsdoc): with eslint 6, we can't use schema for defaults, so revert to old approach chore(linting): update eslint devDep testing: avoid timeout (not an issue anymore with eslint 6) testing(check-examples): use absolute paths with `matchingFileName` (used with `getConfigForFile`/`Linter`) per eslint 6 testing(check-examples): use a simple `matchingFileName` file which doesn't have problem with loading `babel-eslint` in eslint 6 as does our config testing(require-param): use absolute paths with `parser` per eslint 6 docs(testing): add info on test coverage testing: increase timeout to 7000ms for rare occasion goes over 5000 testing: require `check-coverage` and set branches/lines/statements to 95% until `exportParser.js` coverage may be added docs: generate docs Add a negative test case for interface classes in require-returns-check docs: generate docs Skip interface class methods in require-returns-check docs: generate docs Add invalid test cases for generic types Simplify by using `flatMap` docs: generate docs Parse multiple template types in one tag docs: generate docs ...
2 parents 6019502 + 68c6cd6 commit 519bf87

24 files changed

+398
-120
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,4 @@ package-lock.json
1111
!.npmignore
1212
!.README
1313
!.travis.yml
14+
!.ncurc.js

.ncurc.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
module.exports = {
2+
// Whitelist all for checking besides `peer` which indicates
3+
// somewhat older versions of `eslint` we still support even
4+
// while our devDeps point to a more recent version
5+
"dep": "prod,dev,optional,bundle"
6+
};

.travis.yml

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,32 @@
11
language: node_js
22
node_js:
3-
- node
3+
- 12
4+
- 10
45
- 8
56
- 6
67
before_install:
78
- npm config set depth 0
9+
before_script:
10+
- 'if [ -n "${ESLINT-}" ]; then npm install --no-save "eslint@${ESLINT}" ; fi'
811
notifications:
912
email: false
1013
sudo: false
1114
script:
1215
- npm run test
13-
- npm run lint
16+
- 'if [ -n "${LINT-}" ]; then npm run lint; fi'
1417
- npm run build
18+
env:
19+
matrix:
20+
- ESLINT=6
21+
- ESLINT=5
22+
matrix:
23+
fast_finish: true
24+
include:
25+
- node_js: 'lts/*'
26+
env: LINT=true
27+
exclude:
28+
- node_js: 6
29+
env: ESLINT=6
1530
after_success:
1631
- export NODE_ENV=production
1732
- npm run build

CONTRIBUTING.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,11 @@ See ESLint's [RuleTester](https://eslint.org/docs/developer-guide/nodejs-api#rul
4343
for more on the allowable properties (e.g., `code`, `errors` (for invalid rules),
4444
`options`, `settings`, etc.).
4545

46+
Note that besides `npm test`, there is `npm run test-cov` which shows more detailed
47+
information on coverage. Coverage should be maintained at 100%, and if there are
48+
a few guards in place for future use, the code block in question can be ignored
49+
by being preceded by `/* istanbul ignore next */`.
50+
4651
## Requirements for PRs
4752

4853
PRs should be mergeable, [rebasing](https://git-scm.com/book/en/v2/Git-Branching-Rebasing)
@@ -53,3 +58,12 @@ can better show a progression of features.
5358

5459
Commit messages should be worded clearly and the reason for any PR made clear
5560
by linking to an issue or giving a full description of what it achieves.
61+
62+
## Merging
63+
64+
We use [semantic-release](https://github.com/semantic-release/semantic-release)
65+
for preparing releases, so the commit messages (or at least the merge that
66+
brings them into `master`) must follow the
67+
[AngularJS commit guidelines](https://github.com/angular/angular.js/blob/master/DEVELOPERS.md#-git-commit-guidelines) with a special format such as `feat: describe new feature`
68+
in order for the releasing to occur and for the described items to be added
69+
to the release notes.

README.md

Lines changed: 73 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -678,7 +678,7 @@ function quux () {}
678678
function quux2 () {
679679

680680
}
681-
// Settings: {"jsdoc":{"matchingFileName":"test/jsdocUtils.js"}}
681+
// Settings: {"jsdoc":{"matchingFileName":"/Users/brett/eslint-plugin-jsdoc/test/rules/data/test.js"}}
682682
// Message: @example error (semi): Missing semicolon.
683683

684684
/**
@@ -2791,6 +2791,35 @@ function quux(foo, bar, baz) {
27912791
// Settings: {"jsdoc":{"preferredTypes":{"hertype":{"replacement":false},"histype":"HisType"}}}
27922792
// Options: [{"definedTypes":["MyType"],"preferredTypesDefined":true}]
27932793
// Message: The type 'HerType' is undefined.
2794+
2795+
class Foo {
2796+
/**
2797+
* @return {TEMPLATE_TYPE}
2798+
*/
2799+
bar () {
2800+
}
2801+
}
2802+
// Message: The type 'TEMPLATE_TYPE' is undefined.
2803+
2804+
class Foo {
2805+
/**
2806+
* @return {TEMPLATE_TYPE}
2807+
*/
2808+
invalidTemplateReference () {
2809+
}
2810+
}
2811+
2812+
/**
2813+
* @template TEMPLATE_TYPE
2814+
*/
2815+
class Bar {
2816+
/**
2817+
* @return {TEMPLATE_TYPE}
2818+
*/
2819+
validTemplateReference () {
2820+
}
2821+
}
2822+
// Message: The type 'TEMPLATE_TYPE' is undefined.
27942823
````
27952824

27962825
The following patterns are not considered problems:
@@ -2941,6 +2970,29 @@ function quux(foo, bar, baz) {
29412970
}
29422971
// Settings: {"jsdoc":{"preferredTypes":{"hertype":{"replacement":"HerType<>"},"histype":"HisType.<>"}}}
29432972
// Options: [{"definedTypes":["MyType"],"preferredTypesDefined":true}]
2973+
2974+
/**
2975+
* @template TEMPLATE_TYPE
2976+
*/
2977+
class Foo {
2978+
/**
2979+
* @return {TEMPLATE_TYPE}
2980+
*/
2981+
bar () {
2982+
}
2983+
}
2984+
2985+
/**
2986+
* @template TEMPLATE_TYPE_A, TEMPLATE_TYPE_B
2987+
*/
2988+
class Foo {
2989+
/**
2990+
* @param {TEMPLATE_TYPE_A} baz
2991+
* @return {TEMPLATE_TYPE_B}
2992+
*/
2993+
bar (baz) {
2994+
}
2995+
}
29442996
````
29452997

29462998

@@ -5016,6 +5068,15 @@ const language = {
50165068
}
50175069
}
50185070
// Message: JSDoc @returns declaration present but return expression not available in function.
5071+
5072+
class Foo {
5073+
/**
5074+
* @returns {string}
5075+
*/
5076+
bar () {
5077+
}
5078+
}
5079+
// Message: JSDoc @returns declaration present but return expression not available in function.
50195080
````
50205081

50215082
The following patterns are not considered problems:
@@ -5104,6 +5165,17 @@ function quux () {
51045165
function quux () {
51055166
}
51065167

5168+
/**
5169+
* @interface
5170+
*/
5171+
class Foo {
5172+
/**
5173+
* @returns {string}
5174+
*/
5175+
bar () {
5176+
}
5177+
}
5178+
51075179
/**
51085180
* @returns {undefined} Foo.
51095181
*/

package.json

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
"babel-plugin-add-module-exports": "^1.0.2",
2525
"babel-plugin-istanbul": "^5.1.4",
2626
"chai": "^4.2.0",
27-
"eslint": "^5.14.1",
27+
"eslint": "^6.0.0",
2828
"eslint-config-canonical": "^17.1.1",
2929
"gitdown": "^2.5.8",
3030
"glob": "^7.1.4",
@@ -54,7 +54,7 @@
5454
"main": "./dist/index.js",
5555
"name": "eslint-plugin-jsdoc",
5656
"peerDependencies": {
57-
"eslint": ">=5.16.0"
57+
"eslint": "^5.0.0 || ^6.0.0"
5858
},
5959
"repository": {
6060
"type": "git",
@@ -65,8 +65,8 @@
6565
"build": "rm -fr ./dist && NODE_ENV=production babel ./src --out-dir ./dist --copy-files --source-maps",
6666
"create-readme": "gitdown ./.README/README.md --output-file ./README.md && npm run add-assertions",
6767
"lint": "eslint ./src ./test",
68-
"test-cov": "BABEL_ENV=test nyc mocha --recursive --require @babel/register --reporter progress --timeout 5000",
69-
"test": "BABEL_ENV=test nyc --reporter text-summary mocha --recursive --require @babel/register --reporter progress --timeout 5000"
68+
"test-cov": "BABEL_ENV=test nyc mocha --recursive --require @babel/register --reporter progress --timeout 7000",
69+
"test": "BABEL_ENV=test nyc --reporter text-summary mocha --recursive --require @babel/register --reporter progress --timeout 7000"
7070
},
7171
"nyc": {
7272
"require": [
@@ -76,7 +76,12 @@
7676
"instrument": false,
7777
"include": [
7878
"src/"
79-
]
79+
],
80+
"check-coverage": true,
81+
"branches": 95,
82+
"lines": 95,
83+
"functions": 100,
84+
"statements": 95
8085
},
8186
"version": "1.0.0"
8287
}

src/iterateJsdoc.js

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -189,20 +189,23 @@ const curryUtils = (
189189
return false;
190190
};
191191

192-
utils.classHasTag = (tagName) => {
192+
utils.getClassJsdoc = () => {
193193
const classNode = utils.getClassNode();
194194
const classJsdocNode = getJSDocComment(sourceCode, classNode);
195195

196196
if (classJsdocNode) {
197197
const indent = _.repeat(' ', classJsdocNode.loc.start.column);
198-
const classJsdoc = parseComment(classJsdocNode, indent);
199198

200-
if (jsdocUtils.hasTag(classJsdoc, tagName)) {
201-
return true;
202-
}
199+
return parseComment(classJsdocNode, indent);
203200
}
204201

205-
return false;
202+
return null;
203+
};
204+
205+
utils.classHasTag = (tagName) => {
206+
const classJsdoc = utils.getClassJsdoc();
207+
208+
return classJsdoc && jsdocUtils.hasTag(classJsdoc, tagName);
206209
};
207210

208211
utils.forEachTag = (tagName, arrayHandler) => {

src/jsdocUtils.js

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -467,6 +467,22 @@ const isInlineTag = (tag) => {
467467
};
468468
*/
469469

470+
/**
471+
* Parses GCC Generic/Template types
472+
*
473+
* @see {https://github.com/google/closure-compiler/wiki/Generic-Types}
474+
* @param {JsDocTag} tag
475+
* @returns {Array<string>}
476+
*/
477+
const parseClosureTemplateTag = (tag) => {
478+
return tag.source
479+
.split('@template')[1]
480+
.split(',')
481+
.map((type) => {
482+
return type.trim();
483+
});
484+
};
485+
470486
export default {
471487
getFunctionParameterNames,
472488
getJsdocParameterNames,
@@ -480,5 +496,6 @@ export default {
480496
isNamepathTag,
481497
isPotentiallyEmptyNamepathTag,
482498
isTagWithType,
483-
isValidTag
499+
isValidTag,
500+
parseClosureTemplateTag
484501
};

src/rules/newlineAfterDescription.js

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -56,12 +56,12 @@ export default iterateJsdoc(({
5656
}, {
5757
meta: {
5858
fixable: 'whitespace',
59+
schema: [
60+
{
61+
enum: ['always', 'never'],
62+
type: 'string'
63+
}
64+
],
5965
type: 'layout'
60-
},
61-
schema: [
62-
{
63-
enum: ['always'],
64-
type: 'string'
65-
}
66-
]
66+
}
6767
});

src/rules/noUndefinedTypes.js

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import 'flat-map-polyfill';
33
import _ from 'lodash';
44
import {parse as parseType, traverse} from 'jsdoctypeparser';
55
import iterateJsdoc, {parseComment} from '../iterateJsdoc';
6+
import jsdocUtils from '../jsdocUtils';
67

78
const extraTypes = [
89
'null', 'undefined', 'string', 'boolean', 'object',
@@ -67,6 +68,18 @@ export default iterateJsdoc(({
6768
})
6869
.value();
6970

71+
let closureGenericTypes = [];
72+
const classJsdoc = utils.getClassJsdoc();
73+
if (classJsdoc && classJsdoc.tags) {
74+
closureGenericTypes = classJsdoc.tags
75+
.filter((tag) => {
76+
return tag.tag === 'template';
77+
})
78+
.flatMap((tag) => {
79+
return jsdocUtils.parseClosureTemplateTag(tag);
80+
});
81+
}
82+
7083
const allDefinedTypes = globalScope.variables.map((variable) => {
7184
return variable.name;
7285
})
@@ -89,7 +102,8 @@ export default iterateJsdoc(({
89102
.concat(extraTypes)
90103
.concat(typedefDeclarations)
91104
.concat(definedTypes)
92-
.concat(definedPreferredTypes);
105+
.concat(definedPreferredTypes)
106+
.concat(closureGenericTypes);
93107

94108
const jsdocTags = utils.filterTags((tag) => {
95109
return utils.isTagWithType(tag.tag);

0 commit comments

Comments
 (0)