PrismJS / PrismJS/prism

Swift class regex doesn't support private names (ex. '_Foo')

Open Beginner friendly
#4,100 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
JavaScript
Stars
13k
Forks
1.4k
Avg merge
15h 36m
Merged PRs (30d)
3

Description

https://github.com/PrismJS/prism/blob/d805f30275e279907cbad8a339a3d899fc0ea8d8/src/languages/swift.js#L139-L140

In swift, we have a pattern of naming private things a client can but really shouldn't touch with one or more prefixed underscore.
With the current regex though, it must start with /[A-Z]/, is something like _Foo would not match.
The solution could be as simple as: /\b_*[A-Z](?:[A-Z_\d]*[a-z]\w*)?\b/, or /\b(?:_+)?[A-Z](?:[A-Z_\d]*[a-z]\w*)?\b/.

Technically swift also supports naming both classes (and funcs and vars) literally anything (even including whitespace) by wrapping the name in backticks (ex. `Foo Bar`), but that's very rarely used and I think can safely be excluded.

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start in src/languages/swift.js at lines 139-140, where the class-name regex is defined. Check the existing pattern against a private Swift class such as _Foo, then update it so prefixed-underscore names are recognized while ordinary class names continue to match.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, swift
Domain
tooling
Issue type
Bug
Difficulty
1/5
Estimated time
Under an hour
Activity status
Active
Clarity
Clearly specified
Newbie friendliness
88/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.