# test.rules/rules/eslint/file-length.eslint.rule.test.ts

> 39 lines of code and 0 definitions.

Tree: Codebase Testing
Language: typescript
Canonical: https://banes-lab.com/anatomy/testing#file-testing-test-rules-rules-eslint-file-length-eslint-rule-test-ts
Source text: https://banes-lab.com/source/testing/test.rules/rules/eslint/file-length.eslint.rule.test.ts.txt

Listed in [test.rules/rules/eslint](https://banes-lab.com/api/source/testing/test.rules/rules/eslint.md), after [test.rules/rules/eslint/factory-owned-value.eslint.rule.test.ts](https://banes-lab.com/source/testing/test.rules/rules/eslint/factory-owned-value.eslint.rule.test.ts.md) and before [test.rules/rules/eslint/markup-through-builder.eslint.rule.test.ts](https://banes-lab.com/source/testing/test.rules/rules/eslint/markup-through-builder.eslint.rule.test.ts.md).

## Contained in

- [test.rules/rules/eslint](https://banes-lab.com/anatomy/testing/folder-testing-test-rules-rules-eslint.md)

## Source

```typescript
import { describe, expect, it } from "vitest";
import { FILE_LENGTH } from "@ssot/govlab/shared/generated/thresholds.generated.ts";
import { Linter } from "eslint";
import { absolutePath } from "@ssot/paths";
import { concernSuffix } from "@ssot/govlab/shared/manifests/taxonomy.manifest.ts";
import fileLength from "@ssot/govlab/rules/eslint/file-length.eslint.rule.ts";
import { sep } from "node:path";

const linter = new Linter();

const config: Linter.Config = {
    files: ["**/*.ts"],
    languageOptions: { ecmaVersion: 2025, sourceType: "module" },
    plugins: { local: { rules: { "file-length": fileLength } } },
    rules: { "local/file-length": "error" },
};

const overLong = Array.from(
    { length: FILE_LENGTH + 1 },
    (_, index) => `export const v${String(index)} = ${String(index)};`,
).join("\n");

const lint = function lint(filename: string): Linter.LintMessage[] {
    return linter.verify(overLong, config, { filename });
};

describe("file-length", () => {
    it("reports a source file over the budget", () => {
        const msgs = lint("page.loader.ts");
        expect(msgs).toHaveLength(1);
        expect(msgs[0]?.messageId).toBe("tooLong");
    });

    it("exempts a strings module, whose length is decided by its copy", () => {
        expect(lint(`methodology${concernSuffix("strings")}`)).toHaveLength(0);
    });

    it("exempts a standalone server script, which ships as one file", () => {
        const scripts = absolutePath("app.nginxScripts").split(sep).join("/");
        expect(lint(`${scripts}/probe.entrypoint.ts`)).toHaveLength(0);
    });

    it("exempts tests and generated files", () => {
        expect(lint("page.loader.test.ts")).toHaveLength(0);
        expect(lint("diagram.generated.ts")).toHaveLength(0);
    });
});
```
