Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions app/javascript/packages/normalize-yaml/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
*.d.ts
65 changes: 65 additions & 0 deletions app/javascript/packages/normalize-yaml/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
# @18f/identity-normalize-yaml

Normalizes YAML files to ensure consistency and typographical quality:

- Alphabetizes keys.
- Applies improved punctuation.
- Converts straight quotes `"` and `'` to smart quotes `“`, `”`, and `’`
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Of course I'm realizing after publishing that this should have included the left form of the single smart quote 🤦

Suggested change
- Converts straight quotes `"` and `'` to smart quotes ``, ``, and ``
- Converts straight quotes `"` and `'` to smart quotes ``, ``, ``, and ``

- Converts three dots `...` to ellipsis `…`
- Stylizes content using [Prettier](https://prettier.io/), respecting local project Prettier configuration.

## Installation

Install using npm or Yarn. To reduce conflicts with a project's own Prettier dependency version, you must install Prettier as a separate dependency if not already installed.

Using npm:

```
npm install @18f/identity-normalize-yaml prettier
```

Using Yarn:

```
yarn add @18f/identity-normalize-yaml prettier
```

## Usage

### CLI

The included `normalize-yaml` binary receives files as an argument, with optional flags:

- `--disable-sort-keys`: Disable the default behavior to sort keys.
- `--disable-smart-punctuation`: Disable the default behavior to apply smart punctuation.

**Example:**

Using npm:

```
npm exec normalize-yaml path/to/file.yml -- --disable-sort-keys
```

Using Yarn:

```
yarn normalize-yaml path/to/file.yml --disable-sort-keys
```

### API

#### `normalize(content: string, config?: Options): string`

Given an input YAML string and optional options, returns a normalized YAML string.

**Options:**

- `prettierConfig` (`Record<string, any>`): Optional Prettier configuration object.
- `exclude` (`Formatter[]`) Formatters to exclude.

## License

This project is in the public domain within the United States, and copyright and related rights in the work worldwide are waived through the [CC0 1.0 Universal public domain dedication](https://creativecommons.org/publicdomain/zero/1.0/).

All contributions to this project will be released under the CC0 dedication. By submitting a pull request or issue, you are agreeing to comply with this waiver of copyright interest.
2 changes: 2 additions & 0 deletions app/javascript/packages/normalize-yaml/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ import { getVisitors } from './visitors/index.js';
*/

/**
* Given an input YAML string and optional options, returns a normalized YAML string.
*
* @param {string} content Original content.
* @param {NormalizeOptions} options Normalize options.
*
Expand Down
34 changes: 31 additions & 3 deletions app/javascript/packages/normalize-yaml/package.json
Original file line number Diff line number Diff line change
@@ -1,14 +1,42 @@
{
"name": "@18f/identity-normalize-yaml",
"private": true,
"private": false,
"description": "Normalizes YAML files to ensure consistency and typographical quality",
"version": "1.0.0",
"type": "module",
"main": "./index.js",
"types": "./types/index.d.ts",
"bin": {
"normalize-yaml": "./cli.js"
},
"scripts": {
"prebuild:types": "rm -rf types",
"build:types": "tsc",
"prepublishOnly": "npm run build:types"
},
"files": [
"cli.js",
"index.js",
"visitors/index.js",
"visitors/smart-punctuation.js",
"visitors/sort-keys.js",
"types"
],
"license": "CC0-1.0",
"bugs": {
"url": "https://github.com/18f/identity-idp/issues"
},
"homepage": "https://github.com/18f/identity-idp",
"repository": {
"type": "git",
"url": "https://github.com/18f/identity-idp.git",
"directory": "app/javascript/packages/normalize-yaml"
},
"dependencies": {
"prettier": "^2.6.0",
"smartquotes": "^2.3.2",
"yaml": "^2.2.2"
"yaml": "^2.3.1"
},
"peerDependencies": {
"prettier": "*"
}
}
11 changes: 11 additions & 0 deletions app/javascript/packages/normalize-yaml/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"extends": "../../../../tsconfig.json",
"compilerOptions": {
"outDir": "types",
"noEmit": false,
"declaration": true,
"emitDeclarationOnly": true
},
"include": ["./**/*.js"],
"exclude": ["types", "**/*.spec.js"]
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"main": "rails-i18n-webpack-plugin.js",
"dependencies": {
"webpack-sources": "^2.3.0",
"yaml": "^2.2.2"
"yaml": "^2.3.1"
},
"peerDependencies": {
"sinon": "*",
Expand Down
1 change: 0 additions & 1 deletion scripts/validate-workspaces.js
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,6 @@ const EXCEPTIONS = {
'app/javascript/packages/form-steps/package.json',
'app/javascript/packages/masked-text-toggle/package.json',
'app/javascript/packages/memorable-date/package.json',
'app/javascript/packages/normalize-yaml/package.json',
'app/javascript/packages/password-toggle/package.json',
'app/javascript/packages/phone-input/package.json',
'app/javascript/packages/spinner-button/package.json',
Expand Down
10 changes: 5 additions & 5 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -5407,7 +5407,7 @@ prettier-linter-helpers@^1.0.0:
dependencies:
fast-diff "^1.1.2"

prettier@^2.6.0, prettier@^2.7.1:
prettier@^2.7.1:
version "2.7.1"
resolved "https://registry.yarnpkg.com/prettier/-/prettier-2.7.1.tgz#e235806850d057f97bb08368a4f7d899f7760c64"
integrity sha512-ujppO+MkdPqoVINuDFDRLClm7D78qbDt0/NR+wp5FqEZOoTNAjPHWj17QRhu7geIHJfcNhRk1XVQmF8Bp3ye+g==
Expand Down Expand Up @@ -7103,10 +7103,10 @@ yallist@^4.0.0:
resolved "https://registry.yarnpkg.com/yallist/-/yallist-4.0.0.tgz#9bb92790d9c0effec63be73519e11a35019a3a72"
integrity sha512-3wdGidZyq5PB084XLES5TpOSRA3wjXAlIWMhum2kRcv/41Sn2emQ0dycQW4uZXLejwKvg6EsvbdlVL+FYEct7A==

yaml@^2.2.2:
version "2.2.2"
resolved "https://registry.yarnpkg.com/yaml/-/yaml-2.2.2.tgz#ec551ef37326e6d42872dad1970300f8eb83a073"
integrity sha512-CBKFWExMn46Foo4cldiChEzn7S7SRV+wqiluAb6xmueD/fGyRHIhX8m14vVGgeFWjN540nKCNVj6P21eQjgTuA==
yaml@^2.3.1:
version "2.3.1"
resolved "https://registry.yarnpkg.com/yaml/-/yaml-2.3.1.tgz#02fe0975d23cd441242aa7204e09fc28ac2ac33b"
integrity sha512-2eHWfjaoXgTBC2jNM1LRef62VQa0umtvRiDSk6HSzW7RvS5YtkabJrwYLLEKWBc8a5U2PTSCs+dJjUTJdlHsWQ==

yargs-parser@20.2.4:
version "20.2.4"
Expand Down