Coder Social home page Coder Social logo

source-foundry / ufofmt Goto Github PK

View Code? Open in Web Editor NEW
7.0 5.0 1.0 364 KB

A fast, flexible UFO source file formatter based on the Rust Norad library

License: Apache License 2.0

Rust 99.72% Makefile 0.28%
ufo typeface source-code formatter normalizer font rustlang

ufofmt's Introduction

ufofmt

crates.io stable toolchain unit tests beta toolchain unit tests

A fast, flexible UFO source file formatter based on the Rust Norad library

About

ufofmt is a Rust executable that supports customizable UFO source file formatting.

Default source file format

  glif plist fea
line endings line feed line feed line feed
indentation spacing single tab per level single tab per level n/a
XML declaration attributes double quotes double quotes n/a

Custom formatting options are described in the Usage section below.

Installation

The installation process installs the ufofmt executable.

Install Rust, then follow the instructions below.

User installation

The following command installs the latest release build:

$ cargo install ufofmt

Upgrade a previous installation to a new release version with:

$ cargo install --force ufofmt

Developer installation

The following command installs a build from the latest commit in the main branch of the repository:

$ git clone https://github.com/source-foundry/ufofmt.git
$ cd ufofmt && cargo install --path .

Usage

Pass one or more UFO source directory paths to the ufofmt executable:

$ ufofmt [OPTIONS] [UFO PATH 1] ... [UFO PATH N]

Use the command ufofmt --help to view all available command line options.

Custom source formatting options

Indentation spacing character type

Single tab indentation spacing per level is the default. Switch to space characters with the --indent-space command line option. See the section below to define the number of indentation spacing characters per level.

Indentation spacing character number per level

Define between 1 - 4 tab or space indentation chars with the --indent-number [NUMBER] command line option. See the section above to use spaces instead of tabs.

XML declaration quote style

XML declaration attributes are enclosed in double quotes by default. Convert to single quotes with the --singlequotes command line option.

Contributing

Contributions to the project are welcomed! All contributions are accepted under the project license defined in the License section below.

Source contributions

Test local changes in the executable with:

$ cargo run -- [ARGS]

Add tests to cover your source changes and run the test suite locally with:

$ cargo test

Please open a GitHub pull request with your change proposal.

Documentation contributions

Please build and review your documentation changes locally with:

$ cargo doc --open

Please open a GitHub pull request with your change proposal.

License

Apache License v2.0

ufofmt's People

Contributors

chrissimpkins avatar dependabot[bot] avatar madig avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

Forkers

isabella232

ufofmt's Issues

Support custom single / double quote formatting in write files

norad's default is double quote formatting of the XML declaration attribute definitions in all UFO XML / plist files.

This is another source of multi-file diffs across UFO serializer tools. Some format the attribute definitions with single quotes.

The most flexible, useful formatting approach may be one where the user is permitted to define what they want?

This is not currently supported in the norad lib / its plist lib dependency TMK.

Related #18

norad default UFO serialization format

Thread to track the stability of the norad UFO write format.

Current status: unstable
norad v1.0 tracker: linebender/norad#195

Defaults:

  • line endings: line feed (\n) across plist, glif, and fea files on all platforms
  • spacing: single tab per level
  • XML declaration header quote style around attributes: double quotes
  • plist lib keys are sorted in lexicographic ordering by Unicode code point value (see #22 (comment))
  glif plist fea
line ending line feed line feed line feed
XML declaration double quotes double quotes n/a
indentation spacing single tab single tab n/a

Improve invalid source path error messages

$ target/release/ufofmt 1 2 3 4 5
[ERROR] Read error in "4": Io(Os { code: 2, kind: NotFound, message: "No such file or directory" })
[ERROR] Read error in "5": Io(Os { code: 2, kind: NotFound, message: "No such file or directory" })
[ERROR] Read error in "3": Io(Os { code: 2, kind: NotFound, message: "No such file or directory" })
[ERROR] Read error in "1": Io(Os { code: 2, kind: NotFound, message: "No such file or directory" })
[ERROR] Read error in "2": Io(Os { code: 2, kind: NotFound, message: "No such file or directory" })

Display chained errors

I'm trying to make norad cleanly chain errors instead of hoisting the error messages form lower into wrapping error messages. Compare what anyhow does:

Error: Failed to read glyph file from 'C:\...\MutatorSansLightWide.ufo\glyphs\A_.glif'

Caused by:
    0: Failed to read or parse XML file
    1: Expecting </array> found </dict>

vs. ufofmt's

[ERROR] norad read error: C:\...\MutatorSansLightWide.ufo: Failed to read glyph file from 'C:\...\MutatorSansLightWide.ufo\glyphs\A_.glif'

Remove validators module

I thought that we may need multiple file path validators on this side but it looks like these may be available in custom error types to support error msgs here linebender/norad#146

Will remove the validators module and transition to a norad lib error handling approach if those changes land in a release.

Related #11

Support custom indentation space formatting in write files

Related linebender/norad#145

It might be useful for a user to define the type (tab, space) and length (one, two, four) of space formatting in the file writes. This would reduce text diffs relative to other tooling used in a UFO work pipeline. I'm not sure that it is necessary to be dogmatic about this issue. The goal is to achieve consistent formatting and that can be, at least partially, user-defined + project-specific?

This would require support in the norad project.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.