From cbae9067ce7bc2426b9d566942beadf75a42dcb5 Mon Sep 17 00:00:00 2001 From: Simon Cozens Date: Wed, 16 Jul 2025 11:49:50 +0100 Subject: [PATCH] Plug linter into tag tool --- tagger2/TagsByFont.js | 9 +++++++++ tagger2/index.html | 4 ++++ tagger2/models.js | 21 +++++++++++++++++++++ tagger2/style.css | 9 +++++++++ 4 files changed, 43 insertions(+) create mode 100644 tagger2/style.css diff --git a/tagger2/TagsByFont.js b/tagger2/TagsByFont.js index 179a39126..cb5977723 100644 --- a/tagger2/TagsByFont.js +++ b/tagger2/TagsByFont.js @@ -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 { + + ` }; diff --git a/tagger2/index.html b/tagger2/index.html index 478e40414..88dc1255c 100644 --- a/tagger2/index.html +++ b/tagger2/index.html @@ -2,6 +2,7 @@ +
@@ -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); diff --git a/tagger2/models.js b/tagger2/models.js index 5283d0164..cc16517ba 100644 --- a/tagger2/models.js +++ b/tagger2/models.js @@ -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 index 000000000..a82bc3615 --- /dev/null +++ b/tagger2/style.css @@ -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 -- 2.47.2