@zgeoff/oxlint-config 0.10.1 → 0.10.2

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
@@ -70,8 +70,8 @@ The plugin is addressable on its own at `@zgeoff/oxlint-config/plugin` for confi
70
70
  - Comments: `zgeoff/no-jsdoc` and `zgeoff/max-consecutive-line-comments` keep comments to the reason
71
71
  for a line. See
72
72
  [the comment rules](../../docs/architecture/oxlint-config.md#zgeoffno-jsdoc-and-zgeoffmax-consecutive-line-comments).
73
- - Code style: function verbs, verb contracts, module order, abbreviated names and classes. See
74
- [code-style rules](../../docs/architecture/oxlint-config-code-style.md).
73
+ - Code style: function verbs, verb contracts, module order, file names, abbreviated names and
74
+ classes. See [code-style rules](../../docs/architecture/oxlint-config-code-style.md).
75
75
  - Test files: a test sits beside its module, holds only `setupTest()` and its tests, uses inline
76
76
  snapshots, keeps each timeout within its lane's limit, and waits on a condition, never a sleep.
77
77
  See [test-file rules](../../docs/architecture/oxlint-config-tests.md).
@@ -0,0 +1,177 @@
1
+ import { basename } from 'node:path';
2
+
3
+ const exemptBases = new Set(['index', 'types', 'constants']);
4
+
5
+ const fileNamedForExport = {
6
+ meta: {
7
+ type: 'suggestion',
8
+ messages: {
9
+ mismatch:
10
+ "No export of '{{file}}' is named for the file: name the main export '{{base}}' in camelCase, PascalCase or SCREAMING_SNAKE_CASE, or rename the file for its main export.",
11
+ },
12
+ schema: [],
13
+ },
14
+ create(context) {
15
+ return {
16
+ Program(program) {
17
+ const file = basename(context.physicalFilename);
18
+ const [base, ...suffixes] = file.split('.');
19
+
20
+ // a role suffix, such as `.config` or `.bench`, marks a file that a tool loads, and the
21
+ // tool sets its exports
22
+ if (suffixes.length !== 1 || exemptBases.has(base)) {
23
+ return;
24
+ }
25
+
26
+ const exports = collectExports(program.body);
27
+
28
+ if (exports.statements.length === 0 || exports.names === null) {
29
+ return;
30
+ }
31
+
32
+ const wanted = toComparableName(base);
33
+
34
+ if (exports.names.some((name) => toComparableName(name) === wanted)) {
35
+ return;
36
+ }
37
+
38
+ context.report({
39
+ node: exports.statements[0],
40
+ messageId: 'mismatch',
41
+ data: { file, base },
42
+ });
43
+ },
44
+ };
45
+ },
46
+ };
47
+
48
+ export default fileNamedForExport;
49
+
50
+ const exportTypes = new Set([
51
+ 'ExportNamedDeclaration',
52
+ 'ExportDefaultDeclaration',
53
+ 'ExportAllDeclaration',
54
+ 'TSExportAssignment',
55
+ ]);
56
+
57
+ // an `export * from` or an `export { default } from` hides the name it exports, so names is null
58
+ // and the file passes
59
+ function collectExports(body) {
60
+ const statements = body.filter(
61
+ (statement) => exportTypes.has(statement.type) && !isEmptyExport(statement),
62
+ );
63
+ const names = [];
64
+
65
+ for (const statement of statements) {
66
+ const exported = collectExportNames(statement);
67
+
68
+ if (exported === null) {
69
+ return { statements, names: null };
70
+ }
71
+
72
+ names.push(...exported);
73
+ }
74
+
75
+ return { statements, names };
76
+ }
77
+
78
+ // `export {}` only marks a script as a module
79
+ function isEmptyExport(statement) {
80
+ return (
81
+ statement.type === 'ExportNamedDeclaration' &&
82
+ statement.declaration === null &&
83
+ statement.specifiers.length === 0
84
+ );
85
+ }
86
+
87
+ function collectExportNames(statement) {
88
+ if (statement.type === 'ExportAllDeclaration') {
89
+ return statement.exported === null ? null : [toExportName(statement.exported)];
90
+ }
91
+
92
+ if (statement.type === 'TSExportAssignment') {
93
+ return collectValueNames(statement.expression);
94
+ }
95
+
96
+ if (statement.type === 'ExportDefaultDeclaration') {
97
+ return collectValueNames(statement.declaration);
98
+ }
99
+
100
+ if (statement.declaration !== null) {
101
+ return collectDeclarationNames(statement.declaration);
102
+ }
103
+
104
+ const names = statement.specifiers.map((specifier) => {
105
+ const exported = toExportName(specifier.exported);
106
+
107
+ return exported === 'default' ? toExportName(specifier.local) : exported;
108
+ });
109
+
110
+ return statement.source !== null && names.includes('default') ? null : names;
111
+ }
112
+
113
+ function toExportName(node) {
114
+ return node.type === 'Identifier' ? node.name : node.value;
115
+ }
116
+
117
+ const wrapperTypes = new Set(['TSAsExpression', 'TSSatisfiesExpression', 'TSNonNullExpression']);
118
+
119
+ function collectValueNames(value) {
120
+ if (wrapperTypes.has(value.type)) {
121
+ return collectValueNames(value.expression);
122
+ }
123
+
124
+ if (value.type === 'Identifier') {
125
+ return [value.name];
126
+ }
127
+
128
+ return value.id?.type === 'Identifier' ? [value.id.name] : [];
129
+ }
130
+
131
+ function collectDeclarationNames(declaration) {
132
+ if (declaration.type === 'VariableDeclaration') {
133
+ return declaration.declarations.flatMap((declarator) => collectPatternNames(declarator.id));
134
+ }
135
+
136
+ return declaration.id === null || declaration.id === undefined
137
+ ? []
138
+ : [toRootName(declaration.id)];
139
+ }
140
+
141
+ function collectPatternNames(pattern) {
142
+ if (pattern.type === 'Identifier') {
143
+ return [pattern.name];
144
+ }
145
+
146
+ if (pattern.type === 'ObjectPattern') {
147
+ return pattern.properties.flatMap((property) => {
148
+ const target = property.type === 'RestElement' ? property.argument : property.value;
149
+
150
+ return collectPatternNames(target);
151
+ });
152
+ }
153
+
154
+ if (pattern.type === 'ArrayPattern') {
155
+ return pattern.elements.flatMap((element) =>
156
+ element === null ? [] : collectPatternNames(element),
157
+ );
158
+ }
159
+
160
+ if (pattern.type === 'AssignmentPattern') {
161
+ return collectPatternNames(pattern.left);
162
+ }
163
+
164
+ return pattern.type === 'RestElement' ? collectPatternNames(pattern.argument) : [];
165
+ }
166
+
167
+ function toRootName(name) {
168
+ if (name.type === 'TSQualifiedName') {
169
+ return toRootName(name.left);
170
+ }
171
+
172
+ return toExportName(name);
173
+ }
174
+
175
+ function toComparableName(name) {
176
+ return name.replaceAll(/[-_]/gu, '').toLowerCase();
177
+ }
@@ -0,0 +1,2 @@
1
+ export { default as collectRefusingEdges } from '../collect-refusing-edges.js';
2
+ export { default as importZonesSchema } from '../import-zones-schema.js';
package/oxlintrc.json CHANGED
@@ -45,6 +45,7 @@
45
45
  "zgeoff/feature-folders": "error",
46
46
  "zgeoff/seed-only": "error",
47
47
  "zgeoff/test-beside-seed": "error",
48
+ "zgeoff/file-named-for-export": "error",
48
49
 
49
50
  // name a value for what it holds, in full words: one letter only for a
50
51
  // coordinate, zod's `z`, Bun's shell `$` or an unread `_` placeholder, and
@@ -156,7 +157,7 @@
156
157
  "unicorn/no-useless-undefined": ["error", { "checkArguments": false }],
157
158
  "unicorn/no-null": "off",
158
159
  "unicorn/number-literal-case": "off",
159
- "unicorn/filename-case": "off",
160
+ "unicorn/filename-case": ["error", { "case": "kebabCase" }],
160
161
 
161
162
  // one declaration per variable; a declaration list has no order to sort
162
163
  "one-var": ["error", "never"],
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zgeoff/oxlint-config",
3
- "version": "0.10.1",
3
+ "version": "0.10.2",
4
4
  "description": "Shareable oxlint config: strict categories, house-style rules, and a custom JS plugin",
5
5
  "license": "MIT",
6
6
  "repository": {
@@ -28,10 +28,10 @@
28
28
  "no-jsdoc.js",
29
29
  "no-comment-rule-override.js",
30
30
  "no-hidden-cast.js",
31
- "test-beside-module.js",
31
+ "build-test-beside-module.js",
32
32
  "no-file-snapshot.js",
33
33
  "setup-test-only.js",
34
- "max-test-timeout.js",
34
+ "build-max-test-timeout.js",
35
35
  "test-timeout-exception-ticket.js",
36
36
  "build-lane-limits.js",
37
37
  "read-rig-lanes.js",
@@ -47,8 +47,8 @@
47
47
  "find-static-key.js",
48
48
  "import-zones.js",
49
49
  "import-zones-schema.js",
50
- "import-zones-entry.js",
51
- "import-zones-entry.d.ts",
50
+ "import-zones/index.js",
51
+ "import-zones/index.d.ts",
52
52
  "collect-refusing-edges.js",
53
53
  "is-edge-refusing.js",
54
54
  "is-entry-applying.js",
@@ -70,8 +70,9 @@
70
70
  "read-stale-pending.js",
71
71
  "read-package-manifest.js",
72
72
  "read-module-paths.js",
73
- "seed-only.js",
73
+ "build-seed-only.js",
74
74
  "test-beside-seed.js",
75
+ "file-named-for-export.js",
75
76
  "read-folder-sources.js",
76
77
  "collect-written-tables.js",
77
78
  "collect-sql-writes.js",
@@ -87,8 +88,8 @@
87
88
  "./react.json": "./react.json",
88
89
  "./plugin": "./plugin.js",
89
90
  "./import-zones": {
90
- "types": "./import-zones-entry.d.ts",
91
- "default": "./import-zones-entry.js"
91
+ "types": "./import-zones/index.d.ts",
92
+ "default": "./import-zones/index.js"
92
93
  }
93
94
  },
94
95
  "publishConfig": {
@@ -102,7 +103,7 @@
102
103
  },
103
104
  "devDependencies": {
104
105
  "@types/bun": "1.4.4",
105
- "@zgeoff/rig": "0.2.1",
106
+ "@zgeoff/rig": "0.2.2",
106
107
  "@zgeoff/std": "0.4.3",
107
108
  "@zgeoff/testing": "0.3.0",
108
109
  "tsrs": "0.18.0-ts7.1.0-dev.20260929",
package/plugin.js CHANGED
@@ -2,11 +2,14 @@ import { existsSync } from 'node:fs';
2
2
  // oxlint-disable-next-line zgeoff/no-require -- only resolves rig's path from the repo root; an import loads it
3
3
  import { createRequire } from 'node:module';
4
4
  import { join } from 'node:path';
5
+ import buildMaxTestTimeout from './build-max-test-timeout.js';
6
+ import buildSeedOnly from './build-seed-only.js';
7
+ import buildTestBesideModule from './build-test-beside-module.js';
5
8
  import featureFolders from './feature-folders.js';
9
+ import fileNamedForExport from './file-named-for-export.js';
6
10
  import functionVerb from './function-verb.js';
7
11
  import importZones from './import-zones.js';
8
12
  import maxConsecutiveLineComments from './max-consecutive-line-comments.js';
9
- import buildMaxTestTimeout from './max-test-timeout.js';
10
13
  import moduleOrder from './module-order.js';
11
14
  import noAbbreviatedNames from './no-abbreviated-names.js';
12
15
  import noClass from './no-class.js';
@@ -20,9 +23,7 @@ import noTestSleep from './no-test-sleep.js';
20
23
  import readFolderSources from './read-folder-sources.js';
21
24
  import readRigLanes from './read-rig-lanes.js';
22
25
  import resolveRepoRoot from './resolve-repo-root.js';
23
- import buildSeedOnly from './seed-only.js';
24
26
  import setupTestOnly from './setup-test-only.js';
25
- import buildTestBesideModule from './test-beside-module.js';
26
27
  import testBesideSeed from './test-beside-seed.js';
27
28
  import testShape from './test-shape.js';
28
29
  import testTimeoutExceptionTicket from './test-timeout-exception-ticket.js';
@@ -138,6 +139,7 @@ const plugin = {
138
139
  'feature-folders': featureFolders,
139
140
  'seed-only': buildSeedOnly(readFolderSources),
140
141
  'test-beside-seed': testBesideSeed,
142
+ 'file-named-for-export': fileNamedForExport,
141
143
  },
142
144
  };
143
145
 
@@ -1,2 +0,0 @@
1
- export { default as collectRefusingEdges } from './collect-refusing-edges.js';
2
- export { default as importZonesSchema } from './import-zones-schema.js';
File without changes