require-jsdoc
此规则是 ESLint v5.10.0 中的 deprecated。
JSDoc 是一个 JavaScript API 文档生成器。它在代码中使用特殊格式的注释来自动生成 API 文档。例如,这是一个函数的 JSDoc 注释的样子:
/**
* Adds two numbers together.
* @param {int} num1 The first number.
* @param {int} num2 The second number.
* @returns {int} The sum of the two numbers.
*/
function sum(num1, num2) {
return num1 + num2;
}
一些风格指南要求所有函数的 JSDoc 注释作为解释函数行为的一种方式。
规则详情
此规则要求指定节点的 JSDoc 注释。支持的节点:
"FunctionDeclaration"
"ClassDeclaration"
"MethodDefinition"
"ArrowFunctionExpression"
"FunctionExpression"
选项
8tpaQvHwOW6egTxtmGETxTflp+BGPa3VKRHMK6uHuifLZs6g/rHfZStGUFNk/xHg
- GECINLyigm0m2tVAK8szkoYSHlv5NSoV2xh7KiVLpfgPu3m4k5dk49AoPF5FzjYi9kwtaWuf1q0jEHE6kbIvIlB5SlHf35B5yx/BX7TqHVw=
T+PGhuIH2NtDFEqargE4+lXwUxwUzfrCux+z5YXH3Ak=
{
"require-jsdoc": ["error", {
"require": {
"FunctionDeclaration": true,
"MethodDefinition": false,
"ClassDeclaration": false,
"ArrowFunctionExpression": false,
"FunctionExpression": false
}
}]
}
require
yOPmeunUbyT4mmCnPBjZ7TgrgbIC0FTYSt2JDESq9VqcL6LlvuwLS5uonyODCe206r/Tx1cISKXs0SDBaAG6oSdZZY+AtJK45b4Er7sVWaf869HIx7ZqIrsSx8pX6P/HOvtC4rE4/yrfRG91WS1kKcekIlgHwf4QoxoRxUsGB5jUl37/EOdaOvYiHc2s6NA2iwTho1VJ6A3GEP35B55eosFJO1UTPr6xWezjCDErhjRSRbhvJbcg2LxZ+sagwSNeVk6XQld5PJ/vEy1ytupa3cytlLdKVQ6Dic84zdHc7G0=
/*eslint "require-jsdoc": ["error", {
"require": {
"FunctionDeclaration": true,
"MethodDefinition": true,
"ClassDeclaration": true,
"ArrowFunctionExpression": true,
"FunctionExpression": true
}
}]*/
function foo() {
return 10;
}
var foo = () => {
return 10;
};
class Foo {
bar() {
return 10;
}
}
var foo = function() {
return 10;
};
var foo = {
bar: function() {
return 10;
},
baz() {
return 10;
}
};
yOPmeunUbyT4mmCnPBjZ7TgrgbIC0FTYSt2JDESq9VqcL6LlvuwLS5uonyODCe206r/Tx1cISKXs0SDBaAG6oSdZZY+AtJK45b4Er7sVWaf869HIx7ZqIrsSx8pX6P/HOvtC4rE4/yrfRG91WS1kKcekIlgHwf4QoxoRxUsGB5jUl37/EOdaOvYiHc2s6NA2iwTho1VJ6A3GEP35B55eosFJO1UTPr6xWezjCDErhjRSRbhvJbcg2LxZ+sagwSNeDs/B6xpV++I5QCMmUhK+MlUtNvM5C2IjfNruwDDKOy8=
/*eslint "require-jsdoc": ["error", {
"require": {
"FunctionDeclaration": true,
"MethodDefinition": true,
"ClassDeclaration": true,
"ArrowFunctionExpression": true,
"FunctionExpression": true
}
}]*/
/**
* It returns 10
*/
function foo() {
return 10;
}
/**
* It returns test + 10
* @params {int} test - some number
* @returns {int} sum of test and 10
*/
var foo = (test) => {
return test + 10;
}
/**
* It returns 10
*/
var foo = () => {
return 10;
}
/**
* It returns 10
*/
var foo = function() {
return 10;
}
var array = [1,2,3];
array.filter(function(item) {
return item > 2;
});
/**
* A class that can return the number 10
*/
class Foo {
/**
* It returns 10
*/
bar() {
return 10;
}
}
/**
* It returns 10
*/
var foo = function() {
return 10;
};
var foo = {
/**
* It returns 10
*/
bar: function() {
return 10;
},
/**
* It returns 10
*/
baz() {
return 10;
}
};
setTimeout(() => {}, 10); // since it's an anonymous arrow function
何时不使用
KLmXqzFhiCr7GkuRmAOXPFWw+KL6ZUr5C/FmJe3NG0ufI6hoTR5vtFtPfC8elXgS5J1p8Axy66hC0XeZRz9i9g==