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

Fix linting warnings + add pre-commit hook #572

Merged
merged 2 commits into from
Aug 25, 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
4 changes: 4 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,10 @@ module.exports = {
format: ['PascalCase'],
custom: { regex: '^I[A-Z]', match: false },
},
{
selector: ['classProperty', 'objectLiteralProperty', 'typeProperty'], // могут быть какими угодно
format: null,
},
],
'@typescript-eslint/interface-name-prefix': 'off',
'@typescript-eslint/no-empty-interface': 'off',
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/publish_dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:
with:
node-version: 18
registry-url: 'https://registry.npmjs.org'
- run: yarn
- run: yarn install --frozen-lockfile --ignore-scripts
- name: Assigning new version
run: npm version prerelease --commit-hooks=false --git-tag-version=false --preid=dev-${GITHUB_SHA:0:6}
- name: Publishing release
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/publish_docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ jobs:
uses: actions/setup-node@v3
with:
node-version: 18
- run: yarn
- run: yarn install --frozen-lockfile --ignore-scripts
- run: npm run build

- name: Prepare tokens data
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/publish_from_git.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:
with:
node-version: 18
registry-url: 'https://registry.npmjs.org'
- run: yarn
- run: yarn install --frozen-lockfile --ignore-scripts
- name: Publishing release
run: npm run publish:dist
env:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/publish_release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ jobs:
node-version: 18
cache: 'npm'
registry-url: https://registry.npmjs.org/
- run: yarn
- run: yarn install --frozen-lockfile --ignore-scripts
- run: npm run publish:latest
if: '!github.event.release.prerelease'
env:
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:
- uses: actions/setup-node@v3
with:
node-version: '18'
- run: yarn
- run: yarn install --frozen-lockfile --ignore-scripts
- run: npm run lint
test:
runs-on: ubuntu-latest
Expand All @@ -23,7 +23,7 @@ jobs:
- uses: actions/setup-node@v3
with:
node-version: '18'
- run: yarn
- run: yarn install --frozen-lockfile --ignore-scripts
- run: npm run test:ci
build:
runs-on: ubuntu-latest
Expand All @@ -32,7 +32,7 @@ jobs:
- uses: actions/setup-node@v3
with:
node-version: '18'
- run: yarn
- run: yarn install --frozen-lockfile --ignore-scripts
- run: npm run build
- run: npm run docs:prepare-data
- run: npm run docs:build
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,4 @@ junit.xml
docs/src/**/*.d.ts
docs/public/**/*.json
docs/dist/
!.husky
4 changes: 4 additions & 0 deletions .husky/pre-commit
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/usr/bin/env sh
. "$(dirname -- "$0")/_/husky.sh"

yarn pre-commit
17 changes: 15 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,18 @@
"styleguide": "sh ./tasks/styleguide.sh",
"docs:dev": "cd docs/webpack && webpack-dev-server --config webpack.client.js --mode development",
"docs:build": "cd docs/webpack && webpack --config webpack.client.js --mode production",
"docs:prepare-data": "ts-node tasks/docs/prepareTokensData.ts"
"docs:prepare-data": "ts-node tasks/docs/prepareTokensData.ts",
"prepare": "husky install",
"pre-commit": "lint-staged"
},
"lint-staged": {
"*.{ts,tsx,js,jsx}": [
"prettier --write",
"eslint"
],
"*.{json,md}": [
"prettier --write"
]
},
"repository": "https://github.com/VKCOM/vkui-tokens.git",
"dependencies": {
Expand All @@ -39,8 +50,8 @@
"@types/common-tags": "1.8.1",
"@types/fs-extra": "11.0.1",
"@types/node": "18.11.10",
"@types/react-dom": "18.2.1",
"@types/react": "18.2.0",
"@types/react-dom": "18.2.1",
"@typescript-eslint/eslint-plugin": "4.33.0",
"@typescript-eslint/parser": "4.33.0",
"@vkontakte/appearance": "https://github.com/VKCOM/Appearance#v10.1.4",
Expand Down Expand Up @@ -70,8 +81,10 @@
"eslint-plugin-sonarjs": "0.19.0",
"fs-extra": "11.1.1",
"html-webpack-plugin": "5.5.1",
"husky": "8.0.3",
"jest": "29.5.0",
"jest-junit": "16.0.0",
"lint-staged": "14.0.1",
"lodash": "4.17.21",
"prettier": "2.8.8",
"react": "18.2.0",
Expand Down
4 changes: 2 additions & 2 deletions src/build/compilers/cssVars/helpers/getVarString.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@ export const getVarString = ({
valuesObject,
prefix,
delimeter = '\n',
callback,
callback: callbackFn,
}: GetVarStringParams): string => {
return Object.entries(valuesObject)
.map(([name, value]) => {
callback?.(name, value);
callbackFn?.(name, value);
return `${prefix}${name}: ${value};`;
})
.join(delimeter);
Expand Down
3 changes: 3 additions & 0 deletions src/build/compilers/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ function writeJsonFile<T = Theme>(themePath: string, theme: T, _?: ThemeBuildTyp
console.log(`успешно записали файл ${fileName}`);
}

// eslint-disable-next-line max-params
function writeTsFile<T extends SpecialTokens = Theme>(
themePath: string,
theme: T,
Expand Down Expand Up @@ -123,9 +124,11 @@ function writeStyleFiles<PT extends PixelifyTheme = PixelifyTheme>(
});
}

// eslint-disable-next-line max-params
function writeCssVarsSourceFile<PT extends PixelifyTheme = PixelifyTheme>(
themePath: string,
theme: PT,
// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
cssVarsTheme: any,
themeBase?: PT,
): void {
Expand Down
2 changes: 1 addition & 1 deletion src/build/compilers/styles/compileStyles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ export const compileStyles = <PT extends PixelifyTheme = PixelifyTheme>(
theme: PT,
mode: CompileStylesMode = 'default',
themeBase?: PT,
// eslint-disable-next-line sonarjs/cognitive-complexity
// eslint-disable-next-line sonarjs/cognitive-complexity, max-params
): string => {
const classicCssType = isClassicCssType(format);
const prefix = getPrefix(format, theme);
Expand Down
19 changes: 12 additions & 7 deletions src/build/compilers/styles/helpers/tokenRecognition.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,19 @@ import { ViewportsOrdered, ViewportsTuple } from '@/interfaces/general/tools/vie

const stringKeys = ['themeName', 'themeNameBase', 'themeInheritsFrom'];

export function isString(token: any, key: string): token is string {
export function isString(token: unknown, key: string): token is string {
return typeof token === 'string' && stringKeys.includes(key);
}

export function isColor(token: any): token is ColorWithStates {
export function isColor(token: unknown): token is ColorWithStates {
if (typeof token !== 'object') {
return false;
}

return token.normal !== undefined;
return (token as ColorWithStates).normal !== undefined;
}

export function isGroupToken(token: any): token is Record<string, any> {
export function isGroupToken(token: unknown): token is Record<string, any> {
if (typeof token !== 'object') {
return false;
}
Expand All @@ -30,12 +30,15 @@ export function isGroupToken(token: any): token is Record<string, any> {
return !isColor(token);
}

export function isAdaptiveFlatToken(token: any): token is Adaptive<any> {
export function isAdaptiveFlatToken(token: unknown): token is Adaptive<any> {
if (typeof token !== 'object') {
return false;
}

return token.regular !== undefined && typeof token.regular !== 'object';
return (
(token as Adaptive<any>).regular !== undefined &&
typeof (token as Adaptive<any>).regular !== 'object'
);
}

const allCustomMediaKeys = Object.keys(
Expand Down Expand Up @@ -69,6 +72,8 @@ const allCustomMediaKeys = Object.keys(
}),
);

export function isCustomMediaToken(key: any): key is CustomMediaByViewportUnion<ViewportsTuple> {
export function isCustomMediaToken(
key: unknown,
): key is CustomMediaByViewportUnion<ViewportsTuple> {
return typeof key === 'string' && allCustomMediaKeys.includes(key);
}
2 changes: 1 addition & 1 deletion src/build/helpers/getGradientPointsFromColor.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import color from 'color';
import { Property } from 'csstype';
import type { Property } from 'csstype';

import { GradientPoints } from '@/interfaces/general/gradients';

Expand Down
2 changes: 1 addition & 1 deletion src/build/themeProcessors/expandColors/expandColors.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Property } from 'csstype';
import type { Property } from 'csstype';

import { isColorDescriptionCallable, isColorWithStates } from '@/build/helpers/cssHelpers';
import { ColorsDescription, ColorsFinal } from '@/interfaces/general';
Expand Down
2 changes: 1 addition & 1 deletion src/build/themeProcessors/expandColors/mixColors.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { describe, expect, it } from '@jest/globals';
import { Property } from 'csstype';
import type { Property } from 'csstype';

import { mixColors } from './mixColors';

Expand Down
2 changes: 1 addition & 1 deletion src/build/themeProcessors/expandColors/mixColors.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import color from 'color';
import { Property } from 'csstype';
import type { Property } from 'csstype';

export const mixColors = (
colorArg: Property.Color,
Expand Down
2 changes: 1 addition & 1 deletion src/interfaces/general/animations/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Property } from 'csstype';
import type { Property } from 'csstype';

/**
* Переменные отвечающие за параметры анимаций
Expand Down
2 changes: 1 addition & 1 deletion src/interfaces/general/colors/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Property } from 'csstype';
import type { Property } from 'csstype';

import { ColorsDescription, ColorsScheme } from '@/interfaces/general';

Expand Down
2 changes: 1 addition & 1 deletion src/interfaces/general/elevation/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Property } from 'csstype';
import type { Property } from 'csstype';

export interface Elevation {
/**
Expand Down
8 changes: 4 additions & 4 deletions src/interfaces/general/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import { Property } from 'csstype';
import type { Property } from 'csstype';

import { StaticTokens, Tokens } from '@/interfaces/general/tools/tokenValue';

import { Animations } from './animations';
import { ColorDescription, Colors, ColorsDescriptionStruct } from './colors';
Expand All @@ -11,8 +13,6 @@ import { NamifyObject } from './tools/cssVars';
import { StringifyObject } from './tools/utils';
import { Fonts, TypographyBaseProps } from './typography';
import { ZIndex } from './zIndex';
import ColorScheme = Property.ColorScheme;
import { StaticTokens, Tokens } from '@/interfaces/general/tools/tokenValue';

interface AdaptiveInterfaceValues extends Sizes, Fonts {}

Expand Down Expand Up @@ -106,7 +106,7 @@ export type PixelifyTheme<T extends Partial<Record<keyof T, any>> = StaticTokens
Pick<T, Extract<'breakpoints', keyof T>> & {
themeType: 'pixelify';
themeName: string;
colorScheme: ColorScheme;
colorScheme: Property.ColorScheme;
};

/**
Expand Down
2 changes: 1 addition & 1 deletion src/interfaces/general/typography/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Property } from 'csstype';
import type { Property } from 'csstype';

type TLength = string | 0;

Expand Down
2 changes: 1 addition & 1 deletion src/interfaces/namespaces/paradigm/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Property } from 'csstype';
import type { Property } from 'csstype';

import { Theme, ThemeCssVars, ThemeCssVarsWide, ThemeDescription } from '@/interfaces/general';
import {
Expand Down
2 changes: 1 addition & 1 deletion src/interfaces/themes/calendar/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Property } from 'csstype';
import type { Property } from 'csstype';

import { ThemeCssVars } from '@/interfaces/general';
import {
Expand Down
2 changes: 1 addition & 1 deletion src/interfaces/themes/media/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Property } from 'csstype';
import type { Property } from 'csstype';

import { ColorDescription, ColorWithStates } from '@/interfaces/general/colors';
import { Adaptive } from '@/interfaces/general/tools';
Expand Down
2 changes: 1 addition & 1 deletion src/interfaces/themes/mycom/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Property } from 'csstype';
import type { Property } from 'csstype';

import { ColorWithStates } from '@/interfaces/general/colors';
import { ParadigmThemeCssVars } from '@/interfaces/namespaces/paradigm';
Expand Down
2 changes: 1 addition & 1 deletion src/interfaces/themes/octavius/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Property } from 'csstype';
import type { Property } from 'csstype';

import { ThemeCssVars } from '@/interfaces/general';
import {
Expand Down
2 changes: 1 addition & 1 deletion src/interfaces/themes/portalUI/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Property } from 'csstype';
import type { Property } from 'csstype';

import { ColorDescription, ColorWithStates } from '@/interfaces/general/colors';
import { GradientPoints } from '@/interfaces/general/gradients';
Expand Down
2 changes: 1 addition & 1 deletion src/interfaces/themes/promo/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Property } from 'csstype';
import type { Property } from 'csstype';

import { Adaptive } from '@/interfaces/general/tools';
import { ViewportsOrdered } from '@/interfaces/general/tools/viewports';
Expand Down
2 changes: 1 addition & 1 deletion src/interfaces/themes/pulse/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Property } from 'csstype';
import type { Property } from 'csstype';

import { ColorsDescription, ThemeCssVars, ThemeDescription } from '@/interfaces/general';
import { ColorDescription, ColorWithStates } from '@/interfaces/general/colors';
Expand Down
2 changes: 1 addition & 1 deletion src/interfaces/themes/search/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Property } from 'csstype';
import type { Property } from 'csstype';

import {
ColorDescription,
Expand Down
2 changes: 1 addition & 1 deletion src/themeDescriptions/base/paradigm.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Property } from 'csstype';
import type { Property } from 'csstype';

import { getGradientPointsFromColor } from '@/build/helpers/getGradientPointsFromColor';
import { alias, staticRef } from '@/build/helpers/tokenHelpers';
Expand Down
2 changes: 1 addition & 1 deletion src/themeDescriptions/base/vk.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Property } from 'csstype';
import type { Property } from 'csstype';

import { getGradientPointsFromColor } from '@/build/helpers/getGradientPointsFromColor';
import { alias } from '@/build/helpers/tokenHelpers';
Expand Down
2 changes: 1 addition & 1 deletion src/themeDescriptions/common/colors/projectColors.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Property } from 'csstype';
import type { Property } from 'csstype';

export type ProjectColors = {
colorPrimaryAuto: Property.Color;
Expand Down
2 changes: 1 addition & 1 deletion src/themeDescriptions/common/colors/socialColors.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Property } from 'csstype';
import type { Property } from 'csstype';

export type SocialColors = {
colorSocialVk: Property.Color;
Expand Down
2 changes: 1 addition & 1 deletion src/themeDescriptions/themes/calendar/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Property } from 'csstype';
import type { Property } from 'csstype';

import { ThemeCalendarDescription } from '@/interfaces/themes/calendar';
import { ThemeCalendarDarkDescription } from '@/interfaces/themes/calendarDark';
Expand Down
2 changes: 1 addition & 1 deletion src/themeDescriptions/themes/calls/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Property } from 'csstype';
import type { Property } from 'csstype';

import { ThemeCallsDescription } from '@/interfaces/themes/calls';

Expand Down
2 changes: 1 addition & 1 deletion src/themeDescriptions/themes/cloud/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Property } from 'csstype';
import type { Property } from 'csstype';

import { staticRef } from '@/build/helpers/tokenHelpers';
import { Font } from '@/interfaces/general/typography';
Expand Down
2 changes: 1 addition & 1 deletion src/themeDescriptions/themes/pulse/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Property } from 'csstype';
import type { Property } from 'csstype';

import {
AllowedParadigmColorDescriptions,
Expand Down
Loading