Skip to content

Commit 4418543

Browse files
committed
feat: support ESLint 8.x
BREAKING CHANGE: Requires ESLint@^7.0.0 || ^8.0.0
1 parent f0c1e44 commit 4418543

File tree

11 files changed

+97
-55
lines changed

11 files changed

+97
-55
lines changed

.README/rules/check-examples.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
### `check-examples`
22

3+
> **NOTE**: This rule currently does not work in ESLint 8 (we are waiting for
4+
> [issue 14745](https://github.com/eslint/eslint/issues/14745)).
5+
36
Ensures that (JavaScript) examples within JSDoc adhere to ESLint rules. Also
47
has options to lint the default values of optional `@param`/`@arg`/`@argument`
58
and `@property`/`@prop` tags or the values of `@default`/`@defaultvalue` tags.

.travis.yml

Lines changed: 6 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -9,37 +9,26 @@ node_js:
99

1010
before_install:
1111
- npm config set depth 0
12+
install:
13+
- echo "Avoid Travis's npm auto-install"
1214
before_script: >
13-
node_version=$(node -v);
14-
if [ ${node_version:3:1} = "." ]; then
15-
echo "Node 10+"
16-
if [ ${ESLINT} = "6" ]; then
17-
npm install --legacy-peer-deps --no-save "eslint@${ESLINT}" eslint-config-canonical@24.4.4
18-
else
19-
npm install --legacy-peer-deps --no-save "eslint@${ESLINT}"
20-
fi
21-
else
22-
echo "Node 8+"
23-
npm install --legacy-peer-deps --no-save "eslint@${ESLINT}" husky@3.1.0 semantic-release@15.14.0 eslint-config-canonical@18.1.1
24-
fi
15+
npm install --legacy-peer-deps --no-save "eslint@${ESLINT}"
2516
notifications:
2617
email: false
2718
script:
2819
- npm run test
29-
- 'if [ -n "${LINT-}" ]; then npm run lint; fi'
20+
# Disable until eslint-config-canonical fixed
21+
# - 'if [ -n "${LINT-}" ]; then npm run lint; fi'
3022
- npm run build
3123
env:
3224
jobs:
25+
- ESLINT=8
3326
- ESLINT=7
34-
- ESLINT=6
3527
jobs:
3628
fast_finish: true
3729
include:
3830
- node_js: 'lts/*'
3931
env: LINT=true
40-
exclude:
41-
- node_js: 8
42-
env: ESLINT=7
4332
after_success:
4433
- export NODE_ENV=production
4534
- npm run build

README.md

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -945,6 +945,9 @@ function quux (foo) {
945945
<a name="eslint-plugin-jsdoc-rules-check-examples"></a>
946946
### <code>check-examples</code>
947947

948+
> **NOTE**: This rule currently does not work in ESLint 8 (we are waiting for
949+
> [issue 14745](https://github.com/eslint/eslint/issues/14745)).
950+
948951
Ensures that (JavaScript) examples within JSDoc adhere to ESLint rules. Also
949952
has options to lint the default values of optional `@param`/`@arg`/`@argument`
950953
and `@property`/`@prop` tags or the values of `@default`/`@defaultvalue` tags.
@@ -6914,7 +6917,7 @@ class MyClass {
69146917
*/
69156918
myClassField = 1
69166919
}
6917-
// "jsdoc/match-description": ["error"|"warn", {"contexts":["ClassProperty"]}]
6920+
// "jsdoc/match-description": ["error"|"warn", {"contexts":["PropertyDefinition"]}]
69186921
// Message: JSDoc description does not satisfy the regex pattern.
69196922
69206923
/**
@@ -7182,7 +7185,7 @@ class MyClass {
71827185
*/
71837186
myClassField = 1
71847187
}
7185-
// "jsdoc/match-description": ["error"|"warn", {"contexts":["ClassProperty"]}]
7188+
// "jsdoc/match-description": ["error"|"warn", {"contexts":["PropertyDefinition"]}]
71867189
71877190
/**
71887191
* Foo.
@@ -12813,7 +12816,7 @@ class Animal {
1281312816
@SomeAnnotation('optionalParameter')
1281412817
tail: boolean;
1281512818
}
12816-
// "jsdoc/require-jsdoc": ["error"|"warn", {"contexts":["ClassProperty"]}]
12819+
// "jsdoc/require-jsdoc": ["error"|"warn", {"contexts":["PropertyDefinition"]}]
1281712820
// Message: Missing JSDoc comment.
1281812821

1281912822
@Entity('users')
@@ -12907,7 +12910,7 @@ export class MyComponentComponent {
1290712910
@Input()
1290812911
public value = new EventEmitter();
1290912912
}
12910-
// "jsdoc/require-jsdoc": ["error"|"warn", {"contexts":["ClassProperty:has(Decorator[expression.callee.name=\"Input\"])"]}]
12913+
// "jsdoc/require-jsdoc": ["error"|"warn", {"contexts":["PropertyDefinition > Decorator[expression.callee.name=\"Input\"]"]}]
1291112914
// Message: Missing JSDoc comment.
1291212915

1291312916
requestAnimationFrame(draw)
@@ -12951,6 +12954,12 @@ function comment () {
1295112954
}
1295212955
// "jsdoc/require-jsdoc": ["error"|"warn", {"enableFixer":false,"fixerMessage":" TODO: add comment"}]
1295312956
// Message: Missing JSDoc comment.
12957+
12958+
export class InovaAutoCompleteComponent {
12959+
public disabled = false;
12960+
}
12961+
// "jsdoc/require-jsdoc": ["error"|"warn", {"contexts":["PropertyDefinition"],"publicOnly":true}]
12962+
// Message: Missing JSDoc comment.
1295412963
````
1295512964

1295612965
The following patterns are not considered problems:

package.json

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
"url": "http://gajus.com"
66
},
77
"dependencies": {
8-
"@es-joy/jsdoccomment": "0.10.8",
8+
"@es-joy/jsdoccomment": "0.11.0",
99
"comment-parser": "1.2.4",
1010
"debug": "^4.3.2",
1111
"esquery": "^1.4.0",
@@ -26,12 +26,12 @@
2626
"@babel/preset-env": "^7.15.8",
2727
"@babel/register": "^7.15.3",
2828
"@hkdobrev/run-if-changed": "^0.3.1",
29-
"@typescript-eslint/parser": "^4.33.0",
29+
"@typescript-eslint/parser": "^5.0.0",
3030
"babel-plugin-add-module-exports": "^1.0.4",
3131
"babel-plugin-istanbul": "^6.0.0",
3232
"chai": "^4.3.4",
3333
"cross-env": "^7.0.3",
34-
"eslint": "7.32.0",
34+
"eslint": "^8.0.0",
3535
"eslint-config-canonical": "^28.0.0",
3636
"gitdown": "^3.1.4",
3737
"glob": "^7.2.0",
@@ -48,10 +48,10 @@
4848
"node": "^12 || ^14 || ^16"
4949
},
5050
"lint-staged": {
51-
".eslintignore": "npm run lint",
52-
"./*.js": "npm run lint-arg --",
53-
"src/**/*.js": "npm run lint-arg --",
54-
"test/**/*.js": "npm run lint-arg --"
51+
"DISABLE.eslintignore": "npm run lint",
52+
"DISABLE./*.js": "npm run lint-arg --",
53+
"DISABLEsrc/**/*.js": "npm run lint-arg --",
54+
"DISABLEtest/**/*.js": "npm run lint-arg --"
5555
},
5656
"run-if-changed": {
5757
"package-lock.json": "npm run install-offline"
@@ -65,7 +65,7 @@
6565
"main": "./dist/index.js",
6666
"name": "eslint-plugin-jsdoc",
6767
"peerDependencies": {
68-
"eslint": "^6.0.0 || ^7.0.0"
68+
"eslint": "^7.0.0 || ^8.0.0"
6969
},
7070
"repository": {
7171
"type": "git",
@@ -95,6 +95,9 @@
9595
"include": [
9696
"src/"
9797
],
98+
"exclude": [
99+
"src/rules/checkExamples.js"
100+
],
98101
"check-coverage": true,
99102
"branches": 100,
100103
"lines": 100,

src/iterateJsdoc.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -708,6 +708,8 @@ const makeReport = (context, commentNode) => {
708708
end: {line: lineNumber},
709709
start: {line: lineNumber},
710710
};
711+
// Todo: Remove once `check-examples` can be restored for ESLint 8+
712+
// istanbul ignore if
711713
if (jsdocLoc.column) {
712714
const colNumber = commentNode.loc.start.column + jsdocLoc.column;
713715

src/jsdocUtils.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -718,6 +718,9 @@ const hasNonEmptyResolverCall = (node, resolverName) => {
718718
case 'ObjectProperty':
719719
/* eslint-disable no-fallthrough */
720720
// istanbul ignore next -- In Babel?
721+
case 'PropertyDefinition':
722+
/* eslint-disable no-fallthrough */
723+
// istanbul ignore next -- In Babel?
721724
case 'ClassProperty':
722725
/* eslint-enable no-fallthrough */
723726
case 'Property':
@@ -907,6 +910,9 @@ const hasNonFunctionYield = (node, checkYieldReturnValue) => {
907910
return hasNonFunctionYield(property, checkYieldReturnValue);
908911
});
909912
913+
// istanbul ignore next -- In Babel?
914+
case 'PropertyDefinition':
915+
/* eslint-disable no-fallthrough */
910916
// istanbul ignore next -- In Babel?
911917
case 'ObjectProperty':
912918
/* eslint-disable no-fallthrough */

src/rules/checkExamples.js

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
// Todo: When peerDeps bump to ESLint 7, see about replacing `CLIEngine`
2-
// with non-deprecated `ESLint` class:
1+
// Todo: When replace `CLIEngine` with `ESLint` when feature set complete per https://github.com/eslint/eslint/issues/14745
32
// https://github.com/eslint/eslint/blob/master/docs/user-guide/migrating-to-7.0.0.md#-the-cliengine-class-has-been-deprecated
43
import {
5-
CLIEngine,
4+
CLIEngine, ESLint,
65
} from 'eslint';
6+
import semver from 'semver'
77
import iterateJsdoc from '../iterateJsdoc';
88

99
const zeroBasedLineIndexAdjust = -1;
@@ -85,6 +85,13 @@ export default iterateJsdoc(({
8585
context,
8686
globalState,
8787
}) => {
88+
if (semver.gte(ESLint.version, '8.0.0')) {
89+
return report({
90+
loc: { start: { column: 1, line: 1 } },
91+
message: `This rule cannot yet be supported for ESLint 8; you should either downgrade to ESLint 7 or disable this rule. The possibility for ESLint 8 support is being tracked at https://github.com/eslint/eslint/issues/14745`,
92+
});
93+
}
94+
8895
if (!globalState.has('checkExamples-matchingFileName')) {
8996
globalState.set('checkExamples-matchingFileName', new Map());
9097
}
@@ -196,8 +203,7 @@ export default iterateJsdoc(({
196203
matchingFileNameMap.set(fileNameMapKey, cliFile);
197204
}
198205

199-
const {results: [{messages}]} =
200-
cliFile.executeOnText(src);
206+
const {results: [{messages}]} = cliFile.executeOnText(src);
201207

202208
if (!('line' in tag)) {
203209
tag.line = tag.source[0].number;

src/rules/requireJsdoc.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -308,7 +308,7 @@ export default {
308308

309309
if (
310310
['VariableDeclarator', 'AssignmentExpression', 'ExportDefaultDeclaration'].includes(node.parent.type) ||
311-
['Property', 'ObjectProperty', 'ClassProperty'].includes(node.parent.type) && node === node.parent.value
311+
['Property', 'ObjectProperty', 'ClassProperty', 'PropertyDefinition'].includes(node.parent.type) && node === node.parent.value
312312
) {
313313
checkJsDoc({isFunctionContext: true}, null, node);
314314
}
@@ -351,7 +351,7 @@ export default {
351351

352352
if (
353353
['VariableDeclarator', 'AssignmentExpression', 'ExportDefaultDeclaration'].includes(node.parent.type) ||
354-
['Property', 'ObjectProperty', 'ClassProperty'].includes(node.parent.type) && node === node.parent.value
354+
['Property', 'ObjectProperty', 'ClassProperty', 'PropertyDefinition'].includes(node.parent.type) && node === node.parent.value
355355
) {
356356
checkJsDoc({isFunctionContext: true}, null, node);
357357
}

test/rules/assertions/matchDescription.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -794,7 +794,7 @@ export default {
794794
options: [
795795
{
796796
contexts: [
797-
'ClassProperty',
797+
'PropertyDefinition',
798798
],
799799
},
800800
],
@@ -1269,7 +1269,7 @@ export default {
12691269
options: [
12701270
{
12711271
contexts: [
1272-
'ClassProperty',
1272+
'PropertyDefinition',
12731273
],
12741274
},
12751275
],

test/rules/assertions/requireJsdoc.js

Lines changed: 33 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,6 @@
22
* @see https://github.com/eslint/eslint/blob/master/tests/lib/rules/require-jsdoc.js
33
*/
44

5-
import {
6-
CLIEngine,
7-
} from 'eslint';
8-
95
export default {
106
invalid: [
117
{
@@ -2591,7 +2587,7 @@ function quux (foo) {
25912587
],
25922588
options: [
25932589
{
2594-
contexts: ['ClassProperty'],
2590+
contexts: ['PropertyDefinition'],
25952591
},
25962592
],
25972593
output: `
@@ -3016,15 +3012,7 @@ function quux (foo) {
30163012
},
30173013
],
30183014
options: [{
3019-
contexts: [
3020-
// Only fixed to support `:has()` with TS later in ESLint 7, but
3021-
// for our testing of ESLint 6, we use `>` which is equivalent in
3022-
// this case; after having peerDeps. to ESLint 7+, we can remove
3023-
// this check and use of `CLIEngine`
3024-
CLIEngine.version.startsWith('6') ?
3025-
'ClassProperty > Decorator[expression.callee.name="Input"]' :
3026-
'ClassProperty:has(Decorator[expression.callee.name="Input"])',
3027-
],
3015+
contexts: ['PropertyDefinition > Decorator[expression.callee.name="Input"]'],
30283016
}],
30293017
output: `
30303018
export class MyComponentComponent {
@@ -3262,6 +3250,37 @@ function quux (foo) {
32623250
}
32633251
`,
32643252
},
3253+
{
3254+
code: `
3255+
export class InovaAutoCompleteComponent {
3256+
public disabled = false;
3257+
}
3258+
`,
3259+
errors: [
3260+
{
3261+
line: 3,
3262+
message: 'Missing JSDoc comment.',
3263+
}
3264+
],
3265+
options: [
3266+
{
3267+
contexts: ['PropertyDefinition'],
3268+
publicOnly: true,
3269+
},
3270+
],
3271+
output: `
3272+
export class InovaAutoCompleteComponent {
3273+
/**
3274+
*
3275+
*/
3276+
public disabled = false;
3277+
}
3278+
`,
3279+
parser: require.resolve('@typescript-eslint/parser'),
3280+
parserOptions: {
3281+
sourceType: 'module',
3282+
},
3283+
},
32653284
],
32663285
valid: [{
32673286
code: `

0 commit comments

Comments
 (0)