Skip to content
This repository was archived by the owner on May 12, 2025. It is now read-only.

Commit 19f5d53

Browse files
committed
fix eslint plugin issue
1 parent adb372a commit 19f5d53

File tree

7 files changed

+453
-39
lines changed

7 files changed

+453
-39
lines changed

.eslintrc.js

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,7 @@
11
module.exports = {
22
root: true,
3-
extends: [
4-
'airbnb-base',
5-
'plugin:prettier/recommended',
6-
'plugin:openapi/recommended',
7-
],
3+
extends: ['react-app', 'plugin:openapi/recommended'],
84
rules: {
9-
'func-names': 'off',
10-
'no-console': 'off',
11-
'object-shorthand': 'off',
5+
'no-var': 1,
126
},
137
};

.travis.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ node_js: 12
33

44
jobs:
55
include:
6+
- stage: lint
7+
script: yarn lint
68
- stage: test
79
script: yarn test
810
- stage: deploy

eslint-plugin-openapi/index.js

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ const tagToName = {
1616
security: 'security scheme name',
1717
};
1818

19+
const openAPIRegex = /^(GET|PUT|POST|DELETE|OPTIONS|HEAD|PATCH|TRACE) \/.*$/;
20+
1921
const missing = (context, comment, tag, name) => {
2022
const commentLines = comment.value.split(/\r\n|\r|\n/);
2123
const start = commentLines[tag.line].indexOf(`@${tag.tag}`);
@@ -56,13 +58,9 @@ const statusCodeUndefined = (context, comment, tag, status) => {
5658
});
5759
};
5860

59-
function parseErrors(comment, context) {
61+
function parseErrors(comment, jsDocComment, context) {
6062
const seenResponses = [];
6163

62-
const openAPIRegex = /^(GET|PUT|POST|DELETE|OPTIONS|HEAD|PATCH|TRACE) \/.*$/;
63-
64-
const [jsDocComment] = parseComments(`/*${comment.value}*/`);
65-
6664
if (openAPIRegex.test(jsDocComment.description)) {
6765
jsDocComment.tags.forEach((tag) => {
6866
// const commentLines = comment.value.split(/\r\n|\r|\n/);
@@ -226,11 +224,7 @@ function parseErrors(comment, context) {
226224
}
227225
}
228226

229-
function parse(comment, context) {
230-
const openAPIRegex = /^(GET|PUT|POST|DELETE|OPTIONS|HEAD|PATCH|TRACE) \/.*$/;
231-
232-
const [jsDocComment] = parseComments(`/*${comment.value}*/`);
233-
227+
function parse(comment, jsDocComment, context) {
234228
if (openAPIRegex.test(jsDocComment.description)) {
235229
const [method, path] = jsDocComment.description.split(' ');
236230

@@ -387,7 +381,10 @@ function getComments(cb) {
387381
node.comments
388382
.filter((comment) => comment.type === 'Block')
389383
.forEach((comment) => {
390-
cb(comment);
384+
const [jsDocComment] = parseComments(`/*${comment.value}*/`);
385+
if (jsDocComment) {
386+
cb(comment, jsDocComment);
387+
}
391388
});
392389
},
393390
};
@@ -397,15 +394,15 @@ module.exports = {
397394
rules: {
398395
errors: {
399396
create: function (context) {
400-
return getComments((comment) => {
401-
parseErrors(comment, context);
397+
return getComments((comment, jsDocComment) => {
398+
parseErrors(comment, jsDocComment, context);
402399
});
403400
},
404401
},
405402
warnings: {
406403
create: (context) => {
407-
return getComments((comment) => {
408-
parse(comment, context);
404+
return getComments((comment, jsDocComment) => {
405+
parse(comment, jsDocComment, context);
409406
});
410407
},
411408
},

eslint-plugin-openapi/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "eslint-plugin-openapi",
3-
"version": "0.0.3",
3+
"version": "0.0.4",
44
"main": "index.js",
55
"license": "MIT",
66
"scripts": {

example/src/routes/pet.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,12 @@ const { Router } = require('express');
22

33
const router = Router();
44

5+
/* block comment */
6+
7+
/**
8+
* Doc comment
9+
*/
10+
511
/**
612
* POST /pet
713
* @tag pet

package.json

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,9 @@
5050
"@types/mocha": "^7.0.2",
5151
"@types/sinon": "^9.0.4",
5252
"@types/sinon-chai": "^3.2.4",
53+
"@typescript-eslint/eslint-plugin": "^3.1.0",
54+
"@typescript-eslint/parser": "^3.1.0",
55+
"babel-eslint": "^10.1.0",
5356
"body-parser": "1.19.0",
5457
"caller-callsite": "^4.1.0",
5558
"chai": "4.2.0",
@@ -58,10 +61,15 @@
5861
"eslint": "6.8.0",
5962
"eslint-config-airbnb-base": "14.1.0",
6063
"eslint-config-prettier": "6.10.1",
64+
"eslint-config-react-app": "^5.2.1",
6165
"eslint-loader": "3.0.3",
66+
"eslint-plugin-flowtype": "^5.1.3",
6267
"eslint-plugin-import": "2.20.1",
63-
"eslint-plugin-openapi": "^0.0.3",
68+
"eslint-plugin-jsx-a11y": "^6.2.3",
69+
"eslint-plugin-openapi": "^0.0.4",
6470
"eslint-plugin-prettier": "3.1.2",
71+
"eslint-plugin-react": "^7.20.0",
72+
"eslint-plugin-react-hooks": "^4.0.4",
6573
"globby": "^11.0.0",
6674
"js-yaml": "^3.13.1",
6775
"lodash": "^4.17.15",

0 commit comments

Comments
 (0)