generated from 18F/open-source-policy
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update scripts per luacheck and add a script to run luacheck
- Loading branch information
Showing
5 changed files
with
33 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
dev-utils |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
#!/bin/sh | ||
|
||
# Spins up a docker container to run luacheck on the scripts directory. | ||
# Run this from the repo root (it uses pwd). | ||
|
||
# luacheck image tags include "latest" and "edge," "edge" being later than "latest" | ||
docker run -it --rm \ | ||
-v "$(pwd)/scripts:/code/scripts" \ | ||
pipelinecomponents/luacheck:latest luacheck scripts |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
# README: luacheck | ||
|
||
The `dev-utils/luacheck-scripts.sh` script will spin up a small docker container and run luacheck on all `.lua` files in this directory. | ||
|
||
luacheck documentation: https://luacheck.readthedocs.io/en/stable/config.html | ||
|
||
A `--luacheck:ignore` comment after a function declaration suppresses a warning about setting a global variable and that this is an unused function. (Scripts that are called only from fluent bit will appear to be unused.) It does _not_ tell luacheck to ignore the rest of the function. | ||
|
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,25 @@ | ||
-- This parser is just a proof-of-concept. | ||
-- These functions parse "tags" and "gauge" data into JSON key/value | ||
-- pairs. The "eq_pairs" of the function name are strings of | ||
-- non-whitespace (and non-=) characters separated by an equal sign. | ||
|
||
KEYS_TO_PARSE = {"tags", "gauge"} | ||
local KEYS_TO_PARSE = {"tags", "gauge"} | ||
|
||
-- Splits a string of foo="bar" pairs and makes parsable json out of it. | ||
function parse_keys_with_eq_pairs(tag, timestamp, record) | ||
for k, v in pairs(KEYS_TO_PARSE) do | ||
if (record[v] ~= nil) then | ||
local eq_pairs_to_json_string = function (orig_string) | ||
local new_string = string.gsub(orig_string, "(%S+)=(%S+)", "\"%1\":%2,") | ||
-- trim off that last , and add curly braces around: | ||
new_string = string.gsub(new_string, "(.+),$", "{%1}") | ||
return new_string | ||
end | ||
|
||
-- Splits a string of foo="bar" pairs and makes parsable json out of it. | ||
function parse_keys_with_eq_pairs(tag, timestamp, record) --luacheck:ignore | ||
for _, v in pairs(KEYS_TO_PARSE) do | ||
if (record[v] ~= nil) then | ||
record[v] = eq_pairs_to_json_string(record[v]) | ||
end | ||
end | ||
-- 2 leaves timestamp unchanged | ||
return 2, timestamp, record | ||
end | ||
|
||
function eq_pairs_to_json_string(orig_string) | ||
local new_string = string.gsub(orig_string, "(%S+)=(%S+)", "\"%1\":%2,") | ||
-- trim off that last , and add curly braces around: | ||
new_string = string.gsub(new_string, "(.+),$", "{%1}") | ||
return new_string | ||
end | ||
|