Skip to content

Commit

Permalink
chore: add @typescript-eslint
Browse files Browse the repository at this point in the history
  • Loading branch information
marcalexiei committed Jan 1, 2024
1 parent d5ed7e5 commit d7b096c
Show file tree
Hide file tree
Showing 16 changed files with 873 additions and 176 deletions.
82 changes: 82 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
/* eslint-disable @typescript-eslint/naming-convention */
module.exports = {
root: true,
env: {
mocha: true,
browser: true,
},
parser: '@typescript-eslint/parser',
parserOptions: {
project: './tsconfig.lint.json',
},
settings: {
'import/resolver': {
typescript: {
project: './tsconfig.lint.json',
},
},
},
plugins: ['@typescript-eslint'],
extends: ['airbnb-base', 'plugin:@typescript-eslint/strict', 'prettier'],
rules: {
'no-plusplus': 'off',
'no-param-reassign': 'off',
'prefer-destructuring': 'off',
'default-param-last': 'off',
'prefer-spread': 'off',
'no-continue': 'off',
'no-constructor-return': 'off',
'consistent-return': 'off',

'import/extensions': 'off',

/** @todo consider to replace any with unknown */
'@typescript-eslint/no-explicit-any': 'off',

'@typescript-eslint/no-invalid-void-type': 'off',
'@typescript-eslint/no-dynamic-delete': 'off',
'@typescript-eslint/no-magic-numbers': 'off',
'no-use-before-define': 'off',
'@typescript-eslint/no-use-before-define': 'error',
'no-shadow': 'off',
'@typescript-eslint/no-shadow': 'error',
'@typescript-eslint/naming-convention': [
'error',
{
selector: 'default',
format: ['camelCase'],
leadingUnderscore: 'allow',
trailingUnderscore: 'allow',
},

{
selector: ['import', 'parameter'],
format: ['camelCase', 'PascalCase'],
},

{
selector: 'variable',
format: ['camelCase', 'UPPER_CASE'],
leadingUnderscore: 'allow',
trailingUnderscore: 'allow',
},

{
selector: 'typeLike',
format: ['PascalCase'],
},

{
selector: 'interface',
format: ['PascalCase'],
filter: 'i18n',
},

{
selector: 'typeAlias',
format: ['PascalCase'],
leadingUnderscore: 'allow',
},
],
},
};
34 changes: 0 additions & 34 deletions .eslintrc.json

This file was deleted.

3 changes: 2 additions & 1 deletion .npmignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ assets/
.babelrc
.editorconfig
.eslintignore
.eslintrc
.eslintrc.js
.gitignore
bower.json
gulpfile.js
Expand All @@ -16,6 +16,7 @@ sample.html
.codeclimate.yml
.coveralls.yml
tsconfig.json
tsconfig.lint.json
.prettierignore
.prettierrc.json
rollup.config.js
Expand Down
3 changes: 2 additions & 1 deletion i18next.js
Original file line number Diff line number Diff line change
Expand Up @@ -1789,7 +1789,8 @@
},
interpolation: {
escapeValue: true,
format: (value, format, lng, options) => value,
/** @type {import('i18next').FormatFunction} */
format: value => value,
prefix: '{{',
suffix: '}}',
formatSeparator: ',',
Expand Down
1 change: 1 addition & 0 deletions index.d.mts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ export type * from './typescript/t.js';

export interface CustomInstanceExtenstions {}

// eslint-disable-next-line @typescript-eslint/naming-convention
export interface i18n extends i18nextMod.i18n, CustomInstanceExtenstions {}

declare const i18next: i18n;
Expand Down
10 changes: 6 additions & 4 deletions index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import type {
ResourceLanguage,
TOptions,
} from './typescript/options.js';

import type { KeyPrefix, TFunction } from './typescript/t.js';

export interface WithT<Ns extends Namespace = DefaultNamespace> {
Expand All @@ -32,12 +31,14 @@ export class ResourceStore {
constructor(data: Resource, options: InitOptions);

public data: Resource;

public options: InitOptions;

/**
* Gets fired when resources got added or removed
*/
on(event: 'added' | 'removed', callback: (lng: string, ns: string) => void): void;

/**
* Remove event listener
* removes all callback when callback not specified
Expand Down Expand Up @@ -92,9 +93,9 @@ export type MultiReadCallback = (err: CallbackError, data: Resource | null | und
* Can be provided as a singleton or as a prototype constructor (preferred for supporting multiple instances of i18next).
* For singleton set property `type` to `'backend'` For a prototype constructor set static property.
*/
export interface BackendModule<TOptions = object> extends Module {
export interface BackendModule<Options = object> extends Module {
type: 'backend';
init(services: Services, backendOptions: TOptions, i18nextOptions: InitOptions): void;
init(services: Services, backendOptions: Options, i18nextOptions: InitOptions): void;
read(language: string, namespace: string, callback: ReadCallback): void;
/** Save the missing translation */
create?(
Expand Down Expand Up @@ -136,7 +137,7 @@ export interface LanguageDetectorAsyncModule extends Module {
/** Set to true to enable async detection */
async: true;
init?(services: Services, detectorOptions: object, i18nextOptions: InitOptions): void;
/** Must call callback passing detected language or return a Promise*/
/** Must call callback passing detected language or return a Promise */
detect(
callback: (lng: string | readonly string[] | undefined) => void | undefined,
): void | Promise<string | readonly string[] | undefined>;
Expand Down Expand Up @@ -218,6 +219,7 @@ export interface CloneOptions extends InitOptions {

export interface CustomInstanceExtenstions {}

// eslint-disable-next-line @typescript-eslint/naming-convention
export interface i18n extends CustomInstanceExtenstions {
// Expose parameterized t in the i18next interface hierarchy
t: TFunction<[DefaultNamespace, ...Exclude<FlatNamespace, DefaultNamespace>[]]>;
Expand Down
Loading

0 comments on commit d7b096c

Please sign in to comment.