Skip to content

Commit 4aca635

Browse files
committed
Merge branch 'master' into add-more-type-checks-to-valid-types
* master: chore: report unused disable directives in eslint refactor: remove unused disable directives fix(require-jsdoc): avoid exported functions possessing jsdoc blocks causing other non-public functions to be treated as exported; fixes gajus#358 refactor(require-jsdoc): remove redundant check docs(require-returns): Fix typo chore: update devDeps; avoid `lint-staged` Add type "symbol" to noUndefinedTypes chore: update `lint-staged` for husky issue: typicode/husky#247 chore(CI): stop running broken npm script `check-readme` fix(no-undefined-types): avoid `flat-map-polyfill` entirely; further further fix for gajus#366 fix(check-tag-names): ensure `replacement` field overrides a default tag name preference; fixes gajus#367 chore: update comment-parser dep. and devDeps; avoid buggy eslint6.2 and for eslint 6 tests, avoid breaking typescript-eslint/parser update fix(`no-undefined-types`): import flat-map polyfill directly to avoid renamed `flatten` method from polluting prototype (gajus#366)
2 parents cb02b85 + 112f244 commit 4aca635

File tree

13 files changed

+78
-32
lines changed

13 files changed

+78
-32
lines changed

.README/rules/require-returns.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ Will also report if multiple `@returns` tags are present.
1515
- `forceReturnsWithAsync` - By default `async` functions that do not explicitly return a value pass this rule. You can force all `async` functions to require return statements by setting `forceReturnsWithAsync` to `true` on the options object. This may be useful as an `async` function will always return a `Promise`, even if the `Promise` returns void. Defaults to `false`.
1616

1717
```js
18-
'jsdoc/require-jsdoc': ['error', {forceReturnsWithAsync: true}]
18+
'jsdoc/require-returns': ['error', {forceReturnsWithAsync: true}]
1919
```
2020

2121
|||

.travis.yml

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,14 @@ node_js:
77
before_install:
88
- npm config set depth 0
99
before_script:
10-
- 'if [ "${ESLINT-}" == "6" ]; then npm install --no-save "eslint@${ESLINT}" ; fi'
11-
- 'if [ "${ESLINT-}" == "5" ]; then npm install --no-save "eslint@${ESLINT}" [email protected] [email protected] ; fi'
10+
- 'if [ "${ESLINT-}" == "6" ]; then npm install --no-save "eslint@${ESLINT}.1" ; fi'
11+
- 'if [ "${ESLINT-}" == "5" ]; then npm install --no-save "eslint@${ESLINT}" [email protected] [email protected] @typescript-eslint/[email protected] ; fi'
1212
notifications:
1313
email: false
1414
sudo: false
1515
script:
1616
- npm run test
1717
- 'if [ -n "${LINT-}" ]; then npm run lint; fi'
18-
- 'if [ -n "${CHECK_README-}" ]; then npm run check-readme; fi'
1918
- npm run build
2019
env:
2120
matrix:
@@ -26,8 +25,6 @@ matrix:
2625
include:
2726
- node_js: 'lts/*'
2827
env: LINT=true
29-
- node_js: 'lts/*'
30-
env: CHECK_README=true
3128
exclude:
3229
- node_js: 6
3330
env: ESLINT=6

README.md

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1550,6 +1550,14 @@ function quux (foo) {
15501550
function quux () {
15511551

15521552
}
1553+
1554+
/**
1555+
* @extends Foo
1556+
*/
1557+
function quux () {
1558+
1559+
}
1560+
// Settings: {"jsdoc":{"tagNamePreference":{"augments":{"message":"@extends is to be used over @augments.","replacement":"extends"}}}}
15531561
````
15541562

15551563

@@ -5630,6 +5638,15 @@ const myObject = {
56305638
myProp: true
56315639
};
56325640
// Options: [{"contexts":[]}]
5641+
5642+
function bear() {}
5643+
/**
5644+
*
5645+
*/
5646+
function quux () {
5647+
}
5648+
export default quux;
5649+
// Options: [{"publicOnly":true,"require":{"FunctionExpression":true}}]
56335650
````
56345651

56355652

@@ -6860,7 +6877,7 @@ Will also report if multiple `@returns` tags are present.
68606877
- `forceReturnsWithAsync` - By default `async` functions that do not explicitly return a value pass this rule. You can force all `async` functions to require return statements by setting `forceReturnsWithAsync` to `true` on the options object. This may be useful as an `async` function will always return a `Promise`, even if the `Promise` returns void. Defaults to `false`.
68616878

68626879
```js
6863-
'jsdoc/require-jsdoc': ['error', {forceReturnsWithAsync: true}]
6880+
'jsdoc/require-returns': ['error', {forceReturnsWithAsync: true}]
68646881
```
68656882

68666883
|||

package.json

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,8 @@
55
"url": "http://gajus.com"
66
},
77
"dependencies": {
8-
"comment-parser": "^0.6.1",
8+
"comment-parser": "^0.6.2",
99
"debug": "^4.1.1",
10-
"flat-map-polyfill": "^0.3.8",
1110
"jsdoctypeparser": "5.0.1",
1211
"lodash": "^4.17.15",
1312
"object.entries-ponyfill": "^1.0.1",
@@ -21,19 +20,19 @@
2120
"@babel/plugin-transform-flow-strip-types": "^7.4.4",
2221
"@babel/preset-env": "^7.5.5",
2322
"@babel/register": "^7.5.5",
24-
"@typescript-eslint/parser": "^1.13.0",
25-
"babel-eslint": "^10.0.2",
23+
"@typescript-eslint/parser": "^2.0.0",
24+
"babel-eslint": "^10.0.3",
2625
"babel-plugin-add-module-exports": "^1.0.2",
2726
"babel-plugin-istanbul": "^5.2.0",
2827
"chai": "^4.2.0",
29-
"eslint": "^6.1.0",
30-
"eslint-config-canonical": "^17.3.4",
28+
"eslint": "6.2.2",
29+
"eslint-config-canonical": "^17.4.0",
3130
"gitdown": "^3.1.1",
3231
"glob": "^7.1.4",
33-
"husky": "^3.0.3",
32+
"husky": "^3.0.4",
3433
"mocha": "^6.2.0",
3534
"nyc": "^14.1.1",
36-
"semantic-release": "^15.13.19",
35+
"semantic-release": "^15.13.24",
3736
"typescript": "^3.5.3"
3837
},
3938
"engines": {
@@ -63,8 +62,8 @@
6362
"build": "rm -fr ./dist && NODE_ENV=production babel ./src --out-dir ./dist --copy-files --source-maps",
6463
"check-readme": "babel-node ./src/bin/generateReadme.js --check",
6564
"create-readme": "babel-node ./src/bin/generateReadme.js",
66-
"lint-fix": "eslint --fix ./src ./test",
67-
"lint": "eslint ./src ./test",
65+
"lint-fix": "eslint --report-unused-disable-directives --fix ./src ./test",
66+
"lint": "eslint --report-unused-disable-directives ./src ./test",
6867
"test-cov": "BABEL_ENV=test nyc mocha --recursive --require @babel/register --reporter progress --timeout 9000",
6968
"test-no-cov": "BABEL_ENV=test mocha --recursive --require @babel/register --reporter progress --timeout 9000",
7069
"test-index": "BABEL_ENV=test mocha --recursive --require @babel/register --reporter progress --timeout 9000 test/rules/index.js",

src/eslint/getJSDocComment.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ const looksLikeExport = function (astNode) {
2626
astNode.type === 'ExportAllDeclaration' || astNode.type === 'ExportSpecifier';
2727
};
2828

29-
/* eslint-disable complexity */
3029
/**
3130
* Retrieves the JSDoc comment for a given node.
3231
*
@@ -107,6 +106,5 @@ const getJSDocComment = function (sourceCode, node, settings) {
107106
return findJSDocComment(node);
108107
}
109108
};
110-
/* eslint-enable complexity */
111109

112110
export default getJSDocComment;

src/exportParser.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -340,9 +340,7 @@ const findExportedNode = function (block, node, cache) {
340340
if (Object.prototype.hasOwnProperty.call(props, key)) {
341341
blockCache.push(props[key]);
342342
if (props[key].exported) {
343-
// If not always true, we need a test
344-
/* istanbul ignore next */
345-
if (findNode(node, block)) {
343+
if (node === props[key].value || findNode(node, props[key].value)) {
346344
return true;
347345
}
348346
}

src/jsdocUtils.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,10 @@ const getJsdocParameterNames = (jsdoc : Object, targetTagName : string) : Array<
6161
};
6262

6363
const getPreferredTagName = (name : string, tagPreference : Object = {}) : string => {
64-
if (_.values(tagPreference).includes(name)) {
64+
const prefValues = _.values(tagPreference);
65+
if (prefValues.includes(name) || prefValues.some((prefVal) => {
66+
return prefVal && typeof prefVal === 'object' && prefVal.replacement === name;
67+
})) {
6568
return name;
6669
}
6770

src/rules/noUndefinedTypes.js

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,12 @@
1-
// eslint-disable-next-line import/no-unassigned-import
2-
import 'flat-map-polyfill';
31
import _ from 'lodash';
42
import {parse as parseType, traverse} from 'jsdoctypeparser';
53
import iterateJsdoc, {parseComment} from '../iterateJsdoc';
64
import jsdocUtils from '../jsdocUtils';
75

86
const extraTypes = [
9-
'null', 'undefined', 'string', 'boolean', 'object',
7+
'null', 'undefined', 'string', 'symbol', 'boolean', 'object',
108
'function',
11-
'number', 'NaN', 'Infinity',
9+
'number', 'bigint', 'NaN', 'Infinity',
1210
'any', '*',
1311
'Array', 'Object', 'RegExp', 'Date', 'Function',
1412
];
@@ -78,7 +76,7 @@ export default iterateJsdoc(({
7876
);
7977
}
8078

81-
const closureGenericTypes = templateTags.flatMap((tag) => {
79+
const closureGenericTypes = _.flatMap(templateTags, (tag) => {
8280
return jsdocUtils.parseClosureTemplateTag(tag);
8381
});
8482

src/rules/requireJsdoc.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ export default {
182182
const parseResult = exportParser.parse(sourceCode.ast, node, opt);
183183
const exported = exportParser.isExported(node, parseResult, opt);
184184

185-
if (exported && !jsDocNode) {
185+
if (exported) {
186186
context.report({
187187
fix,
188188
messageId: 'missingJsDoc',

src/rules/requireParam.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import iterateJsdoc from '../iterateJsdoc';
22

3-
// eslint-disable-next-line complexity
43
export default iterateJsdoc(({
54
report,
65
utils,

test/rules/assertions/checkExamples.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
/* eslint-disable no-restricted-syntax */
2-
31
export default {
42
invalid: [
53
{

test/rules/assertions/checkTagNames.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -517,5 +517,25 @@ export default {
517517
}
518518
`,
519519
},
520+
{
521+
code: `
522+
/**
523+
* @extends Foo
524+
*/
525+
function quux () {
526+
527+
}
528+
`,
529+
settings: {
530+
jsdoc: {
531+
tagNamePreference: {
532+
augments: {
533+
message: '@extends is to be used over @augments.',
534+
replacement: 'extends',
535+
},
536+
},
537+
},
538+
},
539+
},
520540
],
521541
};

test/rules/assertions/requireJsdoc.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2163,5 +2163,24 @@ export default {
21632163
contexts: [],
21642164
},
21652165
],
2166+
}, {
2167+
code: `
2168+
function bear() {}
2169+
/**
2170+
*
2171+
*/
2172+
function quux () {
2173+
}
2174+
export default quux;
2175+
`,
2176+
options: [{
2177+
publicOnly: true,
2178+
require: {
2179+
FunctionExpression: true,
2180+
},
2181+
}],
2182+
parserOptions: {
2183+
sourceType: 'module',
2184+
},
21662185
}],
21672186
};

0 commit comments

Comments
 (0)