Skip to content

Commit

Permalink
docs: add Vue support docs for eslint-plugin-formatjs
Browse files Browse the repository at this point in the history
  • Loading branch information
longlho committed Jan 2, 2021
1 parent 1ab7a95 commit 088eb4d
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 1 deletion.
20 changes: 19 additions & 1 deletion website/docs/tooling/linter.md
Expand Up @@ -3,7 +3,7 @@ id: linter
title: eslint-plugin-formatjs
---

This eslint plugin allows you to enforce certain rules in your ICU message. This is currently under development
This eslint plugin allows you to enforce certain rules in your ICU message.

## Usage

Expand Down Expand Up @@ -44,6 +44,8 @@ Then in your eslint config:
}
```

### React

Currently this uses `intl.formatMessage`, `defineMessage`, `defineMessages`, `<FormattedMessage>` from `react-intl` as hooks to verify the message. Therefore, in your code use 1 of the following mechanisms:

```tsx
Expand Down Expand Up @@ -74,6 +76,22 @@ function foo() {
}
```

### Vue

This will check against `intl.formatMessage`, `$formatMessage` function calls in both your JS/TS & your SFC `.vue` files. For example:

```vue
<template>
<p>
{{
$formatMessage({
defaultMessage: 'today is {now, date}',
})
}}
</p>
</template>
```

## Available Rules

### `blacklist-elements`
Expand Down
30 changes: 30 additions & 0 deletions website/docs/vue-intl.md
Expand Up @@ -116,3 +116,33 @@ We currently support:
- `$formatTimeRange`
- `$formatDisplayName`
- `$formatList`

## Caveats

### Using ICU in Vue SFC

Since `}}` & `{{` are special tokens in `.vue` `<template>`, this can cause potential conflict with ICU MessageFormat syntax, e.g:

```html {4}
<template>
<p>
{{ $formatMessage({ defaultMessage: '{count, selectordinal, offset:1 one {#}
other {# more}}', }) }}
</p>
</template>
```

Notice the `{# more}}` where it ends with `}}`. This will cause parsing issue in your `vue` template. In order to work around this issue, we recommend using space to turn `}}` into `} }`.

```vue {6}
<template>
<p>
{{
$formatMessage({
defaultMessage:
'{count, selectordinal, offset:1 one {#} other {# more} }',
})
}}
</p>
</template>
```

0 comments on commit 088eb4d

Please sign in to comment.