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
10 changes: 10 additions & 0 deletions app/javascript/packages/normalize-yaml/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
## Unreleased

### Breaking Changes

- The new punctuation formatter described in "New Features" is enabled by default, which may identify new existing issues in your YAML files.

### New Features

- Added new punctuation formatter to collapse multiple spaces to a single space.

## v2.0.0

### Breaking Changes
Expand Down
2 changes: 2 additions & 0 deletions app/javascript/packages/normalize-yaml/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ Normalizes YAML files to ensure consistency and typographical quality:
- Applies improved punctuation.
- Converts straight quotes `"` and `'` to smart quotes `“`, `”`, and `’`
- Converts three dots `...` to ellipsis `…`
- Collapse multiple spaces to a single space.
- Stylizes content using [Prettier](https://prettier.io/), respecting local project Prettier configuration.

## Installation
Expand All @@ -32,6 +33,7 @@ The included `normalize-yaml` binary receives files as an argument, with optiona

- `--disable-sort-keys`: Disable the default behavior to sort keys.
- `--disable-smart-punctuation`: Disable the default behavior to apply smart punctuation.
- `--disable-collapse-spacing`: Disable the default behavior to collapse multiple spaces to a single space.

**Example:**

Expand Down
1 change: 1 addition & 0 deletions app/javascript/packages/normalize-yaml/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ const options = {
[
flags.includes('--disable-sort-keys') && 'sortKeys',
flags.includes('--disable-smart-punctuation') && 'smartPunctuation',
flags.includes('--disable-collapse-spacing') && 'collapseSpacing',
].filter(Boolean)
),
};
Expand Down
6 changes: 3 additions & 3 deletions app/javascript/packages/normalize-yaml/index.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import YAML from 'yaml';
import prettier from 'prettier';
import { getVisitors } from './visitors/index.js';
import { getUnifiedVisitor } from './visitors/index.js';

/** @typedef {'smartPunctuation'|'sortKeys'} Formatter */
/** @typedef {'smartPunctuation'|'sortKeys'|'collapseSpacing'} Formatter */

/**
* @typedef NormalizeOptions
Expand All @@ -21,7 +21,7 @@ import { getVisitors } from './visitors/index.js';
*/
function normalize(content, { prettierConfig, exclude } = {}) {
const document = YAML.parseDocument(content);
YAML.visit(document, getVisitors({ exclude }));
YAML.visit(document, getUnifiedVisitor({ exclude }));
return prettier.format(document.toString(), { ...prettierConfig, parser: 'yaml' });
}

Expand Down
7 changes: 7 additions & 0 deletions app/javascript/packages/normalize-yaml/index.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,13 @@ describe('normalize', () => {
expect(await normalize(original)).to.equal(expected);
});

it('collapses multiple spaces', async () => {
const original = '---\nparagraph: Lorem ipsum. Dolor sit amet.';
const expected = '---\nparagraph: Lorem ipsum. Dolor sit amet.\n';

expect(await normalize(original)).to.equal(expected);
});

it('formats using prettier', async () => {
const original = "---\nfoo: 'bar' ";
const expected = '---\nfoo: "bar"\n';
Expand Down
1 change: 1 addition & 0 deletions app/javascript/packages/normalize-yaml/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
"cli.js",
"index.js",
"visitors/index.js",
"visitors/colllapse-spacing.js",
"visitors/smart-punctuation.js",
"visitors/sort-keys.js",
"types"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
export default /** @type {import('yaml').visitor} */ ({
Scalar(_key, node) {
if (typeof node.value === 'string') {
node.value = node.value.replace(/ {2,}/g, ' ');
}
},
});
20 changes: 17 additions & 3 deletions app/javascript/packages/normalize-yaml/visitors/index.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,32 @@
import smartPunctuation from './smart-punctuation.js';
import sortKeys from './sort-keys.js';
import collapseSpacing from './collapse-spacing.js';

/** @typedef {import('yaml').visitor} Visitor */
/** @typedef {import('../').Formatter} Formatter */

/** @type {Record<Formatter, Visitor>} */
const DEFAULT_VISITORS = { smartPunctuation, sortKeys };
const DEFAULT_VISITORS = { smartPunctuation, sortKeys, collapseSpacing };

/** @type {(...callbacks: Array<(...args: any[]) => any>) => (...args: any[]) => void} */
const over =
(...callbacks) =>
(...args) =>
callbacks.forEach((callback) => callback(...args));

/**
* @param {{ exclude?: Formatter[] }} exclude
*
* @return {Visitor}
*/
export const getVisitors = ({ exclude = [] }) =>
export const getUnifiedVisitor = ({ exclude = [] }) =>
Object.entries(DEFAULT_VISITORS)
.filter(([formatter]) => !exclude.includes(/** @type {Formatter} */ (formatter)))
.reduce((result, [, visitor]) => Object.assign(result, visitor), /* @type {Visitor} */ {});
.map(([_formatter, visitor]) => visitor)
.reduce((result, visitor) => {
Object.entries(visitor).forEach(([key, callback]) => {
result[key] = result[key] ? over(result[key], callback) : callback;
});

return result;
}, /** @type {Visitor} */ ({}));
2 changes: 1 addition & 1 deletion config/locales/account_reset/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ en:
to use the same email address and set up new authentication methods.
However, deleting will remove any agency applications you have linked
to your account and you will need to restore each connection.
- If you continue, you will first receive an email confirmation. As a
- If you continue, you will first receive an email confirmation. As a
security measure, you will receive another email with the link to
continue deleting your account 24 hours after the initial confirmation
email arrives.
Expand Down
2 changes: 1 addition & 1 deletion config/locales/errors/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ en:
one: Password must be at least one character long
other: Password must be at least %{count} characters long
capture_doc:
invalid_link: This link is expired or not valid. Please request another link to
invalid_link: This link is expired or not valid. Please request another link to
verify your identity on a mobile phone.
confirm_password_incorrect: Incorrect password.
doc_auth:
Expand Down
6 changes: 3 additions & 3 deletions config/locales/telephony/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,13 @@ en:
invalid_phone_number: The phone number entered is not valid.
opt_out: The phone number entered has opted out of text messages.
permanent_failure: The phone number entered is not valid.
rate_limited: That number is experiencing high message volume. Please try again
rate_limited: That number is experiencing high message volume. Please try again
later.
sms_unsupported: The phone number entered doesn’t support text messaging. Try
the Phone call option.
temporary_failure: We are experiencing technical difficulties. Please try again later.
temporary_failure: We are experiencing technical difficulties. Please try again later.
timeout: The server took too long to respond. Please try again.
unknown_failure: We are experiencing technical difficulties. Please try again later.
unknown_failure: We are experiencing technical difficulties. Please try again later.
voice_unsupported: Invalid phone number. Check that you’ve entered the correct
country code or area code.
format_type:
Expand Down
2 changes: 1 addition & 1 deletion config/locales/titles/fr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ fr:
mfa_setup:
face_touch_unlock_confirmation: Déverrouillage facial ou tactile ajouté
suggest_second_mfa: Vous avez ajouté votre première méthode d’authentification !
Ajoutez-en une deuxième en guise de sauvegarde.
Ajoutez-en une deuxième en guise de sauvegarde.
no_auth_option: Aucun message de connexion trouvé
openid_connect:
authorization: Autorisation OpenID Connect
Expand Down
2 changes: 1 addition & 1 deletion config/locales/two_factor_authentication/es.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ es:
link: eliminando su cuenta
pending: Actualmente tiene una solicitud pendiente para eliminar su cuenta. Se
necesitan 24 horas desde el momento en que realizó la solicitud para
completar el proceso. Por favor, vuelva más tarde.
completar el proceso. Por favor, vuelva más tarde.
successful_cancel: Gracias. Su solicitud para eliminar su cuenta de %{app_name}
ha sido cancelada.
text_html: Si no puede usar ninguna de estas opciones de seguridad anteriores,
Expand Down
4 changes: 2 additions & 2 deletions config/locales/two_factor_authentication/fr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ fr:
cancel_link: Annuler votre demande
link: supprimer votre compte
pending: Vous avez actuellement une demande en attente pour supprimer votre
compte. Il faut compter 24 heures à partir du moment où vous avez fait
la demande pour terminer le processus. Veuillez vérifier plus tard.
compte. Il faut compter 24 heures à partir du moment où vous avez fait
la demande pour terminer le processus. Veuillez vérifier plus tard.
successful_cancel: Je vous remercie. Votre demande de suppression de votre
compte %{app_name} a été annulée.
text_html: Si vous ne pouvez pas utiliser l’une de ces options de sécurité
Expand Down
4 changes: 2 additions & 2 deletions config/locales/user_mailer/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,7 @@ en:
your letter will no longer work and you’ll have to verify your identity
again.
gpo_letter_header: Your letter is on the way
header: To finish resetting your password, please click the link below or copy
header: To finish resetting your password, please click the link below or copy
and paste the entire link into your browser.
link_text: Reset your password
subject: Reset your password
Expand All @@ -292,7 +292,7 @@ en:
visit the %{app_name_html} %{help_link_html} or %{contact_link_html}.
intro_html: This email address is already associated with a %{app_name_html}
account, so we can’t use it to create a new account. To sign in with
your existing account, follow the link below. If you are not trying to
your existing account, follow the link below. If you are not trying to
sign in with this email address, you can ignore this message.
link_text: Go to %{app_name}
reset_password_html: If you can’t remember your password, go to %{app_name_html} to reset it.
Expand Down
2 changes: 1 addition & 1 deletion config/locales/user_mailer/es.yml
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,7 @@ es:
phone_added:
disavowal_link: restablezca su contraseña
help_html: Si no realizó este cambio, inicie sesión en su perfil y administre
sus números de teléfono. También le recomendamos que
sus números de teléfono. También le recomendamos que
%{disavowal_link_html}.
intro: Se agregó un nuevo número de teléfono a su perfil de %{app_name}.
subject: Nuevo número de teléfono añadido
Expand Down
2 changes: 1 addition & 1 deletion config/locales/zxcvbn/fr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ fr:
repeats_like_aaa_are_easy_to_guess: Les répétitions comme « aaa » sont faciles à deviner
repeats_like_abcabcabc_are_only_slightly_harder_to_guess_than_abc: |-
Les répétitions comme « abcabcabc » sont à peine
plus difficiles à deviner que « abc »
plus difficiles à deviner que « abc »
reversed_words_arent_much_harder_to_guess: Les mots inversés ne sont pas très difficiles à deviner
sequences_like_abc_or_6543_are_easy_to_guess: Les séquences comme abc ou 6543 sont faciles à deviner
short_keyboard_patterns_are_easy_to_guess: Les motifs de clavier courts sont faciles à deviner
Expand Down