typos icon indicating copy to clipboard operation
typos copied to clipboard

False positive: wdth

Open kachick opened this issue 7 months ago • 2 comments

Please complete the following tasks

Valid word

wdth

Incorrect correction

width

Justification

When I test with typos 1.32.0, it flags wdth as a typo and suggests width.

However, wdth is a design-variation axes and the tag in OpenType 1.8 spec, meaning Width. This tag is also widely used by web developers in CSS, for example, with the font-variation-settings property.

  • OpenType definition: https://github.com/microsoft/OpenTypeDesignVariationAxisTags/blob/5ea229006014c614654242a29f49424c1d0659fa/BackgroundOnAxes.md?plain=1#L20-L25
    • Italic (tag: ital)
    • Optical size (tag: opsz)
    • Slant (tag: slnt)
    • Weight (tag: wght)
    • Width (tag: wdth)
  • CSS usage example: https://github.com/mdn/content/blob/d80455b193a5e5f1789e4c941aaaecaae3034d5b/files/en-us/web/css/font-variation-settings/index.md?plain=1#L90-L121
  • typos started detecting wdth after a request in: https://github.com/crate-ci/typos/issues/1024#issuecomment-2168557914.

Notes

wdth is mostly used in CSS and HTML files. It's not common in general text.

My suggestion is to allow wdth only in files like .css and .html. This way, typos can avoid false positives while still catching real typos in other files.

kachick avatar May 28 '25 10:05 kachick

We have a lot of these odd cases for typos / false positives and I worry that if we try to handle every valid non-standard spelling that exists, we won't have any typos left to correct. I wonder what the line should be for us having built-in support vs leaving this to people's configs.

In particular, when it comes to per-file-type overides, there is the issue of how much is something referred to outside of that file type.

epage avatar May 28 '25 14:05 epage

Yeah, I agree this is a trade-off problem, and I respect the project's decisions on how to handle these cases. Thanks for your consideration.

I'm already using a global typos config to ignore 1-3 character words. This helps avoid common false positives, and I haven't seen any issues from this setting in 13 months.

My issue is wdth has 4 characters. I often make typos in words this long or longer, so a blanket ignore for 4+ character words isn't practical. I usually add such specific cases to my config individually.

However, I understand typos doesn't currently offer file-specific word ignores through personal configs; that seems to be only possible by modifying the tool itself. If typos supported file-specific word ignores via personal configs, that would be perfectly sufficient for my needs.

kachick avatar May 28 '25 16:05 kachick

If typos supported file-specific word ignores via personal configs, that would be perfectly sufficient for my needs.

To be clear, you can

  • ignore wdth for all files
  • ignore wdth for specific file types (.css, .html)
  • use some common regexes to define inline ignore directives (#316 for built-in support)

Is there a reason you need to define per-file ignores in the config over any of the above options?

epage avatar Aug 13 '25 20:08 epage

Ah, my apologies for the confusing wording.

When I wrote file-specific, I meant to say file-type-specific. Likely ignore wdth for specific file types (.css, .html).

kachick avatar Aug 14 '25 02:08 kachick

That would be

[type.css.extend-words]
wdth = "wdth"
[type.html.extend-words]
wdth = "wdth"

epage avatar Aug 14 '25 13:08 epage

Oops, I didn't realize that config options for file types are already available. I'll close this issue now. My apologies for the confusion.

kachick avatar Aug 14 '25 13:08 kachick

Relevant commands and config

See supported types

$ typos --type-list

See the effective config

$ typos --dump-config -

Add globs to a file type (including for defining new file types)

[type.<name>]
extend-glob = []

epage avatar Aug 14 '25 14:08 epage