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: linting fixes #261

Merged
merged 6 commits into from
Dec 3, 2024
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: 1 addition & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* eslint-disable import/unambiguous */
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

disabled a rule to make our eslintrc file more readable

Before

Screenshot 2024-12-03 at 2 20 32 PM

After

Screenshot 2024-12-03 at 2 20 51 PM

module.exports = {
root: true,
extends: ['@metamask/eslint-config', '@metamask/eslint-config-nodejs'],
Expand Down
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,11 @@
"create-component:react": "yarn workspace @metamask/design-system-react create-component",
"create-package": "ts-node scripts/create-package",
"lint": "yarn lint:eslint && yarn lint:misc --check && yarn constraints && yarn lint:dependencies",
"lint:clear-cache": "rimraf .eslintcache",
"lint:dependencies": "depcheck && yarn dedupe --check",
"lint:dependencies:fix": "depcheck && yarn dedupe",
"lint:eslint": "eslint . --cache --ext js,cjs,mjs,ts",
"lint:fix": "yarn lint:eslint --fix && yarn lint:misc --write && yarn constraints --fix && yarn lint:dependencies:fix",
"lint:eslint": "eslint . --cache --ext js,cjs,mjs,ts,tsx",
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added .tsx extension to ESLint configuration to ensure React TypeScript components are properly linted. This helps maintain consistent code quality across both JavaScript and TypeScript React and React Native files in our codebase.

"lint:fix": "yarn lint:clear-cache && yarn lint:eslint --fix && yarn lint:misc --write && yarn constraints --fix && yarn lint:dependencies:fix",
"lint:misc": "prettier '**/*.json' '**/*.md' '!**/CHANGELOG.old.md' '**/*.yml' '!.yarnrc.yml' '!merged-packages/**' --ignore-path .prettierignore",
"prepack": "./scripts/prepack.sh",
"prepare-preview-builds": "./scripts/prepare-preview-builds.sh",
Expand Down
19 changes: 19 additions & 0 deletions packages/design-system-react/.eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
module.exports = {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added .eslintrc.js to support browser environment in React package

This ESLint configuration extends the root config but adds browser-specific settings. The root ESLint config is Node.js-focused, so this configuration:

  • Enables browser environment
  • Disables Node.js environment
  • Turns off no-restricted-globals rule to allow browser globals
  • Adds TypeScript configuration for .ts/.tsx files

extends: ['../../.eslintrc.js'],
env: {
browser: true,
node: false,
},
rules: {
'no-restricted-globals': 'off',
},
overrides: [
{
files: ['**/*.{ts,tsx}'],
parserOptions: {
tsconfigRootDir: __dirname,
project: ['./tsconfig.json'],
},
},
],
};
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React from 'react';
import type { Meta, StoryObj } from '@storybook/react';

import { ComponentName } from './ComponentName';
import README from './README.mdx';

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React from 'react';
import { render, screen } from '@testing-library/react';
import React from 'react';

import { ComponentName } from './ComponentName';
import '@testing-library/jest-dom';

describe('ComponentName Component', () => {
it('renders children correctly', () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import React from 'react';

import { twMerge } from '../../utils/tw-merge';
import { ComponentNameProps } from './ComponentName.types';
import type { ComponentNameProps } from './ComponentName.types';

export const ComponentName: React.FC<ComponentNameProps> = ({
children,
Expand Down

This file was deleted.

This file was deleted.

16 changes: 0 additions & 16 deletions packages/design-system-react/src/components/button/Button.tsx

This file was deleted.

2 changes: 0 additions & 2 deletions packages/design-system-react/src/components/button/index.ts

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import React, { useState } from 'react';
import type { StoryObj } from '@storybook/react';
import React, { useState } from 'react';

import { Icon } from './Icon';
import { IconName, IconSize, IconColor } from './Icon.types';
import README from './README.mdx';
Expand Down
20 changes: 12 additions & 8 deletions packages/design-system-react/src/components/icon/Icon.test.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import React from 'react';
import { render, screen } from '@testing-library/react';
import React from 'react';

import { Icon } from './Icon';
import { IconName, IconSize, IconColor } from './Icon.types';
import { ICON_SIZE_CLASS_MAP } from './Icon.constants';
import { IconName, IconSize, IconColor } from './Icon.types';
import type { IconProps } from './Icon.types';

describe('Icon', () => {
it('should render correctly', () => {
Expand All @@ -21,7 +23,7 @@ describe('Icon', () => {
data-testid={`icon-${size}`}
/>,
);
const icon = container.firstChild as HTMLElement;
const icon = container.firstChild;
expect(icon).toHaveClass('inline-block');
expect(icon).toHaveClass(ICON_SIZE_CLASS_MAP[size]);
});
Expand All @@ -36,7 +38,7 @@ describe('Icon', () => {
data-testid={`icon-${color}`}
/>,
);
const icon = container.firstChild as HTMLElement;
const icon = container.firstChild;
expect(icon).toHaveClass('inline-block');
expect(icon).toHaveClass(color);
});
Expand All @@ -46,14 +48,14 @@ describe('Icon', () => {
const { container } = render(
<Icon name={IconName.AddSquare} className="custom-class" />,
);
const icon = container.firstChild as HTMLElement;
const icon = container.firstChild;
expect(icon).toHaveClass('inline-block');
expect(icon).toHaveClass('custom-class');
});

it('should have correct SVG attributes', () => {
const { container } = render(<Icon name={IconName.AddSquare} />);
const svg = container.firstChild as SVGElement;
const svg = container.firstChild;

expect(svg).toHaveAttribute('xmlns', 'http://www.w3.org/2000/svg');
expect(svg).toHaveAttribute('viewBox', '0 0 512 512');
Expand All @@ -65,7 +67,7 @@ describe('Icon', () => {
const { container } = render(
<Icon name={IconName.AddSquare} style={customStyle} />,
);
const icon = container.firstChild as HTMLElement;
const icon = container.firstChild;
expect(icon).toHaveStyle(customStyle);
});
});
Expand All @@ -86,7 +88,9 @@ describe('Icon error cases', () => {
});

it('should warn and return null when name prop is missing', () => {
const { container } = render(<Icon {...({} as any)} />);
const { container } = render(
<Icon {...({ name: undefined } as unknown as IconProps)} />,
);
expect(consoleSpy).toHaveBeenCalledWith('Icon name is required');
expect(container.firstChild).toBeNull();
});
Expand Down
3 changes: 2 additions & 1 deletion packages/design-system-react/src/components/icon/Icon.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import React from 'react';

import { twMerge } from '../../utils/tw-merge';
import { ICON_SIZE_CLASS_MAP } from './Icon.constants';
import { IconSize, IconColor } from './Icon.types';
import type { IconProps } from './Icon.types';
import { ICON_SIZE_CLASS_MAP } from './Icon.constants';

export const Icon: React.FC<IconProps> = ({
name,
Expand Down
3 changes: 0 additions & 3 deletions packages/design-system-react/src/components/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,6 @@ export {
} from './text';
export type { TextProps } from './text';

export { Button } from './button';
export type { ButtonProps } from './button';

export { Icon } from './icon';
export { IconName, IconSize, IconColor } from './icon';
export type { IconProps } from './icon';
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import React from 'react';
import type { Meta, StoryObj } from '@storybook/react';
import { action } from '@storybook/addon-actions';
import React from 'react';

import README from './README.mdx';
import { Text } from './Text';
import {
TextVariant,
Expand All @@ -11,7 +12,7 @@ import {
OverflowWrap,
TextColor,
} from './Text.types';
import README from './README.mdx';

const meta: Meta<typeof Text> = {
title: 'React Components/Text',
component: Text,
Expand Down Expand Up @@ -167,7 +168,13 @@ export const AsChild: Story = {
<span>Text rendered as span</span>
</Text>
<Text asChild className="block">
<button type="button" onClick={action('button-clicked')}>
<button
type="button"
onClick={() => {
// eslint-disable-next-line no-alert, no-restricted-globals
alert('button-clicked');
}}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was previously using storybook-actions but once we add it as a dev dependency it clashes with the @storybook/addon-actions version we can fix it in a subsequent PR

>
Text rendered as button
</button>
</Text>
Expand Down
6 changes: 4 additions & 2 deletions packages/design-system-react/src/components/text/Text.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import React from 'react';
import { Slot } from '@radix-ui/react-slot';
import React from 'react';

import { twMerge } from '../../utils/tw-merge';
import { TextVariant, TextProps, TextColor } from './Text.types';
import { TEXT_CLASS_MAP, TEXT_DEFAULT_TAG_MAP } from './Text.constants';
import type { TextProps } from './Text.types';
import { TextVariant, TextColor } from './Text.types';

export const Text: React.FC<TextProps> = ({
variant = TextVariant.BodyMd,
Expand Down
2 changes: 1 addition & 1 deletion packages/design-system-react/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,5 @@
"lib": ["ES2020", "DOM"]
},
"references": [],
"include": ["./src", "./src/**/*.d.ts", "scripts/**/*"]
"include": ["./src", "./src/**/*.d.ts", "scripts/**/*", "jest.setup.ts"]
}
1 change: 1 addition & 0 deletions packages/design-tokens/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
"devDependencies": {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Adding missing dev dependency

"@metamask/auto-changelog": "^3.4.4",
"@metamask/design-system-react": "workspace:^",
"@storybook/react": "^8.3.5",
"@ts-bridge/cli": "^0.5.1",
"@types/jest": "^27.4.1",
"@types/node": "^16.18.54",
Expand Down
7 changes: 4 additions & 3 deletions packages/design-tokens/stories/BrandColors.stories.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
import React from 'react';
import type { Meta, StoryObj } from '@storybook/react';
import React from 'react';

import { brandColor as brandColorJS } from '../src/js';
import README from './BrandColors.mdx';
import { ColorSwatchGroup, ColorSwatch } from './components';
import {
getCSSVariablesFromStylesheet,
getContrastYIQ,
useJsonColor,
} from './test-utils';
import { ColorSwatchGroup, ColorSwatch } from './components';
import README from './BrandColors.mdx';

const meta: Meta<typeof ColorSwatchGroup> = {
title: 'Design Tokens/Color/Brand Colors',
Expand Down
9 changes: 5 additions & 4 deletions packages/design-tokens/stories/Shadows.stories.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
import React from 'react';
import type { Meta, StoryObj } from '@storybook/react';
import { Text, TextColor } from '@metamask/design-system-react';
import type { Meta, StoryObj } from '@storybook/react';
import React from 'react';

import README from './Shadows.mdx';

interface ShadowSwatchProps {
type ShadowSwatchProps = {
children: React.ReactNode;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use type instead of interface

className?: string;
}
};

const ShadowSwatch: React.FC<ShadowSwatchProps> = ({
children,
Expand Down
8 changes: 5 additions & 3 deletions packages/design-tokens/stories/ThemeColors.stories.tsx
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
import React from 'react';
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lint fixes


import { lightTheme as lightThemeJS, darkTheme as darkThemeJS } from '../src';
import brandColor from '../src/figma/brandColors.json';
import { ColorSwatch, ColorSwatchGroup } from './components';
import README from './ThemeColors.mdx';
import {
getCSSVariablesFromStylesheet,
getContrastYIQ,
getJSColors,
useJsonColor,
} from './test-utils';
import README from './ThemeColors.mdx';

export default {
const meta = {
title: 'Design Tokens/Color/Theme Colors',
component: ColorSwatchGroup,
parameters: {
Expand All @@ -20,6 +20,8 @@ export default {
},
};

export default meta;

export const FigmaLightTheme = {
render: () => {
const { lightTheme } = useJsonColor();
Expand Down
19 changes: 10 additions & 9 deletions packages/design-tokens/stories/Typography.stories.tsx
Original file line number Diff line number Diff line change
@@ -1,26 +1,27 @@
/* eslint-disable no-restricted-globals */
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lint fixes and ignoring no-restriced-globals so we can get the CSS variables from the stylesheet for typography CSS variables


import { Text } from '@metamask/design-system-react';
import type { StoryFn, Meta } from '@storybook/react';
import React from 'react';
import { StoryFn, Meta } from '@storybook/react';
import { typography } from '../src/js/typography';

import { fontSizes } from '../src/js/typography/fontSizes';
import { lineHeights } from '../src/js/typography/lineHeights';
import { typography } from '../src/js/typography';
import { fontFamilies } from '../src/js/typography/fontFamilies';
import { fontSizes } from '../src/js/typography/fontSizes';
import { fontWeights } from '../src/js/typography/fontWeights';
import { letterSpacing } from '../src/js/typography/letterSpacing';

import { Text } from '@metamask/design-system-react';

import { lineHeights } from '../src/js/typography/lineHeights';
import README from './Typography.mdx';

export default {
const meta: Meta<typeof Text> = {
title: 'Design Tokens/Typography/Typography',
parameters: {
docs: {
page: README,
},
},
} as Meta<typeof Text>;
};

export default meta;
export const FontFamily: StoryFn<typeof Text> = (...args) => {
const styles = {
displayMD: {
Expand Down
Loading
Loading