• Stars
    star
    175
  • Rank 218,059 (Top 5 %)
  • Language
    Swift
  • License
    MIT License
  • Created about 8 years ago
  • Updated over 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

A utility to find needless words in Swift function names.

Omit Needless Words

To promote clear usage, the Swift API Design Guidelines advice that we omit needless words in function names. Words that merely repeat type information are specifically identified as needless.

This is a tool that helps you spot those words in your code base.

Install

Prerequisite: have Swift 3 installed on your system.

  1. Clone or download content of this repository.
  2. run make.

Usage

Basic

The command needless can process text from STDIN or files specified in a list of paths. The simplest way to use it is one of the following:

needless path/to/file1.swift path/to/file2.swift
echo "func someName(foo bar: Baz..." | needless

needless will print out function names with needless words and suggest an alternative.

Run needless -h for more details, or read the next section.

Options

Several output formats are included for different use scenarios. They make this command more useful when combined with other scripts/tools.

  • By default, needless prints output in a readable format:

    potential needless words in first parameter label in path/to/file.swift (line 87)
        private func buttonTitleColor(forType type: NewsfeedItemType) -> UIColor {
                ^
    possible alternative: func buttonTitleColor(for type: NewsfeedItemType …
    
  • Use the option -Xcode for clang/swiftc style warning:

    needless -Xcode path/to/file.swift
    
    path/to/file.swift:23:5: warning: potential needless words in function name 'func testWithData(_ data: Data …'; perhaps use 'func test(with data: Data …' instead?
    

    This means you can add needless as a build phase in Xcode to get inline highlighting.

    needless in Xcode

    1. add a "Run Script" build phase in your Xcode project and paste in the following:

      needless -dollar path/to/file.swift
      
      IFS=$'\n' find . -name "*.swift" -exec needless -Xcode {} \;
      

      (customize the command according to your needs. e.g. you may want to change the path . to Sources to avoid warnings for files in Packages or Pods folder).

    2. build your Xcode project.

  • -dollar prints results in $-separated strings:

    needless -dollar path/to/file.swift
    
    potential needless words in function name$path/to/file.swift$22$4$func testWithData(_ data: Data$func test(with data: Data
    

    That's [description]$[path]$[line number]$[column number]$[original name]$[suggested name]

    This format is convenient for parsing and further actions. It's trivial to read it and do automated replacement, for example.

  • -diff will make needless only process lines that begin with character +, ! or >. This is handy when you are dealing with patch formats. Make needless part of your git hooks!

    -diff can be combined with -dollar and -Xcode.

Not a robot

The API guideline starts with "every word in a name should convey salient information at the use site". needless isn't AI with advanced natural language processing capabilities (yet?). In fact, it assumes you use camelCase in function names and merely tries to find problematic function names in a very mechanical (dumb) way. Its suggestions are often awkward/too aggressive. Always prioritize good human judgement please :)

More Repositories

1

Just

Swift HTTP for Humans
Swift
1,397
star
2

tre

Tree command, improved.
Rust
757
star
3

DrString

DrString finds issues in your Swift docstrings and fixes them for you.
Swift
170
star
4

Pathos

File management and path analysis for Swift
Swift
110
star
5

Markra

An open-source Markdown-to-JIRA syntax editor written in SwiftUI for macOS
Swift
92
star
6

Termbox

Swift Wrapper for Termbox: A Lightweight TUI Library
C
66
star
7

TOMLDecoder

From TOML to Swift Codable types.
Swift
63
star
8

git2dayone

A script for logging git commit messages in the app Day One
Shell
39
star
9

DistributionTests

Swift 3 distribution test for open-source libraries.
Makefile
23
star
10

Swift-Framework-Without-Xcode

A sample project to demonstrate how to build and link to Swift frameworks dynamically without using Xcode.
Makefile
22
star
11

Lic

Easy, safe object slicing for Swift
Swift
21
star
12

Tweet-Importer-For-Day-One

Imports Tweet Archive To Day One
Python
21
star
13

dotfiles

Nix
20
star
14

Swipe-Away

An iOS 7 demo of user interaction with UIView achieved via UIDynamics.
Objective-C
17
star
15

cURLLook

Represent your NSURLRequest with a cURL command.
Swift
16
star
16

Comprehension

List Comprehension For Swift
Swift
16
star
17

django-sophie

Just another Django-based blog engine, that runs on GAE.
Python
14
star
18

Clue

Clue is a Swift library, and a command-line tool that finds symbol references in Swift projects.
Swift
14
star
19

ea

ea: make your CLI output actionable.
Rust
13
star
20

BrainAss

A Brainfuck to WebAssembly compiler written in Haskell
Haskell
9
star
21

TerminalPaint

A project that demonstrates how to build a TUI program in Swift
Swift
9
star
22

swift-system-extras

Swift System, battery included.
Swift
9
star
23

Dye

Cross-platform terminal styling for Swift command-line interface.
Swift
8
star
24

NetTime

RFC 3339 compliant date/time data types.
Swift
8
star
25

BitArray

A space-efficient bit array with RandomAccessCollection conformance in Swift.
Swift
5
star
26

Flapcopy

A Flappy Bird inspired HTML5 game.
CoffeeScript
5
star
27

Relay

Stateless alternatives to Combine.Subject
Swift
5
star
28

DrString.vim

Vim integration for DrString
Vim Script
4
star
29

TOMLDeserializer

Replaced by https://github.com/dduan/TOMLDecoder
Swift
4
star
30

IsTTY

Helps you decide whether your file is a terminal device.
Swift
4
star
31

CoverMaker

A small macOS that generates YouTube video thumbnails from metadata, built with SwiftUI and The Composable Architecture
Swift
4
star
32

Factorino

Swift
3
star
33

swift-system-exit

`exit` system call for Swift
Swift
2
star
34

Scmark

Thin, faithful, but Swift-y wrappers for cmark.
C
2
star
35

nixSwiftPM

Nix helper for SwiftPM
Nix
2
star
36

PEG

Parsing Expression Grammar implemented in Swift.
Swift
1
star
37

AllTheSwiftFiles

Fetch all popular Swift files from Github for language feature study
Python
1
star
38

scoop-bucket

Scoop (https://scoop.sh) apps.
1
star
39

herp

Help Extract Real Phrases: A CLI Utility.
Swift
1
star
40

mmm

A interactive CLI helper for manipulating files.
Rust
1
star
41

SwiftOnNix

Scripts for generating Nix expression for the Swift toolchain.
Nix
1
star