-
-
Notifications
You must be signed in to change notification settings - Fork 160
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
In typescript mode, only allow 'object' #800
Comments
I realized that maybe |
Why doesn't this change "jsdoc": {
"mode": "typescript",
"preferredTypes": {
// Use 'object' in typescript mode, see TypeScript's Do's and Dont's
"Object": "object"
}
} I even tried: "jsdoc": {
"mode": "typescript",
"preferredTypes": {
// Use 'object' in typescript mode, see TypeScript's Do's and Dont's
"Object": "object",
"Object[]": "object[]",
}
} But that did not work either. Is that a bug? |
Yes, this was a bug. I've fixed this in https://github.com/gajus/eslint-plugin-jsdoc/releases/tag/v37.6.3 to allow a mapping of |
@brettz9 great that you fixed it in 37.6.3, thanks! I am not sure about the answer to your question. My intent is to use this in JSDoc as soon as jsdoc-type-pratt-parser/jsdoc-type-pratt-parser#101 has been fixed: "preferredTypes": {
"Object": "object",
"Object<>": false,
"Object.<>": false,
"object<>": false,
"object.<>": false
}, Afaik |
@brettz9 the fix made in 37.6.3 broke it in other, unforseen ways: "settings": {
"jsdoc": {
"mode": "typescript",
"preferredTypes": {
// Use 'object' in typescript mode, see TypeScript's Do's and Dont's
"Object": "object",
"object<>": "Object<>", // see https://github.com/jsdoc-type-pratt-parser/jsdoc-type-pratt-parser/issues/101
"object.<>": "Object<>" // see https://github.com/jsdoc-type-pratt-parser/jsdoc-type-pratt-parser/issues/101
}
}
} This config now changes (via --fix): /**
* @returns {Object<string, string>} variables passed to the dashboard
*/ into /**
* @returns {object<string, string>} variables passed to the dashboard
*/ But the latter is reported as So I am in a deadloop here. |
I'm afraid I don't have time to look at this now. If you want to fix it, feel free to send in a PR. I'm also sorry about there being in a sense a regression, but I think it is preferable to at least have a single substitution working as intended, and deal with the circular issue in another fix (and then make it the default for TS if that is the consensus here). |
@brettz9 that is fine, I can wait. |
I am afraid the changes in https://github.com/gajus/eslint-plugin-jsdoc/releases/tag/v37.6.3 blocks us from updating to that version or later. "mode": "typescript",
"preferredTypes": {
// Use 'object' in typescript mode, see TypeScript's Do's and Dont's
"Object": "object",
"object<>": "Object<>", // see https://github.com/jsdoc-type-pratt-parser/jsdoc-type-pratt-parser/issues/101
"object.<>": "Object<>" // see https://github.com/jsdoc-type-pratt-parser/jsdoc-type-pratt-parser/issues/101
}, |
No promises, but I hope to take a look at this within the next day or so. |
With a little exploring. in trying TS within JSDoc... It appears that TS simply doesn't allow: Trying And However, TS does support Both So I think we want the following instead (adding dots to your last two, and adding a new case to convert `Object<>"): "preferredTypes": {
// Use 'object' in typescript mode, see TypeScript's Do's and Dont's
"Object": "object",
"object<>": "Object.<>", // see https://github.com/jsdoc-type-pratt-parser/jsdoc-type-pratt-parser/issues/101
"object.<>": "Object.<>", // see https://github.com/jsdoc-type-pratt-parser/jsdoc-type-pratt-parser/issues/101
"Object<>": "Object.<>"
}, I think we should probably make this the default for JSDoc too so as to foster better compatibility. Apparently TS uses |
@brettz9 I just tested it locally in VS Code, where hovering function definitions with this shows proper TypeScript parsing. I am not sure why that did not work for you. |
Ah, sorry--I had been switching branches, so perhaps that was getting me to use an older version. Yeah, I see that it works now. I also see that if microsoft/TypeScript#20555 is followed, there will eventually be no differences between the casings as well. But frankly, I find that confusing, and think it's better to follow the TypeScript differentiation of casing (and our convention) But I guess we can go with preferring the non-dot form even if the TS JSDoc page uses that in its example as does the JSDoc type docs. |
…ding parent objects unless there is `unifyParentAndChildTypeChecks` config (should only unify with arrays); fixes gajus#800 Also updates devDeps.
…ding parent objects unless there is `unifyParentAndChildTypeChecks` config (should only unify with arrays); fixes gajus#800
…pescript" mode even with generic preferredTypes match (unless there is `unifyParentAndChildTypeChecks` config); fixes gajus#800
I've submitted #835 to fix this if someone else wants to try that before I apply it @thernstig / @jaydenseric . |
Note that the PR does not switch the defaults nor apply to non-TypeScript mode. I figure we could roll that up with with #834 |
@brettz9 it works! I get a bit of a strange output though:
|
@thernstig : Those quotes are for the name portion of the tag, i.e., the string of non-whitespace after the type, e.g., you could get that result with |
I think I will go ahead and release. I'll mark this as fixed and people can track #834 if we make this the default (as I think we should). |
…pescript" mode even with generic preferredTypes match (unless there is `unifyParentAndChildTypeChecks` config); fixes #800
🎉 This issue has been resolved in version 37.7.1 🎉 The release is available on: Your semantic-release bot 📦🚀 |
This PR contains the following updates: | Package | Type | Update | Change | |---|---|---|---| | [eslint-plugin-jsdoc](https://github.com/gajus/eslint-plugin-jsdoc) | devDependencies | patch | [`37.7.0` -> `37.7.1`](https://renovatebot.com/diffs/npm/eslint-plugin-jsdoc/37.7.0/37.7.1) | --- ### Release Notes <details> <summary>gajus/eslint-plugin-jsdoc</summary> ### [`v37.7.1`](https://github.com/gajus/eslint-plugin-jsdoc/releases/v37.7.1) [Compare Source](gajus/eslint-plugin-jsdoc@v37.7.0...v37.7.1) ##### Bug Fixes - **`check-types`:** prevent parent objects from being reported in "typescript" mode even with generic preferredTypes match (unless there is `unifyParentAndChildTypeChecks` config); fixes [#​800](gajus/eslint-plugin-jsdoc#800) ([9d0a75d](gajus/eslint-plugin-jsdoc@9d0a75d)) </details> --- ### Configuration 📅 **Schedule**: At any time (no schedule defined). 🚦 **Automerge**: Disabled by config. Please merge this manually once you are satisfied. ♻ **Rebasing**: Renovate will not automatically rebase this PR, because other commits have been found. 🔕 **Ignore**: Close this PR and you won't be reminded about this update again. --- - [ ] <!-- rebase-check -->If you want to rebase/retry this PR, click this checkbox. --- This PR has been generated by [Renovate Bot](https://github.com/renovatebot/renovate). Co-authored-by: cabr2-bot <[email protected]> Co-authored-by: crapStone <[email protected]> Reviewed-on: https://codeberg.org/Calciumdibromid/CaBr2/pulls/1145 Reviewed-by: crapStone <[email protected]> Co-authored-by: Calciumdibromid Bot <[email protected]> Co-committed-by: Calciumdibromid Bot <[email protected]>
…s`, prefer `object` for plain objects and otherwise prefer `Object<>`; fixes gajus#800
🎉 This issue has been resolved in version 38.1.0 🎉 The release is available on: Your semantic-release bot 📦🚀 |
This PR contains the following updates: | Package | Type | Update | Change | |---|---|---|---| | [eslint-plugin-jsdoc](https://github.com/gajus/eslint-plugin-jsdoc) | devDependencies | minor | [`38.0.8` -> `38.1.3`](https://renovatebot.com/diffs/npm/eslint-plugin-jsdoc/38.0.8/38.1.3) | --- ### Release Notes <details> <summary>gajus/eslint-plugin-jsdoc</summary> ### [`v38.1.3`](https://github.com/gajus/eslint-plugin-jsdoc/releases/v38.1.3) [Compare Source](gajus/eslint-plugin-jsdoc@v38.1.2...v38.1.3) ##### Bug Fixes - **`check-types`, `no-undefined-types`:** safer optional chaining ([63a96ee](gajus/eslint-plugin-jsdoc@63a96ee)) ### [`v38.1.2`](https://github.com/gajus/eslint-plugin-jsdoc/releases/v38.1.2) [Compare Source](gajus/eslint-plugin-jsdoc@v38.1.1...v38.1.2) ##### Bug Fixes - **`check-types`:** proper use of optional chaining; fixes [#​861](gajus/eslint-plugin-jsdoc#861) ([7dbdd9f](gajus/eslint-plugin-jsdoc@7dbdd9f)) ### [`v38.1.1`](https://github.com/gajus/eslint-plugin-jsdoc/releases/v38.1.1) [Compare Source](gajus/eslint-plugin-jsdoc@v38.1.0...v38.1.1) ##### Bug Fixes - **`check-types`:** for `jsdoc` mode, avoid objecting to upper-case; fixes [#​860](gajus/eslint-plugin-jsdoc#860) ([d11d271](gajus/eslint-plugin-jsdoc@d11d271)) ### [`v38.1.0`](https://github.com/gajus/eslint-plugin-jsdoc/releases/v38.1.0) [Compare Source](gajus/eslint-plugin-jsdoc@v38.0.8...v38.1.0) ##### Features - unless the user supplies their own `object` type `preferredTypes`, prefer `object` for plain objects and otherwise prefer `Object<>`; fixes [#​800](gajus/eslint-plugin-jsdoc#800) ([#​855](gajus/eslint-plugin-jsdoc#855)) ([0f27282](gajus/eslint-plugin-jsdoc@0f27282)) </details> --- ### Configuration 📅 **Schedule**: At any time (no schedule defined). 🚦 **Automerge**: Disabled by config. Please merge this manually once you are satisfied. ♻ **Rebasing**: Whenever PR becomes conflicted, or you tick the rebase/retry checkbox. 🔕 **Ignore**: Close this PR and you won't be reminded about this update again. --- - [ ] <!-- rebase-check -->If you want to rebase/retry this PR, click this checkbox. --- This PR has been generated by [Renovate Bot](https://github.com/renovatebot/renovate). Co-authored-by: cabr2-bot <[email protected]> Reviewed-on: https://codeberg.org/Calciumdibromid/CaBr2/pulls/1262 Reviewed-by: 6543 <[email protected]> Co-authored-by: Calciumdibromid Bot <[email protected]> Co-committed-by: Calciumdibromid Bot <[email protected]>
Motivation
TypeScript Do's and Dont's (https://www.typescriptlang.org/docs/handbook/declaration-files/do-s-and-don-ts.html#general-types) says to never use
Object
(capital O). So when in typescript mode, only everobject
should be allowed as default, and notObject
.The reason is that a ton of users in our project always incorrectly uses
Object
in JSDoc, when it pretty much always should beobject
since we use typescript mode, which causes a lot of unnecessary code review comments.Current behavior
When eslint-plugin-jsdoc is set to
"mode": "typescript"
, then bothObject
andobject
is allowed. See https://github.com/gajus/eslint-plugin-jsdoc#check-types.Desired behavior
When
"mode": "typescript"
is set, onlyobject
should be allowed by default.Optional: Also
object<>
,object.<>
,Object<>
andObject.<>
should be disallowed. One can use{s: string, n: number}
instead when in typescript mode.Alternatives considered
I could define this setting:
But the problem with that is that pretty much anyone using typescript mode would have to use that setting. It'd be much better to change the default, as that is an absolute "do and don't" to follow.
Those who want to allow
Object
orObject<>
etc. can already do that viapreferredTypes
.Slightly related #709.
The text was updated successfully, but these errors were encountered: