@vvedantb/config 0.4.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.
@@ -0,0 +1,86 @@
1
+ import { isIdentifier } from "../utils.mjs";
2
+
3
+ const strictMessage =
4
+ "Do not assign a bare `JSON.parse(...)` result — it is `any` and flows " +
5
+ "unchecked. Validate at the boundary: `schema.safeParse(JSON.parse(x))` or " +
6
+ "`schema.parse(JSON.parse(x))`.";
7
+
8
+ const lenientMessage =
9
+ strictMessage +
10
+ " Or annotate the result `: unknown` (or `as unknown`) so downstream code " +
11
+ "must narrow it.";
12
+
13
+ const isJsonParse = (node) =>
14
+ node?.type === "CallExpression" &&
15
+ node.callee?.type === "MemberExpression" &&
16
+ isIdentifier(node.callee.object, "JSON") &&
17
+ isIdentifier(node.callee.property, "parse");
18
+
19
+ const isUnknownKeyword = (node) => node?.type === "TSUnknownKeyword";
20
+
21
+ /**
22
+ * Flags a bare `JSON.parse(...)` whose `any` result flows unchecked.
23
+ *
24
+ * Always allowed: wrapping in a schema parse (`schema.safeParse(JSON.parse(x))`
25
+ * or `schema.parse(JSON.parse(x))`). With `allowUnknownEscapeHatch: true`, a
26
+ * `: unknown` annotation or `as unknown` cast is also allowed (vmem's original
27
+ * behaviour); the default is strict (eva's), where `unknown` is not an escape.
28
+ */
29
+ export default {
30
+ meta: {
31
+ type: "problem",
32
+ docs: { description: strictMessage },
33
+ schema: [
34
+ {
35
+ type: "object",
36
+ properties: { allowUnknownEscapeHatch: { type: "boolean" } },
37
+ additionalProperties: false,
38
+ },
39
+ ],
40
+ },
41
+ create(context) {
42
+ const allowUnknown = context.options?.[0]?.allowUnknownEscapeHatch === true;
43
+ const message = allowUnknown ? lenientMessage : strictMessage;
44
+ // JSON.parse nodes that sit in a disciplined position. Enclosing nodes are
45
+ // visited before the inner JSON.parse (top-down), so this is populated in
46
+ // time for the check below.
47
+ const allowed = new Set();
48
+ const allow = (node) => {
49
+ if (isJsonParse(node)) allowed.add(node);
50
+ };
51
+
52
+ const visitors = {
53
+ CallExpression(node) {
54
+ const callee = node.callee;
55
+ // `schema.safeParse(JSON.parse(...))` / `schema.parse(JSON.parse(...))`
56
+ if (
57
+ callee?.type === "MemberExpression" &&
58
+ !isIdentifier(callee.object, "JSON") &&
59
+ (isIdentifier(callee.property, "safeParse") ||
60
+ isIdentifier(callee.property, "parse"))
61
+ ) {
62
+ for (const arg of node.arguments ?? []) allow(arg);
63
+ }
64
+
65
+ if (isJsonParse(node) && !allowed.has(node)) {
66
+ context.report({ node, message });
67
+ }
68
+ },
69
+ };
70
+
71
+ if (allowUnknown) {
72
+ // `const x: unknown = JSON.parse(...)`
73
+ visitors.VariableDeclarator = (node) => {
74
+ if (isUnknownKeyword(node.id?.typeAnnotation?.typeAnnotation)) {
75
+ allow(node.init);
76
+ }
77
+ };
78
+ // `JSON.parse(...) as unknown`
79
+ visitors.TSAsExpression = (node) => {
80
+ if (isUnknownKeyword(node.typeAnnotation)) allow(node.expression);
81
+ };
82
+ }
83
+
84
+ return visitors;
85
+ },
86
+ };
@@ -0,0 +1,78 @@
1
+ /**
2
+ * Message shown when a test reads a repo source file. Written as an
3
+ * instruction to whoever (human or agent) is editing the test.
4
+ */
5
+ const message =
6
+ "BANNED: tests that read source files as text. A regex over source breaks " +
7
+ "on every refactor and passes on real logic bugs. Import the code and assert " +
8
+ "on what it returns or does. If the rule is about code shape, write a lint " +
9
+ "rule instead.";
10
+
11
+ const TEST_FILE =
12
+ /(\.(test|spec)\.[cm]?[jt]sx?$)|(\/__tests__\/)|(\/tests\/[^/]+\.[cm]?[jt]sx?$)/;
13
+ /** A path or file name ending in a source extension, not a bare extension. */
14
+ const SOURCE_PATH = /[^/.][^/]*\.(ts|tsx|mts|css|html)$/;
15
+ /** File reads, plus helpers that wrap them (`read`, `readSource`, `sourceOf`). */
16
+ const READ_CALL = /^(read|source)|Source$/;
17
+
18
+ function calleeName(call) {
19
+ const callee = call.callee;
20
+ if (callee.type === "Identifier") return callee.name;
21
+ if (callee.type === "MemberExpression" && callee.property.type === "Identifier") {
22
+ return callee.property.name;
23
+ }
24
+ return "";
25
+ }
26
+
27
+ /** True when the string is (part of) an argument to a file-read call. */
28
+ function isReadArgument(node) {
29
+ let child = node;
30
+ for (let parent = node.parent; parent; parent = parent.parent) {
31
+ if (
32
+ parent.type === "CallExpression" &&
33
+ parent.callee !== child &&
34
+ READ_CALL.test(calleeName(parent))
35
+ ) {
36
+ return true;
37
+ }
38
+ if (parent.type.endsWith("Statement") || parent.type === "VariableDeclarator") {
39
+ return false;
40
+ }
41
+ child = parent;
42
+ }
43
+ return false;
44
+ }
45
+
46
+ /**
47
+ * Flags a source file name (`foo.ts`, `src/app.css`, `index.html`) passed to a
48
+ * file read in a test file: `readFileSync(join(dir, "x.ts"))`, or a
49
+ * wrapper such as `readSource("x.ts")`. Plain path strings used as test data
50
+ * stay allowed, because file paths are handled as data elsewhere.
51
+ */
52
+ export default {
53
+ meta: {
54
+ type: "problem",
55
+ docs: { description: message },
56
+ },
57
+ create(context) {
58
+ const filename = (context.filename ?? context.getFilename?.() ?? "").replaceAll(
59
+ "\\",
60
+ "/",
61
+ );
62
+ if (!TEST_FILE.test(filename)) return {};
63
+ const check = (node, value) => {
64
+ if (SOURCE_PATH.test(value) && isReadArgument(node)) {
65
+ context.report({ message, node });
66
+ }
67
+ };
68
+ return {
69
+ Literal(node) {
70
+ if (typeof node.value === "string") check(node, node.value);
71
+ },
72
+ TemplateLiteral(node) {
73
+ const last = node.quasis[node.quasis.length - 1];
74
+ if (last) check(node, last.value.cooked ?? last.value.raw);
75
+ },
76
+ };
77
+ },
78
+ };
@@ -0,0 +1,165 @@
1
+ const bailoutPreamble =
2
+ "React Compiler bails on the ENTIRE FILE here, so every component in it " +
3
+ "silently loses memoization with no build error. ";
4
+
5
+ const valueBlockMessage =
6
+ bailoutPreamble +
7
+ "It cannot compile expression-level control flow inside a `try` block. " +
8
+ "Use statement-level control flow instead: `if`/`else` rather than `?:` " +
9
+ "and `&&`/`||`/`??`, `if (fn) fn()` rather than `fn?.()`. Or move the " +
10
+ "expression above the `try`, or into a helper function called from it. " +
11
+ "`catch` bodies, nested functions, `if`/`else` and `switch` are all fine.";
12
+
13
+ const finallyMessage =
14
+ bailoutPreamble +
15
+ "It cannot compile a `finally` clause at all, whatever the contents. " +
16
+ "Duplicate the cleanup into the `catch` and after the `try`, or move the " +
17
+ "whole `try` into a helper function.";
18
+
19
+ const throwMessage =
20
+ bailoutPreamble +
21
+ "It cannot compile a `throw` inside a `try` block. Handle the failure in " +
22
+ "place with `if`/`else` instead of throwing to your own catch, or validate " +
23
+ "and throw above the `try`. Throwing from a `catch` body is fine.";
24
+
25
+ const noCatchMessage =
26
+ bailoutPreamble +
27
+ "It cannot compile a `try` without a `catch`. Add a `catch` clause — use " +
28
+ "`catch { }` if there is genuinely nothing to handle.";
29
+
30
+ /** Value blocks: expression-level control flow the compiler cannot lower here. */
31
+ const VALUE_BLOCKS = new Set([
32
+ "ConditionalExpression",
33
+ "LogicalExpression",
34
+ "ChainExpression",
35
+ ]);
36
+
37
+ /** Loops bail too — their test expression is itself lowered as a value block. */
38
+ const LOOPS = new Set([
39
+ "ForStatement",
40
+ "ForInStatement",
41
+ "ForOfStatement",
42
+ "WhileStatement",
43
+ "DoWhileStatement",
44
+ ]);
45
+
46
+ /** `&&=` / `||=` / `??=` desugar to a value block just like their operators. */
47
+ const LOGICAL_ASSIGN = new Set(["&&=", "||=", "??="]);
48
+
49
+ const FUNCTIONS = new Set([
50
+ "FunctionDeclaration",
51
+ "FunctionExpression",
52
+ "ArrowFunctionExpression",
53
+ ]);
54
+
55
+ /** Wrappers that keep the component name on the outer binding. */
56
+ const NAME_PRESERVING_CALLS = new Set(["memo", "forwardRef", "observer"]);
57
+
58
+ /** React Compiler only lowers components (`Foo`) and hooks (`useFoo`). */
59
+ const isCompiledName = (name) =>
60
+ typeof name === "string" && /^(use[A-Z]|[A-Z])/.test(name);
61
+
62
+ function isOffending(node) {
63
+ if (VALUE_BLOCKS.has(node.type)) return true;
64
+ if (LOOPS.has(node.type)) return true;
65
+ if (node.type === "AssignmentExpression") return LOGICAL_ASSIGN.has(node.operator);
66
+ // Optional chaining, when the parser emits no wrapping ChainExpression.
67
+ if (node.type === "MemberExpression" || node.type === "CallExpression")
68
+ return node.optional === true;
69
+ return false;
70
+ }
71
+
72
+ /** Generic child iteration, so no per-node-type traversal table is needed. */
73
+ function* children(node) {
74
+ for (const key of Object.keys(node)) {
75
+ if (key === "parent") continue;
76
+ const value = node[key];
77
+ if (Array.isArray(value)) {
78
+ for (const item of value) if (item && typeof item.type === "string") yield item;
79
+ } else if (value && typeof value.type === "string") {
80
+ yield value;
81
+ }
82
+ }
83
+ }
84
+
85
+ /**
86
+ * Report every value block or loop directly in a bailing block, stopping at
87
+ * nested function boundaries — those get their own lowering and do not bail.
88
+ */
89
+ function scanTryBlock(node, report) {
90
+ if (!node || FUNCTIONS.has(node.type)) return;
91
+ if (node.type === "ThrowStatement") report(node, throwMessage);
92
+ else if (isOffending(node)) report(node, valueBlockMessage);
93
+ for (const child of children(node)) scanTryBlock(child, report);
94
+ }
95
+
96
+ /**
97
+ * Walk looking for `try` statements, tracking whether we are inside a function
98
+ * React Compiler actually compiles. `compiled` latches on: everything lexically
99
+ * within a component or hook is lowered as part of it.
100
+ */
101
+ function walk(node, report, compiled, nameHint) {
102
+ if (FUNCTIONS.has(node.type)) {
103
+ const name = node.id?.name ?? nameHint;
104
+ const inner = compiled || isCompiledName(name);
105
+ for (const child of children(node)) walk(child, report, inner, null);
106
+ return;
107
+ }
108
+
109
+ if (node.type === "TryStatement" && compiled) {
110
+ // A finalizer or a missing catch bails on its own, whatever the contents,
111
+ // so those are reported against the clause rather than scanned.
112
+ if (node.finalizer) report(node.finalizer, finallyMessage);
113
+ if (!node.handler) report(node, noCatchMessage);
114
+ scanTryBlock(node.block, report);
115
+ // Still descend: the catch body, and nested functions anywhere in the
116
+ // statement, can hold their own `try` blocks.
117
+ }
118
+
119
+ // Carry the binding name onto the function it names, so `const Foo = () => {}`
120
+ // and `const Foo = memo(() => {})` are both recognised as components.
121
+ let hint = null;
122
+ if (node.type === "VariableDeclarator") hint = node.id?.name;
123
+ else if (node.type === "PropertyDefinition" || node.type === "Property")
124
+ hint = node.key?.name;
125
+ else if (
126
+ node.type === "CallExpression" &&
127
+ NAME_PRESERVING_CALLS.has(node.callee?.name)
128
+ )
129
+ hint = nameHint;
130
+
131
+ for (const child of children(node)) walk(child, report, compiled, hint);
132
+ }
133
+
134
+ /**
135
+ * Flags the four ways a `try` statement makes React Compiler give up: a value
136
+ * block inside the `try`, a `throw` inside the `try`, a `finally` clause, and a
137
+ * missing `catch`.
138
+ *
139
+ * The bailout is file-scoped: one offending construct anywhere in a compiled
140
+ * function drops memoization for every component in that file, silently and
141
+ * with no build error. That makes it invisible without a rule like this one.
142
+ */
143
+ export default {
144
+ meta: {
145
+ type: "problem",
146
+ docs: { description: valueBlockMessage },
147
+ },
148
+ create(context) {
149
+ const report = (node, message) => context.report({ node, message });
150
+
151
+ return {
152
+ Program(program) {
153
+ // Whole-file opt-out; nothing in the file is compiled.
154
+ const optedOut = (program.body ?? []).some(
155
+ (statement) =>
156
+ statement.type === "ExpressionStatement" &&
157
+ statement.expression?.type === "Literal" &&
158
+ statement.expression.value === "use no memo",
159
+ );
160
+ if (optedOut) return;
161
+ for (const child of children(program)) walk(child, report, false, null);
162
+ },
163
+ };
164
+ },
165
+ };
@@ -0,0 +1,11 @@
1
+ // Shared AST helpers for the @vvedantb/config oxlint rules.
2
+
3
+ /** True if `node` is an Identifier (optionally with a specific `name`). */
4
+ export function isIdentifier(node, name) {
5
+ return node?.type === "Identifier" && (name === undefined || node.name === name);
6
+ }
7
+
8
+ /** Normalise a file path to forward slashes so rules work on Windows too. */
9
+ export function toPosix(filename) {
10
+ return (filename ?? "").replace(/\\/g, "/");
11
+ }
package/package.json CHANGED
@@ -1,11 +1,12 @@
1
1
  {
2
2
  "name": "@vvedantb/config",
3
- "version": "0.4.0",
3
+ "version": "0.5.0",
4
4
  "license": "MIT",
5
5
  "description": "Shared tsconfig bases, oxlint base, Vite, Vitest, Babel and Metro presets, a WXT preset and host-permission helper for Chrome extensions, pinned tool versions, a sync CLI for Claude commands, CLAUDE.md, Cursor environment and Convex tsconfig, a packaged Electron app.asar module check and a CLI that adds an extension to Clerk's allowed origins.",
6
6
  "type": "module",
7
7
  "publishConfig": {
8
- "access": "public"
8
+ "access": "public",
9
+ "provenance": true
9
10
  },
10
11
  "repository": {
11
12
  "type": "git",
@@ -15,7 +16,8 @@
15
16
  "bin": {
16
17
  "vvedantb-config": "./dist/cli.js",
17
18
  "vvedantb-check-asar": "./dist/check-asar-cli.js",
18
- "vvedantb-clerk-allow": "./dist/clerk-allow-cli.js"
19
+ "vvedantb-clerk-allow": "./dist/clerk-allow-cli.js",
20
+ "vvedantb-android-release": "./dist/android-release-cli.js"
19
21
  },
20
22
  "exports": {
21
23
  ".": {
@@ -31,6 +33,7 @@
31
33
  "./tsconfig/convex.json": "./tsconfig/convex.json",
32
34
  "./tsconfig/react-native.json": "./tsconfig/react-native.json",
33
35
  "./oxlint/base.json": "./oxlint/base.json",
36
+ "./oxlint/plugin.mjs": "./oxlint/plugin.mjs",
34
37
  "./package.json": "./package.json"
35
38
  },
36
39
  "types": "./dist/index.d.ts",
@@ -42,26 +45,30 @@
42
45
  "CHANGELOG.md",
43
46
  "LICENSE"
44
47
  ],
45
- "scripts": {
46
- "build": "tsc -p tsconfig.json",
47
- "typecheck": "tsc -p tsconfig.test.json",
48
- "test": "vitest run",
49
- "prepack": "tsc -p tsconfig.json"
50
- },
51
48
  "peerDependencies": {
52
- "@electron/asar": "^3.2.0 || ^4.0.0"
49
+ "@electron/asar": "^3.2.0 || ^4.0.0",
50
+ "@expo/config-plugins": ">=9.0.0"
53
51
  },
54
52
  "peerDependenciesMeta": {
55
53
  "@electron/asar": {
56
54
  "optional": true
55
+ },
56
+ "@expo/config-plugins": {
57
+ "optional": true
57
58
  }
58
59
  },
59
60
  "devDependencies": {
60
61
  "@electron/asar": "^4.3.1",
61
62
  "@types/node": "^22.0.0",
62
63
  "@vitejs/plugin-react": "^6.1.2",
64
+ "oxlint": "^1.80.0",
63
65
  "typescript": "^5.9.0",
64
66
  "vite": "^8.3.4",
65
67
  "vitest": "^3.2.0"
68
+ },
69
+ "scripts": {
70
+ "build": "tsc -p tsconfig.json",
71
+ "typecheck": "tsc -p tsconfig.test.json",
72
+ "test": "vitest run"
66
73
  }
67
- }
74
+ }