@brutalway/check-tree 0.5.1 → 0.6.0

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  # @brutalway/check-tree
2
2
 
3
- Checks the folders of a source tree, which a linter does not see: no empty folder, no category folder with a single child, and files of one kind grouped in that kind's folder once there are two of them.
3
+ Checks the folders of a source tree, which a linter does not see: only the folders the layout names, no empty folder, no category folder with a single child, and files of one kind grouped in that kind's folder once there are two of them.
4
4
 
5
5
  ## Install
6
6
 
@@ -17,7 +17,7 @@ npx check-tree src
17
17
  npx check-tree src --categories components,hooks,utils
18
18
  ```
19
19
 
20
- The grouping rule only applies to the kinds listed in the table below that are also in this list.
20
+ These are the kind folders the layout accepts, and the grouping rule only applies to the kinds listed in the table below that are also in this list.
21
21
 
22
22
  ### Keep the entry points of a published package
23
23
 
@@ -41,6 +41,11 @@ It takes the category folders as second argument and `{ rootEntries: true }` as
41
41
 
42
42
  ### Rules
43
43
 
44
+ - a folder has a name the layout gives it:
45
+ - `src/` holds `app/`, `features/`, `shared-features/` and `shared/`, next to its entry files, and `app/` is not checked
46
+ - `src/shared/` holds kind folders only (`lib/`, `types/`, `configs/`...), since it has no domain
47
+ - a feature (`features/<x>/`) or a shared feature (`shared-features/<x>/`), at any depth, holds kind folders, `features/` for its sub-features, `shared-features/` for the business code they share and `shared/` for the code with no domain
48
+ - a kind folder holds kind folders only, like `presenters/` inside `components/`
44
49
  - no empty folder
45
50
  - a category folder (`components`, `hooks`, `stores`…) does not hold a single child: move the child up and delete the folder
46
51
  - files of one kind stay at the root of their folder while there is one of them, and move into the kind's folder from two on. A folder that has that kind's folder keeps none of them next to it. The kinds are recognized by their name:
package/dist/checkTree.js CHANGED
@@ -1,5 +1,5 @@
1
1
  #!/usr/bin/env node
2
- import { t as treeViolations } from "./treeViolations-DzriZgEc.js";
2
+ import { t as treeViolations } from "./treeViolations-CeTXg9WP.js";
3
3
  import { resolve } from "node:path";
4
4
  import { parseArgs } from "node:util";
5
5
  // src/checkTree.ts
@@ -1,4 +1,4 @@
1
- import { basename, join, relative } from "node:path";
1
+ import { basename, dirname, join, relative } from "node:path";
2
2
  import { readdirSync } from "node:fs";
3
3
  // src/features/tree-violations/TreeViolationsConfig.ts
4
4
  const DEFAULT_CATEGORY_FOLDERS = [
@@ -116,6 +116,61 @@ const FILE_GROUPS = [
116
116
  appliesIn: outsideOwnFolder("lib")
117
117
  }
118
118
  ];
119
+ // src/features/tree-violations/features/layout/childLayer.ts
120
+ const SOURCE_LAYERS = /* @__PURE__ */ new Map([
121
+ ["app", "free"],
122
+ ["features", "features"],
123
+ ["shared-features", "features"],
124
+ ["shared", "shared"]
125
+ ]);
126
+ const FEATURE_LAYERS = /* @__PURE__ */ new Map([
127
+ ["features", "features"],
128
+ ["shared-features", "features"],
129
+ ["shared", "shared"]
130
+ ]);
131
+ function kindFolder(path, categories, reason) {
132
+ if (categories.has(basename(path))) return {
133
+ layer: "kind",
134
+ violations: []
135
+ };
136
+ return {
137
+ layer: "free",
138
+ violations: [`${path} is not a kind folder: ${reason}`]
139
+ };
140
+ }
141
+ function sourceChild(path) {
142
+ const layer = SOURCE_LAYERS.get(basename(path));
143
+ if (layer !== void 0) return {
144
+ layer,
145
+ violations: []
146
+ };
147
+ return {
148
+ layer: "free",
149
+ violations: [`${path} is not a layer: ${dirname(path)}/ holds app/, features/, shared-features/ and shared/ next to its entry files, move it into one of them`]
150
+ };
151
+ }
152
+ function featureChild(path, categories) {
153
+ const layer = FEATURE_LAYERS.get(basename(path));
154
+ if (layer !== void 0) return {
155
+ layer,
156
+ violations: []
157
+ };
158
+ return kindFolder(path, categories, "a feature holds kind folders, features/ for its sub-features, shared-features/ for the business code they share and shared/, move it into features/ as a sub-feature or spread its files into kind folders");
159
+ }
160
+ function childLayer(layer, path, categories) {
161
+ if (layer === "source") return sourceChild(path);
162
+ if (layer === "features") return {
163
+ layer: "feature",
164
+ violations: []
165
+ };
166
+ if (layer === "feature") return featureChild(path, categories);
167
+ if (layer === "shared") return kindFolder(path, categories, `${dirname(path)}/ holds no domain, move its files into lib/, types/, configs/... or into a shared feature`);
168
+ if (layer === "kind") return kindFolder(path, categories, `${dirname(path)}/ holds its files and kind folders only`);
169
+ return {
170
+ layer: "free",
171
+ violations: []
172
+ };
173
+ }
119
174
  // src/features/tree-violations/treeViolations.ts
120
175
  function groupViolations(name, folderName, listing, categoryFolders) {
121
176
  const violations = [];
@@ -148,9 +203,13 @@ function folderViolations(folder, name, categoryFolders, groupsFiles) {
148
203
  }
149
204
  function treeViolations(root, categoryFolders = DEFAULT_CATEGORY_FOLDERS, options = {}) {
150
205
  const categories = new Set(categoryFolders);
151
- function walk(folder) {
152
- return [...folderViolations(folder, relative(join(root, ".."), folder), categories, folder !== root || options.rootEntries !== true), ...readdirSync(folder, { withFileTypes: true }).filter((entry) => entry.isDirectory()).flatMap((entry) => walk(join(folder, entry.name)))];
206
+ function walk(folder, layer) {
207
+ const name = relative(join(root, ".."), folder);
208
+ return [...folderViolations(folder, name, categories, folder !== root || options.rootEntries !== true), ...readdirSync(folder, { withFileTypes: true }).filter((entry) => entry.isDirectory()).flatMap((entry) => {
209
+ const child = childLayer(layer, `${name}/${entry.name}`, categories);
210
+ return [...child.violations, ...walk(join(folder, entry.name), child.layer)];
211
+ })];
153
212
  }
154
- return walk(root);
213
+ return walk(root, "source");
155
214
  }
156
215
  export { treeViolations as t };
@@ -1 +1 @@
1
- export { t as treeViolations } from "./treeViolations-DzriZgEc.js";
1
+ export { t as treeViolations } from "./treeViolations-CeTXg9WP.js";
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@brutalway/check-tree",
3
- "version": "0.5.1",
4
- "description": "Checks a source tree: no empty folder, no category folder holding a single child, stylesheets grouped in styles/.",
3
+ "version": "0.6.0",
4
+ "description": "Checks a source tree: only the folders the layout names, no empty folder, no category folder holding a single child, stylesheets grouped in styles/.",
5
5
  "keywords": [
6
6
  "lint",
7
7
  "folder-structure",
@@ -37,22 +37,38 @@
37
37
  "deps": "depcruise --output-type err-long src",
38
38
  "tree": "node src/checkTree.ts src --root-entries",
39
39
  "duplicates": "jscpd src",
40
- "check": "npm run typecheck && npm run lint && npm run deps && npm run tree && npm run duplicates",
41
- "test": "node --test 'src/**/*.test.ts'"
40
+ "check": "prettier --check . && npm run typecheck && npm run lint && npm run deps && npm run tree && npm run duplicates && npm run unused",
41
+ "test": "node --test 'src/**/*.test.ts'",
42
+ "format": "prettier --write .",
43
+ "unused": "knip"
42
44
  },
43
45
  "devDependencies": {
44
46
  "@brutalway/dependency-cruiser-config": "0.5.0",
45
47
  "@brutalway/oxlint-config-node": "0.2.1",
46
48
  "@brutalway/oxlint-config-node-test": "0.1.0",
49
+ "@brutalway/prettier-config": "0.3.0",
47
50
  "@brutalway/tsconfig": "0.4.0",
51
+ "@swc/core": "1.16.22",
52
+ "@types/node": "26.6.6",
48
53
  "dependency-cruiser": "18.7.2",
49
- "jscpd": "5.4.2",
50
- "oxlint": "1.91.0",
51
- "oxlint-tsgolint": "7.0.2005",
52
- "tsdown": "0.23.5",
54
+ "jscpd": "5.4.3",
55
+ "knip": "6.44.2",
56
+ "oxlint": "1.92.0",
57
+ "oxlint-tsgolint": "7.0.2006",
58
+ "prettier": "3.9.10",
59
+ "tsdown": "0.23.7",
53
60
  "typescript": "7.0.2"
54
61
  },
55
62
  "imports": {
56
63
  "#src/*": "./src/*"
64
+ },
65
+ "prettier": "@brutalway/prettier-config",
66
+ "allowScripts": {
67
+ "@swc/core": false
68
+ },
69
+ "overrides": {
70
+ "eslint-plugin-no-comments": {
71
+ "minimatch": "^11.0.1"
72
+ }
57
73
  }
58
74
  }