All Projects → schuchard → Prettier Schematic

schuchard / Prettier Schematic

Licence: mit
Add Prettier to an Angular project

Projects that are alternatives of or similar to Prettier Schematic

Homepage
my personal website
Stars: ✭ 80 (-37.98%)
Mutual labels:  prettier
Simple React Calendar
A simple react based calendar component to be used for selecting dates and date ranges
Stars: ✭ 97 (-24.81%)
Mutual labels:  prettier
Vm80a
i8080 precise replica in Verilog, based on reverse engineering of real die
Stars: ✭ 114 (-11.63%)
Mutual labels:  schematics
Parallel Prettier
Concurrent prettier runner
Stars: ✭ 84 (-34.88%)
Mutual labels:  prettier
Prettier Package Json
Prettier formatter for package.json files
Stars: ✭ 86 (-33.33%)
Mutual labels:  prettier
Nx Electron
Electron schematics for nrwl nx platform
Stars: ✭ 105 (-18.6%)
Mutual labels:  schematics
Mostly
They mostly come at night; mostly.
Stars: ✭ 78 (-39.53%)
Mutual labels:  prettier
Javascriptprettier
A Visual Studio extension
Stars: ✭ 118 (-8.53%)
Mutual labels:  prettier
React Boilerplate
This project is deprecated. Please use CRA instead.
Stars: ✭ 88 (-31.78%)
Mutual labels:  prettier
Zoe
🌀 Zero-config ESLint toolchain with sensible defaults.
Stars: ✭ 113 (-12.4%)
Mutual labels:  prettier
Pcbdl
PCB Design Language: A programming way to design schematics.
Stars: ✭ 84 (-34.88%)
Mutual labels:  schematics
Vim Prettier
A Vim plugin for Prettier
Stars: ✭ 1,268 (+882.95%)
Mutual labels:  prettier
Prettier
Prettier is an opinionated code formatter.
Stars: ✭ 41,411 (+32001.55%)
Mutual labels:  prettier
Plugin Php
Prettier PHP Plugin
Stars: ✭ 1,243 (+863.57%)
Mutual labels:  prettier
Simple Boilerplate
A simple webpack boilerplate for your comfortable work with HTML, JS and CSS.
Stars: ✭ 116 (-10.08%)
Mutual labels:  prettier
Gatsby Starter Typescript Rebass Netlifycms
My default Gatsby setup. Includes rich MDX support.
Stars: ✭ 79 (-38.76%)
Mutual labels:  prettier
Conf
Landing page for event React Conf Brazil
Stars: ✭ 104 (-19.38%)
Mutual labels:  prettier
Pretty Quick
⚡ Get Pretty Quick
Stars: ✭ 1,766 (+1268.99%)
Mutual labels:  prettier
Reeakt
A modern React boilerplate to awesome web applications
Stars: ✭ 116 (-10.08%)
Mutual labels:  prettier
Lecture Frontend Dev Env
"[인프런] 프론트엔드 개발환경의 이해와 실습" 강의 실습 자료입니다.
Stars: ✭ 108 (-16.28%)
Mutual labels:  prettier

Angular Prettier schematic

A Schematic that adds prettier and a pre-commit hook for formatting staged files.

CircleCI npm Commitizen friendly

Usage 🚀

Run in an Angular CLI project

ng add @schuchard/prettier

or install globally

npm install -g @schuchard/prettier

then in an Angular CLI project:

ng g @schuchard/prettier:add

How does Prettier work with Angular

Automatically against staged files

By default lint-staged is configured along with a pre-commit hook. This will run Prettier against all new files as they are committed according to the settings defined in prettier.config.json. Generally speaking, your workflow should remain unchanged - git add, commit, push

lint-staged-example

Disabling lint-staged install

lint-stage and the precommit hook can be disabled with the following

ng g @schuchard/prettier:add --lintStaged=false

Manually

While lint-staged only runs prettier against staged files, you can manually run Prettier against ALL targeted files with the script added to the package.json

npm run prettier

Angular formatting

Beginning with 1.15, Prettier supports formatting HTML and Angular files.

Format all Angular Files - {js,json,css,md,ts,html,component.html}

format-angular-files

Format only Typescript files

Previous versions of this schematic only formatted Typescript files. That functionality is still available and is configured in the CLI prompts or via the --formatAllAngularFiles=false if desired. The default is true.

format-typescript-files

Defaults Prettier options

Angular 7

This schematic takes advantage of CLI prompts for configuring Prettier options. If you're unsure of a setting, press enter to select the default. You can skip a prompt by passing any of the options when call the schematic.

ng g @schuchard/prettier:add --printWidth=100

schematic-cli

< Angular 7

Without any CLI arguments the default Prettier options will be applied. The defaults can be changed in one of two ways:

  • modifying the ./prettier.config.js after the schematic runs
  • passing a flag to the schematic with the desired value for any of the options. For example:
    • ng g @schuchard/prettier:add --printWidth=100 --tabWidth=4

Example default prettier.config.js

printWidth = 80;
tabWidth = 2;
useTabs = false;
semi = true;
singleQuote = false;
trailingComma = "none";
bracketSpacing = true;
jsxBracketSameLine = false;
arrowParens = "avoid";
rangeStart = 0;
rangeEnd = Infinity;
requirePragma = false;
insertPragma = false;
proseWrap = "preserve";
lintStaged = true;

Contributing

Getting started

Install dependencies:

yarn && cd sandbox && yarn

Test changes to the schematic

yarn dev

Test changes to the schematic AND run E2E tests in the sandbox

yarn test

Reset the sandbox state after running the schematic locally

yarn clean

Documentation

Unsure how to do something with schematics? Check the Angular schematics for inspiration.

Inspiration came from this excellent article by Aaron Frost

Publishing

  • First, ensure you're authenticated with npm login.
npm run release

Issues & Requests 📬

Submit an issue

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].