-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit abf24c9
Showing
15 changed files
with
8,468 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
// `@rushstack/eslint-patch` patches eslint so that shared configs can include | ||
// plugins as dependencies. Without this patch, plugins have to be included as | ||
// peer dependencies in studios. | ||
// | ||
// create-react-app https://github.com/facebook/create-react-app/blob/9673858a3715287c40aef9e800c431c7d45c05a2/packages/eslint-config-react-app/base.js#L11 | ||
// and next.js: https://github.com/vercel/next.js/blob/0de84472eb565d5ecae1e6b71994f0cd46c8ecb9/packages/eslint-config-next/index.js#L7 | ||
// both use this | ||
require('@rushstack/eslint-patch/modern-module-resolution'); | ||
|
||
module.exports = { | ||
plugins: ['i18next', '@sanity/i18n'], | ||
|
||
parser: '@typescript-eslint/parser', | ||
parserOptions: { | ||
ecmaVersion: 'latest', | ||
ecmaFeatures: { jsx: true }, | ||
}, | ||
|
||
rules: { | ||
'i18next/no-literal-string': 'error', | ||
'@sanity/i18n/no-attribute-string-literals': 'error', | ||
'@sanity/i18n/no-attribute-template-literals': 'error', | ||
}, | ||
|
||
overrides: [ | ||
{ | ||
files: [`**/*/test/**/*`, '**/*/__tests__/**/*', '**/*.test.{js,ts,tsx}'], | ||
rules: { | ||
'i18next/no-literal-string': 'off', | ||
'@sanity/i18n/no-attribute-string-literals': 'off', | ||
'@sanity/i18n/no-attribute-template-literals': 'off', | ||
}, | ||
}, | ||
], | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
## Description | ||
|
||
<!-- | ||
Please describe your issue or feature request. Share your intent and use case | ||
so we can evaluate what options are best. | ||
If you're describing a bug, please include the version of ESLint and Typescript | ||
(if in use) and include instructions on how to reproduce the bug if applicable. | ||
--> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
## Description | ||
|
||
<!-- | ||
Please describe what this PR is, why you are opening it, and what to test out if | ||
applicable. | ||
Please squash-merge utilizing conventional commits. | ||
e.g. `feat: add new rule` `fix: replace deprecated rule` | ||
Once your PR is merged, it will be automatically released to NPM via our CI. | ||
This repo uses semantic-release to version releases and the commit messages bump | ||
the version. | ||
--> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
{ | ||
"$schema": "https://docs.renovatebot.com/renovate-schema.json", | ||
"extends": ["github>sanity-io/renovate-config"] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
name: Release | ||
on: | ||
push: | ||
branches: | ||
- main | ||
- alpha | ||
jobs: | ||
release: | ||
name: Release | ||
runs-on: ubuntu-latest | ||
permissions: | ||
contents: write # to be able to publish a GitHub release | ||
issues: write # to be able to comment on released issues | ||
pull-requests: write # to be able to comment on released pull requests | ||
id-token: write # to enable use of OIDC for npm provenance | ||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@v3 | ||
with: | ||
fetch-depth: 0 | ||
|
||
- name: Setup Node.js | ||
uses: actions/setup-node@v3 | ||
with: | ||
node-version: lts/* | ||
|
||
- name: Install dependencies | ||
run: npm ci | ||
|
||
- name: Run tests | ||
run: npm t | ||
|
||
- name: Release | ||
env: | ||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
NPM_TOKEN: ${{ secrets.NPM_TOKEN }} | ||
run: npx semantic-release |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
name: Test | ||
on: | ||
- pull_request | ||
|
||
jobs: | ||
release: | ||
name: Test | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@v3 | ||
with: | ||
fetch-depth: 0 | ||
|
||
- name: Setup Node.js | ||
uses: actions/setup-node@v3 | ||
with: | ||
node-version: lts/* | ||
|
||
- name: Install dependencies | ||
run: npm ci | ||
|
||
- name: Run tests | ||
run: npm t |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
mock-files | ||
node_modules |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
{ | ||
"extends": "@sanity/semantic-release-preset", | ||
"branches": ["main", { "name": "alpha", "prerelease": true }] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
MIT License | ||
|
||
Copyright (c) 2023 Sanity.io | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
# @sanity/eslint-config-i18n | ||
|
||
An ESLint configuration to help with localizing Sanity Studios. | ||
|
||
This package utilizes [@rushstack/eslint-patch](https://github.com/microsoft/rushstack/tree/ebee58403b1595027da7ef00a4d817d83ecbd737/eslint/eslint-patch#what-it-does) to include plugins as dependencies. This making installation easier and allows us to manage those dependencies for you. | ||
|
||
Depends on: | ||
|
||
- [`@sanity/eslint-plugin-i18n`](https://github.com/sanity-io/eslint-plugin-i18n) | ||
- Rule [`no-attribute-string-literals`](https://github.com/sanity-io/eslint-plugin-i18n#no-attribute-string-literals) | ||
- Rule [`no-attribute-template-literals`](https://github.com/sanity-io/eslint-plugin-i18n#no-attribute-template-literals) | ||
- [`eslint-plugin-i18next`](https://github.com/edvardchen/eslint-plugin-i18next) | ||
- Rule [`no-literal-string`](https://github.com/edvardchen/eslint-plugin-i18next#rule-no-literal-string) | ||
|
||
## Installation | ||
|
||
### Install | ||
|
||
``` | ||
yarn add eslint @sanity/eslint-config-i18n --dev | ||
``` | ||
|
||
or | ||
|
||
``` | ||
npm install eslint @sanity/eslint-config-i18n --save-dev | ||
``` | ||
|
||
### Update the configuration | ||
|
||
Update your `.eslintrc` to include `"@sanity/eslint-config-i18n"` | ||
|
||
``` | ||
{ | ||
"extends": [ | ||
"@sanity/eslint-config-studio", | ||
"@sanity/eslint-config-i18n" | ||
] | ||
} | ||
``` | ||
|
||
Optionally: If you wish to configure `@sanity/eslint-plugin-i18n`: | ||
|
||
```json | ||
{ | ||
"extends": ["@sanity/eslint-config-studio", "@sanity/eslint-config-i18n"], | ||
"rules": { | ||
"@sanity/i18n/no-attribute-string-literals": [ | ||
"error", | ||
// See https://github.com/sanity-io/eslint-plugin-i18n#rule-options | ||
{ | ||
"ignores": {}, | ||
"only": {}, | ||
"mode": "extends" | ||
} | ||
], | ||
"@sanity/i18n/no-attribute-string-literals": [ | ||
"error", | ||
// See https://github.com/sanity-io/eslint-plugin-i18n#rule-options | ||
{ | ||
"ignores": {}, | ||
"only": {}, | ||
"mode": "extends" | ||
} | ||
] | ||
}, | ||
"overrides": [ | ||
// turn off these rules for your tests | ||
{ | ||
"files": [ | ||
"**/*/test/**/*", | ||
"**/*/__tests__/**/*", | ||
"**/*.test.{js,ts,tsx}" | ||
], | ||
"rules": { | ||
"i18next/no-literal-string": "off", | ||
"@sanity/i18n/no-attribute-string-literals": "off", | ||
"@sanity/i18n/no-attribute-template-literals": "off" | ||
} | ||
} | ||
] | ||
} | ||
``` | ||
|
||
## Release new version | ||
|
||
Run ["CI & Release" workflow](https://github.com/sanity-io/eslint-config-i18n/actions). | ||
Make sure to select the main branch and check "Release new version". | ||
|
||
Semantic release will only release on configured branches, so it is safe to run release on any branch. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
function Component() { | ||
return ( | ||
<> | ||
string literal{' '} | ||
<Button stringAttr="hello" templateAttr={`hello ${name}`} /> | ||
</> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
module.exports = require("./.eslintrc.js"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import { exec } from 'child_process'; | ||
import assert from 'assert'; | ||
|
||
const stdout = await new Promise((resolve, reject) => { | ||
exec('npx eslint ./example.js --format json', (_, stdout, stderr) => { | ||
if (stderr) { | ||
reject(new Error(`Had stderr output:\n${stderr}`)); | ||
} else { | ||
resolve(stdout); | ||
} | ||
}); | ||
}); | ||
|
||
const output = JSON.parse(stdout); | ||
const { messages } = output[0]; | ||
const [first, second, third] = messages; | ||
|
||
assert(output.length === 1); | ||
assert(messages.length === 3); | ||
assert(first.ruleId === 'i18next/no-literal-string'); | ||
assert(second.ruleId === '@sanity/i18n/no-attribute-string-literals'); | ||
assert(third.ruleId === '@sanity/i18n/no-attribute-template-literals'); |
Oops, something went wrong.