Skip to content

Commit 53660ba

Browse files
authored
Merge pull request #955 from nextcloud-libraries/chore/update-eslit
chore: update ESLint to v9 and adjust code style
2 parents 7ff2598 + d467d22 commit 53660ba

21 files changed

Lines changed: 2659 additions & 3806 deletions

.eslintrc.json

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

build/format-changelog.mjs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
1-
/**
1+
/*!
22
* SPDX-FileCopyrightText: Nextcloud GmbH and Nextcloud contributors
33
* SPDX-License-Identifier: GPL-3.0-or-later
44
*/
5+
6+
/* eslint-disable no-console */
7+
58
import { readFile, writeFile } from 'node:fs/promises'
69
import { join } from 'node:path'
710

eslint.config.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
/*!
2+
* SPDX-FileCopyrightText: 2025 Nextcloud GmbH and Nextcloud contributors
3+
* SPDX-License-Identifier: CC0-1.0
4+
*/
5+
6+
import { recommendedLibrary } from '@nextcloud/eslint-config'
7+
8+
export default [
9+
...recommendedLibrary,
10+
11+
// Fix tsdoc generation
12+
{
13+
files: ['lib/**.ts'],
14+
rules: {
15+
'jsdoc/check-tag-names': [
16+
'error',
17+
{ definedTags: ['packageDocumentation'] },
18+
],
19+
},
20+
},
21+
]

lib/date.ts

Lines changed: 7 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1+
/// <reference types="@nextcloud/typings" />
12
/*!
23
* SPDX-FileCopyrightText: 2022 Nextcloud GmbH and Nextcloud contributors
34
* SPDX-License-Identifier: GPL-3.0-or-later
45
*/
5-
/// <reference types="@nextcloud/typings" />
66

7-
import { getCanonicalLocale } from './locale'
7+
import { getCanonicalLocale } from './locale.ts'
88

9-
declare let window: Nextcloud.v27.WindowWithGlobals
9+
declare let window: Nextcloud.v29.WindowWithGlobals
1010

1111
export type WeekDay = 0 | 1 | 2 | 3 | 4 | 5 | 6
1212

@@ -26,10 +26,10 @@ export function getFirstDay(): WeekDay {
2626
// Node.js and Samsung Internet only has accessor property weekInfo instead
2727
type WeekInfoDay = 1 | 2 | 3 | 4 | 5 | 6 | 7
2828
type WeekInfo = {
29-
firstDay: WeekInfoDay,
30-
weekend: WeekInfoDay,
31-
minimalDays: WeekInfoDay,
32-
}
29+
firstDay: WeekInfoDay
30+
weekend: WeekInfoDay
31+
minimalDays: WeekInfoDay
32+
}
3333
const intl = new Intl.Locale(getCanonicalLocale())
3434
// @ts-expect-error These properties are not part of the standard
3535
const weekInfo: WeekInfo = intl.getWeekInfo?.() ?? intl.weekInfo
@@ -44,8 +44,6 @@ export function getFirstDay(): WeekDay {
4444

4545
/**
4646
* Get a list of day names (full names)
47-
*
48-
* @return {string[]}
4947
*/
5048
export function getDayNames(): string[] {
5149
// Server rendered
@@ -68,8 +66,6 @@ export function getDayNames(): string[] {
6866

6967
/**
7068
* Get a list of day names (short names)
71-
*
72-
* @return {string[]}
7369
*/
7470
export function getDayNamesShort(): string[] {
7571
if (typeof window.dayNamesShort !== 'undefined') {
@@ -92,8 +88,6 @@ export function getDayNamesShort(): string[] {
9288

9389
/**
9490
* Get a list of day names (minified names)
95-
*
96-
* @return {string[]}
9791
*/
9892
export function getDayNamesMin(): string[] {
9993
// Server rendered
@@ -116,8 +110,6 @@ export function getDayNamesMin(): string[] {
116110

117111
/**
118112
* Get a list of month names (full names)
119-
*
120-
* @return {string[]}
121113
*/
122114
export function getMonthNames(): string[] {
123115
// Server rendered
@@ -145,8 +137,6 @@ export function getMonthNames(): string[] {
145137

146138
/**
147139
* Get a list of month names (short names)
148-
*
149-
* @return {string[]}
150140
*/
151141
export function getMonthNamesShort(): string[] {
152142
// Server rendered

lib/gettext.ts

Lines changed: 31 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,9 @@ const gt = getGettextBuilder()
1818
gt.gettext('some string to translate')
1919
```
2020
*/
21+
2122
import type { AppTranslations } from './registry.ts'
23+
2224
import { getLanguage, getPlural, translate, translatePlural } from './index.ts'
2325

2426
export interface GettextTranslation {
@@ -34,14 +36,40 @@ export interface GettextTranslationContext {
3436
export interface GettextTranslationBundle {
3537
headers: {
3638
[headerName: string]: string
37-
},
39+
}
3840
translations: {
3941
[context: string]: GettextTranslationContext
4042
}
4143
}
4244

43-
class GettextBuilder {
45+
class GettextWrapper {
46+
constructor(private bundle: AppTranslations) {
47+
}
48+
49+
/**
50+
* Get translated string (singular form), optionally with placeholders
51+
*
52+
* @param original original string to translate
53+
* @param placeholders map of placeholder key to value
54+
*/
55+
gettext(original: string, placeholders: Record<string, string | number> = {}): string {
56+
return translate('', original, placeholders, undefined, { bundle: this.bundle })
57+
}
4458

59+
/**
60+
* Get translated string with plural forms
61+
*
62+
* @param singular Singular text form
63+
* @param plural Plural text form to be used if `count` requires it
64+
* @param count The number to insert into the text
65+
* @param placeholders optional map of placeholder key to value
66+
*/
67+
ngettext(singular: string, plural: string, count: number, placeholders: Record<string, string | number> = {}): string {
68+
return translatePlural('', singular, plural, count, placeholders, { bundle: this.bundle })
69+
}
70+
}
71+
72+
class GettextBuilder {
4573
private debug = false
4674
private language = 'en'
4775
private translations = {} as Record<string, GettextTranslationBundle>
@@ -81,6 +109,7 @@ class GettextBuilder {
81109

82110
build(): GettextWrapper {
83111
if (this.debug) {
112+
// eslint-disable-next-line no-console
84113
console.debug(`Creating gettext instance for language ${this.language}`)
85114
}
86115

@@ -99,38 +128,6 @@ class GettextBuilder {
99128

100129
return new GettextWrapper(bundle)
101130
}
102-
103-
}
104-
105-
class GettextWrapper {
106-
107-
constructor(
108-
private bundle: AppTranslations,
109-
) {
110-
}
111-
112-
/**
113-
* Get translated string (singular form), optionally with placeholders
114-
*
115-
* @param original original string to translate
116-
* @param placeholders map of placeholder key to value
117-
*/
118-
gettext(original: string, placeholders: Record<string, string | number> = {}): string {
119-
return translate('', original, placeholders, undefined, { bundle: this.bundle })
120-
}
121-
122-
/**
123-
* Get translated string with plural forms
124-
*
125-
* @param singular Singular text form
126-
* @param plural Plural text form to be used if `count` requires it
127-
* @param count The number to insert into the text
128-
* @param placeholders optional map of placeholder key to value
129-
*/
130-
ngettext(singular: string, plural: string, count: number, placeholders: Record<string, string | number> = {}): string {
131-
return translatePlural('', singular, plural, count, placeholders, { bundle: this.bundle })
132-
}
133-
134131
}
135132

136133
/**

lib/index.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,11 @@ console.warn(n('my-app', 'Got an error', 'Got multiple errors', 2));
1717
```
1818
*/
1919

20-
export type { Translations } from './registry'
20+
export type { Translations } from './registry.ts'
2121

22-
export * from './date'
23-
export * from './locale'
24-
export * from './translation'
22+
export * from './date.ts'
23+
export * from './locale.ts'
24+
export * from './translation.ts'
2525

2626
export {
2727
type FormatDateOptions,

lib/locale.ts

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -37,33 +37,33 @@ export function isRTL(language?: string): boolean {
3737

3838
// Source: https://meta.wikimedia.org/wiki/Template:List_of_language_names_ordered_by_code
3939
const rtlLanguages = [
40-
/* eslint-disable no-multi-spaces */
41-
'ae', // Avestan
42-
'ar', // 'العربية', Arabic
40+
41+
'ae', // Avestan
42+
'ar', // 'العربية', Arabic
4343
'arc', // Aramaic
4444
'arz', // 'مصرى', Egyptian
4545
'bcc', // 'بلوچی مکرانی', Southern Balochi
4646
'bqi', // 'بختياري', Bakthiari
4747
'ckb', // 'Soranî / کوردی', Sorani
48-
'dv', // Dhivehi
49-
'fa', // 'فارسی', Persian
48+
'dv', // Dhivehi
49+
'fa', // 'فارسی', Persian
5050
'glk', // 'گیلکی', Gilaki
51-
'ha', // 'هَوُسَ', Hausa
52-
'he', // 'עברית', Hebrew
51+
'ha', // 'هَوُسَ', Hausa
52+
'he', // 'עברית', Hebrew
5353
'khw', // 'کھوار', Khowar
54-
'ks', // 'कॉशुर / کٲشُر', Kashmiri
55-
'ku', // 'Kurdî / كوردی', Kurdish
54+
'ks', // 'कॉशुर / کٲشُر', Kashmiri
55+
'ku', // 'Kurdî / كوردی', Kurdish
5656
'mzn', // 'مازِرونی', Mazanderani
5757
'nqo', // 'ߒߞߏ', N’Ko
5858
'pnb', // 'پنجابی', Western Punjabi
59-
'ps', // 'پښتو', Pashto,
60-
'sd', // 'سنڌي', Sindhi
61-
'ug', // 'Uyghurche / ئۇيغۇرچە', Uyghur
62-
'ur', // 'اردو', Urdu
59+
'ps', // 'پښتو', Pashto,
60+
'sd', // 'سنڌي', Sindhi
61+
'ug', // 'Uyghurche / ئۇيغۇرچە', Uyghur
62+
'ur', // 'اردو', Urdu
6363
'ur-PK', // 'اردو', Urdu (nextcloud BCP47 variant)
6464
'uz-AF', // 'اوزبیکی', Uzbek Afghan
65-
'yi', // 'ייִדיש', Yiddish
66-
/* eslint-enable no-multi-spaces */
65+
'yi', // 'ייִדיש', Yiddish
66+
6767
]
6868

6969
return rtlLanguages.includes(languageCode)

lib/registry.ts

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
/// <reference types="@nextcloud/typings" />
2-
32
/*!
43
* SPDX-FileCopyrightText: 2022 Nextcloud GmbH and Nextcloud contributors
54
* SPDX-License-Identifier: GPL-3.0-or-later
@@ -54,8 +53,8 @@ export interface AppTranslations {
5453
/**
5554
* Check if translations and plural function are set for given app
5655
*
57-
* @param {string} appId the app id
58-
* @return {boolean}
56+
* @param appId - The app id
57+
* @return
5958
*/
6059
export function hasAppTranslations(appId: string) {
6160
return (
@@ -67,9 +66,9 @@ export function hasAppTranslations(appId: string) {
6766
/**
6867
* Register new, or extend available, translations for an app
6968
*
70-
* @param {string} appId the app id
71-
* @param {object} translations the translations list
72-
* @param {Function} pluralFunction the plural function
69+
* @param appId - The app id
70+
* @param translations - The translations list
71+
* @param pluralFunction - The plural function
7372
*/
7473
export function registerAppTranslations(
7574
appId: string,
@@ -98,7 +97,7 @@ export function registerAppTranslations(
9897
/**
9998
* Unregister all translations and plural function for given app
10099
*
101-
* @param {string} appId the app id
100+
* @param appId - The app id
102101
*/
103102
export function unregisterAppTranslations(appId: string) {
104103
delete window._oc_l10n_registry_translations?.[appId]
@@ -108,8 +107,7 @@ export function unregisterAppTranslations(appId: string) {
108107
/**
109108
* Get translations bundle for given app and current locale
110109
*
111-
* @param {string} appId the app id
112-
* @return {object}
110+
* @param appId - The app id
113111
*/
114112
export function getAppTranslations(appId: string): AppTranslations {
115113
return {

lib/time.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,18 +8,21 @@ import { getLanguage } from './locale.ts'
88
export interface FormatDateOptions {
99
/**
1010
* If set then instead of showing seconds since the timestamp show the passed message.
11+
*
1112
* @default false
1213
*/
1314
ignoreSeconds?: string | false
1415

1516
/**
1617
* The relative time formatting option to use
18+
*
1719
* @default 'long
1820
*/
1921
relativeTime?: 'long' | 'short' | 'narrow'
2022

2123
/**
2224
* Language to use
25+
*
2326
* @default 'current language'
2427
*/
2528
language?: string
@@ -32,7 +35,7 @@ export interface FormatDateOptions {
3235
* @param opts Options for the formatting
3336
*/
3437
export function formatRelativeTime(
35-
timestamp: Date|number = Date.now(),
38+
timestamp: Date | number = Date.now(),
3639
opts: FormatDateOptions = {},
3740
): string {
3841
const options: Required<FormatDateOptions> = {

0 commit comments

Comments
 (0)