Skip to content

Complexity Check Plugin

Generate diagnostics for content complexity using @player-tools/complexity-check-plugin. The plugin analyzes your Player Content and calculates complexity based on asset types, nesting depth, and overall structure to provide a single complexity score per file.

Install the plugin:

Terminal window
npm i @player-tools/complexity-check-plugin
const COMPLEXITY_WARNING_THRESHOLD = 1000;
export default {
plugins: [
new ComplexityCheck({
maxAcceptableComplexity: 20000,
maxWarningLevel: COMPLEXITY_WARNING_THRESHOLD,
}),
],
};

Override the default complexity weights for different asset types:

new ComplexityCheck({
typeWeights: {
text: 5, // Add 5 for each text asset found
action: 25, // Add 25 for each action asset found
},
});

The plugin uses base weights for different complexity factors. See the complete list of weights in the source code.

You can override these base weights using baseWeightOverrides:

new ComplexityCheck({
baseWeightOverrides: {
modelGet: 8, // Increase model get complexity
template: 2, // Increase template complexity
},
});
  • maxAcceptableComplexity: Maximum complexity before error (default: 10000)
  • maxWarningLevel: Complexity level that triggers warnings (default: 1000)
  • typeWeights: Custom complexity weights for different asset types
  • baseWeightOverrides: Override base complexity weights

Enable verbose mode to see a detailed breakdown: yarn run player json validate -v trace

This will output detailed information about how complexity is calculated.

The ComplexityCheck plugin produces diagnostics like Content complexity is 640 which can be consumed by the Metrics Output Plugin.

// In your MetricsOutputPlugin configuration
stats: {
complexity: extractFromDiagnostics(/Content complexity is (\d+)/, Number),
}