]> git.ipfire.org Git - thirdparty/google/fonts.git/commitdiff
Plug linter into tag tool tagger2-taglint
authorSimon Cozens <simon@simon-cozens.org>
Wed, 16 Jul 2025 10:49:50 +0000 (11:49 +0100)
committerSimon Cozens <simon@simon-cozens.org>
Wed, 16 Jul 2025 10:49:50 +0000 (11:49 +0100)
tagger2/TagsByFont.js
tagger2/index.html
tagger2/models.js
tagger2/style.css [new file with mode: 0644]

index 179a3912635a3d0bbac240bdcbbd56565e8f4608..cb597772380480a1378f4e04264ca9ea7e797a1a 100644 (file)
@@ -4,6 +4,9 @@ export default {
     filteredTags() {
       // Assumes each tag has a property 'family' with a 'name'
       return this.tags.filter(tag => tag.family && tag.family.name === this.font);
+    },
+    lintErrors() {
+      return this.$root.gf.linter(this.$root.gf.lintRules, this.font, this.filteredTags);
     }
   },
   methods: {
@@ -26,6 +29,12 @@ export default {
            <button @click="removeTag(tag)">Remove</button>
         </li>
       </ul>
+
+      <ul>
+        <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 478e40414cea1b036d89baafa2af9a44c5e9f66d..88dc1255caf98a959cbda8e3385cffc60dbfcf57 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">
@@ -24,6 +25,7 @@
     import Panel from "./Panel.js";
     import TagView from "./TagView.js";
     import AddTag from "./AddTag.js";
+    import { linter } from "./linter.js";
 
     Vue.component('tags-by-font', TagsByFont);
     Vue.component('tags-by-categories', TagsByCategories);
@@ -77,7 +79,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.items = this.tags.items;
         this.$root.$on("remove-tag", this.removeTag);
index 5283d0164d2612ac96cb92c88714e2da1d79f82f..cc16517ba313a984890ffe26ea24a032a1e41dba 100644 (file)
@@ -83,6 +83,7 @@ export class GF {
     constructor() {
         this.familyData = {}; 
         this.families = [];
+        this.lintRules = [];
     }
     async getFamilyData() {
         let data = await loadText('family_data.json');
@@ -92,6 +93,26 @@ export class GF {
             this.familyData[family.family] = family;
         });
     }
+    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