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: fix eslint errors #833

Merged
merged 1 commit into from
Dec 27, 2023
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
1 change: 0 additions & 1 deletion .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ module.exports = {
'@taiga-ui/experience/strict-tui-doc-example': 'off',
'@taiga-ui/experience/prefer-inject-decorator': 'off',
'@typescript-eslint/consistent-type-assertions': 'off',
'no-restricted-syntax': 'off', // TODO
},
},
],
Expand Down
35 changes: 18 additions & 17 deletions projects/core/src/lib/utils/dom/hotkey.ts
Original file line number Diff line number Diff line change
@@ -1,44 +1,45 @@
export const enum HotkeyModifier {
CTRL = 1 << 0,
ALT = 1 << 1,
SHIFT = 1 << 2,
META = 1 << 3,
}
export const HotkeyModifier = {
CTRL: 1 << 0,
ALT: 1 << 1,
SHIFT: 1 << 2,
META: 1 << 3,
} as const;

// TODO add variants that can be processed correctly
export const enum HotkeyCode {
Y = 89,
Z = 90,
}
export const HotkeyCode = {
Y: 89,
Z: 90,
} as const;

/**
* Checks if the passed keyboard event match the required hotkey.
*
* We intentionally use legacy {@link KeyboardEvent#keyCode `keyCode`} property. It is more
* "keyboard-layout"-independent than {@link KeyboardEvent#key `key`} or {@link KeyboardEvent#code `code`} properties.
*
* @example
* input.addEventListener('keydown', (event) => {
* if (isHotkey(event, HotkeyModifier.CTRL | HotkeyModifier.SHIFT, HotkeyCode.Z)) {
* // redo hotkey pressed
* }
* })
*
* @see {@link https://github.com/taiga-family/maskito/issues/315 `KeyboardEvent#code` issue}
*
* @return will return `true` only if the {@link HotkeyCode} matches and only the necessary
* {@link HotkeyModifier modifiers} have been pressed
*/
export function isHotkey(
event: KeyboardEvent,
modifiers: HotkeyModifier,
hotkeyCode: HotkeyCode,
modifiers: (typeof HotkeyModifier)[keyof typeof HotkeyModifier],
hotkeyCode: (typeof HotkeyCode)[keyof typeof HotkeyCode],
): boolean {
return (
event.ctrlKey === !!(modifiers & HotkeyModifier.CTRL) &&
event.altKey === !!(modifiers & HotkeyModifier.ALT) &&
event.shiftKey === !!(modifiers & HotkeyModifier.SHIFT) &&
event.metaKey === !!(modifiers & HotkeyModifier.META) &&
/**
* We intentionally use legacy {@link KeyboardEvent#keyCode `keyCode`} property. It is more
* "keyboard-layout"-independent than {@link KeyboardEvent#key `key`} or {@link KeyboardEvent#code `code`} properties.
* @see {@link https://github.com/taiga-family/maskito/issues/315 `KeyboardEvent#code` issue}
*/
// eslint-disable-next-line sonar/deprecation
event.keyCode === hotkeyCode
);
}
60 changes: 30 additions & 30 deletions projects/demo/src/app/constants/demo-path.ts
Original file line number Diff line number Diff line change
@@ -1,30 +1,30 @@
export const enum DemoPath {
WhatIsMaskito = 'getting-started/what-is-maskito',
MaskitoLibraries = 'getting-started/maskito-libraries',
CoreConceptsOverview = 'core-concepts/overview',
MaskExpression = 'core-concepts/mask-expression',
ElementState = 'core-concepts/element-state',
Processors = 'core-concepts/processors',
Plugins = 'core-concepts/plugins',
OverwriteMode = 'core-concepts/overwrite-mode',
Transformer = 'core-concepts/transformer',
Angular = 'frameworks/angular',
React = 'frameworks/react',
Vue = 'frameworks/vue',
Number = 'kit/number',
Time = 'kit/time',
Date = 'kit/date',
DateRange = 'kit/date-range',
DateTime = 'kit/date-time',
PhonePackage = 'addons/phone',
Card = 'recipes/card',
Phone = 'recipes/phone',
Textarea = 'recipes/textarea',
Prefix = 'recipes/prefix',
Postfix = 'recipes/postfix',
Placeholder = 'recipes/placeholder',
BrowserSupport = 'browser-support',
Changelog = 'changelog',
Stackblitz = 'stackblitz',
Cypress = 'cypress',
}
export const DemoPath = {
WhatIsMaskito: 'getting-started/what-is-maskito',
MaskitoLibraries: 'getting-started/maskito-libraries',
CoreConceptsOverview: 'core-concepts/overview',
MaskExpression: 'core-concepts/mask-expression',
ElementState: 'core-concepts/element-state',
Processors: 'core-concepts/processors',
Plugins: 'core-concepts/plugins',
OverwriteMode: 'core-concepts/overwrite-mode',
Transformer: 'core-concepts/transformer',
Angular: 'frameworks/angular',
React: 'frameworks/react',
Vue: 'frameworks/vue',
Number: 'kit/number',
Time: 'kit/time',
Date: 'kit/date',
DateRange: 'kit/date-range',
DateTime: 'kit/date-time',
PhonePackage: 'addons/phone',
Card: 'recipes/card',
Phone: 'recipes/phone',
Textarea: 'recipes/textarea',
Prefix: 'recipes/prefix',
Postfix: 'recipes/postfix',
Placeholder: 'recipes/placeholder',
BrowserSupport: 'browser-support',
Changelog: 'changelog',
Stackblitz: 'stackblitz',
Cypress: 'cypress',
} as const;
14 changes: 7 additions & 7 deletions projects/demo/src/app/constants/doc-example-primary-tab.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
export enum DocExamplePrimaryTab {
MaskitoOptions = 'mask',
JavaScript = 'JavaScript',
Angular = 'Angular',
React = 'React',
Vue = 'Vue',
}
export const DocExamplePrimaryTab = {
MaskitoOptions: 'mask',
JavaScript: 'JavaScript',
Angular: 'Angular',
React: 'React',
Vue: 'Vue',
} as const;
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import {ChangeDetectionStrategy, Component} from '@angular/core';
import {DemoPath} from '@demo/constants';
import {RawLoaderContent} from '@taiga-ui/addon-doc';
import {TuiRawLoaderContent} from '@taiga-ui/addon-doc';

const DROP_TS_NO_CHECK_REG = /\/\/\s@ts-nocheck[^\n]+\n/;

Expand All @@ -15,7 +15,7 @@ export class ReactDocPageComponent {
'./examples/1-use-maskito-basic-usage/use-maskito-basic-usage.tsx?raw'
);

readonly elementPredicateExample: Record<string, RawLoaderContent> = {
readonly elementPredicateExample: Record<string, TuiRawLoaderContent> = {
'index.tsx': import('./examples/2-element-predicate/index.tsx?raw').then(m => ({
// See: https://github.com/vuejs/core/issues/1033#issuecomment-1340309622
// TODO: Check if it still required after upgrade Vue to 3.4 (https://github.com/vuejs/core/pull/7958)
Expand Down