@crutchcrew/oxlint-plugin-import-access 0.0.0-stage → 1.0.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.
@@ -0,0 +1,9 @@
1
+ import type { CreateOnceRule } from "@oxlint/plugins";
2
+ import { ImportabilityChecker } from "../core/checkImportability.js";
3
+ /**
4
+ * Process-wide caches shared by every file and every options object.
5
+ */
6
+ export declare const checker: ImportabilityChecker;
7
+ declare const rule: CreateOnceRule;
8
+ /** @public */
9
+ export default rule;
@@ -0,0 +1,8 @@
1
+ import type { Tag } from "./jsdoc.js";
2
+ import type { Importability } from "./options.js";
3
+ /**
4
+ * Access level declared by JSDoc tags: the first of `@package`, `@private`, `@public`
5
+ * or `@access <level>` wins, otherwise `defaultImportability`.
6
+ * @public
7
+ */
8
+ export declare function getAccessOfJsDocs(tags: readonly Tag[], defaultImportability: Importability): Importability;
@@ -0,0 +1,19 @@
1
+ import type { PackageOptions } from "./options.js";
2
+ /**
3
+ * Decides which directory is the "package" of a file and whether two files share a package.
4
+ * Create one per options object: it memoizes per-directory answers.
5
+ * @public
6
+ */
7
+ export declare class PackageBoundaries {
8
+ #private;
9
+ constructor(options: PackageOptions);
10
+ /**
11
+ * The package directory of a file: its own directory, or with `packageDirectory` patterns,
12
+ * the closest ancestor directory that is a package boundary.
13
+ */
14
+ packageDirectoryOf(filePath: string): string;
15
+ /**
16
+ * Whether `importer` is in the same package as `exporter`, or in a descendant package.
17
+ */
18
+ isInPackage(importer: string, exporter: string): boolean;
19
+ }
@@ -0,0 +1,46 @@
1
+ /**
2
+ * A JSDoc tag such as `@package` or `@access package`.
3
+ * @public
4
+ */
5
+ export type Tag = {
6
+ readonly name: string;
7
+ readonly text: string;
8
+ };
9
+ /**
10
+ * Minimal comment shape shared by oxc-parser and oxlint's `sourceCode`.
11
+ * `value` excludes the `/*` and `*\/` delimiters.
12
+ * @public
13
+ */
14
+ export type Comment = {
15
+ readonly type: "Line" | "Block";
16
+ readonly value: string;
17
+ readonly start: number;
18
+ readonly end: number;
19
+ };
20
+ /**
21
+ * Find the JSDoc comments attached to a node starting at `nodeStart`, following TypeScript's rules:
22
+ *
23
+ * - only block comments starting with `/**` (but not the empty `/**\/`) count,
24
+ * - they must sit in the trivia between the previous token and the node,
25
+ * - for statements, comments on the same line as the previous token belong to that token
26
+ * (`includeSameLine: false`); export specifiers and variable declarators take them too.
27
+ */
28
+ export declare function findJsDocComments(sourceText: string, comments: readonly Comment[], nodeStart: number, includeSameLine?: boolean): Comment[];
29
+ /**
30
+ * Parse the block tags of a JSDoc comment the way TypeScript does.
31
+ *
32
+ * A tag starts with `@` followed by its name, at the beginning of a line (after the optional `*`
33
+ * margin) or after a space or tab, but not inside backticks. Its text runs until the next tag.
34
+ */
35
+ export declare function parseJsDocTags(comment: Comment): Tag[];
36
+ /**
37
+ * Tags as TypeScript reports them for a node: `symbol.getJsDocTags()` only sees the last JSDoc block
38
+ * (`own`), while the declaration's `jsDoc` holds every block (`all`).
39
+ * @public
40
+ */
41
+ export type NodeTags = {
42
+ readonly own: readonly Tag[];
43
+ readonly all: readonly Tag[];
44
+ };
45
+ /** @public */
46
+ export declare function jsDocTagsAt(sourceText: string, comments: readonly Comment[], nodeStart: number, includeSameLine?: boolean): NodeTags;
@@ -0,0 +1,55 @@
1
+ /** @public */
2
+ export type Importability = "public" | "package" | "private";
3
+ /**
4
+ * Options of the `import-access/jsdoc` rule.
5
+ * @public
6
+ */
7
+ export type JSDocRuleOptions = {
8
+ /**
9
+ * Allow importing package-private exports from `index.ts` in a subdirectory,
10
+ * as if `sub/index.ts` were `sub.ts`.
11
+ * @default true
12
+ */
13
+ indexLoophole: boolean;
14
+ /**
15
+ * Allow `foo.ts` to import package-private exports from files in `foo/`.
16
+ * @default false
17
+ */
18
+ filenameLoophole: boolean;
19
+ /**
20
+ * Importability of exports that have no access tag in their JSDoc.
21
+ * @default "package"
22
+ */
23
+ defaultImportability: Importability;
24
+ /**
25
+ * How to treat imports that use the package's own name (Node.js self-reference).
26
+ * `external` skips the check like for any other package; `internal` checks them.
27
+ * @default "external"
28
+ */
29
+ treatSelfReferenceAs: "internal" | "external";
30
+ /**
31
+ * Glob patterns, relative to the working directory, of exporter files to skip.
32
+ * Useful for generated code.
33
+ * @default []
34
+ */
35
+ excludeSourcePatterns: readonly string[];
36
+ /**
37
+ * Glob patterns of directories that are package boundaries. By default every directory is one.
38
+ * Negated patterns (`"!**\/_internal"`) exclude directories, which then belong to their parent package.
39
+ */
40
+ packageDirectory?: readonly string[] | undefined;
41
+ };
42
+ /**
43
+ * Resolved options used by the importability check.
44
+ * @public
45
+ */
46
+ export type PackageOptions = Readonly<JSDocRuleOptions> & {
47
+ /** Base directory for relative glob patterns. */
48
+ readonly projectDirectory: string;
49
+ };
50
+ export declare const defaultOptions: JSDocRuleOptions;
51
+ /**
52
+ * Fill in defaults for user-provided options.
53
+ * @public
54
+ */
55
+ export declare function normalizeOptions(options: Partial<JSDocRuleOptions> | undefined, projectDirectory: string): PackageOptions;
package/package.json CHANGED
@@ -1,6 +1,102 @@
1
1
  {
2
- "name": "@crutchcrew/oxlint-plugin-import-access",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
2
+ "name": "@crutchcrew/oxlint-plugin-import-access",
3
+ "version": "1.0.0",
4
+ "description": "Oxlint JS plugin for import access via JSDoc @public, @package and @private, without a type checker",
5
+ "keywords": [
6
+ "import-access",
7
+ "jsdoc",
8
+ "oxlint",
9
+ "oxlint-plugin",
10
+ "package-private",
11
+ "typescript"
12
+ ],
13
+ "homepage": "https://github.com/crutchcrew/oxlint-plugin-import-access#readme",
14
+ "bugs": {
15
+ "url": "https://github.com/crutchcrew/oxlint-plugin-import-access/issues"
16
+ },
17
+ "license": "MIT",
18
+ "repository": {
19
+ "type": "git",
20
+ "url": "git+https://github.com/crutchcrew/oxlint-plugin-import-access.git"
21
+ },
22
+ "workspaces": [
23
+ "src/__tests__/fixtures/packages/workspaces/*"
24
+ ],
25
+ "files": [
26
+ "dist"
27
+ ],
28
+ "type": "module",
29
+ "sideEffects": false,
30
+ "main": "dist/index.js",
31
+ "types": "dist/index.d.ts",
32
+ "exports": {
33
+ ".": {
34
+ "types": "./dist/index.d.ts",
35
+ "import": "./dist/index.js"
36
+ },
37
+ "./package.json": "./package.json"
38
+ },
39
+ "scripts": {
40
+ "bench": "bun bench/run.ts",
41
+ "build": "bun run --parallel build:compile build:declaration",
42
+ "build:compile": "bun build src/index.ts --outdir dist --format esm --target node --packages external",
43
+ "build:declaration": "tsc -p tsconfig.build.json && bun scripts/fix-dts-extensions.ts",
44
+ "check": "bun run --parallel fmt:check lint lockfile:check",
45
+ "fmt": "oxfmt --write .",
46
+ "fmt:check": "oxfmt --check .",
47
+ "lint": "oxlint",
48
+ "lint:fix": "oxlint --fix",
49
+ "lockfile:check": "bun install --frozen-lockfile",
50
+ "prebuild": "rm -rf dist",
51
+ "prepare": "lefthook install",
52
+ "prepublishOnly": "bun run build",
53
+ "test": "vitest run --project unit",
54
+ "test:coverage": "vitest run --project unit --coverage",
55
+ "test:e2e": "vitest run --project e2e"
56
+ },
57
+ "dependencies": {
58
+ "minimatch": "^10.2.6",
59
+ "oxc-parser": "^0.155.0",
60
+ "oxc-resolver": "^11.24.2"
61
+ },
62
+ "devDependencies": {
63
+ "@fixture-package-third-party/has-sub-module": "file:src/__tests__/fixtures/packages/third-party/has-sub-module",
64
+ "@fixture-package-third-party/missing-entrypoint": "file:src/__tests__/fixtures/packages/third-party/missing-entrypoint",
65
+ "@fixture-package-third-party/with-exports-field": "file:src/__tests__/fixtures/packages/third-party/with-exports-field",
66
+ "@fixture-package-workspace/has-sub-module": "workspace:*",
67
+ "@fixture-package-workspace/missing-entrypoint": "workspace:*",
68
+ "@fixture-package-workspace/with-exports-field": "workspace:*",
69
+ "@oxlint/plugins": "^1.89.0",
70
+ "@types/node": "^24.13.3",
71
+ "@vitest/coverage-v8": "^5.0.5",
72
+ "lefthook": "^2.2.2",
73
+ "oxfmt": "^0.74.0",
74
+ "oxlint": "^1.89.0",
75
+ "oxlint-tsgolint": "^7.0.2005",
76
+ "typescript": "^7.0.2",
77
+ "vitest": "^5.0.5"
78
+ },
79
+ "peerDependencies": {
80
+ "oxlint": ">=1.40.0"
81
+ },
82
+ "devEngines": {
83
+ "packageManager": {
84
+ "name": "bun",
85
+ "onFail": "warn"
86
+ },
87
+ "runtime": [
88
+ {
89
+ "name": "bun",
90
+ "onFail": "warn"
91
+ },
92
+ {
93
+ "name": "node",
94
+ "version": ">=22.18.0",
95
+ "onFail": "warn"
96
+ }
97
+ ]
98
+ },
99
+ "engines": {
100
+ "node": "^20.19.0 || >=22.12.0"
101
+ }
102
+ }