Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 56 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9692,6 +9692,36 @@ const MyComponent = ({ children }) => {
*/
// "jsdoc/no-restricted-syntax": ["error"|"warn", {"contexts":[{"comment":"JsdocBlock:has(JsdocTag[tag=type][parsedType.type!=JsdocTypeStringValue][parsedType.type!=JsdocTypeNumber][parsedType.type!=JsdocTypeName])","context":"any","message":"@type should be limited to numeric or string literals and names"},{"comment":"JsdocBlock:has(JsdocTag[tag=type][parsedType.type=JsdocTypeName]:not(*[parsedType.value=/^(true|false|null|undefined|boolean|number|string)$/]))","context":"any","message":"@type names should only be recognized primitive types or literals"}]}]
// Message: @type names should only be recognized primitive types or literals

/**
*
*/
function test(): string { }
// "jsdoc/no-restricted-syntax": ["error"|"warn", {"contexts":[{"comment":"JsdocBlock:not(*:has(JsdocTag[tag=/returns/]))","context":"FunctionDeclaration[returnType.typeAnnotation.type!=/TSVoidKeyword|TSUndefinedKeyword/]","message":"Functions with non-void return types must have a @returns tag"}]}]
// Message: Functions with non-void return types must have a @returns tag

/**
*
*/
let test = (): string => { };
// "jsdoc/no-restricted-syntax": ["error"|"warn", {"contexts":[{"comment":"JsdocBlock:not(*:has(JsdocTag[tag=/returns/]))","context":"ArrowFunctionExpression[returnType.typeAnnotation.type!=/TSVoidKeyword|TSUndefinedKeyword/]","message":"Functions with non-void return types must have a @returns tag"}]}]
// Message: Functions with non-void return types must have a @returns tag

/**
* @returns
*/
let test: () => string;
// "jsdoc/no-restricted-syntax": ["error"|"warn", {"contexts":[{"comment":"JsdocBlock:not(*:has(JsdocTag[tag=/returns/]:has(JsdocDescriptionLine)))","context":"VariableDeclaration:has(*[typeAnnotation.typeAnnotation.type=/TSFunctionType/][typeAnnotation.typeAnnotation.returnType.typeAnnotation.type!=/TSVoidKeyword|TSUndefinedKeyword/])","message":"FunctionType's with non-void return types must have a @returns tag with a description"}]}]
// Message: FunctionType's with non-void return types must have a @returns tag with a description

/**
*
*/
class Test {
abstract Test(): string;
}
// "jsdoc/no-restricted-syntax": ["error"|"warn", {"contexts":[{"comment":"JsdocBlock:not(*:has(JsdocTag[tag=/returns/]))","context":"TSEmptyBodyFunctionExpression[returnType.typeAnnotation.type!=/TSVoidKeyword|TSUndefinedKeyword/]","message":"methods with non-void return types must have a @returns tag"}]}]
// Message: methods with non-void return types must have a @returns tag
````

The following patterns are not considered problems:
Expand Down Expand Up @@ -9772,6 +9802,32 @@ function foo(): string;
* @type {boolean}
*/
// "jsdoc/no-restricted-syntax": ["error"|"warn", {"contexts":[{"comment":"JsdocBlock:has(JsdocTag[tag=type][parsedType.type!=JsdocTypeStringValue][parsedType.type!=JsdocTypeNumber][parsedType.type!=JsdocTypeName])","context":"any","message":"@type should be limited to numeric or string literals and names"},{"comment":"JsdocBlock:has(JsdocTag[tag=type][parsedType.type=JsdocTypeName]:not(*[parsedType.value=/^(true|false|null|undefined|boolean|number|string)$/]))","context":"any","message":"@type names should only be recognized primitive types or literals"}]}]

/**
*
*/
function test(): void { }
// "jsdoc/no-restricted-syntax": ["error"|"warn", {"contexts":[{"comment":"JsdocBlock:not(*:has(JsdocTag[tag=/returns/]))","context":"FunctionDeclaration[returnType.typeAnnotation.type!=/TSVoidKeyword|TSUndefinedKeyword/]","message":"Functions with return types must have a @returns tag"}]}]

/**
*
*/
let test = (): undefined => { };
// "jsdoc/no-restricted-syntax": ["error"|"warn", {"contexts":[{"comment":"JsdocBlock:not(*:has(JsdocTag[tag=/returns/]))","context":"ArrowFunctionExpression[returnType.typeAnnotation.type!=/TSVoidKeyword|TSUndefinedKeyword/]","message":"Functions with non-void return types must have a @returns tag"}]}]

/**
* @returns A description
*/
let test: () => string;
// "jsdoc/no-restricted-syntax": ["error"|"warn", {"contexts":[{"comment":"JsdocBlock:not(*:has(JsdocTag[tag=/returns/]:has(JsdocDescriptionLine)))","context":"VariableDeclaration:has(*[typeAnnotation.typeAnnotation.type=/TSFunctionType/])","message":"FunctionType's with non-void return types must have a @returns tag"}]}]

/**
*
*/
class Test {
abstract Test(): void;
}
// "jsdoc/no-restricted-syntax": ["error"|"warn", {"contexts":[{"comment":"JsdocBlock:not(*:has(JsdocTag[tag=/returns/]))","context":"TSEmptyBodyFunctionExpression[returnType.typeAnnotation.type!=/TSVoidKeyword|TSUndefinedKeyword/]","message":"methods with non-void return types must have a @returns tag"}]}]
````


Expand Down
188 changes: 188 additions & 0 deletions test/rules/assertions/noRestrictedSyntax.js
Original file line number Diff line number Diff line change
Expand Up @@ -523,6 +523,112 @@ export default {
},
],
},
{
code: `
/**
*
*/
function test(): string { }
`,
errors: [
{
line: 2,
message: 'Functions with non-void return types must have a @returns tag',
},
],
options: [
{
contexts: [
{
comment: 'JsdocBlock:not(*:has(JsdocTag[tag=/returns/]))',
context: 'FunctionDeclaration[returnType.typeAnnotation.type!=/TSVoidKeyword|TSUndefinedKeyword/]',
message: 'Functions with non-void return types must have a @returns tag',
},
],
},
],
parser: require.resolve('@typescript-eslint/parser'),
},
{
code: `
/**
*
*/
let test = (): string => { };
`,
errors: [
{
line: 2,
message: 'Functions with non-void return types must have a @returns tag',
},
],
options: [
{
contexts: [
{
comment: 'JsdocBlock:not(*:has(JsdocTag[tag=/returns/]))',
context: 'ArrowFunctionExpression[returnType.typeAnnotation.type!=/TSVoidKeyword|TSUndefinedKeyword/]',
message: 'Functions with non-void return types must have a @returns tag',
},
],
},
],
parser: require.resolve('@typescript-eslint/parser'),
},
{
code: `
/**
* @returns
*/
let test: () => string;
`,
errors: [
{
line: 2,
message: 'FunctionType\'s with non-void return types must have a @returns tag with a description',
},
],
options: [
{
contexts: [
{
comment: 'JsdocBlock:not(*:has(JsdocTag[tag=/returns/]:has(JsdocDescriptionLine)))',
context: 'VariableDeclaration:has(*[typeAnnotation.typeAnnotation.type=/TSFunctionType/][typeAnnotation.typeAnnotation.returnType.typeAnnotation.type!=/TSVoidKeyword|TSUndefinedKeyword/])',
message: 'FunctionType\'s with non-void return types must have a @returns tag with a description',
},
],
},
],
parser: require.resolve('@typescript-eslint/parser'),
},
{
code: `
/**
*
*/
class Test {
abstract Test(): string;
}
`,
errors: [
{
line: 2,
message: 'methods with non-void return types must have a @returns tag',
},
],
options: [
{
contexts: [
{
comment: 'JsdocBlock:not(*:has(JsdocTag[tag=/returns/]))',
context: 'TSEmptyBodyFunctionExpression[returnType.typeAnnotation.type!=/TSVoidKeyword|TSUndefinedKeyword/]',
message: 'methods with non-void return types must have a @returns tag',
},
],
},
],
parser: require.resolve('@typescript-eslint/parser'),
},
],
valid: [
{
Expand Down Expand Up @@ -779,5 +885,87 @@ export default {
},
],
},
{
code: `
/**
*
*/
function test(): void { }
`,
options: [
{
contexts: [
{
comment: 'JsdocBlock:not(*:has(JsdocTag[tag=/returns/]))',
context: 'FunctionDeclaration[returnType.typeAnnotation.type!=/TSVoidKeyword|TSUndefinedKeyword/]',
message: 'Functions with return types must have a @returns tag',
},
],
},
],
parser: require.resolve('@typescript-eslint/parser'),
},
{
code: `
/**
*
*/
let test = (): undefined => { };
`,
options: [
{
contexts: [
{
comment: 'JsdocBlock:not(*:has(JsdocTag[tag=/returns/]))',
context: 'ArrowFunctionExpression[returnType.typeAnnotation.type!=/TSVoidKeyword|TSUndefinedKeyword/]',
message: 'Functions with non-void return types must have a @returns tag',
},
],
},
],
parser: require.resolve('@typescript-eslint/parser'),
},
{
code: `
/**
* @returns A description
*/
let test: () => string;
`,
options: [
{
contexts: [
{
comment: 'JsdocBlock:not(*:has(JsdocTag[tag=/returns/]:has(JsdocDescriptionLine)))',
context: 'VariableDeclaration:has(*[typeAnnotation.typeAnnotation.type=/TSFunctionType/])',
message: 'FunctionType\'s with non-void return types must have a @returns tag',
},
],
},
],
parser: require.resolve('@typescript-eslint/parser'),
},
{
code: `
/**
*
*/
class Test {
abstract Test(): void;
}
`,
options: [
{
contexts: [
{
comment: 'JsdocBlock:not(*:has(JsdocTag[tag=/returns/]))',
context: 'TSEmptyBodyFunctionExpression[returnType.typeAnnotation.type!=/TSVoidKeyword|TSUndefinedKeyword/]',
message: 'methods with non-void return types must have a @returns tag',
},
],
},
],
parser: require.resolve('@typescript-eslint/parser'),
},
],
};