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

Open
4 tasks done
wooorm opened this issue Dec 21, 2023 · 2 comments
Open
4 tasks done
Labels
🤞 phase/open Post is being triaged manually

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🤞 phase/open Post is being triaged manually
Development

No branches or pull requests

2 participants