Skip to content

Commit 097c5d3

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

File tree

7 files changed

+34
-47
lines changed

7 files changed

+34
-47
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: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -10,18 +10,7 @@ node_js:
1010
before_install:
1111
- npm config set depth 0
1212
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
13+
npm install --legacy-peer-deps --no-save "eslint@${ESLINT}"
2514
notifications:
2615
email: false
2716
script:
@@ -30,16 +19,13 @@ script:
3019
- npm run build
3120
env:
3221
jobs:
22+
- ESLINT=8
3323
- ESLINT=7
34-
- ESLINT=6
3524
jobs:
3625
fast_finish: true
3726
include:
3827
- node_js: 'lts/*'
3928
env: LINT=true
40-
exclude:
41-
- node_js: 8
42-
env: ESLINT=7
4329
after_success:
4430
- export NODE_ENV=production
4531
- npm run build

README.md

Lines changed: 4 additions & 1 deletion
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.
@@ -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":["ClassProperty > Decorator[expression.callee.name=\"Input\"]"]}]
1291112914
// Message: Missing JSDoc comment.
1291212915

1291312916
requestAnimationFrame(draw)

package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -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-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",
@@ -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",

src/rules/checkExamples.js

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,5 @@
1-
// Todo: When peerDeps bump to ESLint 7, see about replacing `CLIEngine`
2-
// with non-deprecated `ESLint` class:
3-
// https://github.com/eslint/eslint/blob/master/docs/user-guide/migrating-to-7.0.0.md#-the-cliengine-class-has-been-deprecated
4-
import {
5-
CLIEngine,
6-
} from 'eslint';
1+
import { ESLint } from 'eslint';
2+
import semver from 'semver'
73
import iterateJsdoc from '../iterateJsdoc';
84

95
const zeroBasedLineIndexAdjust = -1;
@@ -85,6 +81,13 @@ export default iterateJsdoc(({
8581
context,
8682
globalState,
8783
}) => {
84+
if(semver.gte(ESLint.version, '8.0.0')) {
85+
return context.report({
86+
loc: { start: { column: 1, line: 1 } },
87+
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`,
88+
});
89+
}
90+
8891
if (!globalState.has('checkExamples-matchingFileName')) {
8992
globalState.set('checkExamples-matchingFileName', new Map());
9093
}
@@ -172,16 +175,16 @@ export default iterateJsdoc(({
172175
if (matchingFileNameMap.has(fileNameMapKey)) {
173176
cliFile = matchingFileNameMap.get(fileNameMapKey);
174177
} else {
175-
const cli = new CLIEngine(cliConfig);
178+
const cli = new ESLint(cliConfig);
176179
let config;
177180
if (filename || checkEslintrc) {
178-
config = cli.getConfigForFile(file);
181+
config = cli.calculateConfigForFile(file);
179182
}
180183

181184
// We need a new instance to ensure that the rules that may only
182185
// be available to `file` (if it has its own `.eslintrc`),
183186
// will be defined.
184-
cliFile = new CLIEngine({
187+
cliFile = new ESLint({
185188
allowInlineConfig,
186189
baseConfig: {
187190
...baseConfig,
@@ -196,8 +199,7 @@ export default iterateJsdoc(({
196199
matchingFileNameMap.set(fileNameMapKey, cliFile);
197200
}
198201

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

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

test/rules/assertions/requireJsdoc.js

Lines changed: 1 addition & 13 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
{
@@ -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: ['ClassProperty > Decorator[expression.callee.name="Input"]'],
30283016
}],
30293017
output: `
30303018
export class MyComponentComponent {

test/rules/index.js

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,18 @@
1-
import {
2-
RuleTester,
3-
} from 'eslint';
1+
import { ESLint, RuleTester } from 'eslint';
42
import _ from 'lodash';
3+
import semver from 'semver'
54
import config from '../../src';
65
import ruleNames from './ruleNames.json';
76

87
const ruleTester = new RuleTester();
98

109
(process.env.npm_config_rule ? process.env.npm_config_rule.split(',') : ruleNames).forEach(async (ruleName) => {
10+
if(semver.gte(ESLint.version, '8.0.0') && ruleName === 'check-examples') {
11+
// This rule cannot yet be supported for ESLint 8;
12+
// The possibility for ESLint 8 support is being tracked at https://github.com/eslint/eslint/issues/14745
13+
return;
14+
}
15+
1116
const rule = config.rules[ruleName];
1217

1318
const parserOptions = {

0 commit comments

Comments
 (0)