GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — feat(lint): extend Hermes API bans with a configurable API list (#11982) · incognitojam/styal@69dc103

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • oxlint-plugin-t3code
    • index.ts
    • rules
      • no-hermes-unsupported-apis.test.ts
      • no-hermes-unsupported-apis.ts
      • no-hermes-unsupported-array-methods.ts
  • vite.config.ts
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎oxlint-plugin-t3code/index.ts‎

Copy file name to clipboardExpand all lines: oxlint-plugin-t3code/index.ts
+2-2Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { definePlugin } from "@oxlint/plugins";
22

33
import namespaceNodeImports from "./rules/namespace-node-imports.ts";
44
import noGlobalProcessRuntime from "./rules/no-global-process-runtime.ts";
5-
import noHermesUnsupportedArrayMethods from "./rules/no-hermes-unsupported-array-methods.ts";
5+
import noHermesUnsupportedApis from "./rules/no-hermes-unsupported-apis.ts";
66
import noInlineSchemaCompile from "./rules/no-inline-schema-compile.ts";
77
import noManualEffectRuntimeInTests from "./rules/no-manual-effect-runtime-in-tests.ts";
88
import noMobileUniwindThemeEscapeHatches from "./rules/no-mobile-uniwind-theme-escape-hatches.ts";
@@ -15,7 +15,7 @@ export default definePlugin({
1515
rules: {
1616
"namespace-node-imports": namespaceNodeImports,
1717
"no-global-process-runtime": noGlobalProcessRuntime,
18-
"no-hermes-unsupported-array-methods": noHermesUnsupportedArrayMethods,
18+
"no-hermes-unsupported-apis": noHermesUnsupportedApis,
1919
"no-inline-schema-compile": noInlineSchemaCompile,
2020
"no-manual-effect-runtime-in-tests": noManualEffectRuntimeInTests,
2121
"no-mobile-uniwind-theme-escape-hatches": noMobileUniwindThemeEscapeHatches,
Collapse file

‎…hermes-unsupported-array-methods.test.ts‎ ‎…rules/no-hermes-unsupported-apis.test.ts‎oxlint-plugin-t3code/rules/no-hermes-unsupported-array-methods.test.ts renamed to oxlint-plugin-t3code/rules/no-hermes-unsupported-apis.test.ts oxlint-plugin-t3code/rules/no-hermes-unsupported-array-methods.test.ts renamed to oxlint-plugin-t3code/rules/no-hermes-unsupported-apis.test.ts

Copy file name to clipboardExpand all lines: oxlint-plugin-t3code/rules/no-hermes-unsupported-apis.test.ts
+24-2Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@ import { assert, describe } from "@effect/vitest";
22

33
import { createOxlintRuleHarness } from "../test/utils.ts";
44

5-
const rule = createOxlintRuleHarness("t3code/no-hermes-unsupported-array-methods", {
5+
const rule = createOxlintRuleHarness("t3code/no-hermes-unsupported-apis", {
66
filename: "fixture.ts",
77
});
88

9-
describe("t3code/no-hermes-unsupported-array-methods", () => {
9+
describe("t3code/no-hermes-unsupported-apis", () => {
1010
rule.valid("allows in-place sort on a copy", `const sorted = [...items].sort(compare);`);
1111

1212
rule.valid("allows in-place reverse on a copy", `const reversed = [...items].reverse();`);
@@ -54,4 +54,26 @@ describe("t3code/no-hermes-unsupported-array-methods", () => {
5454
"ignores a template-literal property with substitutions",
5555
"const value = items[`to${suffix}`]();",
5656
);
57+
58+
rule.valid("allows supported Intl constructors", `new Intl.NumberFormat();`);
59+
rule.valid("allows feature detection", `const supported = typeof Intl.Segmenter === "function";`);
60+
rule.valid("allows unrelated Segmenter constructors", `new custom.Segmenter();`);
61+
rule.valid("ignores dynamic computed names", `new Intl[Segmenter](); items[toSorted]();`);
62+
63+
for (const expression of [
64+
"new Intl.Segmenter(undefined, { granularity: 'grapheme' })",
65+
"new Intl['Segmenter']()",
66+
"new Intl[`Segmenter`]()",
67+
"new globalThis.Intl.Segmenter()",
68+
"new globalThis['Intl']['Segmenter']()",
69+
"new global.Intl.Segmenter()",
70+
"new window.Intl.Segmenter()",
71+
"Intl.Segmenter()",
72+
"Intl.Segmenter?.()",
73+
]) {
74+
rule.invalid(`reports ${expression}`, `${expression};`, (output) => {
75+
assert.match(output, /Hermes does not implement Intl\.Segmenter/);
76+
assert.match(output, /portable implementation/);
77+
});
78+
}
5779
});
Collapse file

‎oxlint-plugin-t3code/rules/no-hermes-unsupported-apis.ts‎

Copy file name to clipboard
+70Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
import { defineRule, type ESTree } from "@oxlint/plugins";
2+
3+
// Add global APIs by dotted path, or instance methods by name. Values explain the replacement.
4+
const UNSUPPORTED_GLOBAL_APIS = new Map([
5+
[
6+
"Intl.Segmenter",
7+
"Use a portable implementation or a simpler character-counting approximation.",
8+
],
9+
]);
10+
11+
const UNSUPPORTED_METHODS = new Map([
12+
[
13+
"toSorted",
14+
"Hermes does not implement Array#toSorted. Copy the array first: [...array].sort(...).",
15+
],
16+
[
17+
"toReversed",
18+
"Hermes does not implement Array#toReversed. Copy the array first: [...array].reverse().",
19+
],
20+
// splice returns the removed elements, so the copy itself is the result.
21+
[
22+
"toSpliced",
23+
"Hermes does not implement Array#toSpliced. Copy the array first: const copy = [...array]; copy.splice(...); use copy.",
24+
],
25+
]);
26+
27+
function memberName(node: ESTree.MemberExpression): string | null {
28+
const { property } = node;
29+
if (!node.computed && property.type === "Identifier") return property.name;
30+
if (property.type === "Literal" && typeof property.value === "string") return property.value;
31+
if (property.type === "TemplateLiteral" && property.expressions.length === 0)
32+
return property.quasis[0]?.value.cooked ?? null;
33+
return null;
34+
}
35+
36+
function globalApiPath(node: ESTree.Node): string | null {
37+
if (node.type === "Identifier") return node.name;
38+
if (node.type !== "MemberExpression") return null;
39+
const object = globalApiPath(node.object);
40+
const property = memberName(node);
41+
if (object === null || property === null) return null;
42+
return ["globalThis", "global", "window"].includes(object) ? property : `${object}.${property}`;
43+
}
44+
45+
export default defineRule({
46+
meta: {
47+
type: "problem",
48+
docs: {
49+
description: "Disallow APIs that Hermes does not implement in mobile and shared client code.",
50+
},
51+
},
52+
create(context) {
53+
function checkApi(node: ESTree.CallExpression | ESTree.NewExpression) {
54+
const path = globalApiPath(node.callee);
55+
const replacement = path === null ? undefined : UNSUPPORTED_GLOBAL_APIS.get(path);
56+
if (replacement !== undefined) {
57+
context.report({
58+
node: node.callee,
59+
message: `Hermes does not implement ${path}. ${replacement}`,
60+
});
61+
return;
62+
}
63+
if (node.type !== "CallExpression" || node.callee.type !== "MemberExpression") return;
64+
const name = memberName(node.callee);
65+
const message = name === null ? undefined : UNSUPPORTED_METHODS.get(name);
66+
if (message !== undefined) context.report({ node: node.callee.property, message });
67+
}
68+
return { NewExpression: checkApi, CallExpression: checkApi };
69+
},
70+
});
Collapse file

‎oxlint-plugin-t3code/rules/no-hermes-unsupported-array-methods.ts‎

Copy file name to clipboardExpand all lines: oxlint-plugin-t3code/rules/no-hermes-unsupported-array-methods.ts
-45Lines changed: 0 additions & 45 deletions
This file was deleted.
Collapse file

‎vite.config.ts‎

Copy file name to clipboardExpand all lines: vite.config.ts
+3-3Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -136,8 +136,8 @@ export default defineConfig({
136136
rules: { "t3code/no-mobile-uniwind-theme-escape-hatches": "error" },
137137
},
138138
{
139-
// Code that runs on Hermes. It has no ES2023 change-array-by-copy methods, and
140-
// tsconfig targets ESNext, so only lint stands between a call and a fatal launch.
139+
// Shared client code must not call APIs missing from Hermes. Our ESNext
140+
// TypeScript target accepts them even when they would crash mobile at launch.
141141
// Tests run on Node and are exempt.
142142
files: [
143143
"apps/mobile/src/**",
@@ -146,7 +146,7 @@ export default defineConfig({
146146
"packages/shared/src/**",
147147
],
148148
excludeFiles: ["**/*.test.ts", "**/*.test.tsx"],
149-
rules: { "t3code/no-hermes-unsupported-array-methods": "error" },
149+
rules: { "t3code/no-hermes-unsupported-apis": "error" },
150150
},
151151
{
152152
// Reviewed native and third-party interop boundaries that cannot consume a className.

0 commit comments

Comments
0 (0)
You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.