Skip to content

Commit

Permalink
Swap eslint with biome (#3678)
Browse files Browse the repository at this point in the history
  • Loading branch information
joshwooding authored Jul 9, 2024
1 parent 8b43adf commit 9d6919d
Show file tree
Hide file tree
Showing 2,350 changed files with 12,702 additions and 13,378 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ jobs:
- name: Lint
# Continue on error so, we can see lint issues but not fail the build, we should fix them incrementally
continue-on-error: true
run: yarn run lint:ci
run: yarn biome ci --reporter=github
- name: Prettier
run: yarn run prettier:ci
- name: Stylelint
Expand Down
21 changes: 13 additions & 8 deletions .prettierignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,24 @@ node_modules
# production
dist
site/build
site/.docusaurus
storybook-static
.next
.tmp

# Autogenerated CSS
/packages/ag-grid-theme/uitk-ag-theme.css
/packages/ag-grid-theme/salt-ag-theme.css
/docs/css/salt-core.css
/docs/css/salt-lab.css

/site/snapshots
/docs/public/mockServiceWorker.js

# Prettier doesn't support MDX v2 yet
site/docs/patterns/*.mdx

# Covered by biome
*.tsx
*.ts
*.mts
*.cts
*.js
*.jsx
*.mjs
*.cjs
*.json
*.jsonc
*.css
16 changes: 8 additions & 8 deletions .storybook/main.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { dirname, join } from "path";
import { dirname, join } from "node:path";
import type { StorybookConfig } from "@storybook/react-vite";
import type { UserConfig } from "vite";
import { cssVariableDocgen } from "css-variable-docgen-plugin";
import type { UserConfig } from "vite";
import { typescriptTurbosnap } from "vite-plugin-typescript-turbosnap";
import { cssInline } from "../tooling/css-inline-plugin";

Expand Down Expand Up @@ -36,10 +36,8 @@ const config: StorybookConfig = {
plugins: [cssInline(), cssVariableDocgen()],
};

if (configType === "PRODUCTION") {
customConfig.plugins!.push(
typescriptTurbosnap({ rootDir: config.root! })
);
if (configType === "PRODUCTION" && config.root) {
customConfig.plugins?.push(typescriptTurbosnap({ rootDir: config.root }));
}

return mergeConfig(customConfig, config);
Expand All @@ -48,6 +46,8 @@ const config: StorybookConfig = {

module.exports = config;

function getAbsolutePath(value: string): any {
return dirname(require.resolve(join(value, "package.json")));
function getAbsolutePath<Value>(value: string): Value {
return dirname(
require.resolve(join(value, "package.json")),
) as unknown as Value;
}
14 changes: 7 additions & 7 deletions .storybook/preview.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { Parameters, GlobalTypes, ArgTypes } from "@storybook/types";
import type { ArgTypes, GlobalTypes, Parameters } from "@storybook/types";
import "@salt-ds/theme/index.css";
import "@salt-ds/theme/css/theme-next.css";
import "@fontsource/open-sans/300.css";
Expand All @@ -16,15 +16,15 @@ import "@fontsource/open-sans/800-italic.css";
import "@fontsource/pt-mono";
import "./styles.css";

import { ComponentProps } from "react";
import { withTheme } from "docs/decorators/withTheme";
import { withResponsiveWrapper } from "docs/decorators/withResponsiveWrapper";
import { WithTextSpacingWrapper } from "docs/decorators/withTextSpacingWrapper";
import { withScaffold } from "docs/decorators/withScaffold";
import { withDateMock } from "docs/decorators/withDateMock";
import { SaltProvider, UNSTABLE_SaltProviderNext } from "@salt-ds/core";
import { DocsContainer } from "@storybook/addon-docs";
import { withDateMock } from "docs/decorators/withDateMock";
import { withResponsiveWrapper } from "docs/decorators/withResponsiveWrapper";
import { withScaffold } from "docs/decorators/withScaffold";
import { WithTextSpacingWrapper } from "docs/decorators/withTextSpacingWrapper";
import { withTheme } from "docs/decorators/withTheme";
import { initialize, mswLoader } from "msw-storybook-addon";
import type { ComponentProps } from "react";

import { globalOptions as themeNextGlobals } from "./toolbar/ThemeNextToolbar";

Expand Down
15 changes: 6 additions & 9 deletions .storybook/toolbar/ThemeNextToolbar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {
import { BeakerIcon, CheckIcon } from "@storybook/icons";
import { useGlobals } from "@storybook/manager-api";
import { clsx } from "clsx";
import React, { AnchorHTMLAttributes } from "react";
import React, { type AnchorHTMLAttributes } from "react";

import "./ThemeNextToolbar.css";

Expand Down Expand Up @@ -60,10 +60,9 @@ const GroupWrapper = ({
children,
}: AnchorHTMLAttributes<HTMLAnchorElement>) => {
return (
<div
className={clsx(className, "theme-next-toolbar-group-wrapper")}
children={children}
/>
<div className={clsx(className, "theme-next-toolbar-group-wrapper")}>
{children}
</div>
);
};

Expand All @@ -81,9 +80,7 @@ export const ThemeNextToolbar = ({ active }: { active?: boolean }) => {
},
...globalOptions[globalKey].items.map((value) => {
const disabled =
globalKey === "themeNext"
? false
: globals["themeNext"] !== "enable";
globalKey === "themeNext" ? false : globals.themeNext !== "enable";
const active = globals[globalKey] === value;

return {
Expand All @@ -100,7 +97,7 @@ export const ThemeNextToolbar = ({ active }: { active?: boolean }) => {
};
}),
];
}
},
);

return (
Expand Down
153 changes: 153 additions & 0 deletions biome.jsonc
Original file line number Diff line number Diff line change
@@ -0,0 +1,153 @@
{
"$schema": "https://biomejs.dev/schemas/1.8.0/schema.json",
"vcs": {
"enabled": true,
"clientKind": "git",
"useIgnoreFile": true,
"defaultBranch": "main"
},
"files": {
"ignore": [".next", "mockServiceWorker.js", "*-props.json", ".tmp"]
},
"organizeImports": {
"enabled": true
},
"formatter": {
"enabled": true,
"indentStyle": "space"
},
"linter": {
"enabled": true,
"rules": {
"recommended": true,
"style": {
// Changed to warn because we have a lot of non-null assertions.
"noNonNullAssertion": "warn"
},
"complexity": {
// Changed to warn because it is useful to keep this in mind, but it doesn't need to be a strict requirement.
"noForEach": "warn"
},
"a11y": {
// Disabled because autofocus is necessary in some cases.
"noAutofocus": "off",
// Disabled because we write a lot of custom components.
"noNoninteractiveElementToInteractiveRole": "off",
"noNoninteractiveTabindex": "off",
// Disabled until biome doesn't flag hidden SVGs.
"noSvgWithoutTitle": "off",
// Changed to warn because biome has some false positives.
"useAriaPropsForRole": "warn"
},
"correctness": {
"useExhaustiveDependencies": {
"level": "warn",
"options": {
"hooks": [
{
"name": "useIsomorphicLayoutEffect",
"closureIndex": 0,
"dependenciesIndex": 1
},
{
"name": "useControlled",
"stableResult": [1]
}
]
}
}
},
"suspicious": {
// Changed to warn because it is useful to keep this in mind, but it doesn't need to be a strict requirement.
"noArrayIndexKey": "warn",
// Changed to warn because it is useful to keep this in mind, but it doesn't need to be a strict requirement.
"noExplicitAny": "warn"
}
}
},
"css": {
"formatter": {
"enabled": true,
"lineWidth": 200
},
"linter": {
"enabled": true
},
"parser": {
"cssModules": true
}
},
"overrides": [
{
// Disable some rules for tests and stories, because they are not production code.
"include": ["__tests__/**", "stories/**"],
"linter": {
"rules": {
"a11y": {
"useButtonType": "off"
},
"complexity": {
"noForEach": "off"
},
"suspicious": {
"noImplicitAnyLet": "off"
}
}
}
},
{
// Disable some rules for legacy code, because it is not worth fixing.
"include": [
"lab/src/responsive/**",
"packages/data-grid/**",
"lab/src/common-hooks/**"
],
"linter": {
"rules": {
"style": {
"noParameterAssign": "off"
},
"suspicious": {
"noAssignInExpressions": "off"
}
}
}
},
{
// Disable noExplicitAny for utils, because any is useful in some cases.
"include": ["utils/**"],
"linter": {
"rules": {
"suspicious": {
"noExplicitAny": "off"
}
}
}
},
{
// Disable noArrayIndexKey for layout examples because array indexes are useful in this case.
"include": [
"packages/*/stories/*-layout/**",
"site/src/examples/*-layout/**"
],
"linter": {
"rules": {
"suspicious": {
"noArrayIndexKey": "off"
}
}
}
},
{
// Disable noShadowRestrictedNames for examples and stories because it is useful to shadow restricted names for example names.
"include": ["site/src/examples/**", "packages/*/stories/**"],
"linter": {
"rules": {
"suspicious": {
"noShadowRestrictedNames": "off"
}
}
}
}
]
}
18 changes: 9 additions & 9 deletions cypress.config.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import { defineConfig } from "cypress";
import react from "@vitejs/plugin-react";
import tsconfigPaths from "vite-tsconfig-paths";
import IstanbulPlugin from "vite-plugin-istanbul";
import { isCI } from "ci-info";
import path from "path";
import { UserConfig } from "vite";
import { version as reactVersion } from "react";
import path from "node:path";
// @ts-ignore
import installCoverageTask from "@cypress/code-coverage/task";
import react from "@vitejs/plugin-react";
import { isCI } from "ci-info";
import { cssInline } from "css-inline-plugin";
import { defineConfig } from "cypress";
import { version as reactVersion } from "react";
import type { UserConfig } from "vite";
import IstanbulPlugin from "vite-plugin-istanbul";
import tsconfigPaths from "vite-tsconfig-paths";

async function getViteConfig(config: UserConfig) {
const { mergeConfig } = await import("vite");
Expand Down Expand Up @@ -52,7 +52,7 @@ async function getViteConfig(config: UserConfig) {
"@salt-ds/core": path.resolve(__dirname, "./dist/salt-ds-core"),
"@salt-ds/data-grid": path.resolve(
__dirname,
"./dist/salt-ds-data-grid"
"./dist/salt-ds-data-grid",
),
"@salt-ds/lab": path.resolve(__dirname, "./dist/salt-ds-lab"),
"@salt-ds/icons": path.resolve(__dirname, "./dist/salt-ds-icons"),
Expand Down
8 changes: 4 additions & 4 deletions cypress/support/AnnouncementListener.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { useRef, useEffect } from "react";
import { useEffect, useRef } from "react";

const positiveLookUp = [
'[aria-live="polite"]',
Expand All @@ -14,7 +14,7 @@ const walkTheDOM = (node: Element, handler: (node: Element) => void) => {
if (node.nodeType === 1) {
handler(node);
if (node.children.length) {
for (let childNode of node.children) {
for (const childNode of node.children) {
walkTheDOM(childNode, handler);
}
}
Expand All @@ -26,9 +26,9 @@ export function AnnouncementListener(props: {
}) {
const { onAnnouncement } = props;
const handleAnnouncement: MutationCallback = (mutations) => {
for (let mutation of mutations) {
for (const mutation of mutations) {
if (mutation.type !== "attributes") {
let regionNode = mutation.target as HTMLElement;
const regionNode = mutation.target as HTMLElement;
// if (regionNode.innerText) {
onAnnouncement?.(regionNode.innerText);
// }
Expand Down
Loading

0 comments on commit 9d6919d

Please sign in to comment.