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: eslint sort import #10

Merged
merged 3 commits into from
Mar 1, 2025
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
17 changes: 17 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# EditorConfig helps developers define and maintain consistent
# coding styles between different editors and IDEs
# editorconfig.org

root = true

[*]

indent_style = space
indent_size = 2

end_of_line = lf
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true

max_line_length = 100
12 changes: 9 additions & 3 deletions .github/ISSUE_TEMPLATE/bug.md
Original file line number Diff line number Diff line change
@@ -1,22 +1,28 @@
## Bug Description

[Concise description of the bug]

## Steps to Reproduce
1.
2.
3.

1.
2.
3.

## Expected Behavior

[What you expected to happen]

## Actual Behavior

[What actually happened]

## Environment

- Library version:
- Node.js version:
- Browser (if applicable):
- OS:

## Additional Context

[Any other relevant information, screenshots, etc.]
7 changes: 6 additions & 1 deletion .github/ISSUE_TEMPLATE/feature_request.md
Original file line number Diff line number Diff line change
@@ -1,14 +1,19 @@
## Feature Description

[Concise description of the proposed feature]

## Problem It Solves

[Explain the problem this feature would solve]

## Proposed Solution

[Your ideas on how to implement the feature]

## Alternatives Considered

[Any alternative solutions or features you've considered]

## Additional Context
[Any other relevant information, mockups, etc.]

[Any other relevant information, mockups, etc.]
5 changes: 5 additions & 0 deletions .github/pull_request_template.md
Original file line number Diff line number Diff line change
@@ -1,17 +1,21 @@
## Summary

[Provide a brief description of the changes in this PR]

## Type of change

- [ ] Bug fix
- [ ] New feature
- [ ] Breaking change
- [ ] Documentation update
- [ ] Other (specify below)

## How Has This Been Tested?

[Describe the tests you ran to verify your changes]

## Checklist:

- [ ] Code follows style guidelines
- [ ] Self-review completed
- [ ] Code commented where necessary
Expand All @@ -22,4 +26,5 @@
- [ ] Dependent changes merged

## Additional Notes:

[Add any additional information or context about the PR here]
2 changes: 1 addition & 1 deletion .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- name: Setup deps
uses: ./.github/actions/setup

Expand Down
69 changes: 45 additions & 24 deletions eslint.config.js
Original file line number Diff line number Diff line change
@@ -1,29 +1,50 @@
import eslint from '@eslint/js';
import tseslint from 'typescript-eslint';
import eslint from "@eslint/js";
import tseslint from "typescript-eslint";
import simpleImportSort from "eslint-plugin-simple-import-sort";

export default tseslint.config(
eslint.configs.recommended,
...tseslint.configs.strictTypeChecked,
{
files: ['src/**/*.{ts,tsx}'],
languageOptions: {
parserOptions: {
projectService: true,
tsconfigRootDir: import.meta.dirname,
},
},
eslint.configs.recommended,
...tseslint.configs.strictTypeChecked,
{
files: ["src/**/*.{ts,tsx}"],
languageOptions: {
parserOptions: {
projectService: true,
tsconfigRootDir: import.meta.dirname,
},
},
{
rules: {
'@typescript-eslint/no-unused-vars': ['error', {
'argsIgnorePattern': '^_',
'varsIgnorePattern': '^_',
'caughtErrorsIgnorePattern': '^_'
}],
},
},
{
plugins: {
"simple-import-sort": simpleImportSort,
},
{

ignores: ['node_modules/**', 'dist/**', "*.config.{js,ts}", "react-native.js", "react-native.d.ts"],
rules: {
"@typescript-eslint/no-unused-vars": [
"error",
{
argsIgnorePattern: "^_",
varsIgnorePattern: "^_",
caughtErrorsIgnorePattern: "^_",
},
],
"@typescript-eslint/consistent-type-imports": ["error", {
fixStyle: "separate-type-imports",
}],
"simple-import-sort/imports": [
"error",
{
groups: [["^\\u0000", "^node:", "^@?\\w", "^"], ["^\\."]],
},
],
},
);
},
{
ignores: [
"node_modules/**",
"dist/**",
"*.config.{js,ts}",
"react-native.js",
"react-native.d.ts",
],
},
);
10 changes: 5 additions & 5 deletions jest.config.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
export default {
preset: 'ts-jest',
testEnvironment: 'node',
testMatch: ['**/__tests__/**/*.ts?(x)', '**/?(*.)+(spec|test).ts?(x)'],
moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx', 'json', 'node'],
};
preset: "ts-jest",
testEnvironment: "node",
testMatch: ["**/__tests__/**/*.ts?(x)", "**/?(*.)+(spec|test).ts?(x)"],
moduleFileExtensions: ["ts", "tsx", "js", "jsx", "json", "node"],
};
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,9 @@
"@types/react": "^19.0.10",
"@types/react-reconciler": "^0.28.9",
"eslint": "^9.21.0",
"eslint-plugin-simple-import-sort": "^12.1.1",
"jest": "^29.7.0",
"prettier": "^3.5.2",
"react": "^19.0.0",
"release-it": "^18.1.2",
"ts-jest": "^29.2.6",
Expand Down
22 changes: 22 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

19 changes: 11 additions & 8 deletions src/__tests__/renderer.test.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import { act, createElement, ReactElement } from "react";
import { expect, test } from "@jest/globals";
import { createRoot, RootOptions } from "../renderer";
import type { ReactElement } from "react";
import { act, createElement } from "react";

import type { RootOptions } from "../renderer";
import { createRoot } from "../renderer";

const originalConsoleError = console.error;

Expand Down Expand Up @@ -43,7 +46,7 @@ test("render with single allowed text component", () => {
<div>
<hr />
</div>,
{ textComponents: ["Text"] }
{ textComponents: ["Text"] },
);
expect(renderer.root?.toJSON()).toMatchInlineSnapshot(`
<div>
Expand All @@ -56,7 +59,7 @@ test("render with single allowed text component", () => {
renderer.render(<div>Hello!</div>);
});
}).toThrowErrorMatchingInlineSnapshot(
`"Invariant Violation: Text strings must be rendered within a <Text> component. Detected attempt to render "Hello!" string within a <div> component."`
`"Invariant Violation: Text strings must be rendered within a <Text> component. Detected attempt to render "Hello!" string within a <div> component."`,
);
});

Expand All @@ -66,7 +69,7 @@ test("render with two allowed text components", () => {
{createElement("A", null, "Hello!")}
{createElement("B", null, "Hi!")}
</div>,
{ textComponents: ["A", "B"] }
{ textComponents: ["A", "B"] },
);
expect(renderer.root?.toJSON()).toMatchInlineSnapshot(`
<div>
Expand All @@ -84,7 +87,7 @@ test("render with two allowed text components", () => {
renderer.render(createElement("X", null, "Hello!"));
});
}).toThrowErrorMatchingInlineSnapshot(
`"Invariant Violation: Text strings must be rendered within a <A> or <B> component. Detected attempt to render "Hello!" string within a <X> component."`
`"Invariant Violation: Text strings must be rendered within a <A> or <B> component. Detected attempt to render "Hello!" string within a <X> component."`,
);
});

Expand All @@ -95,14 +98,14 @@ test("render with multiple allowed text components", () => {
{createElement("B", null, "Hi!")}
{createElement("C", null, "Hola!")}
</div>,
{ textComponents: ["A", "B", "C"] }
{ textComponents: ["A", "B", "C"] },
);

expect(() => {
act(() => {
renderer.render(createElement("X", null, "Hello!"));
});
}).toThrowErrorMatchingInlineSnapshot(
`"Invariant Violation: Text strings must be rendered within a <A>, <B>, or <C> component. Detected attempt to render "Hello!" string within a <X> component."`
`"Invariant Violation: Text strings must be rendered within a <A>, <B>, or <C> component. Detected attempt to render "Hello!" string within a <X> component."`,
);
});
14 changes: 5 additions & 9 deletions src/host-element.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,14 @@
import { CONTAINER_TYPE } from "./constants";
import { Container, Instance, TextInstance } from "./reconciler";
import { JsonNode, renderToJson } from "./render-to-json";
import type { Container, Instance, TextInstance } from "./reconciler";
import type { JsonNode} from "./render-to-json";
import { renderToJson } from "./render-to-json";

export type HostNode = HostElement | string;

// eslint-disable-next-line @typescript-eslint/no-explicit-any
export type HostElementProps = Record<string, any>;

const instanceToHostElementMap = new WeakMap<
Container | Instance,
HostElement
>();
const instanceToHostElementMap = new WeakMap<Container | Instance, HostElement>();

export class HostElement {
private instance: Instance | Container;
Expand All @@ -20,9 +18,7 @@ export class HostElement {
}

get type(): string {
return this.instance.tag === "INSTANCE"
? this.instance.type
: CONTAINER_TYPE;
return this.instance.tag === "INSTANCE" ? this.instance.type : CONTAINER_TYPE;
}

get props(): HostElementProps {
Expand Down
6 changes: 4 additions & 2 deletions src/platforms/react-native.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import { ReactElement } from "react";
import { createRoot, Root } from "../renderer";
import type { ReactElement } from "react";

import type { Root } from "../renderer";
import { createRoot } from "../renderer";

export type ReactNativeRootOptions = {
createNodeMock?: (element: ReactElement) => object;
Expand Down
Loading
Loading