From b4749f7896994d5b75e9acf2d3226959bc1f2af6 Mon Sep 17 00:00:00 2001 From: Patrice Chalin Date: Sun, 5 Nov 2023 17:14:51 -0500 Subject: [PATCH] Adjust dict normalization script --- .../blog/2023/contributing-to-otel/index.md | 2 +- scripts/normalize-cspell-front-matter.pl | 38 ++++++++++++++----- 2 files changed, 30 insertions(+), 10 deletions(-) diff --git a/content/en/blog/2023/contributing-to-otel/index.md b/content/en/blog/2023/contributing-to-otel/index.md index 81e04905b1cf..52b380ecf408 100644 --- a/content/en/blog/2023/contributing-to-otel/index.md +++ b/content/en/blog/2023/contributing-to-otel/index.md @@ -6,7 +6,7 @@ author: >- # If you have only one author, then add the single name on this line in quotes. [Adriana Villela](https://github.com/avillela) (Lightstep), canonical_url: https://medium.com/cloud-native-daily/how-to-contribute-to-opentelemetry-5962e8b2447e -cSpell:ignore: EUWG, nolan, riaan, sayin, servian +cSpell:ignore: sayin --- ![Sunset over the water over an orange sky, with long grass in the foreground.](turks-sunset.jpg) diff --git a/scripts/normalize-cspell-front-matter.pl b/scripts/normalize-cspell-front-matter.pl index 6cb4b734a523..555c7eed4f68 100755 --- a/scripts/normalize-cspell-front-matter.pl +++ b/scripts/normalize-cspell-front-matter.pl @@ -9,7 +9,7 @@ my $lineLenLimit = 79; my $last_file = ''; my $last_line = ''; -my %dictionary = getSiteWideDictWords('.vscode/cspell.json', '.textlintrc.json'); +my %dictionary = getSiteWideDictWords('.vscode/cspell.json', '.textlintrc.yml'); while (<>) { if (/^\s*(spelling: |-\s*)?cSpell:ignore:?(.*)$/ @@ -52,18 +52,38 @@ sub getSiteWideDictWords { my $data = $json->decode($json_text); my %dictionary = map { $_ => 1 } @{ $data->{words} }; - # Read the .textlintrc.json file - $fh = FileHandle->new($textlintrc_file, "r") or die "Could not open file '$textlintrc_file': $!"; - $json_text = join "", $fh->getlines(); - # Remove JSON comments $json_text =~ s/^\s*\/\/.*$//mg; + # Merge dictionaries + @dictionary{keys %textlintDictionary} = values %textlintDictionary; + + return %dictionary; +} - $data = $json->decode($json_text); +sub processTextlintRcYml { + my $file_path = shift; + my $fh = FileHandle->new($file_path, "r") or die "Could not open file '$file_path': $!"; + my @lines = $fh->getlines(); + $fh->close(); + + my %dictionary; + my $indentation = ''; + my $in_terms = 0; + foreach my $line (@lines) { + chomp $line; + if ($line =~ /^(\s*)terms:/) { + $indentation = $1 || ''; + $in_terms = 1; + # print STDOUT "Found terms!"; + } elsif ($line =~ /^$indentation - (\w[^\s]*)$/ && $in_terms) { + my $term = $1; + $dictionary{$term} = 1 if $term; + } elsif ($line !~ /^ / && $in_terms) { + $in_terms = 0; + } + } - # Add terms from .textlintrc.json to dictionary - my @terms = @{ $data->{rules}->{terminology}->{terms} }; - @dictionary{@terms} = (1) x @terms; + die "ERROR: no words read from '$file_path'!" unless %dictionary; # sanity check return %dictionary; }