mirror of
https://github.com/Ku6epXBOCTuK/easy-png-tools.git
synced 2026-11-13 17:08:20 +00:00
chore: add lint rules, fix script\configs
This commit is contained in:
@@ -0,0 +1,79 @@
|
||||
// Tests for the conventions/ascii-only rule
|
||||
// (web/eslint-plugins/conventions/ascii-only.js).
|
||||
//
|
||||
// Pure file-content check, no filesystem: standard RuleTester with the
|
||||
// tseslint parser. The scoping to test files lives in eslint.config.js, so
|
||||
// filenames here are arbitrary.
|
||||
import { RuleTester } from "eslint";
|
||||
import tseslint from "typescript-eslint";
|
||||
import { describe, it } from "vitest";
|
||||
import asciiOnly from "../conventions/ascii-only.js";
|
||||
import { asRuleModule } from "./helpers.js";
|
||||
|
||||
RuleTester.describe = describe;
|
||||
RuleTester.it = it;
|
||||
|
||||
const tester = new RuleTester({
|
||||
languageOptions: {
|
||||
parser: tseslint.parser,
|
||||
},
|
||||
});
|
||||
|
||||
tester.run("ascii-only", asRuleModule(asciiOnly), {
|
||||
valid: [
|
||||
{ code: "const x = 1;", filename: "a.test.ts" },
|
||||
{
|
||||
code: "describe('resize pipeline', () => {});",
|
||||
filename: "a.test.ts",
|
||||
},
|
||||
{
|
||||
// Glyphs listed in allowChars pass.
|
||||
code: "expect(label).toBe('512×512');",
|
||||
filename: "a.test.ts",
|
||||
options: [{ allowChars: ["×"] }],
|
||||
},
|
||||
],
|
||||
invalid: [
|
||||
{
|
||||
code: "it('ресайзит картинку', () => {});",
|
||||
filename: "a.test.ts",
|
||||
errors: [{ messageId: "nonAscii" }],
|
||||
},
|
||||
{
|
||||
code: "// arrow → here\nconst x = 1;",
|
||||
filename: "a.test.ts",
|
||||
errors: [{ messageId: "nonAscii" }],
|
||||
},
|
||||
{
|
||||
// Em dash and ellipsis on one line collapse to a single report.
|
||||
code: "it('a — b … c', () => {});",
|
||||
filename: "a.test.ts",
|
||||
errors: [{ messageId: "nonAscii" }],
|
||||
},
|
||||
{
|
||||
// Two offending lines produce two reports.
|
||||
code: "// über\n// café\nconst x = 1;",
|
||||
filename: "a.test.ts",
|
||||
errors: [{ messageId: "nonAscii" }, { messageId: "nonAscii" }],
|
||||
},
|
||||
{
|
||||
// allowChars does not whitelist other glyphs on the same line.
|
||||
code: "expect(s).toBe('512×512 → done');",
|
||||
filename: "a.test.ts",
|
||||
options: [{ allowChars: ["×"] }],
|
||||
errors: [{ messageId: "nonAscii" }],
|
||||
},
|
||||
{
|
||||
// Control characters (here: vertical tab) are not printable ASCII.
|
||||
code: "const s = '\x0B';",
|
||||
filename: "a.test.ts",
|
||||
errors: [{ messageId: "nonAscii" }],
|
||||
},
|
||||
{
|
||||
// DEL (U+007F) is not printable either.
|
||||
code: "const s = '\x7F';",
|
||||
filename: "a.test.ts",
|
||||
errors: [{ messageId: "nonAscii" }],
|
||||
},
|
||||
],
|
||||
});
|
||||
@@ -0,0 +1,98 @@
|
||||
// Tests for the conventions/comment-format rule
|
||||
// (web/eslint-plugins/conventions/comment-format.js).
|
||||
//
|
||||
// Pure AST check (comment nodes + line counts), standard RuleTester.
|
||||
import { RuleTester } from "eslint";
|
||||
import tseslint from "typescript-eslint";
|
||||
import { describe, it } from "vitest";
|
||||
import commentFormat from "../conventions/comment-format.js";
|
||||
import { asRuleModule } from "./helpers.js";
|
||||
|
||||
RuleTester.describe = describe;
|
||||
RuleTester.it = it;
|
||||
|
||||
const tester = new RuleTester({
|
||||
languageOptions: {
|
||||
parser: tseslint.parser,
|
||||
},
|
||||
});
|
||||
|
||||
const longBlock = [
|
||||
"// one",
|
||||
"// two",
|
||||
"// three",
|
||||
"// four",
|
||||
"// five",
|
||||
"// six",
|
||||
"const x = 1;",
|
||||
].join("\n");
|
||||
|
||||
tester.run("comment-format", asRuleModule(commentFormat), {
|
||||
// Density is off (maxRatio: 1) in the block-focused cases: tiny snippets
|
||||
// are comment-dominated by construction.
|
||||
valid: [
|
||||
{
|
||||
code: "// why\nconst x = 1;",
|
||||
filename: "a.ts",
|
||||
options: [{ maxRatio: 1 }],
|
||||
},
|
||||
{
|
||||
code: "// a\n// b\n// c\n// d\n// e\nconst x = 1;",
|
||||
filename: "a.ts",
|
||||
options: [{ maxRatio: 1 }],
|
||||
},
|
||||
{
|
||||
// Blank line breaks the run: two 3-line blocks, both under the cap.
|
||||
code: "// a\n// b\n// c\n\n// d\n// e\n// f\nconst x = 1;",
|
||||
filename: "a.ts",
|
||||
options: [{ maxRatio: 1 }],
|
||||
},
|
||||
{
|
||||
// Trailing inline comment does not extend the block above it.
|
||||
code: "// a\n// b\nconst x = 1; // tail",
|
||||
filename: "a.ts",
|
||||
options: [{ maxRatio: 1 }],
|
||||
},
|
||||
{
|
||||
// A wider block cap admits the same comment.
|
||||
code: longBlock,
|
||||
filename: "a.ts",
|
||||
options: [{ maxBlockLines: 6, maxRatio: 1 }],
|
||||
},
|
||||
{
|
||||
// Density is skipped below minLines: small files are exempt.
|
||||
code: "// a\n// b\nconst x = 1;\nconst y = 2;",
|
||||
filename: "a.ts",
|
||||
options: [{ maxBlockLines: 5, maxRatio: 0.4, minLines: 10 }],
|
||||
},
|
||||
],
|
||||
invalid: [
|
||||
{
|
||||
code: longBlock,
|
||||
filename: "a.ts",
|
||||
options: [{ maxRatio: 1 }],
|
||||
errors: [{ messageId: "blockTooLong" }],
|
||||
},
|
||||
{
|
||||
// A single block comment counts its full line span.
|
||||
code: "/*\n1\n2\n3\n4\n5\n6\n*/\nconst x = 1;",
|
||||
filename: "a.ts",
|
||||
options: [{ maxRatio: 1 }],
|
||||
errors: [{ messageId: "blockTooLong" }],
|
||||
},
|
||||
{
|
||||
// Density: 2 comment lines against 2 code lines is 50%.
|
||||
code: "// a\n// b\nconst x = 1;\nconst y = 2;",
|
||||
filename: "a.ts",
|
||||
options: [{ maxBlockLines: 5, maxRatio: 0.4 }],
|
||||
errors: [{ messageId: "tooDense" }],
|
||||
},
|
||||
{
|
||||
// Both violations in one file produce two reports.
|
||||
code: longBlock + "\n// extra",
|
||||
filename: "a.ts",
|
||||
options: [{ maxBlockLines: 5, maxRatio: 0.5 }],
|
||||
errors: [{ messageId: "blockTooLong" }, { messageId: "tooDense" }],
|
||||
},
|
||||
],
|
||||
});
|
||||
@@ -0,0 +1,96 @@
|
||||
// Tests for the conventions/comments-english rule
|
||||
// (web/eslint-plugins/conventions/comments-english.js).
|
||||
//
|
||||
// Pure AST check over comment nodes with an ASCII whitelist; string literals
|
||||
// are ignored by construction (they are not comments), which the cases below
|
||||
// pin down.
|
||||
import { RuleTester } from "eslint";
|
||||
import tseslint from "typescript-eslint";
|
||||
import { describe, it } from "vitest";
|
||||
import commentsEnglish from "../conventions/comments-english.js";
|
||||
import { asRuleModule } from "./helpers.js";
|
||||
|
||||
RuleTester.describe = describe;
|
||||
RuleTester.it = it;
|
||||
|
||||
const tester = new RuleTester({
|
||||
languageOptions: {
|
||||
parser: tseslint.parser,
|
||||
},
|
||||
});
|
||||
|
||||
tester.run("comments-english", asRuleModule(commentsEnglish), {
|
||||
valid: [
|
||||
{ code: "// resize the canvas\nconst x = 1;", filename: "a.ts" },
|
||||
{ code: "/* multi\nline */\nconst x = 1;", filename: "a.ts" },
|
||||
{
|
||||
// Localized strings are dictionary content, not comments.
|
||||
code: "const title = 'Пример';",
|
||||
filename: "a.ts",
|
||||
},
|
||||
{
|
||||
// Glyphs listed in allowChars pass.
|
||||
code: "// size 512×512\nconst x = 1;",
|
||||
filename: "a.ts",
|
||||
options: [{ allowChars: ["×"] }],
|
||||
},
|
||||
{
|
||||
// A tab inside a comment is legitimate whitespace.
|
||||
code: "//\tnote\nconst x = 1;",
|
||||
filename: "a.ts",
|
||||
},
|
||||
],
|
||||
invalid: [
|
||||
{
|
||||
code: "// ресайз холста\nconst x = 1;",
|
||||
filename: "a.ts",
|
||||
errors: [{ messageId: "nonAscii" }],
|
||||
},
|
||||
{
|
||||
// Whitelist catches scripts beyond Cyrillic too.
|
||||
code: "// 调整画布大小\nconst x = 1;",
|
||||
filename: "a.ts",
|
||||
errors: [{ messageId: "nonAscii" }],
|
||||
},
|
||||
{
|
||||
code: "// تغيير حجم اللوحة\nconst x = 1;",
|
||||
filename: "a.ts",
|
||||
errors: [{ messageId: "nonAscii" }],
|
||||
},
|
||||
{
|
||||
// Typography in an otherwise English comment is still non-ASCII.
|
||||
code: "// resize — then crop\nconst x = 1;",
|
||||
filename: "a.ts",
|
||||
errors: [{ messageId: "nonAscii" }],
|
||||
},
|
||||
{
|
||||
code: "/* много\nстрочный */\nconst x = 1;",
|
||||
filename: "a.ts",
|
||||
errors: [{ messageId: "nonAscii" }],
|
||||
},
|
||||
{
|
||||
code: "const x = 1; // хвостовой комментарий",
|
||||
filename: "a.ts",
|
||||
errors: [{ messageId: "nonAscii" }],
|
||||
},
|
||||
{
|
||||
// One report per offending comment, not per file.
|
||||
code: "// раз\n// два\nconst x = 1;",
|
||||
filename: "a.ts",
|
||||
errors: [{ messageId: "nonAscii" }, { messageId: "nonAscii" }],
|
||||
},
|
||||
{
|
||||
// allowChars does not whitelist other glyphs in the same comment.
|
||||
code: "// 512×512 → done\nconst x = 1;",
|
||||
filename: "a.ts",
|
||||
options: [{ allowChars: ["×"] }],
|
||||
errors: [{ messageId: "nonAscii" }],
|
||||
},
|
||||
{
|
||||
// Control characters (here: vertical tab) are not printable ASCII.
|
||||
code: "// \x0B note\nconst x = 1;",
|
||||
filename: "a.ts",
|
||||
errors: [{ messageId: "nonAscii" }],
|
||||
},
|
||||
],
|
||||
});
|
||||
Reference in New Issue
Block a user