Skip to content

Structure

structure

Node structure rule — the package.json/tsconfig pendant of the pyproject rule.

Ports the intent of the Python STRUCTURE_PYPROJECT completeness check to the Node ecosystem: a published package must declare the manifest fields and the strict TypeScript config the research flags as gold-standard. This is a pure file-read rule (no subprocess), so it subclasses ProjectRule directly.

NodeStructureRule

Bases: ProjectRule

Check package.json completeness + tsconfig strict mode.

Mirrors the Python PyprojectCompletenessRule: binary field-presence checks, 100 - missing * 10.

Source code in packages/axm-audit/src/axm_audit/core/rules/node/structure.py
Python
@register_rule("structure", framework=Framework.NODE)
class NodeStructureRule(ProjectRule):
    """Check package.json completeness + tsconfig strict mode.

    Mirrors the Python ``PyprojectCompletenessRule``: binary field-presence
    checks, ``100 - missing * 10``.
    """

    @property
    def rule_id(self) -> str:
        """Unique identifier for this rule."""
        return "STRUCTURE_PACKAGE_JSON"

    def check(self, project_path: Path) -> CheckResult:
        """Score by the count of missing manifest fields + strict tsconfig opts."""
        pkg = _load_json(project_path / "package.json")
        if pkg is None:
            return CheckResult(
                rule_id=self.rule_id,
                passed=False,
                message="package.json missing or unparsable",
                severity=Severity.ERROR,
                score=0,
                fix_hint="Create a valid package.json (npm init).",
            )
        missing = _missing_package_fields(pkg) + _missing_tsconfig(project_path)
        score = max(0, 100 - len(missing) * 10)
        passed = not missing
        return CheckResult(
            rule_id=self.rule_id,
            passed=passed,
            message=(
                "package.json + tsconfig complete"
                if passed
                else f"Missing: {', '.join(missing)}"
            ),
            severity=Severity.WARNING if not passed else Severity.INFO,
            score=score,
            details={"missing": missing},
            fix_hint=f"Add {', '.join(missing)}" if missing else None,
        )
rule_id property

Unique identifier for this rule.

check(project_path)

Score by the count of missing manifest fields + strict tsconfig opts.

Source code in packages/axm-audit/src/axm_audit/core/rules/node/structure.py
Python
def check(self, project_path: Path) -> CheckResult:
    """Score by the count of missing manifest fields + strict tsconfig opts."""
    pkg = _load_json(project_path / "package.json")
    if pkg is None:
        return CheckResult(
            rule_id=self.rule_id,
            passed=False,
            message="package.json missing or unparsable",
            severity=Severity.ERROR,
            score=0,
            fix_hint="Create a valid package.json (npm init).",
        )
    missing = _missing_package_fields(pkg) + _missing_tsconfig(project_path)
    score = max(0, 100 - len(missing) * 10)
    passed = not missing
    return CheckResult(
        rule_id=self.rule_id,
        passed=passed,
        message=(
            "package.json + tsconfig complete"
            if passed
            else f"Missing: {', '.join(missing)}"
        ),
        severity=Severity.WARNING if not passed else Severity.INFO,
        score=score,
        details={"missing": missing},
        fix_hint=f"Add {', '.join(missing)}" if missing else None,
    )