Skip to content

Commit

Permalink
feat: first commit
Browse files Browse the repository at this point in the history
  • Loading branch information
ricokahler committed Dec 5, 2023
0 parents commit abf24c9
Show file tree
Hide file tree
Showing 15 changed files with 8,468 additions and 0 deletions.
35 changes: 35 additions & 0 deletions .eslintrc.js
@@ -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',
},
},
],
};
11 changes: 11 additions & 0 deletions .github/issue_template.md
@@ -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.
-->
16 changes: 16 additions & 0 deletions .github/pull_request_template.md
@@ -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.
-->
4 changes: 4 additions & 0 deletions .github/renovate.json
@@ -0,0 +1,4 @@
{
"$schema": "https://docs.renovatebot.com/renovate-schema.json",
"extends": ["github>sanity-io/renovate-config"]
}
37 changes: 37 additions & 0 deletions .github/workflows/release.yml
@@ -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
24 changes: 24 additions & 0 deletions .github/workflows/test.yml
@@ -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
2 changes: 2 additions & 0 deletions .gitignore
@@ -0,0 +1,2 @@
mock-files
node_modules
4 changes: 4 additions & 0 deletions .releaserc.json
@@ -0,0 +1,4 @@
{
"extends": "@sanity/semantic-release-preset",
"branches": ["main", { "name": "alpha", "prerelease": true }]
}
21 changes: 21 additions & 0 deletions LICENSE
@@ -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.
90 changes: 90 additions & 0 deletions README.md
@@ -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.
8 changes: 8 additions & 0 deletions example.js
@@ -0,0 +1,8 @@
function Component() {
return (
<>
string literal{' '}
<Button stringAttr="hello" templateAttr={`hello ${name}`} />
</>
);
}
1 change: 1 addition & 0 deletions index.js
@@ -0,0 +1 @@
module.exports = require("./.eslintrc.js");
22 changes: 22 additions & 0 deletions index.test.mjs
@@ -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');

0 comments on commit abf24c9

Please sign in to comment.