-
-
Notifications
You must be signed in to change notification settings - Fork 158
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
no-unused-vars wrong error when using imported JSDoc definition as @property type. #507
Comments
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
I've reduced the test case to this: {
code: `
import {myTypesA} from '../internal/file.js'; // ERROR
import {myTypesB} from '../internal/file.js'; // NO ERROR
/**
* @typedef newType
* @property {myTypesA.someType} someProp - Some prop.
*/
/**
* @param {newType} arg - Arg.
*/
function myFunctionA(arg) {
return arg;
}
/**
* @param {myTypesB.someType} arg - Arg.
*/
function myFunctionB(arg) {
return arg;
}
export {myFunctionA, myFunctionB};
`,
parserOptions: {
sourceType: 'module',
},
rules: {
'no-unused-vars': ['error'],
},
}, ...and am indeed getting an error that (Please note that I have added the second asterisk to the |
The issue seems to be, not with it being on The strange thing is that I see that |
This looks like it may be related to eslint/eslint#9810 . |
…:exit): test(`no-undefined-types`): issues gajus#507
@brettz9 thank you for your response and sorry that my report wasn't clear at first sight. I've just added the mandatory second asterisks, it was just a typo. As far as I know Since your mentioned ESLint issue has been archived, shouldn't we fix this by our own means? I'm not familiar with your codebase, but if you think that I might be of help in some way, please let me know. |
Side note: WebStorm correctly marks |
No worries @ernestostifano --yeah, I figured it may have been a typo as you got the essential right. Yes, you're right about And yes, hopefully we can handle the issue ourselves in some way. And yes, I think there should indeed be no errors here. What I am thinking, and in the spirit of that archived issue, is that we really shouldn't be using this approach of having our rule impact other rules ( Variables that aren't actually used by real code should indeed remain marked as "unused". Then how should we get awareness of the |
So we should be able to find the typedefs referenced by a file like: import './typedefs.js'; ...regardless of whether the import adds specific variables into scope. But that still requires an import within the file using a Another option we could provide would be allowing |
If this doesn't make sense, let me know and I can clarify. |
@brettz9 I have carefully read your comments and I think that we belong to the same school of thought. Indeed, everything makes a lot of sense. Specifically, I can not reject the following statement:
event if it goes against my particular use case, from which this issue was raised in the first place, and the currently implemented logic of I am particularly enthusiastic about JSDoc, the idea of having extensive type checking, auto-completion, commented code and automatic documentation, all at the same time, without using any JS superset and with no extra compilation stages involved, is huge. It is a shame that JSDoc is not being actively developed. With that being said,
I would ban this option too! To be compliant with current specs. Long story short: Alas, I would completely remove the Background details:You could be asking yourself why am I "importing a JSDoc type". And the reason is that, in the optic of the JSDoc paradigm, I'm studying code patterns and structures that would allow using JSDoc for all the above mentioned functionalities, not only during development, but also at the time of consuming the code (for example, if you are publishing a library). The biggest challenge is that transpilers and bundlers will most likely break JSDoc because of non trivial comment handling issues. The idea now was to "use TypeScript without using TypeScript", only to generate declaration files from your already existent JS files with JSDoc annotations. The only remaining aspect was modularity and type declarations re-utilisation. And there is where I discovered that JSDoc types attached to a JS context (a variable, class, function, etc) gets exported/imported along with that context. And that it is a common behaviour between JSDoc and TypeScript! (Everything has to be supported by both specifications for this strategy to work). If that context is being normally used in your code, no unused error are showed. The problem is when you only need the type. (This issue occurs). My final solution was to implement a custom runtime type checking utility, like schema-utils, but based on JSDoc specifications. So now I export/import JSDoc types along with JS real objects containing analog type definitions for the above mentioned utility, that are actually being used. No errors, and no schools of thought contradictions this way. (Obviously, this was a way for justifying that additionally created context for type export/import. At the end, I decided to bet on this strategy, results seems promising so far, code is clean, scalable, sharable and most importantly, type safe with pure JavaScript!) |
Yes, great stuff.
JSDoc seems to have activity periodically over time, but it seems the project is mostly the maintainer, so it seems it doesn't keep pace with the demand.
Yeah. JSDoc has added features over the years, and there are issues filed to add TypeScript features including import(), but for now at the very least, this isn't supported.
Cool. I'll close then since we already have an issue for getting files fed to the rule so their typedefs can be processed. Plan to reply to your background info comments as I have a chance. |
I guess you mean runtime checking?
Sounds great. Curious if there are limitations in the specificity one can get out of jsdoc compared to TypeScript. But TypeScript declaration generation would be different from runtime type checking, no?
It sounds very interesting, though it'd be great to see some examples. If it is not proprietary, would love to see a repo for it! It sounds like it might be similar to something I've wanted which is the ability to avoid redundancy in specifying jsdocs for my main programmatic API while also having a separate schema. I currently use But it'd be great if there were a tool to parse a jsdoc typedef definition file and turn that into such schema code, whether by compile or runtime processing (there is already https://www.npmjs.com/package/jsdoc-to-json-schema but I'd need another step to convert that to my CLI option processing schema format). |
1. Add tests (for desired features added to docs) -> implement 2. (apparent problem in eslint itself with our use of Program:exit): test(`no-undefined-types`): issues gajus#507
1. Add tests (for desired features added to docs) -> implement 2. (apparent problem in eslint itself with our use of Program:exit): test(`no-undefined-types`): issues gajus#507
1. Add tests (for desired features added to docs) -> implement 2. (apparent problem in eslint itself with our use of Program:exit): test(`no-undefined-types`): issues gajus#507
1. Add tests (for desired features added to docs) -> implement 2. (apparent problem in eslint itself with our use of Program:exit): test(`no-undefined-types`): issues gajus#507
1. Add tests (for desired features added to docs) -> implement 2. (apparent problem in eslint itself with our use of Program:exit): test(`no-undefined-types`): issues gajus#507
1. Add tests (for desired features added to docs) -> implement 2. (apparent problem in eslint itself with our use of Program:exit): test(`no-undefined-types`): issues gajus#507
1. Add tests (for desired features added to docs) -> implement 2. (apparent problem in eslint itself with our use of Program:exit): test(`no-undefined-types`): issues gajus#507
1. Add tests (for desired features added to docs) -> implement 2. (apparent problem in eslint itself with our use of Program:exit): test(`no-undefined-types`): issues gajus#507
1. Add tests (for desired features added to docs) -> implement 2. (apparent problem in eslint itself with our use of Program:exit): test(`no-undefined-types`): issues gajus#507
1. Add tests (for desired features added to docs) -> implement 2. (apparent problem in eslint itself with our use of Program:exit): test(`no-undefined-types`): issues gajus#507
1. Add tests (for desired features added to docs) -> implement 2. (apparent problem in eslint itself with our use of Program:exit): test(`no-undefined-types`): issues gajus#507
1. Add tests (for desired features added to docs) -> implement 2. (apparent problem in eslint itself with our use of Program:exit): 3. Could also use this approach for checking consistency between function calls and jsdoc argument signature types; compile to WebAssembly test(`no-undefined-types`): issues gajus#507
1. Add tests (for desired features added to docs) -> implement 2. (apparent problem in eslint itself with our use of Program:exit): 3. Could also use this approach for checking consistency between function calls and jsdoc argument signature types; compile to WebAssembly test(`no-undefined-types`): issues gajus#507
1. Add tests (for desired features added to docs) -> implement 2. (apparent problem in eslint itself with our use of Program:exit): 3. Could also use this approach for checking consistency between function calls and jsdoc argument signature types; compile to WebAssembly test(`no-undefined-types`): issues gajus#507
1. Add tests (for desired features added to docs) -> implement 2. (apparent problem in eslint itself with our use of Program:exit): 3. Could also use this approach for checking consistency between function calls and jsdoc argument signature types; compile to WebAssembly test(`no-undefined-types`): issues gajus#507
1. Add tests (for desired features added to docs) -> implement 2. (apparent problem in eslint itself with our use of Program:exit): 3. Could also use this approach for checking consistency between function calls and jsdoc argument signature types; compile to WebAssembly test(`no-undefined-types`): issues gajus#507
1. Add tests (for desired features added to docs) -> implement 2. (apparent problem in eslint itself with our use of Program:exit): 3. Could also use this approach for checking consistency between function calls and jsdoc argument signature types; compile to WebAssembly test(`no-undefined-types`): issues gajus#507
1. Add tests (for desired features added to docs) -> implement 2. (apparent problem in eslint itself with our use of Program:exit): 3. Could also use this approach for checking consistency between function calls and jsdoc argument signature types; compile to WebAssembly test(`no-undefined-types`): issues gajus#507
1. Add tests (for desired features added to docs) -> implement 2. (apparent problem in eslint itself with our use of Program:exit): 3. Could also use this approach for checking consistency between function calls and jsdoc argument signature types; compile to WebAssembly test(`no-undefined-types`): issues gajus#507
eslint-plugin-jsdoc/no-undefined-types
is correctly added to ESLint configuration.What did you expect to happen?
There should not be an error.
JSDoc definition is correctly imported and used even when the error is present.
The error only appears when imported type is used as a type for a
@property
tag.Error does not appear is used in
@param
tag.What actually happened? Please include the actual, raw output from ESLint.
Please see this ESLint issue for more details.
The text was updated successfully, but these errors were encountered: