Closed seantiz closed 1 week ago
We might also be able to carry over the Complexity Score to a number field
Bug: duplication was happening because analyseFeatureComplexity()
was written to count every class_specifier as its own instance of a class, whenever it detected a mention of it inside module content.
For now the fix is to put a filter method on our classNodes
variable, but there may be a cleaner way to do this in review:
const classNodes = tree.rootNode.descendantsOfType('class_specifier')
.filter(node => {
// Only include nodes that are actual class definitions
// Check if node has a body/implementation
return node.childForFieldName('body') !== null;
});
The other fix was cleaning up the way features were appended in general in analyseFeatureComplexity
export function analyseFeatureComplexity(moduleMap: Map<string, ModuleMapValues>) {
for (const [file, data] of moduleMap) {
if (!data.complexity?.tree?.rootNode) continue;
const localFeatureMap = new Map(); // Create a new map for each file
const tree = data.complexity.tree;
const classNodes = tree.rootNode.descendantsOfType('class_specifier')
.filter(node => {
// Only include nodes that are actual class definitions
// Check if node has a body/implementation
return node.childForFieldName('body') !== null;
});
classNodes.forEach((classNode) => {
const className = classNode.childForFieldName('name')?.text;
if (!className) return;
const methods = classNode.descendantsOfType('function_definition')
const classType = determineClassType(classNode, methods, className);
localFeatureMap.set(className, {
type: classType,
methods: methods.map(m => ({
name: m.text,
visibility: 'public'
})),
metrics: {
inheritsFrom: [],
uses: [],
usedBy: []
},
occurrences: [file]
});
});
// Store relationships immediately for this file
if (!data.complexity.classRelationships) {
data.complexity.classRelationships = {};
}
// Only add classes found in this specific file
for (const [className, featureData] of localFeatureMap) {
data.complexity.classRelationships[className] = {
type: featureData.type,
methods: featureData.methods,
metrics: featureData.metrics,
occurrences: featureData.occurrences
};
}
}
return moduleMap;
}
Possible feature that would be really cool since Github Projects currently has no import feature.
Implementation
More info: https://stackoverflow.com/questions/76594802/how-to-import-data-into-github-projects-view