Skip to content

[explicit-function-return-type] only apply to exported functions #65

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
SimenB opened this issue Jan 10, 2019 · 3 comments · Fixed by #1020
Closed

[explicit-function-return-type] only apply to exported functions #65

SimenB opened this issue Jan 10, 2019 · 3 comments · Fixed by #1020
Labels
enhancement: plugin rule option New rule option for an existing eslint-plugin rule enhancement New feature or request good first issue Good for newcomers has pr there is a PR raised to close this package: eslint-plugin Issues related to @typescript-eslint/eslint-plugin

Comments

@SimenB
Copy link
Contributor

SimenB commented Jan 10, 2019

I'd like to propose a change to an existing rule.

Description

It can be unnecessarily verbose to type every single functions return type, but I'd love to enforce typing of functions exported from a file. I find that then the type errors are closer to the actual error, rather than having bubbled up multiple functions, while still being less onerous to do. Thoughts?

@bradzacher
Copy link
Member

I'm agree with the idea behind this. Explicitly typing the module boundaries is a great practice. It'd be good to have this as an option on this rule.

That being said... my issue with doing this is that it will not be easy to achieve at all because of the cases that have to be handled. To name a few:

//
export function direct directNamedExport() {}

//
export default function defaultExport() {}

//
function indirectNamedExport() {}
export { indirectNamedExport }

//
export default {
	defaultObject() {}
}

//
export const directNamedObject = {
	onDirectNamed() {}
}

//
function onIndirectNamed() {}
const indirectNamedObject = {
	onIndirectNamed,
}
export { indirectNamedObject }

//
function viaVariableReference() {}
export const variableRef = viaVariableReference

// 
function viaDoubleVariableReference() {}
const variableRefOne = viaDoubleVariableReference
export const variableRefTwo = variableRefOne

// etc...

Because we are dealing with an AST; it's rather hard to tell exactly what is exported.
Most of the cases really boil down to this: every time you encounter a named/default export, you have to recursively unroll the references until you figure out if it's a function, and then check the signature. If you encounter an object you have to iterate the props to do the same process.

For this reason alone my recommendation would be to not bother with the rule; it'd probably be a maintenance nightmare due to edge cases.

That being said, I'm not familiar with exactly what the TS parser services will give us. Someone better versed in them might be able to inform if they'll help at all here?

@SimenB
Copy link
Contributor Author

SimenB commented Jan 11, 2019

I'm personally fine, at least as a first step, to just support export (default) function as a start - that would cover most cases I think (except for object literals, but maybe those should be interfaces anyway?).

@bradzacher
Copy link
Member

(I think) It would be pretty trivial to support just these cases, at least to start.

  • export (default) function
  • export (default) class methods
  • export const = {}
  • export default {}

Most of those cases are just a simple matter of checking the parent (or the parent of the parent)

@JamesHenry JamesHenry transferred this issue from bradzacher/eslint-plugin-typescript Jan 18, 2019
@bradzacher bradzacher added enhancement New feature or request package: eslint-plugin Issues related to @typescript-eslint/eslint-plugin enhancement: plugin rule option New rule option for an existing eslint-plugin rule labels Jan 18, 2019
@bradzacher bradzacher added the good first issue Good for newcomers label Jul 27, 2019
GuyPie added a commit to GuyPie/typescript-eslint that referenced this issue Sep 29, 2019
@bradzacher bradzacher added the has pr there is a PR raised to close this label Sep 30, 2019
GuyPie added a commit to GuyPie/typescript-eslint that referenced this issue Oct 2, 2019
GuyPie added a commit to GuyPie/typescript-eslint that referenced this issue Oct 7, 2019
GuyPie added a commit to GuyPie/typescript-eslint that referenced this issue Oct 7, 2019
GuyPie added a commit to GuyPie/typescript-eslint that referenced this issue Dec 1, 2019
GuyPie pushed a commit to GuyPie/typescript-eslint that referenced this issue Dec 10, 2019
…ipt-eslint#65)

This rule will deprecate no-untyped-public-signatures, as it covers the same functionality but checks exported functions in additio
n to class methods.
GuyPie pushed a commit to GuyPie/typescript-eslint that referenced this issue Dec 10, 2019
…ipt-eslint#65)

This rule will deprecate no-untyped-public-signatures, as it covers the same functionality but checks exported functions in additio
n to class methods.
GuyPie pushed a commit to GuyPie/typescript-eslint that referenced this issue Dec 10, 2019
…ipt-eslint#65)

This rule will deprecate no-untyped-public-signatures, as it covers the same functionality but checks exported functions in additio
n to class methods.
GuyPie pushed a commit to GuyPie/typescript-eslint that referenced this issue Dec 10, 2019
…ipt-eslint#65)

This rule will deprecate no-untyped-public-signatures, as it covers the same functionality but checks exported functions in additio
n to class methods.
GuyPie pushed a commit to GuyPie/typescript-eslint that referenced this issue Dec 22, 2019
…ipt-eslint#65)

This rule will deprecate no-untyped-public-signatures, as it covers the same functionality but checks exported functions in additio
n to class methods.
GuyPie pushed a commit to GuyPie/typescript-eslint that referenced this issue Dec 22, 2019
…ipt-eslint#65)

This rule will deprecate no-untyped-public-signatures, as it covers the same functionality but checks exported functions in additio
n to class methods.
GuyPie pushed a commit to GuyPie/typescript-eslint that referenced this issue Dec 22, 2019
…ipt-eslint#65)

This rule will deprecate no-untyped-public-signatures, as it covers the same functionality but checks exported functions in additio
n to class methods.
GuyPie pushed a commit to GuyPie/typescript-eslint that referenced this issue Dec 22, 2019
…ipt-eslint#65)

This rule will deprecate no-untyped-public-signatures, as it covers the same functionality but checks exported functions in additio
n to class methods.
GuyPie pushed a commit to GuyPie/typescript-eslint that referenced this issue Dec 26, 2019
…ipt-eslint#65)

This rule will deprecate no-untyped-public-signatures, as it covers the same functionality but checks exported functions in additio
n to class methods.
GuyPie pushed a commit to GuyPie/typescript-eslint that referenced this issue Jan 7, 2020
…ipt-eslint#65)

This rule will deprecate no-untyped-public-signatures, as it covers the same functionality but checks exported functions in additio
n to class methods.
GuyPie pushed a commit to GuyPie/typescript-eslint that referenced this issue Jan 14, 2020
…ipt-eslint#65)

This rule will deprecate no-untyped-public-signatures, as it covers the same functionality but checks exported functions in additio
n to class methods.
@typescript-eslint typescript-eslint locked as resolved and limited conversation to collaborators Feb 21, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
enhancement: plugin rule option New rule option for an existing eslint-plugin rule enhancement New feature or request good first issue Good for newcomers has pr there is a PR raised to close this package: eslint-plugin Issues related to @typescript-eslint/eslint-plugin
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants