IconPolicy.test.ts 1.2 KB

123456789101112131415161718192021222324252627282930313233
  1. import { readdirSync, readFileSync } from 'node:fs';
  2. import { join, resolve } from 'node:path';
  3. import { describe, expect, test } from 'vitest';
  4. const sourceRoot = resolve(process.cwd(), 'src');
  5. const generatedDirectories = new Set(['.umi', '.umi-production']);
  6. const emojiPattern = /[\u{1F000}-\u{1FAFF}\u{2600}-\u{27BF}]/u;
  7. function sourceFiles(directory: string): string[] {
  8. return readdirSync(directory, { withFileTypes: true }).flatMap((entry) => {
  9. const path = join(directory, entry.name);
  10. if (entry.isDirectory()) {
  11. return generatedDirectories.has(entry.name) ? [] : sourceFiles(path);
  12. }
  13. return /\.(?:ts|tsx|less)$/.test(entry.name) ? [path] : [];
  14. });
  15. }
  16. describe('图标与符号规范', () => {
  17. test('业务界面仅使用 Lucide 图标且不包含表情符号', () => {
  18. const violations = sourceFiles(sourceRoot).flatMap((path) => {
  19. const content = readFileSync(path, 'utf8');
  20. const reasons = [
  21. content.includes('@ant-design/icons') ? '使用了非 Lucide 图标库' : '',
  22. emojiPattern.test(content) ? '包含表情符号' : '',
  23. ].filter(Boolean);
  24. return reasons.map((reason) => `${path}: ${reason}`);
  25. });
  26. expect(violations).toEqual([]);
  27. });
  28. });