jpsim / jpsim/SourceKitten

[Question] Is there a way to detect capture lists?

Open
#398 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Swift
Stars
2.4k
Forks
237
PR merge metrics
No merged PRs in 30d

Description

Hi! Thanks for the amazing tool!

Could you help me to deal with swift capture lists?

$ sourcekitten syntax --text "[weak module]" returns

[
  {
    "type" : "source.lang.swift.syntaxtype.identifier",
    "offset" : 1,
    "length" : 4
  },
  {
    "type" : "source.lang.swift.syntaxtype.identifier",
    "offset" : 6,
    "length" : 6
  }
]

Same for unowned
$ sourcekitten syntax --text "[unowned module]"

[
  {
    "type" : "source.lang.swift.syntaxtype.identifier",
    "offset" : 1,
    "length" : 7
  },
  {
    "type" : "source.lang.swift.syntaxtype.identifier",
    "offset" : 9,
    "length" : 6
  }
]

Note that both weak and unowned are described as identifiers. However they are expected to be attribute.builtins like in the following examples:

$ sourcekitten syntax --text "unowned var module = module"

[
  {
    "type" : "source.lang.swift.syntaxtype.attribute.builtin",
    "offset" : 0,
    "length" : 7
  },
  {
    "type" : "source.lang.swift.syntaxtype.keyword",
    "offset" : 8,
    "length" : 3
  },
  {
    "type" : "source.lang.swift.syntaxtype.identifier",
    "offset" : 12,
    "length" : 6
  },
  {
    "type" : "source.lang.swift.syntaxtype.identifier",
    "offset" : 21,
    "length" : 6
  }
]

$ sourcekitten syntax --text "weak var module = module"

[
  {
    "type" : "source.lang.swift.syntaxtype.attribute.builtin",
    "offset" : 0,
    "length" : 4
  },
  {
    "type" : "source.lang.swift.syntaxtype.keyword",
    "offset" : 5,
    "length" : 3
  },
  {
    "type" : "source.lang.swift.syntaxtype.identifier",
    "offset" : 9,
    "length" : 6
  },
  {
    "type" : "source.lang.swift.syntaxtype.identifier",
    "offset" : 18,
    "length" : 6
  }
]

I want to write a swiftlint rule for restricting unowned usages.
Any help is appreciated. Thanks in advance!

Contributor guide

Open the contributing guide

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 by reproducing the two sourcekitten syntax --text capture-list examples and compare them with the weak var and unowned var outputs in the issue. Determine whether the requested outcome is syntax classification support or usage guidance for SwiftLint; the issue does not identify files, tests, or a defined completion criterion.

Written by the indexing model from the issue text.

Assessment

Tech stack
swift
Domain
tooling
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.