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

Add support for translating between character offsets and code point indices #14

Closed
4 tasks done
wooorm opened this issue Dec 21, 2023 · 4 comments
Closed
4 tasks done
Labels
🙅 no/wontfix This is not (enough of) an issue for this project 👎 phase/no Post cannot or will not be acted on

Comments

@wooorm
Copy link
Member

wooorm commented Dec 21, 2023

Initial checklist

Problem

Related: syntax-tree/unist#99.

remark-lint where a user provides a max size of say 80, and they don’t mean the way that JS stores strings.
To check if things are (not) allowed at that point, a lint tool needs to be aware of that difference, and be able to translate between the two.

Solution

Two new methods: toCodePointIndex(offset: number): number / fromCodePointIndex(index: number): number

Alternatives

Different utility.

@github-actions github-actions bot added 👋 phase/new Post is being triaged automatically 🤞 phase/open Post is being triaged manually and removed 👋 phase/new Post is being triaged automatically labels Dec 21, 2023
@remcohaszing
Copy link
Member

remark-lint where a user provides a max size of say 80

I think you mean a max line length by this? In that case, I think you just need to calculate the code point index on the current line, not of the whole file.

@wooorm
Copy link
Member Author

wooorm commented Dec 21, 2023

Yes, it would possible in that case to only look at single lines.

This package can be passed single lines; if that remark-lint rule or other potential use-cases want to implement shortcuts like that, they can. The conversion still needs to be implemented somewhere.

But several remark-lint rules already use this package, to convert between offsets and points. As the entire file is already indexed once, and that rule already looks at every single line, I’m not sure how much it would help to look at single lines.

@wooorm
Copy link
Member Author

wooorm commented Feb 24, 2025

For remark-lint, which was used as the use case for this feature, this was not needed after all: remarkjs/remark-lint@ab5954d.

It might still be an interesting feature, also because of the closed-as-unresolved syntax-tree/unist#99, at some point in the future.

@wooorm wooorm closed this as not planned Won't fix, can't repro, duplicate, stale Feb 24, 2025
@wooorm wooorm added the 🙅 no/wontfix This is not (enough of) an issue for this project label Feb 24, 2025

This comment has been minimized.

@github-actions github-actions bot added 👎 phase/no Post cannot or will not be acted on and removed 🤞 phase/open Post is being triaged manually labels Feb 24, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🙅 no/wontfix This is not (enough of) an issue for this project 👎 phase/no Post cannot or will not be acted on
Development

No branches or pull requests

2 participants