Skip to content

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Repository files navigation

attractor-swift

Swift plugin for attractor, the churn vs. complexity tool. Complexity is the per-function cyclomatic complexity reported by lizard; churn comes from attractor's git history.

Installation

gem install attractor attractor-swift

lizard is a Python tool. attractor runs it through uv when lizard itself is not on your PATH:

# one of
brew install uv          # then `uvx lizard` fetches lizard on first use
pip install lizard

attractor finds the plugin by its gem name; nothing to configure.

Usage

cd my-swift-project
attractor calc -c 0 --format table              # every file, table
attractor calc --format json                    # per-function details with line ranges
attractor diff --base main --head HEAD -c 0     # complexity delta of a branch
attractor report                                # the interactive chart

Method-level details carry lizard's CCN and location:

"details": {
  "total": {"score": 3, "line": 6, "end_line": 15},
  "pay":   {"score": 3, "line": 24, "end_line": 30}
}

Two things to know about the numbers:

  • CCN is McCabe cyclomatic complexity, a different scale from flog's Ruby score. attractor reports per language, so they are never compared.
  • lizard names functions without their type (total, not Cart.total). Two functions with the same name in one file are kept apart by their start line (card@32, card@50).

Force a specific runner with ATTRACTOR_LIZARD="python -m lizard".

Using this repository as a template for another language

Everything language-specific is two strings and a detector. To make attractor-kotlin:

  1. Copy this repository. Rename swift → kotlin in file names, module names, the gemspec and the workflow.
  2. lib/attractor/calculators/kotlin_calculator.rb: language: "kotlin" (a name from lizard --help, under -l), file_extension: "kt" (a regex-ish string is fine: "(kt|kts)"), @type = "Kotlin".
  3. lib/attractor/detectors/kotlin_detector.rb: what marks a project (build.gradle.kts, any *.kt).
  4. Replace the fixture in spec/fixtures/ and the expected numbers in the calculator spec; run uvx lizard -l kotlin --csv spec/fixtures/... once to get them.
  5. Push, tag, rake release.

Languages lizard scores today include C/C++, C#, Go, Java, JavaScript, Kotlin, Lua, Objective-C, PHP, Python, Rust, Scala, Swift, TypeScript and more. For languages with a better native metric tool (Ruby has flog, JavaScript has escomplex with class and import context), write the calculator against that tool instead, as attractor-ruby and attractor-javascript do.

Development

bin/setup
bundle exec rspec        # the lizard integration example skips without lizard or uv
bundle exec standardrb

Against an unreleased attractor: ATTRACTOR_PATH=../attractor bundle install.

License

MIT.

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages