{"_id":"@sanity/eslint-plugin-i18n","_rev":"102-4500c952e363733eb28954ecb97e68f0","name":"@sanity/eslint-plugin-i18n","dist-tags":{"latest":"1.1.0"},"versions":{"1.0.0":{"name":"@sanity/eslint-plugin-i18n","version":"1.0.0","keywords":["sanity","eslint","eslintplugin"],"author":{"name":"Sanity.io","email":"hello@sanity.io"},"license":"MIT","_id":"@sanity/eslint-plugin-i18n@1.0.0","maintainers":[{"name":"sergeisarviro","email":"sergei@sanity.io"},{"name":"ash","email":"ashley@juice49.com"},{"name":"indrek.karner","email":"indrek.karner@sanity.io"},{"name":"cngonzalez-sanity","email":"carolina@sanity.io"},{"name":"rdunk","email":"rupert@rupertdunk.com"},{"name":"rneatherway-sanity","email":"robin.neatherway@sanity.io"},{"name":"ricokahler","email":"ricokahler@me.com"},{"name":"pedro-sanity","email":"pedro@sanity.io"},{"name":"jonabc","email":"jon.ruskin@gmail.com"},{"name":"kenjonespizza","email":"ken@sanity.io"},{"name":"pauloborgesf","email":"paulo@sanity.io"},{"name":"binoy14","email":"me@binoy.io"},{"name":"simen.svale","email":"simen@sanity.io"},{"name":"svirs","email":"shur@sanity.io"},{"name":"josh_sanity_io","email":"josh@sanity.io"},{"name":"joneidejohnsen","email":"jon@sanity.io"},{"name":"nina.andal","email":"nina@sanity.io"},{"name":"rankers","email":"richardankers@gmail.com"},{"name":"snorreeb","email":"snorre.e.brekke@gmail.com"},{"name":"mattcraig","email":"matt@sanity.io"},{"name":"vincentquigley","email":"vincent@sanity.io"},{"name":"stipsan","email":"stipsan@gmail.com"},{"name":"michael-sanity","email":"michael@sanity.io"},{"name":"rubioz","email":"jarubc@gmail.com"},{"name":"tonina","email":"zhelyazkova.tonina@gmail.com"},{"name":"ritasdias","email":"anarita151@gmail.com"},{"name":"simeonsanity","email":"simeon@sanity.io"},{"name":"kmelve","email":"knut.melvaer@gmail.com"},{"name":"bjoerge","email":"bjoerge@gmail.com"},{"name":"rexxars","email":"espen@hovlandsdal.com"},{"name":"skogsmaskin","email":"per.kristian.nordnes@gmail.com"},{"name":"robinpyon","email":"robin@robinpyon.com"},{"name":"mariuslundgard","email":"studio@mariuslundgard.com"},{"name":"sanity-io","email":"developers@sanity.io"},{"name":"evenw","email":"even@sanity.io"},{"name":"radhe_sanity","email":"radhe@sanity.io"},{"name":"rbotten","email":"rbotten@gmail.com"},{"name":"judofyr","email":"judofyr@gmail.com"},{"name":"obliadp","email":"orjan@sanity.io"},{"name":"dcilke","email":"dain.cilke@gmail.com"},{"name":"fredcarlsen","email":"fred@superbig.co"},{"name":"hermanw","email":"herman@sanity.io"},{"name":"sgulseth","email":"sgulseth@gmail.com"},{"name":"atombender","email":"npm@purefiction.net"}],"homepage":"https://www.sanity.io/","bugs":{"url":"https://github.com/sanity-io/eslint-plugin-i18n/issues"},"dist":{"shasum":"b7838e83ebda73a6853c2d6c52525dd62e6f3380","tarball":"https://registry.npmjs.org/@sanity/eslint-plugin-i18n/-/eslint-plugin-i18n-1.0.0.tgz","fileCount":13,"integrity":"sha512-ibPaZttafAWLRz2SXAk8LOBr+nykU4BoMUYjdQVIx/N3D2deZdJp0s1c0lmljkrE2B3LmB0B7oTzF9CUrw3Kyg==","signatures":[{"sig":"MEQCIHHZjh9r9u5G944GQpEeYzSaeHHEE/y+sozv9e15zPP5AiA1dBS76QrzJ/4+AnK5kBh9yfKyKxzVHpAKy2o2h9/iSg==","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"attestations":{"url":"https://registry.npmjs.org/-/npm/v1/attestations/@sanity%2feslint-plugin-i18n@1.0.0","provenance":{"predicateType":"https://slsa.dev/provenance/v1"}},"unpackedSize":30551},"main":"./dist/index.js","types":"./index-shim.d.ts","exports":{".":{"types":"./index-shim.d.ts","default":"./dist/index.js"},"./defaults":{"types":"./dist/defaults.d.ts","default":"./dist/defaults.js"},"./package.json":"./package.json"},"gitHead":"5473d7ee14b8852ae14f0a4e49cc8cde9b464e31","scripts":{"test":"jest","build":"tsc && rollup -c","prepare":"npm run build"},"_npmUser":{"name":"ricokahler","email":"ricokahler@me.com"},"repository":{"url":"git+https://github.com/sanity-io/eslint-plugin-i18n.git","type":"git"},"_npmVersion":"10.2.4","description":"This ESLint plugin provides rules to enforce specific code standards in internationalization practices, particularly focusing on attribute strings and template literals in JSX.","directories":{},"_nodeVersion":"20.10.0","publishConfig":{"access":"public","provenance":true},"_hasShrinkwrap":false,"devDependencies":{"jest":"^29.7.0","eslint":"^8.54.0","rollup":"^4.6.1","typescript":"^5.3.2","@types/eslint":"^8.44.8","@babel/preset-env":"^7.23.5","@rollup/plugin-babel":"^6.0.4","@rollup/plugin-replace":"^5.0.5","@babel/preset-typescript":"^7.23.3","@typescript-eslint/parser":"^6.13.1","@rollup/plugin-node-resolve":"^15.2.3","@typescript-eslint/rule-tester":"^6.13.1","@sanity/semantic-release-preset":"^4.1.6","@typescript-eslint/typescript-estree":"^6.13.1"},"_npmOperationalInternal":{"tmp":"tmp/eslint-plugin-i18n_1.0.0_1701730284059_0.8777042720560848","host":"s3://npm-registry-packages"}},"1.1.0":{"name":"@sanity/eslint-plugin-i18n","version":"1.1.0","keywords":["sanity","eslint","eslintplugin"],"author":{"name":"Sanity.io","email":"hello@sanity.io"},"license":"MIT","_id":"@sanity/eslint-plugin-i18n@1.1.0","maintainers":[{"name":"sergeisarviro","email":"sergei@sanity.io"},{"name":"ash","email":"ashley@juice49.com"},{"name":"indrek.karner","email":"indrek.karner@sanity.io"},{"name":"cngonzalez-sanity","email":"carolina@sanity.io"},{"name":"rdunk","email":"rupert@rupertdunk.com"},{"name":"rneatherway-sanity","email":"robin.neatherway@sanity.io"},{"name":"ricokahler","email":"ricokahler@me.com"},{"name":"pedro-sanity","email":"pedro@sanity.io"},{"name":"jonabc","email":"jon.ruskin@gmail.com"},{"name":"kenjonespizza","email":"ken@sanity.io"},{"name":"pauloborgesf","email":"paulo@sanity.io"},{"name":"binoy14","email":"me@binoy.io"},{"name":"simen.svale","email":"simen@sanity.io"},{"name":"svirs","email":"shur@sanity.io"},{"name":"josh_sanity_io","email":"josh@sanity.io"},{"name":"joneidejohnsen","email":"jon@sanity.io"},{"name":"nina.andal","email":"nina@sanity.io"},{"name":"rankers","email":"richardankers@gmail.com"},{"name":"snorreeb","email":"snorre.e.brekke@gmail.com"},{"name":"mattcraig","email":"matt@sanity.io"},{"name":"vincentquigley","email":"vincent@sanity.io"},{"name":"stipsan","email":"stipsan@gmail.com"},{"name":"michael-sanity","email":"michael@sanity.io"},{"name":"rubioz","email":"jarubc@gmail.com"},{"name":"tonina","email":"zhelyazkova.tonina@gmail.com"},{"name":"ritasdias","email":"anarita151@gmail.com"},{"name":"simeonsanity","email":"simeon@sanity.io"},{"name":"kmelve","email":"knut.melvaer@gmail.com"},{"name":"bjoerge","email":"bjoerge@gmail.com"},{"name":"rexxars","email":"espen@hovlandsdal.com"},{"name":"skogsmaskin","email":"per.kristian.nordnes@gmail.com"},{"name":"robinpyon","email":"robin@robinpyon.com"},{"name":"mariuslundgard","email":"studio@mariuslundgard.com"},{"name":"sanity-io","email":"developers@sanity.io"},{"name":"evenw","email":"even@sanity.io"},{"name":"radhe_sanity","email":"radhe@sanity.io"},{"name":"rbotten","email":"rbotten@gmail.com"},{"name":"judofyr","email":"judofyr@gmail.com"},{"name":"obliadp","email":"orjan@sanity.io"},{"name":"dcilke","email":"dain.cilke@gmail.com"},{"name":"fredcarlsen","email":"fred@superbig.co"},{"name":"hermanw","email":"herman@sanity.io"},{"name":"sgulseth","email":"sgulseth@gmail.com"},{"name":"atombender","email":"npm@purefiction.net"}],"homepage":"https://www.sanity.io/","bugs":{"url":"https://github.com/sanity-io/eslint-plugin-i18n/issues"},"dist":{"shasum":"5fb1d97d030dd28545475cd0394b4dba71d87197","tarball":"https://registry.npmjs.org/@sanity/eslint-plugin-i18n/-/eslint-plugin-i18n-1.1.0.tgz","fileCount":15,"integrity":"sha512-EpoqPVqaP2NSmG8vGa4zsD6BuyBTVHwmD3VigOya7roHB8GZXuJjDg6+SXzhb+cTVuZtWaAjt8NMYVYx4uWCIQ==","signatures":[{"sig":"MEUCIQC0scRBOf/Co5cZA1D0ntgPCRLGxrTmzCctVHzjobF+eQIgDsTcyyWXc90jLlGtE8/mi1clAXZslTPJ3w1bdOnhWNs=","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"attestations":{"url":"https://registry.npmjs.org/-/npm/v1/attestations/@sanity%2feslint-plugin-i18n@1.1.0","provenance":{"predicateType":"https://slsa.dev/provenance/v1"}},"unpackedSize":34461},"main":"./dist/index.js","types":"./index-shim.d.ts","exports":{".":{"types":"./index-shim.d.ts","default":"./dist/index.js"},"./defaults":{"types":"./dist/defaults.d.ts","default":"./dist/defaults.js"},"./package.json":"./package.json"},"gitHead":"5ecea3317676c37cd30e0adda664f2e243d8e497","scripts":{"test":"jest","build":"tsc && rollup -c","prepare":"npm run build","prettify":"prettier -w ."},"_npmUser":{"name":"ricokahler","email":"ricokahler@me.com"},"repository":{"url":"git+https://github.com/sanity-io/eslint-plugin-i18n.git","type":"git"},"_npmVersion":"10.2.4","description":"This ESLint plugin provides rules to enforce specific code standards in internationalization practices, particularly focusing on attribute strings and template literals in JSX.","directories":{},"_nodeVersion":"20.10.0","publishConfig":{"access":"public","provenance":true},"_hasShrinkwrap":false,"devDependencies":{"jest":"^29.7.0","eslint":"^8.54.0","rollup":"^4.6.1","prettier":"^3.2.4","typescript":"^5.3.2","@types/node":"^18.0.0","@types/eslint":"^8.44.8","@babel/preset-env":"^7.23.5","@rollup/plugin-babel":"^6.0.4","@rollup/plugin-replace":"^5.0.5","@babel/preset-typescript":"^7.23.3","@typescript-eslint/parser":"^6.13.1","@rollup/plugin-node-resolve":"^15.2.3","@typescript-eslint/rule-tester":"^6.13.1","@sanity/semantic-release-preset":"^4.1.6","@typescript-eslint/typescript-estree":"^6.13.1"},"_npmOperationalInternal":{"tmp":"tmp/eslint-plugin-i18n_1.1.0_1705966437797_0.47442425559679635","host":"s3://npm-registry-packages"}}},"time":{"created":"2023-12-04T22:51:23.969Z","modified":"2026-04-08T15:21:44.556Z","1.0.0":"2023-12-04T22:51:24.263Z","1.1.0":"2024-01-22T23:33:57.955Z"},"bugs":{"url":"https://github.com/sanity-io/eslint-plugin-i18n/issues"},"author":{"name":"Sanity.io","email":"hello@sanity.io"},"license":"MIT","homepage":"https://www.sanity.io/","keywords":["sanity","eslint","eslintplugin"],"repository":{"url":"git+https://github.com/sanity-io/eslint-plugin-i18n.git","type":"git"},"description":"This ESLint plugin provides rules to enforce specific code standards in internationalization practices, particularly focusing on attribute strings and template literals in JSX.","maintainers":[{"email":"svc.npm@sanity.io","name":"sanity-svc.npm"},{"email":"developers@sanity.io","name":"sanity-io"}],"readme":"# @sanity/eslint-plugin-i18n\n\nThis ESLint plugin provides rules to enforce specific code standards in internationalization practices, particularly focusing on attribute strings and template literals in JSX. It aims to improve code quality and maintainability in projects with internationalization concerns.\n\n## Installation\n\n> **👋 Note:** We **highly** recommend installing [`@sanity/eslint-config-i18n`](https://github.com/sanity-io/eslint-config-i18n) instead which comes bundled with other plugins that are useful for localizing your Studio.\n\nEnsure [ESLint](https://eslint.org/) is installed and initialized then install the following package:\n\n```\nnpm install @sanity/eslint-plugin-i18n --save-dev\n```\n\nThen update your eslint configuration:\n\n```js\n// .eslintrc.cjs\nmodule.exports = {\n  plugins: ['@sanity/i18n'],\n  rules: {\n    '@sanity/i18n/no-attribute-string-literals': 'error',\n    '@sanity/i18n/no-attribute-template-literals': 'error',\n    '@sanity/i18n/no-i18next-import': 'error',\n  },\n};\n```\n\n## Rules\n\n### `no-attribute-string-literals`\n\nThis rule finds string literals within JSX attributes. These attribute can be nested within ternary expression and logical expressions.\n\n**Note:** This rule does not report if there is an expression within template literals as this is what `no-attribute-template-literals` is for.\n\nExamples of **incorrect** code for this rule:\n\n```jsx\n// 🛑 JSX literal\n<MyComponent prop=\"some string literal\">\n```\n\n```jsx\n// 🛑 string literal inside of a JSX expression container\n<MyComponent prop={'some string literal'}>\n```\n\n```jsx\n// 🛑 template literal with no expressions in a JSX expression container\n<MyComponent prop={`some string literal`}>\n```\n\n```jsx\n// 🛑 string literals nested within a ternary\n<MyComponent prop={conditional ? 'nested literal' : 'another literal'}>\n```\n\n```jsx\n// 🛑 string literals nested within a logical expression\n<MyComponent prop={nullishValue ?? 'fallback literal'}>\n```\n\nExamples of **correct** code for this rule:\n\n```jsx\n// ✅ function call\n<MyComponent text={t('some.localized.text')}>\n```\n\n```jsx\n// ✅ not string literals\n<MyComponent booleanAttr numberAttr={5}>\n```\n\n### `no-attribute-template-literals`\n\nThis rule finds template literals _with expressions_ within JSX attributes. These attribute can be nested within ternary expression and logical expressions.\n\n**Note:** With the default configuration, this rule will only report if there is whitespace within a template element. See [usage](#usage) below to change this behavior.\n\nExamples of **incorrect** code for this rule:\n\n```jsx\n// 🛑 template literal with an expression and whitespace\n<MyComponent prop={`Hello ${name}!`}>\n```\n\n```jsx\n// 🛑 template literals with expressions nested within a ternary\n<MyComponent prop={conditional ? `Hello ${name}` : `Goodbye ${name}`}>\n```\n\n```jsx\n// 🛑 template literals with expression nested within a logical expression\n<MyComponent prop={nullishValue ?? `Hello ${name}`}>\n```\n\nExamples of **correct** code for this rule:\n\n```jsx\n// ✅ does not contain an expression (this will break the other rule)\n<MyComponent text={`no expression`}>\n```\n\n```jsx\n// ✅ no whitespace in the template element (with the default config)\n<MyComponent id={`prefix-${id}`}>\n```\n\n```jsx\n// ✅ not string literals\n<MyComponent booleanAttr numberAttr={5}>\n```\n\n### `no-i18next-import`\n\nThis rule finds imports of the `i18next` and `react-i18next` package. While these packages are (currently) used as dependencies of `sanity`, this is considered an implementation detail and should not be relied upon. Instead, you should import any i18n utility/helper from the `sanity` module directly.\n\nExamples of **incorrect** code for this rule:\n\n```js\n// 🛑 importing from `react-i18next``\nimport { useTranslation } from 'react-i18next';\n```\n\n```js\n// 🛑 requiring from `react-i18next``\nconst { Trans } = require('react-i18next');\n```\n\nExamples of **correct** code for this rule:\n\n```js\n// ✅ requiring from `sanity`\nconst { Translate } = require('sanity');\n```\n\n## Usage\n\nIn your ESLint config, add `\"@sanity/i18n\"` to the list of plugins and enable the rules:\n\n```js\n// .eslintrc.cjs\nmodule.exports = {\n  plugins: ['@sanity/i18n'],\n  rules: {\n    '@sanity/i18n/no-attribute-string-literals': [\n      'error',\n      // these take in the same options.\n      // you may omit this if you don't want to configure any more options.\n      {\n        ignores: {\n          // ...\n        },\n        only: {\n          // ...\n        },\n        mode: 'extend',\n      },\n    ],\n    '@sanity/i18n/no-attribute-template-literals': [\n      'error',\n      // these take in the same options.\n      // you may omit this if you don't want to configure any more options.\n      {\n        ignores: {\n          // ...\n        },\n        only: {\n          // ...\n        },\n        mode: 'extend',\n      },\n    ],\n    '@sanity/i18n/no-i18next-import': 'error',\n  },\n};\n```\n\n### Rule options\n\n| Option    | Description                                                                                                                                                                           | Type                          | Default value                |\n| --------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ----------------------------- | ---------------------------- |\n| `mode`    | If the mode is specified as `override` the default configuration for `ignores` and `only` will be overridden by the user configuration. The default behavior is to `extend`.          | `'extend' \\| 'override'`      | `'extend'`                   |\n| `only`    | If specified, only attributes matching its conditions will be considered. If omitted, all attributes are initially selected.                                                          | [`InputOption`](#inputoption) | [See here](/src/defaults.ts) |\n| `ignores` | This is the primary filter used to specify exceptions or conditions for which attributes should not be reported. Attributes matching its conditions are excluded from being reported. | [`InputOption`](#inputoption) | [See here](/src/defaults.ts) |\n\n**Note:** If the `only` option is present with `ignores`, the `only` option will determine which attributes to consider and then the `ignores` option is used to ignore any attributes that match.\n\n#### `InputOption`\n\nThe `only` and `ignores` options take in this `InputOption` type shown below. Note how you can combine logic expressions to consider and ignore different attributes.\n\n```ts\ntype InputOption =\n  | { and: InputOption[] }\n  | { or: InputOption[] }\n  | { not: InputOption }\n  | {\n      /**\n       * List of attributes to match.\n       *\n       * For instance, to match the attribute `foo` in `<Component foo=\"text\" />`,\n       * add \"foo\" to this list.\n       */\n      attributes?: string[];\n\n      /**\n       * Regex patterns for attribute names. (case insensitive)\n       *\n       * E.g., to match all `data-` attributes in `<Component data-testid=\"a\" />`,\n       * use the pattern \"^data-\\w+\".\n       */\n      attributePatterns?: string[];\n\n      /**\n       * List of string literals or template element values to match.\n       *\n       * For instance, to match the value `hello ` in `<Component text={`hello ${name}`} />`,\n       * add `'hello '` to this list.\n       */\n      values?: string[];\n\n      /**\n       * Regex patterns to match string literals or template element values.\n       * (case insensitive)\n       *\n       * For instance, to match the value `id:` in `<Component text={`id:${name}`} />`,\n       * add `'id:'` to this list.\n       */\n      valuePatterns?: string[];\n\n      /**\n       * List of component names to match.\n       *\n       * For instance, to match the `<Button />` component,\n       * add \"Button\" to this list.\n       */\n      components?: string[];\n\n      /**\n       * Regex patterns for component names. (case insensitive)\n       *\n       * E.g., to match any component with \"Btn\" in its name like `<SubmitBtn />` or `<CancelBtn />`,\n       * use the pattern \".*btn\".\n       */\n      componentPatterns?: string[];\n    };\n```\n\nThere are three logical operators to aid in crafting your criteria:\n\n- **OR (`or`)**: Any condition within the `or` block being true makes the entire block true.\n- **AND (`and`)**: All conditions within the `and` block must be true for the entire block to be true.\n- **NOT (`not`)**: Inverts the result of its condition.\n\nWhen multiple keys are present in the input object, they follow the \"OR\" logic. If you desire an \"AND\" relationship, use the `and` condition explicitly. For example, to enforce that an attribute must be from the `Button` component AND named 'as', you'd use:\n\n```json\n{\n  \"and\": [{ \"components\": [\"Button\"] }, { \"attributes\": [\"as\"] }]\n}\n```\n\nSee the [defaults](./src/defaults.ts) for more examples.\n\nAdditionally the default options can be imported via `@sanity/eslint-plugin-i18n/defaults`\n\n```js\nconst {\n  defaultNoAttributeTemplateLiteralsOptions,\n  defaultNoAttributeStringLiteralsOptions,\n} = require('@sanity/eslint-plugin-i18n/defaults');\n```\n","readmeFilename":"README.md"}