Skip to content

Local React

FieldValue
TypeSkill Resource
Source~/.copilot/skills/frontend/templates/oxlint/local-react.js
DescriptionNot specified

Source Content

// Custom oxlint JS plugin (oxlint's alpha plugin API — ESLint-compatible
// visitor + context.report shape). Live-tested against oxlint 1.73.0.
//
// Rule: no-unnecessary-react-import
// React 19's automatic JSX runtime never needs `import React from 'react'`
// unless the file actually references the `React` namespace (React.useRef,
// React.FC, etc). Flags the import when it does not.
const plugin = {
meta: { name: 'local-react' },
rules: {
'no-unnecessary-react-import': {
create(context) {
let reactImportNode = null;
let usesReactNamespace = false;
return {
ImportDeclaration(node) {
if (node.source.value !== 'react') return;
const defaultSpec = node.specifiers.find(
(s) => s.type === 'ImportDefaultSpecifier' || s.type === 'ImportNamespaceSpecifier'
);
if (defaultSpec && defaultSpec.local.name === 'React') {
reactImportNode = node;
}
},
MemberExpression(node) {
if (node.object.type === 'Identifier' && node.object.name === 'React') {
usesReactNamespace = true;
}
},
'Program:exit'() {
if (reactImportNode && !usesReactNamespace) {
context.report({
node: reactImportNode,
message:
"Unnecessary default import of React — React 19's automatic JSX runtime doesn't need it unless you reference React.* somewhere in this file.",
});
}
},
};
},
},
},
};
export default plugin;