Enforce trailing commas

This commit is contained in:
Rene Saarsoo 2020-09-21 18:15:45 +03:00
parent a390ec62ee
commit 77bfbbd0a8
4 changed files with 21 additions and 20 deletions

View File

@ -1,3 +1,4 @@
{
"printWidth": 120
"printWidth": 120,
"trailingComma": "all"
}

View File

@ -5,7 +5,7 @@ import { Interval, Workout } from "./ast";
const generateRangeInterval = (
tagName: "Warmup" | "Cooldown",
{ duration, intensity, cadence }: Interval
{ duration, intensity, cadence }: Interval,
): xml.XmlObject => {
return {
[tagName]: [
@ -57,6 +57,6 @@ export const generateZwo = ({ name, author, description, intervals }: Workout):
...intervals.map(generateInterval),
],
},
{ indent: " " }
{ indent: " " },
);
};

View File

@ -3,11 +3,11 @@ import { parse } from ".";
describe("Parser", () => {
it("throws error for empty file", () => {
expect(() => parse("")).toThrowErrorMatchingInlineSnapshot(
`"Workout is missing a name. Use \`Name:\` to declare one. at line 1 char 1"`
`"Workout is missing a name. Use \`Name:\` to declare one. at line 1 char 1"`,
);
expect(() => parse(" \n \n \t")).toThrowErrorMatchingInlineSnapshot(
`"Workout is missing a name. Use \`Name:\` to declare one. at line 1 char 1"`
`"Workout is missing a name. Use \`Name:\` to declare one. at line 1 char 1"`,
);
});
@ -32,7 +32,7 @@ Description:
Do it when you dare,
it'll cause lots of pain.
`)
`),
).toMatchInlineSnapshot(`
Object {
"author": "John Doe",
@ -56,7 +56,7 @@ Rest: 5:00 50%
Interval: 10:00 80% 90rpm
Rest: 5:00 45%
`).intervals
`).intervals,
).toMatchInlineSnapshot(`
Array [
Object {
@ -97,7 +97,7 @@ Name: My Workout
Warmup: 5:30 50%..80% 100rpm
Cooldown: 5:30 70%..45%
`).intervals
`).intervals,
).toMatchInlineSnapshot(`
Array [
Object {
@ -126,13 +126,13 @@ Cooldown: 5:30 70%..45%
it("requires duration and power parameters to be specified", () => {
expect(() => parseInterval("Interval: 50%")).toThrowErrorMatchingInlineSnapshot(
`"Duration not specified at line 2 char 1"`
`"Duration not specified at line 2 char 1"`,
);
expect(() => parseInterval("Interval: 30:00")).toThrowErrorMatchingInlineSnapshot(
`"Power not specified at line 2 char 1"`
`"Power not specified at line 2 char 1"`,
);
expect(() => parseInterval("Interval: 10rpm")).toThrowErrorMatchingInlineSnapshot(
`"Duration not specified at line 2 char 1"`
`"Duration not specified at line 2 char 1"`,
);
});
@ -210,34 +210,34 @@ Cooldown: 5:30 70%..45%
it("throws error for incorrect duration formats", () => {
expect(() => parseInterval("Interval: 10 50%")).toThrowErrorMatchingInlineSnapshot(
`"Unrecognized interval parameter \\"10\\" at line 2 char 11"`
`"Unrecognized interval parameter \\"10\\" at line 2 char 11"`,
);
expect(() => parseInterval("Interval: :10 50%")).toThrowErrorMatchingInlineSnapshot(
`"Unrecognized interval parameter \\":10\\" at line 2 char 11"`
`"Unrecognized interval parameter \\":10\\" at line 2 char 11"`,
);
expect(() => parseInterval("Interval: 0:100 50%")).toThrowErrorMatchingInlineSnapshot(
`"Unrecognized interval parameter \\"0:100\\" at line 2 char 11"`
`"Unrecognized interval parameter \\"0:100\\" at line 2 char 11"`,
);
expect(() => parseInterval("Interval: 00:00:00:10 50%")).toThrowErrorMatchingInlineSnapshot(
`"Unrecognized interval parameter \\"00:00:00:10\\" at line 2 char 11"`
`"Unrecognized interval parameter \\"00:00:00:10\\" at line 2 char 11"`,
);
});
it("throws error for unexpected interval parameter", () => {
expect(() => parseInterval("Interval: 10:00 50% foobar")).toThrowErrorMatchingInlineSnapshot(
`"Unrecognized interval parameter \\"foobar\\" at line 2 char 21"`
`"Unrecognized interval parameter \\"foobar\\" at line 2 char 21"`,
);
expect(() => parseInterval("Interval: 10:00 50% 123blah")).toThrowErrorMatchingInlineSnapshot(
`"Unrecognized interval parameter \\"123blah\\" at line 2 char 21"`
`"Unrecognized interval parameter \\"123blah\\" at line 2 char 21"`,
);
expect(() => parseInterval("Interval: 10:00 50% ^*&")).toThrowErrorMatchingInlineSnapshot(
`"Unrecognized interval parameter \\"^*&\\" at line 2 char 21"`
`"Unrecognized interval parameter \\"^*&\\" at line 2 char 21"`,
);
});
it("throws error for unexpected type of interval", () => {
expect(() => parseInterval("Interval: 30:00 5% \n CustomInterval: 15:00 10%")).toThrowErrorMatchingInlineSnapshot(
`"Unexpected token [text CustomInterval: 15:00 10%] at line 3 char 1"`
`"Unexpected token [text CustomInterval: 15:00 10%] at line 3 char 1"`,
);
});
});

View File

@ -30,6 +30,6 @@ export const normalizedIntensity = (intervals: Interval[]): number => {
rollingAverages,
(averages) => averages.map(fourthPower),
average,
fourthRoot
fourthRoot,
)(intervals);
};