Track HiveGrid Cloud planning reference
This commit is contained in:
1 parent
b3d5ea6764
commit
e341c5938a
5784 files changed
+1104929
-3
No files matched your search
@@ -0,0 +1,97 @@
|
||||
import { describe, it, expect } from "vitest";
|
||||
import {
|
||||
countOccurrences,
|
||||
tallyCounts,
|
||||
BASELINE,
|
||||
} from "./verify-eslint-baseline.mjs";
|
||||
|
||||
const ESLINT_DISABLE =
|
||||
/(?:\/\/|\/\*)[^\n]*?\beslint-disable(?:-next-line|-line)?\b/g;
|
||||
const TS_IGNORE = /(?:\/\/|\/\*)[^\n]*?@ts-ignore\b/g;
|
||||
const TS_EXPECT = /(?:\/\/|\/\*)[^\n]*?@ts-expect-error\b/g;
|
||||
|
||||
describe("verify-eslint-baseline counters", () => {
|
||||
it("counts eslint-disable in line and block comments", () => {
|
||||
const src = `
|
||||
// eslint-disable-next-line no-console
|
||||
console.log(1);
|
||||
/* eslint-disable-line some-rule */
|
||||
const a = 1; // eslint-disable-line foo
|
||||
/* eslint-disable bar */
|
||||
`;
|
||||
expect(countOccurrences(src, ESLINT_DISABLE)).toBe(4);
|
||||
});
|
||||
|
||||
it("does not count eslint-disable inside ordinary string literals", () => {
|
||||
const src = `const msg = "this string mentions eslint-disable but is not a comment";`;
|
||||
expect(countOccurrences(src, ESLINT_DISABLE)).toBe(0);
|
||||
});
|
||||
|
||||
it("counts @ts-ignore only inside comments", () => {
|
||||
const src = `
|
||||
// @ts-ignore foo
|
||||
const x = 1;
|
||||
/* @ts-ignore */
|
||||
const y = 2;
|
||||
const note = "the words @ts-ignore here are just a string";
|
||||
`;
|
||||
expect(countOccurrences(src, TS_IGNORE)).toBe(2);
|
||||
});
|
||||
|
||||
it("counts @ts-expect-error and does not confuse with @ts-ignore", () => {
|
||||
const src = `
|
||||
// @ts-expect-error reason
|
||||
const a: number = "x";
|
||||
// @ts-ignore other
|
||||
const b: number = "y";
|
||||
`;
|
||||
expect(countOccurrences(src, TS_EXPECT)).toBe(1);
|
||||
expect(countOccurrences(src, TS_IGNORE)).toBe(1);
|
||||
});
|
||||
|
||||
it("tallyCounts aggregates across multiple sources", () => {
|
||||
const sources = [
|
||||
`// eslint-disable-next-line foo\nconst a = 1;`,
|
||||
`// @ts-ignore\nconst b: number = "x";`,
|
||||
`// @ts-expect-error reason\nconst c: number = "x";`,
|
||||
`const ok = 1;`,
|
||||
];
|
||||
const totals = tallyCounts(sources);
|
||||
expect(totals).toEqual({
|
||||
eslintDisable: 1,
|
||||
tsIgnore: 1,
|
||||
tsExpectError: 1,
|
||||
});
|
||||
});
|
||||
|
||||
it("does not match partial tokens like eslint-disabled or @ts-ignored", () => {
|
||||
const src = `
|
||||
// eslint-disabled (typo, not a real directive)
|
||||
// @ts-ignored fake
|
||||
const x = 1;
|
||||
`;
|
||||
expect(countOccurrences(src, ESLINT_DISABLE)).toBe(0);
|
||||
expect(countOccurrences(src, TS_IGNORE)).toBe(0);
|
||||
});
|
||||
|
||||
it("counts multiple directives on the same source independently", () => {
|
||||
const src = `
|
||||
// eslint-disable-next-line a
|
||||
// eslint-disable-next-line b
|
||||
/* eslint-disable c, d */
|
||||
`;
|
||||
expect(countOccurrences(src, ESLINT_DISABLE)).toBe(3);
|
||||
});
|
||||
|
||||
it("exposes a frozen-shape BASELINE with all three categories", () => {
|
||||
expect(Object.keys(BASELINE).sort()).toEqual([
|
||||
"eslintDisable",
|
||||
"tsExpectError",
|
||||
"tsIgnore",
|
||||
]);
|
||||
for (const v of Object.values(BASELINE)) {
|
||||
expect(Number.isInteger(v)).toBe(true);
|
||||
expect(v).toBeGreaterThanOrEqual(0);
|
||||
}
|
||||
});
|
||||
});
|
||||
Reference in new issue
Block a user