@jterrazz/codestyle 1.2.2 → 1.2.4
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/README.md +10 -8
- package/package.json +2 -3
- package/src/oxlint/base.json +9 -5
- package/src/postinstall.js +0 -106
package/README.md
CHANGED
|
@@ -12,7 +12,7 @@ Create `.oxlintrc.json`:
|
|
|
12
12
|
|
|
13
13
|
```json
|
|
14
14
|
{
|
|
15
|
-
"extends": ["
|
|
15
|
+
"extends": ["node_modules/@jterrazz/codestyle/src/oxlint/node.json"]
|
|
16
16
|
}
|
|
17
17
|
```
|
|
18
18
|
|
|
@@ -25,11 +25,12 @@ npx codestyle --fix # Fix everything
|
|
|
25
25
|
|
|
26
26
|
## Configurations
|
|
27
27
|
|
|
28
|
-
| Config
|
|
29
|
-
|
|
|
30
|
-
|
|
|
31
|
-
|
|
|
32
|
-
|
|
|
28
|
+
| Config | Use Case |
|
|
29
|
+
| -------------------------------------------------------------------------- | ---------------------------------- |
|
|
30
|
+
| `node_modules/@jterrazz/codestyle/src/oxlint/node.json` | Node.js (requires .js extensions) |
|
|
31
|
+
| `node_modules/@jterrazz/codestyle/src/oxlint/expo.json` | Expo / React Native |
|
|
32
|
+
| `node_modules/@jterrazz/codestyle/src/oxlint/nextjs.json` | Next.js |
|
|
33
|
+
| `node_modules/@jterrazz/codestyle/src/oxlint/architectures/hexagonal.json` | Hexagonal architecture enforcement |
|
|
33
34
|
|
|
34
35
|
## What's Included
|
|
35
36
|
|
|
@@ -38,6 +39,7 @@ npx codestyle --fix # Fix everything
|
|
|
38
39
|
- Named exports enforcement (no default exports)
|
|
39
40
|
- Performance warnings (spread in loops, etc.)
|
|
40
41
|
- Style consistency (curly braces, comments, naming)
|
|
42
|
+
- Custom rules: architecture boundaries, import extensions
|
|
41
43
|
|
|
42
44
|
## CLI
|
|
43
45
|
|
|
@@ -57,8 +59,8 @@ Enforce hexagonal architecture boundaries:
|
|
|
57
59
|
```json
|
|
58
60
|
{
|
|
59
61
|
"extends": [
|
|
60
|
-
"
|
|
61
|
-
"
|
|
62
|
+
"node_modules/@jterrazz/codestyle/src/oxlint/node.json",
|
|
63
|
+
"node_modules/@jterrazz/codestyle/src/oxlint/architectures/hexagonal.json"
|
|
62
64
|
]
|
|
63
65
|
}
|
|
64
66
|
```
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@jterrazz/codestyle",
|
|
3
|
-
"version": "1.2.
|
|
3
|
+
"version": "1.2.4",
|
|
4
4
|
"author": "Jean-Baptiste Terrazzoni <contact@jterrazz.com>",
|
|
5
5
|
"bin": {
|
|
6
6
|
"codestyle": "./src/codestyle.sh"
|
|
@@ -27,8 +27,7 @@
|
|
|
27
27
|
"lint:fix": "oxlint --fix --ignore-pattern '**/fixtures/**' && oxfmt",
|
|
28
28
|
"test": "vitest --run",
|
|
29
29
|
"test:watch": "vitest",
|
|
30
|
-
"build": "# no build script"
|
|
31
|
-
"postinstall": "node src/postinstall.js"
|
|
30
|
+
"build": "# no build script"
|
|
32
31
|
},
|
|
33
32
|
"dependencies": {
|
|
34
33
|
"@typescript/native-preview": "^7.0.0-dev",
|
package/src/oxlint/base.json
CHANGED
|
@@ -5,9 +5,9 @@
|
|
|
5
5
|
"categories": {
|
|
6
6
|
"correctness": "error",
|
|
7
7
|
"suspicious": "error",
|
|
8
|
-
"perf": "
|
|
8
|
+
"perf": "error",
|
|
9
9
|
"pedantic": "off",
|
|
10
|
-
"style": "
|
|
10
|
+
"style": "error",
|
|
11
11
|
"nursery": "off"
|
|
12
12
|
},
|
|
13
13
|
"rules": {
|
|
@@ -80,21 +80,25 @@
|
|
|
80
80
|
"no-continue": "off",
|
|
81
81
|
"arrow-body-style": "off",
|
|
82
82
|
"prefer-destructuring": "off",
|
|
83
|
+
"new-cap": "off",
|
|
84
|
+
"no-await-in-loop": "off",
|
|
83
85
|
"typescript/consistent-type-definitions": "off",
|
|
84
86
|
"typescript/array-type": "off",
|
|
87
|
+
"typescript/no-inferrable-types": "off",
|
|
85
88
|
"unicorn/no-null": "off",
|
|
86
89
|
"unicorn/no-array-sort": "off",
|
|
90
|
+
"import/no-unassigned-import": "off",
|
|
91
|
+
"import/no-named-default": "off",
|
|
87
92
|
|
|
88
93
|
// ============================================
|
|
89
94
|
// ENABLED - Code style enforcement
|
|
90
95
|
// ============================================
|
|
91
96
|
|
|
92
|
-
"capitalized-comments": "
|
|
93
|
-
"new-cap": "error",
|
|
97
|
+
"capitalized-comments": "error",
|
|
94
98
|
"curly": "error",
|
|
95
99
|
"no-nested-ternary": "error",
|
|
96
100
|
"unicorn/catch-error-name": "error",
|
|
97
|
-
"unicorn/numeric-separators-style": "
|
|
101
|
+
"unicorn/numeric-separators-style": "error",
|
|
98
102
|
|
|
99
103
|
// ============================================
|
|
100
104
|
// DISABLED - Conflicts with other rules
|
package/src/postinstall.js
DELETED
|
@@ -1,106 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
|
|
3
|
-
import fs from "fs";
|
|
4
|
-
import path from "path";
|
|
5
|
-
import { fileURLToPath } from "url";
|
|
6
|
-
|
|
7
|
-
const __dirname = path.dirname(fileURLToPath(import.meta.url));
|
|
8
|
-
|
|
9
|
-
function findProjectRoot() {
|
|
10
|
-
let dir = process.cwd();
|
|
11
|
-
if (dir.includes("node_modules")) {
|
|
12
|
-
dir = dir.split("node_modules")[0];
|
|
13
|
-
}
|
|
14
|
-
return dir;
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
// Rule mappings based on extended configs
|
|
18
|
-
const ruleMappings = [
|
|
19
|
-
{
|
|
20
|
-
pattern: "architectures/hexagonal",
|
|
21
|
-
rule: ["codestyle/arch-hexagonal", "error"],
|
|
22
|
-
},
|
|
23
|
-
{
|
|
24
|
-
pattern: "oxlint/node",
|
|
25
|
-
rule: ["codestyle/imports-with-ext", "error"],
|
|
26
|
-
},
|
|
27
|
-
{
|
|
28
|
-
pattern: "oxlint/expo",
|
|
29
|
-
rule: ["codestyle/imports-without-ext", "error"],
|
|
30
|
-
},
|
|
31
|
-
{
|
|
32
|
-
pattern: "oxlint/nextjs",
|
|
33
|
-
rule: ["codestyle/imports-without-ext", "error"],
|
|
34
|
-
},
|
|
35
|
-
];
|
|
36
|
-
|
|
37
|
-
function run() {
|
|
38
|
-
const projectRoot = findProjectRoot();
|
|
39
|
-
const configPath = path.join(projectRoot, ".oxlintrc.json");
|
|
40
|
-
|
|
41
|
-
if (!fs.existsSync(configPath)) {
|
|
42
|
-
return;
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
let config;
|
|
46
|
-
try {
|
|
47
|
-
config = JSON.parse(fs.readFileSync(configPath, "utf8"));
|
|
48
|
-
} catch {
|
|
49
|
-
console.log("[@jterrazz/codestyle] Could not parse .oxlintrc.json");
|
|
50
|
-
return;
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
const configStr = JSON.stringify(config);
|
|
54
|
-
const neededRules = new Map();
|
|
55
|
-
let needsPlugin = false;
|
|
56
|
-
|
|
57
|
-
for (const mapping of ruleMappings) {
|
|
58
|
-
if (configStr.includes(mapping.pattern)) {
|
|
59
|
-
neededRules.set(mapping.rule[0], mapping.rule[1]);
|
|
60
|
-
needsPlugin = true;
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
if (!needsPlugin) {
|
|
65
|
-
return;
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
let updated = false;
|
|
69
|
-
const updates = [];
|
|
70
|
-
|
|
71
|
-
// Add plugin
|
|
72
|
-
const pluginPath = "./node_modules/@jterrazz/codestyle/src/oxlint/plugins/codestyle.js";
|
|
73
|
-
config.jsPlugins = config.jsPlugins || [];
|
|
74
|
-
if (!config.jsPlugins.includes(pluginPath)) {
|
|
75
|
-
config.jsPlugins.push(pluginPath);
|
|
76
|
-
updated = true;
|
|
77
|
-
updates.push(" + jsPlugins: codestyle.js");
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
// Add rules
|
|
81
|
-
config.rules = config.rules || {};
|
|
82
|
-
for (const [ruleName, ruleLevel] of neededRules) {
|
|
83
|
-
if (!config.rules[ruleName]) {
|
|
84
|
-
config.rules[ruleName] = ruleLevel;
|
|
85
|
-
updated = true;
|
|
86
|
-
updates.push(` + rule: ${ruleName}`);
|
|
87
|
-
}
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
if (!updated) {
|
|
91
|
-
return;
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
fs.writeFileSync(
|
|
95
|
-
configPath,
|
|
96
|
-
`${JSON.stringify(config, null, 2)}
|
|
97
|
-
`,
|
|
98
|
-
);
|
|
99
|
-
|
|
100
|
-
console.log("[@jterrazz/codestyle] Updated .oxlintrc.json:");
|
|
101
|
-
for (const update of updates) {
|
|
102
|
-
console.log(update);
|
|
103
|
-
}
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
run();
|