@apdesign/code-style-react 1.2.3 → 2.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/biome.jsonc ADDED
@@ -0,0 +1,107 @@
1
+ {
2
+ "$schema": "https://biomejs.dev/schemas/2.2.6/schema.json",
3
+ "extends": ["ultracite"],
4
+ "formatter": {
5
+ "enabled": true,
6
+ "indentStyle": "space",
7
+ "indentWidth": 2,
8
+ "lineWidth": 100
9
+ },
10
+ "javascript": {
11
+ "formatter": {
12
+ "quoteStyle": "single",
13
+ "semicolons": "always",
14
+ "trailingCommas": "all",
15
+ "bracketSpacing": true,
16
+ "arrowParentheses": "always"
17
+ }
18
+ },
19
+ "json": {
20
+ "formatter": {
21
+ "trailingCommas": "none"
22
+ }
23
+ },
24
+ "linter": {
25
+ "enabled": true,
26
+ "rules": {
27
+ "recommended": false,
28
+ "a11y": {
29
+ "noNoninteractiveElementInteractions": "off",
30
+ "noStaticElementInteractions": "off",
31
+ "useKeyWithClickEvents": "off"
32
+ },
33
+ "complexity": {
34
+ "noBannedTypes": "off",
35
+ "noUselessConstructor": "error",
36
+ "noUselessFragments": "off",
37
+ "noUselessTypeConstraint": "off",
38
+ "noForEach": "off",
39
+ "noExcessiveCognitiveComplexity": "off",
40
+ "noVoid": "off"
41
+ },
42
+ "correctness": {
43
+ "noPrecisionLoss": "warn",
44
+ "noUndeclaredVariables": "off",
45
+ "noUnusedVariables": "warn",
46
+ "noUnusedImports": "warn",
47
+ "noUnusedPrivateClassMembers": "warn",
48
+ "noUnusedFunctionParameters": "off",
49
+ "useExhaustiveDependencies": "off",
50
+ "noEmptyCharacterClassInRegex": "warn"
51
+ },
52
+ "style": {
53
+ "noNamespace": "off",
54
+ "noParameterAssign": "warn",
55
+ "noNonNullAssertion": "off",
56
+ "useArrayLiterals": "off",
57
+ "useAsConstAssertion": "off",
58
+ "useBlockStatements": "off",
59
+ "useNamingConvention": "off",
60
+ "useTemplate": "warn",
61
+ "useFilenamingConvention": "off",
62
+ "useNumberNamespace": "off",
63
+ "useNodejsImportProtocol": "off",
64
+ "noUnusedTemplateLiteral": "off",
65
+ "useExponentiationOperator": "warn",
66
+ "noNegationElse": "off",
67
+ "noMagicNumbers": "off"
68
+ },
69
+ "suspicious": {
70
+ "noEmptyBlockStatements": "warn",
71
+ "noExplicitAny": "warn",
72
+ "noExtraNonNullAssertion": "warn",
73
+ "noMisleadingInstantiator": "warn",
74
+ "noUnsafeDeclarationMerging": "warn",
75
+ "noArrayIndexKey": "warn",
76
+ "noShadowRestrictedNames": "warn",
77
+ "noConsole": "off",
78
+ "noDoubleEquals": "off",
79
+ "noPrototypeBuiltins": "off"
80
+ },
81
+ "performance": {
82
+ "noAccumulatingSpread": "off",
83
+ "noDelete": "off",
84
+ "useTopLevelRegex": "off"
85
+ }
86
+ }
87
+ },
88
+ "files": {
89
+ "includes": [
90
+ "**/*.js",
91
+ "**/*.jsx",
92
+ "**/*.ts",
93
+ "**/*.tsx",
94
+ "**/*.json",
95
+ "**/*.jsonc"
96
+ ],
97
+ "experimentalScannerIgnores": [
98
+ "**/dist/**",
99
+ "**/node_modules/**",
100
+ "**/*.d.ts",
101
+ "**/mock/**",
102
+ "**/.eslintrc.cjs",
103
+ "**/build/**",
104
+ "**/coverage/**"
105
+ ]
106
+ }
107
+ }
package/cli.js CHANGED
@@ -1,15 +1,49 @@
1
- #!/usr/bin/env node
2
-
3
- const main = require('./index');
4
-
5
- const args = process.argv.slice(2);
6
- const command = args[0];
7
-
8
- if (command === 'init') {
9
- main();
10
- } else if (command === 'eslint') {
11
- const runEslint = require('./scripts/runEslint');
12
- runEslint(args.slice(1));
13
- } else {
14
- console.log(`Unknown command: "${command}"`);
15
- }
1
+ #!/usr/bin/env node
2
+
3
+ const main = require('./index');
4
+ const { execSync } = require('node:child_process');
5
+
6
+ const args = process.argv.slice(2);
7
+ const command = args[0];
8
+
9
+ if (command === 'init') {
10
+ main();
11
+ } else if (command === 'fix') {
12
+ // 运行 ultracite fix
13
+ try {
14
+ execSync('npx ultracite fix', { stdio: 'inherit' });
15
+ } catch (_error) {
16
+ process.exit(1);
17
+ }
18
+ } else if (command === 'check') {
19
+ // 运行 ultracite check
20
+ try {
21
+ execSync('npx ultracite check', { stdio: 'inherit' });
22
+ } catch (_error) {
23
+ process.exit(1);
24
+ }
25
+ } else if (command === 'eslint') {
26
+ // 保留向后兼容的 eslint 命令
27
+ const runEslint = require('./scripts/runEslint');
28
+ runEslint(args.slice(1));
29
+ } else if (command === 'stylelint') {
30
+ // 保留 stylelint 命令
31
+ const runStylelint = require('./scripts/runStylelint');
32
+ runStylelint(args.slice(1));
33
+ } else {
34
+ console.log(`
35
+ Usage: apdesign-code-style <command>
36
+
37
+ Commands:
38
+ init 初始化配置文件(Biome, Stylelint, Husky)
39
+ fix 格式化并自动修复代码问题(使用 Ultracite)
40
+ check 检查代码问题但不修复(使用 Ultracite)
41
+ stylelint 运行 Stylelint 检查样式文件
42
+ eslint [已废弃] 运行 ESLint(建议使用 fix 或 check)
43
+
44
+ Example:
45
+ apdesign-code-style init
46
+ apdesign-code-style fix
47
+ apdesign-code-style check
48
+ `);
49
+ }
package/index.js CHANGED
@@ -1,13 +1,13 @@
1
- #!/usr/bin/env node
2
-
3
- const initHusky = require('./scripts/initHusky');
4
- const initScripts = require('./scripts/initScripts');
5
- const initConfigs = require('./scripts/initConfigs');
6
-
7
- function main() {
8
- initHusky();
9
- initScripts();
10
- initConfigs();
11
- }
12
-
13
- module.exports = main;
1
+ #!/usr/bin/env node
2
+
3
+ const initHusky = require('./scripts/initHusky');
4
+ const initScripts = require('./scripts/initScripts');
5
+ const initConfigs = require('./scripts/initConfigs');
6
+
7
+ function main() {
8
+ initHusky();
9
+ initScripts();
10
+ initConfigs();
11
+ }
12
+
13
+ module.exports = main;
package/lefthook.yml ADDED
@@ -0,0 +1,19 @@
1
+ pre-commit:
2
+ parallel: true
3
+ commands:
4
+ # 使用 lint-staged 来运行 Ultracite,会自动处理暂存的文件
5
+ lint-staged:
6
+ run: npx lint-staged
7
+
8
+ pre-push:
9
+ parallel: true
10
+ commands:
11
+ # 在 push 前检查代码质量
12
+ biome-check:
13
+ glob: "*.{js,jsx,ts,tsx,json,jsonc}"
14
+ run: npx ultracite check {staged_files}
15
+
16
+ # 检查样式文件
17
+ stylelint-check:
18
+ glob: "*.{css,scss,less}"
19
+ run: npx stylelint {staged_files}
package/package.json CHANGED
@@ -1,45 +1,67 @@
1
- {
2
- "name": "@apdesign/code-style-react",
3
- "version": "1.2.3",
4
- "scripts": {},
5
- "bin": {
6
- "apdesign-code-style": "cli.js"
7
- },
8
- "files": [
9
- "index.js",
10
- ".prettierrc.js",
11
- "eslint",
12
- "stylelint",
13
- "husky",
14
- "scripts"
15
- ],
16
- "keywords": [],
17
- "author": "",
18
- "license": "ISC",
19
- "description": "",
20
- "dependencies": {
21
- "@types/glob": "^8.1.0",
22
- "@typescript-eslint/eslint-plugin": "^6.21.0",
23
- "@typescript-eslint/parser": "^6.21.0",
24
- "css-color-names": "^1.0.1",
25
- "eslint": "^8.57.1",
26
- "eslint-config-airbnb": "^19.0.4",
27
- "eslint-config-prettier": "^9.1.0",
28
- "eslint-import-resolver-alias": "^1.1.2",
29
- "eslint-plugin-import": "^2.31.0",
30
- "eslint-plugin-jsx-a11y": "^6.10.2",
31
- "eslint-plugin-prettier": "^5.2.1",
32
- "eslint-plugin-react": "^7.37.2",
33
- "eslint-plugin-react-hooks": "^4.6.2",
34
- "glob": "^11.0.3",
35
- "husky": "^9.1.7",
36
- "lint-staged": "^15.3.0",
37
- "postcss-less": "^6.0.0",
38
- "postcss-scss": "^4.0.9",
39
- "prettier": "^3.3.3",
40
- "stylelint": "^16.19.1",
41
- "stylelint-config-standard": "^38.0.0",
42
- "stylelint-less": "^3.0.1",
43
- "stylelint-scss": "^6.12.0"
44
- }
45
- }
1
+ {
2
+ "name": "@apdesign/code-style-react",
3
+ "version": "2.0.1",
4
+ "description": "基于 Ultracite (Biome) 的现代化前端代码规范工具集,专为 React/TypeScript 项目设计",
5
+ "keywords": [
6
+ "biome",
7
+ "ultracite",
8
+ "code-style",
9
+ "linter",
10
+ "formatter",
11
+ "react",
12
+ "typescript",
13
+ "eslint",
14
+ "prettier",
15
+ "stylelint",
16
+ "code-quality"
17
+ ],
18
+ "author": "apdesign",
19
+ "license": "ISC",
20
+ "repository": {
21
+ "type": "git",
22
+ "url": "https://github.com/apdesign/code-style-react.git"
23
+ },
24
+ "bugs": {
25
+ "url": "https://github.com/apdesign/code-style-react/issues"
26
+ },
27
+ "homepage": "https://github.com/apdesign/code-style-react#readme",
28
+ "scripts": {
29
+ "prepublishOnly": "npx @biomejs/biome check ."
30
+ },
31
+ "bin": {
32
+ "apdesign-code-style": "cli.js"
33
+ },
34
+ "files": [
35
+ "index.js",
36
+ "cli.js",
37
+ ".prettierrc.js",
38
+ "biome.jsonc",
39
+ "lefthook.yml",
40
+ "stylelint",
41
+ "husky",
42
+ "scripts",
43
+ "README.md",
44
+ "CHANGELOG.md",
45
+ "MIGRATION.md"
46
+ ],
47
+ "dependencies": {
48
+ "@biomejs/biome": "^2.2.6",
49
+ "css-color-names": "^1.0.1",
50
+ "husky": "^9.1.7",
51
+ "lefthook": "^1.12.4",
52
+ "lint-staged": "^16.1.6",
53
+ "postcss-less": "^6.0.0",
54
+ "postcss-scss": "^4.0.9",
55
+ "prettier": "^3.3.3",
56
+ "stylelint": "^16.19.1",
57
+ "stylelint-config-standard": "^38.0.0",
58
+ "stylelint-less": "^3.0.1",
59
+ "stylelint-scss": "^6.12.0",
60
+ "ultracite": "^5.6.2"
61
+ },
62
+ "lint-staged": {
63
+ "*.{js,jsx,ts,tsx,json,jsonc,css,scss,md,mdx}": [
64
+ "npx ultracite fix"
65
+ ]
66
+ }
67
+ }
@@ -1,60 +1,60 @@
1
- #!/usr/bin/env sh
2
- echo "🔍 Starting ESLint check (Git diff files only)..."
3
-
4
- # 切换到 Git 仓库根目录
5
- PROJECT_ROOT=$(git rev-parse --show-toplevel)
6
- cd "$PROJECT_ROOT" || exit 1
7
-
8
- # 参数:commitId(必填),路径(可选)
9
- TARGET_COMMIT=$1
10
- LATEST_COMMIT=$(git rev-parse HEAD)
11
-
12
- if [ -z "$TARGET_COMMIT" ]; then
13
- echo "❗ Error: Missing target commit ID."
14
- echo "👉 Usage: $0 <target-commit-id> [project-path]"
15
- exit 1
16
- fi
17
-
18
- echo "获取到上一次运行commit ID: $TARGET_COMMIT"
19
- echo "获取到当前最新的commit ID: $LATEST_COMMIT"
20
-
21
- # 处理路径参数
22
- if [ -n "$FULL_PATH" ]; then
23
- PROJECT_NAME=$(basename "$FULL_PATH")
24
- echo "📂 检测子项目: $PROJECT_NAME"
25
- DIFF_FILES=$(git diff --name-only "$TARGET_COMMIT" "$LATEST_COMMIT" -- "*/$PROJECT_NAME/*.{ts,tsx,js,jsx}")
26
- else
27
- DIFF_FILES=$(git diff --name-only "$TARGET_COMMIT" "$LATEST_COMMIT" -- '*.ts' '*.tsx' '*.js' '*.jsx')
28
- fi
29
-
30
- if [ -z "$DIFF_FILES" ]; then
31
- echo "✅ No matching file changes detected, skipping ESLint check"
32
- exit 0
33
- fi
34
-
35
- echo "📂 Changed files:"
36
- echo "$DIFF_FILES"
37
-
38
- FILE_COUNT=$(echo "$DIFF_FILES" | wc -l)
39
- echo "🧾 Total changed files: $FILE_COUNT"
40
-
41
- ESLINT_CONFIG_FILE="$PROJECT_ROOT/.eslintrc.build.cjs"
42
-
43
- ESLINT_CMD_ARGS="--no-error-on-unmatched-pattern --report-unused-disable-directives"
44
-
45
- if [ -f "$ESLINT_CONFIG_FILE" ]; then
46
- echo "🔧 Using ESLint config file: $ESLINT_CONFIG_FILE"
47
- ESLINT_CMD_ARGS="--config $ESLINT_CONFIG_FILE $ESLINT_CMD_ARGS"
48
- else
49
- echo "⚠️ ESLint config file not found, using default ESLint config resolution."
50
- fi
51
-
52
- echo "$DIFF_FILES" | tr -d '\r' | \
53
- xargs -d '\n' -P 4 -n 30 npx --no-install eslint $ESLINT_CMD_ARGS
54
-
55
- if [ $? -ne 0 ]; then
56
- echo "❌ ESLint check failed. Aborting build process"
57
- exit 1
58
- fi
59
-
1
+ #!/usr/bin/env sh
2
+ echo "🔍 Starting ESLint check (Git diff files only)..."
3
+
4
+ # 切换到 Git 仓库根目录
5
+ PROJECT_ROOT=$(git rev-parse --show-toplevel)
6
+ cd "$PROJECT_ROOT" || exit 1
7
+
8
+ # 参数:commitId(必填),路径(可选)
9
+ TARGET_COMMIT=$1
10
+ LATEST_COMMIT=$(git rev-parse HEAD)
11
+
12
+ if [ -z "$TARGET_COMMIT" ]; then
13
+ echo "❗ Error: Missing target commit ID."
14
+ echo "👉 Usage: $0 <target-commit-id> [project-path]"
15
+ exit 1
16
+ fi
17
+
18
+ echo "获取到上一次运行commit ID: $TARGET_COMMIT"
19
+ echo "获取到当前最新的commit ID: $LATEST_COMMIT"
20
+
21
+ # 处理路径参数
22
+ if [ -n "$FULL_PATH" ]; then
23
+ PROJECT_NAME=$(basename "$FULL_PATH")
24
+ echo "📂 检测子项目: $PROJECT_NAME"
25
+ DIFF_FILES=$(git diff --name-only "$TARGET_COMMIT" "$LATEST_COMMIT" -- "*/$PROJECT_NAME/*.{ts,tsx,js,jsx}")
26
+ else
27
+ DIFF_FILES=$(git diff --name-only "$TARGET_COMMIT" "$LATEST_COMMIT" -- '*.ts' '*.tsx' '*.js' '*.jsx')
28
+ fi
29
+
30
+ if [ -z "$DIFF_FILES" ]; then
31
+ echo "✅ No matching file changes detected, skipping ESLint check"
32
+ exit 0
33
+ fi
34
+
35
+ echo "📂 Changed files:"
36
+ echo "$DIFF_FILES"
37
+
38
+ FILE_COUNT=$(echo "$DIFF_FILES" | wc -l)
39
+ echo "🧾 Total changed files: $FILE_COUNT"
40
+
41
+ ESLINT_CONFIG_FILE="$PROJECT_ROOT/.eslintrc.build.cjs"
42
+
43
+ ESLINT_CMD_ARGS="--no-error-on-unmatched-pattern --report-unused-disable-directives"
44
+
45
+ if [ -f "$ESLINT_CONFIG_FILE" ]; then
46
+ echo "🔧 Using ESLint config file: $ESLINT_CONFIG_FILE"
47
+ ESLINT_CMD_ARGS="--config $ESLINT_CONFIG_FILE $ESLINT_CMD_ARGS"
48
+ else
49
+ echo "⚠️ ESLint config file not found, using default ESLint config resolution."
50
+ fi
51
+
52
+ echo "$DIFF_FILES" | tr -d '\r' | \
53
+ xargs -d '\n' -P 4 -n 30 npx --no-install eslint $ESLINT_CMD_ARGS
54
+
55
+ if [ $? -ne 0 ]; then
56
+ echo "❌ ESLint check failed. Aborting build process"
57
+ exit 1
58
+ fi
59
+
60
60
  echo "✅ ESLint check passed"