Skip to content

Commit 73f67d0

Browse files
chore: update eslint
1 parent e45a2af commit 73f67d0

31 files changed

+1736
-728
lines changed

.eslintignore

Lines changed: 0 additions & 9 deletions
This file was deleted.

.eslintrc

Lines changed: 0 additions & 26 deletions
This file was deleted.

eslint.config.mjs

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
import pluginJs from "@eslint/js"
2+
import tseslint from "typescript-eslint"
3+
import pluginReact from "eslint-plugin-react"
4+
import { config } from "typescript-eslint"
5+
import importPlugin from "eslint-plugin-import"
6+
7+
export default config(
8+
{ files: ["./packages/**/*.{ts,tsx,js,jsx}"] },
9+
pluginJs.configs.recommended,
10+
...tseslint.configs.recommended,
11+
{
12+
plugins: {
13+
import: importPlugin,
14+
},
15+
},
16+
importPlugin.flatConfigs.typescript,
17+
{
18+
ignores: [
19+
"**/dist/*",
20+
"**/fixtures/*",
21+
"**/locale/*",
22+
"**/test/**/expected/*",
23+
"**/test/**/actual/*",
24+
],
25+
},
26+
{
27+
rules: {
28+
"@typescript-eslint/no-unused-expressions": [
29+
"error",
30+
{
31+
allowShortCircuit: true,
32+
allowTernary: true,
33+
},
34+
],
35+
"@typescript-eslint/no-explicit-any": "off",
36+
"@typescript-eslint/no-require-imports": "off",
37+
"@typescript-eslint/no-unused-vars": "off",
38+
"import/no-extraneous-dependencies": [
39+
"error",
40+
{
41+
devDependencies: [
42+
"**/test/**",
43+
"**/*.test.{ts,tsx}",
44+
"**/*.test-d.{ts,tsx}",
45+
"**/vite.config.ts",
46+
],
47+
},
48+
],
49+
"no-undef": "off",
50+
},
51+
},
52+
{
53+
files: ["**/*.test-d.{ts,tsx}", "**/*.test.{ts,tsx}", "eslint.config.mjs"],
54+
rules: {
55+
"import/no-extraneous-dependencies": "off",
56+
},
57+
},
58+
{
59+
files: ["./packages/react/*.{ts,tsx,js,jsx}"],
60+
...pluginReact.configs.flat.recommended,
61+
}
62+
)

package.json

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
"test:tsd": "jest -c jest.config.types.js",
1717
"test:all": "yarn test && yarn test:integration && yarn test:e2e && yarn test:tsd",
1818
"lint:types": "tsc",
19-
"lint:eslint": "eslint './packages/**/*.{ts,tsx,js,jsx}'",
19+
"lint:eslint": "eslint './packages",
2020
"lint:all": "yarn lint:eslint && yarn lint:types",
2121
"prettier": "prettier --write '**/*.{ts,tsx,js,jsx}'",
2222
"prettier:check": "prettier --check '**/*.{ts,tsx,js,jsx}'",
@@ -41,25 +41,20 @@
4141
"@babel/preset-env": "^7.20.2",
4242
"@babel/preset-react": "^7.18.6",
4343
"@babel/preset-typescript": "^7.18.6",
44+
"@eslint/js": "^9.17.0",
4445
"@size-limit/preset-small-lib": "^8.1.1",
4546
"@swc/core": "^1.3.26",
4647
"@tsd/typescript": "^4.9.5",
4748
"@types/jest": "^29.4.0",
4849
"@types/mock-fs": "^4.13.1",
4950
"@types/node": "20.14.8",
5051
"@types/ramda": "^0.27.23",
51-
"@typescript-eslint/eslint-plugin": "^5.50.0",
52-
"@typescript-eslint/parser": "^5.50.0",
53-
"babel-eslint": "^10.1.0",
5452
"babel-jest": "^29.7.0",
5553
"chalk": "^4.1.0",
5654
"cross-env": "^7.0.2",
57-
"eslint": "^7.32.0",
58-
"eslint-import-resolver-typescript": "^3.5.3",
59-
"eslint-plugin-import": "^2.27.5",
60-
"eslint-plugin-jest": "^24.1.0",
61-
"eslint-plugin-node": "^11.1.0",
62-
"eslint-plugin-promise": "^4.1.1",
55+
"eslint": "^9.17.0",
56+
"eslint-plugin-import": "^2.31.0",
57+
"eslint-plugin-react": "^7.37.2",
6358
"husky": "^8.0.3",
6459
"jest": "^29.7.0",
6560
"jest-environment-jsdom": "^29.7.0",
@@ -79,7 +74,8 @@
7974
"strip-ansi": "^6.0.1",
8075
"swc-node": "^1.0.0",
8176
"ts-jest": "^29.2.4",
82-
"typescript": "^4.9.5"
77+
"typescript": "^4.9.5",
78+
"typescript-eslint": "^8.18.1"
8379
},
8480
"workspaces": [
8581
"packages/*",

packages/babel-plugin-lingui-macro/src/icu.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ export class ICUMessageFormat {
8282
switch (token.format) {
8383
case "plural":
8484
case "select":
85-
case "selectordinal":
85+
case "selectordinal": {
8686
const formatOptions = Object.keys(token.options)
8787
.filter((key) => token.options[key] != null)
8888
.map((key) => {
@@ -116,6 +116,7 @@ export class ICUMessageFormat {
116116
values,
117117
elements: jsxElements,
118118
}
119+
}
119120
default:
120121
return {
121122
message: token.raw ? `${token.name}` : `{${token.name}}`,
@@ -124,7 +125,7 @@ export class ICUMessageFormat {
124125
}
125126
} else if (token.type === "element") {
126127
let message = ""
127-
let elementValues: ParsedResult["values"] = {}
128+
const elementValues: ParsedResult["values"] = {}
128129
Object.assign(jsxElements, { [token.name]: token.value })
129130
token.children.forEach((child) => {
130131
const {

packages/babel-plugin-lingui-macro/src/index.ts

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
import type { PluginObj, Visitor, PluginPass, BabelFile } from "@babel/core"
1+
import type { PluginObj, Visitor, PluginPass } from "@babel/core"
22
import type * as babelTypes from "@babel/types"
33
import { Program, Identifier } from "@babel/types"
44
import { MacroJSX } from "./macroJsx"
5-
import { NodePath } from "@babel/traverse"
5+
import type { NodePath } from "@babel/traverse"
66
import { MacroJs } from "./macroJs"
77
import {
88
MACRO_CORE_PACKAGE,
@@ -161,9 +161,6 @@ export default function ({
161161
}
162162
return {
163163
name: "lingui-macro-plugin",
164-
pre(file: BabelFile) {
165-
file.hub
166-
},
167164
visitor: {
168165
Program: {
169166
enter(path, state) {

packages/babel-plugin-lingui-macro/src/macro.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { createMacro, MacroParams } from "babel-plugin-macros"
22

3-
import { VisitNodeObject } from "@babel/traverse"
3+
import type { VisitNodeObject } from "@babel/traverse"
44
import { Program } from "@babel/types"
55

66
import linguiPlugin from "./index"

packages/babel-plugin-lingui-macro/src/macroJs.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import {
77
ObjectExpression,
88
ObjectProperty,
99
} from "@babel/types"
10-
import { NodePath } from "@babel/traverse"
10+
import type { NodePath } from "@babel/traverse"
1111

1212
import { Tokens } from "./icu"
1313
import { JsMacroName } from "./constants"
@@ -282,7 +282,7 @@ export class MacroJs {
282282
currentPath.isCallExpression() &&
283283
currentPath.get("arguments")[0]?.isObjectExpression()
284284
) {
285-
let descriptor = processDescriptor(
285+
const descriptor = processDescriptor(
286286
(currentPath.get("arguments")[0] as NodePath<ObjectExpression>)
287287
.node,
288288
ctx

packages/babel-plugin-lingui-macro/src/macroJsx.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import {
1313
TemplateLiteral,
1414
SourceLocation,
1515
} from "@babel/types"
16-
import { NodePath } from "@babel/traverse"
16+
import type { NodePath } from "@babel/traverse"
1717

1818
import { ArgToken, ElementToken, TextToken, Token } from "./icu"
1919
import { makeCounter } from "./utils"

packages/babel-plugin-lingui-macro/test/js-defineMessage.test.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ macroTester({
7171
code: `
7272
import { defineMessage } from '@lingui/core/macro';
7373
const msg = defineMessage({
74-
message: \`Hello $\{name\}\`,
74+
message: \`Hello \${name}\`,
7575
comment: 'description for translators',
7676
context: 'My Context',
7777
})
@@ -83,7 +83,7 @@ macroTester({
8383
code: `
8484
import { defineMessage } from '@lingui/core/macro';
8585
const msg = defineMessage({
86-
message: \`Hello $\{name\}\`,
86+
message: \`Hello \${name}\`,
8787
id: 'msgId',
8888
comment: 'description for translators',
8989
context: 'My Context',
@@ -95,7 +95,7 @@ macroTester({
9595
code: `
9696
import { defineMessage, t } from '@lingui/core/macro';
9797
const message = defineMessage({
98-
message: t\`Hello $\{name\}\`
98+
message: t\`Hello \${name}\`
9999
})
100100
`,
101101
},

packages/babel-plugin-lingui-macro/test/js-t.test.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ macroTester({
5151
name: "Variables with escaped double quotes are correctly formatted",
5252
code: `
5353
import { t } from '@lingui/core/macro';
54-
t\`Variable \"name\"\`;
54+
t\`Variable "name"\`;
5555
`,
5656
},
5757
{
@@ -194,7 +194,7 @@ macroTester({
194194
import { t } from '@lingui/core/macro';
195195
import { i18n } from './lingui';
196196
const msg = t(i18n)({
197-
message: \`Hello $\{name\}\`,
197+
message: \`Hello \${name}\`,
198198
id: 'msgId',
199199
comment: 'description for translators',
200200
context: 'My Context',
@@ -207,7 +207,7 @@ macroTester({
207207
code: `
208208
import { t } from '@lingui/core/macro';
209209
const msg = t({
210-
message: \`Hello $\{name\}\`,
210+
message: \`Hello \${name}\`,
211211
id: 'msgId',
212212
comment: 'description for translators',
213213
context: 'My Context',
@@ -223,7 +223,7 @@ macroTester({
223223
code: `
224224
import { t } from '@lingui/macro';
225225
const msg = t({
226-
message: \`Hello $\{name\}\`,
226+
message: \`Hello \${name}\`,
227227
id: 'msgId',
228228
comment: 'description for translators',
229229
context: 'My Context',
@@ -239,7 +239,7 @@ macroTester({
239239
code: `
240240
import { t } from '@lingui/core/macro';
241241
const msg = t({
242-
message: \`Hello $\{name\}\`,
242+
message: \`Hello \${name}\`,
243243
id: 'msgId',
244244
comment: 'description for translators',
245245
context: 'My Context',

packages/babel-plugin-lingui-macro/test/macroTester.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
// use package path instead relative because we want
22
// to test it in from /dist folder in integration tests
3+
// eslint-disable-next-line import/no-extraneous-dependencies
34
import linguiMacroPlugin, {
45
LinguiPluginOpts,
56
} from "@lingui/babel-plugin-lingui-macro"

packages/cli/src/api/catalog/extractFromFiles.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ export async function extractFromFiles(
3535
const messages: ExtractedCatalogType = {}
3636

3737
let catalogSuccess = true
38-
for (let filename of paths) {
38+
for (const filename of paths) {
3939
const fileSuccess = await extract(
4040
filename,
4141
(next: ExtractedMessage) => {

packages/cli/src/api/catalog/getTranslationsForCatalog.ts

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ function getTranslation(
7373
// -> template message
7474
// ** last resort **
7575
// -> id
76-
let translation =
76+
const translation =
7777
// Get translation in target locale
7878
getTranslation(locale) ||
7979
// We search in fallbackLocales as dependent of each locale
@@ -83,12 +83,10 @@ function getTranslation(
8383
sourceLocaleFallback(catalogs[sourceLocale], key))
8484

8585
if (!translation) {
86-
onMissing &&
87-
onMissing({
88-
id: key,
89-
source:
90-
msg.message || sourceLocaleFallback(catalogs[sourceLocale], key),
91-
})
86+
onMissing?.({
87+
id: key,
88+
source: msg.message || sourceLocaleFallback(catalogs[sourceLocale], key),
89+
})
9290
}
9391

9492
return (

packages/cli/src/api/extractors/babel.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ export const babelRe = new RegExp(
2828
)
2929

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

3434
/**

packages/cli/src/api/extractors/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ export default async function extract(
2020
): Promise<boolean> {
2121
const extractorsToExtract = options.extractors ?? DEFAULT_EXTRACTORS
2222

23-
for (let ext of extractorsToExtract) {
23+
for (const ext of extractorsToExtract) {
2424
if (!ext.match(filename)) continue
2525

2626
try {

packages/cli/src/api/help.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,9 @@ export function helpRun(command: string) {
2626
let findRootPkgJson: Record<string, unknown>
2727
try {
2828
findRootPkgJson = require(resolve(join(process.cwd(), "package.json")))
29-
} catch (error) {}
29+
} catch (error) {
30+
// noting
31+
}
3032

3133
if (findRootPkgJson?.scripts) {
3234
const res = Object.entries(findRootPkgJson.scripts).find(([_, value]) =>

packages/cli/src/api/stats.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
12
// @ts-ignore
23
import Table from "cli-table"
34
import chalk from "chalk"

packages/cli/src/lingui-extract-template.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ export default async function command(
1818
): Promise<boolean> {
1919
options.verbose && console.log("Extracting messages from source files…")
2020
const catalogs = await getCatalogs(config)
21-
const catalogStats: { [path: string]: Number } = {}
21+
const catalogStats: { [path: string]: number } = {}
2222

2323
let commandSuccess = true
2424

0 commit comments

Comments
 (0)