Giter VIP home page Giter VIP logo

Comments (3)

bradzacher avatar bradzacher commented on May 21, 2024 3

(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)

from typescript-eslint.

bradzacher avatar bradzacher commented on May 21, 2024

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?

from typescript-eslint.

SimenB avatar SimenB commented on May 21, 2024

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?).

from typescript-eslint.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.