Skip to content
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

feat: add missing type definitions #246

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

aryaemami59
Copy link

This PR:

@aryaemami59 aryaemami59 force-pushed the type-definitions branch 2 times, most recently from 5826543 to d8f9980 Compare October 26, 2024 21:56
@aryaemami59 aryaemami59 marked this pull request as ready for review October 26, 2024 22:11
index.js Outdated Show resolved Hide resolved
package.json Outdated Show resolved Hide resolved
tsconfig.json Outdated Show resolved Hide resolved
types/index.d.ts Outdated Show resolved Hide resolved
.github/workflows/ci.yml Outdated Show resolved Hide resolved
configs.js Outdated
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should revert this file as well

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The reason I made those changes is because it would otherwise cause issues when with named exports in ESM files, here is a before and after:

Before:

eslint-plugin-eslint-comments-before

After:

eslint-plugin-eslint-comments-after

Comment on lines +26 to +31
"typesVersions": {
"*": {
"configs": [
"./types/configs.d.ts"
]
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We already have configs types defined, so I don't think it's necessary to declare them again in typesVersions?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Without it Node10 module resolution will fail when importing from @eslint-community/eslint-plugin-eslint-comments/configs.

Copy link

@scagood scagood left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Generally looks good to me 🙇‍♂️

package.json Outdated
"@babel/core": "^7.22.9",
"@babel/eslint-parser": "^7.22.9",
"@eslint-community/eslint-plugin-mysticatea": "^15.5.1",
"@types/eslint": "^9.6.1",
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe it's best to shadow the eslint version here? (^8)

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could update version of eslint instead since eslint now provides its own type definitions so no need to use @types/eslint. Thoughts?

types/configs.d.ts Outdated Show resolved Hide resolved
@aryaemami59
Copy link
Author

I'm thinking about adding some type tests to instill some more confidence, let me know if that's something you would be interested in.

@scagood
Copy link

scagood commented Nov 17, 2024

That very much would be!

We have an issue in a different eslint-community repo to do exactly that (eslint-community/eslint-plugin-n#212). So I would (possibly) look to 'borrow' the prior art if you do end up adding some tests :)

Comment on lines +1 to +6
import configs = require("@eslint-community/eslint-plugin-eslint-comments/configs")
import expectTypeModule = require("expect-type")

import type { Linter } from "eslint"

import expectTypeOf = expectTypeModule.expectTypeOf
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should most of this not be const instead of import?

Suggested change
import configs = require("@eslint-community/eslint-plugin-eslint-comments/configs")
import expectTypeModule = require("expect-type")
import type { Linter } from "eslint"
import expectTypeOf = expectTypeModule.expectTypeOf
const configs = require("@eslint-community/eslint-plugin-eslint-comments/configs")
const { expectTypeOf } = require("expect-type")
import type { Linter } from "eslint"

I have never seen this syntax before, so do correct me if I am wrong 😅

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In this file I'm testing the types to make sure they work with TypeScript's CJS syntax. So something like const configs = require("@eslint-community/eslint-plugin-eslint-comments/configs") becomes import configs = require("@eslint-community/eslint-plugin-eslint-comments/configs"). It's to test ESM/CJS Interoperability on a type level.

Reference

Copy link

@scagood scagood Nov 20, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, neat! Thanks for the explanation :)


Edit: I can't seem to mark this as resolved 👀

Copy link
Author

@aryaemami59 aryaemami59 Nov 20, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@scagood It might be good to fully migrate to TypeScript so the types and runtime code don't get out of sync. Thoughts?

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here is the previous discussion in the eslint-plugin-n repo, I am okay with either tbh
eslint-community/eslint-plugin-n#371


That being said, that is more a question for @eslint-community/eslint-plugin-eslint-comments.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ah I see, honestly I would be happy to do it, I've done a lot of TS migrations and I could definitely do this one too. We can bundle with tsup which would be even easier. Do you want me to put together a quick POC so you can kind of see what it will look like?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

missing TypeScript declaration file
4 participants