Skip to content

Refactor ideas #9496

Closed
Closed

Description

@fregante

Just some notes for copilot refactors that may or may not come when there are few PRs open

Activity

  1. self-assigned this
    on May 17, 2026
  2. added
    meta
    on May 17, 2026
  3. fregante commented on May 22, 2026

    @fregante
    MemberAuthor
    • move certain features.test.ts checks into restricted-syntax or custom plugins if possible, so they show up in the IDE

    Tried this:

    if (
    /api\.v4|getDefaultBranch|getPrInfo/.test(String(file.contents()))
    && /observe\(|delegate\(/.test(String(file.contents()))
    ) {
    assert(
    /requiresToken:\s*true|hasToken/.test(String(file.contents())),
    `${file.id} uses the v4 API, so it should include \`requiresToken: true\`, or if the token is optional, \`hasToken\` anywhere`,
    );
    }

    Claude generated this rule for a single check:

    import type {Rule} from 'eslint';
    import type {CallExpression, Node} from 'estree';
    
    const v4ApiNames = new Set(['getDefaultBranch', 'getPrInfo']);
    
    function isV4Call(node: CallExpression): boolean {
    	// api.v4(...)
    	return (
    		node.callee.type === 'MemberExpression'
    		&& node.callee.object.type === 'Identifier'
    		&& node.callee.object.name === 'api'
    		&& node.callee.property.type === 'Identifier'
    		&& node.callee.property.name === 'v4'
    	);
    }
    
    function isV4Helper(node: CallExpression): boolean {
    	// getDefaultBranch(...) / getPrInfo(...)
    	return (
    		node.callee.type === 'Identifier'
    		&& v4ApiNames.has(node.callee.name)
    	);
    }
    
    function isObserveCall(node: CallExpression): boolean {
    	return (
    		node.callee.type === 'Identifier'
    		&& (node.callee.name === 'observe' || node.callee.name === 'delegate')
    	);
    }
    
    function getFeaturesAddArgs(node: CallExpression): Node[] {
    	// features.add(import.meta.url, ...featureObjects)
    	return (
    		node.callee.type === 'MemberExpression'
    		&& node.callee.object.type === 'Identifier'
    		&& node.callee.object.name === 'features'
    		&& node.callee.property.type === 'Identifier'
    		&& node.callee.property.name === 'add'
    	) ? node.arguments.slice(1) : [];
    }
    
    function hasTokenProperty(obj: Node): boolean {
    	if (obj.type !== 'ObjectExpression') return false;
    	return obj.properties.some(
    		p =>
    			p.type === 'Property'
    			&& p.key.type === 'Identifier'
    			&& (p.key.name === 'requiresToken' || p.key.name === 'hasToken'),
    	);
    }
    
    function isDescendant(child: Node, ancestor: Node): boolean {
    	let current: Node | undefined = (child as Rule.NodeParentExtension).parent;
    	while (current) {
    		if (current === ancestor) return true;
    		current = (current as Rule.NodeParentExtension).parent;
    	}
    
    	return false;
    }
    
    const rule: Rule.RuleModule = {
    	meta: {
    		type: 'problem',
    		docs: {description: 'features.add() blocks using the v4 API with observers must declare requiresToken or hasToken'},
    		schema: [],
    		messages: {
    			missingToken: 'This features.add() block uses the v4 API, so it should include `requiresToken` in its setup or, if the token is optional, `hasToken` anywhere',
    		},
    	},
    	create(context) {
    		const v4Calls = new Set<Node>();
    		const observeCalls = new Set<Node>();
    
    		return {
    			CallExpression(node) {
    				if (isV4Call(node) || isV4Helper(node)) v4Calls.add(node);
    				if (isObserveCall(node)) observeCalls.add(node);
    			},
    			'CallExpression:exit'(node) {
    				const args = getFeaturesAddArgs(node);
    				if (args.length === 0) return;
    
    				for (const arg of args) {
    					if (arg.type !== 'ObjectExpression') continue;
    					if (hasTokenProperty(arg)) continue;
    
    					const usesV4 = [...v4Calls].some(c => isDescendant(c, arg));
    					const usesObserve = [...observeCalls].some(c => isDescendant(c, arg));
    
    					if (usesV4 && usesObserve) {
    						context.report({node: arg, messageId: 'missingToken'});
    					}
    				}
    			},
    		};
    	},
    };
    
    export default {
    	rules: {'requires-token': rule},
    } satisfies {rules: Record<string, Rule.RuleModule>};

    Absolutely not worth it.

  4. fregante commented on May 22, 2026

    @fregante
    MemberAuthor
    • enforce CSS inside html:not([rgh-OFF-align-issue-labels]) classes to make sure features don't leak (including JS features)

    Too much trouble at this point. This is already somewhat enforced for CSS-only features anyway, where it is 100% required.

  5. fregante commented on May 22, 2026

    @fregante
    MemberAuthor
    • refactor some or all has-rgh/has-rgh-inner features

    Not really needed. These are small features that work best without observe, at least until they break.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

meta

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions