Skip to content

Commit

Permalink
Merge pull request #406 from chris48s/405-toml
Browse files Browse the repository at this point in the history
add toml document parsing
  • Loading branch information
chris48s authored Jan 25, 2024
2 parents d019eda + 7c7198f commit e7051a3
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 3 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
node: ['16', '18', '20']
node: ['18', '20']
steps:
- name: Checkout
uses: actions/checkout@v4
Expand Down
17 changes: 16 additions & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
"js-yaml": "^4.0.0",
"json5": "^2.2.0",
"minimatch": "^9.0.0",
"smol-toml": "^1.0.1",
"yargs": "^17.0.1"
},
"devDependencies": {
Expand All @@ -55,7 +56,7 @@
"prettier": "^3.0.0"
},
"engines": {
"node": ">=16"
"node": ">=18"
},
"type": "module",
"keywords": [
Expand Down
10 changes: 10 additions & 0 deletions src/cli.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -421,6 +421,16 @@ describe("CLI", function () {
});
});

it("should validate toml files", function () {
return cli({
patterns: ["./testfiles/files/valid.toml"],
schema: "./testfiles/schemas/schema.json",
}).then((result) => {
assert.equal(result, 0);
assert(logContainsSuccess("./testfiles/files/valid.toml is valid"));
});
});

it("should use custom parser in preference to file extension if specified", function () {
return cli({
patterns: ["./testfiles/files/with-comments.json"],
Expand Down
3 changes: 3 additions & 0 deletions src/parser.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import JSON5 from "json5";
import yaml from "js-yaml";
import { parse } from "smol-toml";

function parseDocument(contents, format) {
switch (format) {
Expand All @@ -13,6 +14,8 @@ function parseDocument(contents, format) {
case ".yml":
case ".yaml":
return yaml.load(contents);
case ".toml":
return parse(contents);
default:
throw new Error(`Unsupported format ${format}`);
}
Expand Down
1 change: 1 addition & 0 deletions testfiles/files/valid.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
num = 4

0 comments on commit e7051a3

Please sign in to comment.