Skip to content

Commit

Permalink
Adjust dict normalization script
Browse files Browse the repository at this point in the history
  • Loading branch information
chalin committed Nov 5, 2023
1 parent 719766c commit b4749f7
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 10 deletions.
2 changes: 1 addition & 1 deletion content/en/blog/2023/contributing-to-otel/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
38 changes: 29 additions & 9 deletions scripts/normalize-cspell-front-matter.pl
Original file line number Diff line number Diff line change
Expand Up @@ -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:?(.*)$/
Expand Down Expand Up @@ -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;
}

0 comments on commit b4749f7

Please sign in to comment.