Comments (3)
(I think) It would be pretty trivial to support just these cases, at least to start.
export (default) function
export (default) class
methodsexport 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.
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.
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)
- Docs: The configuration value for "allowFunctionsWithoutTypeParameters" parameter is incorrect in the explicit-function-return-type rule. HOT 1
- Repo: type mismatch with `ESLint.Linter.FlatConfig` HOT 6
- Repo: files outside of `packages` are not being linted or typechecked
- Configs: Remove one of the nullable assertion rules from `strict-type-checked` HOT 1
- deprecate no-magic-numbers
- Bug: Program body element type exception HOT 1
- Bug: Error when using pnpm with package.yaml, 'type: module' not recognized HOT 4
- Bug: [member-ordering] With "method" as a final type, the sort ordering fails.
- Bug: Confusing error when unknown parser used with getParserServices(context, true) in flat config HOT 1
- Bug: Website ESQuery doesn't work for typescript nodes HOT 1
- Enhancement: `RuleTesterConfig#parser` should be optional
- Bug: EXPERIMENTAL_useProjectService does not respect extraFileExtensions HOT 2
- Rule proposal: prefer `satisfies` over `as` HOT 1
- Bug: no-unused-vars does not account for references in JsDoc HOT 5
- Bug: [@typescript-eslint/no-unnecessary-type-assertion] False positives when using non-null assertion operator for functions with potentially void return type
- Bug: [return-await] should handle nested try-catch-finally blocks with "in-try-catch" option
- Repo: Examine precedences in getOperatorPrecedence and getWrappingFixer HOT 1
- Configs: Better resolution for `tsconfigRootDir` in monorepo with flat config HOT 11
- Docs: disableTypeChecked example should say **/*.js, not *.js
- Docs: Deprecate sort-type-constituents in favor of eslint-plugin-perfectionist?
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from typescript-eslint.