@zgeoff/oxlint-config 0.3.0 → 0.5.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.
@@ -1,6 +1,6 @@
1
1
  import { readFileSync, readdirSync } from 'node:fs';
2
2
  import { join } from 'node:path';
3
- import findRepoRoot from './find-repo-root.js';
3
+ import resolveRepoRoot from './resolve-repo-root.js';
4
4
 
5
5
  // every repo runs the comment rules exactly as this config ships them
6
6
  const lockedRules = ['zgeoff/no-jsdoc', 'zgeoff/max-consecutive-line-comments'];
@@ -47,7 +47,7 @@ const noCommentRuleOverride = {
47
47
  schema: [],
48
48
  },
49
49
  create(context) {
50
- const root = findRepoRoot(context.filename);
50
+ const root = resolveRepoRoot(context.filename);
51
51
 
52
52
  if (root === null) {
53
53
  return {};
@@ -33,7 +33,7 @@ const noFileSnapshot = {
33
33
  const filename = context.physicalFilename;
34
34
  const name = `${basename(filename)}.snap`;
35
35
 
36
- if (!isFile(join(dirname(filename), '__snapshots__', name))) {
36
+ if (!probeFile(join(dirname(filename), '__snapshots__', name))) {
37
37
  return;
38
38
  }
39
39
 
@@ -51,7 +51,7 @@ function getMatcherName(node) {
51
51
  return node.type === 'Identifier' ? node.name : node.value;
52
52
  }
53
53
 
54
- function isFile(path) {
54
+ function probeFile(path) {
55
55
  return statSync(path, { throwIfNoEntry: false })?.isFile() ?? false;
56
56
  }
57
57
 
package/oxlintrc.json CHANGED
@@ -31,6 +31,8 @@
31
31
  "zgeoff/max-consecutive-line-comments": ["error", { "max": 3 }],
32
32
  "zgeoff/no-comment-rule-override": "error",
33
33
  "zgeoff/function-verb": "error",
34
+ "zgeoff/verb-contract": "error",
35
+ "zgeoff/module-order": "error",
34
36
  "zgeoff/test-beside-module": "error",
35
37
  "zgeoff/no-file-snapshot": "error",
36
38
  "zgeoff/setup-test-only": "error",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zgeoff/oxlint-config",
3
- "version": "0.3.0",
3
+ "version": "0.5.0",
4
4
  "description": "Shareable oxlint config: strict categories, house-style rules, and a custom JS plugin",
5
5
  "license": "MIT",
6
6
  "repository": {
@@ -12,6 +12,13 @@
12
12
  "oxlintrc.json",
13
13
  "plugin.js",
14
14
  "function-verb.js",
15
+ "verb-contract.js",
16
+ "module-order.js",
17
+ "collect-module-entries.js",
18
+ "build-module-order-fix.js",
19
+ "is-static-value.js",
20
+ "find-function-name.js",
21
+ "is-verb-match.js",
15
22
  "no-restricted-words.js",
16
23
  "no-abbreviated-names.js",
17
24
  "max-consecutive-line-comments.js",
@@ -23,7 +30,7 @@
23
30
  "setup-test-only.js",
24
31
  "import-zones.js",
25
32
  "import-zones-schema.js",
26
- "find-repo-root.js",
33
+ "resolve-repo-root.js",
27
34
  "load-workspace-manifests.js",
28
35
  "load-zone-options.js",
29
36
  "make-glob-matcher.js",
package/plugin.js CHANGED
@@ -1,6 +1,7 @@
1
1
  import functionVerb from './function-verb.js';
2
2
  import importZones from './import-zones.js';
3
3
  import maxConsecutiveLineComments from './max-consecutive-line-comments.js';
4
+ import moduleOrder from './module-order.js';
4
5
  import noAbbreviatedNames from './no-abbreviated-names.js';
5
6
  import noClass from './no-class.js';
6
7
  import noCommentRuleOverride from './no-comment-rule-override.js';
@@ -9,6 +10,7 @@ import noJSDoc from './no-jsdoc.js';
9
10
  import noRestrictedWords from './no-restricted-words.js';
10
11
  import setupTestOnly from './setup-test-only.js';
11
12
  import testBesideModule from './test-beside-module.js';
13
+ import verbContract from './verb-contract.js';
12
14
 
13
15
  // custom rules loaded through oxlint's jsPlugins (ESLint v9 rule API): each
14
16
  // bans a shape no native oxlint rule can express, as an esquery selector or a
@@ -110,6 +112,8 @@ const plugin = {
110
112
  'max-consecutive-line-comments': maxConsecutiveLineComments,
111
113
  'no-comment-rule-override': noCommentRuleOverride,
112
114
  'function-verb': functionVerb,
115
+ 'verb-contract': verbContract,
116
+ 'module-order': moduleOrder,
113
117
  'no-restricted-words': noRestrictedWords,
114
118
  'no-abbreviated-names': noAbbreviatedNames,
115
119
  'test-beside-module': testBesideModule,
@@ -10,10 +10,10 @@ const sourceExtensions = { '.js': ['.ts', '.tsx'], '.mjs': ['.mts'], '.cjs': ['.
10
10
  // names through `imports`, and a workspace name to a path in its folder.
11
11
  export default function resolveImportTarget(filename, specifier, settings) {
12
12
  if (isPathSpecifier(specifier)) {
13
- return toTarget(findImportedFile(filename, toFileSpecifier(specifier), settings.extensions));
13
+ return toTarget(resolveImportedFile(filename, toFileSpecifier(specifier), settings.extensions));
14
14
  }
15
15
 
16
- const manifest = findPackageManifest(dirname(filename), settings.root);
16
+ const manifest = readPackageManifest(dirname(filename), settings.root);
17
17
 
18
18
  return resolveManifestTarget(manifest, specifier, settings);
19
19
  }
@@ -107,7 +107,7 @@ function isPathSpecifier(specifier) {
107
107
 
108
108
  const manifests = new Map();
109
109
 
110
- function findPackageManifest(dir, root) {
110
+ function readPackageManifest(dir, root) {
111
111
  if (manifests.has(dir)) {
112
112
  return manifests.get(dir);
113
113
  }
@@ -119,7 +119,7 @@ function findPackageManifest(dir, root) {
119
119
  if (existsSync(path)) {
120
120
  manifest = { dir, ...JSON.parse(readFileSync(path, 'utf8')) };
121
121
  } else if (dir !== root && parent !== dir) {
122
- manifest = findPackageManifest(parent, root);
122
+ manifest = readPackageManifest(parent, root);
123
123
  }
124
124
 
125
125
  manifests.set(dir, manifest);
@@ -211,7 +211,7 @@ function findConditionTarget(value, conditions) {
211
211
  );
212
212
  }
213
213
 
214
- function findImportedFile(filename, specifier, extensions) {
214
+ function resolveImportedFile(filename, specifier, extensions) {
215
215
  const base = resolve(dirname(filename), specifier);
216
216
  const swapped = Object.keys(sourceExtensions).flatMap((ext) =>
217
217
  base.endsWith(ext)
@@ -226,9 +226,9 @@ function findImportedFile(filename, specifier, extensions) {
226
226
  ...extensions.map((ext) => join(base, `index${ext}`)),
227
227
  ];
228
228
 
229
- return candidates.find((candidate) => isFile(candidate)) ?? null;
229
+ return candidates.find((candidate) => probeFile(candidate)) ?? null;
230
230
  }
231
231
 
232
- function isFile(path) {
232
+ function probeFile(path) {
233
233
  return statSync(path, { throwIfNoEntry: false })?.isFile() ?? false;
234
234
  }
@@ -3,7 +3,7 @@ import { dirname, join } from 'node:path';
3
3
 
4
4
  // the nearest ancestor holding `.git` (a directory, or a worktree's file), or
5
5
  // null outside a repository
6
- export default function findRepoRoot(filename) {
6
+ export default function resolveRepoRoot(filename) {
7
7
  let dir = dirname(filename);
8
8
 
9
9
  while (!existsSync(join(dir, '.git'))) {
@@ -1,6 +1,6 @@
1
1
  import { readdirSync, statSync } from 'node:fs';
2
2
  import { basename, dirname, join, relative, sep } from 'node:path';
3
- import findRepoRoot from './find-repo-root.js';
3
+ import resolveRepoRoot from './resolve-repo-root.js';
4
4
 
5
5
  const testFilePattern = /^(?<base>.+)\.test\.tsx?$/u;
6
6
 
@@ -10,7 +10,7 @@ const exemptRootDirs = new Set(['e2e', 'evals']);
10
10
  // the repo root, not oxlint's working directory, so a per-package lint
11
11
  // script neither exempts a package's own e2e/ nor flags the root one
12
12
  function isUnderExemptRoot(cwd, filename) {
13
- const [first] = relative(findRepoRoot(filename) ?? cwd, filename).split(sep);
13
+ const [first] = relative(resolveRepoRoot(filename) ?? cwd, filename).split(sep);
14
14
 
15
15
  return exemptRootDirs.has(first);
16
16
  }
@@ -18,7 +18,7 @@ function isUnderExemptRoot(cwd, filename) {
18
18
  // a module is `<name>.<ext>` with a single-segment extension, so a
19
19
  // declaration file never stands in for one, and neither does another test
20
20
  // (`foo.test.ts` beside `foo.test.test.ts`)
21
- function hasModuleSibling(dir, name) {
21
+ function probeModuleSibling(dir, name) {
22
22
  return readdirSync(dir).some((entry) => {
23
23
  const dot = entry.lastIndexOf('.');
24
24
 
@@ -26,13 +26,13 @@ function hasModuleSibling(dir, name) {
26
26
  dot > 0 &&
27
27
  entry.slice(0, dot) === name &&
28
28
  !testFilePattern.test(entry) &&
29
- isFile(join(dir, entry))
29
+ probeFile(join(dir, entry))
30
30
  );
31
31
  });
32
32
  }
33
33
 
34
34
  // follows a symlink, so a linked module counts as the file it points at
35
- function isFile(path) {
35
+ function probeFile(path) {
36
36
  return statSync(path, { throwIfNoEntry: false })?.isFile() ?? false;
37
37
  }
38
38
 
@@ -57,7 +57,7 @@ const testBesideModule = {
57
57
 
58
58
  const name = match.groups.base;
59
59
 
60
- if (hasModuleSibling(dirname(filename), name)) {
60
+ if (probeModuleSibling(dirname(filename), name)) {
61
61
  return;
62
62
  }
63
63