Skip to content

Commit

Permalink
ci: add eslint rules for declare enums (#4825)
Browse files Browse the repository at this point in the history
  • Loading branch information
splincode authored Jul 3, 2023
1 parent 816759f commit 923975a
Show file tree
Hide file tree
Showing 16 changed files with 35 additions and 6 deletions.
2 changes: 2 additions & 0 deletions projects/addon-commerce/enums/currency-code.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
*
* @link https://en.wikipedia.org/wiki/ISO_4217
*/
// TODO: change type in v4.0
// eslint-disable-next-line no-restricted-syntax
export enum TuiCurrencyCode {
/**
* Russian ruble
Expand Down
2 changes: 2 additions & 0 deletions projects/addon-commerce/enums/currency.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
*
* @link https://en.wikipedia.org/wiki/ISO_4217
*/
// TODO: change type in v4.0
// eslint-disable-next-line no-restricted-syntax
export enum TuiCurrency {
/**
* Russian ruble
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import {TuiLanguageEditor} from '@taiga-ui/i18n';
import {Observable} from 'rxjs';
import {map} from 'rxjs/operators';

// TODO: change type in v4.0
// eslint-disable-next-line no-restricted-syntax
export enum TuiTableCommands {
InsertColumnBefore,
InsertColumnAfter,
Expand Down
2 changes: 2 additions & 0 deletions projects/addon-editor/enums/editor-tool.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// TODO: change type in v4.0
// eslint-disable-next-line no-restricted-syntax
export enum TuiEditorTool {
Undo = `undo`,
Anchor = `anchor`,
Expand Down
2 changes: 2 additions & 0 deletions projects/cdk/enums/day-of-week.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// TODO: change type in v4.0
// eslint-disable-next-line no-restricted-syntax
export enum TuiDayOfWeek {
Sunday,
Monday,
Expand Down
2 changes: 2 additions & 0 deletions projects/cdk/enums/month-number.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// TODO: change type in v4.0
// eslint-disable-next-line no-restricted-syntax
export enum TuiMonthNumber {
January,
February,
Expand Down
2 changes: 2 additions & 0 deletions projects/cdk/observables/drag-and-drop-from.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import {endWith, map, repeat, take, takeWhile} from 'rxjs/operators';
import {tuiMouseDragFinishFrom} from './mouse-drag-finish-from';
import {tuiTypedFromEvent} from './typed-from-event';

// TODO: change type in v4.0
// eslint-disable-next-line no-restricted-syntax
export enum TuiDragStage {
Start,
Continues,
Expand Down
2 changes: 2 additions & 0 deletions projects/core/enums/appearance.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// TODO: change type in v4.0
// eslint-disable-next-line no-restricted-syntax
export enum TuiAppearance {
Icon = `icon`,
Primary = `primary`,
Expand Down
1 change: 1 addition & 0 deletions projects/core/enums/dropdown-animation.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
/** @deprecated not used anymore TODO: remove in 4.0 **/
// eslint-disable-next-line no-restricted-syntax
export enum TuiDropdownAnimation {
FadeInBottom = `fadeInBottom`,
FadeInTop = `fadeInTop`,
Expand Down
2 changes: 2 additions & 0 deletions projects/core/enums/interactive-state.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
/**
* @internal used in calendar, year picker and wrapper
*/
// TODO: change type in v4.0
// eslint-disable-next-line no-restricted-syntax
export enum TuiInteractiveState {
Disabled = `disabled`,
Readonly = `readonly`,
Expand Down
2 changes: 2 additions & 0 deletions projects/core/enums/notification.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// TODO: change type in v4.0
// eslint-disable-next-line no-restricted-syntax
export enum TuiNotification {
Info = `info`,
Warning = `warning`,
Expand Down
2 changes: 2 additions & 0 deletions projects/core/enums/range-state.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
/**
* @internal used in calendar and year picker
*/
// TODO: change type in v4.0
// eslint-disable-next-line no-restricted-syntax
export enum TuiRangeState {
Start = `start`,
End = `end`,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
export enum PaymentMode {
ByNewCard = 0,
BySavedCard = 1,
}
export const PaymentMode = {
ByNewCard: 0,
BySavedCard: 1,
} as const;

export interface FetchedCards {
cards: AccountCard[];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import {
tuiDefaultCardValidator,
TuiInputCardGroupedComponent,
} from '@taiga-ui/addon-commerce';
import {TUI_IS_IOS, TuiDestroyService} from '@taiga-ui/cdk';
import {TUI_IS_IOS, TuiDestroyService, TuiValuesOf} from '@taiga-ui/cdk';
import {TuiDialogContext} from '@taiga-ui/core';
import {POLYMORPHEUS_CONTEXT} from '@tinkoff/ng-polymorpheus';
import {BehaviorSubject} from 'rxjs';
Expand Down Expand Up @@ -47,7 +47,7 @@ export class PayModalComponent implements OnInit {
});

cards: AccountCard[] = [];
paymentMode: PaymentMode = PaymentMode.ByNewCard;
paymentMode: TuiValuesOf<typeof PaymentMode> = PaymentMode.ByNewCard;
loading$ = new BehaviorSubject(false);
payProcessing$ = new BehaviorSubject(false);
amount: number = this.context?.data?.amount ?? 0;
Expand Down
2 changes: 2 additions & 0 deletions projects/i18n/enums/country-iso-code.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// TODO: change type in v4.0
// eslint-disable-next-line no-restricted-syntax
export enum TuiCountryIsoCode {
AD = `AD`,
AE = `AE`,
Expand Down
4 changes: 4 additions & 0 deletions scripts/eslint/no-restricted-syntax.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ module.exports = {
rules: {
'no-restricted-syntax': [
'error',
{
selector: 'TSEnumDeclaration',
message: `Don't declare enums, please use "const MyEnumType = { ... } as const;"`,
},
{
selector: "CallExpression[callee.name='mapTo']",
message:
Expand Down

0 comments on commit 923975a

Please sign in to comment.