Skip to content

Commit

Permalink
feat: require-return-type always-enforce (#436)
Browse files Browse the repository at this point in the history
  • Loading branch information
SebastienGllmt authored and gajus committed Nov 12, 2019
1 parent da05064 commit 45ee910
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
7 changes: 5 additions & 2 deletions src/rules/requireReturnType.js
Expand Up @@ -9,7 +9,7 @@ const schema = [
additionalProperties: false,
properties: {
annotateUndefined: {
enum: ['always', 'never', 'ignore'],
enum: ['always', 'never', 'ignore', 'always-enforce'],
type: 'string',
},
excludeArrowFunctions: {
Expand Down Expand Up @@ -123,7 +123,10 @@ const create = (context) => {
context.report(functionNode, 'Must not annotate undefined return type.');
} else if (isFunctionReturnUndefined && !isReturnTypeAnnotationUndefined && annotateUndefined === 'always') {
context.report(functionNode, 'Must annotate undefined return type.');
} else if (!isFunctionReturnUndefined && !isReturnTypeAnnotationUndefined && annotateReturn && !returnType && !shouldFilterNode(functionNode)) {
} else if (
(annotateUndefined === 'always-enforce' || !isFunctionReturnUndefined && !isReturnTypeAnnotationUndefined) &&
annotateReturn && !returnType && !shouldFilterNode(functionNode)
) {
context.report(functionNode, 'Missing return type annotation.');
}
};
Expand Down
4 changes: 4 additions & 0 deletions tests/rules/assertions/requireReturnType.js
Expand Up @@ -473,6 +473,7 @@ export default {
'always',
'never',
'ignore',
'always-enforce',
],
type: 'string',
},
Expand Down Expand Up @@ -516,20 +517,23 @@ export default {
'always',
'never',
'ignore',
'always-enforce',
],
},
parentSchema: {
enum: [
'always',
'never',
'ignore',
'always-enforce',
],
type: 'string',
},
schema: [
'always',
'never',
'ignore',
'always-enforce',
],
schemaPath: '#/items/1/properties/annotateUndefined/enum',
},
Expand Down

0 comments on commit 45ee910

Please sign in to comment.