npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@aparajita/swiftly

v1.0.4

Published

A wrapper around swiftlint and swiftformat that combines their execution and formats their output like eslint

Downloads

32

Readme

swiftly

swiftlint is an essential tool for checking and formatting Swift code. But it doesn’t do much formatting, especially compared to Prettier. That’s where swiftformat shines, because it lets you (almost) forget about formatting your code altogether, just like Prettier. Wouldn’t it be great to be able to run both swiftlint and swiftformat as one? Now you can!

This package installs a binary that wraps the functionality of both swiftlint and swiftformat together, while offering the following advantages:

  • Errors from both tools are aggregated and sorted.
  • The output from both tools is reformatted in a unified way to be way easier to read, including a concise and informative summary at the end.
  • You can use globs with swiftformat.
  • Both binaries return a non-zero exit code if they find problems, which helps with command pipelines.

Installation

Before installing this package, you will first have to install swiftlint and swiftformat globally. On macOS, use Homebrew:

% brew install swiftlint swiftformat

For other platforms, see the installation instructions for the respective binaries.

Once you have installed the binaries, you can install this package as a dev dependency.

% pnpm add -D @aparajita/swiftly

Usage

If you run swiftly --help, you will get a description of all of the options:

Usage: swiftly [options] [files]

Options:
      --help         Show help                                 [boolean]
      --version      Show version number                       [boolean]
  -l, --swiftlint    Only run swiftlint                        [boolean]
  -f, --swiftformat  Only run swiftformat                      [boolean]
  -F, --fix          Fix any fixable errors                    [boolean]
  -s, --single-line  Output errors like eslint’s unix format   [boolean]
  -q, --quiet        Do not produce any output                 [boolean]

Choosing the tools to run

By default, if you specify neither --swiftlint nor --swiftformat, both tools will run. If you specify either of those, only that tool will run. Those two options are mutually exclusive.

Specifying the format

By default, the results are colorized and output in a format very similar to eslint’s stylish format, which groups errors under the file path, making the output very easy to read. In WebStorm, the line:column references produced in its terminal by the default format of swiftly are clickable links that open the file at that point. VS Code (and presumably many other editors) cannot parse the stylish format, so to produce a format with clickable links, you will want to pass the --single-line option, which produces output like eslint’s unix format, but with file paths colorized according to the error level!

Linting vs. fixing

By default, the tools are run in lint-only mode. They will find and report any errors. If you pass --fix, first the tools are run in fix mode, and then they are run in lint-only mode to report any errors that could not be fixed. In either case, if there are no errors, there is no output.

Exit status

If either tool reports any errors, swiftly exits with a status of 1. This makes it easy to include it in a script pipeline, for example:

{
  "scripts": {
    "build": "pnpm check && vite build",
    "check": "pnpm lint && pnpm swiftly",
    "swiftly": "swiftly 'src/**/*.swift'"
  }
}

Sometimes you may only be interested in the exit status. In that case pass --quiet and all output will be suppressed, but the exit status will still be set.

Specifying the files to check

Any non-option arguments passed to swiftly are considered either paths or globs. Note that to pass a glob to swiftly you must enclose it is single or double quotes, otherwise the shell will expand it.

If an argument is a glob, it is expanded, otherwise it is taken as is. For example, given the following file structure:

project
  test
    TestList.swift
  src
    Foo.swift
    Bar.swift
    ui
      List.swift
      Dialog.swift

this would check every Swift file in the src directory and its subdirectories:

% swiftly src

while this would only check Swift files within the src directory itself:

% swiftly 'src/*.swift'

and this would check all Swift files in the project:

% swiftly '**/*.swift'

Configuration

Because swiftly is passing arguments to two very different tools, you cannot pass configuration options (other than those listed above) directly to the tools from the command line. You can, however, use configuration files.

Under the hood, swiftly uses node-swiftlint to run swiftlint, so in addition to the standard .swiftlint.yml configuration file, you can also use an npm package (such as @ionic/swiftlint-config) as a config source.

As for swiftformat, you can use a standard .swiftformat config file.