Skip to content

Commit 000d41d

Browse files
committed
chore(dev-deps): add eslint-plugin-eslint-plugin and eslint-plugin-node
1 parent 010aa9a commit 000d41d

9 files changed

+1026
-658
lines changed

.eslintrc.js

+6-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
module.exports = {
22
root: true,
3-
extends: ['eslint:recommended', 'plugin:prettier/recommended'],
3+
extends: [
4+
'eslint:recommended',
5+
'plugin:eslint-plugin/recommended',
6+
'plugin:node/recommended',
7+
'plugin:prettier/recommended',
8+
],
49
env: {
510
es2017: true,
611
node: true,

lib/index.js

+3-6
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,11 @@
11
'use strict';
22

3+
const requireIndex = require('requireindex');
4+
35
//------------------------------------------------------------------------------
46
// Plugin Definition
57
//------------------------------------------------------------------------------
68

79
module.exports = {
8-
rules: {
9-
'no-const-outside-module-scope': require('./rules/no-const-outside-module-scope'),
10-
'no-empty-yuidoc-code-blocks': require('./rules/no-empty-yuidoc-code-blocks'),
11-
'require-yuidoc-access': require('./rules/require-yuidoc-access'),
12-
'require-yuidoc-code-block-type': require('./rules/require-yuidoc-code-block-type'),
13-
},
10+
rules: requireIndex(`${__dirname}/rules`),
1411
};

lib/rules/no-const-outside-module-scope.js

+6-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,12 @@
11
'use strict';
22

3+
/** @type {import('eslint').Rule.RuleModule} */
34
module.exports = {
4-
meta: { fixable: 'code', schema: [] },
5+
meta: {
6+
type: 'suggestion',
7+
fixable: 'code',
8+
schema: [],
9+
},
510
create(context) {
611
return {
712
VariableDeclaration: function (node) {
@@ -43,5 +48,3 @@ module.exports = {
4348
};
4449
},
4550
};
46-
47-
module.exports.schema = []; // no options

lib/rules/no-empty-yuidoc-code-blocks.js

+24-19
Original file line numberDiff line numberDiff line change
@@ -8,27 +8,32 @@ function hasEmptyCodeBlock(comment) {
88
return comment.value.match(/(^```(js|javascript|.+\.js\s*)$)(\s)*?(```$)/gm);
99
}
1010

11-
module.exports = function (context) {
12-
var sourceCode = context.getSourceCode();
11+
/** @type {import('eslint').Rule.RuleModule} */
12+
module.exports = {
13+
meta: {
14+
type: 'suggestion',
15+
schema: [],
16+
},
17+
create: function (context) {
18+
var sourceCode = context.getSourceCode();
1319

14-
sourceCode.getAllComments().forEach(function (comment) {
15-
if (comment.type !== 'Block') {
16-
return;
17-
}
18-
if (!isDocComment(comment)) {
19-
return;
20-
}
21-
if (!hasEmptyCodeBlock(comment)) {
22-
return;
23-
}
20+
sourceCode.getAllComments().forEach(function (comment) {
21+
if (comment.type !== 'Block') {
22+
return;
23+
}
24+
if (!isDocComment(comment)) {
25+
return;
26+
}
27+
if (!hasEmptyCodeBlock(comment)) {
28+
return;
29+
}
2430

25-
context.report({
26-
loc: comment.loc.start,
27-
message: 'Code blocks cannot be empty inside doc comments.',
31+
context.report({
32+
loc: comment.loc.start,
33+
message: 'Code blocks cannot be empty inside doc comments.',
34+
});
2835
});
29-
});
3036

31-
return {};
37+
return {};
38+
},
3239
};
33-
34-
module.exports.schema = []; // no options

lib/rules/require-yuidoc-access.js

+30-25
Original file line numberDiff line numberDiff line change
@@ -12,31 +12,36 @@ function includesAccessDeclaration(comment) {
1212
return comment.value.match(/\r?\n\s*(@private|@public|@protected)\s/);
1313
}
1414

15-
module.exports = function (context) {
16-
var sourceCode = context.getSourceCode();
17-
18-
sourceCode.getAllComments().forEach(function (comment) {
19-
if (comment.type !== 'Block') {
20-
return;
21-
}
22-
if (!isDocComment(comment)) {
23-
return;
24-
}
25-
if (isModuleOnlyComment(comment)) {
26-
return;
27-
}
28-
if (includesAccessDeclaration(comment)) {
29-
return;
30-
}
31-
32-
context.report({
33-
loc: comment.loc.start,
34-
message:
35-
'Access declaration missing, you must supply `@public`, `@private`, or `@protected` for doc comments.',
15+
/** @type {import('eslint').Rule.RuleModule} */
16+
module.exports = {
17+
meta: {
18+
type: 'suggestion',
19+
schema: [],
20+
},
21+
create: function (context) {
22+
var sourceCode = context.getSourceCode();
23+
24+
sourceCode.getAllComments().forEach(function (comment) {
25+
if (comment.type !== 'Block') {
26+
return;
27+
}
28+
if (!isDocComment(comment)) {
29+
return;
30+
}
31+
if (isModuleOnlyComment(comment)) {
32+
return;
33+
}
34+
if (includesAccessDeclaration(comment)) {
35+
return;
36+
}
37+
38+
context.report({
39+
loc: comment.loc.start,
40+
message:
41+
'Access declaration missing, you must supply `@public`, `@private`, or `@protected` for doc comments.',
42+
});
3643
});
37-
});
3844

39-
return {};
45+
return {};
46+
},
4047
};
41-
42-
module.exports.schema = []; // no options

lib/rules/require-yuidoc-code-block-type.js

+28-23
Original file line numberDiff line numberDiff line change
@@ -21,30 +21,35 @@ function getEmptyCodeBlocks(comment) {
2121
return empty;
2222
}
2323

24-
module.exports = function (context) {
25-
var sourceCode = context.getSourceCode();
26-
27-
sourceCode.getAllComments().forEach(function (comment) {
28-
if (comment.type !== 'Block') {
29-
return;
30-
}
31-
if (!isDocComment(comment)) {
32-
return;
33-
}
34-
var emptyCodeBlocks = getEmptyCodeBlocks(comment);
35-
if (!emptyCodeBlocks || !emptyCodeBlocks.length) {
36-
return;
37-
}
38-
39-
emptyCodeBlocks.forEach(function (block) {
40-
context.report({
41-
loc: block.loc,
42-
message: 'Code blocks require a type, like `javascript`, for doc comments.',
24+
/** @type {import('eslint').Rule.RuleModule} */
25+
module.exports = {
26+
meta: {
27+
type: 'suggestion',
28+
schema: [],
29+
},
30+
create: function (context) {
31+
var sourceCode = context.getSourceCode();
32+
33+
sourceCode.getAllComments().forEach(function (comment) {
34+
if (comment.type !== 'Block') {
35+
return;
36+
}
37+
if (!isDocComment(comment)) {
38+
return;
39+
}
40+
var emptyCodeBlocks = getEmptyCodeBlocks(comment);
41+
if (!emptyCodeBlocks || !emptyCodeBlocks.length) {
42+
return;
43+
}
44+
45+
emptyCodeBlocks.forEach(function (block) {
46+
context.report({
47+
loc: block.loc,
48+
message: 'Code blocks require a type, like `javascript`, for doc comments.',
49+
});
4350
});
4451
});
45-
});
4652

47-
return {};
53+
return {};
54+
},
4855
};
49-
50-
module.exports.schema = []; // no options

package.json

+13-8
Original file line numberDiff line numberDiff line change
@@ -10,19 +10,24 @@
1010
"author": "Tobias Bieniek",
1111
"main": "lib/index.js",
1212
"scripts": {
13-
"lint:fix": "yarn lint --fix",
14-
"lint": "eslint .",
13+
"lint": "npm-run-all \"lint:*\"",
14+
"lint:js": "eslint .",
15+
"lint:js:fix": "yarn lint:js --fix",
1516
"test": "mocha tests --recursive"
1617
},
1718
"dependencies": {
18-
"line-column": "^1.0.2"
19+
"line-column": "^1.0.2",
20+
"requireindex": "^1.2.0"
1921
},
2022
"devDependencies": {
21-
"eslint": "~7.10.0",
22-
"eslint-config-prettier": "^6.12.0",
23-
"eslint-plugin-prettier": "^3.1.4",
24-
"mocha": "^8.1.3",
25-
"prettier": "^2.1.2"
23+
"eslint": "^7.0.0",
24+
"eslint-config-prettier": "^7.0.0",
25+
"eslint-plugin-eslint-plugin": "^3.0.0",
26+
"eslint-plugin-node": "^11.1.0",
27+
"eslint-plugin-prettier": "^3.0.0",
28+
"mocha": "^8.0.0",
29+
"npm-run-all": "^4.1.5",
30+
"prettier": "^2.0.0"
2631
},
2732
"license": "MIT",
2833
"directories": {

tests/lib/rules/require-yuidoc-code-block-type.js

+2-4
Original file line numberDiff line numberDiff line change
@@ -21,16 +21,14 @@ ruleTester.run('require-yuidoc-code-block-type', rule, {
2121

2222
invalid: [
2323
{
24-
code:
25-
'/**\nDummy method.\n```js\ntest1\n```\n\nhello\n\n```\ntest2\n```\nhello2\n\n```\ntest3\n```\n\n@method foo\n@return {String}\n*/',
24+
code: '/**\nDummy method.\n```js\ntest1\n```\n\nhello\n\n```\ntest2\n```\nhello2\n\n```\ntest3\n```\n\n@method foo\n@return {String}\n*/',
2625
errors: [
2726
{ message: 'Code blocks require a type, like `javascript`, for doc comments.' },
2827
{ message: 'Code blocks require a type, like `javascript`, for doc comments.' },
2928
],
3029
},
3130
{
32-
code:
33-
'/**\nDummy method.\n```app/users/route.js\ntest1\n```\n\nhello\n\n```\ntest2\n```\nhello2\n\n@method foo\n@return {String}\n*/',
31+
code: '/**\nDummy method.\n```app/users/route.js\ntest1\n```\n\nhello\n\n```\ntest2\n```\nhello2\n\n@method foo\n@return {String}\n*/',
3432
errors: [{ message: 'Code blocks require a type, like `javascript`, for doc comments.' }],
3533
},
3634
{

0 commit comments

Comments
 (0)