Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: update eslint #2133

Merged
merged 1 commit into from
Dec 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 0 additions & 9 deletions .eslintignore

This file was deleted.

26 changes: 0 additions & 26 deletions .eslintrc

This file was deleted.

62 changes: 62 additions & 0 deletions eslint.config.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
import pluginJs from "@eslint/js"
import tseslint from "typescript-eslint"
import pluginReact from "eslint-plugin-react"
import { config } from "typescript-eslint"
import importPlugin from "eslint-plugin-import"

export default config(
{ files: ["./packages/**/*.{ts,tsx,js,jsx}"] },
pluginJs.configs.recommended,
...tseslint.configs.recommended,
{
plugins: {
import: importPlugin,
},
},
importPlugin.flatConfigs.typescript,
{
ignores: [
"**/dist/*",
"**/fixtures/*",
"**/locale/*",
"**/test/**/expected/*",
"**/test/**/actual/*",
],
},
{
rules: {
"@typescript-eslint/no-unused-expressions": [
"error",
{
allowShortCircuit: true,
allowTernary: true,
},
],
"@typescript-eslint/no-explicit-any": "off",
"@typescript-eslint/no-require-imports": "off",
"@typescript-eslint/no-unused-vars": "off",
"import/no-extraneous-dependencies": [
"error",
{
devDependencies: [
"**/test/**",
"**/*.test.{ts,tsx}",
"**/*.test-d.{ts,tsx}",
"**/vite.config.ts",
],
},
],
"no-undef": "off",
},
},
{
files: ["**/*.test-d.{ts,tsx}", "**/*.test.{ts,tsx}", "eslint.config.mjs"],
rules: {
"import/no-extraneous-dependencies": "off",
},
},
{
files: ["./packages/react/*.{ts,tsx,js,jsx}"],
...pluginReact.configs.flat.recommended,
}
)
18 changes: 7 additions & 11 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
"test:tsd": "jest -c jest.config.types.js",
"test:all": "yarn test && yarn test:integration && yarn test:e2e && yarn test:tsd",
"lint:types": "tsc",
"lint:eslint": "eslint './packages/**/*.{ts,tsx,js,jsx}'",
"lint:eslint": "eslint './packages",
"lint:all": "yarn lint:eslint && yarn lint:types",
"prettier": "prettier --write '**/*.{ts,tsx,js,jsx}'",
"prettier:check": "prettier --check '**/*.{ts,tsx,js,jsx}'",
Expand All @@ -41,25 +41,20 @@
"@babel/preset-env": "^7.20.2",
"@babel/preset-react": "^7.18.6",
"@babel/preset-typescript": "^7.18.6",
"@eslint/js": "^9.17.0",
"@size-limit/preset-small-lib": "^8.1.1",
"@swc/core": "^1.3.26",
"@tsd/typescript": "^4.9.5",
"@types/jest": "^29.4.0",
"@types/mock-fs": "^4.13.1",
"@types/node": "20.14.8",
"@types/ramda": "^0.27.23",
"@typescript-eslint/eslint-plugin": "^5.50.0",
"@typescript-eslint/parser": "^5.50.0",
"babel-eslint": "^10.1.0",
"babel-jest": "^29.7.0",
"chalk": "^4.1.0",
"cross-env": "^7.0.2",
"eslint": "^7.32.0",
"eslint-import-resolver-typescript": "^3.5.3",
"eslint-plugin-import": "^2.27.5",
"eslint-plugin-jest": "^24.1.0",
"eslint-plugin-node": "^11.1.0",
"eslint-plugin-promise": "^4.1.1",
"eslint": "^9.17.0",
"eslint-plugin-import": "^2.31.0",
"eslint-plugin-react": "^7.37.2",
"husky": "^8.0.3",
"jest": "^29.7.0",
"jest-environment-jsdom": "^29.7.0",
Expand All @@ -79,7 +74,8 @@
"strip-ansi": "^6.0.1",
"swc-node": "^1.0.0",
"ts-jest": "^29.2.4",
"typescript": "^4.9.5"
"typescript": "^4.9.5",
"typescript-eslint": "^8.18.1"
},
"workspaces": [
"packages/*",
Expand Down
5 changes: 3 additions & 2 deletions packages/babel-plugin-lingui-macro/src/icu.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ export class ICUMessageFormat {
switch (token.format) {
case "plural":
case "select":
case "selectordinal":
case "selectordinal": {
const formatOptions = Object.keys(token.options)
.filter((key) => token.options[key] != null)
.map((key) => {
Expand Down Expand Up @@ -116,6 +116,7 @@ export class ICUMessageFormat {
values,
elements: jsxElements,
}
}
default:
return {
message: token.raw ? `${token.name}` : `{${token.name}}`,
Expand All @@ -124,7 +125,7 @@ export class ICUMessageFormat {
}
} else if (token.type === "element") {
let message = ""
let elementValues: ParsedResult["values"] = {}
const elementValues: ParsedResult["values"] = {}
Object.assign(jsxElements, { [token.name]: token.value })
token.children.forEach((child) => {
const {
Expand Down
7 changes: 2 additions & 5 deletions packages/babel-plugin-lingui-macro/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import type { PluginObj, Visitor, PluginPass, BabelFile } from "@babel/core"
import type { PluginObj, Visitor, PluginPass } from "@babel/core"
import type * as babelTypes from "@babel/types"
import { Program, Identifier } from "@babel/types"
import { MacroJSX } from "./macroJsx"
import { NodePath } from "@babel/traverse"
import type { NodePath } from "@babel/traverse"
import { MacroJs } from "./macroJs"
import {
MACRO_CORE_PACKAGE,
Expand Down Expand Up @@ -161,9 +161,6 @@ export default function ({
}
return {
name: "lingui-macro-plugin",
pre(file: BabelFile) {
file.hub
},
visitor: {
Program: {
enter(path, state) {
Expand Down
2 changes: 1 addition & 1 deletion packages/babel-plugin-lingui-macro/src/macro.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { createMacro, MacroParams } from "babel-plugin-macros"

import { VisitNodeObject } from "@babel/traverse"
import type { VisitNodeObject } from "@babel/traverse"
import { Program } from "@babel/types"

import linguiPlugin from "./index"
Expand Down
4 changes: 2 additions & 2 deletions packages/babel-plugin-lingui-macro/src/macroJs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {
ObjectExpression,
ObjectProperty,
} from "@babel/types"
import { NodePath } from "@babel/traverse"
import type { NodePath } from "@babel/traverse"

import { Tokens } from "./icu"
import { JsMacroName } from "./constants"
Expand Down Expand Up @@ -282,7 +282,7 @@ export class MacroJs {
currentPath.isCallExpression() &&
currentPath.get("arguments")[0]?.isObjectExpression()
) {
let descriptor = processDescriptor(
const descriptor = processDescriptor(
(currentPath.get("arguments")[0] as NodePath<ObjectExpression>)
.node,
ctx
Expand Down
2 changes: 1 addition & 1 deletion packages/babel-plugin-lingui-macro/src/macroJsx.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import {
TemplateLiteral,
SourceLocation,
} from "@babel/types"
import { NodePath } from "@babel/traverse"
import type { NodePath } from "@babel/traverse"

import { ArgToken, ElementToken, TextToken, Token } from "./icu"
import { makeCounter } from "./utils"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ macroTester({
code: `
import { defineMessage } from '@lingui/core/macro';
const msg = defineMessage({
message: \`Hello $\{name\}\`,
message: \`Hello \${name}\`,
comment: 'description for translators',
context: 'My Context',
})
Expand All @@ -83,7 +83,7 @@ macroTester({
code: `
import { defineMessage } from '@lingui/core/macro';
const msg = defineMessage({
message: \`Hello $\{name\}\`,
message: \`Hello \${name}\`,
id: 'msgId',
comment: 'description for translators',
context: 'My Context',
Expand All @@ -95,7 +95,7 @@ macroTester({
code: `
import { defineMessage, t } from '@lingui/core/macro';
const message = defineMessage({
message: t\`Hello $\{name\}\`
message: t\`Hello \${name}\`
})
`,
},
Expand Down
10 changes: 5 additions & 5 deletions packages/babel-plugin-lingui-macro/test/js-t.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ macroTester({
name: "Variables with escaped double quotes are correctly formatted",
code: `
import { t } from '@lingui/core/macro';
t\`Variable \"name\"\`;
t\`Variable "name"\`;
`,
},
{
Expand Down Expand Up @@ -194,7 +194,7 @@ macroTester({
import { t } from '@lingui/core/macro';
import { i18n } from './lingui';
const msg = t(i18n)({
message: \`Hello $\{name\}\`,
message: \`Hello \${name}\`,
id: 'msgId',
comment: 'description for translators',
context: 'My Context',
Expand All @@ -207,7 +207,7 @@ macroTester({
code: `
import { t } from '@lingui/core/macro';
const msg = t({
message: \`Hello $\{name\}\`,
message: \`Hello \${name}\`,
id: 'msgId',
comment: 'description for translators',
context: 'My Context',
Expand All @@ -223,7 +223,7 @@ macroTester({
code: `
import { t } from '@lingui/macro';
const msg = t({
message: \`Hello $\{name\}\`,
message: \`Hello \${name}\`,
id: 'msgId',
comment: 'description for translators',
context: 'My Context',
Expand All @@ -239,7 +239,7 @@ macroTester({
code: `
import { t } from '@lingui/core/macro';
const msg = t({
message: \`Hello $\{name\}\`,
message: \`Hello \${name}\`,
id: 'msgId',
comment: 'description for translators',
context: 'My Context',
Expand Down
1 change: 1 addition & 0 deletions packages/babel-plugin-lingui-macro/test/macroTester.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// use package path instead relative because we want
// to test it in from /dist folder in integration tests
// eslint-disable-next-line import/no-extraneous-dependencies
import linguiMacroPlugin, {
LinguiPluginOpts,
} from "@lingui/babel-plugin-lingui-macro"
Expand Down
2 changes: 1 addition & 1 deletion packages/cli/src/api/catalog/extractFromFiles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ export async function extractFromFiles(
const messages: ExtractedCatalogType = {}

let catalogSuccess = true
for (let filename of paths) {
for (const filename of paths) {
const fileSuccess = await extract(
filename,
(next: ExtractedMessage) => {
Expand Down
12 changes: 5 additions & 7 deletions packages/cli/src/api/catalog/getTranslationsForCatalog.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ function getTranslation(
// -> template message
// ** last resort **
// -> id
let translation =
const translation =
// Get translation in target locale
getTranslation(locale) ||
// We search in fallbackLocales as dependent of each locale
Expand All @@ -83,12 +83,10 @@ function getTranslation(
sourceLocaleFallback(catalogs[sourceLocale], key))

if (!translation) {
onMissing &&
onMissing({
id: key,
source:
msg.message || sourceLocaleFallback(catalogs[sourceLocale], key),
})
onMissing?.({
id: key,
source: msg.message || sourceLocaleFallback(catalogs[sourceLocale], key),
})
}

return (
Expand Down
2 changes: 1 addition & 1 deletion packages/cli/src/api/extractors/babel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export const babelRe = new RegExp(
)

const inlineSourceMapsRE = new RegExp(
/\/[\/\*][#@]\s+sourceMappingURL=data:application\/json;(?:charset:utf-8;)?base64,/i
/\/[/*][#@]\s+sourceMappingURL=data:application\/json;(?:charset:utf-8;)?base64,/i
)

/**
Expand Down
2 changes: 1 addition & 1 deletion packages/cli/src/api/extractors/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export default async function extract(
): Promise<boolean> {
const extractorsToExtract = options.extractors ?? DEFAULT_EXTRACTORS

for (let ext of extractorsToExtract) {
for (const ext of extractorsToExtract) {
if (!ext.match(filename)) continue

try {
Expand Down
4 changes: 3 additions & 1 deletion packages/cli/src/api/help.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,9 @@ export function helpRun(command: string) {
let findRootPkgJson: Record<string, unknown>
try {
findRootPkgJson = require(resolve(join(process.cwd(), "package.json")))
} catch (error) {}
} catch (error) {
// noting
}

if (findRootPkgJson?.scripts) {
const res = Object.entries(findRootPkgJson.scripts).find(([_, value]) =>
Expand Down
1 change: 1 addition & 0 deletions packages/cli/src/api/stats.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
import Table from "cli-table"
import chalk from "chalk"
Expand Down
2 changes: 1 addition & 1 deletion packages/cli/src/lingui-extract-template.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export default async function command(
): Promise<boolean> {
options.verbose && console.log("Extracting messages from source files…")
const catalogs = await getCatalogs(config)
const catalogStats: { [path: string]: Number } = {}
const catalogStats: { [path: string]: number } = {}

let commandSuccess = true

Expand Down
Loading
Loading