• Stars
    star
    207
  • Rank 181,619 (Top 4 %)
  • Language
    Elixir
  • License
    Apache License 2.0
  • Created 12 months ago
  • Updated 11 months ago

Reviews

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

Repository Details

An @elixir-lang code-style enforcer that will just FIFY instead of complaining

Styler

Styler is an Elixir formatter plugin that's combination of mix format and mix credo, except instead of telling you what's wrong, it just rewrites the code for you to fit its style rules.

Installation

Add :styler as a dependency to your project's mix.exs:

def deps do
  [
    {:styler, "~> 0.7", only: [:dev, :test], runtime: false},
  ]
end

Usage

We recommend using Styler as a formatter plugin, but it comes with a task for making it easy to try styling smaller portions of your project or for installing without modifying your dependencies (via mix's archive.install feature)

As a Formatter plugin

Add Styler as a plugin to your .formatter.exs file

[
  plugins: [Styler]
]

And that's it! Now when you run mix format you'll also get the benefits of Styler's definitely-always-right style fixes.

As a Mix Task

$ mix style

The task can helpful for slowly converting a codebase directory-by-directory. It also allows you to use mix archive.install to easily test run Styler on a project without modifying its dependencies:

$ mix archive.install hex styler

mix style is designed to take the same basic options as mix format.

See mix help style for more.

Configuration

There isn't any! This is intentional.

Styler's @adobe's internal Style Guide Enforcer - allowing exceptions to the styles goes against that ethos. Happily, it's open source and thus yours to do with as you will =)

Styles

You can find the currently-enabled styles in the Styler module, inside of its @styles module attribute. Each Style's moduledoc will tell you more about what it rewrites.

Credo Rules Styler Replaces

If you're using Credo and Styler, we recommend disabling these rules in .credo.exs to save on unnecessary checks in CI.

Credo credo notes
Credo.Check.Consistency.MultiAliasImportRequireUse always expands A.{B, C}
Credo.Check.Consistency.ParameterPatternMatching also case statements, anon functions
Credo.Check.Readability.AliasOrder
Credo.Check.Readability.BlockPipe
Credo.Check.Readability.LargeNumbers goes further than formatter - fixes bad underscores, eg: 100_00 -> 10_000
Credo.Check.Readability.ModuleDoc adds @moduledoc false
Credo.Check.Readability.MultiAlias
Credo.Check.Readability.OneArityFunctionInPipe
Credo.Check.Readability.ParenthesesOnZeroArityDefs removes parens
Credo.Check.Readability.PipeIntoAnonymousFunctions
Credo.Check.Readability.PreferImplicitTry
Credo.Check.Readability.SinglePipe
Credo.Check.Readability.StrictModuleLayout potentially breaks compilation (see notes above)
Credo.Check.Readability.UnnecessaryAliasExpansion
Credo.Check.Refactor.CaseTrivialMatches
Credo.Check.Refactor.FilterCount in pipes only
Credo.Check.Refactor.MapInto in pipes only
Credo.Check.Refactor.MapJoin in pipes only
Credo.Check.Refactor.PipeChainStart allows ecto's from

Your first Styling

Speed: Expect the first run to take some time as Styler rewrites violations of styles.

Once styled the first time, future styling formats shouldn't take noticeably more time.

Roughly, Styler puts about a 10% slow down on mix format.

Troubleshooting: Compilation broke due to Module Directive rearrangement

Sometimes naively moving Module Directives around can break compilation.

Here's helpers on how to manually fix that and have a happy styling for the rest of your codebase's life.

Alias dependency

If you have an alias that, for example, a @behaviour relies on, compilation will break after your first run. This requires one-time manual fixing to get your repo in line with Styler's standards.

For example, if your code was this:

defmodule MyModule do
  @moduledoc "Implements MyBehaviour!"
  alias Deeply.Nested.MyBehaviour
  @behaviour MyBehaviour
  ...
end

then Styler will style the file like this, which cannot compile due to MyBehaviour not being defined.

defmodule MyModule do
  @moduledoc "Implements MyBehaviour!"
  @behaviour MyBehaviour  # <------ compilation error, MyBehaviour is not defined!

  alias Deeply.Nested.MyBehaviour

  ...
end

A simple solution is to manually expand the alias with a find-replace-all like: @behaviour MyBehaviour -> @behaviour Deeply.Nested.MyBehaviour. It's important to specify that you only want to find-replace with the @behaviour prefix or you'll unintentially expand MyBehaviour everywhere in the codebase.

Module Attribute dependency

Another common compilation break on the first run is a @moduledoc that depended on another module attribute which was moved below it.

For example, given the following broken code after an initial mix format:

defmodule MyGreatLibrary do
  @moduledoc make_pretty_docs(@library_options)

  @library_options [ ... ]
end

You can fix the code by moving the static value outside of the module into a naked variable and then reference it in the module.

Yes, this is a thing you can do in a .ex file =)

library_options = [ ... ]

defmodule MyGreatLibrary do
  @moduledoc make_pretty_docs(library_options)

  @library_options library_options
end

Thanks & Inspiration

Sourceror

This work was inspired by earlier large-scale rewrites of an internal codebase that used the fantastic tool Sourceror.

The initial implementation of Styler used Sourceror, but Sourceror's AST-embedding comment algorithm slows Styler down to the point that it's no longer an appropriate drop-in for mix format.

Still, we're grateful for the inspiration Sourceror provided and the changes to the Elixir AST APIs that it drove.

The AST-Zipper implementation in this project was forked from Sourceror's implementation.

Credo

Similarly, this project originated from one-off scripts doing large scale rewrites of an enormous codebase as part of an effort to enable particular Credo rules for that codebase. Credo's tests and implementations were referenced for implementing Styles that took the work the rest of the way. Thanks to Credo & the Elixir community at large for coalescing around many of these Elixir style credos.

More Repositories

1

brackets

An open source code editor for the web, written in JavaScript, HTML and CSS.
JavaScript
33,313
star
2

react-spectrum

A collection of libraries and tools that help you build adaptive, accessible, and robust user experiences.
TypeScript
11,372
star
3

leonardo

Generate colors based on a desired contrast ratio
JavaScript
1,834
star
4

antialiased-cnns

pip install antialiased-cnns to improve stability and accuracy
Python
1,611
star
5

balance-text

A plugin for implementing balancing of wrapping text in a web page
JavaScript
1,362
star
6

adobe.github.com

Adobe central hub for open source
CSS
1,290
star
7

brackets-shell

CEF3-based application shell for Brackets.
Python
1,176
star
8

spectrum-web-components

Spectrum Web Components
TypeScript
1,151
star
9

spectrum-css

The standard CSS implementation of the Spectrum design language.
CSS
1,146
star
10

aem-core-wcm-components

Standardized components to build websites with AEM.
Java
706
star
11

S3Mock

A simple mock implementation of the AWS S3 API startable as Docker image, TestContainer, JUnit 4 rule, JUnit Jupiter extension or TestNG listener
Java
699
star
12

jsonschema2md

Convert Complex JSON Schemas into Markdown Documentation
JavaScript
563
star
13

NLP-Cube

Natural Language Processing Pipeline - Sentence Splitting, Tokenization, Lemmatization, Part-of-speech Tagging and Dependency Parsing
HTML
549
star
14

aem-project-archetype

Maven template to create best-practice websites on AEM.
JavaScript
520
star
15

ferrum

Features from the rust language in javascript: Provides Traits/Type classes & a hashing infrastructure and an advanced library for working with sequences/iterators in js
JavaScript
496
star
16

brackets-app

Deprecated CEF1-based app shell for Brackets. Use https://github.com/adobe/brackets-shell instead.
C++
490
star
17

cryptr

Cryptr: a GUI for Hashicorp's Vault
HTML
481
star
18

cssfilterlab

CSS FilterLab
JavaScript
348
star
19

hyde

A front-end to Jekyll that parses C++ sources to produce and enforce out-of-line documentation
C++
303
star
20

node-smb-server

A 100% JavaScript implementation of the SMB file sharing protocol.
JavaScript
276
star
21

htl-spec

HTML Template Language Specification
275
star
22

aem-guides-wknd

Tutorial Code companion for Getting Started Developing with AEM Sites WKND Tutorial
JavaScript
261
star
23

lit-mobx

Mixin and base class for using mobx with lit-element
TypeScript
258
star
24

xdm

Experience Data Model
JavaScript
230
star
25

lagrange

A Robust Geometry Processing Library
C++
215
star
26

webkit

Experiments and contributions to WebKit. Tracks git://git.webkit.org/WebKit.git
213
star
27

chromium

Experiments and contributions to Chromium project
C++
207
star
28

avmplus

Source code for the Actionscript virtual machine
ActionScript
194
star
29

ops-cli

Ops - cli wrapper for Terraform, Ansible, Helmfile and SSH for cloud automation
Python
186
star
30

pdf-embed-api-samples

Samples for Adobe Document Services PDF Embed API
JavaScript
155
star
31

Deep-Audio-Prior

Audio Source Separation Without Any Training Data.
Python
154
star
32

rules_gitops

This repository contains rules for continuous, GitOps driven Kubernetes deployments.
Starlark
151
star
33

aem-htl-repl

Read–Eval–Print Loop environment for HTL.
JavaScript
151
star
34

OSAS

One Stop Anomaly Shop: Anomaly detection using two-phase approach: (a) pre-labeling using statistics, Natural Language Processing and static rules; (b) anomaly scoring using supervised and unsupervised machine learning.
Python
150
star
35

stringlifier

Stringlifier is on Opensource ML Library for detecting random strings in raw text. It can be used in sanitising logs, detecting accidentally exposed credentials and as a pre-processing step in unsupervised ML-based analysis of application text data.
Python
148
star
36

svg-native-viewer

SVG Native viewer is a library that parses and renders SVG Native documents
C++
142
star
37

Spry

Spry is a JavaScript-based framework that enables the rapid development of Ajax-powered web pages.
HTML
140
star
38

XMP-Toolkit-SDK

The XMP Toolkit allows you to integrate XMP functionality into your product or solution
C++
135
star
39

brackets-phonegap

A brackets extension for PhoneGap development.
JavaScript
112
star
40

brackets.io

brackets.io website
HTML
111
star
41

tf-manage

Shell
110
star
42

aem-component-generator

AEM Component Generator is a java project that enables developers to generate the base structure of an AEM component using a JSON configuration file specifying component and dialog properties and other configuration options.
Java
109
star
43

adobe-client-data-layer

An event-driven store for all trackable data of your site.
JavaScript
107
star
44

GLS3D

An implementation of OpenGL for Stage3D that can run inside Flash Player 11+
C
105
star
45

coral-spectrum

A JavaScript library of Web Components following Spectrum design patterns.
JavaScript
104
star
46

aem-core-cif-components

A set of configurations and components to get you started with AEM Commerce development
Java
102
star
47

himl

A hierarchical yaml config in Python
Python
101
star
48

react-webcomponent

This projects automates the wrapping of a React component in a CustomElement.
JavaScript
95
star
49

aem-boilerplate

Use this repository template for new AEM projects.
JavaScript
92
star
50

web-platform

JavaScript
90
star
51

ride

REST API Automation framework for functional, integration, fuzzing, and performance testing
Java
88
star
52

alloy

Alloy is the web SDK for the Adobe Experience Platform.
JavaScript
85
star
53

go-starter

Bootstrap a new project from a template.
Go
83
star
54

asset-share-commons

A modern, open-source asset share reference implementation built on Adobe Experience Manager (AEM)
Java
83
star
55

orc

ORC is a tool for finding violations of C++'s One Definition Rule on the OSX toolchain.
C++
79
star
56

pdfservices-node-sdk-samples

Samples for the Adobe Document Services PDF Tools Node SDK
HTML
77
star
57

sbmc

Sample-based Monte Carlo Denoising using a Kernel-Splatting Network [Siggraph 2019]
Python
76
star
58

git-server

A GitHub Protocol & API emulation
JavaScript
75
star
59

experience-platform-postman-samples

71
star
60

spectrum-tokens

Tokens used by Spectrum, Adobe's design system.
JavaScript
70
star
61

aem-sample-we-retail-journal

We.Retail Journal is a sample showcasing SPA Editing capabilities in AEM using React and Angular
CSS
69
star
62

aem-guides-wknd-spa

69
star
63

aio-theme

The Adobe I/O theme for building markdown powered sites
JavaScript
67
star
64

frontend-regression-validator

Visual regression tool used to compare baseline and updated instances of a website in a deployment pipeline.
Python
67
star
65

blackhole

An HTTP sink (for testing) with optional recording and playback ability
Go
65
star
66

aem-spa-project-archetype

Maven Archetype for creating new AEM SPA projects
CSS
63
star
67

aio-cli

Adobe I/O Extensible CLI
JavaScript
60
star
68

aem-upload

Makes uploading to AEM easier, and can be used as a command line executable or required as a Node.js module.
JavaScript
59
star
69

aem-modernize-tools

A suite of tools to modernize your AEM Sites implementations off legacy features.
Java
58
star
70

dds2atf

Tool for converting DDS files into ATF files suitable for use with the Flash Stage3D API
C++
58
star
71

redux-saga-promise

Create actions that return promises, which are resolved/rejected by a redux saga
JavaScript
58
star
72

aem-react-editable-components

SPA React Editable Components for Adobe Experience Manager
TypeScript
55
star
73

xmp-docs

XMP documentation
52
star
74

brackets-edge-web-fonts

Edge Web Fonts extension for Brackets. Simply unzip and drop into your Brackets extension folder to browse and include Edge Web Fonts.
JavaScript
50
star
75

aem-enablement

Content required for AEM Enablement
Java
50
star
76

aem-brackets-extension

Brackets extension for Adobe Experience Manager (AEM) front-end developers with auto-sync and HTL support.
JavaScript
50
star
77

helix-home

The home of Project Helix
HTML
49
star
78

aem-testing-clients

Testing tools for Adobe Experience Manager
Java
49
star
79

brackets-registry

A registry system for hosting Brackets extensions powered by node.js
JavaScript
46
star
80

aem-guides-wknd-graphql

JavaScript
46
star
81

helix-cli

Command-line tools for developing with AEM
JavaScript
45
star
82

htlengine

An HTL (Sightly) Interpreter/Compiler for Node.js
HTML
45
star
83

aem-dispatcher-experiments

Experiments to demonstrate the impact of the Dispatcher and it's configuration parameters.
HTML
44
star
84

pdfservices-python-sdk-samples

Adobe PDFServices python SDK Samples
Python
44
star
85

node-fetch-retry

Node Module for performing retries using node-fetch
JavaScript
42
star
86

commerce-cif-connector

AEM Commerce connector for Magento and GraphQL
Java
42
star
87

aem-react-core-wcm-components

41
star
88

behavior_tree_editor

A visual editor for building behavior trees for the bots
JavaScript
41
star
89

libLOL

Python
40
star
90

starter-repo

Documentation templates for use in open source and open development projects
40
star
91

commerce-cif-magento

Adobe Commerce Integration Framework (CIF) Magento Integration
JavaScript
40
star
92

bin2c

Convert to/Embed binary files in C source files, quickly and efficiently.
C
38
star
93

graphicalweb-keynote

Keynote for Graphical Web Conference
JavaScript
37
star
94

adobe-photoshop-api-sdk

Adobe Photoshop API SDK
JavaScript
37
star
95

aem-site-template-standard

Basic site template for AEM that allows non-Java experts to create new sites by customizing CSS and JS only.
SCSS
37
star
96

aio-cli-plugin-cloudmanager

Cloud Manager plugin for the Adobe I/O CLI
JavaScript
37
star
97

oss-contributors

How do tech companies rank amongst themselves when it comes to github.com activity?
JavaScript
35
star
98

aem-eclipse-developer-tools

The Eclipse plugin that brings you the full connection to the Adobe Experience Manager, with auto-sync and project creation wizard.
Java
35
star
99

fetch

Simplified HTTP/1(.1) and HTTP/2 requests with Server Push Support
JavaScript
34
star
100

PDFServices.NET.SDK.Samples

This .NET sample solution helps you get started with the Adobe PDF Services SDK.
HTML
33
star