initial commit
This commit is contained in:
@@ -0,0 +1,59 @@
|
|||||||
|
import type { RuleFunction } from "@eslint-react/kit";
|
||||||
|
import { type TSESTree, AST_NODE_TYPES } from "@typescript-eslint/types";
|
||||||
|
|
||||||
|
/** Enforce `import * as React from "react"` only. */
|
||||||
|
export function preferNamespaceImport(): RuleFunction {
|
||||||
|
return (context, { settings }) => {
|
||||||
|
const { importSource } = settings;
|
||||||
|
|
||||||
|
return {
|
||||||
|
[`ImportDeclaration[source.value="${importSource}"]`](
|
||||||
|
node: TSESTree.ImportDeclaration,
|
||||||
|
) {
|
||||||
|
const specifiers = node.specifiers;
|
||||||
|
|
||||||
|
// already valid
|
||||||
|
if (
|
||||||
|
specifiers.length === 1 &&
|
||||||
|
specifiers[0]?.type ===
|
||||||
|
AST_NODE_TYPES.ImportNamespaceSpecifier
|
||||||
|
) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// choose React identifier:
|
||||||
|
// import React from "react" -> React
|
||||||
|
// import { useState } -> React
|
||||||
|
// import Foo, { useState } -> Foo
|
||||||
|
const localName =
|
||||||
|
specifiers.find(
|
||||||
|
(s) =>
|
||||||
|
s.type === AST_NODE_TYPES.ImportDefaultSpecifier ||
|
||||||
|
s.type === AST_NODE_TYPES.ImportNamespaceSpecifier,
|
||||||
|
)?.local.name ?? "React";
|
||||||
|
|
||||||
|
context.report({
|
||||||
|
node,
|
||||||
|
data: { importSource },
|
||||||
|
message: `Prefer importing React only as 'import * as ${localName} from "${importSource}"'`,
|
||||||
|
|
||||||
|
fix(fixer) {
|
||||||
|
const original = context.sourceCode.getText(node);
|
||||||
|
const semi = original.endsWith(";") ? ";" : "";
|
||||||
|
const quote = node.source.raw.at(0) ?? "'";
|
||||||
|
const isTypeImport = node.importKind === "type";
|
||||||
|
|
||||||
|
return fixer.replaceText(
|
||||||
|
node,
|
||||||
|
[
|
||||||
|
`import${isTypeImport ? " type" : ""}`,
|
||||||
|
`* as ${localName}`,
|
||||||
|
`from ${quote}${importSource}${quote}${semi}`,
|
||||||
|
].join(" "),
|
||||||
|
);
|
||||||
|
},
|
||||||
|
});
|
||||||
|
},
|
||||||
|
};
|
||||||
|
};
|
||||||
|
}
|
||||||
+24
@@ -0,0 +1,24 @@
|
|||||||
|
# Logs
|
||||||
|
logs
|
||||||
|
*.log
|
||||||
|
npm-debug.log*
|
||||||
|
yarn-debug.log*
|
||||||
|
yarn-error.log*
|
||||||
|
pnpm-debug.log*
|
||||||
|
lerna-debug.log*
|
||||||
|
|
||||||
|
node_modules
|
||||||
|
dist
|
||||||
|
dist-ssr
|
||||||
|
*.local
|
||||||
|
|
||||||
|
# Editor directories and files
|
||||||
|
.vscode/*
|
||||||
|
!.vscode/extensions.json
|
||||||
|
.idea
|
||||||
|
.DS_Store
|
||||||
|
*.suo
|
||||||
|
*.ntvs*
|
||||||
|
*.njsproj
|
||||||
|
*.sln
|
||||||
|
*.sw?
|
||||||
@@ -0,0 +1,5 @@
|
|||||||
|
{
|
||||||
|
"useTabs": true,
|
||||||
|
"tabWidth": 4,
|
||||||
|
"printWidth": 70
|
||||||
|
}
|
||||||
@@ -0,0 +1,66 @@
|
|||||||
|
import js from "@eslint/js";
|
||||||
|
import globals from "globals";
|
||||||
|
import react from "@eslint-react/eslint-plugin";
|
||||||
|
import reactHooks from "eslint-plugin-react-hooks";
|
||||||
|
import reactRefresh from "eslint-plugin-react-refresh";
|
||||||
|
import tseslint from "typescript-eslint";
|
||||||
|
import eslintReactKit from "@eslint-react/kit";
|
||||||
|
import { defineConfig, globalIgnores } from "eslint/config";
|
||||||
|
import { preferNamespaceImport } from "./.config/preferNamespaceImport";
|
||||||
|
|
||||||
|
export default defineConfig([
|
||||||
|
globalIgnores(["dist"]),
|
||||||
|
{
|
||||||
|
files: ["**/*.{ts,tsx}"],
|
||||||
|
extends: [
|
||||||
|
js.configs.recommended,
|
||||||
|
tseslint.configs.strictTypeChecked,
|
||||||
|
tseslint.configs.stylisticTypeChecked,
|
||||||
|
react.configs.strict,
|
||||||
|
reactHooks.configs.flat.recommended,
|
||||||
|
reactRefresh.configs.vite,
|
||||||
|
eslintReactKit().use(preferNamespaceImport).getConfig(),
|
||||||
|
],
|
||||||
|
rules: {
|
||||||
|
"@typescript-eslint/array-type": [
|
||||||
|
"error",
|
||||||
|
{
|
||||||
|
default: "array",
|
||||||
|
},
|
||||||
|
],
|
||||||
|
"@typescript-eslint/consistent-generic-constructors": [
|
||||||
|
"error",
|
||||||
|
"constructor",
|
||||||
|
],
|
||||||
|
"@typescript-eslint/no-unsafe-type-assertion": "error",
|
||||||
|
"@typescript-eslint/strict-boolean-expressions": "error",
|
||||||
|
"@typescript-eslint/switch-exhaustiveness-check": [
|
||||||
|
"error",
|
||||||
|
{
|
||||||
|
requireDefaultForNonUnion: true,
|
||||||
|
considerDefaultExhaustiveForUnions: true,
|
||||||
|
},
|
||||||
|
],
|
||||||
|
"no-extra-boolean-cast": "off",
|
||||||
|
"no-fallthrough": [
|
||||||
|
"error",
|
||||||
|
{
|
||||||
|
reportUnusedFallthroughComment: true,
|
||||||
|
},
|
||||||
|
],
|
||||||
|
"@typescript-eslint/no-unused-vars": [
|
||||||
|
"error",
|
||||||
|
{
|
||||||
|
varsIgnorePattern: "^_",
|
||||||
|
reportUsedIgnorePattern: true,
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
languageOptions: {
|
||||||
|
globals: globals.browser,
|
||||||
|
parserOptions: {
|
||||||
|
projectService: true,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
]);
|
||||||
+13
@@ -0,0 +1,13 @@
|
|||||||
|
<!doctype html>
|
||||||
|
<html lang="en">
|
||||||
|
<head>
|
||||||
|
<meta charset="UTF-8" />
|
||||||
|
<link rel="icon" type="image/svg+xml" href="/favicon.svg" />
|
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||||
|
<title>Application</title>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<div id="root"></div>
|
||||||
|
<script type="module" src="/src/main.tsx"></script>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
@@ -0,0 +1,47 @@
|
|||||||
|
{
|
||||||
|
"name": "graph",
|
||||||
|
"private": true,
|
||||||
|
"version": "0.0.0",
|
||||||
|
"type": "module",
|
||||||
|
"scripts": {
|
||||||
|
"dev": "vite",
|
||||||
|
"build": "tsc -b && vite build",
|
||||||
|
"fmt": "prettier --write .",
|
||||||
|
"lint": "eslint .",
|
||||||
|
"preview": "vite preview"
|
||||||
|
},
|
||||||
|
"dependencies": {
|
||||||
|
"@tailwindcss/postcss": "^4.3.1",
|
||||||
|
"react": "^19.2.6",
|
||||||
|
"react-dom": "^19.2.6",
|
||||||
|
"tailwindcss": "^4.3.1"
|
||||||
|
},
|
||||||
|
"devDependencies": {
|
||||||
|
"@babel/core": "^7.29.0",
|
||||||
|
"@eslint-react/eslint-plugin": "^5.9.0",
|
||||||
|
"@eslint-react/kit": "^5.9.0",
|
||||||
|
"@eslint/js": "^10.0.1",
|
||||||
|
"@rolldown/plugin-babel": "^0.2.3",
|
||||||
|
"@types/babel__core": "^7.20.5",
|
||||||
|
"@types/node": "^24.12.3",
|
||||||
|
"@types/react": "^19.2.14",
|
||||||
|
"@types/react-dom": "^19.2.3",
|
||||||
|
"@typescript-eslint/types": "^8.61.1",
|
||||||
|
"@vitejs/plugin-react": "^6.0.1",
|
||||||
|
"autoprefixer": "^10.5.0",
|
||||||
|
"babel-plugin-react-compiler": "^1.0.0",
|
||||||
|
"eslint": "^10.3.0",
|
||||||
|
"eslint-plugin-react-hooks": "^7.1.1",
|
||||||
|
"eslint-plugin-react-namespace-import": "^1.0.5",
|
||||||
|
"eslint-plugin-react-refresh": "^0.5.2",
|
||||||
|
"globals": "^17.6.0",
|
||||||
|
"jiti": "^2.7.0",
|
||||||
|
"postcss": "^8.5.15",
|
||||||
|
"postcss-load-config": "^6.0.1",
|
||||||
|
"postcss-nested": "^7.0.2",
|
||||||
|
"prettier": "^3.8.4",
|
||||||
|
"typescript": "~6.0.2",
|
||||||
|
"typescript-eslint": "^8.59.2",
|
||||||
|
"vite": "^8.0.12"
|
||||||
|
}
|
||||||
|
}
|
||||||
Generated
+2445
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,8 @@
|
|||||||
|
import { type Config } from "postcss-load-config";
|
||||||
|
import autoprefixer from "autoprefixer";
|
||||||
|
import postcssNested from "postcss-nested";
|
||||||
|
import tailwindcss from "@tailwindcss/postcss";
|
||||||
|
|
||||||
|
export default {
|
||||||
|
plugins: [autoprefixer(), postcssNested(), tailwindcss()],
|
||||||
|
} satisfies Config;
|
||||||
@@ -0,0 +1,5 @@
|
|||||||
|
import * as React from "react";
|
||||||
|
|
||||||
|
export function App() {
|
||||||
|
return <h1 className="text-3xl">Hello world!</h1>;
|
||||||
|
}
|
||||||
@@ -0,0 +1,17 @@
|
|||||||
|
export class AssertionError extends Error {
|
||||||
|
constructor(msg?: string) {
|
||||||
|
super(msg);
|
||||||
|
this.name = "AssertionError";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export function assert(
|
||||||
|
condition: unknown,
|
||||||
|
message?: string,
|
||||||
|
): asserts condition {
|
||||||
|
if (Boolean(condition)) return;
|
||||||
|
const parts = ["assertion failed", message].filter(
|
||||||
|
(v) => v !== undefined,
|
||||||
|
);
|
||||||
|
throw new AssertionError(parts.join(": "));
|
||||||
|
}
|
||||||
@@ -0,0 +1,15 @@
|
|||||||
|
import * as React from "react";
|
||||||
|
import { createRoot } from "react-dom/client";
|
||||||
|
import { App } from "./app";
|
||||||
|
import { assert } from "./lib/assert";
|
||||||
|
|
||||||
|
import "./style.pcss";
|
||||||
|
|
||||||
|
const root = document.getElementById("root");
|
||||||
|
assert(root, "document doesn't contain any #root element");
|
||||||
|
|
||||||
|
createRoot(root).render(
|
||||||
|
<React.StrictMode>
|
||||||
|
<App />
|
||||||
|
</React.StrictMode>,
|
||||||
|
);
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
@import "tailwindcss";
|
||||||
@@ -0,0 +1,24 @@
|
|||||||
|
{
|
||||||
|
"compilerOptions": {
|
||||||
|
"tsBuildInfoFile": "./node_modules/.tmp/tsconfig.app.tsbuildinfo",
|
||||||
|
"target": "es2023",
|
||||||
|
"lib": ["ES2023", "DOM"],
|
||||||
|
"module": "esnext",
|
||||||
|
"types": ["vite/client"],
|
||||||
|
"skipLibCheck": true,
|
||||||
|
|
||||||
|
/* Bundler mode */
|
||||||
|
"moduleResolution": "bundler",
|
||||||
|
"allowImportingTsExtensions": true,
|
||||||
|
"verbatimModuleSyntax": true,
|
||||||
|
"moduleDetection": "force",
|
||||||
|
"noEmit": true,
|
||||||
|
"jsx": "react-jsx",
|
||||||
|
|
||||||
|
/* Linting */
|
||||||
|
"noUnusedLocals": false,
|
||||||
|
"noUncheckedIndexedAccess": true,
|
||||||
|
"erasableSyntaxOnly": true,
|
||||||
|
},
|
||||||
|
"include": ["src"]
|
||||||
|
}
|
||||||
@@ -0,0 +1,7 @@
|
|||||||
|
{
|
||||||
|
"files": [],
|
||||||
|
"references": [
|
||||||
|
{ "path": "./tsconfig.app.json" },
|
||||||
|
{ "path": "./tsconfig.node.json" }
|
||||||
|
]
|
||||||
|
}
|
||||||
@@ -0,0 +1,21 @@
|
|||||||
|
{
|
||||||
|
"compilerOptions": {
|
||||||
|
"tsBuildInfoFile": "./node_modules/.tmp/tsconfig.node.tsbuildinfo",
|
||||||
|
"target": "es2023",
|
||||||
|
"lib": ["ES2023"],
|
||||||
|
"module": "esnext",
|
||||||
|
"types": ["node"],
|
||||||
|
"skipLibCheck": true,
|
||||||
|
|
||||||
|
/* Bundler mode */
|
||||||
|
"moduleResolution": "bundler",
|
||||||
|
"allowImportingTsExtensions": true,
|
||||||
|
"verbatimModuleSyntax": true,
|
||||||
|
"moduleDetection": "force",
|
||||||
|
"noEmit": true,
|
||||||
|
|
||||||
|
/* Linting */
|
||||||
|
"erasableSyntaxOnly": true,
|
||||||
|
},
|
||||||
|
"include": ["./*.config.ts", ".config/**/*"]
|
||||||
|
}
|
||||||
@@ -0,0 +1,7 @@
|
|||||||
|
import { defineConfig } from "vite";
|
||||||
|
import react, { reactCompilerPreset } from "@vitejs/plugin-react";
|
||||||
|
import babel from "@rolldown/plugin-babel";
|
||||||
|
|
||||||
|
export default defineConfig({
|
||||||
|
plugins: [react(), babel({ presets: [reactCompilerPreset()] })],
|
||||||
|
});
|
||||||
Reference in New Issue
Block a user