]> git.ipfire.org Git - thirdparty/google/fonts.git/commitdiff
Plug linter into tag tool
authorSimon Cozens <simon@simon-cozens.org>
Wed, 16 Jul 2025 10:49:50 +0000 (11:49 +0100)
committerMarc Foley <m.foley.88@gmail.com>
Fri, 18 Jul 2025 12:44:56 +0000 (13:44 +0100)
tagger2/TagsByFont.js
tagger2/index.html
tagger2/models.js
tagger2/style.css [new file with mode: 0644]

index 496811028f53aacbd4b6b0428266db6562421154..4844b4dab70b13fa3acc8e8524deff5a49d2699a 100644 (file)
@@ -7,6 +7,9 @@ export default {
     },
     similarFamilies() {
       return this.$root.gf.similarFamilies(this.font, 10);
+    },
+    lintErrors() {
+      return this.$root.gf.linter(this.$root.gf.lintRules, this.font, this.filteredTags);
     }
   },
   methods: {
@@ -37,6 +40,9 @@ export default {
         <li v-for="family in similarFamilies" :key="family" :style="{ fontFamily: family }">
           {{ family }} <button @click="addFontPanel(family)">Add</button>
         </li>
+        <li v-for="error in lintErrors" :key="error.description" :class="{ 'tag-error': error.severity === 'ERROR', 'tag-warn': error.severity === 'WARN', 'tag-fail': error.severity === 'FAIL', 'tag-info': error.severity === 'INFO' }">
+        {{ error.description }}
+        </li>
       </ul>
     </div>
   `
index 718f761b77f9bc64994a6d55b4751cdccfd33fb4..4e4ac1c2e2549475d6e40cf88f9dd551d962e106 100644 (file)
@@ -2,6 +2,7 @@
 <html>
 <head>
   <script src="https://cdn.jsdelivr.net/npm/vue@2/dist/vue.js"></script>
+  <link rel="stylesheet" href="style.css">
 </head>
 <body>
   <div id="app">
@@ -33,6 +34,7 @@
     import AddTags from "./AddTags.js";
     import AddCategory from "./AddCategory.js";
     import VFView from "./VFView.js";
+    import { linter } from "./linter.js";
 
     Vue.component('tags-by-font', TagsByFont);
     Vue.component('tags-by-categories', TagsByCategories);
@@ -93,7 +95,9 @@
         // Load the GF and Tags classes
         this.gf = new GF();
         await this.gf.getFamilyData();
+        await this.gf.getLintRules();
         this.gf.loadFamilies();
+        this.gf.linter = linter;
         this.tags = new Tags(this.gf);
         this.tags.sortCategories();
         this.$root.$on("remove-tag", this.removeTag);
index 40816a5bd0e643d6b3e6fa2b1d592ca63d290444..9e41fdaec04e588ebb9406265d8f14fc2cd7ee84 100644 (file)
@@ -97,6 +97,7 @@ export class GF {
     constructor() {
         this.familyData = {}; 
         this.families = [];
+        this.lintRules = [];
     }
     async getFamilyData() {
         let data = await loadText('family_data.json');
@@ -111,6 +112,26 @@ export class GF {
             }
         });
     }
+    async getLintRules() {
+        let data = await loadText('tag_rules.csv');
+        const lines = data.split('\n');
+        for (let line of lines) {
+            if (line.startsWith('#') || line.trim() === '') {
+                continue;
+            }
+            let [rule, severity, description] = line.split(',');
+            description = description.replace(/^"(.*)"$/, '$1');
+            if (!rule || !description || !severity) {
+                console.warn("Skipping line due to missing fields:", line);
+                continue;
+            }
+            this.lintRules.push({
+                rule: rule.trim(),
+                description: description.trim(),
+                severity: severity.trim()
+            });
+        }
+    }
     loadFamilies() {
         for (let familyName in this.familyData) {
             const axes = []
diff --git a/tagger2/style.css b/tagger2/style.css
new file mode 100644 (file)
index 0000000..a82bc36
--- /dev/null
@@ -0,0 +1,9 @@
+body {
+    font-family: sans-serif;
+    margin: 0;
+}
+
+.tag-error { background-color: #f88f7e; padding: 2px; }
+.tag-warn { color: #c0a007; }
+.tag-fail { color: #c02007; }
+.tag-info { color: #007ac0; }
\ No newline at end of file