Repository navigation
refactor(core): centralize worktree config derivation #9915
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 3 commits
1ec898b
75690e4
9fd6266
23349f1
94d0174
feca442
b553b21
ded65e6
56ca877
8f7779a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,59 @@ | ||
| function importsConfig(node) { | ||
| return ( | ||
| typeof node.source.value === 'string' && | ||
| node.source.value.endsWith('/config/config.js') && | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The |
||
| node.specifiers.some( | ||
| (specifier) => | ||
| specifier.type === 'ImportSpecifier' && | ||
| specifier.imported.type === 'Identifier' && | ||
| specifier.imported.name === 'Config', | ||
| ) | ||
| ); | ||
| } | ||
|
|
||
| function isObjectCreate(node) { | ||
| return ( | ||
| node.callee.type === 'MemberExpression' && | ||
| !node.callee.computed && | ||
| node.callee.object.type === 'Identifier' && | ||
| node.callee.object.name === 'Object' && | ||
| node.callee.property.type === 'Identifier' && | ||
| node.callee.property.name === 'create' && | ||
| !(node.arguments[0]?.type === 'Literal' && node.arguments[0].value === null) | ||
| ); | ||
| } | ||
|
|
||
| export default { | ||
| meta: { | ||
| type: 'problem', | ||
| docs: { | ||
| description: | ||
| 'Require Config prototype derivation to go through deriveConfig.', | ||
| }, | ||
| schema: [], | ||
| messages: { | ||
| useDeriveConfig: | ||
| 'Do not derive Config with Object.create(). Use deriveConfig() or a specialized Config factory.', | ||
| }, | ||
| }, | ||
|
|
||
| create(context) { | ||
| let hasConfigImport = false; | ||
| const objectCreateCalls = []; | ||
|
|
||
| return { | ||
| ImportDeclaration(node) { | ||
| if (importsConfig(node)) hasConfigImport = true; | ||
| }, | ||
| CallExpression(node) { | ||
| if (isObjectCreate(node)) objectCreateCalls.push(node); | ||
| }, | ||
| 'Program:exit'() { | ||
| if (!hasConfigImport) return; | ||
| for (const node of objectCreateCalls) { | ||
| context.report({ node, messageId: 'useDeriveConfig' }); | ||
| } | ||
| }, | ||
| }; | ||
| }, | ||
| }; | ||
Uh oh!
There was an error while loading. Please reload this page.