The fastest, cheapest, most efficient open-source agent harness. Run more than 500 agents on a $10 VPS.
Rust agent-orchestrationai-agentsai-assistantdesktopllmlocal-firstmcppersonal-aiprivacyrustsecond-braintauri
lint(app): pin the selector to import.meta and cover computed access\n\nCodeRabbit found two real holes in the selector, both reproduced with\neslint before changing anything:\n\n import.meta.env.DEV flagged correct\n import.meta['env'].DEV NOT flagged a silent bypass of the rule\n new.target.env flagged false positive; a different\n meta-property entirely\n\nComputed member access stores the key on property.value, not\nproperty.name, so the original selector never saw the bracket form. And\n[object.type="MetaProperty"] matches new.target just as well as\nimport.meta, so the meta-property is now pinned by name.\n\nAdds a test that reads the selector and the ignore list out of the real\neslint.config.js rather than restating them, so the two cannot drift.\nReverting the selector turns exactly the two cases above red and nothing\nelse. The probes run through a bare Linter because the repo config is\ntype-aware and parserOptions.project rejects a synthetic file path.\n\ntsc, eslint, prettier and the new tests are all clean.\n
Nguyen Thanh Dat934d6b673724
diff --git a/app/eslint.config.js b/app/eslint.config.jsindex d606e1249f..4ea65fcfc8 100644--- a/app/eslint.config.js+++ b/app/eslint.config.js@@ -247,7 +247,10 @@ export default ['no-restricted-syntax': ['error',{- selector: 'MemberExpression[object.type="MetaProperty"][property.name="env"]',+ // Pin the meta-property to `import.meta` -- `new.target` is a MetaProperty+ // too -- and match both `import.meta.env` and `import.meta['env']`.+ selector:+ 'MemberExpression[object.type="MetaProperty"][object.meta.name="import"][object.property.name="meta"]:matches([computed=false][property.name="env"], [computed=true][property.value="env"])',message:'Read frontend config from src/utils/config.ts (IS_DEV, IS_DEV_LIKE, ...) instead of import.meta.env directly; add the value there if it is missing.',},diff --git a/app/src/test/eslintCentralizedConfigRule.test.ts b/app/src/test/eslintCentralizedConfigRule.test.tsnew file mode 100644index 0000000000..166a896eb5--- /dev/null+++ b/app/src/test/eslintCentralizedConfigRule.test.ts@@ -0,0 +1,70 @@+import { Linter } from 'eslint';+import tsparser from '@typescript-eslint/parser';+import { describe, expect, it } from 'vitest';++// eslint.config.js is plain JS and ships no declarations; importing the real+// file is the point of this test, so the shape is asserted below at runtime.+// @ts-expect-error -- untyped JS module+import eslintConfig from '../../eslint.config.js';++/**+ * Guards the `no-restricted-syntax` selector that keeps frontend config reads+ * funnelled through `src/utils/config.ts`. The selector is easy to get subtly+ * wrong in both directions -- `new.target` is a MetaProperty just like+ * `import.meta`, and computed access stores the key on `property.value` rather+ * than `property.name` -- so the exact boundary is pinned here.+ *+ * The selector and the ignore list are read out of the real `eslint.config.js`+ * rather than restated, so these assertions cannot drift away from what ships.+ * Linting runs through a bare `Linter` because the repo config is type-aware+ * and `parserOptions.project` rejects the synthetic file used for the probes.+ */++const configBlock = (eslintConfig as Linter.Config[]).find(+ (block) => block.rules?.['no-restricted-syntax'],+);++const [, restriction] = (configBlock?.rules?.['no-restricted-syntax'] ?? []) as [+ string,+ { selector: string; message: string },+];++const linter = new Linter();++function lint(code: string) {+ const messages = linter.verify(code, {+ languageOptions: { parser: tsparser, ecmaVersion: 'latest', sourceType: 'module' },+ rules: { 'no-restricted-syntax': ['error', restriction] },+ });+ // A parse failure would otherwise read as "the rule did not fire".+ expect(messages.filter((message) => message.fatal)).toEqual([]);+ return messages;+}++describe('centralized-frontend-config lint rule', () => {+ it('is wired into the shipped config', () => {+ expect(restriction?.selector).toBeTypeOf('string');+ expect(configBlock?.ignores).toContain('src/utils/config.ts');+ expect(configBlock?.ignores).toContain('src/test/**');+ });++ it('rejects dotted import.meta.env access', () => {+ expect(lint('export const a = import.meta.env.DEV;')).toHaveLength(1);+ });++ it('rejects computed import.meta["env"] access', () => {+ expect(lint("export const a = import.meta['env'].DEV;")).toHaveLength(1);+ });++ it('allows other import.meta properties', () => {+ expect(lint('export const a = import.meta.url;')).toHaveLength(0);+ });++ it('allows new.target.env, which is a different meta-property', () => {+ expect(lint('export function G() { return new.target.env; }')).toHaveLength(0);+ });++ it('allows a plain object property named env', () => {+ expect(lint('const o = { env: 1 }; export const a = o.env;')).toHaveLength(0);+ });+});