diff --git a/.eslintignore b/.eslintignore index dc0ec529e..45a530480 100644 --- a/.eslintignore +++ b/.eslintignore @@ -3,3 +3,4 @@ **/fixtures/* **/locale/* docs/* +README.md \ No newline at end of file diff --git a/.eslintrc b/.eslintrc index 494d7fefb..95117785a 100644 --- a/.eslintrc +++ b/.eslintrc @@ -2,6 +2,7 @@ "env": { "jest/globals": true }, + "parser": "@typescript-eslint/parser", "parserOptions": { "ecmaVersion": 2020, "sourceType": "module", @@ -10,7 +11,7 @@ } }, "extends": ["plugin:import/errors", "plugin:import/warnings"], - "plugins": ["promise", "import", "react", "jest"], + "plugins": ["promise", "import", "react", "jest", "@typescript-eslint"], "settings": { "import/extensions": [".js", ".jsx", ".ts", ".tsx"], "import/parsers": { @@ -24,6 +25,7 @@ }, "rules": { "no-duplicate-imports": "off", - "react/display-name": "off" + "react/display-name": "off", + "@typescript-eslint/consistent-type-definitions": ["error", "type"] } } diff --git a/package.json b/package.json index 80858bd20..a382b4300 100644 --- a/package.json +++ b/package.json @@ -13,7 +13,7 @@ "watch": "cross-env NODE_ICU_DATA=node_modules/full-icu jest -c scripts/jest/config.unit.js --watch", "watch:integration": "cross-env NODE_ICU_DATA=node_modules/full-icu jest -c scripts/jest/config.integration.js --watch", "lint:types": "tsc", - "lint:eslint": "eslint packages/", + "lint:eslint": "eslint packages/**", "lint": "yarn lint:eslint; yarn lint:types", "release": "node ./scripts/release.js", "release:integration": "node ./scripts/integration.js", @@ -36,6 +36,7 @@ "@types/jest": "^25.2.1", "@types/ramda": "^0.27.3", "@types/react": "^16.9.34", + "@typescript-eslint/eslint-plugin": "^2.28.0", "@typescript-eslint/parser": "^2.28.0", "babel-code-frame": "^6.26.0", "babel-core": "7.0.0-bridge.0", diff --git a/packages/cli/src/api/catalog.ts b/packages/cli/src/api/catalog.ts index 8998022db..cc10ff47f 100644 --- a/packages/cli/src/api/catalog.ts +++ b/packages/cli/src/api/catalog.ts @@ -23,16 +23,16 @@ const NAME = "{name}" const LOCALE = "{locale}" const PATHSEP = "/" // force posix everywhere -export interface MakeOptions extends CliExtractOptions { +export type MakeOptions = CliExtractOptions & { projectType?: string orderBy?: OrderBy } -export interface MergeOptions { +export type MergeOptions = { overwrite: boolean } -export interface GetTranslationsOptions { +export type GetTranslationsOptions = { sourceLocale: string fallbackLocale: string } diff --git a/packages/cli/src/api/compile.ts b/packages/cli/src/api/compile.ts index 06740062e..935646364 100644 --- a/packages/cli/src/api/compile.ts +++ b/packages/cli/src/api/compile.ts @@ -8,7 +8,7 @@ import pseudoLocalize from "./pseudoLocalize" export type CompiledCatalogNamespace = "cjs" | "es" | string -export interface CreateCompileCatalogOptions { +export type CreateCompileCatalogOptions = { strict?: boolean namespace?: CompiledCatalogNamespace pseudoLocale?: string diff --git a/packages/cli/src/api/extractors/types.ts b/packages/cli/src/api/extractors/types.ts index 382c1d281..af9f07cea 100644 --- a/packages/cli/src/api/extractors/types.ts +++ b/packages/cli/src/api/extractors/types.ts @@ -3,12 +3,12 @@ export type ExtractorType = { extract(filename: string, targetDir: string, options?: ExtractOptions): void } -export interface BabelOptions { +export type BabelOptions = { plugins?: Array presets?: Array } -export interface ExtractOptions { +export type ExtractOptions = { projectType?: string babelOptions?: BabelOptions } diff --git a/packages/cli/src/api/formats/index.ts b/packages/cli/src/api/formats/index.ts index ce87605f4..9a4b7cb60 100644 --- a/packages/cli/src/api/formats/index.ts +++ b/packages/cli/src/api/formats/index.ts @@ -6,12 +6,12 @@ import { CatalogType } from "../types" const formats: { [key: string]: CatalogFormat } = { lingui, minimal, po, csv } -export interface CatalogFormatOptions { +export type CatalogFormatOptions = { locale: string origins: false } -export interface CatalogFormat { +export type CatalogFormat = { catalogExtension: string write( filename: string, diff --git a/packages/cli/src/api/types.ts b/packages/cli/src/api/types.ts index bd72e5fcc..bb55ce02e 100644 --- a/packages/cli/src/api/types.ts +++ b/packages/cli/src/api/types.ts @@ -2,7 +2,7 @@ type Maybe = T | null | undefined export type IdempotentResult = [boolean, Maybe] // [ created, result ] -export interface ExtractedMessageType { +export type ExtractedMessageType = { message?: string origin: Array<[number, string]> comment?: string @@ -11,7 +11,7 @@ export interface ExtractedMessageType { flags?: Array } -export interface MessageType extends ExtractedMessageType { +export type MessageType = ExtractedMessageType & { translation: string } diff --git a/packages/cli/src/lingui-extract.ts b/packages/cli/src/lingui-extract.ts index ff3ef720d..00fb3d423 100644 --- a/packages/cli/src/lingui-extract.ts +++ b/packages/cli/src/lingui-extract.ts @@ -1,8 +1,7 @@ import chalk from "chalk" import program from "commander" -import { getConfig } from "@lingui/conf" -import { LinguiConfig } from "@lingui/conf" +import { getConfig, LinguiConfig } from "@lingui/conf" import { getCatalogs } from "./api/catalog" diff --git a/packages/core/src/i18n.ts b/packages/core/src/i18n.ts index e8fb981bb..ed35c19b5 100644 --- a/packages/core/src/i18n.ts +++ b/packages/core/src/i18n.ts @@ -26,7 +26,7 @@ export type Messages = Record export type AllMessages = Record -export interface MessageDescriptor { +export type MessageDescriptor = { id?: string comment?: string message?: string diff --git a/packages/macro/index.d.ts b/packages/macro/index.d.ts index efb3f7e9e..e85c5d3d3 100644 --- a/packages/macro/index.d.ts +++ b/packages/macro/index.d.ts @@ -1,13 +1,13 @@ -import { ComponentType, ReactNode } from "react" -import { MessageDescriptor } from "@lingui/core" -import { TransRenderType } from "@lingui/react" +import type { ComponentType, ReactNode } from "react" +import type { MessageDescriptor } from "@lingui/core" +import type { TransRenderType } from "@lingui/react" export function t( literals: TemplateStringsArray, ...placeholders: any[] ): string -export interface ChoiceOptions { +export type ChoiceOptions = { offset?: number zero?: T one?: T @@ -26,20 +26,21 @@ export function defineMessages>( ): M export function defineMessage(descriptor: MessageDescriptor): MessageDescriptor -export interface TransProps { +export type TransProps = { id?: string comment?: string render?: TransRenderType } -export interface ChoiceProps extends TransProps, ChoiceOptions { +export type ChoiceProps = { value?: string | number -} +} & TransProps & + ChoiceOptions -export interface SelectProps extends TransProps { +export type SelectProps = { value?: string other?: ReactNode -} +} & TransProps export const Trans: ComponentType export const Plural: ComponentType diff --git a/packages/react/src/I18nProvider.tsx b/packages/react/src/I18nProvider.tsx index cbcd1fd86..1a8a6c847 100644 --- a/packages/react/src/I18nProvider.tsx +++ b/packages/react/src/I18nProvider.tsx @@ -2,12 +2,12 @@ import React, { FunctionComponent } from "react" import { I18n } from "@lingui/core" import { TransRenderType } from "./Trans" -interface I18nContext { +type I18nContext = { i18n: I18n defaultRender?: TransRenderType } -export interface I18nProviderProps extends I18nContext {} +export type I18nProviderProps = I18nContext const LinguiContext = React.createContext(null) diff --git a/packages/react/src/Trans.tsx b/packages/react/src/Trans.tsx index 41000a040..dad348b8e 100644 --- a/packages/react/src/Trans.tsx +++ b/packages/react/src/Trans.tsx @@ -3,7 +3,7 @@ import React from "react" import { useLingui } from "./I18nProvider" import { formatElements } from "./format" -export interface TransRenderProps { +export type TransRenderProps = { id: string translation: React.ReactNode message: string | null @@ -14,7 +14,7 @@ export type TransRenderType = | React.ElementType | React.ReactElement -export interface TransProps { +export type TransProps = { id: string message?: string values: Object diff --git a/yarn.lock b/yarn.lock index 550476a26..121aabe84 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1537,6 +1537,16 @@ dependencies: "@types/yargs-parser" "*" +"@typescript-eslint/eslint-plugin@^2.28.0": + version "2.33.0" + resolved "https://registry.yarnpkg.com/@typescript-eslint/eslint-plugin/-/eslint-plugin-2.33.0.tgz#d6c8319d5011b4783bb3d2dadf105d8bdd499bd5" + integrity sha512-QV6P32Btu1sCI/kTqjTNI/8OpCYyvlGjW5vD8MpTIg+HGE5S88HtT1G+880M4bXlvXj/NjsJJG0aGcVh0DdbeQ== + dependencies: + "@typescript-eslint/experimental-utils" "2.33.0" + functional-red-black-tree "^1.0.1" + regexpp "^3.0.0" + tsutils "^3.17.1" + "@typescript-eslint/experimental-utils@2.28.0", "@typescript-eslint/experimental-utils@^2.5.0": version "2.28.0" resolved "https://registry.yarnpkg.com/@typescript-eslint/experimental-utils/-/experimental-utils-2.28.0.tgz#1fd0961cd8ef6522687b4c562647da6e71f8833d" @@ -1547,6 +1557,16 @@ eslint-scope "^5.0.0" eslint-utils "^2.0.0" +"@typescript-eslint/experimental-utils@2.33.0": + version "2.33.0" + resolved "https://registry.yarnpkg.com/@typescript-eslint/experimental-utils/-/experimental-utils-2.33.0.tgz#000f1e5f344fbea1323dc91cc174805d75f99a03" + integrity sha512-qzPM2AuxtMrRq78LwyZa8Qn6gcY8obkIrBs1ehqmQADwkYzTE1Pb4y2W+U3rE/iFkSWcWHG2LS6MJfj6SmHApg== + dependencies: + "@types/json-schema" "^7.0.3" + "@typescript-eslint/typescript-estree" "2.33.0" + eslint-scope "^5.0.0" + eslint-utils "^2.0.0" + "@typescript-eslint/parser@^2.28.0": version "2.28.0" resolved "https://registry.yarnpkg.com/@typescript-eslint/parser/-/parser-2.28.0.tgz#bb761286efd2b0714761cab9d0ee5847cf080385" @@ -1570,6 +1590,19 @@ semver "^6.3.0" tsutils "^3.17.1" +"@typescript-eslint/typescript-estree@2.33.0": + version "2.33.0" + resolved "https://registry.yarnpkg.com/@typescript-eslint/typescript-estree/-/typescript-estree-2.33.0.tgz#33504c050ccafd38f397a645d4e9534d2eccbb5c" + integrity sha512-d8rY6/yUxb0+mEwTShCQF2zYQdLlqihukNfG9IUlLYz5y1CH6G/9XYbrxQLq3Z14RNvkCC6oe+OcFlyUpwUbkg== + dependencies: + debug "^4.1.1" + eslint-visitor-keys "^1.1.0" + glob "^7.1.6" + is-glob "^4.0.1" + lodash "^4.17.15" + semver "^7.3.2" + tsutils "^3.17.1" + "@webassemblyjs/ast@1.9.0": version "1.9.0" resolved "https://registry.yarnpkg.com/@webassemblyjs/ast/-/ast-1.9.0.tgz#bd850604b4042459a5a41cd7d338cbed695ed964"